Description: Fix unit test PngWriter.Color16Pattern on big-endian architectures
Author: Sebastien Jodogne <s.jodogne@orthanc-labs.com>
Forwarded: yes
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
Index: Orthanc-1.12.1/OrthancFramework/UnitTestsSources/ImageTests.cpp
===================================================================
--- Orthanc-1.12.1.orig/OrthancFramework/UnitTestsSources/ImageTests.cpp
+++ Orthanc-1.12.1/OrthancFramework/UnitTestsSources/ImageTests.cpp
@@ -33,10 +33,11 @@
 #include "../Sources/Images/ImageProcessing.h"
 #include "../Sources/Images/JpegReader.h"
 #include "../Sources/Images/JpegWriter.h"
-#include "../Sources/Images/PngReader.h"
-#include "../Sources/Images/PngWriter.h"
 #include "../Sources/Images/PamReader.h"
 #include "../Sources/Images/PamWriter.h"
+#include "../Sources/Images/PngReader.h"
+#include "../Sources/Images/PngWriter.h"
+#include "../Sources/OrthancException.h"
 #include "../Sources/Toolbox.h"
 
 #if ORTHANC_SANDBOXED != 1
@@ -96,14 +97,33 @@ TEST(PngWriter, Color16Pattern)
     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);
+      }
     }
   }
 
