[Gdal-dev] Creation of geotiff files with gdalwarp that have a transparent background

Jason R Hughes jason.hughes at elantech-inc.com
Wed Mar 24 15:04:25 EST 2004


> The underlying Warp API does contain mechanisms whereby an application
> might be able to maintain an alpha band properly, but the gdalwarp
> program has no mechanism to take advantage of it.  Furthermore, this
> hasn't really be used in the warp api so there may be issues I didn't
> anticipate.
> 
> Currently, the gdalwarp assumption is that nodata pixel values will be
> used to mark unset areas.  So that might involve picking a "background"
> value, like 0, to mark all unset areas.  INIT_DEST could be used to
> pre-apply this to the output file if a non-zero value were used.  Then
> the warper would replace all pixels for which a value exists.   No mechanism
> exists to ensure that the nodata value doesn't existing in the valid image
> data though.
> 
> I think it would make sense to modify gdalwarp to explicitly support
> transparency layers.  Some common forms I could imagine are:
> 
>   o An extra output band used to hold transparency.  Normally this would
>     be assigned 0 to unset pixels and 255 for set pixels.

This feature would be extremely useful for my situation as well.  I do not necessarily need the first more difficult option (the ability to create an additional transparent band) as I would only need the ability to filter out the aformentioned "nodata" value in the image.  Both methods would work for my situation though.  I could write the necessary code if need be.  I was thinking the most consistant to your way of doing things was to add another option in papszWarpOptions called REPLACE = TRUE or FALSE.

Then after the rasterdata is fetched in WarpRegionToBuffer() from the source file I would loop through the source data doing the following:

for(i = 0; i < (nWordSize * nSrcXSize * nSrcYSize); i++)
{

    BOOL noData = FALSE;

    for (int j = 0; j<psOptions->nBandCount; j++)
    {
        if(oWK.papabySrcImage[0][i + j * (nSrcXSize * nSrcYSize)] == initDest[j])
            noData = TRUE;
        else 
        {
            noData = FALSE;
            break;
        }
    }

    if(noData)
        for (int j = 0; j<psOptions->nBandCount; j++)
            oWK.papabySrcImage[0][i + j * (nSrcXSize * nSrcYSize)]++;
}


If this method seems utterly inefficient let me know.

Thanks,
Jason R. Hughes
Elantech, Inc. 
6411 Ivy Lane, Suite 300
Greenbelt, MD 20770
Phone: 301-486-0600
jason.hughes at elantech-inc.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20040324/44304b15/attachment.html


More information about the Gdal-dev mailing list