[gdal-dev] Troubleshooting palette management. Potential bug in palette for overviews?

Even Rouault even.rouault at spatialys.com
Thu Nov 24 08:01:55 PST 2016


On jeudi 24 novembre 2016 16:51:59 CET Daniele Romagnoli wrote:
> Doh!
> Thanks for the feedback, Even. (Indeed it seemed strange to me that nobody
> had ever noticed before)

Not that much regarding software using GDAL since if you don't explicitly request the 
overview bands/datasets but rather use the subsampling RasterIO() calls, you'll never work 
directly with the color table of the overviews but still use the one of the main dataset (or 
even if you request the overviews directly I guess in most cases applications don't bother 
checking if the color table of the overview). In GDAL, overviews conceptually share the same 
palette than the main image. Otherwise subsampling RasterIO() will return values of the 
overview palette that will be interpreted with the palette of the main image. You can imagine 
the fun visual effects if the palette are not the same... So this is assumed, but not checked. 

Could be worth fixing that if that cause issues (apparently in your use case at least), but I'd be 
interested by information of what is the standard/recommanded/best-practice-in-the-
industry/etc... formulas to use for the mapping between the [0,255] and [0,65535] ranges.

> 
> Best Regards,
> Daniele
> 
> On Thu, Nov 24, 2016 at 1:35 PM, Even Rouault <even.rouault at spatialys.com>
> 
> wrote:
> > Daniele,
> > 
> > 
> > 
> > This is indeed an inconsistency I spotted a long time ago :
> > 
> > https://trac.osgeo.org/gdal/ticket/2213
> > 
> > 
> > 
> > Nobody was apparently sufficiently annoyed by this to fix it. Actually I
> > see I proposed a patch. Was probably waiting for feedback. I'm not sure if
> > there's a standardized way of converting between the [0,255] and [0,65535]
> > ranges.
> > 
> > 
> > 
> > Even
> > 
> > > Hi List,
> > > 
> > > I'm investigating on a issue I have with a paletted image with
> > > overviews,
> > > 
> > > using java ImageIO tiff reader (wait... I know on this list we discuss
> > > 
> > > about GDAL topics :) ).
> > > 
> > > I'm trying to better understand palette interpretation and palette
> > 
> > storing
> > 
> > > on tags and how they are handled by GDAL.
> > > 
> > > 
> > > 
> > > From TIFF specifications, colormap entries are stored as short values.
> > > 
> > > I have a sample file with this color tab (as reported by gdalinfo).
> > > 
> > > 
> > > 
> > > Color Table (RGB with 256 entries)
> > > 
> > > 0: *164*,164,164,255
> > > 
> > > 1: *255*,255,255,255
> > > 
> > > 2: 0,0,0,255
> > > 
> > > 3: 0,0,0,255
> > > 
> > > .... repeat 0,0,0,255 to the end.
> > > 
> > > 
> > > 
> > > Using an Hex editor or AsTiffTagViewer, I can see the byte values of the
> > > 
> > > colormap as stored on the file.
> > > 
> > > For the first 4 mappings of the colortable the Red components are:
> > > 
> > > *A4 A4* *FF FF* 00 00 00 00
> > > 
> > > (8 bytes = 4 shorts)
> > > 
> > > 
> > > 
> > > As far as I have understood, this is related to that part of the
> > > 
> > > specification (quoting it, section 5):
> > > 
> > > 
> > > 
> > > 
> > > 
> > > *In a TIFF ColorMap, all the Red values come first, followed by the
> > > Green
> > > 
> > > values, then the Blue values. In the ColorMap, black is represented by
> > > 
> > > 0,0,0 and white is represented by 65535, 65535, 65535*
> > > 
> > > 
> > > 
> > > So the second entry of the map, being white (255, 255, 255) has its red
> > > 
> > > value stored as 65535 = *FF FF *whilst the first color (164,164,164) has
> > > 
> > > its red value stored as 42148 = *A4 A4*
> > > 
> > > 
> > > 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20161124/6bd5ca71/attachment-0001.html>


More information about the gdal-dev mailing list