From 0f20f9152bb2c1e1e0361134846c9d598ac825f4 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 12 Jul 2011 14:56:58 +0100 Subject: [PATCH] icc import/export cast inputs --- ChangeLog | 1 + TODO | 11 ---------- libvips/colour/im_icc_transform.c | 32 +++++++++++++++++++++++++++-- libvips/conversion/im_falsecolour.c | 4 ++-- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index c2dc9110..3d8d3a6f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -70,6 +70,7 @@ - im_blend() also does sizealike, oops - jpeg write was not inverting CMYK, thanks Ole - im_falsecolour() converts to mono 8-bit for you +- im_icc_import*/export*() cast inputs for you 30/11/10 started 7.24.0 - bump for new stable diff --git a/TODO b/TODO index e6c46623..68eceade 100644 --- a/TODO +++ b/TODO @@ -1,18 +1,7 @@ -- maplut should force to 8/16 bit unsigned? or does it? - - im_vip2tiff() pyr builder should use new temp system - can isanalyze still add spurious messages to the vips error buffer? -- icc import / export should cast their inputs, they insist on uchar/ushort at - the moment - - we could band up (mono->rgb) and banddown (take first three? take forst - three, then process, then reattach remainder?) as well - - other colour ops (eg. im_Lab2LCh) just insist on three bands and do a - cast to float for you - - can we call vips7 funcs from the vips8 interface? we already have vips8 from diff --git a/libvips/colour/im_icc_transform.c b/libvips/colour/im_icc_transform.c index f84fd52c..e00af915 100644 --- a/libvips/colour/im_icc_transform.c +++ b/libvips/colour/im_icc_transform.c @@ -17,6 +17,8 @@ * written if we are wrinting to a file * 2/8/10 * - add lcms2 + * 12/7/11 + * - import and export cast @in to an appropriate format for you */ /* @@ -487,14 +489,34 @@ import_buf( PEL *in, float *out, int n, Icc *icc ) } } +/* Save a bit of typing. + */ +#define UC IM_BANDFMT_UCHAR +#define US IM_BANDFMT_USHORT + +/* Type mapping: go to uchar or ushort. + */ +static int bandfmt_icc_import[10] = { +/* UC C US S UI I F X D DX */ + UC, UC, US, US, US, US, US, US, US, US +}; + static int icc_import( IMAGE *in, IMAGE *out, Icc *icc ) { + IMAGE *t; DWORD icc_format; if( im_check_uncoded( "im_icc_import", in ) ) return( -1 ); + /* Cast in to u8/u16. + */ + if( !(t = im_open_local( out, "im_maplut", "p" )) || + im_clip2fmt( in, t, bandfmt_icc_import[in->BandFmt] ) ) + return( -1 ); + in = t; + if( !cmsIsIntentSupported( icc->in_profile, icc->intent, LCMS_USED_AS_INPUT ) ) im_warn( "im_icc_import", @@ -669,6 +691,7 @@ int im_icc_export_depth( IMAGE *in, IMAGE *out, int depth, const char *output_profile_filename, VipsIntent intent ) { + IMAGE *t; Icc *icc; DWORD icc_format; @@ -694,11 +717,16 @@ im_icc_export_depth( IMAGE *in, IMAGE *out, int depth, in = t1; } + /* Force to float anyway. + */ + if( !(t = im_open_local( out, "im_icc_export", "p" )) || + im_clip2fmt( in, t, IM_BANDFMT_FLOAT ) ) + return( -1 ); + /* Check input image. */ if( im_check_uncoded( "im_icc_export", in ) || - im_check_bands( "im_icc_export", in, 3 ) || - im_check_format( "im_icc_export", in, IM_BANDFMT_FLOAT ) ) + im_check_bands( "im_icc_export", in, 3 ) ) return( -1 ); if( depth != 8 && depth != 16 ) { diff --git a/libvips/conversion/im_falsecolour.c b/libvips/conversion/im_falsecolour.c index 7a699288..df72e566 100644 --- a/libvips/conversion/im_falsecolour.c +++ b/libvips/conversion/im_falsecolour.c @@ -338,10 +338,10 @@ im_falsecolour( IMAGE *in, IMAGE *out ) /* Check our args, force to mono 8-bit. */ if( im_piocheck( in, out ) || - im_check_uncoded( "im_falsecolour", in ) ) + im_check_uncoded( "im_falsecolour", in ) || im_open_local_array( out, t, 2, "im_falsecolour", "p" ) || im_extract_band( in, t[0], 0 ) || - im_clip2fmt( t[0], t[1], IM_BANDFMT_UCHAR ) + im_clip2fmt( t[0], t[1], IM_BANDFMT_UCHAR ) ) return( -1 ); in = t[1];