Skip to content

Commit

Permalink
Fix off-by-one bug in the BMP encoder.
Browse files Browse the repository at this point in the history
  • Loading branch information
vkoskiv committed Jan 17, 2020
1 parent 84349ec commit 4dcc12e
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/utils/filehandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ void encodeBMPFromArray(const char *filename, unsigned char *imgData, int width,
//Apparently BMP is BGR, whereas C-ray's internal buffer is RGB (Like it should be)
//So we need to convert the image data before writing to file.
unsigned char *bgrData = calloc(3 * width * height, sizeof(unsigned char));
//FIXME: For some reason we can't access the 0 of X and Y on imgdata. So now BMP images have 1 black row on left and top edges...
for (int y = 1; y < height; y++) {
for (int x = 1; x < width; x++) {
bgrData[(x + (height - y) * width) * 3 + 0] = imgData[(x + (height - y) * width) * 3 + 2];
bgrData[(x + (height - y) * width) * 3 + 1] = imgData[(x + (height - y) * width) * 3 + 1];
bgrData[(x + (height - y) * width) * 3 + 2] = imgData[(x + (height - y) * width) * 3 + 0];
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
bgrData[(x + ((height - 1) - y) * width) * 3 + 0] = imgData[(x + (height - y) * width) * 3 + 2];
bgrData[(x + ((height - 1) - y) * width) * 3 + 1] = imgData[(x + (height - y) * width) * 3 + 1];
bgrData[(x + ((height - 1) - y) * width) * 3 + 2] = imgData[(x + (height - y) * width) * 3 + 0];
}
}
int i;
Expand Down

0 comments on commit 4dcc12e

Please sign in to comment.