]> Creatis software - clitk.git/commitdiff
With ITK 5, add itkReadRawBytesAfterSwappingMacro and itkWriteRawBytesAfterSwappingMacro
authortbaudier <thomas.baudier@creatis.insa-lyon.fr>
Wed, 9 Oct 2019 14:24:17 +0000 (16:24 +0200)
committertbaudier <thomas.baudier@creatis.insa-lyon.fr>
Wed, 9 Oct 2019 14:24:17 +0000 (16:24 +0200)
These macros desappear whit ITK5.0.1

common/clitkEsrfHstImageIO.cxx
common/clitkVoxImageIO.cxx
common/rtkEdfImageIO.cxx
common/rtkImagXImageIO.cxx
common/rtkXRadImageIO.cxx

index e9b8fdf3ed6227a14670706c91bcf21f3b3fbe23..a17807c2df2c61494d3144e1a3eb33a5d147f29e 100644 (file)
@@ -107,6 +107,7 @@ void clitk::EsrfHstImageIO::Read(void * buffer)
 
   // Adapted from itkRawImageIO
   {
+#if ( ITK_VERSION_MAJOR < 5 )
     using namespace itk;
     // Swap bytes if necessary
     if itkReadRawBytesAfterSwappingMacro( unsigned short, USHORT )
@@ -115,10 +116,35 @@ void clitk::EsrfHstImageIO::Read(void * buffer)
           else if itkReadRawBytesAfterSwappingMacro( unsigned char, UCHAR )
             else if itkReadRawBytesAfterSwappingMacro( unsigned int, UINT )
               else if itkReadRawBytesAfterSwappingMacro( int, INT )
-                else if itkReadRawBytesAfterSwappingMacro( unsigned int, ULONG )
-                  else if itkReadRawBytesAfterSwappingMacro( int, LONG )
-                    else if itkReadRawBytesAfterSwappingMacro( float, FLOAT )
-                      else if itkReadRawBytesAfterSwappingMacro( double, DOUBLE );
+                else if itkReadRawBytesAfterSwappingMacro( float, FLOAT )
+                  else if itkReadRawBytesAfterSwappingMacro( double, DOUBLE );
+#else
+  #define itkReadRawBytesAfterSwappingMacro(StrongType, WeakType)   \
+    ( this->GetComponentType() == WeakType )                        \
+      {                                                             \
+      using InternalByteSwapperType = itk::ByteSwapper<StrongType>; \
+      if ( m_ByteOrder == LittleEndian )                            \
+        {                                                           \
+        InternalByteSwapperType::SwapRangeFromSystemToLittleEndian( \
+          (StrongType *)buffer, this->GetImageSizeInComponents() ); \
+        }                                                           \
+      else if ( m_ByteOrder == BigEndian )                          \
+        {                                                           \
+        InternalByteSwapperType::SwapRangeFromSystemToBigEndian(    \
+          (StrongType *)buffer, this->GetImageSizeInComponents() ); \
+        }                                                           \
+      }
+
+    // Swap bytes if necessary
+    if itkReadRawBytesAfterSwappingMacro( unsigned short, USHORT )
+      else if itkReadRawBytesAfterSwappingMacro( short, SHORT )
+        else if itkReadRawBytesAfterSwappingMacro( char, CHAR )
+          else if itkReadRawBytesAfterSwappingMacro( unsigned char, UCHAR )
+            else if itkReadRawBytesAfterSwappingMacro( unsigned int, UINT )
+              else if itkReadRawBytesAfterSwappingMacro( int, INT )
+                else if itkReadRawBytesAfterSwappingMacro( float, FLOAT )
+                  else if itkReadRawBytesAfterSwappingMacro( double, DOUBLE );
+#endif
   }
 }
 
index 065202e5ddbcd3f7acf5ee3f9e5847c93642ba24..568a95ce5136b46c2f725f7c30c72e902429dc1b 100644 (file)
 #include "clitkCommon.h"
 
 // itk include (for itkReadRawBytesAfterSwappingMacro)
+#if ( ITK_VERSION_MAJOR < 5 )
 #include "itkRawImageIO.h"
+#else
+#include <itkByteSwapper.h>
+#endif
 
 //--------------------------------------------------------------------
 // Read Image Information
