This is how i do it. I hope it is what you want:) GByte *myGdalScanData=(GByte *) CPLMalloc(theRasterViewport->drawableAreaXDim*theRasterViewport->drawableAreaYDim*4); if (myGdalScanData == NULL) { std::cout<<"scan data is null! "; } else { CPLErr myErr = GDALRasterIO( myGdalRedBand, GF_Read, theRasterViewport->rectXOffset, theRasterViewport->rectYOffset, theRasterViewport->clippedWidth, theRasterViewport->clippedHeight, myGdalScanData+0, theRasterViewport->drawableAreaXDim, theRasterViewport->drawableAreaYDim, GDT_Byte, 4,theRasterViewport->drawableAreaXDim *4 ); myErr = GDALRasterIO( myGdalGreenBand, GF_Read, theRasterViewport->rectXOffset, theRasterViewport->rectYOffset, theRasterViewport->clippedWidth, theRasterViewport->clippedHeight, myGdalScanData+1, theRasterViewport->drawableAreaXDim, theRasterViewport->drawableAreaYDim, GDT_Byte, 4,theRasterViewport->drawableAreaXDim* 4 ); myErr = GDALRasterIO( myGdalBlueBand, GF_Read, theRasterViewport->rectXOffset, theRasterViewport->rectYOffset, theRasterViewport->clippedWidth, theRasterViewport->clippedHeight, myGdalScanData+2, theRasterViewport->drawableAreaXDim, theRasterViewport->drawableAreaYDim, GDT_Byte, 4,theRasterViewport->drawableAreaXDim * 4 ); myErr = GDALRasterIO( myGdalBlueBand, GF_Read, theRasterViewport->rectXOffset, theRasterViewport->rectYOffset, theRasterViewport->clippedWidth, theRasterViewport->clippedHeight, myGdalScanData+3, theRasterViewport->drawableAreaXDim, theRasterViewport->drawableAreaYDim, GDT_Byte, 4,theRasterViewport->drawableAreaXDim * 4 ); if (myErr != CPLE_None) { std::cout<< "RaterIO error: " << CPLGetLastErrorMsg(); } }
2008/10/19 <[EMAIL PROTECTED]> > I have a BGRA buffer in memory, and a multi-band RGBA TIF image. Is it > possible to use RasterIO to read in values from each band and neatly > interleave them in my buffer. > > For example if I was loading an RGBA image I am hoping to be able to make 4 > separate RasterIO calls. > > Assuming a BGRA image looks like: > > 0 - blue byte > 8 - green byte > 16 - red byte > 24 - alpha byte > 32 - blue byte > 40 - green byte > 48 - red byte > 56 - alpha byte > 64 - .... > > The first RasterIO call would read in the blue values and insert them at 0, > 32, 64, etc making it look like: > > 0 - blue byte > 8 - > 16 - > 24 - > 32 - blue byte > 40 - > 48 - > 56 - > 64 - .... > > The second RasterIO call would read the green values and insert them at 8, > 40, etc making it look like: > > 0 - blue byte > 8 - green byte > 16 - > 24 - > 32 - blue byte > 40 - green byte > 48 - > 56 - > 64 - .... > > Rinse and repeat for red and alpha. > > Is this possible, or is there a much much simpler way that I'm > overlooking? I've been looking at the paramaters for RasterIO but can't > seem to get it to work. I do understand that I can just read the values > into a separate buffer and memcpy them over to my image buffer. I was > trying to minimize the total number of times the same data has to be copied. > > Thanks for the help. > > Craig > > > > _______________________________________________ > gdal-dev mailing list > gdal-dev@lists.osgeo.org > http://lists.osgeo.org/mailman/listinfo/gdal-dev >
_______________________________________________ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev