[Gdal-dev] 8-bit grayscale

Sanges Michele Michele.Sanges at otomelara.it
Thu Jul 1 05:04:58 EDT 2004


Hi all,

I'm trying to develop an embedded application, which must have also the functionalities of a GIS. The application runs on Linux operating system (kernel 2.4.x, busybox filesystem); for the graphic side I use the Microwindows server (a small X server), and the GUI is writted  by means the FLTK library. I successfully compiled and installed GDAL 1.2.0 on my system.

Now, some beginner questions:

- when the method GetColorInterpretation() returns "Undefined" (for example, the "/aig/dblbnd.adf" test file), in order to represent the dataset in an 8?bit grayscale, I used the following conversion:

int nRasterCnt = poDataset->GetRasterCount();
int nRasterXSize =  poDataset->GetRasterXSize();
int nRasterYSize =  poDataset->GetRasterYSize();
double adfMinMax[2];
int bGotMin, bGotMax;
adfMinMax[0]=poBand->GetMinimum(&bGotMin);
adfMinMax[1]=poBand->GetMaximum(&bGotMax);

poBand->RasterIO(GF_Read, 0, 0, nXSize, nYSize, pImageData, nXSize, nYSize, poBand->GetRasterDataType(), 0, 0 );

for (int nByte = 0; nByte < nRasterCnt*nRasterXSize*nRasterYSize; nByte++)
{
	// convert in 0..255 range /(8?bit grayscale)
	int nApp = (255 / (adfMinMax[1] - adfMinMax[0])) * (*(pImageData + nByte) - adfMinMax[0]); 

	if (nApp < 0)
	{
		nApp = 0;
	}
	else if  (nApp > 255)
	{
		nApp = 255;
	}

	*(pData + nByte) =  nApp;
}

Fl_RGB_Image * RGBImg = new Fl_RGB_Image((uchar*)(pData), nRasterXSize, nRasterYSize, poDataset->GetRasterCount());

Using this conversion, the dblbnd.adf file is represented too dark, probabily because the dataset has many low values.
I can solve this problem reducing the range of 8 bit grayscale to [N..255] (N > 0), but how do you generally converted the dataset?

- Somebody is using the FLTK graphic library?

Thanks.



Michele Sanges




More information about the Gdal-dev mailing list