Hi,
  I am trying to use the GDALDataset::RasterIO method to read all the bands into a chunk of memory, and be able to access a pixel's values in all bands by using a [] operator on the memory.
  I got the sizes of the data types in all the bands, sum up to get the total data type size, then define a new type:
 
  typedef char NewType[totalSize]
; /* For exmaple, for a Byte-type RGB raster, the totalSize is 3 */
  pData = (NewType *)CPLMalloc(totalSize*nRows*nCols);
  poDataset->RasterIO(GF_Read, 0, 0, nCols, nRows,
                      pData, nCols, nRows,
                      vDataTypes[0],    
/* using the data type of band 1 */
                      nBands, aBandMap,
                      totalSize,       
/* The byte offset for one pixel is the totalSize, e.g., 3 for a RGB raster */
                      totalSize*nCols, 
/* The byte offset for one line */
                      totalSize/nBands 
/* The byte offset for one band is the size of the data type of one band, e.g, 1 for a RGB raster */
                     );

 
  NewType pixVal;
  memcpy(pixVal,
         pData[0],
/* This should return the pixel's values in all bands, e.g., a 3-byte array containing the RGB values */
         totalSize);


  However, this approach somehow didn't work. Anyone has an idea how to do this? Is it because the NewType isn't correct?
  Thanks.
--
---=== Qingfeng (Gene) Guan ===---
_______________________________________________
gdal-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to