polish vips_xyz() a bit

and remove the old one
This commit is contained in:
John Cupitt 2013-06-12 17:59:29 +01:00
parent 86f3d2b083
commit 7430e49f91
8 changed files with 39 additions and 138 deletions

View File

@ -558,28 +558,28 @@ vips_embed_class_init( VipsEmbedClass *class )
_( "Left edge of input in output" ),
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsEmbed, x ),
-1000000, 1000000, 0 );
-1000000000, 1000000000, 0 );
VIPS_ARG_INT( class, "y", 3,
_( "y" ),
_( "Top edge of input in output" ),
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsEmbed, y ),
-1000000, 1000000, 0 );
-1000000000, 1000000000, 0 );
VIPS_ARG_INT( class, "width", 4,
_( "Width" ),
_( "Image width in pixels" ),
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsEmbed, width ),
1, 1000000, 1 );
1, 1000000000, 1 );
VIPS_ARG_INT( class, "height", 5,
_( "Height" ),
_( "Image height in pixels" ),
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsEmbed, height ),
1, 1000000, 1 );
1, 1000000000, 1 );
VIPS_ARG_ENUM( class, "extend", 6,
_( "Extend" ),

View File

@ -88,29 +88,29 @@ vips_xyz_gen( VipsRegion *or, void *seq, void *a, void *b,
unsigned int *q = (unsigned int *)
VIPS_REGION_ADDR( or, le, y );
unsigned int dims[4];
unsigned int dims[5];
int r;
int h;
h = xyz->height * xyz->csize * xyz->dsize;
dims[3] = y / h;
dims[4] = y / h;
r = y % h;
h /= xyz->dsize;
dims[2] = r / h;
dims[3] = r / h;
r %= h;
h /= xyz->csize;
dims[1] = r / h;
dims[2] = r / h;
r %= h;
dims[0] = r;
dims[1] = r;
for( x = le; x < ri; x++ ) {
q[0] = x;
dims[0] = x;
for( i = 0; i < xyz->dimensions; i++ )
q[i] = dims[i];
for( i = 1; i < xyz->dimensions; i++ )
q[1] = dims[i - 1];
q += xyz->dimensions;
}
}
@ -208,21 +208,21 @@ vips_xyz_class_init( VipsXyzClass *class )
_( "Size of third dimension" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsXyz, csize ),
1, 1000000, 0 );
1, 1000000, 1 );
VIPS_ARG_INT( class, "dsize", 7,
_( "dsize" ),
_( "Size of fourth dimension" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsXyz, dsize ),
1, 1000000, 0 );
1, 1000000, 1 );
VIPS_ARG_INT( class, "esize", 8,
_( "esize" ),
_( "Size of fifth dimension" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsXyz, esize ),
1, 1000000, 0 );
1, 1000000, 1 );
}

View File

@ -1559,6 +1559,22 @@ im_msb_band( VipsImage *in, VipsImage *out, int band )
return( 0 );
}
int
im_make_xy( IMAGE *out, const int xsize, const int ysize )
{
VipsImage *t;
if( vips_xyz( &t, xsize, ysize, NULL ) )
return( -1 );
if( vips_image_write( t, out ) ) {
g_object_unref( t );
return( -1 );
}
g_object_unref( t );
return( 0 );
}
int
im_text( IMAGE *out, const char *text, const char *font,
int width, int align, int dpi )

View File

@ -40,7 +40,6 @@ extern "C" {
int im_grey( VipsImage *out, const int xsize, const int ysize );
int im_fgrey( VipsImage *out, const int xsize, const int ysize );
int im_make_xy( VipsImage *out, const int xsize, const int ysize );
int im_feye( VipsImage *out,
const int xsize, const int ysize, const double factor );

View File

@ -711,6 +711,7 @@ 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 );
int im_black( VipsImage *out, int x, int y, int bands );
int im_make_xy( VipsImage *out, const int xsize, const int ysize );
int im_gaussnoise( VipsImage *out, int x, int y, double mean, double sigma );
int im_grid( VipsImage *in, VipsImage *out, int tile_height, int across, int down );
int im_scale( VipsImage *in, VipsImage *out );

