<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
</head>
<body>
<p>Matt,</p>
<div class="moz-cite-prefix">Le 16/03/2021 à 21:45,
<a class="moz-txt-link-abbreviated" href="mailto:Matt.Wilkie@yukon.ca">Matt.Wilkie@yukon.ca</a> a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:06c7da14be9b4ae9965f595a20fff7be@app-exch2.gov.yk.ca">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<div class="WordSection1">
<p class="MsoNormal">I recently learned that <b>jpegtran</b>
from the JPEG library has the ability to crop and save a new
jpeg losslessly:
</p>
<p class="MsoNormal"> [...]</p>
<p class="MsoNormal"><span>Can GDAL take advantage of this for
jpeg-in-geotiff images?</span></p>
</div>
</blockquote>
<p>to some limited extent, yes. I thought this was documented in
<a class="moz-txt-link-freetext" href="https://gdal.org/drivers/raster/gtiff.html">https://gdal.org/drivers/raster/gtiff.html</a> but I can't find it.</p>
<p>So the most relevant doc is from this comment of the GeoTIFF
driver<br>
</p>
<p> // When CreateCopy'ing() from a JPEG dataset, and asking for
COMPRESS=JPEG,<br>
// use DCT coefficients (unless other options are
incompatible, like<br>
// strip/tile dimensions, specifying JPEG_QUALITY option,
incompatible<br>
// PHOTOMETRIC with the source colorspace, etc.) to avoid the
lossy steps<br>
// involved by decompression/recompression.<br>
</p>
<p>Basically, you can do JPEG to JPEG-in-TIFF lossless transcoding
if doing:</p>
<p>gdal_translate in.jpg out.tif -co COMPRESS=JPEG [[-co TILED=YES]
[-co BLOCKXSIZE=...] [-co BLOCKYSIZE=...]]</p>
<p>where the block size should be a multiple of 16.<br>
</p>
<p>Most other gdal_translate generic option (like -projwin /
-srcwin) or GTiff driver creation option are incompatible with the
implementation of this special mode (subsetting could be in theory
possible on boundaries of JPEG DCT blocks, but isn't implemented).</p>
<p>If adding "--debug on", you should see a line "GTiff: Using
special copy mode from a JPEG dataset" when this lossless
transcoding mode works. Otherwise the generic JPEG decoding /
recoding is used.<br>
</p>
<p class="MsoNormal">JPEG-in-TIFF to JPEG-in-TIFF or JPEG lossless
transcoding<span> could also be in theory supported, but isn't
implemented . With modest effort though with some scripting it
is possible to extract a JPEG file from a tiled JPEG-in-TIFF
file by reassembling the TIFF tile content with the
huffman/quantization tables in the JPEGTABLE TIFF tag.</span></p>
<p class="MsoNormal"><span>If someone wants to propose a pull
request with a doc addition to the GTiff driver doc with the
above content, that'd be welcome.<br>
</span></p>
<p class="MsoNormal"><span>Even<br>
</span></p>
<blockquote type="cite"
cite="mid:06c7da14be9b4ae9965f595a20fff7be@app-exch2.gov.yk.ca">
<div class="WordSection1">
<p class="MsoNormal">
<b><span lang="EN-US">Matt Wilkie</span></b><span lang="EN-US"></span></p>
<p class="MsoNormal"><span lang="EN-US">Geomatics Analyst</span></p>
<p class="MsoNormal"><span lang="EN-US">Environment
<span>|</span> Technology, Innovation and Mapping</span></p>
<p class="MsoNormal"><span lang="EN-US">T 867-667-8133
<span>|</span> </span><u><span><a href="http://yukon.ca/"
moz-do-not-send="true"><span lang="EN-US">Yukon.ca</span></a></span></u></p>
<p class="MsoNormal"><i><span>Hours: 08:30-16:30, Tue-Wed:
Office, Thu-Fri: Remote.</span></i></p>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
gdal-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/gdal-dev">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a>
</pre>
</blockquote>
<pre class="moz-signature" cols="72">--
<a class="moz-txt-link-freetext" href="http://www.spatialys.com">http://www.spatialys.com</a>
My software is free, but my time generally not.</pre>
</body>
</html>