@@ -162,6 +166,7 @@ void clitk::VoxImageIO::Read(void * buffer)
   itkDebugMacro(<< "Reading Done");
 
   {
+#if ( ITK_VERSION_MAJOR < 5 )
     using namespace itk;
     // Swap bytes if necessary
     if itkReadRawBytesAfterSwappingMacro( unsigned short, USHORT )
@@ -172,6 +177,33 @@ void clitk::VoxImageIO::Read(void * buffer)
               else if itkReadRawBytesAfterSwappingMacro( int, INT )
                 else if itkReadRawBytesAfterSwappingMacro( float, FLOAT )
                   else if itkReadRawBytesAfterSwappingMacro( double, DOUBLE );
+#else
+  #define itkReadRawBytesAfterSwappingMacro(StrongType, WeakType)   \
+    ( this->GetComponentType() == WeakType )                        \
+      {                                                             \
+      using InternalByteSwapperType = itk::ByteSwapper<StrongType>; \
+      if ( m_ByteOrder == LittleEndian )                            \
+        {                                                           \
+        InternalByteSwapperType::SwapRangeFromSystemToLittleEndian( \
+          (StrongType *)buffer, this->GetImageSizeInComponents() ); \
+        }                                                           \
+      else if ( m_ByteOrder == BigEndian )                          \
+        {                                                           \
+        InternalByteSwapperType::SwapRangeFromSystemToBigEndian(    \
+          (StrongType *)buffer, this->GetImageSizeInComponents() ); \
+        }                                                           \
+      }
+
+    // Swap bytes if necessary
+    if itkReadRawBytesAfterSwappingMacro( unsigned short, USHORT )
+      else if itkReadRawBytesAfterSwappingMacro( short, SHORT )
+        else if itkReadRawBytesAfterSwappingMacro( char, CHAR )
+          else if itkReadRawBytesAfterSwappingMacro( unsigned char, UCHAR )
+            else if itkReadRawBytesAfterSwappingMacro( unsigned int, UINT )
+              else if itkReadRawBytesAfterSwappingMacro( int, INT )
+                else if itkReadRawBytesAfterSwappingMacro( float, FLOAT )
+                  else if itkReadRawBytesAfterSwappingMacro( double, DOUBLE );
+#endif
   }
 }
 
@@ -243,8 +275,9 @@ void clitk::VoxImageIO::Write(const void * buffer)
   // (warning BigEndian / LittleEndian)
   const unsigned long numberOfBytes      = this->GetImageSizeInBytes();
   const unsigned long numberOfComponents = this->GetImageSizeInComponents();
-  // Swap bytes if necessary
+#if ( ITK_VERSION_MAJOR < 5 )
   using namespace itk;
+  // Swap bytes if necessary
   if itkWriteRawBytesAfterSwappingMacro( unsigned short, USHORT )
     else if itkWriteRawBytesAfterSwappingMacro( short, SHORT )
       else if itkWriteRawBytesAfterSwappingMacro( char, CHAR )
@@ -252,7 +285,49 @@ void clitk::VoxImageIO::Write(const void * buffer)
           else if itkWriteRawBytesAfterSwappingMacro( unsigned int, UINT )
             else if itkWriteRawBytesAfterSwappingMacro( int, INT )
               else if itkWriteRawBytesAfterSwappingMacro( float, FLOAT )
-                else if itkWriteRawBytesAfterSwappingMacro( double, DOUBLE ) ;
+                else if itkWriteRawBytesAfterSwappingMacro( double, DOUBLE );
+#else
+#define itkWriteRawBytesAfterSwappingMacro(StrongType, WeakType)        \
+  ( this->GetComponentType() == WeakType )                              \
+    {                                                                   \
+    using InternalByteSwapperType = itk::ByteSwapper<StrongType>;       \
+    const SizeValueType numberOfPixels = numberOfBytes/(sizeof(StrongType)); \
+    if ( m_ByteOrder == LittleEndian )                                  \
+      {                                                                 \
+      StrongType *tempBuffer = new StrongType[numberOfPixels];          \
+      memcpy((char *)tempBuffer, buffer, numberOfBytes);          \
+      InternalByteSwapperType::SwapRangeFromSystemToLittleEndian(       \
+        (StrongType *)tempBuffer, numberOfComponents);                  \
+      file.write((char *)tempBuffer, numberOfBytes);                            \
+      delete[] tempBuffer;                                              \
+      }                                                                 \
+    else if ( m_ByteOrder == BigEndian )                                \
+      {                                                                 \
+      StrongType *tempBuffer = new StrongType[numberOfPixels];          \
+      memcpy((char *)tempBuffer, buffer, numberOfBytes);          \
+      InternalByteSwapperType::SwapRangeFromSystemToBigEndian(          \
+        (StrongType *)tempBuffer, numberOfComponents);                  \
+      file.write((char *)tempBuffer, numberOfBytes);                            \
+      delete[] tempBuffer;                                              \
+      }                                                                 \
+    else                                                                \
+      {                                                                 \
+      file.write(static_cast< const char * >( buffer ), numberOfBytes); \
+      }                                                                 \
+    }
+
+    // Swap bytes if necessary
+    if itkWriteRawBytesAfterSwappingMacro(unsigned short, USHORT)
+    else if itkWriteRawBytesAfterSwappingMacro(short, SHORT)
+    else if itkWriteRawBytesAfterSwappingMacro(char, CHAR)
+    else if itkWriteRawBytesAfterSwappingMacro(unsigned char, UCHAR)
+    else if itkWriteRawBytesAfterSwappingMacro(unsigned int, UINT)
+    else if itkWriteRawBytesAfterSwappingMacro(int, INT)
+    else if itkWriteRawBytesAfterSwappingMacro(long, LONG)
+    else if itkWriteRawBytesAfterSwappingMacro(unsigned long, ULONG)
+    else if itkWriteRawBytesAfterSwappingMacro(float, FLOAT)
+    else if itkWriteRawBytesAfterSwappingMacro(double, DOUBLE)
+#endif
   //-------------------------------------------
 
   file.close();
