Improve handling oof corrupted PNG images (resolves openfl/openfl#1999)
This commit is contained in:
@@ -724,8 +724,11 @@ class Image {
|
||||
|
||||
if (bytes == null) return null;
|
||||
var image = new Image ();
|
||||
image.__fromBytes (bytes);
|
||||
return image;
|
||||
if (image.__fromBytes (bytes)) {
|
||||
return image;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -768,8 +771,11 @@ class Image {
|
||||
|
||||
if (path == null) return null;
|
||||
var image = new Image ();
|
||||
image.__fromFile (path);
|
||||
return image;
|
||||
if (image.__fromFile (path)) {
|
||||
return image;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1694,7 +1700,7 @@ class Image {
|
||||
}
|
||||
|
||||
|
||||
@:noCompletion private function __fromBytes (bytes:Bytes, onload:Image->Void = null):Void {
|
||||
@:noCompletion private function __fromBytes (bytes:Bytes, onload:Image->Void = null):Bool {
|
||||
|
||||
#if (js && html5)
|
||||
|
||||
@@ -1720,6 +1726,7 @@ class Image {
|
||||
}
|
||||
|
||||
__fromBase64 (__base64Encode (bytes), type, onload);
|
||||
return true;
|
||||
|
||||
#elseif (lime_cffi && !macro)
|
||||
|
||||
@@ -1744,6 +1751,8 @@ class Image {
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
@@ -1752,10 +1761,12 @@ class Image {
|
||||
|
||||
#end
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@:noCompletion private function __fromFile (path:String, onload:Image->Void = null, onerror:Void->Void = null):Void {
|
||||
@:noCompletion private function __fromFile (path:String, onload:Image->Void = null, onerror:Void->Void = null):Bool {
|
||||
|
||||
#if (kha && !macro)
|
||||
|
||||
@@ -1798,6 +1809,8 @@ class Image {
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
} catch (e:Dynamic) {}
|
||||
@@ -1852,6 +1865,8 @@ class Image {
|
||||
// (issue #1019768)
|
||||
if (image.complete) { }
|
||||
|
||||
return true;
|
||||
|
||||
#elseif (lime_cffi || java)
|
||||
|
||||
var buffer:ImageBuffer = null;
|
||||
@@ -1921,6 +1936,8 @@ class Image {
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
@@ -1929,6 +1946,8 @@ class Image {
|
||||
|
||||
#end
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user