speed up copyPixels for c++
This commit is contained in:
committed by
Joshua Granick
parent
d21d1b6056
commit
75bdc7e248
@@ -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 ();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user