Pixmap jpeg decoder fallback
@@ -725,6 +725,7 @@ public class Pixmap implements Disposable{
private void load(byte[] encodedData, int offset, int len, String file){
//use native implementation when possible
if(ArcNativesLoader.loaded){
+ try{
//read with stb_image, which is slightly faster for large images and supports more formats
long[] nativeData = new long[3];
pixels = loadJni(nativeData, encodedData, offset, len);
@@ -734,7 +735,23 @@ public class Pixmap implements Disposable{
width = (int)nativeData[1];
height = (int)nativeData[2];
pixels.position(0).limit(pixels.capacity());
+ }catch(ArcRuntimeException e){
+ //stb_image bug? some PNGs fail with "corrupt JPEG" as the error, try the Java implementation if so
+ if(e.getMessage() != null && e.getMessage().contains("Corrupt JPEG")){
+ try{
+ loadJava(encodedData, offset, len, file);
+ }catch(Exception ignored){
+ //I did my best, fall through and throw the original exception
+ }
+ }
+ throw e;
+ }
}else{
+ loadJava(encodedData, offset, len, file);
+ }
+ }
+
+ private void loadJava(byte[] encodedData, int offset, int len, String file){
//read with the pure java implementation
try{
PngReader reader = new PngReader();
@@ -747,7 +764,6 @@ public class Pixmap implements Disposable{
throw new ArcRuntimeException("Failed to load PNG data" + (file == null ? "" : " (" + file + ")"), e);
}
}
- }
private void load(int width, int height){
//use native implementation when possible
