<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2653.12">
<TITLE>Bug in BMP driver?</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=2 FACE="Arial">Hi,</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">I have problems reading a 32 bit RGB Windows Bitmap (type BMPC_RGB). I changed the ::IReadblock for 32 bit bitmaps and it worked afterwards:</FONT></P>

<P><FONT SIZE=2 FACE="Arial">CPLErr BMPRasterBand::IReadBlock::IReadBlock()</FONT>
<BR><FONT SIZE=2 FACE="Arial">{</FONT>
<BR><FONT SIZE=2 FACE="Arial">...</FONT>
<BR><FONT SIZE=2 FACE="Arial">old:</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; </FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; if ( poGDS-&gt;sInfoHeader.iBitCount == 24 ||</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; poGDS-&gt;sInfoHeader.iBitCount == 32 )</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; {</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for ( i = 0, j = 0; i &lt; nBlockXSize; i++ )</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Colour triplets in BMP file organized in reverse order:</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // blue, green, red</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((GByte *) pImage)[i] = pabyScan[j + iBytesPerPixel - nBand];</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; j += iBytesPerPixel;</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; }</FONT>
<BR><FONT SIZE=2 FACE="Arial">new:</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; if ( poGDS-&gt;sInfoHeader.iBitCount == 24 )</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ... like before</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; else if ( poGDS-&gt;sInfoHeader.iBitCount == 32 )</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; {</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for ( i = 0, j = 0; i &lt; nBlockXSize; i++ )</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((GByte *) pImage)[i] = pabyScan[j + iBytesPerPixel - nBand - 1];</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; j += iBytesPerPixel;</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</FONT>
<BR><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; }</FONT>
<BR><FONT SIZE=2 FACE="Arial">...</FONT>
<BR><FONT SIZE=2 FACE="Arial">}</FONT>
<BR><FONT SIZE=2 FACE="Arial">the reason for the -1 in the 32 bit case:</FONT>
<BR><FONT SIZE=2 FACE="Arial">in 24 bit case for each pixel the array pabyScan looks like [BGR] pImage is assigned [RGB]</FONT>
<BR><FONT SIZE=2 FACE="Arial">the implementation for 32 implies that the order of pabyScan is [ABGR], but I think it should be [BGRA].</FONT>
<BR><FONT SIZE=2 FACE="Arial">I'm not quite sure about it, because I have only one 32 bit bitmap and I couldn't produce another example.</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">Has anybody else problems with 32 bit ..bmp's, or is my .bmp corrupt?</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">Thanks</FONT>
<BR><FONT SIZE=2 FACE="Arial">Roland</FONT>
</P>

<P><FONT SIZE=1 FACE="Arial">_________________________________</FONT>
<BR><FONT FACE="Arial"> </FONT>
<BR><FONT SIZE=1 FACE="Arial">Roland Winkler,</FONT>
<BR><FONT SIZE=1 FACE="Arial">Software Development</FONT>
<BR><FONT FACE="Arial"> </FONT>
<BR><FONT SIZE=1 FACE="Arial">Definiens AG</FONT>
<BR><FONT SIZE=1 FACE="Arial">Trappentreustrasse 1</FONT>
<BR><FONT SIZE=1 FACE="Arial">D-80339 Munich</FONT>
<BR><FONT FACE="Arial"> </FONT>
<BR><FONT SIZE=1 FACE="Arial">Fon: +49 (0)89 - 231180 - 56</FONT>
<BR><FONT SIZE=1 FACE="Arial">Fax: +49 (0)89 - 231180 - 90</FONT>
<BR><FONT FACE="Arial"> </FONT>
<BR><A HREF="mailto:rwinkler@definiens.com"><U><FONT COLOR="#0000FF" SIZE=1 FACE="Arial">mailto:rwinkler@definiens.com</FONT></U></A>
<BR><A HREF="http://www.definiens.com/"><U></U><U></U><U><FONT COLOR="#0000FF" SIZE=1 FACE="Arial">http://www.definiens.com</FONT></U></A>
<BR><FONT SIZE=1 FACE="Arial">_________________________________</FONT>
</P>

</BODY>
</HTML>