From aa107b1bf76aa715172d4a548931078c2a38277d Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sun, 20 Oct 2013 12:30:54 +0100 Subject: [PATCH] remove old 45 degree mask rotate code just a wrapper now --- ChangeLog | 3 +- TODO | 4 +- libvips/conversion/rot45.c | 13 +- libvips/deprecated/rotmask.c | 212 ++++-------------------------- libvips/include/vips/conversion.h | 2 +- 5 files changed, 39 insertions(+), 195 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3e2a4739..d575da57 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,5 @@ 19/10/13 started 7.37.0 -- added vips_rot45() -- redone im_gauss_*mask*() as classes +- redone im_rotate_*mask45(), im_gauss_*mask*() as classes 18/10/13 started 7.36.3 - fix compiler warnings in ubuntu 13.10 diff --git a/TODO b/TODO index b1a8e71f..ff93a325 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,4 @@ - -Next version -============ +- do log mask generation, common base class with the gauss mask builder? - make vips_init() into a macro, check sizes of important structs against size at library compile time diff --git a/libvips/conversion/rot45.c b/libvips/conversion/rot45.c index 4d2ef978..46514608 100644 --- a/libvips/conversion/rot45.c +++ b/libvips/conversion/rot45.c @@ -275,7 +275,7 @@ vips_rot45_class_init( VipsRot45Class *class ) VIPS_ARG_ENUM( class, "angle", 6, _( "Angle" ), _( "Angle to rotate image" ), - VIPS_ARGUMENT_REQUIRED_INPUT, + VIPS_ARGUMENT_OPTIONAL_INPUT, G_STRUCT_OFFSET( VipsRot45, angle ), VIPS_TYPE_ANGLE45, VIPS_ANGLE45_45 ); } @@ -290,9 +290,12 @@ vips_rot45_init( VipsRot45 *rot45 ) * vips_rot45: * @in: input image * @out: output image - * @angle: rotation angle * @...: %NULL-terminated list of optional named arguments * + * Optional arguments: + * + * @angle: rotation angle + * * Rotate @in by a multiple of 45 degrees. Odd-length sides and square images * only. * @@ -301,13 +304,13 @@ vips_rot45_init( VipsRot45 *rot45 ) * Returns: 0 on success, -1 on error */ int -vips_rot45( VipsImage *in, VipsImage **out, VipsAngle45 angle, ... ) +vips_rot45( VipsImage *in, VipsImage **out, ... ) { va_list ap; int result; - va_start( ap, angle ); - result = vips_call_split( "rot45", ap, in, out, angle ); + va_start( ap, out ); + result = vips_call_split( "rot45", ap, in, out ); va_end( ap ); return( result ); diff --git a/libvips/deprecated/rotmask.c b/libvips/deprecated/rotmask.c index 4cdfc6ae..3863eebd 100644 --- a/libvips/deprecated/rotmask.c +++ b/libvips/deprecated/rotmask.c @@ -56,166 +56,6 @@ #include -/* Creates the offsets to rotate by 45 degrees an odd size square mask - */ -int * -im_offsets45( int size ) -{ - int temp; - int x, y; - int size2 = size * size; - int size_2 = size / 2; - int *pnt, *cpnt1, *cpnt2; - - if( size%2 == 0 ) { - im_error( "im_offsets45", "%s", _( "size not odd" ) ); - return( NULL ); - } - if( !(pnt = IM_ARRAY( NULL, size2, int )) ) - return( NULL ); - - /* point at the beginning and end of the buffer - */ - cpnt1 = pnt; cpnt2 = pnt + size2 - 1; - - for( y = 0; y < size_2; y++ ) { - temp = (size_2 + y) * size; - *cpnt1++ = temp; - *cpnt2-- = size2 - 1 - temp; - - for( x = 0; x < y; x++ ) { - temp -= (size-1); - *cpnt1++ = temp; - *cpnt2-- = size2 - 1 - temp; - } - - for( x = 0; x < size_2 - y; x++ ) { - temp -= size; - *cpnt1++ = temp; - *cpnt2-- = size2 - 1 - temp; - } - - for( x = 0; x < size_2 - y; x++ ) { - temp++; - *cpnt1++ = temp; - *cpnt2-- = size2 - 1 - temp; - } - - for( x = 0; x < y; x++ ) { - temp -= ( size - 1 ); - *cpnt1++ = temp; - *cpnt2-- = size2 - 1 - temp; - } - } - - /* the diagonal now - */ - temp = size * (size - 1); - cpnt1 = pnt + size_2 * size; - for( x = 0; x < size; x++ ) { - *cpnt1++ = temp; - temp -= (size-1); - } - -#ifdef PIM_RINT - temp = 0; - for( y = 0; y < size; y++ ) { - for( x = 0; x < size; x++ ) { - fprintf( stderr, "%4d", *(pnt+temp) ); - temp++; - } - fprintf(stderr, "\n"); - } - fprintf(stderr, "\n"); -#endif - - return( pnt ); -} - -/** - * im_rotate_dmask45: - * @in: input matrix - * @filename: name for output matrix - * - * Returns a mask which is the argument mask rotated by 45 degrees. - * Pass the filename to set for the output. - * - * See also: im_rotate_dmask90(). - * - * Returns: the result matrix on success, or %NULL on error. - */ -DOUBLEMASK * -im_rotate_dmask45( DOUBLEMASK *in, const char *filename ) -{ - DOUBLEMASK *out; - int size = in->xsize * in->ysize; - int *offsets; - int i; - - if( in->xsize != in->ysize || (in->xsize % 2) == 0 ) { - im_error( "im_rotate_dmask45", "%s", - _( "mask should be square of odd size" ) ); - return( NULL ); - } - if( !(offsets = im_offsets45( in->xsize )) ) - return( NULL ); - if( !(out = im_create_dmask( filename, in->xsize, in->ysize )) ) { - im_free( offsets ); - return( NULL ); - } - out->scale = in->scale; - out->offset = in->offset; - - for( i = 0; i < size; i++ ) - out->coeff[i] = in->coeff[offsets[i]]; - - im_free( offsets ); - - return( out ); -} - -/** - * im_rotate_imask45: - * @in: input matrix - * @filename: name for output matrix - * - * Returns a mask which is the argument mask rotated by 45 degrees. - * Pass the filename to set for the output. - * - * See also: im_rotate_imask90(). - * - * Returns: the result matrix on success, or %NULL on error. - */ -INTMASK * -im_rotate_imask45( INTMASK *in, const char *filename ) -{ - INTMASK *out; - int size = in->xsize * in->ysize; - int *offsets; - int i; - - if( in->xsize != in->ysize || (in->xsize % 2) == 0 ) { - im_error( "im_rotate_imask45", "%s", - _( "mask should be square of odd size" ) ); - return( NULL ); - } - if( !(offsets = im_offsets45( in->xsize )) ) - return( NULL ); - if( !(out = im_create_imask( filename, in->xsize, in->ysize )) ) { - im_free( offsets ); - return( NULL ); - } - out->scale = in->scale; - out->offset = in->offset; - - for( i = 0; i < size; i++ ) - out->coeff[i] = in->coeff[offsets[i]]; - - im_free( offsets ); - - return( out ); -} - /* The type of the vips operations we support. */ typedef int (*vips_fn)( IMAGE *in, IMAGE *out ); @@ -273,38 +113,42 @@ vapplydmask( DOUBLEMASK *in, const char *name, vips_fn fn ) return( out ); } -/** - * im_rotate_imask90: - * @in: input matrix - * @filename: name for output matrix - * - * Returns a mask which is the argument mask rotated by 90 degrees. - * Pass the filename to set for the output. - * - * See also: im_rotate_imask45(). - * - * Returns: the result matrix on success, or %NULL on error. - */ INTMASK * im_rotate_imask90( INTMASK *in, const char *filename ) { return( vapplyimask( in, filename, im_rot90 ) ); } -/** - * im_rotate_dmask90: - * @in: input matrix - * @filename: name for output matrix - * - * Returns a mask which is the argument mask rotated by 90 degrees. - * Pass the filename to set for the output. - * - * See also: im_rotate_dmask45(). - * - * Returns: the result matrix on success, or %NULL on error. - */ DOUBLEMASK * im_rotate_dmask90( DOUBLEMASK *in, const char *filename ) { return( vapplydmask( in, filename, im_rot90 ) ); } + +static int +im_rot45( IMAGE *in, IMAGE *out ) +{ + VipsImage *t; + + if( vips_rot45( in, &t, NULL ) ) + return( -1 ); + if( vips_image_write( t, out ) ) { + g_object_unref( t ); + return( -1 ); + } + g_object_unref( t ); + + return( 0 ); +} + +INTMASK * +im_rotate_imask45( INTMASK *in, const char *filename ) +{ + return( vapplyimask( in, filename, im_rot45 ) ); +} + +DOUBLEMASK * +im_rotate_dmask45( DOUBLEMASK *in, const char *filename ) +{ + return( vapplydmask( in, filename, im_rot45 ) ); +} diff --git a/libvips/include/vips/conversion.h b/libvips/include/vips/conversion.h index 8164ac4c..6855d428 100644 --- a/libvips/include/vips/conversion.h +++ b/libvips/include/vips/conversion.h @@ -119,7 +119,7 @@ int vips_wrap( VipsImage *in, VipsImage **out, ... ) __attribute__((sentinel)); int vips_rot( VipsImage *in, VipsImage **out, VipsAngle angle, ... ) __attribute__((sentinel)); -int vips_rot45( VipsImage *in, VipsImage **out, VipsAngle45 angle, ... ) +int vips_rot45( VipsImage *in, VipsImage **out, ... ) __attribute__((sentinel)); int vips_zoom( VipsImage *in, VipsImage **out, int xfac, int yfac, ... ) __attribute__((sentinel));