redo im_fractsurf() as a class
This commit is contained in:
parent
4bc67b8bee
commit
2c184ac06a
@ -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
|
||||
|
@ -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 \
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
160
libvips/create/fractsurf.c
Normal file
160
libvips/create/fractsurf.c
Normal file
@ -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 <config.h>
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
#include <vips/intl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <vips/vips.h>
|
||||
|
||||
#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 );
|
||||
}
|
@ -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 );
|
||||
|
||||
}
|
||||
|
||||
|
@ -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 );
|
||||
}
|
||||
|
@ -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@
|
||||
|
@ -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 <config.h>
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
#include <vips/intl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <vips/vips.h>
|
||||
|
||||
/**
|
||||
* 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 );
|
||||
}
|
@ -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 );
|
||||
|
||||
|
@ -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*/
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user