GDBByteChanIO() automatically performs shrinking/zooming between windows of different sizes, mapping between buffer and generic database channels, and data type conversions.
See Also: GDBIntChanIO(), GDBRealChanIO()
void GDBByteChanIO(fpGDB, nFunc, nXOff, nYOff, nXSize, nYSize,
pabyImgBuf, nBufXSize, nBufYSize,
nBufChanCount, panChanMap);
FILE *fpGDB;
File pointer of generic database file to access.
int nFunc;
Function to perform. This should be GDB_READ, to read
from the file into pabyImgBuf, or GDB_WRITE to write from
pabyImgBuf into the file.
int nXOff;
X (pixel) offset to imagery window in file.
int nYOff;
Y (line) offset to imagery window in file.
int nXSize;
X (pixel) size of imagery window in file.
int nYSize;
Y (line) size of imagery window in file.
uchar *pabyImgBuf;
Buffer of byte image data to read/write.
On a read, this buffer receives the imagery data read
from the file. On a write, this buffer contains the
imagery data to write into the file. The image held in
pabyImgBuf has dimensions nBufYSize lines, each line made
up of nBufXSize pixels, each pixel having nBufChanCount
channels.
int nBufXSize;
X (pixel) size of imagery window in buffer.
int nBufYSize;
Y (line) size of imagery window in buffer.
int nBufChanCount;
Number of channel values in imgbuf[].
int *panChanMap;
Channel mapping buffer. The list of channels to read,
or write. This array should contain nBufChanCount entries.
For example: An image window with dimensions two lines by three pixels with two channels can conceptually be arranged as follows:
a11 a12 a13 b11 b12 b13
a21 a22 a23 b21 b22 b23
When packed into pabyImgBuf, data would be arranged as follows:
a11 b11 a12 b12 a13 b13 a21 b21 a22 b22 a23 b23
Channel mapping is determined by the panChanMap buffer where panChanMap[n] holds the channel on disk which is associated with the n'th channel in buffer pabyImgBuf. The panChanMap array has length nBufChanCount.
For example: Suppose the database file has 12 channels, and pabyImgBuf has 3 channels. The first channel in pabyImgBuf is mapped to channel 7 on disk, the second to 11, and the third to 2. panChanMap would be:
panChanMap[0] = 7
panChanMap[1] = 11
panChanMap[2] = 2
The passed buffer pabyImgBuf is assumed to contain an image of the size defined by parameters nBufXSize by nBufYSize.
If the window size on the file and the image size in pabyImgBuf do not match then GDBByteChanIO() will automatically shrink or zoom the image data. Shrinking is done using decimation while zooming is done using replication. In most applications however, data is used at 'full' (1 to 1) resolution where nXSize=nBufXSize and nYSize=nBufYSize.
The caller of GDBByteChanIO() does not need know the type of data each channel on the file contains since GDBByteChanIO() automatically converts between byte and other data types. This gives the appearance that all channels on the file are 8 bit.
As a general rule, when one data type is converted to another, input values which are less than or greater than the minimum or maximum allowed output values are set to the minimum or maximum output value. Real values are truncated to integer values, where necessary. Scaling and rounding is NOT performed.
The following table shows how a pixel value N in the database is converted to and from a byte value in the buffer, for each of the four data types.
+---------------+-----------------------+-----------------------+ | GDBByteChanIO | READ | WRITE | +---------------+---------------+-------+---------------+-------+ | data | file | buffer| buffer | file | | type | input | output| input | output| +---------------+---------------+-------+---------------+-------+ | 8-bit | | | | | | unsigned | 0<=N<=255 | N | 0<=N<=255 | N | | integer | | | | | +---------------+---------------+-------+---------------+-------+ | 16-bit | 0> N | 0 | | | | signed | 0<=N<=255 | N | 0<=N<=255 | N | | integer | N >255 | 255 | | | +---------------+---------------+-------+---------------+-------+ | 16-bit | 0> N | 0 | | | | unsigned | 0<=N<=255 | N | 0<=N<=255 | N | | integer | N >255 | 255 | | | +---------------+---------------+-------+---------------+-------+ | 32-bit | 0> N | 0 | | | | real | 0<=N<=255 | int(N)| 0<=N<=255 |real(N)| | | N >255 | 255 | | | +---------------+---------------+-------+---------------+-------+
. . .
FILE *fp;
int line,pixs,lins,chns,i;
unsigned int pix;
unsigned char imagry[10000];
char dbname[64];
int inchan,outchan;
. . .
fp = GDBOpen (dbname,"r+"); | Open the PCIDSK file
GDBSizeInfo(fp,&pixs,&lins,&chns); | Get database size
inchan = 3;
outchan = 4;
for (line = 1; line <= lins; line++)
| Loop through each line: read, process and write
{
GDBByteChanIO (fp,GDB_READ,0,line-1,pixs,1,
imagry,pixs,1,1,&inchan);
for (i = 0; i < pixs; i++)
{
pix = imagry[i];
pix *= 2;
if (pix > 255) pix = 255;
imagry[i] = pix;
}
GDBByteChanIO (idb_fp,GDB_WRITE,0,line-1,pixs,1,
imagry,pixs,1,1,&outchan);
}
. . .
FILE *fp;
int chnmap[3],window[4];
char dbname[64];
unsigned char bimg[6144]; | 6144=32*64*3
. . .
fp = GDBOpen(dbname,"r+"); | Open the PCIDSK file
window[0] = 123; | X offset
window[1] = 111; | Y offset
window[2] = 128; | X size
window[3] = 128; | Y size
chnmap[0] = 7;
chnmap[1] = 3;
chnmap[2] = 5;
CheckChan (fp,"CHNMAP",CHNMAP,3);
| Check that window is valid and channels exist
CheckWin (fp,"WINDOW",window,chnmap);
GDBByteChanIO(fp,GDB_READ,window[0],window[1],window[2],
window[3],bimg,32,64,3,chnmap);
| Get the window off the database
. . .