[gdal-dev] Fwd: How to reuse memory pointer of GDAL Memory driver

Pol Monsó Purtí lluna.nova at gmail.com
Mon Jun 6 01:58:44 PDT 2016


>
> The MEM format is one of the few that supports the AddBand() method. The
> AddBand() method supports DATAPOINTER, PIXELOFFSET and LINEOFFSET options
> to reference an existing memory array.
>

Thanks Even, you've cured me from my blindness. That's exactly what I need.
Thanks to all of you, this is perfect.

On Mon, Jun 6, 2016 at 10:55 AM, Even Rouault <even.rouault at spatialys.com>
wrote:

> On Monday 06 June 2016 10:45:47 Pol Monsó Purtí wrote:
> > THanks Mateusz,
> >
> > You're right. I'm trying it as we speak.
> >
> > In my case I have a std::vector<GByte*> of the 3 bands, where the GByte*
> > are allocated in the heap with new GByte[width*height]. I guess that
> won't
> > work because the three bands have to be one single memory chunk, am I
> > right? I guess the only solution is to switch to single band float and
> > merge rgb to float. I'd prefer not having to refactor the rest of the
> code.
>
>
> > Is it possible to have a different address for each band?
>
> Yes, create a dataset with 0 band and then add each band with the
> GDALDataset::AddBand() method
>
> See http://gdal.org/frmt_mem.html :
> """The MEM format is one of the few that supports the AddBand() method. The
> AddBand() method supports DATAPOINTER, PIXELOFFSET and LINEOFFSET options
> to
> reference an existing memory array."""
>
> >
> > All this is to support jpg as output. All the operations are done in my
> > GByte array and it's only at the end that I create the dataset and image.
> > At the moment I create a Tiff and finally createcopy to jpg.
> >
> > On Fri, Jun 3, 2016 at 9:10 PM, Mateusz Loskot <mateusz at loskot.net>
> wrote:
> > > On 3 June 2016 at 20:45, Pol Monsó Purtí <lluna.nova at gmail.com> wrote:
> > > > I've seen this mysterious article http://www.gdal.org/frmt_mem.html
> > >
> > > which
> > >
> > > > references the `DATAPOINTER` option. I've seen another reference
> > > > [here](
> > >
> > > https://lists.osgeo.org/pipermail/gdal-dev/2006-November/010583.html)
> > >
> > > > which does
> > >
> > >
> sprintf(filename,"MEM:::DATAPOINTER=%d,PIXELS=%d,LINES=%d,BANDS=1,DATATYPE
> > >
> =%d,PIXELOFFSET=0,LINEOFFSET=0,BANDOFFSET=0",datpt,pixels,lines,datatype);>
> > > >     dataset = GDALOpen(filename,GA_Update);
> > > >
> > > > How would this translate to c++?
> > >
> > > The line above is valid C++, isn't it.
> > > If you followed to Frank's answer [1], you'd see it slightly corrected
> > > but the technique remains the same.
> > >
> > > [1]
> https://lists.osgeo.org/pipermail/gdal-dev/2006-November/010603.html
> > >
> > > Best regards,
> > > --
> > > Mateusz Loskot, http://mateusz.loskot.net
>
> --
> Spatialys - Geospatial professional services
> http://www.spatialys.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20160606/b94ea2e5/attachment.html>


More information about the gdal-dev mailing list