Return-Path: <tiff-bounces@lists.maptools.org>
X-Original-To: info@awaresystems.be
Delivered-To: info@awaresystems.be
Received: from mx-q.b-one.net (mx-q.one.com [91.198.169.248])
	by mail9.b-one.net (Postfix) with ESMTP id 57690400363
	for <info@awaresystems.be>; Sat,  1 Jan 2011 14:48:36 +0100 (CET)
Received: by mx-q.b-one.net (Postfix, from userid 106)
	id 3C143F1F85E; Sat,  1 Jan 2011 14:47:51 +0100 (CET)
X-Virus-Scanned: by one.com
X-Spam-Flag: NO
X-Spam-Score: 0
X-Spam-Level: 
X-Spam-Status: No, score=0 tagged_above=0 required=4 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-q.b-one.net (Postfix) with ESMTP id 7DB78F1F85E for
 <info@awaresystems.be>; Sat,  1 Jan 2011 14:47:50 +0100 (CET)
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by
 lists.maptools.org (Postfix) with ESMTP id A86241B009C; Sat,  1 Jan 2011
 08:46:34 -0500 (EST)
Received: from smtp6-g21.free.fr (smtp6-g21.free.fr [212.27.42.6]) by
 lists.maptools.org (Postfix) with ESMTP id 5C09E1B0076 for
 <tiff@lists.maptools.org>; Sat,  1 Jan 2011 08:41:03 -0500 (EST)
Received: from even-desktop.localnet (unknown [88.162.84.61]) by
 smtp6-g21.free.fr (Postfix) with ESMTP id 067F282276; Sat,  1 Jan 2011
 14:40:57 +0100 (CET)
From: Even Rouault <even.rouault@mines-paris.org>
To: TIFF mailing list <tiff@lists.maptools.org>
Date: Sat, 1 Jan 2011 14:41:00 +0100
User-Agent: KMail/1.13.2 (Linux/2.6.32-27-generic; KDE/4.4.2; x86_64; ; )
MIME-Version: 1.0
Message-Id: <201101011441.00281.even.rouault@mines-paris.org>
Subject: [Tiff] Regression in libtiff 4.0 CVS when creating a JPEG RGB contig
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

Hi Lee,

Happy New Year to begin with. Now, less funny things ;-) I've seen a 
regression in GDAL (http://trac.osgeo.org/gdal/ticket/3887) that I tracked 
down to be caused by the following change in libtiff :

2010-12-14  Lee Howard <faxguy@howardsilvan.com>

        * libtiff/tif_jpeg.c: reduce usage of JCS_UNKNOWN in order
        to improve compatibility with various viewers
        submitted by e-mail from Dwight Kelly <dkelly@apago.com>

--- frmts/gtiff/libtiff/tif_jpeg.c.ok	2011-01-01 14:10:57.226381933 +0100
+++ frmts/gtiff/libtiff/tif_jpeg.c	2011-01-01 14:11:06.736240426 +0100
@@ -1701,8 +1701,15 @@
 			sp->cinfo.c.comp_info[0].h_samp_factor = sp->h_sampling;
 			sp->cinfo.c.comp_info[0].v_samp_factor = sp->v_sampling;
 		} else {
-			sp->cinfo.c.in_color_space = JCS_UNKNOWN;
-			if (!TIFFjpeg_set_colorspace(sp, JCS_UNKNOWN))
+			if (td->td_photometric == PHOTOMETRIC_MINISWHITE || td-
>td_photometric == PHOTOMETRIC_MINISBLACK)
+				sp->cinfo.c.in_color_space = JCS_GRAYSCALE;
+			else if (td->td_photometric == PHOTOMETRIC_RGB)
+				sp->cinfo.c.in_color_space = JCS_RGB;
+			else if (td->td_photometric == PHOTOMETRIC_SEPARATED && td-
>td_samplesperpixel == 4)
+				sp->cinfo.c.in_color_space = JCS_CMYK;
+			else
+				sp->cinfo.c.in_color_space = JCS_UNKNOWN;
+			if (!TIFFjpeg_set_colorspace(sp, (sp->cinfo.c.in_color_space == 
JCS_RGB) ? JCS_YCbCr : sp->cinfo.c.in_color_space))
 				return (0);
 			/* jpeg_set_colorspace set all sampling factors to 1 */
 		}

This can be also reproduced with tifcp :

$ ./tools/tiffcp in.tif  out.tif -c jpeg:r -p contig

where in.tif is a 3 band image (uncompressed, since for some reason tiffcp 
doesn't like compressed images as source)

and then :

$ ./tools/tiffinfo out.tif -D
TIFF Directory at offset 0x1274 (4724)
  Image Width: 128 Image Length: 128
  Tile Width: 256 Tile Length: 16
  Bits/Sample: 8
  Sample Format: unsigned integer
  Compression Scheme: JPEG
  Photometric Interpretation: RGB color
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 3
  Planar Configuration: single image plane
  JPEG Tables: (289 bytes)
JPEGPreDecode: Warning, Improper JPEG sampling factors 2,2
Apparently should be 1,1..
JPEGPreDecode: Cannot honour JPEG sampling factors that exceed those 
specified..
JPEGPreDecode: Warning, Improper JPEG sampling factors 2,2
Apparently should be 1,1..
JPEGPreDecode: Cannot honour JPEG sampling factors that exceed those 
specified..
JPEGPreDecode: Warning, Improper JPEG sampling factors 2,2
Apparently should be 1,1..
JPEGPreDecode: Cannot honour JPEG sampling factors that exceed those 
specified..
JPEGPreDecode: Warning, Improper JPEG sampling factors 2,2
Apparently should be 1,1..
JPEGPreDecode: Cannot honour JPEG sampling factors that exceed those 
specified..
JPEGPreDecode: Warning, Improper JPEG sampling factors 2,2
Apparently should be 1,1..
JPEGPreDecode: Cannot honour JPEG sampling factors that exceed those 
specified..
JPEGPreDecode: Warning, Improper JPEG sampling factors 2,2
Apparently should be 1,1..
JPEGPreDecode: Cannot honour JPEG sampling factors that exceed those 
specified..
JPEGPreDecode: Warning, Improper JPEG sampling factors 2,2
Apparently should be 1,1..
JPEGPreDecode: Cannot honour JPEG sampling factors that exceed those 
specified..
JPEGPreDecode: Warning, Improper JPEG sampling factors 2,2
Apparently should be 1,1..
JPEGPreDecode: Cannot honour JPEG sampling factors that exceed those 
specified..

The line

if (!TIFFjpeg_set_colorspace(sp, (sp->cinfo.c.in_color_space == JCS_RGB) ? 
JCS_YCbCr : sp->cinfo.c.in_color_space))

looks suspicious to me. Why shouldn't it be just :

 if (!TIFFjpeg_set_colorspace(sp, sp->cinfo.c.in_color_space))

I've tried this and it works fine.

Best regards,

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