View File

@ -895,21 +895,21 @@ vips_image_class_init( VipsImageClass *class )
_( "Image width in pixels" ),
VIPS_ARGUMENT_SET_ALWAYS,
G_STRUCT_OFFSET( VipsImage, Xsize ),
0, 1000000, 0 );
1, 1000000000, 1 );
VIPS_ARG_INT( class, "height", 3,
_( "Height" ),
_( "Image height in pixels" ),
VIPS_ARGUMENT_SET_ALWAYS,
G_STRUCT_OFFSET( VipsImage, Ysize ),
0, 1000000, 0 );
1, 1000000000, 1 );
VIPS_ARG_INT( class, "bands", 4,
_( "Bands" ),
_( "Number of bands in image" ),
VIPS_ARGUMENT_SET_ALWAYS,
G_STRUCT_OFFSET( VipsImage, Bands ),
0, 1000000, 0 );
1, 1000000000, 1 );
VIPS_ARG_ENUM( class, "format", 5,
_( "Format" ),
@ -1065,6 +1065,10 @@ vips_image_init( VipsImage *image )
*/
image->magic = vips_amiMSBfirst() ? VIPS_MAGIC_SPARC : VIPS_MAGIC_INTEL;
image->Xsize = 1;
image->Ysize = 1;
image->Bands = 1;
image->Xres = 1.0;
image->Yres = 1.0;

View File

@ -4,7 +4,6 @@ libother_la_SOURCES = \
im_benchmark.c \
im_eye.c \
im_grey.c \
im_make_xy.c \
im_sines.c \
im_zone.c \
other_dispatch.c

View File

@ -1,118 +0,0 @@
/* make an xy index image
*
* 21/4/04
* - from im_grey
* 1/2/11
* - gtk-doc
*/
/*
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 <math.h>
#include <vips/vips.h>
/* Generate function.
*/
static int
make_xy_gen( REGION *or, void *seq, void *a, void *b )
{
Rect *r = &or->valid;
int le = r->left;
int to = r->top;
int ri = IM_RECT_RIGHT( r );
int bo = IM_RECT_BOTTOM( r );
int x, y;
for( y = to; y < bo; y++ ) {
unsigned int *q = (unsigned int *) IM_REGION_ADDR( or, le, y );
for( x = le; x < ri; x++ ) {
q[0] = x;
q[1] = y;
q += 2;
}
}
return( 0 );
}
/**
* im_make_xy:
* @out: output image
* @xsize: image size
* @ysize: image size
*
* Create a two-band uint32 image where the elements in the first band have the
* value of their x coordinate and elements in the second band have their y
* coordinate.
*
* You can make any image where the value of a pixel is a function of its (x,
* y) coordinate by combining this operator with the arithmetic operators.
*
* See also: im_grey(), im_identity().
*
* Returns: 0 on success, -1 on error
*/
int
im_make_xy( IMAGE *out, const int xsize, const int ysize )
{
/* Check args.
*/
if( xsize <=0 || ysize <= 0 ) {
im_error( "im_make_xy", "%s", _( "bad size" ) );
return( -1 );
}
if( im_poutcheck( out ) )
return( -1 );
/* Set image.
*/
im_initdesc( out, xsize, ysize, 2, IM_BBITS_INT, IM_BANDFMT_UINT,
IM_CODING_NONE, IM_TYPE_MULTIBAND, 1.0, 1.0, 0, 0 );
/* Set hints - ANY is ok with us.
*/
if( im_demand_hint( out, IM_ANY, NULL ) )
return( -1 );
/* Generate image.
*/
if( im_generate( out, NULL, make_xy_gen, NULL, NULL, NULL ) )
return( -1 );
return( 0 );
}