diff --git a/ChangeLog b/ChangeLog index 2d046948..94a9b713 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19,6 +19,9 @@ remaining fopen()s - move cooc_* and glds_* to deprecated - move im_dif_std() to almostdeprecated +- move im_simcontr() to almostdeprecated +- add im_sines() to operation db +- move im_spatres() to almostdeprecated 30/11/10 started 7.24.0 - bump for new stable diff --git a/libvips/deprecated/Makefile.am b/libvips/deprecated/Makefile.am index 83af88dd..ebec85fa 100644 --- a/libvips/deprecated/Makefile.am +++ b/libvips/deprecated/Makefile.am @@ -3,6 +3,8 @@ noinst_LTLIBRARIES = libdeprecated.la libdeprecated_la_SOURCES = \ deprecated_dispatch.c \ im_dif_std.c \ + im_simcontr.c \ + im_spatres.c \ cooc_funcs.c \ glds_funcs.c \ im_fav4.c \ diff --git a/libvips/other/im_simcontr.c b/libvips/deprecated/im_simcontr.c similarity index 66% rename from libvips/other/im_simcontr.c rename to libvips/deprecated/im_simcontr.c index eb174650..bdf93fe8 100644 --- a/libvips/other/im_simcontr.c +++ b/libvips/deprecated/im_simcontr.c @@ -1,11 +1,4 @@ -/* @(#) creates a pattern showing the similtaneous constrast effect - * @(#) - * @(#) Usage: int im_simcontr(image, xs, ys) - * @(#) IMAGE *image; - * @(#) int xs, ys; - * @(#) - * @(#) Returns 0 on success and -1 on error - * @(#) +/* creates a pattern showing the similtaneous constrast effect * * Copyright: 1990, N. Dessipris. * @@ -15,6 +8,8 @@ * 22/7/93 JC * - externs removed * - im_outcheck() added + * 1/2/11 + * - gtk-doc */ /* @@ -58,72 +53,84 @@ #include #endif /*WITH_DMALLOC*/ +/** + * im_simcontr: + * @out: output image + * @xsize: image size + * @ysize: image size + * + * Creates a pattern showing the similtaneous constrast effect. + * + * See also: im_eye(). + * + * Returns: 0 on success, -1 on error + */ int -im_simcontr( IMAGE *image, int xs, int ys ) +im_simcontr( IMAGE *out, int xsize, int ysize ) { int x, y; unsigned char *line1, *line2, *cpline; /* Check input args */ - if( im_outcheck( image ) ) + if( im_outcheck( out ) ) return( -1 ); /* Set now image properly */ - im_initdesc(image, xs, ys, 1, IM_BBITS_BYTE, IM_BANDFMT_UCHAR, + im_initdesc(out, xsize, ysize, 1, IM_BBITS_BYTE, IM_BANDFMT_UCHAR, IM_CODING_NONE, IM_TYPE_B_W, 1.0, 1.0, 0, 0 ); /* Set up image checking whether the output is a buffer or a file */ - if (im_setupout( image ) == -1 ) + if (im_setupout( out ) == -1 ) return( -1 ); /* Create data */ - line1 = (unsigned char *)calloc((unsigned)xs, sizeof(char)); - line2 = (unsigned char *)calloc((unsigned)xs, sizeof(char)); + line1 = (unsigned char *)calloc((unsigned)xsize, sizeof(char)); + line2 = (unsigned char *)calloc((unsigned)xsize, sizeof(char)); if ( (line1 == NULL) || (line2 == NULL) ) { im_error( "im_simcontr", "%s", _( "calloc failed") ); return(-1); } cpline = line1; - for (x=0; x #endif /*WITH_DMALLOC*/ +/** + * im_feye: + * @out: output image + * @xsize: image size + * @ysize: image size + * @factor: image size + * + * Create a test pattern with increasing spatial frequence in X and + * amplitude in Y. @factor should be between 0 and 1 and determines the + * maximum spatial frequency. + * + * Creates an one band float image with values in +1 to -1. + * + * See also: im_eye(). + * + * Returns: 0 on success, -1 on error + */ int -im_feye( IMAGE *image, const int xsize, const int ysize, const double factor ) +im_feye( IMAGE *out, const int xsize, const int ysize, const double factor ) { int x, y; double constant; @@ -72,7 +81,7 @@ im_feye( IMAGE *image, const int xsize, const int ysize, const double factor ) /* Check input args */ - if( im_outcheck( image ) ) + if( im_outcheck( out ) ) return( -1 ); if( factor > 1.0 || factor <= 0.0 ) { im_error( "im_feye", "%s", _( "factor should be in [1,0)" ) ); @@ -81,52 +90,61 @@ im_feye( IMAGE *image, const int xsize, const int ysize, const double factor ) /* Set image descriptor */ - im_initdesc( image, xsize, ysize, 1, IM_BBITS_FLOAT, IM_BANDFMT_FLOAT, + im_initdesc( out, xsize, ysize, 1, IM_BBITS_FLOAT, IM_BANDFMT_FLOAT, IM_CODING_NONE, IM_TYPE_B_W, 1.0, 1.0, 0, 0 ); - if( im_setupout( image ) ) + if( im_setupout( out ) ) return( -1 ); /* Allocate space for line buffer. */ - if( !(line = IM_ARRAY( image, xsize, float )) ) + if( !(line = IM_ARRAY( out, xsize, float )) ) return( -1 ); /* Make a lut for easy calculations. */ - if( !(lut = IM_ARRAY( image, image->Xsize, double )) ) + if( !(lut = IM_ARRAY( out, xsize, double )) ) return( -1 ); - constant = factor * IM_PI/(2*(xsize - 1)); - for( x = 0; x < image->Xsize; x++ ) - lut[x] = cos( constant*x*x ) / ((ysize - 1)*(ysize - 1)); + constant = factor * IM_PI / (2 * (xsize - 1)); + for( x = 0; x < xsize; x++ ) + lut[x] = cos( constant * x * x ) / ((ysize - 1) * (ysize - 1)); /* Make image. */ - for( y = 0; y < image->Ysize; y++ ) { - for( x = 0; x < image->Xsize; x++ ) - line[x] = y*y*lut[x]; - if( im_writeline( y, image, (PEL *) line ) ) + for( y = 0; y < ysize; y++ ) { + for( x = 0; x < xsize; x++ ) + line[x] = y * y * lut[x]; + if( im_writeline( y, out, (PEL *) line ) ) return( -1 ); } return( 0 ); } -/* As above, but make a IM_BANDFMT_UCHAR image. +/** + * im_eye: + * @out: output image + * @xsize: image size + * @ysize: image size + * @factor: image size + * + * Exactly as im_feye(), but make a UCHAR image with pixels in the range [0, + * 255]. + * + * See also: im_feye(). + * + * Returns: 0 on success, -1 on error */ int -im_eye( IMAGE *image, const int xsize, const int ysize, const double factor ) +im_eye( IMAGE *out, const int xsize, const int ysize, const double factor ) { - IMAGE *t1 = im_open_local( image, "im_eye:1", "p" ); - IMAGE *t2 = im_open_local( image, "im_eye:2", "p" ); - - if( !t1 ) - return( -1 ); + IMAGE *t[2]; /* Change range to [0,255]. */ - if( im_feye( t1, xsize, ysize, factor ) || - im_lintra( 127.5, t1, 127.5, t2 ) || - im_clip2fmt( t2, image, IM_BANDFMT_UCHAR ) ) + if( im_open_local_array( out, t, 2, "im_grey", "p" ) || + im_feye( t[0], xsize, ysize, factor ) || + im_lintra( 127.5, t[0], 127.5, t[1] ) || + im_clip2fmt( t[1], out, IM_BANDFMT_UCHAR ) ) return( -1 ); return( 0 ); diff --git a/libvips/other/im_grey.c b/libvips/other/im_grey.c index e8c2bc74..3c0585c4 100644 --- a/libvips/other/im_grey.c +++ b/libvips/other/im_grey.c @@ -1,15 +1,4 @@ -/* @(#) Creates a IM_BANDFMT_FLOAT grey level image of a specified size. Range is - * @(#) always [0,1]. - * @(#) - * @(#) Usage: - * @(#) - * @(#) int - * @(#) im_fgrey( image, xsize, ysize ) - * @(#) IMAGE *image; - * @(#) int xsize, ysize; - * @(#) - * @(#) Returns 0 on success and -1 on error - * @(#) +/* grey ramps * * Copyright: 1990, N. Dessipris. * @@ -27,6 +16,8 @@ * - im_grey() now defined in terms of im_fgrey() * 2/3/98 JC * - partialed + * 1/2/11 + * - gtk-doc */ /* @@ -92,7 +83,18 @@ fgrey_gen( REGION *or, void *seq, void *a, void *b ) return( 0 ); } -/* Make a one band grey ramp image. +/** + * im_fgrey: + * @out: output image + * @xsize: image size + * @ysize: image size + * + * Create a one-band float image with the left-most column zero and the + * right-most 1. Intermediate pixels are a linear ramp. + * + * See also: im_grey(), im_make_xy(), im_identity(). + * + * Returns: 0 on success, -1 on error */ int im_fgrey( IMAGE *out, const int xsize, const int ysize ) @@ -124,22 +126,30 @@ im_fgrey( IMAGE *out, const int xsize, const int ysize ) return( 0 ); } -/* As above, but make a IM_BANDFMT_UCHAR [0-255] image. +/** + * im_grey: + * @out: output image + * @xsize: image size + * @ysize: image size + * + * Create a one-band uchar image with the left-most column zero and the + * right-most 255. Intermediate pixels are a linear ramp. + * + * See also: im_fgrey(), im_make_xy(), im_identity(). + * + * Returns: 0 on success, -1 on error */ int -im_grey( IMAGE *image, const int xsize, const int ysize ) +im_grey( IMAGE *out, const int xsize, const int ysize ) { - IMAGE *t1 = im_open_local( image, "im_grey:1", "p" ); - IMAGE *t2 = im_open_local( image, "im_grey:2", "p" ); - - if( !t1 || !t2 ) - return( -1 ); + IMAGE *t[2]; /* Change range to [0,255]. */ - if( im_fgrey( t1, xsize, ysize ) || - im_lintra( 255.0, t1, 0.0, t2 ) || - im_clip2fmt( t2, image, IM_BANDFMT_UCHAR ) ) + if( im_open_local_array( out, t, 2, "im_grey", "p" ) || + im_fgrey( t[0], xsize, ysize ) || + im_lintra( 255.0, t[0], 0.0, t[1] ) || + im_clip2fmt( t[1], out, IM_BANDFMT_UCHAR ) ) return( -1 ); return( 0 ); diff --git a/libvips/other/im_make_xy.c b/libvips/other/im_make_xy.c index ad8500a6..fcf08567 100644 --- a/libvips/other/im_make_xy.c +++ b/libvips/other/im_make_xy.c @@ -1,18 +1,9 @@ -/* @(#) Creates a 2 band IM_BANDFMT_UINT image of a specified size. Each pixel - * @(#) has band 0 == x coordinate, band 1 == y coordinate. - * @(#) - * @(#) Usage: - * @(#) - * @(#) int - * @(#) im_make_xy( image, xsize, ysize ) - * @(#) IMAGE *image; - * @(#) int xsize, ysize; - * @(#) - * @(#) Returns 0 on success and -1 on error - * @(#) +/* make an xy index image * * 21/4/04 * - from im_grey + * 1/2/11 + * - gtk-doc */ /* @@ -82,8 +73,22 @@ make_xy_gen( REGION *or, void *seq, void *a, void *b ) return( 0 ); } -/* Make a two band image ... band 0 is x coordinates, band 1 is y - * coordinates. +/** + * 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 ) diff --git a/libvips/other/im_sines.c b/libvips/other/im_sines.c index ff2f0f5a..ef4cc8fd 100644 --- a/libvips/other/im_sines.c +++ b/libvips/other/im_sines.c @@ -1,16 +1,4 @@ -/* @(#) creates a sinewave with horfreq cycles per horizontal direction and - * @(#) verfreq cycles per vertical direction - * @(#) If horfreq and verfreq are integers the resultant image is periodical - * @(#) and therfore the Fourier transform doesnot present spikes - * @(#) Image should have been set by a call to im_setbuf() or im_openout() - * @(#) - * @(#) Usage: int im_sines(image, xsize, ysize, horfreq, verfreq) - * @(#) IMAGE *image; - * @(#) int xsize, ysize; - * @(#) double horfreq, verfreq; - * @(#) - * @(#) Returns 0 on success and -1 on error - * @(#) +/* creates a 2d sinewave * * Copyright: 1990, N. Dessipris. * @@ -20,6 +8,8 @@ * 22/7/93 JC * - externs removed * - im_outcheck() added + * 1/2/11 + * - gtk-doc */ /* @@ -62,9 +52,32 @@ #ifdef WITH_DMALLOC #include #endif /*WITH_DMALLOC*/ - + +/** + * im_sines: + * @out: output image + * @xsize: image size + * @ysize: image size + * @horfreq: horizontal frequency + * @verfreq: vertical frequency + * + * im_sines() creates a float one band image of the a sine waveform in two + * dimensions. + * + * The number of horizontal and vertical spatial frequencies are + * determined by the variables @horfreq and @verfreq respectively. The + * function is useful for creating displayable sine waves and + * square waves in two dimensions. + * + * If horfreq and verfreq are integers the resultant image is periodical + * and therfore the Fourier transform doesnot present spikes + * + * See also: im_grey(), im_make_xy(). + * + * Returns: 0 on success, -1 on error + */ int -im_sines( IMAGE *image, int xsize, int ysize, double horfreq, double verfreq ) +im_sines( IMAGE *out, int xsize, int ysize, double horfreq, double verfreq ) { int x, y; float *line, *cpline; @@ -73,21 +86,21 @@ im_sines( IMAGE *image, int xsize, int ysize, double horfreq, double verfreq ) double theta_rad, costheta, sintheta, ysintheta; /* Check input args */ - if( im_outcheck( image ) ) + if( im_outcheck( out ) ) return( -1 ); if ( xsize <= 0 || ysize <= 0 ) { im_error( "im_sines", "%s", _( "wrong sizes") ); return(-1); } -/* Set now image properly */ - im_initdesc(image, xsize, ysize, 1, IM_BBITS_FLOAT, IM_BANDFMT_FLOAT, +/* Set now out properly */ + im_initdesc(out, xsize, ysize, 1, IM_BBITS_FLOAT, IM_BANDFMT_FLOAT, IM_CODING_NONE, IM_TYPE_B_W, 1.0, 1.0, 0, 0); -/* Set up image checking whether the output is a buffer or a file */ - if (im_setupout( image ) == -1 ) +/* Set up out checking whether the output is a buffer or a file */ + if (im_setupout( out ) == -1 ) return( -1 ); /* Create data */ - size = image->Xsize; + size = out->Xsize; if ( (line=(float *)calloc((unsigned)size, sizeof(float))) == NULL ) { im_error( "im_sines", "%s", _( "calloc failed") ); return(-1); } @@ -99,19 +112,19 @@ im_sines( IMAGE *image, int xsize, int ysize, double horfreq, double verfreq ) theta_rad = atan(verfreq/horfreq); costheta = cos(theta_rad); sintheta = sin(theta_rad); factor = sqrt ((double)(horfreq*horfreq + verfreq*verfreq)); - cons = factor * IM_PI * 2.0/(double)image->Xsize; + cons = factor * IM_PI * 2.0/(double)out->Xsize; /* There is a bug (rounding error ?) for horfreq=0, *so do this calculation independantly */ if ( horfreq != 0 ) { - for (y=0; yYsize; y++) + for (y=0; yYsize; y++) { ysintheta = y * sintheta; cpline = line; - for (x=0; xXsize; x++) + for (x=0; xXsize; x++) *cpline++ = (float)(cos(cons*(x*costheta-ysintheta))); - if ( im_writeline( y, image, (PEL *)line ) == -1 ) + if ( im_writeline( y, out, (PEL *)line ) == -1 ) { free ( (char *)line ); return( -1 ); @@ -120,13 +133,13 @@ im_sines( IMAGE *image, int xsize, int ysize, double horfreq, double verfreq ) } else { - for (y=0; yYsize; y++) + for (y=0; yYsize; y++) { cpline = line; ysintheta = cos (- cons * y * sintheta); - for (x=0; xXsize; x++) + for (x=0; xXsize; x++) *cpline++ = (float)ysintheta; - if ( im_writeline( y, image, (PEL *)line ) == -1 ) + if ( im_writeline( y, out, (PEL *)line ) == -1 ) { free ( (char *)line ); return( -1 ); diff --git a/libvips/other/other_dispatch.c b/libvips/other/other_dispatch.c index 491efffc..c6a01182 100644 --- a/libvips/other/other_dispatch.c +++ b/libvips/other/other_dispatch.c @@ -54,6 +54,40 @@ * The im_benchmark() operations are for testing the VIPS SMP system. */ +/* Args for im_sines. + */ +static im_arg_desc sines_args[] = { + IM_OUTPUT_IMAGE( "out" ), + IM_INPUT_INT( "xsize" ), + IM_INPUT_INT( "ysize" ), + IM_INPUT_DOUBLE( "horfreq" ), + IM_INPUT_DOUBLE( "verfreq" ) +}; + +/* Call im_sines via arg vector. + */ +static int +sines_vec( im_object *argv ) +{ + int xsize = *((int *) argv[1]); + int ysize = *((int *) argv[2]); + double horfreq = *((double *) argv[3]); + double verfreq = *((double *) argv[4]); + + return( im_sines( argv[0], xsize, ysize, horfreq, verfreq ) ); +} + +/* Description of im_sines. + */ +static im_function sines_desc = { + "im_sines", /* Name */ + "generate 2D sine image", + 0, /* Flags */ + sines_vec, /* Dispatch function */ + IM_NUMBER( sines_args ), /* Size of arg list */ + sines_args /* Arg list */ +}; + /* Args for im_eye. */ static im_arg_desc eye_args[] = { @@ -332,6 +366,7 @@ static im_function *other_list[] = { &fgrey_desc, &fzone_desc, &make_xy_desc, + &sines_desc, &zone_desc };