add "extend" option to affine

so for upsizing with displacement (like resize) we can prevent dark
edges on bright images

see

https://github.com/jcupitt/php-vips/issues/61
This commit is contained in:
John Cupitt 2017-12-07 14:51:07 +00:00
parent bc6fa2452b
commit e9b7231ac0
3 changed files with 30 additions and 6 deletions

View File

@ -44,6 +44,7 @@
adherence adherence
- deprecate the "centre" option for vips_resize(): it's now always on - deprecate the "centre" option for vips_resize(): it's now always on
- setting the EXIF data block automatically sets other image tags - setting the EXIF data block automatically sets other image tags
- add "extend" option to affine; resize uses it to stop black edges
29/8/17 started 8.5.9 29/8/17 started 8.5.9
- make --fail stop jpeg read on any libjpeg warning, thanks @mceachen - make --fail stop jpeg read on any libjpeg warning, thanks @mceachen

View File

@ -84,6 +84,7 @@
* - revise transform ... again * - revise transform ... again
* - see new stress test in nip2/test/extras * - see new stress test in nip2/test/extras
* 7/11/17 * 7/11/17
* - add "extend" param
* - add "background" parameter * - add "background" parameter
* - better clipping means we have no jaggies on edges * - better clipping means we have no jaggies on edges
* - premultiply alpha * - premultiply alpha
@ -153,6 +154,10 @@ typedef struct _VipsAffine {
VipsTransformation trn; VipsTransformation trn;
/* How to generate extra edge pixels.
*/
VipsExtend extend;
/* Background colour. /* Background colour.
*/ */
VipsArrayDouble *background; VipsArrayDouble *background;
@ -507,7 +512,7 @@ vips_affine_build( VipsObject *object )
window_offset + 1, window_offset + 1, window_offset + 1, window_offset + 1,
in->Xsize + window_size - 1 + 2, in->Xsize + window_size - 1 + 2,
in->Ysize + window_size - 1 + 2, in->Ysize + window_size - 1 + 2,
"extend", VIPS_EXTEND_BACKGROUND, "extend", affine->extend,
"background", affine->background, "background", affine->background,
NULL ) ) NULL ) )
return( -1 ); return( -1 );
@ -661,17 +666,26 @@ vips_affine_class_init( VipsAffineClass *class )
G_STRUCT_OFFSET( VipsAffine, idy ), G_STRUCT_OFFSET( VipsAffine, idy ),
-10000000, 10000000, 0 ); -10000000, 10000000, 0 );
VIPS_ARG_BOXED( class, "background", 2, VIPS_ARG_ENUM( class, "extend", 117,
_( "Extend" ),
_( "How to generate the extra pixels" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsAffine, extend ),
VIPS_TYPE_EXTEND, VIPS_EXTEND_BACKGROUND );
VIPS_ARG_BOXED( class, "background", 116,
_( "Background" ), _( "Background" ),
_( "Background value" ), _( "Background value" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsAffine, background ), G_STRUCT_OFFSET( VipsAffine, background ),
VIPS_TYPE_ARRAY_DOUBLE ); VIPS_TYPE_ARRAY_DOUBLE );
} }
static void static void
vips_affine_init( VipsAffine *affine ) vips_affine_init( VipsAffine *affine )
{ {
affine->extend = VIPS_EXTEND_BACKGROUND;
affine->background = vips_array_double_newv( 1, 0.0 ); affine->background = vips_array_double_newv( 1, 0.0 );
} }
@ -693,25 +707,31 @@ vips_affine_init( VipsAffine *affine )
* * @idy: %gdouble, input vertical offset * * @idy: %gdouble, input vertical offset
* * @odx: %gdouble, output horizontal offset * * @odx: %gdouble, output horizontal offset
* * @ody: %gdouble, output vertical offset * * @ody: %gdouble, output vertical offset
* * @extend: #VipsExtend how to generate new pixels
* * @background: #VipsArrayDouble colour for new pixels * * @background: #VipsArrayDouble colour for new pixels
* *
* This operator performs an affine transform on an image using @interpolate. * This operator performs an affine transform on an image using @interpolate.
* *
* The transform is: * The transform is:
* *
* |[
* X = @a * (x + @idx) + @b * (y + @idy) + @odx * X = @a * (x + @idx) + @b * (y + @idy) + @odx
* Y = @c * (x + @idx) + @d * (y + @idy) + @doy * Y = @c * (x + @idx) + @d * (y + @idy) + @doy
* *
* x and y are the coordinates in input image. * where:
* X and Y are the coordinates in output image. * x and y are the coordinates in input image.
* (0,0) is the upper left corner. * X and Y are the coordinates in output image.
* (0,0) is the upper left corner.
* ]|
* *
* The section of the output space defined by @oarea is written to * The section of the output space defined by @oarea is written to
* @out. @oarea is a four-element int array of left, top, width, height. * @out. @oarea is a four-element int array of left, top, width, height.
* By default @oarea is just large enough to cover the whole of the * By default @oarea is just large enough to cover the whole of the
* transformed input image. * transformed input image.
* *
* New pixels are filled with @background. This defaults to zero (black). * By default, new pixels are filled with @background. This defaults to
* zero (black). You can set other extend types with @extend. #VIPS_EXTEND_COPY
* is better for image upsizing.
* *
* @interpolate defaults to bilinear. * @interpolate defaults to bilinear.
* *

View File

@ -267,6 +267,7 @@ vips_resize_build( VipsObject *object )
"interpolate", interpolate, "interpolate", interpolate,
"idx", id, "idx", id,
"idy", id, "idy", id,
"extend", VIPS_EXTEND_COPY,
NULL ) ) NULL ) )
return( -1 ); return( -1 );
in = t[4]; in = t[4];
@ -277,6 +278,7 @@ vips_resize_build( VipsObject *object )
"interpolate", interpolate, "interpolate", interpolate,
"idx", id, "idx", id,
"idy", id, "idy", id,
"extend", VIPS_EXTEND_COPY,
NULL ) ) NULL ) )
return( -1 ); return( -1 );
in = t[4]; in = t[4];
@ -287,6 +289,7 @@ vips_resize_build( VipsObject *object )
"interpolate", interpolate, "interpolate", interpolate,
"idx", id, "idx", id,
"idy", id, "idy", id,
"extend", VIPS_EXTEND_COPY,
NULL ) ) NULL ) )
return( -1 ); return( -1 );
in = t[4]; in = t[4];