<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";
color:black;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
pre
{mso-style-priority:99;
mso-style-link:"Préformaté HTML Car";
margin:0cm;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";
color:black;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
{mso-style-priority:99;
mso-style-link:"Texte de bulles Car";
margin:0cm;
margin-bottom:.0001pt;
font-size:8.0pt;
font-family:"Tahoma","sans-serif";
color:black;}
span.PrformatHTMLCar
{mso-style-name:"Préformaté HTML Car";
mso-style-priority:99;
mso-style-link:"Préformaté HTML";
font-family:Consolas;
color:black;}
p.Preacute, li.Preacute, div.Preacute
{mso-style-name:"Pré\,formaté\,HTML";
mso-style-link:"Pré1\,formaté1\,HTML Car1";
margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";
color:black;}
span.Preacute1
{mso-style-name:"Pré1\,formaté1\,HTML Car1";
mso-style-priority:99;
mso-style-link:"Pré\,formaté\,HTML";
font-family:Consolas;
color:black;}
span.keywordtype
{mso-style-name:keywordtype;}
span.keyword
{mso-style-name:keyword;}
span.EmailStyle23
{mso-style-type:personal;
font-family:"Calibri","sans-serif";
color:#1F497D;}
span.EmailStyle24
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
span.TextedebullesCar
{mso-style-name:"Texte de bulles Car";
mso-style-priority:99;
mso-style-link:"Texte de bulles";
font-family:"Tahoma","sans-serif";
color:black;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body bgcolor="white" lang="FR" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Hi David,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">I have tested both solutions.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">They work but finally I use another to improve performances.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">I read the entire dataset with RasterIO and I reverse it when I display it with StretchDIBits function.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Best regards<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext">De :</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext"> David Strip [mailto:gdal@stripfamily.net]
<br>
<b>Envoyé :</b> samedi 31 août 2013 20:12<br>
<b>À :</b> Ismael BELAAOUAD<br>
<b>Objet :</b> Re: [gdal-dev] TR: Load GDALDataset Into DIB<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">glad to be of help.<br>
Just curious - <br>
did you read one scan line at a time, or did you read the whole array and reverse it?<br>
<br>
(And your English is great - far better than my French.)<br>
<br>
On 8/31/2013 11:50 AM, Ismael BELAAOUAD wrote: <o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Hi David,</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Thank you for your response.</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">It’s working!</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Best regards</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> </span><o:p></o:p></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext">De :</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext"> David Strip [<a href="mailto:gdal@stripfamily.net">mailto:gdal@stripfamily.net</a>]
<br>
<b>Envoyé :</b> samedi 31 août 2013 04:51<br>
<b>À :</b> Ismael BELAAOUAD<br>
<b>Objet :</b> Re: [gdal-dev] TR: Load GDALDataset Into DIB</span><o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">In your code you write:<br>
<br>
<br>
<br>
<o:p></o:p></p>
<pre> else<o:p></o:p></pre>
<pre> {<o:p></o:p></pre>
<pre> for ( int iBand = 1 ,nBandsRead = 0 ; iBand <= nBands ; iBand ++ )<o:p></o:p></pre>
<pre> {<o:p></o:p></pre>
<pre> int iColorOffset;<o:p></o:p></pre>
<pre> switch( poDataset->GetRasterBand(iBand)->GetColorInterpretation() )<o:p></o:p></pre>
<pre> {<o:p></o:p></pre>
<pre> // BGR<o:p></o:p></pre>
<pre> case GCI_RedBand :<o:p></o:p></pre>
<pre> iColorOffset = 2;<o:p></o:p></pre>
<pre> break;<o:p></o:p></pre>
<pre> case GCI_GreenBand :<o:p></o:p></pre>
<pre> iColorOffset = 1;<o:p></o:p></pre>
<pre> break;<o:p></o:p></pre>
<pre> case GCI_BlueBand :<o:p></o:p></pre>
<pre> iColorOffset = 0;<o:p></o:p></pre>
<pre> break;<o:p></o:p></pre>
<pre> default :<o:p></o:p></pre>
<pre> continue ;<o:p></o:p></pre>
<pre> }<o:p></o:p></pre>
<pre> gdErr = poDataset->GetRasterBand(iBand)->RasterIO(<o:p></o:p></pre>
<pre> GF_Read , 0 ,0 , poDataset->GetRasterXSize(), poDataset->GetRasterYSize(),<o:p></o:p></pre>
<pre> ((LPBYTE)pBits) + iColorOffset ,bmi.Header.biWidth,bmi.Header.biHeight,<o:p></o:p></pre>
<pre> GDT_Byte, 3, nScanSize );<o:p></o:p></pre>
<pre> nBandsRead ++;<o:p></o:p></pre>
<pre> }<o:p></o:p></pre>
<pre> <o:p></o:p></pre>
<pre>The key is the GetRasterBand call. By passing in poDataset->GetRasterYSize(), you are asking to read all the rows of the raster. If you look at the example in the <a href="http://www.gdal.org/gdal_tutorial.html">GDAL tutorial</a>, only one scan line at a time is being read - <o:p></o:p></pre>
<pre> <o:p></o:p></pre>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<pre> <span class="keywordtype">float</span> *pafScanline;<o:p></o:p></pre>
<pre> <span class="keywordtype">int</span> nXSize = poBand-><a href="http://www.gdal.org/classGDALRasterBand.html#a46f78e79da622039a670107ae5a94f02" title="Fetch XSize of raster.">GetXSize</a>();<o:p></o:p></pre>
<pre> <o:p></o:p></pre>
<pre> pafScanline = (<span class="keywordtype">float</span> *) CPLMalloc(<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>)*nXSize);<o:p></o:p></pre>
<pre> poBand-><a href="http://www.gdal.org/classGDALRasterBand.html#a5497e8d29e743ee9177202cb3f61c3c7" title="Read/write a region of image data for this band.">RasterIO</a>( <a href="http://www.gdal.org/gdal_8h.html#ae602fdf251b6b0210a5af5a7cf7623b3ab2abfe1fa6e34018b8c692eb48f35cb5">GF_Read</a>, 0, 0, nXSize, 1, <o:p></o:p></pre>
<pre> pafScanline, nXSize, 1, <a href="http://www.gdal.org/gdal_8h.html#a22e22ce0a55036a96f652765793fb7a4af5cbd2f96abffd9ac061fc0dced5cbba">GDT_Float32</a>, <o:p></o:p></pre>
<pre> 0, 0 );<o:p></o:p></pre>
<pre> <o:p></o:p></pre>
</div>
</blockquote>
<p class="MsoNormal">In order to read the data in reverse order, you need to read one scan line at a time. Start with the last scan line, read it into the DIB array (pBits), then increment pBits by the size of the scan line, and read the next scan line.<br>
<br>
Perhaps a simpler way at the expense of using more memory, is to read the array just as you are doing, then allocate a new array and copy the original array in reverse order. You then need to associate the second (reversed) array with your bitmap.<br>
<br>
Hope this helps.<o:p></o:p></p>
<div>
<pre> <o:p></o:p></pre>
</div>
<pre> <o:p></o:p></pre>
<pre> <o:p></o:p></pre>
<p class="MsoNormal"> <o:p></o:p></p>
<pre> <o:p></o:p></pre>
<pre> <o:p></o:p></pre>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal" style="margin-bottom:12.0pt"><o:p> </o:p></p>
</div>
</body>
</html>