index 48acefbb961a2fd3b46af1a464771d033eb5dbdb..ddd4aebc91c698c4fc6a1b37f0e8211b4675e35f 100644 (file)
@@ -256,6 +256,7 @@ void rtk::EdfImageIO::Read(void * buffer)
 
   // Adapted from itkRawImageIO
     {
+#if ( ITK_VERSION_MAJOR < 5 )
     using namespace itk;
     // Swap bytes if necessary
     if itkReadRawBytesAfterSwappingMacro( unsigned short, USHORT )
@@ -264,10 +265,35 @@ void rtk::EdfImageIO::Read(void * buffer)
     else if itkReadRawBytesAfterSwappingMacro( unsigned char, UCHAR )
     else if itkReadRawBytesAfterSwappingMacro( unsigned int, UINT )
     else if itkReadRawBytesAfterSwappingMacro( int, INT )
+    else if itkReadRawBytesAfterSwappingMacro( float, FLOAT )
+    else if itkReadRawBytesAfterSwappingMacro( double, DOUBLE );
+#else
+  #define itkReadRawBytesAfterSwappingMacro(StrongType, WeakType)   \
+    ( this->GetComponentType() == WeakType )                        \
+      {                                                             \
+      using InternalByteSwapperType = itk::ByteSwapper<StrongType>; \
+      if ( m_ByteOrder == LittleEndian )                            \
+        {                                                           \
+        InternalByteSwapperType::SwapRangeFromSystemToLittleEndian( \
+          (StrongType *)buffer, this->GetImageSizeInComponents() ); \
+        }                                                           \
+      else if ( m_ByteOrder == BigEndian )                          \
+        {                                                           \
+        InternalByteSwapperType::SwapRangeFromSystemToBigEndian(    \
+          (StrongType *)buffer, this->GetImageSizeInComponents() ); \
+        }                                                           \
+      }
+
+    // Swap bytes if necessary
+    if itkReadRawBytesAfterSwappingMacro( unsigned short, USHORT )
+    else if itkReadRawBytesAfterSwappingMacro( short, SHORT )
+    else if itkReadRawBytesAfterSwappingMacro( char, CHAR )
+    else if itkReadRawBytesAfterSwappingMacro( unsigned char, UCHAR )
     else if itkReadRawBytesAfterSwappingMacro( unsigned int, UINT )
     else if itkReadRawBytesAfterSwappingMacro( int, INT )
     else if itkReadRawBytesAfterSwappingMacro( float, FLOAT )
     else if itkReadRawBytesAfterSwappingMacro( double, DOUBLE );
+#endif
     }
 }
 
