From a9a144f59b821751d19a41bd7b8e5bc6d6ff7a01 Mon Sep 17 00:00:00 2001 From: tbaudier Date: Wed, 9 Oct 2019 16:24:17 +0200 Subject: [PATCH] With ITK 5, add itkReadRawBytesAfterSwappingMacro and itkWriteRawBytesAfterSwappingMacro These macros desappear whit ITK5.0.1 --- common/clitkEsrfHstImageIO.cxx | 34 +++++++++++++-- common/clitkVoxImageIO.cxx | 79 +++++++++++++++++++++++++++++++++- common/rtkEdfImageIO.cxx | 26 +++++++++++ common/rtkImagXImageIO.cxx | 30 ++++++++++++- common/rtkXRadImageIO.cxx | 30 ++++++++++++- 5 files changed, 189 insertions(+), 10 deletions(-) diff --git a/common/clitkEsrfHstImageIO.cxx b/common/clitkEsrfHstImageIO.cxx index e9b8fdf..a17807c 100644 --- a/common/clitkEsrfHstImageIO.cxx +++ b/common/clitkEsrfHstImageIO.cxx @@ -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; \ + 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 } } diff --git a/common/clitkVoxImageIO.cxx b/common/clitkVoxImageIO.cxx index 065202e..568a95c 100644 --- a/common/clitkVoxImageIO.cxx +++ b/common/clitkVoxImageIO.cxx @@ -33,7 +33,11 @@ #include "clitkCommon.h" // itk include (for itkReadRawBytesAfterSwappingMacro) +#if ( ITK_VERSION_MAJOR < 5 ) #include "itkRawImageIO.h" +#else +#include +#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; \ + 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; \ + 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(); diff --git a/common/rtkEdfImageIO.cxx b/common/rtkEdfImageIO.cxx index 48acefb..ddd4aeb 100644 --- a/common/rtkEdfImageIO.cxx +++ b/common/rtkEdfImageIO.cxx @@ -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; \ + 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 } } diff --git a/common/rtkImagXImageIO.cxx b/common/rtkImagXImageIO.cxx index 09cb910..0d1b4d8 100644 --- a/common/rtkImagXImageIO.cxx +++ b/common/rtkImagXImageIO.cxx @@ -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; \ + 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 } } diff --git a/common/rtkXRadImageIO.cxx b/common/rtkXRadImageIO.cxx index fb02952..df2e8db 100644 --- a/common/rtkXRadImageIO.cxx +++ b/common/rtkXRadImageIO.cxx @@ -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; \ + 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 } } -- 2.47.1