Fix issue #276: Sometimes pixels are missing when storing images as BMPs
That happens only when RLE is applied. The culprit is in compress_row(), where the rightmost pixels which wouldn't be run-length encoded were ignored; instead we now add them uncompressed to the `row`.
This commit is contained in:
parent
272c06b4d9
commit
b355a7f392
@ -395,9 +395,7 @@ static int compress_row(unsigned char *row, int length)
|
||||
}
|
||||
|
||||
if (compressed_run) {
|
||||
if (rle_type == BMP_RLE_TYPE_RLE) {
|
||||
compressed_length += build_rle_packet(row, rle_type, compressed_run, uncompressed_row);
|
||||
}
|
||||
compressed_length += build_rle_packet(row, rle_type, compressed_run, uncompressed_row);
|
||||
}
|
||||
|
||||
gdFree(uncompressed_start);
|
||||
|
2
tests/bmp/.gitignore
vendored
2
tests/bmp/.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
/bmp_im2im
|
||||
/bmp_null
|
||||
/bug00275
|
||||
/bug00276
|
||||
/bug00276_act.bmp
|
||||
|
@ -2,6 +2,7 @@ LIST(APPEND TESTS_FILES
|
||||
bmp_im2im
|
||||
bmp_null
|
||||
bug00275
|
||||
bug00276
|
||||
)
|
||||
|
||||
ADD_GD_TESTS()
|
||||
|
@ -1,6 +1,7 @@
|
||||
libgd_test_programs += \
|
||||
bmp/bmp_null \
|
||||
bmp/bug00275
|
||||
bmp/bug00275 \
|
||||
bmp/bug00276
|
||||
|
||||
if HAVE_LIBPNG
|
||||
libgd_test_programs += \
|
||||
|
44
tests/bmp/bug00276.c
Normal file
44
tests/bmp/bug00276.c
Normal file
@ -0,0 +1,44 @@
|
||||
/* See <https://github.com/libgd/libgd/issues/276> */
|
||||
|
||||
|
||||
#include "gd.h"
|
||||
#include "gdtest.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
gdImagePtr im_orig, im_saved;
|
||||
int white;
|
||||
char *filename;
|
||||
FILE *fp;
|
||||
|
||||
/* create an image */
|
||||
im_orig = gdImageCreate(10, 10);
|
||||
gdImageColorAllocate(im_orig, 0, 0, 0);
|
||||
white = gdImageColorAllocate(im_orig, 255, 255, 255);
|
||||
gdImageLine(im_orig, 0,0, 9,9, white);
|
||||
|
||||
filename = gdTestFilePath2("bmp", "bug00276_act.bmp");
|
||||
|
||||
/* save image as compressed BMP */
|
||||
fp = fopen(filename, "w+");
|
||||
gdTestAssert(fp != NULL);
|
||||
gdImageBmp(im_orig, fp, 1);
|
||||
fclose(fp);
|
||||
|
||||
/* read saved image */
|
||||
fp = fopen(filename, "rb");
|
||||
gdTestAssert(fp != NULL);
|
||||
im_saved = gdImageCreateFromBmp(fp);
|
||||
gdTestAssert(im_saved != NULL);
|
||||
fclose(fp);
|
||||
|
||||
gdAssertImageEquals(im_orig, im_saved);
|
||||
|
||||
/* clean up */
|
||||
gdImageDestroy(im_orig);
|
||||
gdImageDestroy(im_saved);
|
||||
free(filename);
|
||||
|
||||
return gdNumFailures();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user