Skip to content

Commit

Permalink
Explicitly allocate buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
andrews05 committed Oct 16, 2024
1 parent f587e6e commit 7c1ba80
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/blitters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ extern "C" {
// Stride must be a multiple of 4 but the source isn't.
// We need to copy the data into a new buffer line by line.
stride += 4 - (stride % 4);
BYTE buffer[stride * source->raw.height];
BYTE *buffer = (BYTE*)malloc(stride * source->raw.height);
BYTE *output = buffer;
BYTE *input = source->raw.buffer;
for (int i = 0; i < source->raw.height; i++) {
Expand All @@ -77,6 +77,7 @@ extern "C" {
}
Bitmap sBitmap(source->raw.width, source->raw.height, stride, pixelFormat, buffer);
blit(&sBitmap, dest, srcRect, destRect);
free(buffer);
} else {
Bitmap sBitmap(source->raw.width, source->raw.height, stride, pixelFormat, source->raw.buffer);
blit(&sBitmap, dest, srcRect, destRect);
Expand All @@ -99,7 +100,7 @@ extern "C" {
}
// Despite being labelled RGB, the bitmap we create actually operates as BGR.
// We need to convert our RGB source data to BGR pixel by pixel.
BYTE buffer[stride * source->raw.height];
BYTE *buffer = (BYTE*)malloc(stride * source->raw.height);
BYTE *output = buffer;
BYTE *input = source->raw.buffer;
for (int i = 0; i < source->raw.height; i++) {
Expand All @@ -113,6 +114,7 @@ extern "C" {
}
Bitmap sBitmap(source->raw.width, source->raw.height, stride, PixelFormat24bppRGB, buffer);
blit(&sBitmap, dest, srcRect, destRect);
free(buffer);
}

SETDWORD(0x00575B80, _blit32); // 32 to 16
Expand Down

0 comments on commit 7c1ba80

Please sign in to comment.