Clean up the blit row code and add a Haxe alternative

This commit is contained in:
Joshua Granick
2017-05-05 14:39:59 -07:00
parent 71ab0b6e17
commit c72a05ab4a
4 changed files with 35 additions and 34 deletions

View File

@@ -186,23 +186,40 @@ class ImageDataUtil {
var destFormat = image.buffer.format;
var sourcePremultiplied = sourceImage.buffer.premultiplied;
var destPremultiplied = image.buffer.premultiplied;
var sourceBitsPerPixel = sourceImage.buffer.bitsPerPixel;
var destBitsPerPixel = image.buffer.bitsPerPixel;
var sourcePosition, destPosition, sourcePixel:RGBA;
if (!mergeAlpha || !sourceImage.transparent) {
for (y in 0...destView.height) {
if (sourceFormat == destFormat && sourcePremultiplied == destPremultiplied && sourceBitsPerPixel == destBitsPerPixel) {
sourcePosition = sourceView.row (y);
destPosition = destView.row (y);
for (y in 0...destView.height) {
for (x in 0...destView.width) {
sourcePosition = sourceView.row (y);
destPosition = destView.row (y);
sourcePixel.readUInt8 (sourceData, sourcePosition, sourceFormat, sourcePremultiplied);
sourcePixel.writeUInt8 (destData, destPosition, destFormat, destPremultiplied);
destData.buffer.blit (destPosition, sourceData.buffer, sourcePosition, destView.width * destBitsPerPixel);
sourcePosition += 4;
destPosition += 4;
}
} else {
for (y in 0...destView.height) {
sourcePosition = sourceView.row (y);
destPosition = destView.row (y);
for (x in 0...destView.width) {
sourcePixel.readUInt8 (sourceData, sourcePosition, sourceFormat, sourcePremultiplied);
sourcePixel.writeUInt8 (destData, destPosition, destFormat, destPremultiplied);
sourcePosition += 4;
destPosition += 4;
}
}

View File

@@ -20,7 +20,6 @@ namespace lime {
~ImageBuffer ();
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);
int Stride ();
value Value ();

View File

@@ -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) {
this->bitsPerPixel = bitsPerPixel;

View File

@@ -124,26 +124,23 @@ namespace lime {
bool sourcePremultiplied = sourceImage->buffer->premultiplied;
bool destPremultiplied = image->buffer->premultiplied;
int sourceBitsPerPixel = sourceImage->buffer->bitsPerPixel;
int destBitsPerPixel = image->buffer->bitsPerPixel;
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);
destPosition = destView.Row (y);
sourcePosition = sourceView.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++) {