From dad036afbfee5153ab64a364fdf517fca8574386 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 14 Jun 2013 10:34:00 +0100 Subject: [PATCH] make a baseclass for the new create thing --- libvips/create/Makefile.am | 3 + libvips/create/eye.c | 101 ++++------------------ libvips/create/grey.c | 79 ++---------------- libvips/create/point.c | 166 +++++++++++++++++++++++++++++++++++++ libvips/create/point.h | 80 ++++++++++++++++++ libvips/create/sines.c | 106 ++++++----------------- libvips/create/zone.c | 111 ++++--------------------- 7 files changed, 311 insertions(+), 335 deletions(-) create mode 100644 libvips/create/point.c create mode 100644 libvips/create/point.h diff --git a/libvips/create/Makefile.am b/libvips/create/Makefile.am index ffb1fe03..124f289c 100644 --- a/libvips/create/Makefile.am +++ b/libvips/create/Makefile.am @@ -2,6 +2,9 @@ noinst_LTLIBRARIES = libcreate.la libcreate_la_SOURCES = \ create.c \ + create.h \ + point.c \ + point.h \ eye.c \ grey.c \ xyz.c \ diff --git a/libvips/create/eye.c b/libvips/create/eye.c index 6d099ff1..3df1fa9b 100644 --- a/libvips/create/eye.c +++ b/libvips/create/eye.c @@ -59,82 +59,28 @@ #include #include "create.h" +#include "point.h" typedef struct _VipsEye { - VipsCreate parent_instance; - - int width; - int height; + VipsPoint parent_instance; double factor; - gboolean uchar; } VipsEye; -typedef VipsCreateClass VipsEyeClass; +typedef VipsPointClass VipsEyeClass; -G_DEFINE_TYPE( VipsEye, vips_eye, VIPS_TYPE_CREATE ); +G_DEFINE_TYPE( VipsEye, vips_eye, VIPS_TYPE_POINT ); -static int -vips_eye_gen( VipsRegion *or, void *seq, void *a, void *b, - gboolean *stop ) +static float +vips_eye_point( VipsPoint *point, int x, int y ) { - VipsEye *eye = (VipsEye *) a; - VipsRect *r = &or->valid; - int le = r->left; - int to = r->top; - int ri = VIPS_RECT_RIGHT( r ); - int bo = VIPS_RECT_BOTTOM( r ); + VipsEye *eye = (VipsEye *) point; - double c = eye->factor * VIPS_PI / (2 * (eye->width - 1)); - double h = ((eye->height - 1) * (eye->height - 1)); + double c = eye->factor * VIPS_PI / (2 * (point->width - 1)); + double h = ((point->height - 1) * (point->height - 1)); - int x, y; - - for( y = to; y < bo; y++ ) { - float *q = (float *) VIPS_REGION_ADDR( or, le, y ); - - for( x = le; x < ri; x++ ) - *q++ = y * y * cos( c * x * x ) / h; - } - - return( 0 ); -} - -static int -vips_eye_build( VipsObject *object ) -{ - VipsCreate *create = VIPS_CREATE( object ); - VipsEye *eye = (VipsEye *) object; - VipsImage **t = (VipsImage **) vips_object_local_array( object, 7 ); - VipsImage *in; - - if( VIPS_OBJECT_CLASS( vips_eye_parent_class )->build( object ) ) - return( -1 ); - - t[0] = vips_image_new(); - vips_image_init_fields( t[0], - eye->width, eye->height, 1, - VIPS_FORMAT_FLOAT, VIPS_CODING_NONE, VIPS_INTERPRETATION_B_W, - 1.0, 1.0 ); - vips_demand_hint( t[0], - VIPS_DEMAND_STYLE_ANY, NULL ); - if( vips_image_generate( t[0], - NULL, vips_eye_gen, NULL, eye, NULL ) ) - return( -1 ); - - in = t[0]; - if( eye->uchar ) { - if( vips_linear1( in, &t[1], 127.5, 127.5, NULL ) || - vips_cast( t[1], &t[2], VIPS_FORMAT_UCHAR, NULL ) ) - return( -1 ); - in = t[2]; - } - - if( vips_image_write( in, create->out ) ) - return( -1 ); - - return( 0 ); + return( y * y * cos( c * x * x ) / h ); } static void @@ -142,27 +88,16 @@ vips_eye_class_init( VipsEyeClass *class ) { GObjectClass *gobject_class = G_OBJECT_CLASS( class ); VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS( class ); + VipsPointClass *point_class = VIPS_POINT_CLASS( class ); gobject_class->set_property = vips_object_set_property; gobject_class->get_property = vips_object_get_property; vobject_class->nickname = "eye"; - vobject_class->description = _( "make a eye image" ); - vobject_class->build = vips_eye_build; + vobject_class->description = + _( "make an image showing the eye's spatial response" ); - VIPS_ARG_INT( class, "width", 4, - _( "Width" ), - _( "Image width in pixels" ), - VIPS_ARGUMENT_REQUIRED_INPUT, - G_STRUCT_OFFSET( VipsEye, width ), - 1, 1000000, 1 ); - - VIPS_ARG_INT( class, "height", 5, - _( "Height" ), - _( "Image height in pixels" ), - VIPS_ARGUMENT_REQUIRED_INPUT, - G_STRUCT_OFFSET( VipsEye, height ), - 1, 1000000, 1 ); + point_class->point = vips_eye_point; VIPS_ARG_DOUBLE( class, "factor", 6, _( "Factor" ), @@ -170,14 +105,6 @@ vips_eye_class_init( VipsEyeClass *class ) VIPS_ARGUMENT_OPTIONAL_INPUT, G_STRUCT_OFFSET( VipsEye, factor ), 0.0, 1.0, 0.5 ); - - VIPS_ARG_BOOL( class, "uchar", 7, - _( "Uchar" ), - _( "Output an unsigned char image" ), - VIPS_ARGUMENT_OPTIONAL_INPUT, - G_STRUCT_OFFSET( VipsEye, uchar ), - FALSE ); - } static void diff --git a/libvips/create/grey.c b/libvips/create/grey.c index d9218795..4fc2d8d1 100644 --- a/libvips/create/grey.c +++ b/libvips/create/grey.c @@ -66,90 +66,29 @@ #include #include "create.h" +#include "point.h" -typedef struct _VipsGrey { - VipsCreate parent_instance; +typedef VipsPoint VipsGrey; +typedef VipsPointClass VipsGreyClass; - int width; - int height; +G_DEFINE_TYPE( VipsGrey, vips_grey, VIPS_TYPE_POINT ); - gboolean uchar; - -} VipsGrey; - -typedef VipsCreateClass VipsGreyClass; - -G_DEFINE_TYPE( VipsGrey, vips_grey, VIPS_TYPE_CREATE ); - -static int -vips_grey_build( VipsObject *object ) +static float +vips_grey_point( VipsPoint *point, int x, int y ) { - VipsCreate *create = VIPS_CREATE( object ); - VipsGrey *grey = (VipsGrey *) object; - VipsImage **t = (VipsImage **) vips_object_local_array( object, 7 ); - VipsImage *in; - - if( VIPS_OBJECT_CLASS( vips_grey_parent_class )->build( object ) ) - return( -1 ); - - if( vips_xyz( &t[0], grey->width, grey->height, NULL ) || - vips_extract_band( t[0], &t[1], 0, NULL ) ) - return( -1 ); - - if( grey->uchar ) { - if( vips_linear1( t[1], &t[2], - 255.0 / (grey->width - 1), 0.0, NULL ) || - vips_cast( t[2], &t[3], VIPS_FORMAT_UCHAR, NULL ) ) - return( -1 ); - in = t[3]; - } - else { - if( vips_linear1( t[1], &t[2], - 1.0 / (grey->width - 1), 0, NULL ) ) - return( -1 ); - in = t[2]; - } - - if( vips_image_write( in, create->out ) ) - return( -1 ); - - return( 0 ); + return( (double) x / (point->width - 1) ); } static void vips_grey_class_init( VipsGreyClass *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; + VipsPointClass *point_class = VIPS_POINT_CLASS( class ); vobject_class->nickname = "grey"; vobject_class->description = _( "make a grey ramp image" ); - vobject_class->build = vips_grey_build; - - VIPS_ARG_INT( class, "width", 4, - _( "Width" ), - _( "Image width in pixels" ), - VIPS_ARGUMENT_REQUIRED_INPUT, - G_STRUCT_OFFSET( VipsGrey, width ), - 1, 1000000, 1 ); - - VIPS_ARG_INT( class, "height", 5, - _( "Height" ), - _( "Image height in pixels" ), - VIPS_ARGUMENT_REQUIRED_INPUT, - G_STRUCT_OFFSET( VipsGrey, height ), - 1, 1000000, 1 ); - - VIPS_ARG_BOOL( class, "uchar", 7, - _( "Uchar" ), - _( "Output an unsigned char image" ), - VIPS_ARGUMENT_OPTIONAL_INPUT, - G_STRUCT_OFFSET( VipsGrey, uchar ), - FALSE ); + point_class->point = vips_grey_point; } static void diff --git a/libvips/create/point.c b/libvips/create/point.c new file mode 100644 index 00000000..294b9508 --- /dev/null +++ b/libvips/create/point.c @@ -0,0 +1,166 @@ +/* make a test pattern to show the point's frequency response + * + * Copyright: 1990, 1991, N.Dessipris. + * + * Author N. Dessipris + * Written on 30/05/1990 + * Updated on: 27/01/1991, 07/03/1991, + * 22/7/93 JC + * - im_outcheck() added + * 30/8/95 JC + * - modernized + * 1/2/11 + * - gtk-doc + * 13/6/13 + * - 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 + + */ + +/* +#define VIPS_DEBUG + */ + +#ifdef HAVE_CONFIG_H +#include +#endif /*HAVE_CONFIG_H*/ +#include + +#include +#include +#include +#include + +#include + +#include "create.h" +#include "point.h" + +G_DEFINE_ABSTRACT_TYPE( VipsPoint, vips_point, VIPS_TYPE_CREATE ); + +static int +vips_point_gen( VipsRegion *or, void *seq, void *a, void *b, + gboolean *stop ) +{ + VipsPoint *point = (VipsPoint *) a; + VipsPointClass *class = VIPS_POINT_GET_CLASS( point ); + VipsRect *r = &or->valid; + int le = r->left; + int to = r->top; + int ri = VIPS_RECT_RIGHT( r ); + int bo = VIPS_RECT_BOTTOM( r ); + + int x, y; + + for( y = to; y < bo; y++ ) { + float *q = (float *) VIPS_REGION_ADDR( or, le, y ); + + for( x = le; x < ri; x++ ) + *q++ = class->point( point, x, y ); + } + + return( 0 ); +} + +static int +vips_point_build( VipsObject *object ) +{ + VipsCreate *create = VIPS_CREATE( object ); + VipsPoint *point = (VipsPoint *) object; + VipsImage **t = (VipsImage **) vips_object_local_array( object, 3 ); + VipsImage *in; + + if( VIPS_OBJECT_CLASS( vips_point_parent_class )->build( object ) ) + return( -1 ); + + t[0] = vips_image_new(); + vips_image_init_fields( t[0], + point->width, point->height, 1, + VIPS_FORMAT_FLOAT, VIPS_CODING_NONE, VIPS_INTERPRETATION_B_W, + 1.0, 1.0 ); + vips_demand_hint( t[0], + VIPS_DEMAND_STYLE_ANY, NULL ); + if( vips_image_generate( t[0], + NULL, vips_point_gen, NULL, point, NULL ) ) + return( -1 ); + + in = t[0]; + if( point->uchar ) { + if( vips_linear1( in, &t[1], 127.5, 127.5, NULL ) || + vips_cast( t[1], &t[2], VIPS_FORMAT_UCHAR, NULL ) ) + return( -1 ); + in = t[2]; + } + + if( vips_image_write( in, create->out ) ) + return( -1 ); + + return( 0 ); +} + +static void +vips_point_class_init( VipsPointClass *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 = "point"; + vobject_class->description = _( "make a point image" ); + vobject_class->build = vips_point_build; + + VIPS_ARG_INT( class, "width", 2, + _( "Width" ), + _( "Image width in pixels" ), + VIPS_ARGUMENT_REQUIRED_INPUT, + G_STRUCT_OFFSET( VipsPoint, width ), + 1, 1000000, 1 ); + + VIPS_ARG_INT( class, "height", 3, + _( "Height" ), + _( "Image height in pixels" ), + VIPS_ARGUMENT_REQUIRED_INPUT, + G_STRUCT_OFFSET( VipsPoint, height ), + 1, 1000000, 1 ); + + VIPS_ARG_BOOL( class, "uchar", 7, + _( "Uchar" ), + _( "Output an unsigned char image" ), + VIPS_ARGUMENT_OPTIONAL_INPUT, + G_STRUCT_OFFSET( VipsPoint, uchar ), + FALSE ); + +} + +static void +vips_point_init( VipsPoint *point ) +{ +} + diff --git a/libvips/create/point.h b/libvips/create/point.h new file mode 100644 index 00000000..e0681859 --- /dev/null +++ b/libvips/create/point.h @@ -0,0 +1,80 @@ +/* base class for point generators + */ + +/* + + Copyright (C) 1991-2005 The National Gallery + + This library 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.1 of the License, or (at your option) any later version. + + This library 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 library; 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 + + */ + +/* We don't want to get confused with the point.h in include, put an + * extra _ in there. + */ + +#ifndef VIPS__POINT_H +#define VIPS__POINT_H + +#ifdef __cplusplus +extern "C" { +#endif /*__cplusplus*/ + +#define VIPS_TYPE_POINT (vips_point_get_type()) +#define VIPS_POINT( obj ) \ + (G_TYPE_CHECK_INSTANCE_CAST( (obj), \ + VIPS_TYPE_POINT, VipsPoint )) +#define VIPS_POINT_CLASS( klass ) \ + (G_TYPE_CHECK_CLASS_CAST( (klass), \ + VIPS_TYPE_POINT, VipsPointClass)) +#define VIPS_IS_POINT( obj ) \ + (G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_POINT )) +#define VIPS_IS_POINT_CLASS( klass ) \ + (G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_POINT )) +#define VIPS_POINT_GET_CLASS( obj ) \ + (G_TYPE_INSTANCE_GET_CLASS( (obj), \ + VIPS_TYPE_POINT, VipsPointClass )) + +typedef struct _VipsPoint { + VipsCreate parent_instance; + + int width; + int height; + + gboolean uchar; + +} VipsPoint; + +typedef struct _VipsPointClass { + VipsCreateClass parent_class; + + float (*point)( VipsPoint *, int, int ); + +} VipsPointClass; + +GType vips_point_get_type( void ); + +#ifdef __cplusplus +} +#endif /*__cplusplus*/ + +#endif /*VIPS__POINT_H*/ diff --git a/libvips/create/sines.c b/libvips/create/sines.c index 4726488f..aefd1653 100644 --- a/libvips/create/sines.c +++ b/libvips/create/sines.c @@ -58,87 +58,51 @@ #include #include "create.h" +#include "point.h" typedef struct _VipsSines { - VipsCreate parent_instance; - - int width; - int height; + VipsPoint parent_instance; double hfreq; double vfreq; - gboolean uchar; + + double c; + double sintheta; + double costheta; } VipsSines; -typedef VipsCreateClass VipsSinesClass; +typedef VipsPointClass VipsSinesClass; -G_DEFINE_TYPE( VipsSines, vips_sines, VIPS_TYPE_CREATE ); +G_DEFINE_TYPE( VipsSines, vips_sines, VIPS_TYPE_POINT ); -static int -vips_sines_gen( VipsRegion *or, void *seq, void *a, void *b, - gboolean *stop ) +static float +vips_sines_point( VipsPoint *point, int x, int y ) { - VipsSines *sines = (VipsSines *) a; - VipsRect *r = &or->valid; - int le = r->left; - int to = r->top; - int ri = VIPS_RECT_RIGHT( r ); - int bo = VIPS_RECT_BOTTOM( r ); + VipsSines *sines = (VipsSines *) point; - double theta = sines->hfreq == 0.0 ? - VIPS_PI / 2.0 : atan( sines->vfreq / sines->hfreq ); - double costheta = cos( theta ); - double sintheta = sin( theta ); - double factor = sqrt( sines->hfreq * sines->hfreq + - sines->vfreq * sines->vfreq ); - double cons = factor * VIPS_PI * 2.0 / sines->width; - - int x, y; - - for( y = to; y < bo; y++ ) { - float *q = (float *) VIPS_REGION_ADDR( or, le, y ); - double ysintheta = y * sintheta; - - for( x = le; x < ri; x++ ) - *q++ = cos( cons * (x * costheta - ysintheta) ); - } - - return( 0 ); + return( cos( sines->c * (x * sines->costheta - y * sines->sintheta) ) ); } static int vips_sines_build( VipsObject *object ) { - VipsCreate *create = VIPS_CREATE( object ); + VipsPoint *point = VIPS_POINT( object ); VipsSines *sines = (VipsSines *) object; - VipsImage **t = (VipsImage **) vips_object_local_array( object, 7 ); - VipsImage *in; + + double theta; + double factor; if( VIPS_OBJECT_CLASS( vips_sines_parent_class )->build( object ) ) return( -1 ); - t[0] = vips_image_new(); - vips_image_init_fields( t[0], - sines->width, sines->height, 1, - VIPS_FORMAT_FLOAT, VIPS_CODING_NONE, VIPS_INTERPRETATION_B_W, - 1.0, 1.0 ); - vips_demand_hint( t[0], - VIPS_DEMAND_STYLE_ANY, NULL ); - if( vips_image_generate( t[0], - NULL, vips_sines_gen, NULL, sines, NULL ) ) - return( -1 ); - - in = t[0]; - if( sines->uchar ) { - if( vips_linear1( in, &t[1], 127.5, 127.5, NULL ) || - vips_cast( t[1], &t[2], VIPS_FORMAT_UCHAR, NULL ) ) - return( -1 ); - in = t[2]; - } - - if( vips_image_write( in, create->out ) ) - return( -1 ); + theta = sines->hfreq == 0.0 ? + VIPS_PI / 2.0 : atan( sines->vfreq / sines->hfreq ); + factor = sqrt( sines->hfreq * sines->hfreq + + sines->vfreq * sines->vfreq ); + sines->costheta = cos( theta ); + sines->sintheta = sin( theta ); + sines->c = factor * VIPS_PI * 2.0 / point->width; return( 0 ); } @@ -148,6 +112,7 @@ vips_sines_class_init( VipsSinesClass *class ) { GObjectClass *gobject_class = G_OBJECT_CLASS( class ); VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS( class ); + VipsPointClass *point_class = VIPS_POINT_CLASS( class ); gobject_class->set_property = vips_object_set_property; gobject_class->get_property = vips_object_get_property; @@ -156,19 +121,7 @@ vips_sines_class_init( VipsSinesClass *class ) vobject_class->description = _( "make a 2D sine wave" ); vobject_class->build = vips_sines_build; - VIPS_ARG_INT( class, "width", 4, - _( "Width" ), - _( "Image width in pixels" ), - VIPS_ARGUMENT_REQUIRED_INPUT, - G_STRUCT_OFFSET( VipsSines, width ), - 1, 1000000, 1 ); - - VIPS_ARG_INT( class, "height", 5, - _( "Height" ), - _( "Image height in pixels" ), - VIPS_ARGUMENT_REQUIRED_INPUT, - G_STRUCT_OFFSET( VipsSines, height ), - 1, 1000000, 1 ); + point_class->point = vips_sines_point; VIPS_ARG_DOUBLE( class, "hfreq", 6, _( "hfreq" ), @@ -183,14 +136,6 @@ vips_sines_class_init( VipsSinesClass *class ) VIPS_ARGUMENT_OPTIONAL_INPUT, G_STRUCT_OFFSET( VipsSines, vfreq ), 0.0, 10000.0, 0.5 ); - - VIPS_ARG_BOOL( class, "uchar", 8, - _( "Uchar" ), - _( "Output an unsigned char image" ), - VIPS_ARGUMENT_OPTIONAL_INPUT, - G_STRUCT_OFFSET( VipsSines, uchar ), - FALSE ); - } static void @@ -200,7 +145,6 @@ vips_sines_init( VipsSines *sines ) sines->vfreq = 0.5; } - /** * vips_sines: * @out: output image diff --git a/libvips/create/zone.c b/libvips/create/zone.c index 968a6bb3..31b84b46 100644 --- a/libvips/create/zone.c +++ b/libvips/create/zone.c @@ -59,119 +59,37 @@ #include #include "create.h" +#include "point.h" -typedef struct _VipsZone { - VipsCreate parent_instance; +typedef VipsPoint VipsZone; +typedef VipsPointClass VipsZoneClass; - int width; - int height; +G_DEFINE_TYPE( VipsZone, vips_zone, VIPS_TYPE_POINT ); - gboolean uchar; - -} VipsZone; - -typedef VipsCreateClass VipsZoneClass; - -G_DEFINE_TYPE( VipsZone, vips_zone, VIPS_TYPE_CREATE ); - -static int -vips_zone_gen( VipsRegion *or, void *seq, void *a, void *b, - gboolean *stop ) +static float +vips_zone_point( VipsPoint *point, int x, int y ) { - VipsZone *zone = (VipsZone *) a; - VipsRect *r = &or->valid; - int le = r->left; - int to = r->top; - int ri = VIPS_RECT_RIGHT( r ); - int bo = VIPS_RECT_BOTTOM( r ); + VipsZone *zone = (VipsZone *) point; - int hsize = zone->width / 2; + int hwidth = point->width / 2; + int hheight = point->height / 2; + int h2 = (x - hwidth) * (x - hwidth); + int v2 = (y - hheight) * (y - hheight); double c = VIPS_PI / zone->width; - int vsize = zone->height / 2; - int x, y; - - for( y = to; y < bo; y++ ) { - float *q = (float *) VIPS_REGION_ADDR( or, le, y ); - int vp = (y - vsize) * (y - vsize); - - for( x = le; x < ri; x++ ) - *q++ = cos( c * (vp + ((x - hsize) * (x - hsize))) ); - } - - return( 0 ); -} - -static int -vips_zone_build( VipsObject *object ) -{ - VipsCreate *create = VIPS_CREATE( object ); - VipsZone *zone = (VipsZone *) object; - VipsImage **t = (VipsImage **) vips_object_local_array( object, 7 ); - VipsImage *in; - - if( VIPS_OBJECT_CLASS( vips_zone_parent_class )->build( object ) ) - return( -1 ); - - t[0] = vips_image_new(); - vips_image_init_fields( t[0], - zone->width, zone->height, 1, - VIPS_FORMAT_FLOAT, VIPS_CODING_NONE, VIPS_INTERPRETATION_B_W, - 1.0, 1.0 ); - vips_demand_hint( t[0], - VIPS_DEMAND_STYLE_ANY, NULL ); - if( vips_image_generate( t[0], - NULL, vips_zone_gen, NULL, zone, NULL ) ) - return( -1 ); - - in = t[0]; - if( zone->uchar ) { - if( vips_linear1( in, &t[1], 127.5, 127.5, NULL ) || - vips_cast( t[1], &t[2], VIPS_FORMAT_UCHAR, NULL ) ) - return( -1 ); - in = t[2]; - } - - if( vips_image_write( in, create->out ) ) - return( -1 ); - - return( 0 ); + return( cos( c * (v2 + h2) ) ); } static void vips_zone_class_init( VipsZoneClass *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; + VipsPointClass *point_class = VIPS_POINT_CLASS( class ); vobject_class->nickname = "zone"; vobject_class->description = _( "make a zone plate" ); - vobject_class->build = vips_zone_build; - - VIPS_ARG_INT( class, "width", 4, - _( "Width" ), - _( "Image width in pixels" ), - VIPS_ARGUMENT_REQUIRED_INPUT, - G_STRUCT_OFFSET( VipsZone, width ), - 1, 1000000, 1 ); - - VIPS_ARG_INT( class, "height", 5, - _( "Height" ), - _( "Image height in pixels" ), - VIPS_ARGUMENT_REQUIRED_INPUT, - G_STRUCT_OFFSET( VipsZone, height ), - 1, 1000000, 1 ); - - VIPS_ARG_BOOL( class, "uchar", 7, - _( "Uchar" ), - _( "Output an unsigned char image" ), - VIPS_ARGUMENT_OPTIONAL_INPUT, - G_STRUCT_OFFSET( VipsZone, uchar ), - FALSE ); + point_class->point = vips_zone_point; } static void @@ -179,7 +97,6 @@ vips_zone_init( VipsZone *zone ) { } - /** * vips_zone: * @out: output image