Speed up some operations

This commit is contained in:
Joshua Granick
2015-04-13 13:15:19 -07:00
parent 5d435931db
commit a16894571e
6 changed files with 120 additions and 1 deletions

View File

@@ -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" />

View 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

View File

@@ -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);

View 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) {
}
}