png.c: fix 4-bit odd bitmap width bug introduced by [ed3cc5] (MR #111)

This commit is contained in:
gitlost 2021-03-05 17:27:11 +00:00
parent 045c0bae56
commit 6b7b5109b9
3 changed files with 6 additions and 6 deletions

View File

@ -106,6 +106,7 @@ INTERNAL int png_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
int num_trans = 0; int num_trans = 0;
int bit_depth; int bit_depth;
int compression_strategy; int compression_strategy;
unsigned char *pb;
#ifndef _MSC_VER #ifndef _MSC_VER
unsigned char outdata[symbol->bitmap_width]; 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); png_write_info(png_ptr, info_ptr);
/* Pixel Plotting */ /* Pixel Plotting */
pb = pixelbuf;
if (bit_depth == 1) { if (bit_depth == 1) {
for (row = 0; row < symbol->bitmap_height; row++) { for (row = 0; row < symbol->bitmap_height; row++) {
unsigned char *pb = pixelbuf + symbol->bitmap_width * row;
unsigned char *image_data = outdata; unsigned char *image_data = outdata;
for (column = 0; column < symbol->bitmap_width; column += 8, image_data++) { for (column = 0; column < symbol->bitmap_width; column += 8, image_data++) {
unsigned char byte = 0; 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) { } else if (bit_depth == 4) {
for (row = 0; row < symbol->bitmap_height; row++) { for (row = 0; row < symbol->bitmap_height; row++) {
unsigned char *pb = pixelbuf + symbol->bitmap_width * row;
unsigned char *image_data = outdata; unsigned char *image_data = outdata;
for (column = 0; column < symbol->bitmap_width; column += 2, image_data++) { for (column = 0; column < symbol->bitmap_width; column += 2, image_data++) {
unsigned char byte = 0; unsigned char byte = map[*pb++] << 4;
for (i = 0; i < 2 && column + i < symbol->bitmap_width; i++, pb++) { if (column + 1 < symbol->bitmap_width) {
byte |= map[*pb] << (i * 4); byte |= map[*pb++];
} }
*image_data = byte; *image_data = byte;
} }
@ -308,7 +308,6 @@ INTERNAL int png_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
} }
} else { /* Bit depth 8 */ } else { /* Bit depth 8 */
for (row = 0; row < symbol->bitmap_height; row++) { for (row = 0; row < symbol->bitmap_height; row++) {
unsigned char *pb = pixelbuf + symbol->bitmap_width * row;
unsigned char *image_data = outdata; unsigned char *image_data = outdata;
for (column = 0; column < symbol->bitmap_width; column++, pb++, image_data++) { for (column = 0; column < symbol->bitmap_width; column++, pb++, image_data++) {
*image_data = map[*pb]; *image_data = map[*pb];

Binary file not shown.

After

Width:  |  Height:  |  Size: 184 B

View File

@ -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", "" }, /* 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", "" }, /* 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", "" }, /* 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); int data_size = ARRAY_SIZE(data);