2020.10.14 17:11 "[Tiff] Converting JPEG to TIFF without decompressing / recompressing", by Steve McKinney

2020.10.14 17:28 "Re: [Tiff] Converting JPEG to TIFF without decompressing / recompressing", by Even Rouault


I have a need to convert JPEG images to TIFF, ideally without having to decompress and then recompress the JPEG data. I am already using LibTIFF in my application; is there some way I can extract the compressed JPEG data out of a .JPG file (using libjpeg for instance) and shoehorn it into a JPEG compressed TIFF using LibTIFF, and if so could somebody please point me in the right direction? Apologies if I've missed an obvious answer to this question.

You could do this with the GDAL library & tools: https://gdal.org


gdal_translate your.jpg your.tif -co COMPRESS=JPEG

You can use the TILED, BLOCKXSIZE, BLOCKYSIZE creation options documented in if you've particular requirements on the arrangement of the resulting TIFF file: https://gdal.org/ drivers/raster/gtiff.html

(can be done through the GDAL C or C++ API as well)

In this very special mode, it will not recompress a new JPEG code stream but will use the JPEG coefficients directly, so this is lossless compared to the original JPEG file.

The corresponding source code of this specialized JPEG -> TIFF conversion is in: https://github.com/OSGeo/gdal/blob/master/gdal/frmts/gtiff/gt_jpeg_copy.cpp


Spatialys - Geospatial professional services