From 80648c2d2f551b75d094718229a6209d77ab3429 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 27 Jun 2019 17:19:53 +0100 Subject: [PATCH 1/3] text autofit could sometimes underfit The autofit loop would terminate if either width or height fitted exactly, but this could happen very early by chance. This patch makes it keep looping until it finds a dpi which just fits. See https://github.com/libvips/libvips/issues/1352 --- ChangeLog | 1 + libvips/create/text.c | 18 +++++++----------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 581d82e3..62fe3419 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,7 @@ magic number [przemyslawpluta] - remove 256 band limit in arithmetic.c [erdmann] - disable Orc if building with CET [lovell] - fix vipsthumbnail with pyr tiff [kleisauke] +- text autofit could occasionally terminate early [levmorozov] 21/9/18 started 8.8.0 - much faster smartcrop [lovell] diff --git a/libvips/create/text.c b/libvips/create/text.c index 7640b929..6a1cc1f5 100644 --- a/libvips/create/text.c +++ b/libvips/create/text.c @@ -28,6 +28,8 @@ * 16/3/19 * - add `justify` * - set Xoffset/Yoffset to ink left/top + * 27/6/19 + * - fitting could occasionally terminate early [levmorozov] */ /* @@ -58,8 +60,8 @@ */ /* -#define DEBUG */ +#define DEBUG #ifdef HAVE_CONFIG_H #include @@ -204,18 +206,13 @@ vips_text_get_extents( VipsText *text, VipsRect *extents ) return( 0 ); } -/* Return -ve for extents too small, 0 for a fit, +ve for extents too large. +/* Return -ve for extents too small, +ve for extents too large. */ static int vips_text_rect_difference( VipsRect *target, VipsRect *extents ) { - if( vips_rect_includesrect( target, extents ) ) { - if( target->width == extents->width || - target->height == extents->height ) - return( 0 ); - + if( vips_rect_includesrect( target, extents ) ) return( -1 ); - } else return( 1 ); } @@ -261,10 +258,9 @@ vips_text_autofit( VipsText *text ) previous_difference = difference; } - /* Hit the size, or we straddle the target. + /* Stop if we straddle the target. */ - if( difference == 0 || - difference != previous_difference ) + if( difference != previous_difference ) break; previous_difference = difference; From 01a92679b57ab5fdf24ece370cedacde45b17f2f Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 27 Jun 2019 17:34:07 +0100 Subject: [PATCH 2/3] oop left some DEBUG turned on --- libvips/create/text.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libvips/create/text.c b/libvips/create/text.c index 6a1cc1f5..a2d22a30 100644 --- a/libvips/create/text.c +++ b/libvips/create/text.c @@ -60,8 +60,8 @@ */ /* - */ #define DEBUG + */ #ifdef HAVE_CONFIG_H #include From 26100041e7e70f3bebd0376a315f1eccb5ae5206 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 2 Jul 2019 12:23:53 +0100 Subject: [PATCH 3/3] fewer warnings on tiffload We were setting TIFFTAG_JPEGCOLORMODE == JPEGCOLORMODE_RGB for *all* images, but libtiff warns if you use it on an image which is not jpg-compressed. Only set it for jpg-compressed images. See https://github.com/libvips/libvips/issues/1329 --- ChangeLog | 1 + libvips/foreign/tiff2vips.c | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 62fe3419..d747a365 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,7 @@ magic number [przemyslawpluta] - disable Orc if building with CET [lovell] - fix vipsthumbnail with pyr tiff [kleisauke] - text autofit could occasionally terminate early [levmorozov] +- fewer warnings on tiffload [chregu] 21/9/18 started 8.8.0 - much faster smartcrop [lovell] diff --git a/libvips/foreign/tiff2vips.c b/libvips/foreign/tiff2vips.c index 6d0d5430..b7b20689 100644 --- a/libvips/foreign/tiff2vips.c +++ b/libvips/foreign/tiff2vips.c @@ -254,6 +254,7 @@ typedef struct _RtiffHeader { gboolean separate; int orientation; gboolean premultiplied; + uint16 compression; /* Result of TIFFIsTiled(). */ @@ -1331,9 +1332,12 @@ rtiff_set_header( Rtiff *rtiff, VipsImage *out ) uint32 data_length; void *data; - /* Request YCbCr expansion. + /* Request YCbCr expansion. libtiff complains if you do this for + * non-jpg images. */ - TIFFSetField( rtiff->tiff, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB ); + if( rtiff->header.compression == COMPRESSION_JPEG ) + TIFFSetField( rtiff->tiff, + TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB ); out->Xsize = rtiff->header.width; out->Ysize = rtiff->header.height * rtiff->n; @@ -2074,7 +2078,6 @@ rtiff_header_read( Rtiff *rtiff, RtiffHeader *header ) { uint16 extra_samples_count; uint16 *extra_samples_types; - uint16 compression; if( !tfget32( rtiff->tiff, TIFFTAG_IMAGEWIDTH, &header->width ) || !tfget32( rtiff->tiff, TIFFTAG_IMAGELENGTH, &header->height ) || @@ -2088,8 +2091,8 @@ rtiff_header_read( Rtiff *rtiff, RtiffHeader *header ) return( -1 ); TIFFGetFieldDefaulted( rtiff->tiff, - TIFFTAG_COMPRESSION, &compression ); - if( compression == COMPRESSION_JPEG ) + TIFFTAG_COMPRESSION, &header->compression ); + if( header->compression == COMPRESSION_JPEG ) /* We want to always expand subsampled YCBCR images to full * RGB. */