changeset 639:51892be15618

fix for big endian architectures
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 29 Oct 2013 15:56:29 +0000
parents 900274ed996f
children 9a85a2ac1005
files Core/FileFormats/PngWriter.cpp UnitTestsSources/Png.cpp
diffstat 2 files changed, 24 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/Core/FileFormats/PngWriter.cpp	Tue Oct 29 14:28:49 2013 +0000
+++ b/Core/FileFormats/PngWriter.cpp	Tue Oct 29 15:56:29 2013 +0000
@@ -174,15 +174,18 @@
       {
       case PixelFormat_Grayscale16:
       case PixelFormat_SignedGrayscale16:
-        png_set_rows(pimpl_->png_, pimpl_->info_, &pimpl_->rows_[0]);
-
+      {
+        int transforms = 0;
         if (Toolbox::DetectEndianness() == Endianness_Little)
         {
-          // Must swap the endianness!!
-          png_write_png(pimpl_->png_, pimpl_->info_, PNG_TRANSFORM_SWAP_ENDIAN, NULL);
+          transforms = PNG_TRANSFORM_SWAP_ENDIAN;
         }
 
+        png_set_rows(pimpl_->png_, pimpl_->info_, &pimpl_->rows_[0]);
+        png_write_png(pimpl_->png_, pimpl_->info_, transforms, NULL);
+
         break;
+      }
 
       default:
         png_write_image(pimpl_->png_, &pimpl_->rows_[0]);
--- a/UnitTestsSources/Png.cpp	Tue Oct 29 14:28:49 2013 +0000
+++ b/UnitTestsSources/Png.cpp	Tue Oct 29 15:56:29 2013 +0000
@@ -3,6 +3,8 @@
 #include <stdint.h>
 #include "../Core/FileFormats/PngReader.h"
 #include "../Core/FileFormats/PngWriter.h"
+#include "../Core/Toolbox.h"
+
 
 TEST(PngWriter, ColorPattern)
 {
@@ -24,6 +26,11 @@
   }
 
   w.WriteToFile("ColorPattern.png", width, height, pitch, Orthanc::PixelFormat_RGB24, &image[0]);
+
+  std::string f, md5;
+  Orthanc::Toolbox::ReadFile(f, "ColorPattern.png");
+  Orthanc::Toolbox::ComputeMD5(md5, f);
+  ASSERT_EQ("604e785f53c99cae6ea4584870b2c41d", md5);
 }
 
 TEST(PngWriter, Gray8Pattern)
@@ -44,6 +51,11 @@
   }
 
   w.WriteToFile("Gray8Pattern.png", width, height, pitch, Orthanc::PixelFormat_Grayscale8, &image[0]);
+
+  std::string f, md5;
+  Orthanc::Toolbox::ReadFile(f, "Gray8Pattern.png");
+  Orthanc::Toolbox::ComputeMD5(md5, f);
+  ASSERT_EQ("5a9b98bea3d0a6d983980cc38bfbcdb3", md5);
 }
 
 TEST(PngWriter, Gray16Pattern)
@@ -66,6 +78,11 @@
   }
 
   w.WriteToFile("Gray16Pattern.png", width, height, pitch, Orthanc::PixelFormat_Grayscale16, &image[0]);
+
+  std::string f, md5;
+  Orthanc::Toolbox::ReadFile(f, "Gray16Pattern.png");
+  Orthanc::Toolbox::ComputeMD5(md5, f);
+  ASSERT_EQ("0785866a08bf0a02d2eeff87f658571c", md5);
 }
 
 TEST(PngWriter, EndToEnd)
@@ -105,5 +122,4 @@
       ASSERT_EQ(*p, v);
     }
   }
-
 }