Clean up the blit row code and add a Haxe alternative
This commit is contained in:
@@ -186,11 +186,26 @@ class ImageDataUtil {
|
|||||||
var destFormat = image.buffer.format;
|
var destFormat = image.buffer.format;
|
||||||
var sourcePremultiplied = sourceImage.buffer.premultiplied;
|
var sourcePremultiplied = sourceImage.buffer.premultiplied;
|
||||||
var destPremultiplied = image.buffer.premultiplied;
|
var destPremultiplied = image.buffer.premultiplied;
|
||||||
|
var sourceBitsPerPixel = sourceImage.buffer.bitsPerPixel;
|
||||||
|
var destBitsPerPixel = image.buffer.bitsPerPixel;
|
||||||
|
|
||||||
var sourcePosition, destPosition, sourcePixel:RGBA;
|
var sourcePosition, destPosition, sourcePixel:RGBA;
|
||||||
|
|
||||||
if (!mergeAlpha || !sourceImage.transparent) {
|
if (!mergeAlpha || !sourceImage.transparent) {
|
||||||
|
|
||||||
|
if (sourceFormat == destFormat && sourcePremultiplied == destPremultiplied && sourceBitsPerPixel == destBitsPerPixel) {
|
||||||
|
|
||||||
|
for (y in 0...destView.height) {
|
||||||
|
|
||||||
|
sourcePosition = sourceView.row (y);
|
||||||
|
destPosition = destView.row (y);
|
||||||
|
|
||||||
|
destData.buffer.blit (destPosition, sourceData.buffer, sourcePosition, destView.width * destBitsPerPixel);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
for (y in 0...destView.height) {
|
for (y in 0...destView.height) {
|
||||||
|
|
||||||
sourcePosition = sourceView.row (y);
|
sourcePosition = sourceView.row (y);
|
||||||
@@ -208,6 +223,8 @@ class ImageDataUtil {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
var sourceAlpha, destAlpha, oneMinusSourceAlpha, blendAlpha;
|
var sourceAlpha, destAlpha, oneMinusSourceAlpha, blendAlpha;
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ namespace lime {
|
|||||||
~ImageBuffer ();
|
~ImageBuffer ();
|
||||||
|
|
||||||
void Blit (const unsigned char *data, int x, int y, int width, int height);
|
void Blit (const unsigned char *data, int x, int y, int width, int height);
|
||||||
void BlitRow (const unsigned char *data, int sourcePosition, int destPosition, int sourceW);
|
|
||||||
void Resize (int width, int height, int bitsPerPixel = 32);
|
void Resize (int width, int height, int bitsPerPixel = 32);
|
||||||
int Stride ();
|
int Stride ();
|
||||||
value Value ();
|
value Value ();
|
||||||
|
|||||||
@@ -97,18 +97,6 @@ namespace lime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ImageBuffer::BlitRow (const unsigned char *data, int sourcePosition, int destPosition, int sourceW) {
|
|
||||||
|
|
||||||
int stride = (sourceW * (((bitsPerPixel + 3) & ~0x3) >> 3));
|
|
||||||
|
|
||||||
unsigned char *bytes = this->data->Data ();
|
|
||||||
|
|
||||||
memcpy (&bytes[destPosition], &data[sourcePosition], stride);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ImageBuffer::Resize (int width, int height, int bitsPerPixel) {
|
void ImageBuffer::Resize (int width, int height, int bitsPerPixel) {
|
||||||
|
|
||||||
this->bitsPerPixel = bitsPerPixel;
|
this->bitsPerPixel = bitsPerPixel;
|
||||||
|
|||||||
@@ -124,26 +124,23 @@ namespace lime {
|
|||||||
|
|
||||||
bool sourcePremultiplied = sourceImage->buffer->premultiplied;
|
bool sourcePremultiplied = sourceImage->buffer->premultiplied;
|
||||||
bool destPremultiplied = image->buffer->premultiplied;
|
bool destPremultiplied = image->buffer->premultiplied;
|
||||||
|
int sourceBitsPerPixel = sourceImage->buffer->bitsPerPixel;
|
||||||
|
int destBitsPerPixel = image->buffer->bitsPerPixel;
|
||||||
|
|
||||||
if (!mergeAlpha || !sourceImage->buffer->transparent) {
|
if (!mergeAlpha || !sourceImage->buffer->transparent) {
|
||||||
|
|
||||||
if(sourceFormat == destFormat && sourcePremultiplied == destPremultiplied) {
|
if (sourceFormat == destFormat && sourcePremultiplied == destPremultiplied && sourceBitsPerPixel == destBitsPerPixel) {
|
||||||
|
|
||||||
if (false == (destView.x < 0 || destView.x + sourceView.width > image->width || destView.y < 0 || destView.y + destView.height > image->height)) {
|
|
||||||
|
|
||||||
for (int y = 0; y < destView.height; y++) {
|
for (int y = 0; y < destView.height; y++) {
|
||||||
|
|
||||||
sourcePosition = sourceView.Row (y);
|
sourcePosition = sourceView.Row (y);
|
||||||
destPosition = destView.Row (y);
|
destPosition = destView.Row (y);
|
||||||
|
|
||||||
image->buffer->BlitRow(sourceData, sourcePosition, destPosition, sourceView.width);
|
memcpy (&destData[destPosition], &sourceData[sourcePosition], destView.width * destBitsPerPixel);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} else {
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
for (int y = 0; y < destView.height; y++) {
|
for (int y = 0; y < destView.height; y++) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user