From ac033d432fde6bb0144253b5cabcffd725e38660 Mon Sep 17 00:00:00 2001
From: Cyrille Valladeau <cyrille.valladeau@c-s.fr>
Date: Wed, 24 Aug 2011 10:54:09 +0200
Subject: [PATCH] BUG: fix issue writing a long/unsigned long image. bug #406

---
 Code/IO/otbGDALImageIO.cxx | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/Code/IO/otbGDALImageIO.cxx b/Code/IO/otbGDALImageIO.cxx
index eb5ae0b571..4415a17212 100644
--- a/Code/IO/otbGDALImageIO.cxx
+++ b/Code/IO/otbGDALImageIO.cxx
@@ -714,6 +714,16 @@ void GDALImageIO::InternalReadImageInformation()
     {
     m_BytePerPixel = 4;
     }
+  else if (this->GetComponentType() == LONG)
+    {
+    long tmp;
+    m_BytePerPixel = sizeof(tmp);
+    }
+  else if (this->GetComponentType() == ULONG)
+    {
+    long tmp;
+    m_BytePerPixel = sizeof(tmp);
+    }
   else if (this->GetComponentType() == FLOAT)
     {
     m_BytePerPixel = 4;
@@ -1304,6 +1314,26 @@ void GDALImageIO::InternalWriteImageInformation(const void* buffer)
       m_BytePerPixel = 4;
       m_PxType->pixType = GDT_UInt32;
       }
+    else if (this->GetComponentType() == LONG)
+      {
+        long tmp;
+        m_BytePerPixel = sizeof(tmp);
+        if( m_BytePerPixel == 8 )
+          {
+            itkWarningMacro(<< "Cast a long (64 bits) image into an int (32 bits) one.")
+          }
+        m_PxType->pixType = GDT_Int32;
+      }
+    else if (this->GetComponentType() == ULONG)
+      {
+        unsigned long tmp;
+        m_BytePerPixel = sizeof(tmp);
+        if( m_BytePerPixel == 8 )
+          {
+            itkWarningMacro(<< "Cast an unsigned long (64 bits) image into an unsigned int (32 bits) one.")
+              }
+        m_PxType->pixType = GDT_UInt32;
+      }
     else if (this->GetComponentType() == FLOAT)
       {
       m_BytePerPixel = 4;
-- 
GitLab