Fixes
This commit is contained in:
@@ -655,6 +655,10 @@ class ImageDataUtil {
|
||||
var dataView = new ImageDataView (image, rect);
|
||||
var position, argb:ARGB, bgra:BGRA, pixel:RGBA;
|
||||
|
||||
#if !flash
|
||||
var destPosition = 0;
|
||||
#end
|
||||
|
||||
for (y in 0...dataView.height) {
|
||||
|
||||
position = dataView.row (y);
|
||||
@@ -677,10 +681,10 @@ class ImageDataUtil {
|
||||
byteArray.writeByte (pixel.b);
|
||||
byteArray.writeByte (pixel.a);
|
||||
#else
|
||||
byteArray.__set (position, pixel.r);
|
||||
byteArray.__set (position + 1, pixel.g);
|
||||
byteArray.__set (position + 2, pixel.b);
|
||||
byteArray.__set (position + 3, pixel.a);
|
||||
byteArray.__set (destPosition++, pixel.r);
|
||||
byteArray.__set (destPosition++, pixel.g);
|
||||
byteArray.__set (destPosition++, pixel.b);
|
||||
byteArray.__set (destPosition++, pixel.a);
|
||||
#end
|
||||
|
||||
position += 4;
|
||||
|
||||
@@ -28,7 +28,7 @@ abstract RGBA(Int) from Int to Int {
|
||||
|
||||
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) {
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <graphics/PixelFormat.h>
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
namespace lime {
|
||||
@@ -18,8 +19,7 @@ namespace lime {
|
||||
|
||||
for (int i = 0; i < 256; i++) {
|
||||
|
||||
// Seem to need +1 to get the same results as Haxe in multiplyAlpha
|
||||
__alpha16[i] = (i + 1) * ((1 << 16) / 0xFF);
|
||||
__alpha16[i] = ceil ((i + 1) * ((1 << 16) / 0xFF));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,8 @@ namespace lime {
|
||||
uint8_t* destData = (uint8_t*)image->buffer->data->Data ();
|
||||
|
||||
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 destFormat = image->buffer->format;
|
||||
@@ -111,7 +112,8 @@ namespace lime {
|
||||
uint8_t* destData = (uint8_t*)image->buffer->data->Data ();
|
||||
|
||||
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 destFormat = image->buffer->format;
|
||||
@@ -190,7 +192,8 @@ namespace lime {
|
||||
PixelFormat alphaFormat = alphaImage->buffer->format;
|
||||
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;
|
||||
RGBA alphaPixel;
|
||||
|
||||
@@ -340,52 +343,27 @@ namespace lime {
|
||||
int length = int (rect->width * rect->height);
|
||||
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 ());
|
||||
return;
|
||||
PixelFormat sourceFormat = image->buffer->format;
|
||||
bool premultiplied = image->buffer->premultiplied;
|
||||
|
||||
}
|
||||
ImageDataView dataView = ImageDataView (image, rect);
|
||||
int position, destPosition = 0;
|
||||
RGBA pixel;
|
||||
|
||||
uint8_t* data = (uint8_t*)pixels->Data ();
|
||||
uint8_t* srcData = (uint8_t*)image->buffer->data->Data ();
|
||||
for (int y = 0; y < dataView.height; y++) {
|
||||
|
||||
int srcStride = image->buffer->Stride ();
|
||||
int srcPosition = int ((rect->x * 4) + (srcStride * rect->y));
|
||||
int srcRowOffset = srcStride - int (4 * rect->width);
|
||||
int srcRowEnd = int (4 * (rect->x + rect->width));
|
||||
position = dataView.Row (y);
|
||||
|
||||
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++];
|
||||
data[i * 4 + 2] = srcData[srcPosition++];
|
||||
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;
|
||||
|
||||
}
|
||||
position += 4;
|
||||
destPosition += 4;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user