From 7c1bdba8ae1c60ed42aa4d3d32732f3eb836dee6 Mon Sep 17 00:00:00 2001 From: gitlost Date: Fri, 19 Jan 2024 09:28:03 +0000 Subject: [PATCH] output: use doubles when converting in `out_colour_get_rgb()` and `out_colour_get_cmyk()`, to lessen chances of rounding errors (in particular for VC6) test_large: fix regression in change to test for formatting `uint64_t` for `printf()` win32/README: update MinGW/MSYS Qt version --- README.macos | 4 ++-- backend/filemem.c | 4 ++-- backend/filemem.h | 4 ++-- backend/output.c | 14 +++++++------- backend/tests/test_large.c | 5 +++-- backend_qt/qzint.cpp | 2 +- frontend_qt/mainwindow.cpp | 20 ++++++++++---------- win32/README | 12 ++++++------ 8 files changed, 33 insertions(+), 32 deletions(-) diff --git a/README.macos b/README.macos index cc9364d3..d1cfb00e 100644 --- a/README.macos +++ b/README.macos @@ -1,5 +1,5 @@ -% README.macos 2014-01-17 -% Tested on macOS 12.4 Monterey VirtualBox (thanks to https://github.com/myspaghetti/macos-virtualbox) +% README.macos 2014-01-18 +% Tested on macOS 12.7.2 Monterey VirtualBox (thanks to https://github.com/myspaghetti/macos-virtualbox) 1. Prerequisites for building zint and zint-qt ============================================== diff --git a/backend/filemem.c b/backend/filemem.c index 6fad2bf3..0ea982f1 100644 --- a/backend/filemem.c +++ b/backend/filemem.c @@ -1,7 +1,7 @@ /* filemem.c - write to file/memory abstraction */ /* libzint - the open source barcode library - Copyright (C) 2023 Robin Stuart + Copyright (C) 2023-2024 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -287,7 +287,7 @@ static int fm_vprintf(struct filemem *restrict const fmp, const char *fmt, va_li return 1; } -/* `fprintf()` to memory or file, returning 1 on success, 0 on failure */ +/* `fprintf()` to file or memory, returning 1 on success, 0 on failure */ INTERNAL int fm_printf(struct filemem *restrict const fmp, const char *fmt, ...) { va_list ap; int ret; diff --git a/backend/filemem.h b/backend/filemem.h index 74704ecd..f63198cd 100644 --- a/backend/filemem.h +++ b/backend/filemem.h @@ -1,7 +1,7 @@ /* filemem.h - write to file/memory abstraction */ /* libzint - the open source barcode library - Copyright (C) 2023 Robin Stuart + Copyright (C) 2023-2024 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -67,7 +67,7 @@ INTERNAL int fm_putc(const int ch, struct filemem *restrict const fmp); /* `fputs()` to file or memory, returning 1 on success, 0 on failure */ INTERNAL int fm_puts(const char *str, struct filemem *restrict const fmp); -/* `fprintf()` to memory or file, returning 1 on success, 0 on failure */ +/* `fprintf()` to file or memory, returning 1 on success, 0 on failure */ INTERNAL int fm_printf(struct filemem *restrict const fmp, const char *format, ...); /* Output float without trailing zeroes to `fmp` with decimal pts `dp` (precision), returning 1 on success, 0 on diff --git a/backend/output.c b/backend/output.c index d30749ae..d9c3415d 100644 --- a/backend/output.c +++ b/backend/output.c @@ -129,13 +129,13 @@ INTERNAL int out_colour_get_rgb(const char *colour, unsigned char *red, unsigned black = 100 - to_int((const unsigned char *) (comma3 + 1), (int) strlen(comma3 + 1)); val = 100 - to_int((const unsigned char *) colour, (int) (comma1 - colour)); /* Cyan */ - *red = (int) roundf((0xFF * val * black) / 10000.0f); + *red = (int) round((0xFF * val * black) / 10000.0); val = 100 - to_int((const unsigned char *) (comma1 + 1), (int) (comma2 - (comma1 + 1))); /* Magenta */ - *green = (int) roundf((0xFF * val * black) / 10000.0f); + *green = (int) round((0xFF * val * black) / 10000.0); val = 100 - to_int((const unsigned char *) (comma2 + 1), (int) (comma3 - (comma2 + 1))); /* Yellow */ - *blue = (int) roundf((0xFF * val * black) / 10000.0f); + *blue = (int) round((0xFF * val * black) / 10000.0); if (alpha) { *alpha = 0xFF; @@ -176,10 +176,10 @@ INTERNAL int out_colour_get_cmyk(const char *colour, int *cyan, int *magenta, in *cyan = *magenta = *yellow = 0; *black = 100; } else { - *cyan = (int) roundf((k - red) * 100.0f / k); - *magenta = (int) roundf((k - green) * 100.0f / k); - *yellow = (int) roundf((k - blue) * 100.0f / k); - *black = (int) roundf(((0xFF - k) * 100.0f) / 0xFF); + *cyan = (int) round((k - red) * 100.0 / k); + *magenta = (int) round((k - green) * 100.0 / k); + *yellow = (int) round((k - blue) * 100.0 / k); + *black = (int) round(((0xFF - k) * 100.0) / 0xFF); } if (rgb_alpha) { diff --git a/backend/tests/test_large.c b/backend/tests/test_large.c index 4bba4f3f..29903045 100644 --- a/backend/tests/test_large.c +++ b/backend/tests/test_large.c @@ -43,9 +43,10 @@ # if defined(__clang__) # pragma GCC diagnostic ignored "-Wformat-non-iso" # elif defined(__GNUC__) -# pragma GCC diagnostic ignored "-Wformat" /* Unfortunately doesn't seem to be way to only avoid non-ISO warnings */ +# pragma GCC diagnostic ignored "-Wformat" /* Doesn't seem to be way to only avoid non-ISO warnings */ # endif -#elif (defined(__WORDSIZE) && __WORDSIZE == 32) || (defined(ULONG_MAX) && ULONG_MAX <= 0xFFFFFFFF) +#elif (defined(__WORDSIZE) && __WORDSIZE == 32) || (defined(ULONG_MAX) && ULONG_MAX <= 0xFFFFFFFF) \ + || defined(__APPLE__) || defined(__OpenBSD__) # define LX_FMT "ll" #else # define LX_FMT "l" diff --git a/backend_qt/qzint.cpp b/backend_qt/qzint.cpp index 1ab0682c..4e961bf8 100644 --- a/backend_qt/qzint.cpp +++ b/backend_qt/qzint.cpp @@ -46,7 +46,7 @@ namespace Zint { /* Matches RGB(A) hex string or CMYK decimal "C,M,Y,K" percentage string */ static const QString colorREstr( QSL("^([0-9A-Fa-f]{6}([0-9A-Fa-f]{2})?)|(((100|[0-9]{0,2}),){3}(100|[0-9]{0,2}))$")); - Q_GLOBAL_STATIC_WITH_ARGS(QRegularExpression, colorRE, (colorREstr)); + Q_GLOBAL_STATIC_WITH_ARGS(QRegularExpression, colorRE, (colorREstr)) static const QString normalFontFamily = QSL("Arimo"); /* Sans-serif metrically compatible with Arial */ static const QString upceanFontFamily = QSL("OCRB"); /* Monospace OCR-B */ diff --git a/frontend_qt/mainwindow.cpp b/frontend_qt/mainwindow.cpp index 04b50993..b6aa4773 100644 --- a/frontend_qt/mainwindow.cpp +++ b/frontend_qt/mainwindow.cpp @@ -51,22 +51,22 @@ static const int tempMessageTimeout = 2000; // Use on Windows also (i.e. not using QKeySequence::Quit) -Q_GLOBAL_STATIC_WITH_ARGS(QKeySequence, quitKeySeq, (Qt::CTRL | Qt::Key_Q)); +Q_GLOBAL_STATIC_WITH_ARGS(QKeySequence, quitKeySeq, (Qt::CTRL | Qt::Key_Q)) -Q_GLOBAL_STATIC_WITH_ARGS(QKeySequence, openCLISeq, (Qt::SHIFT | Qt::CTRL | Qt::Key_C)); +Q_GLOBAL_STATIC_WITH_ARGS(QKeySequence, openCLISeq, (Qt::SHIFT | Qt::CTRL | Qt::Key_C)) -Q_GLOBAL_STATIC_WITH_ARGS(QKeySequence, copyBMPSeq, (Qt::SHIFT | Qt::CTRL | Qt::Key_B)); -Q_GLOBAL_STATIC_WITH_ARGS(QKeySequence, copyEMFSeq, (Qt::SHIFT | Qt::CTRL | Qt::Key_E)); -Q_GLOBAL_STATIC_WITH_ARGS(QKeySequence, copyGIFSeq, (Qt::SHIFT | Qt::CTRL | Qt::Key_G)); -Q_GLOBAL_STATIC_WITH_ARGS(QKeySequence, copyPNGSeq, (Qt::SHIFT | Qt::CTRL | Qt::Key_P)); -Q_GLOBAL_STATIC_WITH_ARGS(QKeySequence, copySVGSeq, (Qt::SHIFT | Qt::CTRL | Qt::Key_S)); -Q_GLOBAL_STATIC_WITH_ARGS(QKeySequence, copyTIFSeq, (Qt::SHIFT | Qt::CTRL | Qt::Key_T)); +Q_GLOBAL_STATIC_WITH_ARGS(QKeySequence, copyBMPSeq, (Qt::SHIFT | Qt::CTRL | Qt::Key_B)) +Q_GLOBAL_STATIC_WITH_ARGS(QKeySequence, copyEMFSeq, (Qt::SHIFT | Qt::CTRL | Qt::Key_E)) +Q_GLOBAL_STATIC_WITH_ARGS(QKeySequence, copyGIFSeq, (Qt::SHIFT | Qt::CTRL | Qt::Key_G)) +Q_GLOBAL_STATIC_WITH_ARGS(QKeySequence, copyPNGSeq, (Qt::SHIFT | Qt::CTRL | Qt::Key_P)) +Q_GLOBAL_STATIC_WITH_ARGS(QKeySequence, copySVGSeq, (Qt::SHIFT | Qt::CTRL | Qt::Key_S)) +Q_GLOBAL_STATIC_WITH_ARGS(QKeySequence, copyTIFSeq, (Qt::SHIFT | Qt::CTRL | Qt::Key_T)) -Q_GLOBAL_STATIC_WITH_ARGS(QKeySequence, factoryResetSeq, (Qt::SHIFT | Qt::CTRL | Qt::Key_R)); +Q_GLOBAL_STATIC_WITH_ARGS(QKeySequence, factoryResetSeq, (Qt::SHIFT | Qt::CTRL | Qt::Key_R)) // RGB hexadecimal 6 or 8 in length or CMYK comma-separated decimal percentages "C,M,Y,K" static const QString colorREstr(QSL("^([0-9A-Fa-f]{6}([0-9A-Fa-f]{2})?)|(((100|[0-9]{0,2}),){3}(100|[0-9]{0,2}))$")); -Q_GLOBAL_STATIC_WITH_ARGS(QRegularExpression, colorRE, (colorREstr)); +Q_GLOBAL_STATIC_WITH_ARGS(QRegularExpression, colorRE, (colorREstr)) static const QString fgDefault(QSL("000000")); static const QString bgDefault(QSL("FFFFFF")); diff --git a/win32/README b/win32/README index 46145ec1..b1fb0dea 100644 --- a/win32/README +++ b/win32/README @@ -1,4 +1,4 @@ -% win32/README 2024-01-17 +% win32/README 2024-01-18 Visual Studio 2022 ------------------ @@ -179,12 +179,12 @@ using it install the packages: (This should include mingw32-libz-dll) -Any reasonably modern version of Qt can be used. The following uses Qt 5.14.2. +Any reasonably modern version of Qt can be used. The following uses Qt 5.15.2. Using the Qt Maintenance Tool (see the Visual Studio 2022 instructions above) -install the "MinGW 7.3.0 32-bit" component. +install the "MinGW 8.1.0 32-bit" component. (Note the Qt MinGW versions actually refer to Mingw-w64, the 64-bit fork of -MinGW, but versions up to 8.1 seem to be compatible.) +MinGW, but versions up to 8.1.0 at least are compatible.) Open a MinGW/MSYS shell by clicking/running e.g. (your path may differ) @@ -192,10 +192,10 @@ Open a MinGW/MSYS shell by clicking/running e.g. (your path may differ) As above make sure git and cmake are in your PATH. -Add the Qt MinGW 7.3.0 32-bit component to your PATH, e.g. (your path may +Add the Qt MinGW 8.1.0 32-bit component to your PATH, e.g. (your path may differ): - export PATH="/c/Qt/5.14.2/mingw73_32/bin":${PATH} + export PATH="/c/Qt/5.15.2/mingw81_32/bin":${PATH} Go into the directory you want to use and clone zint and libpng: