Temporarily use the Haxe format library to handle PNG assets on native platforms
This commit is contained in:
@@ -7,7 +7,10 @@
|
||||
|
||||
<section unless="display">
|
||||
|
||||
<haxelib name="format" if="native" />
|
||||
|
||||
<haxelib name="hxcpp" if="cpp" />
|
||||
|
||||
<ndll name="std" haxelib="hxcpp" if="cpp" />
|
||||
<ndll name="regexp" haxelib="hxcpp" if="cpp" />
|
||||
<ndll name="zlib" haxelib="hxcpp" if="cpp" />
|
||||
|
||||
@@ -6,6 +6,7 @@ import haxe.Unserializer;
|
||||
import lime.app.Preloader;
|
||||
import lime.graphics.ImageData;
|
||||
import lime.utils.ByteArray;
|
||||
import lime.utils.UInt8Array;
|
||||
import lime.Assets;
|
||||
|
||||
#if sys
|
||||
@@ -209,7 +210,37 @@ class DefaultAssetLibrary extends AssetLibrary {
|
||||
|
||||
#else
|
||||
|
||||
return null;
|
||||
// TODO: Implement in native backend
|
||||
|
||||
var bytes = getBytes (id);
|
||||
var byteInput = new haxe.io.BytesInput (bytes, 0, bytes.length);
|
||||
var png = new format.png.Reader (byteInput).read ();
|
||||
var data = format.png.Tools.extract32 (png);
|
||||
var header = format.png.Tools.getHeader (png);
|
||||
|
||||
var imageWidth = header.width;
|
||||
var imageHeight = header.height;
|
||||
var imageData = new UInt8Array (ByteArray.fromBytes (data));
|
||||
|
||||
var imageLength = imageWidth * imageHeight;
|
||||
var b, g, r, a;
|
||||
|
||||
for (i in 0...imageLength) {
|
||||
|
||||
b = imageData[i * 4];
|
||||
g = imageData[i * 4 + 1];
|
||||
r = imageData[i * 4 + 2];
|
||||
a = imageData[i * 4 + 3];
|
||||
|
||||
imageData[i * 4] = r;
|
||||
imageData[i * 4 + 1] = g;
|
||||
imageData[i * 4 + 2] = b;
|
||||
imageData[i * 4 + 3] = a;
|
||||
|
||||
}
|
||||
|
||||
return new ImageData (imageData, imageWidth, imageHeight);
|
||||
|
||||
//if (className.exists(id)) return cast (Type.createInstance (className.get (id), []), BitmapData);
|
||||
//else return BitmapData.load (path.get (id));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user