add vips_rotate()

vips_similarity() was a little hatrd to discover, so add vips_rotate()
as a more obvious name for it
This commit is contained in:
John Cupitt 2018-03-10 18:45:39 +00:00
parent a1418b8f72
commit 08dcf29b10
4 changed files with 171 additions and 66 deletions

View File

@ -5,6 +5,7 @@
- hough_line scales width to 0 - 180, not 0 - 360 - hough_line scales width to 0 - 180, not 0 - 360
- hough_line is 4x faster - hough_line is 4x faster
- hough_circle is 2x faster - hough_circle is 2x faster
- add vips_rotate() ... a convenience method for vips_similarity()
12/2/18 started 8.6.3 12/2/18 started 8.6.3
- use pkg-config to find libjpeg, if we can - use pkg-config to find libjpeg, if we can

View File

@ -81,6 +81,8 @@ int vips_thumbnail_image( VipsImage *in, VipsImage **out, int width, ... )
int vips_similarity( VipsImage *in, VipsImage **out, ... ) int vips_similarity( VipsImage *in, VipsImage **out, ... )
__attribute__((sentinel)); __attribute__((sentinel));
int vips_rotate( VipsImage *in, VipsImage **out, double angle, ... )
__attribute__((sentinel));
int vips_affine( VipsImage *in, VipsImage **out, int vips_affine( VipsImage *in, VipsImage **out,
double a, double b, double c, double d, ... ) double a, double b, double c, double d, ... )
__attribute__((sentinel)); __attribute__((sentinel));

View File

@ -167,6 +167,7 @@ vips_resample_operation_init( void )
extern GType vips_quadratic_get_type( void ); extern GType vips_quadratic_get_type( void );
extern GType vips_affine_get_type( void ); extern GType vips_affine_get_type( void );
extern GType vips_similarity_get_type( void ); extern GType vips_similarity_get_type( void );
extern GType vips_rotate_get_type( void );
extern GType vips_resize_get_type( void ); extern GType vips_resize_get_type( void );
vips_thumbnail_file_get_type(); vips_thumbnail_file_get_type();
@ -182,6 +183,7 @@ vips_resample_operation_init( void )
vips_quadratic_get_type(); vips_quadratic_get_type();
vips_affine_get_type(); vips_affine_get_type();
vips_similarity_get_type(); vips_similarity_get_type();
vips_rotate_get_type();
vips_resize_get_type(); vips_resize_get_type();
} }

View File

