[Gdal-dev] Pb with CreateCopy from a BMP to MEM
Stephane Routelous
route at cae.com
Thu Jun 16 17:40:29 EDT 2005
Hi Mailing List,
I found a problem (?) in GDAL 1.2.6
I'm create a copy of an image in memory (I tested BMP -> MEM)
The problem is that if I don't specify FlushCache to a band, the
ReadBlock return a empty (zero-ed) buffer
To reproduce, run the following code with commenting out the
"poBand->FlushCache();" line
Perhaps it is a mistake at my side ?
Thanks,
Stephane Routelous
http://www.exotk.org
int main(int argc, char* argv[])
{
GDALAllRegister();
GDALDataset* realDataSet = (GDALDataset *) GDALOpen(
"T:\\airport_fence.bmp", GA_ReadOnly );
if ( realDataSet)
{
GDALDriver *memDriver =
GetGDALDriverManager()->GetDriverByName("MEM");
GDALDataset* memDataSet =
memDriver->CreateCopy("MEM:::",realDataSet,FALSE,NULL,NULL,NULL);
GDALClose(realDataSet);
if ( memDataSet )
{
int sx = memDataSet->GetRasterXSize();
int sy = memDataSet->GetRasterYSize();
GDALRasterBand *poBand =
memDataSet->GetRasterBand( 1 );
///////////////////////////////////////////////////////
// Comment the following line out
//
//poBand->FlushCache();
//
///////////////////////////////////////////////////////
unsigned char* buffer = (unsigned
char*)malloc(sx*sizeof(unsigned char));
poBand->RasterIO( GF_Read, 0, 0, sx, 1,
buffer, sx, 1, GDT_Byte,
0, 0 );
for ( unsigned int i = 0 ; i < sx ; i++ )
{
cout << (int) buffer[i] << " " ;
}
cout << endl << endl << endl ;
poBand->ReadBlock(0,0,buffer);
for ( i = 0 ; i < sx ; i++ )
{
cout << (int) buffer[i] << " " ;
}
}
}
return 0;
}
Output with poBand->FlushCache();
33 33 21 37 21 33 29 29 29 29 51 61 18 29 42 33 37 37 42 51 42 29 29 46
29 21 37
21 42 18 37 37 29 25 25 33 10 33 33 14 29 42 33 37 21 37 21 33 25 33 29
33 37 6
1 33 18 37 37 33 33 42 46 46 33 25 42 42 18 29 33 29 29 25 42 29 25 25
37 10 29
37 21 14 51 33 33 37 25 29 25 29 29 29 29 33 33 61 46 14 33 42 33 37 37
46 51 37
25 37 46 21 25 37 21 42 18 42 33 29 25 33 18 21 37 29 10 46 33
33 33 21 37 21 33 29 29 29 29 51 61 18 29 42 33 37 37 42 51 42 29 29 46
29 21 37
21 42 18 37 37 29 25 25 33 10 33 33 14 29 42 33 37 21 37 21 33 25 33 29
33 37 6
1 33 18 37 37 33 33 42 46 46 33 25 42 42 18 29 33 29 29 25 42 29 25 25
37 10 29
37 21 14 51 33 33 37 25 29 25 29 29 29 29 33 33 61 46 14 33 42 33 37 37
46 51 37
25 37 46 21 25 37 21 42 18 42 33 29 25 33 18 21 37 29 10 46 33
Output without poBand->FlushCache();
33 33 21 37 21 33 29 29 29 29 51 61 18 29 42 33 37 37 42 51 42 29 29 46
29 21 37
21 42 18 37 37 29 25 25 33 10 33 33 14 29 42 33 37 21 37 21 33 25 33 29
33 37 6
1 33 18 37 37 33 33 42 46 46 33 25 42 42 18 29 33 29 29 25 42 29 25 25
37 10 29
37 21 14 51 33 33 37 25 29 25 29 29 29 29 33 33 61 46 14 33 42 33 37 37
46 51 37
25 37 46 21 25 37 21 42 18 42 33 29 25 33 18 21 37 29 10 46 33
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0
0 0 0 0 0 0 0 0 Press any key to continue
More information about the Gdal-dev
mailing list