From aaebb3b346c045b010f4d98881174b00a13f569c Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Wed, 27 May 2020 15:24:27 +0100 Subject: [PATCH] fix thumbnail of mono image we were using RGB as the shrink space --- libvips/foreign/vips2tiff.c | 9 +++++++-- libvips/resample/thumbnail.c | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/libvips/foreign/vips2tiff.c b/libvips/foreign/vips2tiff.c index 9ede77a6..338a976f 100644 --- a/libvips/foreign/vips2tiff.c +++ b/libvips/foreign/vips2tiff.c @@ -628,6 +628,11 @@ wtiff_write_header( Wtiff *wtiff, Layer *layer ) int orientation; +#ifdef DEBUG + printf( "wtiff_write_header: sub %d, width %d, height %d\n", + layer->sub, layer->width, layer->height ); +#endif /*DEBUG*/ + /* Output base header fields. */ TIFFSetField( tif, TIFFTAG_IMAGEWIDTH, layer->width ); @@ -1699,10 +1704,10 @@ write_strip( VipsRegion *region, VipsRect *area, void *a ) Wtiff *wtiff = (Wtiff *) a; Layer *layer = wtiff->layer; -#ifdef DEBUG +#ifdef DEBUG_VERBOSE printf( "write_strip: strip at %d, height %d\n", area->top, area->height ); -#endif/*DEBUG*/ +#endif/*DEBUG_VERBOSE*/ for(;;) { VipsRect *to = &layer->strip->valid; diff --git a/libvips/resample/thumbnail.c b/libvips/resample/thumbnail.c index b2a8c282..5a9c5296 100644 --- a/libvips/resample/thumbnail.c +++ b/libvips/resample/thumbnail.c @@ -524,13 +524,12 @@ vips_thumbnail_build( VipsObject *object ) { VipsThumbnail *thumbnail = VIPS_THUMBNAIL( object ); VipsImage **t = (VipsImage **) vips_object_local_array( object, 15 ); - VipsInterpretation interpretation = thumbnail->linear ? - VIPS_INTERPRETATION_scRGB : VIPS_INTERPRETATION_sRGB; VipsImage *in; int preshrunk_page_height; double hshrink; double vshrink; + VipsInterpretation interpretation; /* TRUE if we've done the import of an ICC transform and still need to * export. @@ -628,6 +627,12 @@ vips_thumbnail_build( VipsObject *object ) */ if( in->Type == VIPS_INTERPRETATION_CMYK ) have_imported = TRUE; + if( thumbnail->linear ) + interpretation = VIPS_INTERPRETATION_scRGB; + else if( in->Bands < 3 ) + interpretation = VIPS_INTERPRETATION_B_W; + else + interpretation = VIPS_INTERPRETATION_sRGB; g_info( "converting to processing space %s", vips_enum_nick( VIPS_TYPE_INTERPRETATION, interpretation ) ); if( vips_colourspace( in, &t[2], interpretation, NULL ) )