<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi, <br>
&nbsp; 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 <i>[]</i> operator on the memory. <br>
&nbsp; 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: <br>
&nbsp; <b><br>
&nbsp; typedef char NewType[totalSize]</b>; <i>/* For exmaple, for a
Byte-type RGB raster, the totalSize is 3 */</i><br>
&nbsp; <b>pData = (NewType *)CPLMalloc(totalSize*nRows*nCols);<br>
&nbsp; poDataset-&gt;RasterIO(GF_Read, 0, 0, nCols, nRows,<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pData, nCols, nRows,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vDataTypes[0],&nbsp;&nbsp;&nbsp;&nbsp; </b><i>/* using the data type
of band 1 */</i><b><br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nBands, aBandMap,<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; totalSize,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </b><i>/* The byte offset for
one pixel is the totalSize, e.g., 3 for a RGB raster */</i><b><br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; totalSize*nCols,&nbsp; </b><i>/* The byte offset for
one line */</i><b><br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; totalSize/nBands&nbsp; </b><i>/* The byte offset for
one band is the size of the data type of one band, e.g, 1 for a RGB
raster */</i><b><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );</b><br>
&nbsp; <br>
&nbsp; <b>NewType pixVal;<br>
&nbsp; memcpy(pixVal,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pData[0], </b><i>/* This should return the pixel's values in
all bands, e.g., a 3-byte array containing the RGB values */</i><b><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; totalSize);</b><br>
<br>
&nbsp; However, this approach somehow didn't work. Anyone has an idea
how to do this? Is it because the NewType isn't correct?<br>
&nbsp; Thanks.
<div class="moz-signature">-- <br>
<title></title>
<font face="Courier New">---=== Qingfeng (Gene) Guan ===---</font><br>
</div>
</body>
</html>