From f4250ab7ab47a02dc57b3c28df38148c56f4ec8d Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sun, 19 Aug 2018 10:53:54 +0100 Subject: [PATCH] scale openexr alpha up scale alpha up to 0 - 255 to match the rest of libvips --- ChangeLog | 2 ++ libvips/foreign/openexr2vips.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/ChangeLog b/ChangeLog index d9b1656b..0f5c899f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -38,6 +38,8 @@ - magickload now sniffs some file types itself - update radiance load from upstream - mapim could fail for float index images with coordinates out of int range +- scale openexr alpha to 0 - 255 +- close input earlier, when we can [kleisauke] 12/3/18 started 8.6.4 - better fitting of fonts with overhanging edges [AdriĆ ] diff --git a/libvips/foreign/openexr2vips.c b/libvips/foreign/openexr2vips.c index 817f8091..1ce1d070 100644 --- a/libvips/foreign/openexr2vips.c +++ b/libvips/foreign/openexr2vips.c @@ -16,6 +16,8 @@ * - tag output as scRGB * 16/8/18 * - shut down the input file as soon as we can [kleisauke] + * 19/8/18 + * - scale alpha up to 0 - 255 to match the rest of libvips */ /* @@ -332,8 +334,16 @@ vips__openexr_generate( VipsRegion *out, float *q = (float *) VIPS_REGION_ADDR( out, hit.left, hit.top + z ); + int i; + ImfHalfToFloatArray( 4 * hit.width, (ImfHalf *) p, q ); + + /* oexr uses 0 - 1 for alpha, but vips is + * always 0 - 255, even for scrgb images. + */ + for( i = 0; i < hit.width; i++ ) + q[4 * i + 3] *= 255; } } @@ -402,6 +412,8 @@ vips__openexr_read( const char *filename, VipsImage *out ) read_header( read, out ); for( y = 0; y < height; y++ ) { + int i; + if( !ImfInputSetFrameBuffer( read->lines, imf_buffer - left - (top + y) * width, 1, width ) ) { @@ -417,6 +429,12 @@ vips__openexr_read( const char *filename, VipsImage *out ) ImfHalfToFloatArray( 4 * width, (ImfHalf *) imf_buffer, vips_buffer ); + /* oexr uses 0 - 1 for alpha, but vips is always 0 - + * 255, even for scrgb images. + */ + for( i = 0; i < width; i++ ) + vips_buffer[4 * i + 3] *= 255; + if( vips_image_write_line( out, y, (VipsPel *) vips_buffer ) ) return( -1 );