From 236b8b99adc425791d3b94fcf9a108b986d71494 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 31 May 2013 18:12:39 +0100 Subject: [PATCH] redo im_wrap() as a class incorporate im_rotquad() as an option too --- ChangeLog | 4 +- libvips/conversion/Makefile.am | 2 +- libvips/conversion/conversion.c | 2 + libvips/conversion/im_wrap.c | 80 ------------- libvips/conversion/wrap.c | 176 +++++++++++++++++++++++++++++ libvips/deprecated/vips7compat.c | 22 ++++ libvips/freq_filt/Makefile.am | 3 +- libvips/freq_filt/im_rotquad.c | 80 ------------- libvips/include/vips/conversion.h | 3 +- libvips/include/vips/freq_filt.h | 1 - libvips/include/vips/vips7compat.h | 2 + po/POTFILES.in | 3 +- 12 files changed, 209 insertions(+), 169 deletions(-) delete mode 100644 libvips/conversion/im_wrap.c create mode 100644 libvips/conversion/wrap.c delete mode 100644 libvips/freq_filt/im_rotquad.c diff --git a/ChangeLog b/ChangeLog index 433b08ed..7c149b02 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,8 +3,8 @@ - turn off caching for im_copy()/vips_copy(), we use copy to stop sharing, and it's cheap so caching doesn't help anyway - auto rshift down to 8 bits on save, if necessary -- im_gaussnoise(), im_copy_file(), im_grid(), im_scale(), im_scaleps() - redone as classes +- im_gaussnoise(), im_copy_file(), im_grid(), im_scale(), im_scaleps(), + im_wrap(), im_rotquad() redone as classes - add --angle option to dzsave 14/5/13 started 7.32.4 diff --git a/libvips/conversion/Makefile.am b/libvips/conversion/Makefile.am index 9e766021..ebd4d0c4 100644 --- a/libvips/conversion/Makefile.am +++ b/libvips/conversion/Makefile.am @@ -30,11 +30,11 @@ libconversion_la_SOURCES = \ im_msb.c \ grid.c \ scale.c \ + wrap.c \ im_subsample.c \ im_system.c \ im_system_image.c \ im_text.c \ - im_wrap.c \ im_zoom.c AM_CPPFLAGS = -I${top_srcdir}/libvips/include @VIPS_CFLAGS@ @VIPS_INCLUDES@ diff --git a/libvips/conversion/conversion.c b/libvips/conversion/conversion.c index c74daede..2fa9d310 100644 --- a/libvips/conversion/conversion.c +++ b/libvips/conversion/conversion.c @@ -128,6 +128,7 @@ vips_conversion_operation_init( void ) extern GType vips_gaussnoise_get_type( void ); extern GType vips_grid_get_type( void ); extern GType vips_scale_get_type( void ); + extern GType vips_wrap_get_type( void ); vips_copy_get_type(); vips_tile_cache_get_type(); @@ -153,6 +154,7 @@ vips_conversion_operation_init( void ) vips_gaussnoise_get_type(); vips_grid_get_type(); vips_scale_get_type(); + vips_wrap_get_type(); } /* The common part of most binary conversion diff --git a/libvips/conversion/im_wrap.c b/libvips/conversion/im_wrap.c deleted file mode 100644 index b26eb904..00000000 --- a/libvips/conversion/im_wrap.c +++ /dev/null @@ -1,80 +0,0 @@ -/* im_wrap - * - * Copyright: 2008, Nottingham Trent University - * Author: Tom Vajzovic - * Written on: 2008-01-15 - * 2/2/10 - * - rewritten in terms of im_replicate()/im_extract_area() - * - gtkdoc - * - allows any x/y - */ - -/* - - This file is part of VIPS. - - VIPS is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA - - */ - -/* - - These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk - - */ - -#ifdef HAVE_CONFIG_H -#include -#endif /*HAVE_CONFIG_H*/ -#include - -#include - -/** - * im_wrap: - * @in: input image - * @out: output image - * @x: horizontal displacement - * @y: vertical displacement - * - * Slice an image up and move the segments about so that the pixel that was - * at 0, 0 is now at @x, @y. - * - * See also: im_embed(), im_replicate(), im_rotquad(). - * - * Returns: 0 on success, -1 on error - */ -int -im_wrap( IMAGE *in, IMAGE *out, int x, int y ) -{ - IMAGE *t; - - /* Clock arithmetic: we want negative x/y to wrap around - * nicely. - */ - x = x < 0 ? -x % in->Xsize : in->Xsize - x % in->Xsize; - y = y < 0 ? -y % in->Ysize : in->Ysize - y % in->Ysize; - - if( !(t = im_open_local( out, "im_wrap", "p" )) || - im_replicate( in, t, 2, 2 ) || - im_extract_area( t, out, x, y, in->Xsize, in->Ysize ) ) - return( -1 ); - - out->Xoffset = x; - out->Yoffset = y; - - return( 0 ); -} diff --git a/libvips/conversion/wrap.c b/libvips/conversion/wrap.c new file mode 100644 index 00000000..67308403 --- /dev/null +++ b/libvips/conversion/wrap.c @@ -0,0 +1,176 @@ +/* im_wrap + * + * Copyright: 2008, Nottingham Trent University + * Author: Tom Vajzovic + * Written on: 2008-01-15 + * 2/2/10 + * - rewritten in terms of im_replicate()/im_extract_area() + * - gtkdoc + * - allows any x/y + * 31/5/13 + * - redone as a class + * - added rotquad behaviour if x/y not set + */ + +/* + + This file is part of VIPS. + + VIPS is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA + + */ + +/* + + These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk + + */ + +#ifdef HAVE_CONFIG_H +#include +#endif /*HAVE_CONFIG_H*/ +#include + +#include + +#include "conversion.h" + +typedef struct _VipsWrap { + VipsConversion parent_instance; + + VipsImage *in; + + int x; + int y; + +} VipsWrap; + +typedef VipsConversionClass VipsWrapClass; + +G_DEFINE_TYPE( VipsWrap, vips_wrap, VIPS_TYPE_CONVERSION ); + +static int +vips_wrap_build( VipsObject *object ) +{ + VipsConversion *conversion = VIPS_CONVERSION( object ); + VipsWrap *wrap = (VipsWrap *) object; + VipsImage **t = (VipsImage **) vips_object_local_array( object, 7 ); + + int x; + int y; + + if( VIPS_OBJECT_CLASS( vips_wrap_parent_class )->build( object ) ) + return( -1 ); + + if( !vips_object_argument_isset( object, "x" ) ) + wrap->x = wrap->in->Xsize / 2; + if( !vips_object_argument_isset( object, "y" ) ) + wrap->y = wrap->in->Ysize / 2; + + /* Clock arithmetic: we want negative x/y to wrap around + * nicely. + */ + x = wrap->x < 0 ? + -wrap->x % wrap->in->Xsize : + wrap->in->Xsize - wrap->x % wrap->in->Xsize; + y = wrap->y < 0 ? + -wrap->y % wrap->in->Ysize : + wrap->in->Ysize - wrap->y % wrap->in->Ysize; + + if( vips_replicate( wrap->in, &t[0], 2, 2, NULL ) || + vips_extract_area( t[0], &t[1], + x, y, wrap->in->Xsize, wrap->in->Ysize, NULL ) || + vips_image_write( t[1], conversion->out ) ) + return( -1 ); + + conversion->out->Xoffset = x; + conversion->out->Yoffset = y; + + return( 0 ); +} + +static void +vips_wrap_class_init( VipsWrapClass *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 = "wrap"; + vobject_class->description = _( "wrap an image to uchar" ); + vobject_class->build = vips_wrap_build; + + VIPS_ARG_IMAGE( class, "in", 1, + _( "Input" ), + _( "Input image" ), + VIPS_ARGUMENT_REQUIRED_INPUT, + G_STRUCT_OFFSET( VipsWrap, in ) ); + + VIPS_ARG_INT( class, "x", 3, + _( "x" ), + _( "Left edge of input in output" ), + VIPS_ARGUMENT_OPTIONAL_INPUT, + G_STRUCT_OFFSET( VipsWrap, x ), + -1000000, 1000000, 0 ); + + VIPS_ARG_INT( class, "y", 4, + _( "y" ), + _( "Top edge of input in output" ), + VIPS_ARGUMENT_OPTIONAL_INPUT, + G_STRUCT_OFFSET( VipsWrap, y ), + -1000000, 1000000, 0 ); + +} + +static void +vips_wrap_init( VipsWrap *wrap ) +{ +} + +/** + * vips_wrap: + * @in: input image + * @out: output image + * @...: %NULL-terminated list of optional named arguments + * + * Optional arguments: + * + * @x: horizontal displacement + * @y: vertical displacement + * + * Slice an image up and move the segments about so that the pixel that was + * at 0, 0 is now at @x, @y. If @x and @y are not set, they default to the + * centre of the image. + * + * See also: vips_embed(), vips_replicate(). + * + * Returns: 0 on success, -1 on error + */ +int +vips_wrap( VipsImage *in, VipsImage **out, ... ) +{ + va_list ap; + int result; + + va_start( ap, out ); + result = vips_call_split( "wrap", ap, in, out ); + va_end( ap ); + + return( result ); +} + diff --git a/libvips/deprecated/vips7compat.c b/libvips/deprecated/vips7compat.c index 57a190ed..d89e26f2 100644 --- a/libvips/deprecated/vips7compat.c +++ b/libvips/deprecated/vips7compat.c @@ -1527,6 +1527,28 @@ im_scale( VipsImage *in, VipsImage *out ) return( 0 ); } +int +im_wrap( IMAGE *in, IMAGE *out, int x, int y ) +{ + VipsImage *t; + + if( vips_wrap( in, &t, "x", x, "y", y, NULL ) ) + return( -1 ); + if( vips_image_write( t, out ) ) { + g_object_unref( t ); + return( -1 ); + } + g_object_unref( t ); + + return( 0 ); +} + +int +im_rotquad( IMAGE *in, IMAGE *out ) +{ + return( im_wrap( in, out, in->Xsize / 2, in->Ysize / 2 ) ); +} + int im_scaleps( VipsImage *in, VipsImage *out ) { diff --git a/libvips/freq_filt/Makefile.am b/libvips/freq_filt/Makefile.am index 3a6ba80e..ed653686 100644 --- a/libvips/freq_filt/Makefile.am +++ b/libvips/freq_filt/Makefile.am @@ -11,7 +11,6 @@ libfreq_filt_la_SOURCES = \ im_freqflt.c \ im_fwfft.c \ im_invfft.c \ - im_invfftr.c \ - im_rotquad.c + im_invfftr.c AM_CPPFLAGS = -I${top_srcdir}/libvips/include @VIPS_CFLAGS@ @VIPS_INCLUDES@ diff --git a/libvips/freq_filt/im_rotquad.c b/libvips/freq_filt/im_rotquad.c deleted file mode 100644 index a78c3403..00000000 --- a/libvips/freq_filt/im_rotquad.c +++ /dev/null @@ -1,80 +0,0 @@ -/* im_rotquad - * - * Copyright: 1990, N. Dessipris. - * - * Author: Nicos Dessipris - * Written on: 12/04/1990 - * Modified on : 09/05/1991 - * Modified on : 09/06/1992, J.Cupitt. - * - now works for any type, any number of bands. - * - uses bcopy instead of a loop: mucho faster. - * now uses memcpy - for Sys5 compat K.Martinez 29/4/92 - * 5/8/93 JC - * - some ANSIfication - * 28/6/95 JC - * - some more modernisation - * 11/7/02 JC - * - redone in term of extract()/insert(), for great partialisation - * 14/4/04 - * - sets Xoffset / Yoffset - * 2/2/10 - * - redone in terms of im_wrap() - * - gtkdoc - */ - -/* - - This file is part of VIPS. - - VIPS is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA - - */ - -/* - - These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk - - */ - -#ifdef HAVE_CONFIG_H -#include -#endif /*HAVE_CONFIG_H*/ -#include - -#include -#include -#include - -#include - -/** - * im_rotquad: - * @in: input image - * @out: output image - * - * Rotate the quadrants of the image so that the point that was at the - * top-left is now in the centre. Handy for moving Fourier images to optical - * space. - * - * See also: im_wrap(). - * - * Returns: 0 on success, -1 on error - */ -int -im_rotquad( IMAGE *in, IMAGE *out ) -{ - return( im_wrap( in, out, in->Xsize / 2, in->Ysize / 2 ) ); -} diff --git a/libvips/include/vips/conversion.h b/libvips/include/vips/conversion.h index e59eabcb..edbeeba0 100644 --- a/libvips/include/vips/conversion.h +++ b/libvips/include/vips/conversion.h @@ -192,6 +192,8 @@ int vips_replicate( VipsImage *in, VipsImage **out, int across, int down, ... ) int vips_grid( VipsImage *in, VipsImage **out, int tile_height, int across, int down, ... ) __attribute__((sentinel)); +int vips_wrap( VipsImage *in, VipsImage **out, ... ) + __attribute__((sentinel)); int vips_cast( VipsImage *in, VipsImage **out, VipsBandFormat format, ... ) __attribute__((sentinel)); @@ -264,7 +266,6 @@ int im_text( VipsImage *out, const char *text, const char *font, int width, int alignment, int dpi ); int im_insertset( VipsImage *main, VipsImage *sub, VipsImage *out, int n, int *x, int *y ); -int im_wrap( VipsImage *in, VipsImage *out, int x, int y ); int im_subsample( VipsImage *in, VipsImage *out, int xshrink, int yshrink ); int im_zoom( VipsImage *in, VipsImage *out, int xfac, int yfac ); diff --git a/libvips/include/vips/freq_filt.h b/libvips/include/vips/freq_filt.h index dc205602..45579761 100644 --- a/libvips/include/vips/freq_filt.h +++ b/libvips/include/vips/freq_filt.h @@ -71,7 +71,6 @@ int im_invfftr( VipsImage *in, VipsImage *out ); int im_freqflt( VipsImage *in, VipsImage *mask, VipsImage *out ); int im_disp_ps( VipsImage *in, VipsImage *out ); -int im_rotquad( VipsImage *in, VipsImage *out ); int im_phasecor_fft( VipsImage *in1, VipsImage *in2, VipsImage *out ); int im_flt_image_freq( VipsImage *in, VipsImage *out, VipsMaskType flag, ... ); diff --git a/libvips/include/vips/vips7compat.h b/libvips/include/vips/vips7compat.h index 5846cd48..d32d3569 100644 --- a/libvips/include/vips/vips7compat.h +++ b/libvips/include/vips/vips7compat.h @@ -705,6 +705,8 @@ int im_extract_bands( VipsImage *in, VipsImage *out, int band, int nbands ); int im_extract_areabands( VipsImage *in, VipsImage *out, int left, int top, int width, int height, int band, int nbands ); int im_replicate( VipsImage *in, VipsImage *out, int across, int down ); +int im_wrap( VipsImage *in, VipsImage *out, int x, int y ); +int im_rotquad( VipsImage *in, VipsImage *out ); int im_clip2fmt( VipsImage *in, VipsImage *out, VipsBandFormat fmt ); int im_bandjoin( VipsImage *in1, VipsImage *in2, VipsImage *out ); int im_gbandjoin( VipsImage **in, VipsImage *out, int n ); diff --git a/po/POTFILES.in b/po/POTFILES.in index 1de21c49..3631a332 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -75,7 +75,7 @@ libvips/conversion/replicate.c libvips/conversion/join.c libvips/conversion/im_text.c libvips/conversion/conver_dispatch.c -libvips/conversion/im_wrap.c +libvips/conversion/wrap.c libvips/conversion/insert.c libvips/conversion/tilecache.c libvips/conversion/im_system_image.c @@ -147,7 +147,6 @@ libvips/freq_filt/im_invfftr.c libvips/freq_filt/fmaskcir.c libvips/freq_filt/fmask4th.c libvips/freq_filt/im_invfft.c -libvips/freq_filt/im_rotquad.c libvips/histograms_lut/im_histeq.c libvips/histograms_lut/im_buildlut.c libvips/histograms_lut/im_histnD.c