From 8bb073cc729449c9b584dee138341e822680414f Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 17 Apr 2008 14:39:54 +0000 Subject: [PATCH] support CMYKA --- ChangeLog | 1 + TODO | 13 ------- configure.in | 6 ++-- libsrc/conversion/im_tiff2vips.c | 49 +++++++++++--------------- libsrc/conversion/im_vips2tiff.c | 14 ++++++-- vips-7.14.pc.in => vips-7.15.pc.in | 0 vips-7.14.spec.in => vips-7.15.spec.in | 0 vipsCC-7.14.pc.in => vipsCC-7.15.pc.in | 0 8 files changed, 37 insertions(+), 46 deletions(-) rename vips-7.14.pc.in => vips-7.15.pc.in (100%) rename vips-7.14.spec.in => vips-7.15.spec.in (100%) rename vipsCC-7.14.pc.in => vipsCC-7.15.pc.in (100%) diff --git a/ChangeLog b/ChangeLog index e91db4c7..a442135d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,7 @@ - fix the en_GB translation - use meta to preserve resunit between tiff load and save - small doc improvements +- read and write CMYKA tiff (thanks Doron) 25/1/08 started 7.14.0 - bump all version numbers for new stable diff --git a/TODO b/TODO index ffe921bd..0b95dc15 100644 --- a/TODO +++ b/TODO @@ -1,16 +1,3 @@ -- set res_unit meta in im_tiff2vips, then use that to set res unit default in - im_vips2tiff - -- setting :res_inch as a tiff option does not multiply by 2.54 :-( ie. - - 1 pixel per mm vips image - save as a tiff with res_cm - sets 10 pixels / cm - save as a tiff with res_inch - sets 10 pixels / inch ... wrong! - -- test, backport to 7.14 - - should check for gettext in configure? see https://sourceforge.net/tracker/index.php?func=detail&aid=1836080&group_id=100050&atid=626186 diff --git a/configure.in b/configure.in index b64fc444..8b202583 100644 --- a/configure.in +++ b/configure.in @@ -356,9 +356,9 @@ AC_SUBST(VIPS_LIBS) AC_SUBST(PACKAGES_USED) AC_OUTPUT([ - vips-7.14.pc - vipsCC-7.14.pc - vips-7.14.spec + vips-7.15.pc + vipsCC-7.15.pc + vips-7.15.spec Makefile include/vips/version.h include/Makefile diff --git a/libsrc/conversion/im_tiff2vips.c b/libsrc/conversion/im_tiff2vips.c index abeb7c39..6d5211e2 100644 --- a/libsrc/conversion/im_tiff2vips.c +++ b/libsrc/conversion/im_tiff2vips.c @@ -99,6 +99,8 @@ * - remove "b" option on TIFFOpen() * 9/4/08 * - set IM_META_RESOLUTION_UNIT + * 17/4/08 + * - allow CMYKA (thanks Doron) */ /* @@ -705,10 +707,10 @@ parse_palette( ReadTiff *rtiff, IMAGE *out ) return( 0 ); } -/* Per-scanline process function for 8-bit RGB/RGBA. +/* Per-scanline process function for 8-bit RGB/RGBA/CMYK/CMYKA. */ static void -rgb8_line( PEL *q, PEL *p, int n, IMAGE *im ) +rgbcmyk8_line( PEL *q, PEL *p, int n, IMAGE *im ) { int x, b; @@ -745,7 +747,7 @@ parse_rgb8( ReadTiff *rtiff, IMAGE *out ) out->Coding = IM_CODING_NONE; out->Type = IM_TYPE_sRGB; - rtiff->sfn = (scanline_process_fn) rgb8_line; + rtiff->sfn = (scanline_process_fn) rgbcmyk8_line; rtiff->client = out; return( 0 ); @@ -857,42 +859,33 @@ parse_32f( ReadTiff *rtiff, int pm, IMAGE *out ) return( 0 ); } -/* Per-scanline process function for CMYK8. - */ -static void -cmyk8_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] = p[3]; - - q += 4; - p += 4; - } -} - /* Read a CMYK image. */ static int parse_cmyk( ReadTiff *rtiff, IMAGE *out ) { - if( !tfequals( rtiff->tiff, TIFFTAG_SAMPLESPERPIXEL, 4 ) || - !tfequals( rtiff->tiff, TIFFTAG_BITSPERSAMPLE, 8 ) || - !tfequals( rtiff->tiff, TIFFTAG_INKSET, INKSET_CMYK ) ) - return( -1 ); + int bands; - out->Bands = 4; + /* Check other TIFF fields to make sure we can read this. Can have 5 + * bands for CMYKA. + */ + if( !tfequals( rtiff->tiff, TIFFTAG_BITSPERSAMPLE, 8 ) || + !tfequals( rtiff->tiff, TIFFTAG_INKSET, INKSET_CMYK ) || + !tfget16( rtiff->tiff, TIFFTAG_SAMPLESPERPIXEL, &bands ) ) + return( -1 ); + if( bands != 4 && bands != 5 ) { + im_error( "im_tiff2vips", _( "4 or 5 bands CMYK TIFF only" ) ); + return( -1 ); + } + + out->Bands = bands; out->Bbits = 8; out->BandFmt = IM_BANDFMT_UCHAR; out->Coding = IM_CODING_NONE; out->Type = IM_TYPE_CMYK; - rtiff->sfn = cmyk8_line; - rtiff->client = NULL; + rtiff->sfn = (scanline_process_fn) rgbcmyk8_line; + rtiff->client = out; return( 0 ); } diff --git a/libsrc/conversion/im_vips2tiff.c b/libsrc/conversion/im_vips2tiff.c index 15da73e0..d13ae714 100644 --- a/libsrc/conversion/im_vips2tiff.c +++ b/libsrc/conversion/im_vips2tiff.c @@ -102,6 +102,8 @@ * - don't try to copy icc profiles when building pyramids (thanks Joe) * 9/4/08 * - use IM_META_RESOLUTION_UNIT to set default resunit + * 17/4/08 + * - allow CMYKA (thanks Doron) */ /* @@ -506,6 +508,14 @@ write_tiff_header( TiffWrite *tw, TIFF *tif, int width, int height ) } break; + case 5: + if( tw->im->Type == IM_TYPE_CMYK ) { + photometric = PHOTOMETRIC_SEPARATED; + TIFFSetField( tif, + TIFFTAG_INKSET, INKSET_CMYK ); + } + break; + default: assert( 0 ); } @@ -1575,8 +1585,8 @@ im_vips2tiff( IMAGE *im, const char *filename ) return( -1 ); } if( im->Coding == IM_CODING_NONE ) { - if( im->Bands < 1 || im->Bands > 4 ) { - im_error( "im_vips2tiff", _( "1 to 4 bands only" ) ); + if( im->Bands < 1 || im->Bands > 5 ) { + im_error( "im_vips2tiff", _( "1 to 5 bands only" ) ); return( -1 ); } } diff --git a/vips-7.14.pc.in b/vips-7.15.pc.in similarity index 100% rename from vips-7.14.pc.in rename to vips-7.15.pc.in diff --git a/vips-7.14.spec.in b/vips-7.15.spec.in similarity index 100% rename from vips-7.14.spec.in rename to vips-7.15.spec.in diff --git a/vipsCC-7.14.pc.in b/vipsCC-7.15.pc.in similarity index 100% rename from vipsCC-7.14.pc.in rename to vipsCC-7.15.pc.in