From 6b7b5109b919a13d3de633e42c8498cf6752526b Mon Sep 17 00:00:00 2001 From: gitlost Date: Fri, 5 Mar 2021 17:27:11 +0000 Subject: [PATCH] png.c: fix 4-bit odd bitmap width bug introduced by [ed3cc5] (MR #111) --- backend/png.c | 11 +++++------ backend/tests/data/png/ultra_odd.png | Bin 0 -> 184 bytes backend/tests/test_png.c | 1 + 3 files changed, 6 insertions(+), 6 deletions(-) create mode 100644 backend/tests/data/png/ultra_odd.png diff --git a/backend/png.c b/backend/png.c index 187459b9..b8f472ac 100644 --- a/backend/png.c +++ b/backend/png.c @@ -106,6 +106,7 @@ INTERNAL int png_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) int num_trans = 0; int bit_depth; int compression_strategy; + unsigned char *pb; #ifndef _MSC_VER unsigned char outdata[symbol->bitmap_width]; @@ -278,9 +279,9 @@ INTERNAL int png_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) png_write_info(png_ptr, info_ptr); /* Pixel Plotting */ + pb = pixelbuf; if (bit_depth == 1) { for (row = 0; row < symbol->bitmap_height; row++) { - unsigned char *pb = pixelbuf + symbol->bitmap_width * row; unsigned char *image_data = outdata; for (column = 0; column < symbol->bitmap_width; column += 8, image_data++) { unsigned char byte = 0; @@ -294,12 +295,11 @@ INTERNAL int png_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) } } else if (bit_depth == 4) { for (row = 0; row < symbol->bitmap_height; row++) { - unsigned char *pb = pixelbuf + symbol->bitmap_width * row; unsigned char *image_data = outdata; for (column = 0; column < symbol->bitmap_width; column += 2, image_data++) { - unsigned char byte = 0; - for (i = 0; i < 2 && column + i < symbol->bitmap_width; i++, pb++) { - byte |= map[*pb] << (i * 4); + unsigned char byte = map[*pb++] << 4; + if (column + 1 < symbol->bitmap_width) { + byte |= map[*pb++]; } *image_data = byte; } @@ -308,7 +308,6 @@ INTERNAL int png_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) } } else { /* Bit depth 8 */ for (row = 0; row < symbol->bitmap_height; row++) { - unsigned char *pb = pixelbuf + symbol->bitmap_width * row; unsigned char *image_data = outdata; for (column = 0; column < symbol->bitmap_width; column++, pb++, image_data++) { *image_data = map[*pb]; diff --git a/backend/tests/data/png/ultra_odd.png b/backend/tests/data/png/ultra_odd.png new file mode 100644 index 0000000000000000000000000000000000000000..ee26fda6f26a9e867025ef5faf6c06ea43e04e1b GIT binary patch literal 184 zcmeAS@N?(olHy`uVBq!ia0vp@Ak4xHBpZ(Y^aoNB0X`wF|NsAI03r~EQVc*I1H&w9 z)%idw+SA1`gyXvI8AGlH0|Ax;ya!`+7ge^ie3VtpcqOv@ZQ1Wy>F12ho|8Dfh3pkN zb#Z(9gW0d*IKQskA#8Javx!q$n%f87+%qjjccwXQXn&}^(0Hm5$FqvN>>vNjFIXw9 Tec