From 6bad5339881ad37957edfffce29300cf93a495af Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 17 Jul 2008 15:53:35 +0000 Subject: [PATCH] better jpeg-in-tiff YCbCr read --- ChangeLog | 1 + TODO | 2 + libsrc/conversion/im_tiff2vips.c | 63 +++++++------------------------- 3 files changed, 17 insertions(+), 49 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0ae65f2e..279c3fa4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -32,6 +32,7 @@ - now tests for MagickWand before ImageMagick (thanks Adam) - added "-rotate" option to vips2dj - added man page for im_resize_linear +- better jpeg-in-tiff YCbCr read (thanks Ole) 25/1/08 started 7.14.0 - bump all version numbers for new stable diff --git a/TODO b/TODO index 0e7d19c8..1358729f 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,7 @@ - wrap meta() stuff in C++, we need it in py as well +- TIFF JPEG read needs to map ycbcr->rgb somehow + - try libsrc/convolution$ grep -l offsets *.c diff --git a/libsrc/conversion/im_tiff2vips.c b/libsrc/conversion/im_tiff2vips.c index 6d5211e2..213e11c7 100644 --- a/libsrc/conversion/im_tiff2vips.c +++ b/libsrc/conversion/im_tiff2vips.c @@ -101,6 +101,8 @@ * - set IM_META_RESOLUTION_UNIT * 17/4/08 * - allow CMYKA (thanks Doron) + * 17/7/08 + * - convert YCbCr to RGB on read */ /* @@ -401,45 +403,6 @@ parse_labs( ReadTiff *rtiff, IMAGE *out ) return( 0 ); } -/* Per-scanline process function for IM_CODING_LABQ. - */ -static void -ycbcr_line( PEL *q, PEL *p, int n, void *dummy ) -{ - int x; - - for( x = 0; x < n; x++ ) { - q[0] = p[0]; - q[1] = p[1]; - q[2] = p[2]; - q[3] = 0; - - q += 4; - p += 3; - } -} - -/* Read a YCbCr image. - */ -static int -parse_ycbcr( ReadTiff *rtiff, IMAGE *out ) -{ - if( !tfequals( rtiff->tiff, TIFFTAG_SAMPLESPERPIXEL, 3 ) || - !tfequals( rtiff->tiff, TIFFTAG_BITSPERSAMPLE, 8 ) ) - return( -1 ); - - out->Bands = 4; - out->Bbits = 8; - out->BandFmt = IM_BANDFMT_UCHAR; - out->Coding = IM_CODING_LABQ; - out->Type = IM_TYPE_LAB; - - rtiff->sfn = ycbcr_line; - rtiff->client = NULL; - - return( 0 ); -} - /* Per-scanline process function for 1 bit images. */ static void @@ -707,7 +670,7 @@ parse_palette( ReadTiff *rtiff, IMAGE *out ) return( 0 ); } -/* Per-scanline process function for 8-bit RGB/RGBA/CMYK/CMYKA. +/* Per-scanline process function for 8-bit RGB/RGBA/CMYK/CMYKA/etc. */ static void rgbcmyk8_line( PEL *q, PEL *p, int n, IMAGE *im ) @@ -1014,14 +977,6 @@ parse_header( ReadTiff *rtiff, IMAGE *out ) break; - case PHOTOMETRIC_YCBCR: - /* Easy decision! - */ - if( parse_ycbcr( rtiff, out ) ) - return( -1 ); - - break; - case PHOTOMETRIC_MINISWHITE: case PHOTOMETRIC_MINISBLACK: switch( bps ) { @@ -1078,8 +1033,18 @@ parse_header( ReadTiff *rtiff, IMAGE *out ) break; + case PHOTOMETRIC_YCBCR: + /* Sometimes JPEG in TIFF images are tagged as YCBCR. Ask + * libtiff to convert to RGB for us. + */ + TIFFSetField( rtiff->tiff, + TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB ); + if( parse_rgb8( rtiff, out ) ) + return( -1 ); + break; + case PHOTOMETRIC_RGB: - /* Plain RGB. + /* RGB. */ switch( bps ) { case 8: