diff --git a/backend/png.c b/backend/png.c index 0552cfca..187459b9 100644 --- a/backend/png.c +++ b/backend/png.c @@ -2,7 +2,7 @@ /* libzint - the open source barcode library - Copyright (C) 2009-2017 Robin Stuart + Copyright (C) 2009-2021 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -37,8 +37,6 @@ #include #include #endif -#include -#include #include "common.h" #ifndef NO_PNG @@ -72,37 +70,47 @@ static void writepng_error_handler(png_structp png_ptr, png_const_charp msg) { longjmp(graphic->jmpbuf, 1); } +/* Guestimate best compression strategy */ +static int guess_compression_strategy(struct zint_symbol *symbol, unsigned char *pixelbuf) { + (void)pixelbuf; + + /* TODO: Do properly */ + + /* It seems the best choice for typical barcode pngs is one of Z_DEFAULT_STRATEGY and Z_FILTERED */ + + /* Some guesses */ + if (symbol->symbology == BARCODE_MAXICODE) { + return Z_DEFAULT_STRATEGY; + } + if (symbol->symbology == BARCODE_AZTEC && symbol->bitmap_width <= 30) { + return Z_DEFAULT_STRATEGY; + } + + /* Z_FILTERED seems to work better for slightly more barcodes+data so default to that */ + return Z_FILTERED; +} + INTERNAL int png_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) { struct mainprog_info_type wpng_info; struct mainprog_info_type *graphic; png_structp png_ptr; png_infop info_ptr; + int i; int row, column; - unsigned char fg[4], bg[4]; - unsigned char white[4] = { 0xff, 0xff, 0xff, 0xff }; - unsigned char cyan[4] = { 0, 0xff, 0xff, 0xff }; - unsigned char blue[4] = { 0, 0, 0xff, 0xff }; - unsigned char magenta[4] = { 0xff, 0, 0xff, 0xff }; - unsigned char red[4] = { 0xff, 0, 0, 0xff }; - unsigned char yellow[4] = { 0xff, 0xff, 0, 0xff }; - unsigned char green[4] = { 0, 0xff, 0, 0xff }; - unsigned char black[4] = { 0, 0, 0, 0xff }; - unsigned char *map[91] = { - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 0x00-0F */ - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 0x10-1F */ - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 0x20-2F */ - bg, fg, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 0-9 */ - NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* :;<=>?@ */ - NULL, blue, cyan, NULL, NULL, NULL, green, NULL, NULL, NULL, black, NULL, magenta, /* A-M */ - NULL, NULL, NULL, NULL, red, NULL, NULL, NULL, NULL, white, NULL, yellow, NULL /* N-Z */ - }; - int use_alpha, incr; - unsigned char *image_data; + png_color bg, fg; + unsigned char bg_alpha, fg_alpha; + unsigned char map[128]; + png_color palette[32]; + int num_palette = 0; + unsigned char trans_alpha[32]; + int num_trans = 0; + int bit_depth; + int compression_strategy; #ifndef _MSC_VER - unsigned char outdata[symbol->bitmap_width * 4]; + unsigned char outdata[symbol->bitmap_width]; #else - unsigned char* outdata = (unsigned char*) _alloca(symbol->bitmap_width * 4); + unsigned char* outdata = (unsigned char*) _alloca(symbol->bitmap_width); #endif graphic = &wpng_info; @@ -110,28 +118,101 @@ INTERNAL int png_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) graphic->width = symbol->bitmap_width; graphic->height = symbol->bitmap_height; - fg[0] = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]); - fg[1] = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]); - fg[2] = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]); - bg[0] = (16 * ctoi(symbol->bgcolour[0])) + ctoi(symbol->bgcolour[1]); - bg[1] = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]); - bg[2] = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]); + fg.red = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]); + fg.green = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]); + fg.blue = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]); + bg.red = (16 * ctoi(symbol->bgcolour[0])) + ctoi(symbol->bgcolour[1]); + bg.green = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]); + bg.blue = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]); - use_alpha = 0; - if (strlen(symbol->fgcolour) > 6) { - fg[3] = (16 * ctoi(symbol->fgcolour[6])) + ctoi(symbol->fgcolour[7]); - white[3] = cyan[3] = blue[3] = magenta[3] = red[3] = yellow[3] = green[3] = black[3] = fg[3]; - if (fg[3] != 0xff) use_alpha = 1; + fg_alpha = (16 * ctoi(symbol->fgcolour[6])) + ctoi(symbol->fgcolour[7]); } else { - fg[3] = 0xff; + fg_alpha = 0xff; } - + if (strlen(symbol->bgcolour) > 6) { - bg[3] = (16 * ctoi(symbol->bgcolour[6])) + ctoi(symbol->bgcolour[7]); - if (bg[3] != 0xff) use_alpha = 1; + bg_alpha = (16 * ctoi(symbol->bgcolour[6])) + ctoi(symbol->bgcolour[7]); } else { - bg[3] = 0xff; + bg_alpha = 0xff; + } + + if (symbol->symbology == BARCODE_ULTRA) { + static const int ultra_chars[8] = { 'W', 'C', 'B', 'M', 'R', 'Y', 'G', 'K' }; + static png_color ultra_colours[8] = { + { 0xff, 0xff, 0xff, }, /* White */ + { 0, 0xff, 0xff, }, /* Cyan */ + { 0, 0, 0xff, }, /* Blue */ + { 0xff, 0, 0xff, }, /* Magenta */ + { 0xff, 0, 0, }, /* Red */ + { 0xff, 0xff, 0, }, /* Yellow */ + { 0, 0xff, 0, }, /* Green */ + { 0, 0, 0, }, /* Black */ + }; + for (i = 0; i < 8; i++) { + map[ultra_chars[i]] = i; + palette[i] = ultra_colours[i]; + if (fg_alpha != 0xff) { + trans_alpha[i] = fg_alpha; + } + } + num_palette = 8; + if (fg_alpha != 0xff) { + num_trans = 8; + } + + /* For Ultracode, have background only if have whitespace/quiet zones */ + if (pixelbuf[0] == '0' || pixelbuf[symbol->bitmap_width - 1] == '0' + || pixelbuf[symbol->bitmap_height * (symbol->bitmap_width - 1)] == '0' + || pixelbuf[symbol->bitmap_height * symbol->bitmap_width - 1] == '0') { + /* Check whether can re-use white */ + if (bg.red == 0xff && bg.green == 0xff && bg.blue == 0xff && bg_alpha == fg_alpha) { + map['0'] = 0; /* Re-use white */ + } else { + if (bg_alpha == 0xff || fg_alpha != 0xff) { + /* No alpha or have foreground alpha - add to end */ + map['0'] = num_palette; + palette[num_palette++] = bg; + } else { + /* Alpha and no foreground alpha - add to front & move white to end */ + map['0'] = 0; + palette[0] = bg; + map['W'] = num_palette; + palette[num_palette++] = ultra_colours[0]; + } + if (bg_alpha != 0xff) { + trans_alpha[num_trans++] = bg_alpha; + } + } + } + } else { + int bg_idx = 0, fg_idx = 1; + /* Do alphas first so can swop indexes if background not alpha */ + if (bg_alpha != 0xff) { + trans_alpha[num_trans++] = bg_alpha; + } + if (fg_alpha != 0xff) { + trans_alpha[num_trans++] = fg_alpha; + if (num_trans == 1) { + /* Only foreground has alpha so swop indexes - saves a byte! */ + bg_idx = 1; + fg_idx = 0; + } + } + + map['0'] = bg_idx; + palette[bg_idx] = bg; + map['1'] = fg_idx; + palette[fg_idx] = fg; + num_palette = 2; + } + + if (num_palette <= 2) { + bit_depth = 1; + } else if (num_palette <= 16) { + bit_depth = 4; + } else { + bit_depth = 8; } /* Open output file in binary mode */ @@ -177,32 +258,64 @@ INTERNAL int png_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) /* set compression */ png_set_compression_level(png_ptr, 9); + /* Compression strategy can make a difference */ + compression_strategy = guess_compression_strategy(symbol, pixelbuf); + if (compression_strategy != Z_DEFAULT_STRATEGY) { + png_set_compression_strategy(png_ptr, compression_strategy); + } + /* set Header block */ - if (use_alpha) - png_set_IHDR(png_ptr, info_ptr, graphic->width, graphic->height, - 8, PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); - else - png_set_IHDR(png_ptr, info_ptr, graphic->width, graphic->height, - 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); + png_set_IHDR(png_ptr, info_ptr, graphic->width, graphic->height, + bit_depth, PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); + + png_set_PLTE(png_ptr, info_ptr, palette, num_palette); + if (num_trans) { + png_set_tRNS(png_ptr, info_ptr, trans_alpha, num_trans, NULL); + } + /* write all chunks up to (but not including) first IDAT */ png_write_info(png_ptr, info_ptr); - /* set up the transformations: for now, just pack low-bit-depth pixels - into bytes (one, two or four pixels per byte) */ - png_set_packing(png_ptr); - /* Pixel Plotting */ - incr = use_alpha ? 4 : 3; - for (row = 0; row < symbol->bitmap_height; row++) { - unsigned char *pb = pixelbuf + symbol->bitmap_width * row; - image_data = outdata; - for (column = 0; column < symbol->bitmap_width; column++, pb++, image_data += incr) { - memcpy(image_data, map[*pb], incr); + 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; + for (i = 0; i < 8 && column + i < symbol->bitmap_width; i++, pb++) { + byte |= map[*pb] << (7 - i); + } + *image_data = byte; + } + /* write row contents to file */ + png_write_row(png_ptr, outdata); + } + } 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); + } + *image_data = byte; + } + /* write row contents to file */ + png_write_row(png_ptr, outdata); + } + } 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]; + } + /* write row contents to file */ + png_write_row(png_ptr, outdata); } - /* write row contents to file */ - png_write_row(png_ptr, outdata); } /* End the file */ @@ -215,6 +328,7 @@ INTERNAL int png_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) } else { fclose(wpng_info.outfile); } + return 0; } #endif /* NO_PNG */ diff --git a/backend/tests/data/png/codablockf_3rows.png b/backend/tests/data/png/codablockf_3rows.png index 90ef5c07..dc71eb97 100644 Binary files a/backend/tests/data/png/codablockf_3rows.png and b/backend/tests/data/png/codablockf_3rows.png differ diff --git a/backend/tests/data/png/code128_egrave_bold.png b/backend/tests/data/png/code128_egrave_bold.png index dccdfb59..53fe08d4 100644 Binary files a/backend/tests/data/png/code128_egrave_bold.png and b/backend/tests/data/png/code128_egrave_bold.png differ diff --git a/backend/tests/data/png/code128_egrave_bold_box3.png b/backend/tests/data/png/code128_egrave_bold_box3.png index 6edfb65b..ac9fb05d 100644 Binary files a/backend/tests/data/png/code128_egrave_bold_box3.png and b/backend/tests/data/png/code128_egrave_bold_box3.png differ diff --git a/backend/tests/data/png/code39_small.png b/backend/tests/data/png/code39_small.png index 09985dc4..45d9813f 100644 Binary files a/backend/tests/data/png/code39_small.png and b/backend/tests/data/png/code39_small.png differ diff --git a/backend/tests/data/png/ean13_2addon_ggs_5.2.2.5.1-2.png b/backend/tests/data/png/ean13_2addon_ggs_5.2.2.5.1-2.png index b9493972..3d8a4377 100644 Binary files a/backend/tests/data/png/ean13_2addon_ggs_5.2.2.5.1-2.png and b/backend/tests/data/png/ean13_2addon_ggs_5.2.2.5.1-2.png differ diff --git a/backend/tests/data/png/ean13_5addon_ggs_5.2.2.5.2-2.png b/backend/tests/data/png/ean13_5addon_ggs_5.2.2.5.2-2.png index aebf10aa..878d837f 100644 Binary files a/backend/tests/data/png/ean13_5addon_ggs_5.2.2.5.2-2.png and b/backend/tests/data/png/ean13_5addon_ggs_5.2.2.5.2-2.png differ diff --git a/backend/tests/data/png/ean13_cc_2addon_cca_4x4.png b/backend/tests/data/png/ean13_cc_2addon_cca_4x4.png index 3fb571c0..fe5fd5f8 100644 Binary files a/backend/tests/data/png/ean13_cc_2addon_cca_4x4.png and b/backend/tests/data/png/ean13_cc_2addon_cca_4x4.png differ diff --git a/backend/tests/data/png/ean13_cc_5addon_ccb_3x4.png b/backend/tests/data/png/ean13_cc_5addon_ccb_3x4.png index 2bcf13cb..c2bf3d93 100644 Binary files a/backend/tests/data/png/ean13_cc_5addon_ccb_3x4.png and b/backend/tests/data/png/ean13_cc_5addon_ccb_3x4.png differ diff --git a/backend/tests/data/png/ean13_cc_5addon_ccb_3x4_notext.png b/backend/tests/data/png/ean13_cc_5addon_ccb_3x4_notext.png index 89fc6b00..cfef2791 100644 Binary files a/backend/tests/data/png/ean13_cc_5addon_ccb_3x4_notext.png and b/backend/tests/data/png/ean13_cc_5addon_ccb_3x4_notext.png differ diff --git a/backend/tests/data/png/ean2.png b/backend/tests/data/png/ean2.png index 2a2602a5..13e68630 100644 Binary files a/backend/tests/data/png/ean2.png and b/backend/tests/data/png/ean2.png differ diff --git a/backend/tests/data/png/ean5.png b/backend/tests/data/png/ean5.png index 3d6ef02a..529dcf58 100644 Binary files a/backend/tests/data/png/ean5.png and b/backend/tests/data/png/ean5.png differ diff --git a/backend/tests/data/png/ean8_2addon.png b/backend/tests/data/png/ean8_2addon.png index 18e27169..d1ac393e 100644 Binary files a/backend/tests/data/png/ean8_2addon.png and b/backend/tests/data/png/ean8_2addon.png differ diff --git a/backend/tests/data/png/ean8_5addon.png b/backend/tests/data/png/ean8_5addon.png index 691bc26d..5683d544 100644 Binary files a/backend/tests/data/png/ean8_5addon.png and b/backend/tests/data/png/ean8_5addon.png differ diff --git a/backend/tests/data/png/ean8_cc_2addon_cca_4x3.png b/backend/tests/data/png/ean8_cc_2addon_cca_4x3.png index 8f524706..044be6db 100644 Binary files a/backend/tests/data/png/ean8_cc_2addon_cca_4x3.png and b/backend/tests/data/png/ean8_cc_2addon_cca_4x3.png differ diff --git a/backend/tests/data/png/ean8_cc_5addon_ccb_8x3.png b/backend/tests/data/png/ean8_cc_5addon_ccb_8x3.png index 572f914e..13e530c8 100644 Binary files a/backend/tests/data/png/ean8_cc_5addon_ccb_8x3.png and b/backend/tests/data/png/ean8_cc_5addon_ccb_8x3.png differ diff --git a/backend/tests/data/png/gs1_128_cc_fig12.png b/backend/tests/data/png/gs1_128_cc_fig12.png index 38a44e0f..222284f5 100644 Binary files a/backend/tests/data/png/gs1_128_cc_fig12.png and b/backend/tests/data/png/gs1_128_cc_fig12.png differ diff --git a/backend/tests/data/png/pdf417_bgalpha.png b/backend/tests/data/png/pdf417_bgalpha.png index 190cee95..4034731e 100644 Binary files a/backend/tests/data/png/pdf417_bgalpha.png and b/backend/tests/data/png/pdf417_bgalpha.png differ diff --git a/backend/tests/data/png/pdf417_bgfgalpha.png b/backend/tests/data/png/pdf417_bgfgalpha.png new file mode 100644 index 00000000..08d39756 Binary files /dev/null and b/backend/tests/data/png/pdf417_bgfgalpha.png differ diff --git a/backend/tests/data/png/pdf417_fgalpha.png b/backend/tests/data/png/pdf417_fgalpha.png index aa1ebed1..c2710c68 100644 Binary files a/backend/tests/data/png/pdf417_fgalpha.png and b/backend/tests/data/png/pdf417_fgalpha.png differ diff --git a/backend/tests/data/png/postnet_zip.png b/backend/tests/data/png/postnet_zip.png index 90e72123..4c165bc8 100644 Binary files a/backend/tests/data/png/postnet_zip.png and b/backend/tests/data/png/postnet_zip.png differ diff --git a/backend/tests/data/png/ultra_alpha.png b/backend/tests/data/png/ultra_alpha.png deleted file mode 100644 index 8fbefaf2..00000000 Binary files a/backend/tests/data/png/ultra_alpha.png and /dev/null differ diff --git a/backend/tests/data/png/ultra_bgalpha.png b/backend/tests/data/png/ultra_bgalpha.png new file mode 100644 index 00000000..ffa7bbb0 Binary files /dev/null and b/backend/tests/data/png/ultra_bgalpha.png differ diff --git a/backend/tests/data/png/ultra_bgfgalpha.png b/backend/tests/data/png/ultra_bgfgalpha.png new file mode 100644 index 00000000..5d4600ad Binary files /dev/null and b/backend/tests/data/png/ultra_bgfgalpha.png differ diff --git a/backend/tests/data/png/ultra_fgalpha.png b/backend/tests/data/png/ultra_fgalpha.png new file mode 100644 index 00000000..37bcf227 Binary files /dev/null and b/backend/tests/data/png/ultra_fgalpha.png differ diff --git a/backend/tests/data/png/ultra_fgalpha_nobg.png b/backend/tests/data/png/ultra_fgalpha_nobg.png new file mode 100644 index 00000000..00074fa3 Binary files /dev/null and b/backend/tests/data/png/ultra_fgalpha_nobg.png differ diff --git a/backend/tests/data/png/upca_2addon_ggs_5.2.6.6-5.png b/backend/tests/data/png/upca_2addon_ggs_5.2.6.6-5.png index 6a2373c9..6d4637ac 100644 Binary files a/backend/tests/data/png/upca_2addon_ggs_5.2.6.6-5.png and b/backend/tests/data/png/upca_2addon_ggs_5.2.6.6-5.png differ diff --git a/backend/tests/data/png/upca_5addon.png b/backend/tests/data/png/upca_5addon.png index 391aee92..4727c528 100644 Binary files a/backend/tests/data/png/upca_5addon.png and b/backend/tests/data/png/upca_5addon.png differ diff --git a/backend/tests/data/png/upca_5addon_bind3.png b/backend/tests/data/png/upca_5addon_bind3.png index 11da1cf6..b6b976ff 100644 Binary files a/backend/tests/data/png/upca_5addon_bind3.png and b/backend/tests/data/png/upca_5addon_bind3.png differ diff --git a/backend/tests/data/png/upca_5addon_notext.png b/backend/tests/data/png/upca_5addon_notext.png index faf3b144..12967b5c 100644 Binary files a/backend/tests/data/png/upca_5addon_notext.png and b/backend/tests/data/png/upca_5addon_notext.png differ diff --git a/backend/tests/data/png/upca_cc_2addon_cca_3x4.png b/backend/tests/data/png/upca_cc_2addon_cca_3x4.png index 262ec095..beeb27ad 100644 Binary files a/backend/tests/data/png/upca_cc_2addon_cca_3x4.png and b/backend/tests/data/png/upca_cc_2addon_cca_3x4.png differ diff --git a/backend/tests/data/png/upca_cc_5addon_ccb_4x4.png b/backend/tests/data/png/upca_cc_5addon_ccb_4x4.png index cb914998..d7d4b432 100644 Binary files a/backend/tests/data/png/upca_cc_5addon_ccb_4x4.png and b/backend/tests/data/png/upca_cc_5addon_ccb_4x4.png differ diff --git a/backend/tests/data/png/upca_cc_5addon_ccb_4x4_bind3.png b/backend/tests/data/png/upca_cc_5addon_ccb_4x4_bind3.png index 6783d167..83a4ed63 100644 Binary files a/backend/tests/data/png/upca_cc_5addon_ccb_4x4_bind3.png and b/backend/tests/data/png/upca_cc_5addon_ccb_4x4_bind3.png differ diff --git a/backend/tests/data/png/upca_cc_5addon_ccb_4x4_notext.png b/backend/tests/data/png/upca_cc_5addon_ccb_4x4_notext.png index d098f7db..ae985ae9 100644 Binary files a/backend/tests/data/png/upca_cc_5addon_ccb_4x4_notext.png and b/backend/tests/data/png/upca_cc_5addon_ccb_4x4_notext.png differ diff --git a/backend/tests/data/png/upce_2addon.png b/backend/tests/data/png/upce_2addon.png index 0dba7cb9..58679682 100644 Binary files a/backend/tests/data/png/upce_2addon.png and b/backend/tests/data/png/upce_2addon.png differ diff --git a/backend/tests/data/png/upce_5addon.png b/backend/tests/data/png/upce_5addon.png index 9ecbcebf..a136d3d7 100644 Binary files a/backend/tests/data/png/upce_5addon.png and b/backend/tests/data/png/upce_5addon.png differ diff --git a/backend/tests/data/png/upce_cc_2addon_cca_5x2.png b/backend/tests/data/png/upce_cc_2addon_cca_5x2.png index 5508fbed..4b97eef6 100644 Binary files a/backend/tests/data/png/upce_cc_2addon_cca_5x2.png and b/backend/tests/data/png/upce_cc_2addon_cca_5x2.png differ diff --git a/backend/tests/data/png/upce_cc_5addon_ccb_8x2.png b/backend/tests/data/png/upce_cc_5addon_ccb_8x2.png index b93ef461..afd8ba5c 100644 Binary files a/backend/tests/data/png/upce_cc_5addon_ccb_8x2.png and b/backend/tests/data/png/upce_cc_5addon_ccb_8x2.png differ diff --git a/backend/tests/data/png/upce_cc_5addon_ccb_8x2_notext.png b/backend/tests/data/png/upce_cc_5addon_ccb_8x2_notext.png index 8874016f..1fec2e4b 100644 Binary files a/backend/tests/data/png/upce_cc_5addon_ccb_8x2_notext.png and b/backend/tests/data/png/upce_cc_5addon_ccb_8x2_notext.png differ diff --git a/backend/tests/data/print/png/code128_aim.png b/backend/tests/data/print/png/code128_aim.png index e961266d..252dcade 100644 Binary files a/backend/tests/data/print/png/code128_aim.png and b/backend/tests/data/print/png/code128_aim.png differ diff --git a/backend/tests/data/print/png/dotcode_aim_fig7.png b/backend/tests/data/print/png/dotcode_aim_fig7.png index d3053123..3ef99708 100644 Binary files a/backend/tests/data/print/png/dotcode_aim_fig7.png and b/backend/tests/data/print/png/dotcode_aim_fig7.png differ diff --git a/backend/tests/data/print/png/maxicode_fig_2.png b/backend/tests/data/print/png/maxicode_fig_2.png index 2366bcdd..8f862199 100644 Binary files a/backend/tests/data/print/png/maxicode_fig_2.png and b/backend/tests/data/print/png/maxicode_fig_2.png differ diff --git a/backend/tests/data/print/png/qr_v1_m.png b/backend/tests/data/print/png/qr_v1_m.png index aa017053..ba94a126 100644 Binary files a/backend/tests/data/print/png/qr_v1_m.png and b/backend/tests/data/print/png/qr_v1_m.png differ diff --git a/backend/tests/data/print/png/ultracode_a.png b/backend/tests/data/print/png/ultracode_a.png index f32580c3..6345d369 100644 Binary files a/backend/tests/data/print/png/ultracode_a.png and b/backend/tests/data/print/png/ultracode_a.png differ diff --git a/backend/tests/test_png.c b/backend/tests/test_png.c index 66ee1570..6fee4d0b 100644 --- a/backend/tests/test_png.c +++ b/backend/tests/test_png.c @@ -1,6 +1,6 @@ /* libzint - the open source barcode library - Copyright (C) 2020 Robin Stuart + Copyright (C) 2020 - 2021 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -164,7 +164,11 @@ static void test_print(int index, int generate, int debug) { /* 29*/ { BARCODE_POSTNET, -1, -1, -1, -1, -1, -1, 0, 3.5, "", "", "12345", "", "../data/png/postnet_zip.png", "300 dpi, using 1/43in X, 300 / 43 / 2 = ~3.5 scale" }, /* 30*/ { BARCODE_PDF417, -1, -1, -1, -1, -1, -1, 0, 0, "", "CFCECDCC", "12345", "", "../data/png/pdf417_bgalpha.png", "" }, /* 31*/ { BARCODE_PDF417, -1, -1, -1, -1, -1, -1, 0, 0, "30313233", "", "12345", "", "../data/png/pdf417_fgalpha.png", "" }, - /* 32*/ { BARCODE_ULTRA, -1, -1, 2, -1, -1, -1, 0, 0, "0000007F", "FF000033", "12345", "", "../data/png/ultra_alpha.png", "" }, + /* 32*/ { BARCODE_PDF417, -1, -1, -1, -1, -1, -1, 0, 0, "20212244", "CFCECDCC", "12345", "", "../data/png/pdf417_bgfgalpha.png", "" }, + /* 33*/ { BARCODE_ULTRA, -1, -1, 2, -1, -1, -1, 0, 0, "0000007F", "FF000033", "12345", "", "../data/png/ultra_bgfgalpha.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", "" }, + /* 36*/ { BARCODE_ULTRA, -1, -1, -1, -1, -1, -1, 0, 0, "0000007F", "", "12345", "", "../data/png/ultra_fgalpha_nobg.png", "" }, }; int data_size = ARRAY_SIZE(data); @@ -242,6 +246,8 @@ static void test_print(int index, int generate, int debug) { ret = testUtilCmpPngs(symbol->outfile, data[i].expected_file); assert_zero(ret, "i:%d %s testUtilCmpPngs(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, data[i].expected_file, ret); + ret = testUtilCmpBins(symbol->outfile, data[i].expected_file); + assert_zero(ret, "i:%d %s testUtilCmpBins(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, data[i].expected_file, ret); assert_zero(remove(symbol->outfile), "i:%d remove(%s) != 0\n", i, symbol->outfile); } diff --git a/backend/tests/test_print.c b/backend/tests/test_print.c index c0d269d9..ca20bc18 100644 --- a/backend/tests/test_print.c +++ b/backend/tests/test_print.c @@ -166,6 +166,8 @@ static void test_print(int index, int generate, int debug) { } else if (strcmp(exts[j], "png") == 0) { ret = testUtilCmpPngs(symbol->outfile, expected_file); assert_zero(ret, "i:%d %s testUtilCmpPngs(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret); + ret = testUtilCmpBins(symbol->outfile, expected_file); + assert_zero(ret, "i:%d %s testUtilCmpBins(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret); } else if (strcmp(exts[j], "svg") == 0) { ret = testUtilCmpSvgs(symbol->outfile, expected_file); assert_zero(ret, "i:%d %s testUtilCmpSvgs(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret);