<div dir="ltr">Great, thanks!<div><br></div><div>I tried this, but got only a red image as result, so I guess only the first channel was used. </div><div><br></div><div>This is the relevant code, where _ds is the input paletted data set </div><div><br></div><div><div><span class="" style="white-space:pre"> </span>vrtDS = vrtDriver->Create("", origW, origH, 3, GDT_Byte, NULL);</div><div><span class="" style="white-space:pre"> </span>double geoTransform[6];</div><div><span class="" style="white-space:pre"> </span>_ds->GetGeoTransform(geoTransform);</div><div><span class="" style="white-space:pre"> </span>vrtDS->SetGeoTransform(geoTransform);</div><div><span class="" style="white-space:pre"> </span>GDALSetProjection(vrtDS, _srcProjectionWKT.c_str());</div><div><br></div><div><span class="" style="white-space:pre"> </span>GDALRasterBand* srcBand = _ds->GetRasterBand(1);</div><div><br></div><div><span class="" style="white-space:pre"> </span>vrtDS->AddBand(GDT_Byte, NULL);</div><div><span class="" style="white-space:pre"> </span>vrtDS->AddBand(GDT_Byte, NULL);</div><div><span class="" style="white-space:pre"> </span>vrtDS->AddBand(GDT_Byte, NULL);</div><div><span class="" style="white-space:pre"> </span>VRTSourcedRasterBand* vrtRBand = (VRTSourcedRasterBand*)vrtDS->GetRasterBand(1);</div><div><span class="" style="white-space:pre"> </span>VRTSourcedRasterBand* vrtGBand = (VRTSourcedRasterBand*)vrtDS->GetRasterBand(2);</div><div><span class="" style="white-space:pre"> </span>VRTSourcedRasterBand* vrtBBand = (VRTSourcedRasterBand*)vrtDS->GetRasterBand(3);</div><div><span class="" style="white-space:pre"> </span>vrtRBand->AddComplexSource(srcBand, -1, -1, -1, -1, -1, -1, -1, -1, 0.0, 1.0, VRT_NODATA_UNSET, 1);</div><div><span class="" style="white-space:pre"> </span>vrtGBand->AddComplexSource(srcBand, -1, -1, -1, -1, -1, -1, -1, -1, 0.0, 1.0, VRT_NODATA_UNSET, 2);</div><div><span class="" style="white-space:pre"> </span>vrtBBand->AddComplexSource(srcBand, -1, -1, -1, -1, -1, -1, -1, -1, 0.0, 1.0, VRT_NODATA_UNSET, 3);</div></div><div><br></div><div>Is there anything I have missed in the setup here?</div><div><br></div><div>- Thomas</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jun 9, 2015 at 1:44 PM, Even Rouault <span dir="ltr"><<a href="mailto:even.rouault@spatialys.com" target="_blank">even.rouault@spatialys.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thomas,<br>
<span class="">><br>
> I'm using the GDALWarp api from C++ to reproject and cut various input<br>
> images. In general this works very well for my purposes, except that for<br>
> paletted images I have to use NearestNeighbour resampling,<br>
><br>
> I would like to use Bilinear or higher order resampling, and wonder if<br>
> there is any way to expand a paletted image to true RGB during the warp<br>
> process, so I can use these resampling methods.<br>
<br>
</span>No, you must use an intermediate step before.<br>
<span class=""><br>
><br>
> Alternatively, is there a way to do this conversion (from code) before the<br>
> warp without having to run through the entire image in memory?<br>
<br>
</span>You can use a in-memory VRT dataset to do on-the-fly expansion to RGB.<br>
<br>
With the AddComplexSource() method of VRTSourcedRasterBand class:<br>
<br>
CPLErr AddComplexSource( GDALRasterBand *poSrcBand,<br>
int nSrcXOff=-1, int nSrcYOff=-1,<br>
int nSrcXSize=-1, int nSrcYSize=-1,<br>
int nDstXOff=-1, int nDstYOff=-1,<br>
int nDstXSize=-1, int nDstYSize=-1,<br>
double dfScaleOff=0.0,<br>
double dfScaleRatio=1.0,<br>
double dfNoDataValue = VRT_NODATA_UNSET,<br>
int nColorTableComponent = 0);<br>
<br>
Set nColorTableComponent to 1,2,3 for respectively R,G,B. This is what<br>
gdal_translate will do if you use "gdal_translate -of VRT -expand rgb pct.tif<br>
out.vrt"<br>
<span class="HOEnZb"><font color="#888888"><br>
Even<br>
<br>
--<br>
Spatialys - Geospatial professional services<br>
<a href="http://www.spatialys.com" target="_blank">http://www.spatialys.com</a><br>
</font></span></blockquote></div><br></div>