diff --git a/project/include/graphics/ImageBuffer.h b/project/include/graphics/ImageBuffer.h index d286a2cc2..65c019c1a 100644 --- a/project/include/graphics/ImageBuffer.h +++ b/project/include/graphics/ImageBuffer.h @@ -20,6 +20,7 @@ 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, int destX, int destY); void Resize (int width, int height, int bitsPerPixel = 32); int Stride (); value Value (); diff --git a/project/src/graphics/ImageBuffer.cpp b/project/src/graphics/ImageBuffer.cpp index b168856fb..71abda57f 100644 --- a/project/src/graphics/ImageBuffer.cpp +++ b/project/src/graphics/ImageBuffer.cpp @@ -97,6 +97,24 @@ namespace lime { } + void ImageBuffer::BlitRow (const unsigned char *data, int sourcePosition, int destPosition, int sourceW, int destX, int destY) { + + if (destX < 0 || destX + sourceW > this->width || destY < 0 || destY + 1 > this->height) { + + return; + + } + + 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; diff --git a/project/src/graphics/utils/ImageDataUtil.cpp b/project/src/graphics/utils/ImageDataUtil.cpp index 379d360ec..6d8a243d5 100644 --- a/project/src/graphics/utils/ImageDataUtil.cpp +++ b/project/src/graphics/utils/ImageDataUtil.cpp @@ -118,26 +118,43 @@ namespace lime { PixelFormat sourceFormat = sourceImage->buffer->format; PixelFormat destFormat = image->buffer->format; - bool sourcePremultiplied = sourceImage->buffer->premultiplied; - bool destPremultiplied = image->buffer->premultiplied; int sourcePosition, destPosition; RGBA sourcePixel; + bool sourcePremultiplied = sourceImage->buffer->premultiplied; + bool destPremultiplied = image->buffer->premultiplied; + if (!mergeAlpha || !sourceImage->buffer->transparent) { - for (int y = 0; y < destView.height; y++) { + if(sourceFormat == destFormat && sourcePremultiplied == destPremultiplied) { - sourcePosition = sourceView.Row (y); - destPosition = destView.Row (y); + for (int y = 0; y < destView.height; y++) { + + sourcePosition = sourceView.Row (y); + destPosition = destView.Row (y); + + image->buffer->BlitRow(sourceData, sourcePosition, destPosition, sourceView.width, destView.x, destView.y+y); + + } - for (int x = 0; x < destView.width; x++) { + } + else { + + for (int y = 0; y < destView.height; y++) { - sourcePixel.ReadUInt8 (sourceData, sourcePosition, sourceFormat, sourcePremultiplied); - sourcePixel.WriteUInt8 (destData, destPosition, destFormat, destPremultiplied); + sourcePosition = sourceView.Row (y); + destPosition = destView.Row (y); - sourcePosition += 4; - destPosition += 4; + for (int x = 0; x < destView.width; x++) { + + sourcePixel.ReadUInt8 (sourceData, sourcePosition, sourceFormat, sourcePremultiplied); + sourcePixel.WriteUInt8 (destData, destPosition, destFormat, destPremultiplied); + + sourcePosition += 4; + destPosition += 4; + + } }