From dfb9345b75a608d6a4c90cf821de827f31838351 Mon Sep 17 00:00:00 2001 From: gitlost Date: Fri, 28 May 2021 14:37:57 +0100 Subject: [PATCH] png: ULTRA: allow for fgcolour if bind/box, bug introduced by [ed3cc5] (MR #111) --- backend/library.c | 8 ++++---- backend/png.c | 18 ++++++++++++++--- .../data/png/ultra_fgalpha_hvwsp1_box1.png | Bin 0 -> 248 bytes backend/tests/test_png.c | 19 +++++++++--------- 4 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 backend/tests/data/png/ultra_fgalpha_hvwsp1_box1.png diff --git a/backend/library.c b/backend/library.c index 530222a5..395e6c3c 100644 --- a/backend/library.c +++ b/backend/library.c @@ -1083,11 +1083,11 @@ int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source, int if (symbol->debug & ZINT_DEBUG_PRINT) { printf("ZBarcode_Encode: symbology: %d, input_mode: 0x%X, ECI: %d, option_1: %d, option_2: %d," - " option_3: %d, scale: %g\n output_options: 0x%X, in_length: %d," - " First 10 source: \"%.10s\", First 10 primary: \"%.10s\"\n", + " option_3: %d, scale: %g\n output_options: 0x%X, fg: %s, bg: %s," + " in_length: %d, First 10 source: \"%.10s\", First 10 primary: \"%.10s\"\n", symbol->symbology, symbol->input_mode, symbol->eci, symbol->option_1, symbol->option_2, - symbol->option_3, symbol->scale, symbol->output_options, in_length, - source, symbol->primary); + symbol->option_3, symbol->scale, symbol->output_options, symbol->fgcolour, symbol->bgcolour, + in_length, source, symbol->primary); } warn_number = 0; diff --git a/backend/png.c b/backend/png.c index 0de9f20d..520ab2de 100644 --- a/backend/png.c +++ b/backend/png.c @@ -163,10 +163,22 @@ INTERNAL int png_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) num_trans = 8; } + /* For Ultracode, have foreground only if have bind/box */ + if (symbol->border_width > 0 && (symbol->output_options & (BARCODE_BIND | BARCODE_BOX))) { + /* Check whether can re-use black */ + if (fg.red == 0 && fg.green == 0 && fg.blue == 0) { + map['1'] = 7; /* Re-use black */ + } else { + map['1'] = num_palette; + palette[num_palette++] = fg; + if (fg_alpha != 0xff) { + trans_alpha[num_trans++] = fg_alpha; + } + } + } + /* 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') { + if (symbol->whitespace_width > 0 || symbol->whitespace_height > 0) { /* TODO: BARCODE_QUIET_ZONES also */ /* 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 */ diff --git a/backend/tests/data/png/ultra_fgalpha_hvwsp1_box1.png b/backend/tests/data/png/ultra_fgalpha_hvwsp1_box1.png new file mode 100644 index 0000000000000000000000000000000000000000..37f38e12d056791591423c32f4fa0b31aec60bbe GIT binary patch literal 248 zcmeAS@N?(olHy`uVBq!ia0vp^YCx>S!VDx2Hf`$$QgQ)4A+G=b|7QRq5Qb6=KpqhM zXV|rO+ozp#4+7boB|(0{^)Rr_