Return-Path: <tiff-bounces@lists.maptools.org>
X-Original-To: info@awaresystems.be
Delivered-To: info@awaresystems.be
Received: from mx-e.b-one.net (mx-e.one.com [91.198.169.52])
	by mail9.b-one.net (Postfix) with ESMTP id 2744E400164
	for <info@awaresystems.be>; Sat, 21 Nov 2009 08:37:34 +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-e.b-one.net (Postfix) with ESMTP id 94F2972A
	for <info@awaresystems.be>; Sat, 21 Nov 2009 08:37:23 +0100 (CET)
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by lists.maptools.org (Postfix) with ESMTP id 32C7F1D18B15C;
	Sat, 21 Nov 2009 02:36:49 -0500 (EST)
Received: from mail-yw0-f185.google.com (mail-yw0-f185.google.com
	[209.85.211.185])
	by lists.maptools.org (Postfix) with ESMTP id AA9921D18E115
	for <tiff@lists.maptools.org>; Sat, 21 Nov 2009 02:35:47 -0500 (EST)
Received: by ywh15 with SMTP id 15so3947232ywh.5
	for <tiff@lists.maptools.org>; Fri, 20 Nov 2009 23:35:47 -0800 (PST)
Received: by 10.150.236.18 with SMTP id j18mr4328186ybh.110.1258788945445;
	Fri, 20 Nov 2009 23:35:45 -0800 (PST)
Received: from ?192.168.1.50? (24-178-10-252.dhcp.ftwo.tx.charter.com
	[24.178.10.252])
	by mx.google.com with ESMTPS id 4sm824708ywg.28.2009.11.20.23.35.43
	(version=TLSv1/SSLv3 cipher=RC4-MD5);
	Fri, 20 Nov 2009 23:35:44 -0800 (PST)
Message-ID: <4B07984E.1090509@gmail.com>
Date: Sat, 21 Nov 2009 01:35:42 -0600
From: Tim Ayres <laur.olb1@gmail.com>
User-Agent: Thunderbird 2.0.0.23 (X11/20090817)
MIME-Version: 1.0
To: tiff@lists.maptools.org
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

> > 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 
http://www.asmail.be/msg0054846657.html 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 (http://code.google.com/p/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 
(http://www.sno.phy.queensu.ca/~phil/exiftool/) -tagsFromFile option to 
copy the tags from the original jpeg file. A simple jpg2tiff shell 
script could look like:

#!/bin/sh
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).

Thanks,
Tim

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