+ std::cout << " Let's swap Pixels" <<std::endl;
+
+ for (unsigned int i=0; i<GetDataSize()/2; i++)
+ {
+ g = ((uint16_t *)Data)[i];
+ g = ( g << 8 | g >> 8 );
+ ((uint16_t *)Data)[i] = g;
+ }
+ return(true);
+}
+
+void TestFile::WriteFile()
+{
+ std::ofstream fp(fileName.c_str(),std::ios::out | std::ios::binary);
+
+ if(!fp)
+ {
+ readable=false;
+ return;
+ }
+
+ WriteFileHeader(&fp);
+ WriteFileData(&fp);
+
+ fp.close();
+}
+
+bool TestFile::WriteFileHeader(std::ofstream *fp)
+{
+ WriteInt8(fp,'g'); // Bitmap tag - must be 'g'
+ WriteInt8(fp,'d'); // Bitmap tag - must be 'd'
+ WriteInt8(fp,'c'); // Bitmap tag - must be 'c'
+ WriteInt8(fp,'m'); // Bitmap tag - must be 'm'
+
+ // FIXME : Think of writting an int32, better !
+ // (('g' << 8 + 'd') << 8 + 'c') + 'm'
+ // if you want to use it to check the endianess.
+ // (and upload again *all* the .tst files ...)
+ WriteInt32(fp,SizeX); // Size X
+ WriteInt32(fp,SizeY); // Size Y
+ WriteInt32(fp,SizeZ); // Size Z
+ WriteInt16(fp,ScalarSize*8); // bits per scalar
+ WriteInt16(fp,Components); // number of components
+
+ return(true);
+}
+
+bool TestFile::WriteFileData(std::ofstream *fp)
+{
+ fp->write((char *)Data,GetDataSize());
+
+ return(true);
+}
+
+uint8_t TestFile::ReadInt8 (std::ifstream *fp)
+#if !(__GNUC__==2 && __GNUC_MINOR__<=96)
+ throw( std::ios::failure )
+#endif
+{
+ uint8_t g;
+ fp->read ((char*)&g, (size_t)1);
+#if !(__GNUC__==2 && __GNUC_MINOR__<=96)
+ if ( fp->fail() )
+ throw std::ios::failure( "TestFile::ReadInt8() - file error." );
+ if( fp->eof() )
+ throw std::ios::failure( "TestFile::ReadInt8() - EOF." );
+#endif
+ return g;
+}
+
+uint16_t TestFile::ReadInt16(std::ifstream *fp)
+#if !(__GNUC__==2 && __GNUC_MINOR__<=96)
+ throw( std::ios::failure )
+#endif
+{
+ uint16_t g;
+ fp->read ((char*)&g, (size_t)2);
+#if !(__GNUC__==2 && __GNUC_MINOR__<=96)
+ if ( fp->fail() )
+ throw std::ios::failure( "TestFile::ReadInt16() - file error." );
+ if( fp->eof() )
+ throw std::ios::failure( "TestFile::ReadInt16() - EOF." );
+#endif
+
+#if defined(GDCM_WORDS_BIGENDIAN)
+ g = ( g << 8 | g >> 8 );
+#endif
+ return g;
+}
+
+uint32_t TestFile::ReadInt32(std::ifstream *fp)
+#if !(__GNUC__==2 && __GNUC_MINOR__<=96)
+ throw( std::ios::failure )
+#endif
+{
+ uint32_t g;
+ fp->read ((char*)&g, (size_t)4);
+#if !(__GNUC__==2 && __GNUC_MINOR__<=96)
+ if ( fp->fail() )
+ throw std::ios::failure( "TestFile::ReadInt32() - file error." );
+ if( fp->eof() )
+ throw std::ios::failure( "TestFile::ReadInt32() - EOF." );
+#endif
+
+#if defined(GDCM_WORDS_BIGENDIAN)
+ g = ( (g<<24) | ((g<<8) & 0x00ff0000) |
+ ( (g>>8) & 0x0000ff00) | (g>>24) );
+#endif
+ return g;
+}
+
+void TestFile::WriteInt8 (std::ofstream *fp,uint8_t value)
+{
+ fp->write((char*)&value, (size_t)1);
+}
+
+void TestFile::WriteInt16(std::ofstream *fp,uint16_t value)
+{
+#if defined(GDCM_WORDS_BIGENDIAN)
+ value = ( value << 8 | value >> 8 );
+#endif
+ fp->write((char*)&value, (size_t)2);
+}
+
+void TestFile::WriteInt32(std::ofstream *fp,uint32_t value)
+{
+#if defined(GDCM_WORDS_BIGENDIAN)
+ value = ( (value<<24) | ((value<<8) & 0x00ff0000) |
+ ( (value>>8) & 0x0000ff00) | (value>>24) );
+#endif
+ fp->write((char*)&value, (size_t)4);
+}
+
+int InternalTest(std::string const &filename,
+ std::string const &referenceFileName )
+{