<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 24, 2016 at 5:01 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u>
<div style="font-family:monospace;font-size:9pt;font-weight:400;font-style:normal"><span class="gmail-">
<p style="margin:0px;text-indent:0px">On jeudi 24 novembre 2016 16:51:59 CET Daniele Romagnoli wrote:</p>
<p style="margin:0px;text-indent:0px">> Doh!</p>
<p style="margin:0px;text-indent:0px">> Thanks for the feedback, Even. </p></span></div></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="font-family:monospace;font-size:9pt;font-weight:400;font-style:normal"><span class="gmail-"><p style="margin:0px;text-indent:0px">(Indeed it seemed strange to me that nobody<span style="font-family:monospace;font-size:9pt"> had ever noticed before)</span></p></span></div></blockquote><div>Sorry, what I meant with that was that I didn't see that ticket before sending my email so it seemed strange to me that nobody noticed the palette math weirdness :)</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="font-family:monospace;font-size:9pt;font-weight:400;font-style:normal"><span class="gmail-">
<p style="margin:0px;text-indent:0px"> </p>
</span><p style="margin:0px;text-indent:0px">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).</p></div></blockquote><div><br></div><div>As far as I can see, the TIFFImageReader parses the metadata information based on imageIndex (so overview number). I will double check if things were working differently in the colormap topic before our changes/optimizations to this class.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="font-family:monospace;font-size:9pt;font-weight:400;font-style:normal"><p style="margin:0px;text-indent:0px"> 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. </p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">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-<wbr>practice-in-the-industry/etc..<wbr>. formulas to use for the mapping between the [0,255] and [0,65535] ranges.</p><div><div class="gmail-h5">
<p style="margin:0px;text-indent:0px"> </p></div></div></div></blockquote><div><br></div><div>Cheers,</div><div>Daniele </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="font-family:monospace;font-size:9pt;font-weight:400;font-style:normal"><div><div class="gmail-h5">
<p style="margin:0px;text-indent:0px">> </p>
<p style="margin:0px;text-indent:0px">> Best Regards,</p>
<p style="margin:0px;text-indent:0px">> Daniele</p>
<p style="margin:0px;text-indent:0px">> </p>
<p style="margin:0px;text-indent:0px">> On Thu, Nov 24, 2016 at 1:35 PM, Even Rouault <<a href="mailto:even.rouault@spatialys.com" target="_blank">even.rouault@spatialys.com</a>></p>
<p style="margin:0px;text-indent:0px">> </p>
<p style="margin:0px;text-indent:0px">> wrote:</p>
<p style="margin:0px;text-indent:0px">> > Daniele,</p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > This is indeed an inconsistency I spotted a long time ago :</p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > <a href="https://trac.osgeo.org/gdal/ticket/2213" target="_blank">https://trac.osgeo.org/gdal/<wbr>ticket/2213</a></p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > Nobody was apparently sufficiently annoyed by this to fix it. Actually I</p>
<p style="margin:0px;text-indent:0px">> > see I proposed a patch. Was probably waiting for feedback. I'm not sure if</p>
<p style="margin:0px;text-indent:0px">> > there's a standardized way of converting between the [0,255] and [0,65535]</p>
<p style="margin:0px;text-indent:0px">> > ranges.</p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > Even</p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > > Hi List,</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > I'm investigating on a issue I have with a paletted image with</p>
<p style="margin:0px;text-indent:0px">> > > overviews,</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > using java ImageIO tiff reader (wait... I know on this list we discuss</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > about GDAL topics :) ).</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > I'm trying to better understand palette interpretation and palette</p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > storing</p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > > on tags and how they are handled by GDAL.</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > From TIFF specifications, colormap entries are stored as short values.</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > I have a sample file with this color tab (as reported by gdalinfo).</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > Color Table (RGB with 256 entries)</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > 0: *164*,164,164,255</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > 1: *255*,255,255,255</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > 2: 0,0,0,255</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > 3: 0,0,0,255</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > .... repeat 0,0,0,255 to the end.</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > Using an Hex editor or AsTiffTagViewer, I can see the byte values of the</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > colormap as stored on the file.</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > For the first 4 mappings of the colortable the Red components are:</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > *A4 A4* *FF FF* 00 00 00 00</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > (8 bytes = 4 shorts)</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > As far as I have understood, this is related to that part of the</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > specification (quoting it, section 5):</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > *In a TIFF ColorMap, all the Red values come first, followed by the</p>
<p style="margin:0px;text-indent:0px">> > > Green</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > values, then the Blue values. In the ColorMap, black is represented by</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > 0,0,0 and white is represented by 65535, 65535, 65535*</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > So the second entry of the map, being white (255, 255, 255) has its red</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > value stored as 65535 = *FF FF *whilst the first color (164,164,164) has</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > its red value stored as 42148 = *A4 A4*</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > I see this behavior is confirmed by the way the geotiff.cpp create the</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > colortable:</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > <a href="https://github.com/OSGeo/gdal/blob/trunk/gdal/frmts/gtiff/" target="_blank">https://github.com/OSGeo/gdal/<wbr>blob/trunk/gdal/frmts/gtiff/</a></p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > geotiff.cpp#L5043</p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > > panTRed[iColor] = static_cast<unsigned short>(257 * sRGB.c1);</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > panTGreen[iColor] = static_cast<unsigned short>(257 * sRGB.c2);</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > panTBlue[iColor] = static_cast<unsigned short>(257 * sRGB.c3)</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > Applying a color*257 multiplication allows to have its 8 bits color</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > representation stored into a short where intensity goes from 0 to 65535.</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > The issue I have is that when using gdaladdo, the overviews are</p>
<p style="margin:0px;text-indent:0px">> > > generated</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > with a different color table.</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > So that the first 8 bytes of the red component stored in the colormap,as</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > reported by AsTiffTagViewer are:</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > *A4* 00 *FF* 00 00 00 00 00</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > When converting it back to a 0-255 color component with the formula</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > R*255/65535 it become *163* instead of 164.</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > I see in the GDAL code that both the IBuildOverviews and</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > CreateOverviewsFromSrcOverview<wbr>s call the CreateTIFFColorTable function</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > which multiplies the colorMapEntry by 256 instead of 257.</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > <a href="https://github.com/OSGeo/gdal/blob/trunk/gdal/frmts/gtiff/" target="_blank">https://github.com/OSGeo/gdal/<wbr>blob/trunk/gdal/frmts/gtiff/</a></p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > geotiff.cpp#L9137</p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > > This may explain the *A4* 00 *FF* 00 entries in the overview with</p>
<p style="margin:0px;text-indent:0px">> > > respect</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > to the *A4 A4 FF FF *entries in the main level.</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > Do you have any feedback on this?</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > Please, let me know what do you think about it.</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > Best Regards,</p>
<p style="margin:0px;text-indent:0px">> > > </p>
<p style="margin:0px;text-indent:0px">> > > Daniele</p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > --</p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > Spatialys - Geospatial professional services</p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > <a href="http://www.spatialys.com" target="_blank">http://www.spatialys.com</a></p>
<p style="margin:0px;text-indent:0px">> > </p>
<p style="margin:0px;text-indent:0px">> > ______________________________<wbr>_________________</p>
<p style="margin:0px;text-indent:0px">> > gdal-dev mailing list</p>
<p style="margin:0px;text-indent:0px">> > <a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a></p>
<p style="margin:0px;text-indent:0px">> > <a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/<wbr>mailman/listinfo/gdal-dev</a></p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">-- </p>
<p style="margin:0px;text-indent:0px">Spatialys - Geospatial professional services</p>
<p style="margin:0px;text-indent:0px"><a href="http://www.spatialys.com" target="_blank">http://www.spatialys.com</a></p></div></div></div><br>______________________________<wbr>_________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" rel="noreferrer" target="_blank">http://lists.osgeo.org/<wbr>mailman/listinfo/gdal-dev</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><span style="font-size:12.8px">==</span><br></div><div dir="ltr"><span style="font-size:12.8px">GeoServer Professional Services from the experts! Visit</span><br style="font-size:12.8px"><a href="http://goo.gl/it488V" style="color:rgb(17,85,204);font-size:12.8px" target="_blank">http://goo.gl/it488V</a><span style="font-size:12.8px"> for more information.</span><br>
==<br>
<br>Ing. Daniele Romagnoli<br>Senior Software Engineer<br><br>GeoSolutions S.A.S.<br><span style="font-size:12.8px">Via di Montramito 3/A</span><br>55054 Massarosa (LU)<br>Italy<br>phone: +39 0584 962313<br>fax: +39 0584 1660272<br><br><a href="http://www.geo-solutions.it" target="_blank">http://www.geo-solutions.it</a><br><a href="http://twitter.com/geosolutions_it" target="_blank">http://twitter.com/geosolutions_it</a><br><br>-------------------------------------------------------<br><p><span lang="IT"><font size="1"><b>AVVERTENZE AI SENSI DEL D.Lgs. 196/2003</b></font></span></p><p><span lang="IT"><font size="1">Le
informazioni contenute in questo messaggio di posta elettronica e/o
nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il
loro utilizzo è consentito esclusivamente al destinatario del messaggio,
per le finalità indicate nel messaggio stesso. Qualora riceviate questo
messaggio senza esserne il destinatario, Vi preghiamo cortesemente di
darcene notizia via e-mail e di procedere alla distruzione del messaggio
stesso, cancellandolo dal Vostro sistema. Conservare il messaggio
stesso, divulgarlo anche in parte, distribuirlo ad altri soggetti,
copiarlo, od utilizzarlo per finalità diverse, costituisce comportamento
contrario ai principi dettati dal D.Lgs. 196/2003.</font></span></p><p><span lang="IT"><font size="1"> </font></span></p><p><font size="1">The
information in this message and/or attachments, is intended solely for
the attention and use of the named addressee(s) and may be confidential
or proprietary in nature or covered by the provisions of privacy act
(Legislative Decree June, 30 2003, no.196 - Italy's New Data Protection
Code).Any use not in accord with its purpose, any disclosure,
reproduction, copying, distribution, or either dissemination, either
whole or partial, is strictly forbidden except previous formal approval
of the named addressee(s). If you are not the intended recipient, please
contact immediately the sender by telephone, fax or e-mail and delete
the information in this message that has been received in error. The
sender does not give any warranty or accept liability as the content,
accuracy or completeness of sent messages and accepts no responsibility
for changes made after they were sent or for other risks which arise as
a result of e-mail transmission, viruses, etc.</font></p><br></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
</div></div>