Return-Path: <tiff-bounces@lists.maptools.org>
X-Original-To: info@awaresystems.be
Delivered-To: info@awaresystems.be
Received: from mx-g.b-one.net (mx-g.one.com [91.198.169.54])
	by mail9.b-one.net (Postfix) with ESMTP id 3E434400125
	for <info@awaresystems.be>; Sun, 22 Feb 2009 13:14:32 +0100 (CET)
X-Virus-Scanned: by one.com
X-Spam-Score: 0
X-Spam-Level: 
X-Spam-Status: No, score=0 tagged_above=0 required=6 tests=[none]
X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4
Received: from lists.maptools.org (lists.maptools.org [65.39.174.144])
	by mx-g.b-one.net (Postfix) with ESMTP id 98E7A140018D
	for <info@awaresystems.be>; Sun, 22 Feb 2009 13:14:31 +0100 (CET)
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by lists.maptools.org (Postfix) with ESMTP id 3D71C1D18DE69;
	Sun, 22 Feb 2009 07:13:45 -0500 (EST)
Received: from csmtp3.b-one.net (csmtp3.one.com [195.47.247.213])
	by lists.maptools.org (Postfix) with ESMTP id DA02A1D18DE7A
	for <tiff@lists.maptools.org>; Sun, 22 Feb 2009 06:30:33 -0500 (EST)
Received: from awarec74cb3e1c (78-22-0-150.access.telenet.be [78.22.0.150])
	by csmtp3.b-one.net (Postfix) with ESMTP id 7E368240EC76;
	Sun, 22 Feb 2009 12:30:32 +0100 (CET)
Message-ID: <E9A539408DAA4ACFB262D64E379A5DB7@awarec74cb3e1c>
From: "Joris Van Damme \(AWare Systems\)" <info@awaresystems.be>
To: "Zhang Weiwu" <zhangweiwu@realss.com>,
	<tiff@lists.maptools.org>
References: <49A126E3.4020005@realss.com>
Date: Sun, 22 Feb 2009 12:30:20 +0100
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2900.5512
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
Subject: Re: [Tiff] losslessly wrap jpeg file into TIFF
X-BeenThere: tiff@lists.maptools.org
X-Mailman-Version: 2.1.9
Precedence: list
List-Id: TIFF and libtiff discussion <tiff.lists.maptools.org>
List-Unsubscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=unsubscribe>
List-Archive: <http://lists.maptools.org/mailman/private/tiff>
List-Post: <mailto:tiff@lists.maptools.org>
List-Help: <mailto:tiff-request@lists.maptools.org?subject=help>
List-Subscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=subscribe>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Sender: tiff-bounces@lists.maptools.org
Errors-To: tiff-bounces@lists.maptools.org

Zhang,

> 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

_______________________________________________
Tiff mailing list: Tiff@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
