[gdal-dev] TR: Load GDALDataset Into DIB

Ismael BELAAOUAD Ismael.BELAAOUAD at circet.fr
Sun Sep 1 23:01:33 PDT 2013


Hi David,

I have tested both solutions.
They work but finally I use another to improve performances.
I read the entire dataset with RasterIO and I reverse it when I display it with StretchDIBits function.

Best regards


De : David Strip [mailto:gdal at stripfamily.net]
Envoyé : samedi 31 août 2013 20:12
À : Ismael BELAAOUAD
Objet : Re: [gdal-dev] TR: Load GDALDataset Into DIB

glad to be of help.
Just curious -
did you read one scan line at a time, or did you read the whole array and reverse it?

(And your English is great - far better than my French.)

On 8/31/2013 11:50 AM, Ismael BELAAOUAD wrote:
Hi David,
Thank you for your response.
It's working!
Best regards

De : David Strip [mailto:gdal at stripfamily.net]
Envoyé : samedi 31 août 2013 04:51
À : Ismael BELAAOUAD
Objet : Re: [gdal-dev] TR: Load GDALDataset Into DIB

In your code you write:




               else

               {

                       for ( int iBand = 1 ,nBandsRead = 0 ; iBand <= nBands ; iBand ++ )

                       {

                               int iColorOffset;

                               switch( poDataset->GetRasterBand(iBand)->GetColorInterpretation() )

                               {

                                              // BGR

                                      case GCI_RedBand :

                                              iColorOffset = 2;

                                              break;

                                      case GCI_GreenBand :

                                              iColorOffset = 1;

                                              break;

                                      case GCI_BlueBand :

                                              iColorOffset = 0;

                                              break;

                                      default :

                                              continue ;

                               }

                               gdErr = poDataset->GetRasterBand(iBand)->RasterIO(

                                           GF_Read , 0 ,0 , poDataset->GetRasterXSize(), poDataset->GetRasterYSize(),

                                           ((LPBYTE)pBits) + iColorOffset ,bmi.Header.biWidth,bmi.Header.biHeight,

                                           GDT_Byte, 3, nScanSize );

                               nBandsRead ++;

                       }



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 GDAL tutorial<http://www.gdal.org/gdal_tutorial.html>, only one scan line at a time is being read -



        float *pafScanline;

        int   nXSize = poBand->GetXSize<http://www.gdal.org/classGDALRasterBand.html#a46f78e79da622039a670107ae5a94f02>();



        pafScanline = (float *) CPLMalloc(sizeof(float)*nXSize);

        poBand->RasterIO<http://www.gdal.org/classGDALRasterBand.html#a5497e8d29e743ee9177202cb3f61c3c7>( GF_Read<http://www.gdal.org/gdal_8h.html#ae602fdf251b6b0210a5af5a7cf7623b3ab2abfe1fa6e34018b8c692eb48f35cb5>, 0, 0, nXSize, 1,

                          pafScanline, nXSize, 1, GDT_Float32<http://www.gdal.org/gdal_8h.html#a22e22ce0a55036a96f652765793fb7a4af5cbd2f96abffd9ac061fc0dced5cbba>,

                          0, 0 );


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.

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.

Hope this helps.













-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20130902/67143ebf/attachment-0001.html>


More information about the gdal-dev mailing list