Hi Eugene,<br><br>Please log a bug report at <a href="http://www.itk.org/Bug/">http://www.itk.org/Bug/</a> and assign it to me.<br><br>Thanks<br>-karthik<br><br><div><span class="gmail_quote">On 11/16/06, <b class="gmail_sendername">
Eugene Guo</b> <<a href="mailto:yguo2006@gmail.com">yguo2006@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>Hi, </div>
<div>I just read through the code of class itkRawImageIO defined in <br>
<span id="st" name="st" class="st">Insight</span>/Code/IO/itkRawImageIO.txx<br>
and notice that there maybe a bug which led to my problem when testing itkRawImageIO:</div>
<div> </div>
<div>the following code is extracted from method itkRawImageIO::Write </div>
<div> </div>
<div>/********************************************************/</div>
<div>
<p> // Actually do the writing<br> //<br> if ( m_FileType == ASCII )<br> {<br>...</p>
<p> }<br> else //binary<br> {</p>
<p> const unsigned long numberOfBytes = this->GetImageSizeInBytes();<br> const unsigned long numberOfComponents = this->GetImageSizeInComponents();<br> <br>#define itkWriteRawBytesAfterSwappingMacro(StrongType, WeakType) \
<br> ( this->GetComponentType() == WeakType ) \<br> { \<br> typedef ByteSwapper< StrongType > InternalByteSwapperType; \<br> if ( m_ByteOrder == LittleEndian ) \<br> { \<br> char * tempBuffer = new char[ numberOfBytes ]; \
<br> memcpy( tempBuffer, buffer , numberOfBytes ); \<br> InternalByteSwapperType::SwapRangeFromSystemToLittleEndian( \<br> (StrongType *)tempBuffer, numberOfComponents ); \<br> file.write( tempBuffer, numberOfBytes ); \
<br> delete [] tempBuffer; \<br> } \<br> else if ( m_ByteOrder == BigEndian ) \<br> { \<br> char * tempBuffer = new char[ numberOfBytes ]; \<br> memcpy( tempBuffer, buffer , numberOfBytes ); \
<br> InternalByteSwapperType::SwapRangeFromSystemToBigEndian( \<br> (StrongType *)tempBuffer, numberOfComponents ); \<br> file.write( tempBuffer, numberOfBytes ); \<br> delete [] tempBuffer; \
<br> } \<br> else \<br> { \<br>
file.write(static_cast<const char*>(buffer), numberOfBytes );
\ //*** may not be executed when this->GetComponentType()
==UCHAR<br> } \<br> }<br> <br> // Swap bytes if necessary
<br> if itkWriteRawBytesAfterSwappingMacro( unsigned short, USHORT ) <br> else if itkWriteRawBytesAfterSwappingMacro( short, SHORT ) <br> else if itkWriteRawBytesAfterSwappingMacro( unsigned int, UINT ) <br> else if itkWriteRawBytesAfterSwappingMacro( int, INT )
<br> else if itkWriteRawBytesAfterSwappingMacro( long, LONG ) <br> else if itkWriteRawBytesAfterSwappingMacro( unsigned long, ULONG ) <br> else if itkWriteRawBytesAfterSwappingMacro( float, FLOAT ) <br> else if itkWriteRawBytesAfterSwappingMacro( double, DOUBLE )
<br> }<br>....</p>
<p>/****************************************************************/</p>
<p> </p>
<p>Here the third file.write may not be executed at all. The swapping
macro only work for those data type longer than two bytes. For my case,
I was trying to write 3D volume in unsigned char
(this->GetComponentType() == UCHAR), which is not covered by those
swapping macro defined. Therefore the file.write was never carried out.</p>
<p>To fix it, I copied the file.write line to the end of *** if itkWriteRawBytesAfterSwappingMacro *** statements, which now looks like:</p>
<p>/**************************************************************/</p>
<p>......</p>
<p> // Swap bytes if necessary<br> if itkWriteRawBytesAfterSwappingMacro( unsigned short, USHORT ) <br> else if itkWriteRawBytesAfterSwappingMacro( short, SHORT ) <br> else if itkWriteRawBytesAfterSwappingMacro( unsigned int, UINT )
<br> else if itkWriteRawBytesAfterSwappingMacro( int, INT ) <br> else if itkWriteRawBytesAfterSwappingMacro( long, LONG ) <br> else if itkWriteRawBytesAfterSwappingMacro( unsigned long, ULONG ) <br> else if itkWriteRawBytesAfterSwappingMacro( float, FLOAT )
<br> else if itkWriteRawBytesAfterSwappingMacro( double, DOUBLE ) <br> else file.write(static_cast<const char*>(buffer), numberOfBytes ); //*******************New line added</p>
<p>....</p>
<p>/*******************************************************************/<br>
</p>
<p>Now my problem seems solved.<br>
</p>
<p> Is this a correct way to do it, or there is another way to solve it without touching the source code? </p>
<p>Thanks</p>
<p> </p>
<p>Eugene</p></div>
<br>_______________________________________________<br><span id="st" name="st" class="st">Insight</span>-<span id="st" name="st" class="st">users</span> mailing list<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:Insight-users@itk.org">
<span id="st" name="st" class="st">Insight</span>-<span id="st" name="st" class="st">users</span>@itk.org</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">
http://www.itk.org/mailman/listinfo/<span id="st" name="st" class="st">insight</span>-<span id="st" name="st" class="st">users</span></a><br><br><br></blockquote></div>