From 72a6ccc901003645ded9834d3649043bf44339a3 Mon Sep 17 00:00:00 2001
From: Thomas Feuvrier <thomas.feuvrier@c-s.fr>
Date: Wed, 31 Jan 2007 18:11:43 +0000
Subject: [PATCH] =?UTF-8?q?Correction=20sur=20lecture=20ONERA=20(Pb=20Swap?=
 =?UTF-8?q?=20mis=20en=20=C3=A9vidence=20sur=20SunOS)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 Code/IO/otbONERAImageIO.cxx | 23 +++++++++++++++++------
 Code/IO/otbONERAImageIO.h   | 13 ++++++++++---
 2 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/Code/IO/otbONERAImageIO.cxx b/Code/IO/otbONERAImageIO.cxx
index b1c2ade4ae..489629c1cf 100644
--- a/Code/IO/otbONERAImageIO.cxx
+++ b/Code/IO/otbONERAImageIO.cxx
@@ -241,11 +241,20 @@ otbMsgDevMacro( <<" Nb Of Components  : "<<this->GetNumberOfComponents());
     }
 
   //byte swapping depending on pixel type:
-  if(this->GetComponentType() == FLOAT)
+/*  if(this->GetComponentType() == FLOAT)
     {
     itk::ByteSwapper<float>::SwapRangeFromSystemToLittleEndian(
         reinterpret_cast<float *>(buffer),cpt);
-    }
+    }*/
+        unsigned long numberOfPixelsPerRegion = lNbLignes * lNbColonnes * 2;
+        // Swap bytes if necessary
+        if ( 0 ) {}
+        otbSwappFileToSystemMacro( float, FLOAT, buffer, numberOfPixelsPerRegion )
+        otbSwappFileToSystemMacro( double, DOUBLE, buffer, numberOfPixelsPerRegion )
+        else
+        {
+                itkExceptionMacro(<<"ONERAImageIO::Read() undefined component type! " );
+        }
 
   delete [] value;
     
@@ -386,7 +395,9 @@ void ONERAImageIO::InternalReadImageInformation()
 otbMsgDebugMacro( <<"Driver to read: ONERA");
 otbMsgDebugMacro( <<"         Read  file         : "<< m_FileName);
 otbMsgDebugMacro( <<"         Size               : "<<m_Dimensions[0]<<","<<m_Dimensions[1]);
-otbMsgDebugMacro( <<"         ComponentType      : "<<this->GetComponentType() );
+otbMsgDebugMacro( <<"         PixelType          : "<<this->GetPixelTypeAsString(this->GetPixelType()));
+otbMsgDebugMacro( <<"         ComponentType      : "<<this->GetComponentTypeAsString(this->GetComponentType()));
+otbMsgDebugMacro( <<"         ComponentSize      : "<<this->GetComponentSize());
 otbMsgDebugMacro( <<"         NumberOfComponents : "<<this->GetNumberOfComponents());
 otbMsgDebugMacro( <<"         NbOctetPixel       : "<<m_NbOctetPixel);
 
@@ -490,11 +501,11 @@ otbMsgDevMacro( <<" Dimensions de l'image  : "<<m_Dimensions[0]<<","<<m_Dimensio
 otbMsgDevMacro( <<" Region lue (IORegion)  : "<<this->GetIORegion());
 otbMsgDevMacro( <<" Nb Of Components  : "<<this->GetNumberOfComponents());
 
-	// Cas particuliers : on controle que si la r�gion � �crire est de la m�me dimension que l'image enti�re,
-	// on commence l'offset � 0 (lorsque que l'on est pas en "Streaming")
+	// Cas particuliers : on controle que si la r�gion � �crire est de la m�me dimension que l'image enti�re,
+	// on commence l'offset � 0 (lorsque que l'on est pas en "Streaming")
 	if( (lNbLignes == m_Dimensions[1]) && (lNbColonnes == m_Dimensions[0]))
 	{
-                otbMsgDevMacro(<<"Force l'offset de l'IORegion � 0");
+                otbMsgDevMacro(<<"Force l'offset de l'IORegion � 0");
 		lPremiereLigne = 0;
 		lPremiereColonne = 0;
 	}
diff --git a/Code/IO/otbONERAImageIO.h b/Code/IO/otbONERAImageIO.h
index 5f6aefa687..243ee053c6 100644
--- a/Code/IO/otbONERAImageIO.h
+++ b/Code/IO/otbONERAImageIO.h
@@ -18,6 +18,7 @@
 #ifndef __otbONERAImageIO_h
 #define __otbONERAImageIO_h
 
+#include "itkByteSwapper.h"
 #include "itkImageIOBase.h"
 #include <fstream>
 
@@ -119,18 +120,24 @@ private:
   ONERAImageIO(const Self&); //purposely not implemented
   void operator=(const Self&); //purposely not implemented
 
-  /** M�thode analyse le nom du fichier a ouvrir. S'il s'agit d'un r�pertoire, 
-    * on regarde s'il contient un produit le fichier ent�te (fichier "ENT...")
+  /** M�thode analyse le nom du fichier a ouvrir. S'il s'agit d'un r�pertoire, 
+    * on regarde s'il contient un produit le fichier ent�te (fichier "ENT...")
     * Dans ce cas, ONERAFileName contient le nom du fichier a ouvrir. 
     * Sinon ONERAFileName contient filename
     */
   void GetOneraImageFileName( const char * filename, std::string & OneraFileName );
 
+#define otbSwappFileToSystemMacro(StrongType, WeakType, buffer, buffer_size) \
+    else if ( this->GetComponentType() == WeakType ) \
+    { \
+        typedef itk::ByteSwapper< StrongType > InternalByteSwapperType; \
+        InternalByteSwapperType::SwapRangeFromSystemToLittleEndian((StrongType *)buffer, buffer_size ); \
+    }
 
   /** Nombre d'octets par pixel */
   int     m_NbOctetPixel;
   bool    m_FlagWriteImageInformation;
-  
+
 
 };
 
-- 
GitLab