This commit is contained in:
Joshua Granick
2015-07-21 10:38:29 -07:00
parent d6750818fc
commit fadc285209
4 changed files with 32 additions and 50 deletions

View File

@@ -655,6 +655,10 @@ class ImageDataUtil {
var dataView = new ImageDataView (image, rect); var dataView = new ImageDataView (image, rect);
var position, argb:ARGB, bgra:BGRA, pixel:RGBA; var position, argb:ARGB, bgra:BGRA, pixel:RGBA;
#if !flash
var destPosition = 0;
#end
for (y in 0...dataView.height) { for (y in 0...dataView.height) {
position = dataView.row (y); position = dataView.row (y);
@@ -677,10 +681,10 @@ class ImageDataUtil {
byteArray.writeByte (pixel.b); byteArray.writeByte (pixel.b);
byteArray.writeByte (pixel.a); byteArray.writeByte (pixel.a);
#else #else
byteArray.__set (position, pixel.r); byteArray.__set (destPosition++, pixel.r);
byteArray.__set (position + 1, pixel.g); byteArray.__set (destPosition++, pixel.g);
byteArray.__set (position + 2, pixel.b); byteArray.__set (destPosition++, pixel.b);
byteArray.__set (position + 3, pixel.a); byteArray.__set (destPosition++, pixel.a);
#end #end
position += 4; position += 4;

View File

@@ -28,7 +28,7 @@ abstract RGBA(Int) from Int to Int {
for (i in 0...256) { for (i in 0...256) {
__alpha16[i] = Math.floor (i * (1 << 16) / 255); __alpha16[i] = Math.ceil ((i) * ((1 << 16) / 0xFF));
} }
@@ -124,7 +124,7 @@ abstract RGBA(Int) from Int to Int {
if (a != 0 && a != 0xFF) { if (a != 0 && a != 0xFF) {
unmult = 255.0 / a; unmult = 255.0 / a;
set (__clamp[Math.floor (r * unmult)], __clamp[Math.floor (g * unmult)], __clamp[Math.floor (b * unmult)], a); set (__clamp[Math.round (r * unmult)], __clamp[Math.round (g * unmult)], __clamp[Math.round (b * unmult)], a);
} }

View File

@@ -4,6 +4,7 @@
#include <graphics/PixelFormat.h> #include <graphics/PixelFormat.h>
#include <stdint.h> #include <stdint.h>
#include <math.h>
namespace lime { namespace lime {
@@ -18,8 +19,7 @@ namespace lime {
for (int i = 0; i < 256; i++) { for (int i = 0; i < 256; i++) {
// Seem to need +1 to get the same results as Haxe in multiplyAlpha __alpha16[i] = ceil ((i + 1) * ((1 << 16) / 0xFF));
__alpha16[i] = (i + 1) * ((1 << 16) / 0xFF);
} }

View File

@@ -54,7 +54,8 @@ namespace lime {
uint8_t* destData = (uint8_t*)image->buffer->data->Data (); uint8_t* destData = (uint8_t*)image->buffer->data->Data ();
ImageDataView srcView = ImageDataView (sourceImage, sourceRect); ImageDataView srcView = ImageDataView (sourceImage, sourceRect);
ImageDataView destView = ImageDataView (image, &Rectangle (destPoint->x, destPoint->y, srcView.width, srcView.height)); Rectangle destRect = Rectangle (destPoint->x, destPoint->y, srcView.width, srcView.height);
ImageDataView destView = ImageDataView (image, &destRect);
PixelFormat srcFormat = sourceImage->buffer->format; PixelFormat srcFormat = sourceImage->buffer->format;
PixelFormat destFormat = image->buffer->format; PixelFormat destFormat = image->buffer->format;
@@ -111,7 +112,8 @@ namespace lime {
uint8_t* destData = (uint8_t*)image->buffer->data->Data (); uint8_t* destData = (uint8_t*)image->buffer->data->Data ();
ImageDataView sourceView = ImageDataView (sourceImage, sourceRect); ImageDataView sourceView = ImageDataView (sourceImage, sourceRect);
ImageDataView destView = ImageDataView (image, &Rectangle (destPoint->x, destPoint->y, sourceView.width, sourceView.height)); Rectangle destRect = Rectangle (destPoint->x, destPoint->y, sourceView.width, sourceView.height);
ImageDataView destView = ImageDataView (image, &destRect);
PixelFormat sourceFormat = sourceImage->buffer->format; PixelFormat sourceFormat = sourceImage->buffer->format;
PixelFormat destFormat = image->buffer->format; PixelFormat destFormat = image->buffer->format;
@@ -190,7 +192,8 @@ namespace lime {
PixelFormat alphaFormat = alphaImage->buffer->format; PixelFormat alphaFormat = alphaImage->buffer->format;
bool alphaPremultiplied = alphaImage->buffer->premultiplied; bool alphaPremultiplied = alphaImage->buffer->premultiplied;
ImageDataView alphaView = ImageDataView (alphaImage, &Rectangle (alphaPoint->x, alphaPoint->y, destView.width, destView.height)); Rectangle alphaRect = Rectangle (alphaPoint->x, alphaPoint->y, destView.width, destView.height);
ImageDataView alphaView = ImageDataView (alphaImage, &alphaRect);
int alphaPosition; int alphaPosition;
RGBA alphaPixel; RGBA alphaPixel;
@@ -340,52 +343,27 @@ namespace lime {
int length = int (rect->width * rect->height); int length = int (rect->width * rect->height);
pixels->Resize (length * 4); pixels->Resize (length * 4);
if (format == RGBA32 && rect->width == image->buffer->width && rect->height == image->buffer->height && rect->x == 0 && rect->y == 0) { uint8_t* data = (uint8_t*)image->buffer->data->Data ();
uint8_t* destData = (uint8_t*)pixels->Data ();
memcpy (pixels->Data (), image->buffer->data->Data (), image->buffer->data->Length ()); PixelFormat sourceFormat = image->buffer->format;
return; bool premultiplied = image->buffer->premultiplied;
} ImageDataView dataView = ImageDataView (image, rect);
int position, destPosition = 0;
RGBA pixel;
uint8_t* data = (uint8_t*)pixels->Data (); for (int y = 0; y < dataView.height; y++) {
uint8_t* srcData = (uint8_t*)image->buffer->data->Data ();
int srcStride = image->buffer->Stride (); position = dataView.Row (y);
int srcPosition = int ((rect->x * 4) + (srcStride * rect->y));
int srcRowOffset = srcStride - int (4 * rect->width);
int srcRowEnd = int (4 * (rect->x + rect->width));
if (format == ARGB32) { for (int x = 0; x < dataView.width; x++) {
for (int i = 0; i < length; i++) { pixel.ReadUInt8 (data, position, sourceFormat, premultiplied);
pixel.WriteUInt8 (destData, destPosition, format, false);
data[i * 4 + 1] = srcData[srcPosition++]; position += 4;
data[i * 4 + 2] = srcData[srcPosition++]; destPosition += 4;
data[i * 4 + 3] = srcData[srcPosition++];
data[i * 4] = srcData[srcPosition++];
if ((srcPosition % srcStride) > srcRowEnd) {
srcPosition += srcRowOffset;
}
}
} else {
for (int i = 0; i < length; i++) {
data[i * 4] = srcData[srcPosition++];
data[i * 4 + 1] = srcData[srcPosition++];
data[i * 4 + 2] = srcData[srcPosition++];
data[i * 4 + 3] = srcData[srcPosition++];
if ((srcPosition % srcStride) > srcRowEnd) {
srcPosition += srcRowOffset;
}
} }