diff --git a/ChangeLog b/ChangeLog index 9787008c..8caada80 100644 --- a/ChangeLog +++ b/ChangeLog @@ -32,7 +32,8 @@ - vipsthumbnail has a --crop option - remove video4linux1 code, it was useless on all modern linuxes - redone freq filter builders as classes -- redone im_fwfft(), im_invfft(), im_freqflt(), im_disp_ps() as classes +- redone im_fwfft(), im_invfft(), im_freqflt(), im_disp_ps(), im_fractsurf() + as classes 20/11/13 started 7.36.5 - better cache sizing in unbuffered sequential mode diff --git a/libvips/create/Makefile.am b/libvips/create/Makefile.am index 14b09e8d..fa6236e6 100644 --- a/libvips/create/Makefile.am +++ b/libvips/create/Makefile.am @@ -12,7 +12,7 @@ libcreate_la_SOURCES = \ point.c \ point.h \ mask.c \ - mask.h \ + pmask.h \ mask_ideal.c \ mask_ideal_ring.c \ mask_ideal_band.c \ @@ -23,6 +23,7 @@ libcreate_la_SOURCES = \ mask_gaussian_ring.c \ mask_gaussian_band.c \ mask_fractal.c \ + fractsurf.c \ eye.c \ grey.c \ xyz.c \ diff --git a/libvips/create/create.c b/libvips/create/create.c index 35e3e168..774c5447 100644 --- a/libvips/create/create.c +++ b/libvips/create/create.c @@ -135,6 +135,7 @@ vips_create_operation_init( void ) extern GType vips_mask_ideal_ring_get_type( void ); extern GType vips_mask_ideal_band_get_type( void ); extern GType vips_mask_fractal_get_type( void ); + extern GType vips_fractsurf_get_type( void ); vips_black_get_type(); vips_gaussmat_get_type(); @@ -162,5 +163,6 @@ vips_create_operation_init( void ) vips_mask_gaussian_ring_get_type(); vips_mask_gaussian_band_get_type(); vips_mask_fractal_get_type(); + vips_fractsurf_get_type(); } diff --git a/libvips/create/fractsurf.c b/libvips/create/fractsurf.c new file mode 100644 index 00000000..6d571176 --- /dev/null +++ b/libvips/create/fractsurf.c @@ -0,0 +1,160 @@ +/* fractal surface + * + * Author: N. Dessipris + * Written on: 10/09/1991 + * Modified on: + * 20/9/95 JC + * - modernised, a little + * 7/2/10 + * - cleanups + * - gtkdoc + * 4/1/14 + * - redo as a class + */ + +/* + + 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 "pcreate.h" + +typedef struct _VipsFractsurf { + VipsCreate parent_instance; + + int width; + int height; + double fractal_dimension; + +} VipsFractsurf; + +typedef VipsCreateClass VipsFractsurfClass; + +G_DEFINE_TYPE( VipsFractsurf, vips_fractsurf, VIPS_TYPE_CREATE ); + +static int +vips_fractsurf_build( VipsObject *object ) +{ + VipsCreate *create = VIPS_CREATE( object ); + VipsFractsurf *fractsurf = (VipsFractsurf *) object; + VipsImage **t = (VipsImage **) vips_object_local_array( object, 5 ); + + if( VIPS_OBJECT_CLASS( vips_fractsurf_parent_class )->build( object ) ) + return( -1 ); + + if( vips_gaussnoise( &t[0], + fractsurf->width, fractsurf->height, 0.0, 1.0, NULL ) || + vips_mask_fractal( &t[1], fractsurf->width, fractsurf->height, + fractsurf->fractal_dimension, NULL ) || + vips_freqmult( t[0], t[1], &t[2], NULL ) || + vips_image_write( t[2], create->out ) ) + return( -1 ); + + return( 0 ); +} + +static void +vips_fractsurf_class_init( VipsFractsurfClass *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 = "fractsurf"; + vobject_class->description = _( "make a fractal surface" ); + vobject_class->build = vips_fractsurf_build; + + VIPS_ARG_INT( class, "width", 4, + _( "Width" ), + _( "Image width in pixels" ), + VIPS_ARGUMENT_REQUIRED_INPUT, + G_STRUCT_OFFSET( VipsFractsurf, width ), + 1, 1000000, 64 ); + + VIPS_ARG_INT( class, "height", 5, + _( "Height" ), + _( "Image height in pixels" ), + VIPS_ARGUMENT_REQUIRED_INPUT, + G_STRUCT_OFFSET( VipsFractsurf, height ), + 1, 1000000, 64 ); + + VIPS_ARG_DOUBLE( class, "fractal_dimension", 8, + _( "Fractal dimension" ), + _( "Fractal dimension" ), + VIPS_ARGUMENT_REQUIRED_INPUT, + G_STRUCT_OFFSET( VipsFractsurf, fractal_dimension ), + 2.0, 3.0, 2.5 ); + +} + +static void +vips_fractsurf_init( VipsFractsurf *fractsurf ) +{ + fractsurf->width = 64; + fractsurf->height = 64; + fractsurf->fractal_dimension = 2.5; +} + +/** + * vips_fractsurf: + * @out: output image + * @width: output width + * @height: output height + * @fractal_dimension: fractal dimension + * @...: %NULL-terminated list of optional named arguments + * + * Generate an image of size @width by @height and fractal dimension + * @fractal_dimension. The dimension should be between 2 and 3. + * + * See also: vips_gaussnoise(), vips_mask_fractal(). + * + * Returns: 0 on success, -1 on error + */ +int +vips_fractsurf( VipsImage **out, + int width, int height, double fractal_dimension, ... ) +{ + va_list ap; + int result; + + va_start( ap, fractal_dimension ); + result = vips_call_split( "fractsurf", ap, + out, width, height, fractal_dimension ); + va_end( ap ); + + return( result ); +} diff --git a/libvips/create/mask_fractal.c b/libvips/create/mask_fractal.c index 8d0659b4..48b08b96 100644 --- a/libvips/create/mask_fractal.c +++ b/libvips/create/mask_fractal.c @@ -94,7 +94,7 @@ vips_mask_fractal_class_init( VipsMaskFractalClass *class ) _( "Fractal dimension" ), VIPS_ARGUMENT_REQUIRED_INPUT, G_STRUCT_OFFSET( VipsMaskFractal, fractal_dimension ), - 1.0, 1000000.0, 2.5 ); + 2.0, 3.0, 2.5 ); } diff --git a/libvips/deprecated/vips7compat.c b/libvips/deprecated/vips7compat.c index 2a8fb05a..deddbe98 100644 --- a/libvips/deprecated/vips7compat.c +++ b/libvips/deprecated/vips7compat.c @@ -4455,3 +4455,19 @@ im_disp_ps( IMAGE *in, IMAGE *out ) return( 0 ); } + +int +im_fractsurf( IMAGE *out, int size, double frd ) +{ + VipsImage *t; + + if( vips_fractsurf( &t, size, size, frd, NULL ) ) + return( -1 ); + if( vips_image_write( t, out ) ) { + g_object_unref( t ); + return( -1 ); + } + g_object_unref( t ); + + return( 0 ); +} diff --git a/libvips/freqfilt/Makefile.am b/libvips/freqfilt/Makefile.am index a2a3fcac..ca9a0607 100644 --- a/libvips/freqfilt/Makefile.am +++ b/libvips/freqfilt/Makefile.am @@ -8,7 +8,6 @@ libfreqfilt_la_SOURCES = \ freqmult.c \ spectrum.c \ im_phasecor_fft.c \ - freq_dispatch.c \ - im_fractsurf.c + freq_dispatch.c AM_CPPFLAGS = -I${top_srcdir}/libvips/include @VIPS_CFLAGS@ @VIPS_INCLUDES@ diff --git a/libvips/freqfilt/im_fractsurf.c b/libvips/freqfilt/im_fractsurf.c deleted file mode 100644 index b495e73f..00000000 --- a/libvips/freqfilt/im_fractsurf.c +++ /dev/null @@ -1,83 +0,0 @@ -/* im_fractsurf - * - * Copyright: 1991, N. Dessipris. - * - * Author: N. Dessipris - * Written on: 10/09/1991 - * Modified on: - * 20/9/95 JC - * - modernised, a little - * 7/2/10 - * - cleanups - * - 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_fractsurf: - * @out: output image - * @size: size of image to generate - * @frd: fractal dimension - * - * Generate an image of size @size and fractal dimension @frd. The dimension - * should be between 2 and 3. - * - * See also: im_gaussnoise(), im_flt_image_freq(). - * - * Returns: 0 on success, -1 on error. - */ -int -im_fractsurf( IMAGE *out, int size, double frd ) -{ - IMAGE *noise; - - if( frd <= 2.0 || frd >= 3.0 ) { - im_error( "im_fractsurf", "%s", - _( "dimension should be in (2,3)" ) ); - return( -1 ); - } - - if( !(noise = im_open_local( out, "im_fractsurf", "p" )) || - im_gaussnoise( noise, size, size, 0.0, 1.0 ) || - im_flt_image_freq( noise, out, IM_MASK_FRACTAL_FLT, frd ) ) - return( -1 ); - - return( 0 ); -} diff --git a/libvips/include/vips/create.h b/libvips/include/vips/create.h index a1f761b7..7943d7e8 100644 --- a/libvips/include/vips/create.h +++ b/libvips/include/vips/create.h @@ -109,6 +109,10 @@ int vips_mask_fractal( VipsImage **out, int width, int height, double fractal_dimension, ... ) __attribute__((sentinel)); +int vips_fractsurf( VipsImage **out, + int width, int height, double fractal_dimension, ... ) + __attribute__((sentinel)); + int im_benchmarkn( VipsImage *in, VipsImage *out, int n ); int im_benchmark2( VipsImage *in, double *out ); diff --git a/libvips/include/vips/freqfilt.h b/libvips/include/vips/freqfilt.h index a1d42479..d2e66a8b 100644 --- a/libvips/include/vips/freqfilt.h +++ b/libvips/include/vips/freqfilt.h @@ -51,8 +51,6 @@ int vips_spectrum( VipsImage *in, VipsImage **out, ... ) int im_phasecor_fft( VipsImage *in1, VipsImage *in2, VipsImage *out ); -int im_fractsurf( VipsImage *out, int size, double frd ); - #ifdef __cplusplus } #endif /*__cplusplus*/ diff --git a/libvips/include/vips/vips7compat.h b/libvips/include/vips/vips7compat.h index 63bb4c94..2b61d427 100644 --- a/libvips/include/vips/vips7compat.h +++ b/libvips/include/vips/vips7compat.h @@ -972,6 +972,7 @@ 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_fractsurf( VipsImage *out, int size, double frd ); #ifdef __cplusplus }