From f65f9088f6b9c2470d6cd377000ddc7842c45022 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sat, 2 Jun 2012 17:42:42 +0100 Subject: [PATCH] make jpeg pyr write work with tiff4 there was a problem with sizing tiles in chrominance subsample mode --- ChangeLog | 1 + libvips/foreign/vips2tiff.c | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9c0f6df7..c94f9afa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ - better resolution unit handling in deprecated im_vips2tiff() - use TIFF_CFLAGS output from pkg-config (thanks Jay) - much faster vips_argument_map() +- make jpeg pyramids work with tiff4 19/4/12 started 7.28.5 - ifthenelse blend mode was broken diff --git a/libvips/foreign/vips2tiff.c b/libvips/foreign/vips2tiff.c index 059d2bd5..ddec2f5f 100644 --- a/libvips/foreign/vips2tiff.c +++ b/libvips/foreign/vips2tiff.c @@ -126,6 +126,9 @@ * 2/12/11 * - make into a simple function call ready to be wrapped as a new-style * VipsForeign class + * 2/6/12 + * - copy jpeg pyramid in gather in RGB mode ... tiff4 doesn't do ycbcr + * mode */ /* @@ -904,7 +907,8 @@ shrink_region( VipsRegion *from, VipsRect *area, /* Write a tile from a layer. */ static int -save_tile( TiffWrite *tw, TIFF *tif, VipsPel *tbuf, VipsRegion *reg, VipsRect *area ) +save_tile( TiffWrite *tw, + TIFF *tif, VipsPel *tbuf, VipsRegion *reg, VipsRect *area ) { /* Have to repack pixels. */ @@ -1340,9 +1344,21 @@ tiff_copy( TiffWrite *tw, TIFF *out, TIFF *in ) /* TIFFTAG_JPEGQUALITY is a pesudo-tag, so we can't copy it. * Set explicitly from TiffWrite. */ - if( tw->compression == COMPRESSION_JPEG ) + if( tw->compression == COMPRESSION_JPEG ) { TIFFSetField( out, TIFFTAG_JPEGQUALITY, tw->jpqual ); + /* Enable rgb->ycbcr conversion in the jpeg write. See also + * the photometric selection below. + */ + TIFFSetField( out, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB ); + + /* And we want ycbcr expanded to rgb on read. Otherwise + * TIFFTileSize() will give us the size of a chrominance + * subsampled tile. + */ + TIFFSetField( in, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB ); + } + /* We can't copy profiles :( Set again from TiffWrite. */ if( embed_profile( tw, out ) ) @@ -1357,7 +1373,7 @@ tiff_copy( TiffWrite *tw, TIFF *out, TIFF *in ) * here to save compression/decompression, but sadly it seems * not to work :-( investigate at some point. */ - len = TIFFReadEncodedTile( in, tile, buf, (tsize_t) -1 ); + len = TIFFReadEncodedTile( in, tile, buf, -1 ); if( len < 0 || TIFFWriteEncodedTile( out, tile, buf, len ) < 0 ) { vips_free( buf ); @@ -1525,7 +1541,8 @@ vips__tiff_write( VipsImage *in, const char *filename, /* Gather layers together into final pyramid file. */ - if( tw->pyramid && gather_pyramid( tw ) ) { + if( tw->pyramid && + gather_pyramid( tw ) ) { free_tiff_write( tw ); return( -1 ); }