Pb with CreateCopy from a BMP to MEM

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Pb with CreateCopy from a BMP to MEM

Stephane Routelous
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
_______________________________________________
Gdal-dev mailing list
[hidden email]
http://xserve.flids.com/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Pb with CreateCopy from a BMP to MEM

Mario Beauchamp
Salut Stephane,

Stephane Routelous wrote:

> 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

I think FlushCache() is needed only when you write to disk, which is of course not the case for
a MEM dataset. BTW, I have ran into probs with MEM and GDAL Python (should we call it pyGDAL?):
in OpenEV, removing a MEM layer does not free its memory... have you observed this in C? Or it
may be OpenEV related only...

> Stephane Routelous
> http://www.exotk.org

Visited... I thought I was the only GDALer in Montreal! :)

A la prochaine!
--
Mario B.

_______________________________________________
Gdal-dev mailing list
[hidden email]
http://xserve.flids.com/mailman/listinfo/gdal-dev