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 00000000..ee26fda6 Binary files /dev/null and b/backend/tests/data/png/ultra_odd.png differ diff --git a/backend/tests/test_png.c b/backend/tests/test_png.c index 6fee4d0b..b194d9e4 100644 --- a/backend/tests/test_png.c +++ b/backend/tests/test_png.c @@ -169,6 +169,7 @@ static void test_print(int index, int generate, int debug) { /* 34*/ { BARCODE_ULTRA, -1, -1, 2, -1, -1, -1, 0, 0, "", "FF000033", "12345", "", "../data/png/ultra_bgalpha.png", "" }, /* 35*/ { BARCODE_ULTRA, -1, -1, 2, -1, -1, -1, 0, 0, "0000007F", "FF0000", "12345", "", "../data/png/ultra_fgalpha.png", "" }, /* 36*/ { BARCODE_ULTRA, -1, -1, -1, -1, -1, -1, 0, 0, "0000007F", "", "12345", "", "../data/png/ultra_fgalpha_nobg.png", "" }, + /* 37*/ { BARCODE_ULTRA, -1, -1, -1, -1, -1, -1, 0, 0.5f, "", "", "1", "", "../data/png/ultra_odd.png", "" }, }; int data_size = ARRAY_SIZE(data);