From 6fea2e7c57f00ff3a6436505e02c194c53a6c314 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 13 Dec 2019 12:45:49 +0000 Subject: [PATCH 1/2] clip negatives off LABS L in tiff save Negative L in LABS needs to be trimmed off before savingf as TIFF. Thanks angelmixu. See https://github.com/libvips/libvips/issues/1499 --- libvips/foreign/vips2tiff.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libvips/foreign/vips2tiff.c b/libvips/foreign/vips2tiff.c index e548f143..3e338eec 100644 --- a/libvips/foreign/vips2tiff.c +++ b/libvips/foreign/vips2tiff.c @@ -1235,23 +1235,25 @@ invert_band0( Wtiff *wtiff, VipsPel *q, VipsPel *p, int n ) static void LabS2Lab16( VipsPel *q, VipsPel *p, int n, int samples_per_pixel ) { - int x; short *p1 = (short *) p; unsigned short *q1 = (unsigned short *) q; + int x; + for( x = 0; x < n; x++ ) { + int v; int i; - /* TIFF uses unsigned 16 bit ... move zero, scale up L. + /* LABS L can be negative. */ - q1[0] = VIPS_LSHIFT_INT( (int) p1[0], 1 ); + q1[0] = VIPS_LSHIFT_INT( VIPS_MAX( 0, p1[0] ), 1 ); for( i = 1; i < samples_per_pixel; i++ ) q1[i] = p1[i]; q1 += samples_per_pixel; p1 += samples_per_pixel; - } + } } /* Pack the pixels in @area from @in into a TIFF tile buffer. From 112dc9101a49eea12afd4dc6cec3aaa2ccb58f1b Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 13 Dec 2019 14:19:09 +0000 Subject: [PATCH 2/2] remove early shutdown from tiff reader since streams do this automatically now --- libvips/conversion/sequential.c | 2 +- libvips/foreign/tiff2vips.c | 9 --------- libvips/foreign/vips2tiff.c | 1 - 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/libvips/conversion/sequential.c b/libvips/conversion/sequential.c index c90b4cdc..1823ba48 100644 --- a/libvips/conversion/sequential.c +++ b/libvips/conversion/sequential.c @@ -195,7 +195,7 @@ vips_sequential_build( VipsObject *object ) if( vips_linecache( sequential->in, &t, "tile_height", sequential->tile_height, "access", VIPS_ACCESS_SEQUENTIAL, - /* We need seq caches to persist across minimise, in case + /* We need seq caches to persist across minimise in case * someone is trying to read an image with a series of crop * operations. */ diff --git a/libvips/foreign/tiff2vips.c b/libvips/foreign/tiff2vips.c index 933325e4..1023a132 100644 --- a/libvips/foreign/tiff2vips.c +++ b/libvips/foreign/tiff2vips.c @@ -2041,15 +2041,6 @@ rtiff_stripwise_generate( VipsRegion *or, rtiff->y_pos += hit.height; } - /* Shut down the input file as soon as we can. - */ - if( rtiff->y_pos >= or->im->Ysize ) { -#ifdef DEBUG - printf( "rtiff_stripwise_generate: early shutdown\n" ); -#endif /*DEBUG*/ - rtiff_free( rtiff ); - } - VIPS_GATE_STOP( "rtiff_stripwise_generate: work" ); return( 0 ); diff --git a/libvips/foreign/vips2tiff.c b/libvips/foreign/vips2tiff.c index 3e338eec..8fcda841 100644 --- a/libvips/foreign/vips2tiff.c +++ b/libvips/foreign/vips2tiff.c @@ -1241,7 +1241,6 @@ LabS2Lab16( VipsPel *q, VipsPel *p, int n, int samples_per_pixel ) int x; for( x = 0; x < n; x++ ) { - int v; int i; /* LABS L can be negative.