AWare Systems, , Home TIFF and LibTiff Mailing List Archive

LibTiff Mailing List

TIFF and LibTiff Mailing List Archive
November 2009

Previous Thread
Next Thread

Previous by Thread
Next by Thread

Previous by Date
Next by Date


The TIFF Mailing List Homepage
Archive maintained by AWare Systems

New Datamatrix section

Valid HTML 4.01!

2009.11.21 07:35 "Re: losslessly wrap jpeg file into TIFF", by Tim Ayres

> > hello. is there a way to use user tool (e.g. tiffcp) to enclose
> > jpeg file into tiff losslessly? It should be in theory possible
> > because TIFF can have jpeg as sub-format, but all solution i know
> > of,e.g. using convert(1), recompress the image during convention
> > and reduce its quality.
>  It's not completely this straightforward.
>  - JPEG is normally used stand-alone. As such, it contains some
>  information in optional markers that shouldn't be included when it is
>  used inside TIFF. Examples are the JFIF app markers. The JPEG should
>  therefore be scanned before encapsulation inside a TIFF file, and
>  such markers should be deleted (probably also used as a basis to
>  decide proper values for TIFF IFD tags that should likely be made to
>  reflect the same information). - JPEG can have mechanisms that are
>  very suitable in some stand-alone situations, but are not correct to
>  use inside TIFF. The primary example is progressive JPEG, with
>  multiple scans, another and more rare example is DNL. From the top of
>  my head, I think it's possible to convert progressive JPEG losslessly
>  to simple baseline sequential JPEG, so it's still possible even in
>  this case, but it requires a considerably complex conversion. The
>  best option might be to decompress to DCT coefficients, and next
>  re-applying single-scan sequential huffman compression, which is all
>  lossless. A much more frequent problem will be the RST marker. On the
>  TIFF end, there's the corresponding problem of division into strips
>  and tiles. Again, the same route through decompressed DCT
>  coefficients could help, I think. - JPEG can have subsampling that is
>  not legit in TIFF, and that most TIFF decoders will likely not
>  support. In fact, any subsampling mode where channels other then the
>  first have a vertical or horizontal subsampling different from 1,
>  does not have a TIFF equivalent. There's no work-around or lossless
>  conversion option at all, for this issue, I think. Furtunately,
>  though, these JPEGs are probably rather rare. - There's at least one
>  JPEG colorspace that I know of that has no equivalent in TIFF, being
>  YCCK. These files might not be too rare, I guess Photoshop likely
>  uses this colorspace when saving CMYK imagery to JPEG. For this
>  problem too, no lossless solution exists.
>  So, in the vast majority of cases, I think you're correct in thinking
>  it should be possible, though it's likely very often not all that
>  straightforward. I don't know of an existing tool for this, though.
>  Best regards,
>  Joris

I recently came across this thread in Google while trying to figure 
out how to do this exact thing, i.e. losslessly wrap a jpeg file into a 
TIFF file. I apologize for resurrecting a 9 month old thread, however I 
did find a solution I thought others may be interested in.

The program sam2p ( can losslessly put 
jpeg data into tiff, pdf, or (e)ps files, as well as other image 
conversions. Unfortunately, sam2p is not too friendly with metadata, 
however this can be overcome by using the exiftool 
( -tagsFromFile option to 
copy the tags from the original jpeg file. A simple jpg2tiff shell 
script could look like:

sam2p $1 "${1%.*}.tif"
exiftool -tagsFromFile $1 "${1%.*}.tif"

I don't know how sam2p overcomes the limitations described above, or if 
the files it produces are completely valid tiff files and interact well 
with the libtiff tools. Still this might prove useful for someone, at 
least until this functionality is included natively in libtiff (if ever).