From 08ebc9e535d4351b70b6d7b2edde3bb332be9614 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 1 Oct 2010 15:45:55 +0000 Subject: [PATCH] im_blend() can take non-uchar conditions --- ChangeLog | 1 + TODO | 8 -------- libvips/inplace/im_draw_smudge.c | 4 ++-- libvips/relational/im_blend.c | 15 ++++++++++++--- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5837d7ee..a5ac1046 100644 --- a/ChangeLog +++ b/ChangeLog @@ -31,6 +31,7 @@ - added im_read_point(), now partial, moved im_readpoint() to deprecated - added im_draw_smudge(), moved im_smudge() / im_smear() to deprecated - convolution functions support complex images +- im_blend() can have any format condition image and it's converted to uchar 12/5/10 started 7.22.2 - the conditional image of ifthenelse can be any format, a (!=0) is added if diff --git a/TODO b/TODO index 08c56f5a..d7a640ab 100644 --- a/TODO +++ b/TODO @@ -5,14 +5,6 @@ make a region, prepare to that, copy back over the image? -- smudge is too strong ... tone it down a bit - -- can we make more use of im__draw_pel()? eg. im_draw_rect() etc. - -- im_blend() is rather fussy about formats, argh - - cf. im_ifthenelse() and the extra !=0 it adds? - diff --git a/libvips/inplace/im_draw_smudge.c b/libvips/inplace/im_draw_smudge.c index 62d5306d..a9d34bad 100644 --- a/libvips/inplace/im_draw_smudge.c +++ b/libvips/inplace/im_draw_smudge.c @@ -100,8 +100,8 @@ im_draw_smudge( VipsImage *im, int left, int top, int width, int height ) return( 0 ); if( !blur ) { - blur = im_create_imaskv( "im_draw_smudge", 3, 1, 1, 2, 1 ); - blur->scale = 4; + blur = im_create_imaskv( "im_draw_smudge", 3, 1, 1, 4, 1 ); + blur->scale = 6; } if( !(t[0] = im_open( "im_draw_smudge", "p" )) ) diff --git a/libvips/relational/im_blend.c b/libvips/relational/im_blend.c index f7dcab13..f38ccfeb 100644 --- a/libvips/relational/im_blend.c +++ b/libvips/relational/im_blend.c @@ -323,7 +323,7 @@ blend( IMAGE *c, IMAGE *a, IMAGE *b, IMAGE *out ) * @b: else #IMAGE * @out: output #IMAGE * - * This operation scans the condition image @c (which must be unsigned char) + * This operation scans the condition image @c * and uses it to blend pixels from either the then image @a or the else * image @b. 255 means @a only, 0 means @b only, and intermediate values are a * mixture. @@ -348,9 +348,9 @@ im_blend( IMAGE *c, IMAGE *a, IMAGE *b, IMAGE *out ) const int repack = a->Coding == IM_CODING_LABQ && b->Coding == IM_CODING_LABQ; - IMAGE *t[7]; + IMAGE *t[8]; - if( im_open_local_array( out, t, 7, "im_blend", "p" ) ) + if( im_open_local_array( out, t, 8, "im_blend", "p" ) ) return( -1 ); /* Unpack LABPACK as a courtesy. @@ -366,6 +366,15 @@ im_blend( IMAGE *c, IMAGE *a, IMAGE *b, IMAGE *out ) b = t[1]; } + /* c must be uchar. + */ + if( c->BandFmt != IM_BANDFMT_UCHAR ) { + if( im_clip2fmt( c, t[7], IM_BANDFMT_UCHAR ) ) + return( -1 ); + + c = t[7]; + } + /* Make a and b match in bands and format. */ if( im__formatalike( a, b, t[2], t[3] ) ||