diff --git a/lime/graphics/ImageBuffer.hx b/lime/graphics/ImageBuffer.hx index d37ebcb21..0bf554d33 100644 --- a/lime/graphics/ImageBuffer.hx +++ b/lime/graphics/ImageBuffer.hx @@ -1,6 +1,8 @@ package lime.graphics; +import haxe.io.Bytes; +import lime.utils.ByteArray; import lime.utils.UInt8Array; #if (js && html5) @@ -83,7 +85,7 @@ class ImageBuffer { buffer.__srcImage = __srcImage; } - #else + #elseif nodejs if (data != null) { buffer.data = new UInt8Array (data.byteLength); @@ -92,6 +94,15 @@ class ImageBuffer { } buffer.__srcCustom = __srcCustom; + #else + if (data != null) { + + var bytes = Bytes.alloc (data.byteLength); + bytes.blit (0, buffer.data.buffer, 0, data.byteLength); + var byteArray = ByteArray.fromBytes (bytes); + buffer.data = new UInt8Array (byteArray); + + } #end buffer.premultiplied = premultiplied; diff --git a/lime/graphics/utils/ImageDataUtil.hx b/lime/graphics/utils/ImageDataUtil.hx index 969537aa6..20864fe72 100644 --- a/lime/graphics/utils/ImageDataUtil.hx +++ b/lime/graphics/utils/ImageDataUtil.hx @@ -7,6 +7,7 @@ import lime.graphics.ImageBuffer; import lime.math.ColorMatrix; import lime.math.Rectangle; import lime.math.Vector2; +import lime.system.System; import lime.utils.ByteArray; import lime.utils.UInt8Array; @@ -501,6 +502,10 @@ class ImageDataUtil { var data = image.buffer.data; if (data == null) return; + #if ((cpp || neko) && !disable_cffi) + lime_image_data_util_multiply_alpha (data.buffer); + #else + var index, a16; var length = Std.int (data.length / 4); @@ -515,6 +520,8 @@ class ImageDataUtil { } + #end + image.buffer.premultiplied = true; image.dirty = true; @@ -731,4 +738,16 @@ class ImageDataUtil { } + + + // Native Methods + + + + + #if (cpp || neko || nodejs) + private static var lime_image_data_util_multiply_alpha = System.load ("lime", "lime_image_data_util_multiply_alpha", 1); + #end + + } \ No newline at end of file diff --git a/project/Build.xml b/project/Build.xml index a7e5659aa..105f0050a 100644 --- a/project/Build.xml +++ b/project/Build.xml @@ -164,6 +164,7 @@ + diff --git a/project/include/graphics/utils/ImageDataUtil.h b/project/include/graphics/utils/ImageDataUtil.h new file mode 100644 index 000000000..aa3bb7e77 --- /dev/null +++ b/project/include/graphics/utils/ImageDataUtil.h @@ -0,0 +1,27 @@ +#ifndef LIME_GRAPHICS_UTILS_IMAGE_DATA_UTIL_H +#define LIME_GRAPHICS_UTILS_IMAGE_DATA_UTIL_H + + +#include +#include + + +namespace lime { + + + class ImageDataUtil { + + + public: + + static void MultiplyAlpha (ByteArray *bytes); + static void UnmultiplyAlpha (ByteArray *bytes); + + + }; + + +} + + +#endif \ No newline at end of file diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index 11d2f102f..6fd69104b 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -15,6 +15,7 @@ #include