From 1338def5353886a813a6ccbdc9ebc29cb73df82e Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 7 Jan 2020 09:00:14 +0000 Subject: [PATCH] fix some autorot issues and a problem with vipsthumbnail of tif see https://github.com/libvips/libvips/issues/1515 --- libvips/foreign/jpeg2vips.c | 6 +++++- libvips/foreign/tiff2vips.c | 33 +++++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/libvips/foreign/jpeg2vips.c b/libvips/foreign/jpeg2vips.c index 613c54d3..3b5766b4 100644 --- a/libvips/foreign/jpeg2vips.c +++ b/libvips/foreign/jpeg2vips.c @@ -829,7 +829,7 @@ read_jpeg_generate( VipsRegion *or, static VipsImage * read_jpeg_rotate( VipsObject *process, VipsImage *im ) { - VipsImage **t = (VipsImage **) vips_object_local_array( process, 2 ); + VipsImage **t = (VipsImage **) vips_object_local_array( process, 3 ); VipsAngle angle = vips_autorot_get_angle( im ); if( angle != VIPS_ANGLE_D0 ) { @@ -848,6 +848,10 @@ read_jpeg_rotate( VipsObject *process, VipsImage *im ) return( NULL ); im = t[1]; + if( vips_copy( im, &t[2], NULL ) ) + return( NULL ); + im = t[2]; + vips_autorot_remove_angle( im ); } diff --git a/libvips/foreign/tiff2vips.c b/libvips/foreign/tiff2vips.c index 8cb72646..dd460193 100644 --- a/libvips/foreign/tiff2vips.c +++ b/libvips/foreign/tiff2vips.c @@ -1722,19 +1722,31 @@ rtiff_autorotate( Rtiff *rtiff, VipsImage *in, VipsImage **out ) const guint64 image_size = VIPS_IMAGE_SIZEOF_IMAGE( in ); const guint64 disc_threshold = vips_get_disc_threshold(); + VipsImage *im; VipsImage *x; if( image_size > disc_threshold ) - x = vips_image_new_temp_file( "%s.v" ); + im = vips_image_new_temp_file( "%s.v" ); else - x = vips_image_new_memory(); + im = vips_image_new_memory(); - if( vips_image_write( in, x ) || - vips_rot( x, out, angle, NULL ) ) { - g_object_unref( x ); + if( vips_image_write( in, im ) ) { + g_object_unref( im ); return( -1 ); } - g_object_unref( x ); + + if( vips_rot( im, &x, angle, NULL ) ) { + g_object_unref( im ); + return( -1 ); + } + g_object_unref( im ); + im = x; + + if( vips_copy( im, out, NULL ) ) { + g_object_unref( im ); + return( -1 ); + } + g_object_unref( im ); /* We must remove the tag to prevent accidental * double rotations. @@ -1901,6 +1913,7 @@ static int rtiff_stripwise_generate( VipsRegion *or, void *seq, void *a, void *b, gboolean *stop ) { + VipsImage *out = or->im; Rtiff *rtiff = (Rtiff *) a; int read_height = rtiff->header.read_height; int page_height = rtiff->header.height; @@ -1964,17 +1977,17 @@ rtiff_stripwise_generate( VipsRegion *or, */ image.left = 0; image.top = 0; - image.width = rtiff->out->Xsize; - image.height = rtiff->out->Ysize; + image.width = out->Xsize; + image.height = out->Ysize; page.left = 0; page.top = page_height * ((r->top + y) / page_height); - page.width = rtiff->out->Xsize; + page.width = out->Xsize; page.height = page_height; strip.left = 0; strip.top = page.top + strip_no * read_height; - strip.width = rtiff->out->Xsize; + strip.width = out->Xsize; strip.height = read_height; /* Clip strip against page and image ... the final strip will