From d20f0bf61759664d6be9f1d7abf6f17e0891b277 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 5 Mar 2015 12:10:26 +0000 Subject: [PATCH] improve bandalike better setting of interpretation in output --- TODO | 12 ++++++++++++ libvips/arithmetic/arithmetic.c | 25 ++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index 0f070d4b..941c13e4 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,15 @@ +- where do we futz with interpretation? can we remove any of that now we + auto-futz in bandalike? + + what about other uses of bandalike, eg. matching a one-band image to a + three-band vector, should we change anything there? + +- jpegsave saves a three-band RGB image tagged as BW with three different + channels as a three-band jpg with all bands equal + + cant be right! + + - does cplusplus need flipver() etc.? - are the mosaic functions calling vips_fastcor()? it must be very slow diff --git a/libvips/arithmetic/arithmetic.c b/libvips/arithmetic/arithmetic.c index 7c3ae398..0b6fe14d 100644 --- a/libvips/arithmetic/arithmetic.c +++ b/libvips/arithmetic/arithmetic.c @@ -382,16 +382,35 @@ vips__bandalike_vec( const char *domain, { int i; int max_bands; + VipsInterpretation interpretation; g_assert( n >= 1 ); + /* We try to set the interpretation of the output images from the + * interpretation of the n-band input. For example, if we are matching + * a set of BW images to an RGB image, we want the BW images to be + * tagged as RGB. + */ max_bands = base_bands; - for( i = 0; i < n; i++ ) - max_bands = VIPS_MAX( max_bands, in[i]->Bands ); - for( i = 0; i < n; i++ ) + interpretation = VIPS_INTERPRETATION_ERROR; + for( i = 0; i < n; i++ ) { + /* >= so we can pick up interpretation if base_bands is equal + * to the number of bands of the largest image. + */ + if( in[i]->Bands >= max_bands ) { + max_bands = in[i]->Bands; + interpretation = in[i]->Type; + } + } + + for( i = 0; i < n; i++ ) { if( vips__bandup( domain, in[i], &out[i], max_bands ) ) return( -1 ); + if( interpretation != VIPS_INTERPRETATION_ERROR ) + out[i]->Type = interpretation; + } + return( 0 ); }