2009.02.22 11:30 "Re: [Tiff] losslessly wrap jpeg file into TIFF", by
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.