Authors belong to:
- University of LYON http://www.universite-lyon.fr/
- - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
+ - Léon Bérard cancer center http://www.centreleonberard.fr
- CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
This software is distributed WITHOUT ANY WARRANTY; without even
- BSD See included LICENSE.txt file
- CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-======================================================================-====*/
+===========================================================================**/
#ifndef CLITKVOXIMAGEIO_CXX
#define CLITKVOXIMAGEIO_CXX
/**
#include "clitkCommon.h"
// itk include (for itkReadRawBytesAfterSwappingMacro)
+#if ( ITK_VERSION_MAJOR < 5 )
#include "itkRawImageIO.h"
+#else
+#include <itkByteSwapper.h>
+#endif
//--------------------------------------------------------------------
// Read Image Information
itkDebugMacro(<< "Reading Done");
{
+#if ( ITK_VERSION_MAJOR < 5 )
using namespace itk;
// Swap bytes if necessary
if itkReadRawBytesAfterSwappingMacro( unsigned short, USHORT )
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
}
}
// (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 )
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();