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> &lt;<a href="mailto:yguo2006@gmail.com">yguo2006@gmail.com</a>&gt; 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&nbsp;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>&nbsp;</div>
<div>the following code is extracted from method itkRawImageIO::Write </div>
<div>&nbsp;</div>
<div>/********************************************************/</div>
<div>
<p>&nbsp; // Actually do the writing<br>&nbsp; //<br>&nbsp; if ( m_FileType == ASCII )<br>&nbsp;&nbsp;&nbsp; {<br>...</p>
<p>&nbsp;&nbsp; }<br>&nbsp; else //binary<br>&nbsp;&nbsp;&nbsp; {</p>
<p>&nbsp;&nbsp;&nbsp; const unsigned long numberOfBytes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = this-&gt;GetImageSizeInBytes();<br>&nbsp;&nbsp;&nbsp; const unsigned long numberOfComponents = this-&gt;GetImageSizeInComponents();<br>&nbsp;&nbsp;&nbsp; <br>#define itkWriteRawBytesAfterSwappingMacro(StrongType, WeakType) \
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ( this-&gt;GetComponentType() ==&nbsp; WeakType ) \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; typedef ByteSwapper&lt; StrongType &gt; InternalByteSwapperType; \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( m_ByteOrder == LittleEndian ) \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char * tempBuffer = new char[ numberOfBytes ]; \
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; memcpy( tempBuffer, buffer , numberOfBytes ); \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InternalByteSwapperType::SwapRangeFromSystemToLittleEndian( \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (StrongType *)tempBuffer, numberOfComponents ); \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; file.write( tempBuffer, numberOfBytes ); \
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; delete [] tempBuffer; \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if ( m_ByteOrder == BigEndian ) \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char * tempBuffer = new char[ numberOfBytes ]; \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; memcpy( tempBuffer, buffer , numberOfBytes ); \
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InternalByteSwapperType::SwapRangeFromSystemToBigEndian( \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (StrongType *)tempBuffer, numberOfComponents ); \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; file.write( tempBuffer, numberOfBytes ); \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; delete [] tempBuffer; \
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
file.write(static_cast&lt;const char*&gt;(buffer), numberOfBytes );
\&nbsp; //*** may not be executed when this-&gt;GetComponentType()
==UCHAR<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; // Swap bytes if necessary
<br>&nbsp;&nbsp;&nbsp; if itkWriteRawBytesAfterSwappingMacro( unsigned short, USHORT ) <br>&nbsp;&nbsp;&nbsp; else if itkWriteRawBytesAfterSwappingMacro( short, SHORT ) <br>&nbsp;&nbsp;&nbsp; else if itkWriteRawBytesAfterSwappingMacro( unsigned int, UINT ) <br>&nbsp;&nbsp;&nbsp; else if itkWriteRawBytesAfterSwappingMacro( int, INT ) 
<br>&nbsp;&nbsp;&nbsp; else if itkWriteRawBytesAfterSwappingMacro( long, LONG ) <br>&nbsp;&nbsp;&nbsp; else if itkWriteRawBytesAfterSwappingMacro( unsigned long, ULONG ) <br>&nbsp;&nbsp;&nbsp; else if itkWriteRawBytesAfterSwappingMacro( float, FLOAT ) <br>&nbsp;&nbsp;&nbsp; else if itkWriteRawBytesAfterSwappingMacro( double, DOUBLE ) 
<br>&nbsp;&nbsp;&nbsp; }<br>....</p>
<p>/****************************************************************/</p>
<p>&nbsp;</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-&gt;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>&nbsp;&nbsp;&nbsp; // Swap bytes if necessary<br>&nbsp;&nbsp;&nbsp; if itkWriteRawBytesAfterSwappingMacro( unsigned short, USHORT ) <br>&nbsp;&nbsp;&nbsp; else if itkWriteRawBytesAfterSwappingMacro( short, SHORT ) <br>&nbsp;&nbsp;&nbsp; else if itkWriteRawBytesAfterSwappingMacro( unsigned int, UINT ) 
<br>&nbsp;&nbsp;&nbsp; else if itkWriteRawBytesAfterSwappingMacro( int, INT ) <br>&nbsp;&nbsp;&nbsp; else if itkWriteRawBytesAfterSwappingMacro( long, LONG ) <br>&nbsp;&nbsp;&nbsp; else if itkWriteRawBytesAfterSwappingMacro( unsigned long, ULONG ) <br>&nbsp;&nbsp;&nbsp; else if itkWriteRawBytesAfterSwappingMacro( float, FLOAT ) 
<br>&nbsp;&nbsp;&nbsp; else if itkWriteRawBytesAfterSwappingMacro( double, DOUBLE ) <br>&nbsp;else file.write(static_cast&lt;const char*&gt;(buffer), numberOfBytes );&nbsp; //*******************New line added</p>
<p>....</p>
<p>/*******************************************************************/<br>
</p>
<p>Now my problem seems solved.<br>
</p>

<p>&nbsp;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>&nbsp;</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>