[gdal-dev] GDALWarp API and paletted images

Thomas Sevaldrud thomas at silentwings.no
Thu Jun 11 08:09:01 PDT 2015


Great, thanks!

I tried this, but got only a red image as result, so I guess only the first
channel was used.

This is the relevant code, where _ds is the input paletted data set

vrtDS = vrtDriver->Create("", origW, origH, 3, GDT_Byte, NULL);
double geoTransform[6];
_ds->GetGeoTransform(geoTransform);
vrtDS->SetGeoTransform(geoTransform);
GDALSetProjection(vrtDS, _srcProjectionWKT.c_str());

GDALRasterBand* srcBand = _ds->GetRasterBand(1);

vrtDS->AddBand(GDT_Byte, NULL);
vrtDS->AddBand(GDT_Byte, NULL);
vrtDS->AddBand(GDT_Byte, NULL);
VRTSourcedRasterBand* vrtRBand =
(VRTSourcedRasterBand*)vrtDS->GetRasterBand(1);
VRTSourcedRasterBand* vrtGBand =
(VRTSourcedRasterBand*)vrtDS->GetRasterBand(2);
VRTSourcedRasterBand* vrtBBand =
(VRTSourcedRasterBand*)vrtDS->GetRasterBand(3);
vrtRBand->AddComplexSource(srcBand, -1, -1, -1, -1, -1, -1, -1, -1, 0.0,
1.0, VRT_NODATA_UNSET, 1);
vrtGBand->AddComplexSource(srcBand, -1, -1, -1, -1, -1, -1, -1, -1, 0.0,
1.0, VRT_NODATA_UNSET, 2);
vrtBBand->AddComplexSource(srcBand, -1, -1, -1, -1, -1, -1, -1, -1, 0.0,
1.0, VRT_NODATA_UNSET, 3);

Is there anything I have missed in the setup here?

- Thomas



On Tue, Jun 9, 2015 at 1:44 PM, Even Rouault <even.rouault at spatialys.com>
wrote:

> Thomas,
> >
> > I'm using the GDALWarp api from C++ to reproject and cut various input
> > images. In general this works very well for my purposes, except that for
> > paletted images I have to use NearestNeighbour resampling,
> >
> > I would like to use Bilinear or higher order resampling, and wonder if
> > there is any way to expand a paletted image to true RGB during the warp
> > process, so I can use these resampling methods.
>
> No, you must use an intermediate step before.
>
> >
> > Alternatively, is there a way to do this conversion (from code) before
> the
> > warp without having to run through the entire image in memory?
>
> You can use a in-memory VRT dataset to do on-the-fly expansion to RGB.
>
> With the AddComplexSource() method of VRTSourcedRasterBand class:
>
>     CPLErr         AddComplexSource( GDALRasterBand *poSrcBand,
>                                      int nSrcXOff=-1, int nSrcYOff=-1,
>                                      int nSrcXSize=-1, int nSrcYSize=-1,
>                                      int nDstXOff=-1, int nDstYOff=-1,
>                                      int nDstXSize=-1, int nDstYSize=-1,
>                                      double dfScaleOff=0.0,
>                                      double dfScaleRatio=1.0,
>                                      double dfNoDataValue =
> VRT_NODATA_UNSET,
>                                      int nColorTableComponent = 0);
>
> Set nColorTableComponent to 1,2,3 for respectively R,G,B. This is what
> gdal_translate will do if you use "gdal_translate -of VRT -expand rgb
> pct.tif
> out.vrt"
>
> Even
>
> --
> Spatialys - Geospatial professional services
> http://www.spatialys.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20150611/ba8c7f03/attachment.html>


More information about the gdal-dev mailing list