# HG changeset patch # User Sebastien Jodogne # Date 1691839037 -7200 # Node ID 91b3154bd4e16db19e2af5a7c03a223c916cdf2a # Parent 0558bdff57ce4c36e706121e5795f04f16a75bf7 Fix unit test PngWriter.Color16Pattern on big-endian architectures diff -r 0558bdff57ce -r 91b3154bd4e1 NEWS --- a/NEWS Mon Jul 24 14:55:14 2023 +0200 +++ b/NEWS Sat Aug 12 13:17:17 2023 +0200 @@ -4,6 +4,8 @@ Maintenance ----------- +* Fix unit test PngWriter.Color16Pattern on big-endian architectures, + as suggested by Etienne Mollier: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1041813 * Prevent the leak of the full path of the source files in the binaries REST API diff -r 0558bdff57ce -r 91b3154bd4e1 OrthancFramework/UnitTestsSources/ImageTests.cpp --- a/OrthancFramework/UnitTestsSources/ImageTests.cpp Mon Jul 24 14:55:14 2023 +0200 +++ b/OrthancFramework/UnitTestsSources/ImageTests.cpp Sat Aug 12 13:17:17 2023 +0200 @@ -33,10 +33,11 @@ #include "../Sources/Images/ImageProcessing.h" #include "../Sources/Images/JpegReader.h" #include "../Sources/Images/JpegWriter.h" +#include "../Sources/Images/PamReader.h" +#include "../Sources/Images/PamWriter.h" #include "../Sources/Images/PngReader.h" #include "../Sources/Images/PngWriter.h" -#include "../Sources/Images/PamReader.h" -#include "../Sources/Images/PamWriter.h" +#include "../Sources/OrthancException.h" #include "../Sources/Toolbox.h" #if ORTHANC_SANDBOXED != 1 @@ -96,14 +97,33 @@ uint8_t *p = &image[0] + y * pitch; for (unsigned int x = 0; x < width; x++, p += 8) { - p[0] = (y % 8 == 0) ? 255 : 0; - p[1] = (y % 8 == 1) ? 255 : 0; - p[2] = (y % 8 == 2) ? 255 : 0; - p[3] = (y % 8 == 3) ? 255 : 0; - p[4] = (y % 8 == 4) ? 255 : 0; - p[5] = (y % 8 == 5) ? 255 : 0; - p[6] = (y % 8 == 6) ? 255 : 0; - p[7] = (y % 8 == 7) ? 255 : 0; + switch (Orthanc::Toolbox::DetectEndianness()) + { + case Orthanc::Endianness_Little: + p[0] = (y % 8 == 0) ? 255 : 0; + p[1] = (y % 8 == 1) ? 255 : 0; + p[2] = (y % 8 == 2) ? 255 : 0; + p[3] = (y % 8 == 3) ? 255 : 0; + p[4] = (y % 8 == 4) ? 255 : 0; + p[5] = (y % 8 == 5) ? 255 : 0; + p[6] = (y % 8 == 6) ? 255 : 0; + p[7] = (y % 8 == 7) ? 255 : 0; + break; + + case Orthanc::Endianness_Big: + p[0] = (y % 8 == 1) ? 255 : 0; + p[1] = (y % 8 == 0) ? 255 : 0; + p[2] = (y % 8 == 3) ? 255 : 0; + p[3] = (y % 8 == 2) ? 255 : 0; + p[4] = (y % 8 == 5) ? 255 : 0; + p[5] = (y % 8 == 4) ? 255 : 0; + p[6] = (y % 8 == 7) ? 255 : 0; + p[7] = (y % 8 == 6) ? 255 : 0; + break; + + default: + throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); + } } }