changeset 5368:91b3154bd4e1

Fix unit test PngWriter.Color16Pattern on big-endian architectures
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 12 Aug 2023 13:17:17 +0200
parents 0558bdff57ce
children 13494da9925d
files NEWS OrthancFramework/UnitTestsSources/ImageTests.cpp
diffstat 2 files changed, 32 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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);
+      }
     }
   }