]> Creatis software - clitk.git/blobdiff - common/rtkXRadImageIO.cxx
With ITK 5, add itkReadRawBytesAfterSwappingMacro and itkWriteRawBytesAfterSwappingMacro
[clitk.git] / common / rtkXRadImageIO.cxx
index db5eb72fe6861c24c22759f155e1ae12d749a81b..df2e8db20503edc2104a413212cdb161f3b7b457 100644 (file)
@@ -37,13 +37,13 @@ void rtk::XRadImageIO::ReadImageInformation()
     {
     std::string line;
     std::getline(is, line);
-    if(line.find('[')!=std::string::npos)
+    if(line.find('[') != std::string::npos)
       {
       unsigned int pos1 = line.find('[');
       unsigned int pos2 = line.find(']');
       section = line.substr(pos1+1, pos2-pos1-1);
       }
-    if(line.find('=')!=std::string::npos)
+    if(line.find('=') != std::string::npos)
       {
       unsigned int pos       = line.find('=');
       std::string paramName  = line.substr(0,pos);
@@ -57,9 +57,9 @@ void rtk::XRadImageIO::ReadImageInformation()
         SetDimensions(2, atoi(paramValue.c_str()));
       else if(paramName == std::string("CBCT.DimensionalAttributes.DataSize"))
         {
-        if(atoi(paramValue.c_str())==3)
+        if(atoi(paramValue.c_str()) == 3)
           SetComponentType(itk::ImageIOBase::FLOAT);
-        if(atoi(paramValue.c_str())==6)
+        if(atoi(paramValue.c_str()) == 6)
           SetComponentType(itk::ImageIOBase::USHORT);
         }
       else if(paramName == std::string("CBCT.DimensionalAttributes.PixelDimension_I_cm"))
@@ -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,28 +135,53 @@ 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
     }
 }
 
 //--------------------------------------------------------------------
 // Write Image Information
-void rtk::XRadImageIO::WriteImageInformation(bool keepOfStream)
+void rtk::XRadImageIO::WriteImageInformation(bool itkNotUsed(keepOfStream))
 {
 }
 
 //--------------------------------------------------------------------
 // Write Image Information
-bool rtk::XRadImageIO::CanWriteFile(const char* FileNameToWrite)
+bool rtk::XRadImageIO::CanWriteFile(const char* itkNotUsed(FileNameToWrite))
 {
   return false;
 }
 
 //--------------------------------------------------------------------
 // Write Image
-void rtk::XRadImageIO::Write(const void * buffer)
+void rtk::XRadImageIO::Write(const void * itkNotUsed(buffer))
 {
 } ////