Speed up some operations
This commit is contained in:
@@ -164,6 +164,7 @@
|
||||
<file name="src/app/UpdateEvent.cpp" />
|
||||
<file name="src/audio/format/WAV.cpp" />
|
||||
<file name="src/audio/AudioBuffer.cpp" />
|
||||
<file name="src/graphics/utils/ImageDataUtil.cpp" />
|
||||
<file name="src/graphics/ImageBuffer.cpp" />
|
||||
<file name="src/graphics/RenderEvent.cpp" />
|
||||
<file name="src/ui/GamepadEvent.cpp" />
|
||||
|
||||
27
project/include/graphics/utils/ImageDataUtil.h
Normal file
27
project/include/graphics/utils/ImageDataUtil.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef LIME_GRAPHICS_UTILS_IMAGE_DATA_UTIL_H
|
||||
#define LIME_GRAPHICS_UTILS_IMAGE_DATA_UTIL_H
|
||||
|
||||
|
||||
#include <hx/CFFI.h>
|
||||
#include <utils/ByteArray.h>
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
|
||||
class ImageDataUtil {
|
||||
|
||||
|
||||
public:
|
||||
|
||||
static void MultiplyAlpha (ByteArray *bytes);
|
||||
static void UnmultiplyAlpha (ByteArray *bytes);
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <audio/AudioBuffer.h>
|
||||
#include <graphics/format/JPEG.h>
|
||||
#include <graphics/format/PNG.h>
|
||||
#include <graphics/utils/ImageDataUtil.h>
|
||||
#include <graphics/ImageBuffer.h>
|
||||
#include <graphics/Renderer.h>
|
||||
#include <graphics/RenderEvent.h>
|
||||
@@ -368,6 +369,15 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_image_data_util_multiply_alpha (value data) {
|
||||
|
||||
ByteArray bytes = ByteArray (data);
|
||||
ImageDataUtil::MultiplyAlpha (&bytes);
|
||||
return alloc_null ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
value lime_image_encode (value buffer, value type, value quality) {
|
||||
|
||||
ImageBuffer imageBuffer = ImageBuffer (buffer);
|
||||
@@ -837,6 +847,7 @@ namespace lime {
|
||||
DEFINE_PRIM (lime_gamepad_event_manager_register, 2);
|
||||
DEFINE_PRIM (lime_gamepad_get_device_guid, 1);
|
||||
DEFINE_PRIM (lime_gamepad_get_device_name, 1);
|
||||
DEFINE_PRIM (lime_image_data_util_multiply_alpha, 1);
|
||||
DEFINE_PRIM (lime_image_encode, 3);
|
||||
DEFINE_PRIM (lime_image_load, 1);
|
||||
DEFINE_PRIM (lime_jni_getenv, 0);
|
||||
|
||||
50
project/src/graphics/utils/ImageDataUtil.cpp
Normal file
50
project/src/graphics/utils/ImageDataUtil.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <graphics/utils/ImageDataUtil.h>
|
||||
#include <system/System.h>
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
|
||||
static long int __alpha16[256];
|
||||
|
||||
int initValues () {
|
||||
|
||||
for (int i = 0; i < 256; i++) {
|
||||
|
||||
__alpha16[i] = i * ((1 << 16) / 255);
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
static int initValues_ = initValues ();
|
||||
|
||||
|
||||
void ImageDataUtil::MultiplyAlpha (ByteArray* bytes) {
|
||||
|
||||
int a16 = 0;
|
||||
int length = bytes->Size () / 4;
|
||||
uint8_t* data = (uint8_t*)bytes->Bytes ();
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
|
||||
a16 = __alpha16[data[3]];
|
||||
data[0] = (data[0] * a16) >> 16;
|
||||
data[1] = (data[1] * a16) >> 16;
|
||||
data[2] = (data[2] * a16) >> 16;
|
||||
data += 4;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ImageDataUtil::UnmultiplyAlpha (ByteArray* bytes) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user