index 09cb910558dc9e9eabedfb81be6c23b0bee42bef..0d1b4d8e0bac56d2b75af37e09b1aded61d6ac87 100644 (file)
@@ -163,6 +163,7 @@ void rtk::ImagXImageIO::Read(void * buffer)
 
   // Adapted from itkRawImageIO
     {
+#if ( ITK_VERSION_MAJOR < 5 )
     using namespace itk;
     // Swap bytes if necessary
     if itkReadRawBytesAfterSwappingMacro( unsigned short, USHORT )
@@ -171,10 +172,35 @@ void rtk::ImagXImageIO::Read(void * buffer)
     else if itkReadRawBytesAfterSwappingMacro( unsigned char, UCHAR )
     else if itkReadRawBytesAfterSwappingMacro( unsigned int, UINT )
     else if itkReadRawBytesAfterSwappingMacro( int, INT )
-    else if itkReadRawBytesAfterSwappingMacro( unsigned int, ULONG )
-    else if itkReadRawBytesAfterSwappingMacro( int, LONG )
     else if itkReadRawBytesAfterSwappingMacro( float, FLOAT )
     else if itkReadRawBytesAfterSwappingMacro( double, DOUBLE );
+#else
+  #define itkReadRawBytesAfterSwappingMacro(StrongType, WeakType)   \
+    ( this->GetComponentType() == WeakType )                        \
+      {                                                             \
+      using InternalByteSwapperType = itk::ByteSwapper<StrongType>; \
+      if ( m_ByteOrder == LittleEndian )                            \
+        {                                                           \
+        InternalByteSwapperType::SwapRangeFromSystemToLittleEndian( \
+          (StrongType *)buffer, this->GetImageSizeInComponents() ); \
+        }                                                           \
+      else if ( m_ByteOrder == BigEndian )                          \
+        {                                                           \
+        InternalByteSwapperType::SwapRangeFromSystemToBigEndian(    \
+          (StrongType *)buffer, this->GetImageSizeInComponents() ); \
+        }                                                           \
+      }
+
+    // Swap bytes if necessary
+    if itkReadRawBytesAfterSwappingMacro( unsigned short, USHORT )
+    else if itkReadRawBytesAfterSwappingMacro( short, SHORT )
+    else if itkReadRawBytesAfterSwappingMacro( char, CHAR )
+    else if itkReadRawBytesAfterSwappingMacro( unsigned char, UCHAR )
+    else if itkReadRawBytesAfterSwappingMacro( unsigned int, UINT )
+    else if itkReadRawBytesAfterSwappingMacro( int, INT )
+    else if itkReadRawBytesAfterSwappingMacro( float, FLOAT )
+    else if itkReadRawBytesAfterSwappingMacro( double, DOUBLE );
+#endif
     }
 }
 
index fb02952016ed37ce421de70ea8dd312694974167..df2e8db20503edc2104a413212cdb161f3b7b457 100644 (file)
@@ -126,6 +126,7 @@ void rtk::XRadImageIO::Read(void * buffer)
 
   // Adapted from itkRawImageIO
     {
+#if ( ITK_VERSION_MAJOR < 5 )
     using namespace itk;
     // Swap bytes if necessary
     if itkReadRawBytesAfterSwappingMacro( unsigned short, USHORT )
@@ -134,10 +135,35 @@ void rtk::XRadImageIO::Read(void * buffer)
     else if itkReadRawBytesAfterSwappingMacro( unsigned char, UCHAR )
     else if itkReadRawBytesAfterSwappingMacro( unsigned int, UINT )
     else if itkReadRawBytesAfterSwappingMacro( int, INT )
-    else if itkReadRawBytesAfterSwappingMacro( unsigned int, ULONG )
-    else if itkReadRawBytesAfterSwappingMacro( int, LONG )
     else if itkReadRawBytesAfterSwappingMacro( float, FLOAT )
     else if itkReadRawBytesAfterSwappingMacro( double, DOUBLE );
+#else
+  #define itkReadRawBytesAfterSwappingMacro(StrongType, WeakType)   \
+    ( this->GetComponentType() == WeakType )                        \
+      {                                                             \
+      using InternalByteSwapperType = itk::ByteSwapper<StrongType>; \
+      if ( m_ByteOrder == LittleEndian )                            \
+        {                                                           \
+        InternalByteSwapperType::SwapRangeFromSystemToLittleEndian( \
+          (StrongType *)buffer, this->GetImageSizeInComponents() ); \
+        }                                                           \
+      else if ( m_ByteOrder == BigEndian )                          \
+        {                                                           \
+        InternalByteSwapperType::SwapRangeFromSystemToBigEndian(    \
+          (StrongType *)buffer, this->GetImageSizeInComponents() ); \
+        }                                                           \
+      }
+
+    // Swap bytes if necessary
+    if itkReadRawBytesAfterSwappingMacro( unsigned short, USHORT )
+    else if itkReadRawBytesAfterSwappingMacro( short, SHORT )
+    else if itkReadRawBytesAfterSwappingMacro( char, CHAR )
+    else if itkReadRawBytesAfterSwappingMacro( unsigned char, UCHAR )
+    else if itkReadRawBytesAfterSwappingMacro( unsigned int, UINT )
+    else if itkReadRawBytesAfterSwappingMacro( int, INT )
+    else if itkReadRawBytesAfterSwappingMacro( float, FLOAT )
+    else if itkReadRawBytesAfterSwappingMacro( double, DOUBLE );
+#endif
     }
 }