@ -13,6 +13,8 @@
* 17/11/17 * 17/11/17
* ` - add optional "background" param * ` - add optional "background" param
* ` - don't use vips_reduce() since it has no "background" param * ` - don't use vips_reduce() since it has no "background" param
* 10/3/18
* - add vips_rotate() class for convenience
*/ */
/* /*
@ -58,46 +60,48 @@
#include "presample.h" #include "presample.h"
typedef struct _VipsSimilarity { typedef struct _VipsSimilarityBase {
VipsResample parent_instance; VipsResample parent_instance;
double scale; double scale;
double angle; double angle;
VipsInterpolate *interpolate; VipsInterpolate *interpolate;
VipsArrayDouble *background;
double odx; double odx;
double ody; double ody;
double idx; double idx;
double idy; double idy;
VipsArrayDouble *background;
} VipsSimilarity; } VipsSimilarityBase;
typedef VipsResampleClass VipsSimilarityClass; typedef VipsResampleClass VipsSimilarityBaseClass;
G_DEFINE_TYPE( VipsSimilarity, vips_similarity, VIPS_TYPE_RESAMPLE ); G_DEFINE_ABSTRACT_TYPE( VipsSimilarityBase, vips_similarity_base,
VIPS_TYPE_RESAMPLE );
static int static int
vips_similarity_build( VipsObject *object ) vips_similarity_base_build( VipsObject *object )
{ {
VipsResample *resample = VIPS_RESAMPLE( object ); VipsResample *resample = VIPS_RESAMPLE( object );
VipsSimilarity *similarity = (VipsSimilarity *) object; VipsSimilarityBase *base = (VipsSimilarityBase *) object;
VipsImage **t = (VipsImage **) VipsImage **t = (VipsImage **)
vips_object_local_array( object, 4 ); vips_object_local_array( object, 4 );
double a = similarity->scale * cos( VIPS_RAD( similarity->angle ) ); double a = base->scale * cos( VIPS_RAD( base->angle ) );
double b = similarity->scale * -sin( VIPS_RAD( similarity->angle ) ); double b = base->scale * -sin( VIPS_RAD( base->angle ) );
double c = -b; double c = -b;
double d = a; double d = a;
if( VIPS_OBJECT_CLASS( vips_similarity_parent_class )->build( object ) ) if( VIPS_OBJECT_CLASS( vips_similarity_base_parent_class )->
build( object ) )
return( -1 ); return( -1 );
if( vips_affine( resample->in, &t[0], a, b, c, d, if( vips_affine( resample->in, &t[0], a, b, c, d,
"interpolate", similarity->interpolate, "interpolate", base->interpolate,
"odx", similarity->odx, "odx", base->odx,
"ody", similarity->ody, "ody", base->ody,
"idx", similarity->idx, "idx", base->idx,
"idy", similarity->idy, "idy", base->idy,
"background", similarity->background, "background", base->background,
NULL ) ) NULL ) )
return( -1 ); return( -1 );
@ -107,6 +111,81 @@ vips_similarity_build( VipsObject *object )
return( 0 ); return( 0 );
} }
static void
vips_similarity_base_class_init( VipsSimilarityBaseClass *class )
{
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS( class );
gobject_class->set_property = vips_object_set_property;
gobject_class->get_property = vips_object_get_property;
vobject_class->nickname = "similarity_base";
vobject_class->description = _( "base similarity transform" );
vobject_class->build = vips_similarity_base_build;
VIPS_ARG_INTERPOLATE( class, "interpolate", 5,
_( "Interpolate" ),
_( "Interpolate pixels with this" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsSimilarityBase, interpolate ) );
VIPS_ARG_BOXED( class, "background", 6,
_( "Background" ),
_( "Background value" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsSimilarityBase, background ),
VIPS_TYPE_ARRAY_DOUBLE );
VIPS_ARG_DOUBLE( class, "odx", 112,
_( "Output offset" ),
_( "Horizontal output displacement" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsSimilarityBase, odx ),
-10000000, 10000000, 0 );
VIPS_ARG_DOUBLE( class, "ody", 113,
_( "Output offset" ),
_( "Vertical output displacement" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsSimilarityBase, ody ),
-10000000, 10000000, 0 );
VIPS_ARG_DOUBLE( class, "idx", 114,
_( "Input offset" ),
_( "Horizontal input displacement" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsSimilarityBase, idx ),
-10000000, 10000000, 0 );
VIPS_ARG_DOUBLE( class, "idy", 115,
_( "Input offset" ),
_( "Vertical input displacement" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsSimilarityBase, idy ),
-10000000, 10000000, 0 );
}
static void
vips_similarity_base_init( VipsSimilarityBase *base )
{
base->scale = 1;
base->angle = 0;
base->interpolate = NULL;
base->odx = 0;
base->ody = 0;
base->idx = 0;
base->idy = 0;
base->background = vips_array_double_newv( 1, 0.0 );
}
typedef VipsSimilarityBase VipsSimilarity;
typedef VipsSimilarityBaseClass VipsSimilarityClass;
G_DEFINE_TYPE( VipsSimilarity, vips_similarity,
vips_similarity_base_get_type() );
static void static void
vips_similarity_class_init( VipsSimilarityClass *class ) vips_similarity_class_init( VipsSimilarityClass *class )
{ {
@ -118,7 +197,6 @@ vips_similarity_class_init( VipsSimilarityClass *class )
vobject_class->nickname = "similarity"; vobject_class->nickname = "similarity";
vobject_class->description = _( "similarity transform of an image" ); vobject_class->description = _( "similarity transform of an image" );
vobject_class->build = vips_similarity_build;
VIPS_ARG_DOUBLE( class, "scale", 3, VIPS_ARG_DOUBLE( class, "scale", 3,
_( "Scale" ), _( "Scale" ),
@ -134,59 +212,11 @@ vips_similarity_class_init( VipsSimilarityClass *class )
G_STRUCT_OFFSET( VipsSimilarity, angle ), G_STRUCT_OFFSET( VipsSimilarity, angle ),
-10000000, 10000000, 0 ); -10000000, 10000000, 0 );
VIPS_ARG_INTERPOLATE( class, "interpolate", 2,
_( "Interpolate" ),
_( "Interpolate pixels with this" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsSimilarity, interpolate ) );
VIPS_ARG_DOUBLE( class, "odx", 112,
_( "Output offset" ),
_( "Horizontal output displacement" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsSimilarity, odx ),
-10000000, 10000000, 0 );
VIPS_ARG_DOUBLE( class, "ody", 113,
_( "Output offset" ),
_( "Vertical output displacement" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsSimilarity, ody ),
-10000000, 10000000, 0 );
VIPS_ARG_DOUBLE( class, "idx", 114,
_( "Input offset" ),
_( "Horizontal input displacement" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsSimilarity, idx ),
-10000000, 10000000, 0 );
VIPS_ARG_DOUBLE( class, "idy", 115,
_( "Input offset" ),
_( "Vertical input displacement" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsSimilarity, idy ),
-10000000, 10000000, 0 );
VIPS_ARG_BOXED( class, "background", 2,
_( "Background" ),
_( "Background value" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsSimilarity, background ),
VIPS_TYPE_ARRAY_DOUBLE );
} }
static void static void
vips_similarity_init( VipsSimilarity *similarity ) vips_similarity_init( VipsSimilarity *similarity )
{ {
similarity->scale = 1;
similarity->angle = 0;
similarity->interpolate = NULL;
similarity->odx = 0;
similarity->ody = 0;
similarity->idx = 0;
similarity->idy = 0;
similarity->background = vips_array_double_newv( 1, 0.0 );
} }
/** /**
@ -200,12 +230,12 @@ vips_similarity_init( VipsSimilarity *similarity )
* * @scale: %gdouble, scale by this factor * * @scale: %gdouble, scale by this factor
* * @angle: %gdouble, rotate by this many degrees clockwise * * @angle: %gdouble, rotate by this many degrees clockwise
* * @interpolate: #VipsInterpolate, interpolate pixels with this * * @interpolate: #VipsInterpolate, interpolate pixels with this
* * @background: #VipsArrayDouble colour for new pixels
* * @idx: %gdouble, input horizontal offset * * @idx: %gdouble, input horizontal offset
* * @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
* * @ody: %gdouble, output vertical offset * * @ody: %gdouble, output vertical offset
* * @background: #VipsArrayDouble colour for new pixels
* *
* This operator calls vips_affine() for you, calculating the matrix for the * This operator calls vips_affine() for you, calculating the matrix for the
* affine transform from @scale and @angle. Other parameters are passed on to * affine transform from @scale and @angle. Other parameters are passed on to
@ -227,3 +257,73 @@ vips_similarity( VipsImage *in, VipsImage **out, ... )
return( result ); return( result );
} }
typedef VipsSimilarityBase VipsRotate;
typedef VipsSimilarityBaseClass VipsRotateClass;
G_DEFINE_TYPE( VipsRotate, vips_rotate, vips_similarity_base_get_type() );
static void
vips_rotate_class_init( VipsRotateClass *class )
{
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS( class );
gobject_class->set_property = vips_object_set_property;
gobject_class->get_property = vips_object_get_property;
vobject_class->nickname = "rotate";
vobject_class->description =
_( "rotate an image by a number of degrees" );
VIPS_ARG_DOUBLE( class, "angle", 4,
_( "Angle" ),
_( "Rotate anticlockwise by this many degrees" ),
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsSimilarity, angle ),
-10000000, 10000000, 0 );
}
static void
vips_rotate_init( VipsRotate *rotate )
{
}
/**
* vips_rotate: (method)
* @in: input image
* @out: (out): output image
* @angle: %gdouble, rotate by this many degrees clockwise
* @...: %NULL-terminated list of optional named arguments
*
* Optional arguments:
*
* * @interpolate: #VipsInterpolate, interpolate pixels with this
* * @background: #VipsArrayDouble colour for new pixels
* * @idx: %gdouble, input horizontal offset
* * @idy: %gdouble, input vertical offset
* * @odx: %gdouble, output horizontal offset
* * @ody: %gdouble, output vertical offset
* * @ody: %gdouble, output vertical offset
*
* This operator calls vips_affine() for you, calculating the matrix for the
* affine transform from @scale and @angle. Other parameters are passed on to
* vips_affine() unaltered.
*
* See also: vips_affine(), #VipsInterpolate.
*
* Returns: 0 on success, -1 on error
*/
int
vips_rotate( VipsImage *in, VipsImage **out, double angle, ... )
{
va_list ap;
int result;
va_start( ap, angle );
result = vips_call_split( "rotate", ap, in, out, angle );
va_end( ap );
return( result );
}