From d5a1d6518386d406af8864964a7763a7b24bf2de Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 8 Nov 2012 22:01:39 +0000 Subject: [PATCH] mostly working still some strange things with order3, not initing ddx correctly? --- libvips/deprecated/deprecated_dispatch.c | 24 ++++++++++++- libvips/deprecated/vips7compat.c | 17 +++++++++ libvips/include/vips/vips7compat.h | 2 ++ libvips/resample/quadratic.c | 44 +++++++++++++----------- 4 files changed, 65 insertions(+), 22 deletions(-) diff --git a/libvips/deprecated/deprecated_dispatch.c b/libvips/deprecated/deprecated_dispatch.c index 2bbeb062..a68f0432 100644 --- a/libvips/deprecated/deprecated_dispatch.c +++ b/libvips/deprecated/deprecated_dispatch.c @@ -44,6 +44,27 @@ static im_arg_desc one_in_one_out[] = { IM_OUTPUT_IMAGE( "out" ) }; +static im_arg_desc quadratic_args[] = { + IM_INPUT_IMAGE( "in" ), + IM_OUTPUT_IMAGE( "out" ), + IM_INPUT_IMAGE( "coeff" ) +}; + +static int +quadratic_vec( im_object *argv ) +{ + return( im_quadratic( argv[0], argv[1], argv[2] ) ); +} + +static im_function quadratic_desc = { + "im_quadratic", /* Name */ + "transform via quadratic", + IM_FN_PIO, /* Flags */ + quadratic_vec, /* Dispatch function */ + IM_NUMBER( quadratic_args ), /* Size of arg list */ + quadratic_args /* Arg list */ +}; + /* Two images in, one out. */ static im_arg_desc two_in_one_out[] = { @@ -2295,7 +2316,8 @@ static im_function *deprecated_list[] = { &moreeqconst_desc, ¬equal_desc, ¬equal_vec_desc, - ¬equalconst_desc + ¬equalconst_desc, + &quadratic_desc }; /* Package of functions. diff --git a/libvips/deprecated/vips7compat.c b/libvips/deprecated/vips7compat.c index 2249c1d1..2ac7bfd9 100644 --- a/libvips/deprecated/vips7compat.c +++ b/libvips/deprecated/vips7compat.c @@ -2789,3 +2789,20 @@ im_icc_ac2rc( VipsImage *in, VipsImage *out, const char *profile_filename ) return( 0 ); } + +int +im_quadratic( IMAGE *in, IMAGE *out, IMAGE *coeff ) +{ + VipsImage *x; + + if( vips_quadratic( in, &x, coeff, + NULL ) ) + return( -1 ); + if( im_copy( x, out ) ) { + g_object_unref( x ); + return( -1 ); + } + g_object_unref( x ); + + return( 0 ); +} diff --git a/libvips/include/vips/vips7compat.h b/libvips/include/vips/vips7compat.h index c00acab4..cb862912 100644 --- a/libvips/include/vips/vips7compat.h +++ b/libvips/include/vips/vips7compat.h @@ -788,6 +788,8 @@ int im_lab_morph( VipsImage *in, VipsImage *out, #define im_col_dE00 vips_col_dE00 +int im_quadratic( IMAGE *in, IMAGE *out, IMAGE *coeff ); + /* ruby-vips uses this */ #define vips_class_map_concrete_all vips_class_map_all diff --git a/libvips/resample/quadratic.c b/libvips/resample/quadratic.c index ef747188..a75ece3e 100644 --- a/libvips/resample/quadratic.c +++ b/libvips/resample/quadratic.c @@ -52,26 +52,23 @@ #include "resample.h" -/* ************************************************************************** -/@ imtranf.c -/@ -/@ ALGORITHM -/@ -/@ x',y' = coordinates of srcim -/@ x,y = coordinates of dstim -/@ -/@ -/@ x = x' + srcvec[0] : order 0 image shift only -/@ + srcvec[2]x' + srcvec[4]y' : order 1 + affine transf. -/@ + srcvec[6]x'y' : order 2 + bilinear transf. -/@ + srcvec[8]x'x' + srcvec[10]y'y': order 3 + quadratic transf. -/@ -/@ y = y' + srcvec[1] -/@ + srcvec[3]x' + srcvec[5]y' -/@ + srcvec[7]x'y' -/@ + srcvec[9]x'x' + srcvec[11]y'y' -/@ -************************************************************************/ +/* The transform we compute: + +x',y' = coordinates of srcim +x,y = coordinates of dstim +a .. l = coefficients + +x = x' + a : order 0 image shift only + + b x' + c y' : order 1 + affine transf. + + d x' y' : order 2 + bilinear transf. + + e x' x' + f y' y' : order 3 + quadratic transf. + +y = y' + g + + h y' + i x' + + j y' x' + + k y' y' + l x' x' + + */ typedef struct _VipsQuadratic { VipsResample parent_instance; @@ -203,6 +200,10 @@ vips_quadratic_gen( VipsRegion *or, void *vseq, fyi += vec[5] * yo + vec[3] * xlow; dx += vec[2]; dy += vec[3]; + + case 0: + /* See above for order 0. + */ break; default: @@ -225,7 +226,6 @@ vips_quadratic_gen( VipsRegion *or, void *vseq, if( xi < 0 || xi >= sizex1 || yi < 0 || yi >= sizey1 ) { for( z = 0; z < ps; z++ ) q[z] = 0; - q += ps; } else { /* @@ -252,6 +252,8 @@ vips_quadratic_gen( VipsRegion *or, void *vseq, TYPE_SWITCH_IPOL; } + q += ps; + fxi += dx; fyi += dy;