Add CFFI setPixels
This commit is contained in:
@@ -29,6 +29,7 @@ namespace lime {
|
||||
static void Merge (Image* image, Image* sourceImage, Rectangle* sourceRect, Vector2* destPoint, int redMultiplier, int greenMultiplier, int blueMultiplier, int alphaMultiplier);
|
||||
static void MultiplyAlpha (Image* image);
|
||||
static void Resize (Image* image, ImageBuffer* buffer, int width, int height);
|
||||
static void SetPixels (Image* image, Rectangle* rect, ByteArray* bytes, PixelFormat format);
|
||||
static void UnmultiplyAlpha (Image* image);
|
||||
|
||||
|
||||
|
||||
@@ -549,6 +549,18 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_image_data_util_set_pixels (value image, value rect, value bytes, value format) {
|
||||
|
||||
Image _image = Image (image);
|
||||
Rectangle _rect = Rectangle (rect);
|
||||
ByteArray _bytes = ByteArray (bytes);
|
||||
PixelFormat _format = (PixelFormat)val_int (format);
|
||||
ImageDataUtil::SetPixels (&_image, &_rect, &_bytes, _format);
|
||||
return alloc_null ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
value lime_image_data_util_unmultiply_alpha (value image) {
|
||||
|
||||
Image _image = Image (image);
|
||||
@@ -958,6 +970,7 @@ namespace lime {
|
||||
DEFINE_PRIM_MULT (lime_image_data_util_merge);
|
||||
DEFINE_PRIM (lime_image_data_util_multiply_alpha, 1);
|
||||
DEFINE_PRIM (lime_image_data_util_resize, 4);
|
||||
DEFINE_PRIM (lime_image_data_util_set_pixels, 4);
|
||||
DEFINE_PRIM (lime_image_data_util_unmultiply_alpha, 1);
|
||||
DEFINE_PRIM (lime_image_encode, 3);
|
||||
DEFINE_PRIM (lime_image_load, 1);
|
||||
|
||||
@@ -466,6 +466,69 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
void ImageDataUtil::SetPixels (Image* image, Rectangle* rect, ByteArray* bytes, PixelFormat format) {
|
||||
|
||||
int len = int (rect->width * rect->height);
|
||||
|
||||
if (format == RGBA && rect->width == image->buffer->width && rect->height == image->buffer->height && rect->x == 0 && rect->y == 0) {
|
||||
|
||||
memcpy (image->buffer->data->Bytes (), bytes->Bytes (), bytes->Size ());
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
uint8_t* data = (uint8_t*)image->buffer->data->Bytes ();
|
||||
int* byteArray = (int*)bytes->Bytes ();
|
||||
|
||||
int offset = int (image->buffer->width * (rect->y + image->offsetX) + (rect->x + image->offsetY));
|
||||
int pos = offset * 4;
|
||||
int boundR = int ((rect->x + rect->width + image->offsetX));
|
||||
int width = image->buffer->width;
|
||||
int color;
|
||||
|
||||
if (format == ARGB) {
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
|
||||
if (((pos) % (width * 4)) >= boundR * 4) {
|
||||
|
||||
pos += (width - boundR) * 4;
|
||||
|
||||
}
|
||||
|
||||
color = byteArray[i];
|
||||
|
||||
data[pos++] = (color >> 16) & 0xFF;
|
||||
data[pos++] = (color >> 8) & 0xFF;
|
||||
data[pos++] = color & 0xFF;
|
||||
data[pos++] = (color >> 24) & 0xFF;
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
|
||||
if (((pos) % (width * 4)) >= boundR * 4) {
|
||||
|
||||
pos += (width - boundR) * 4;
|
||||
|
||||
}
|
||||
|
||||
color = byteArray[i];
|
||||
|
||||
data[pos++] = (color >> 24) & 0xFF;
|
||||
data[pos++] = (color >> 16) & 0xFF;
|
||||
data[pos++] = (color >> 8) & 0xFF;
|
||||
data[pos++] = color & 0xFF;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ImageDataUtil::UnmultiplyAlpha (Image* image) {
|
||||
|
||||
int length = image->buffer->data->Size () / 4;
|
||||
|
||||
Reference in New Issue
Block a user