gtk-doc for mask

This commit is contained in:
John Cupitt 2010-10-23 09:27:41 +00:00
parent 13723a1cec
commit 288d8583ac
14 changed files with 401 additions and 299 deletions

View File

@ -16,7 +16,7 @@
- rewritten im_circle as im_draw_circle, im_circle moved to almostdeprecated
- added IM_TYPE_RW args for inplace ops --- nip2 uses this to wrap inplace ops
automatically
- special-case 3x3 makss in im_conv() for a 20% speedup
- special-case 3x3 masks in im_conv() for a 20% speedup
- add IM_TYPE_RW flag for im__rw_image, helps nip2 auto-wrap inplace ops
- im_insertplace() casts and bandalikes
- copy iconv.m4 and friends in bootstrap, thanks Mike
@ -36,6 +36,7 @@
- im_affine() has a larger safety margin
- fix gtk-doc warnings
- small mask load/save improvements
- mask gtk-doc done
12/5/10 started 7.22.2
- the conditional image of ifthenelse can be any format, a (!=0) is added if

3
TODO
View File

@ -1,6 +1,3 @@
- started gtk-doc-ing libvips/mask
check for maths in gtk-doc ... see im_gauss_dmask()
- maybe im_draw_smudge() is too slow :-( also, we had a sanity failure with

View File

@ -42,13 +42,13 @@
<xi:include href="xml/freq_filt.xml"/>
<xi:include href="xml/histograms_lut.xml"/>
<xi:include href="xml/inplace.xml"/>
<xi:include href="xml/mask.xml"/>
</chapter>
<chapter>
<title>VIPS operation API by section (no gtkdoc comments yet)</title>
<xi:include href="xml/morphology.xml"/>
<xi:include href="xml/resample.xml"/>
<xi:include href="xml/mask.xml"/>
<xi:include href="xml/mosaicing.xml"/>
<xi:include href="xml/other.xml"/>
<xi:include href="xml/video.xml"/>

View File

@ -428,13 +428,13 @@ conv_gen( REGION *or, void *vseq, void *a, void *b )
sum = 0; \
sum += m[0] * p0[0]; \
sum += m[1] * p0[bands]; \
sum += m[2] * p0[bands * 2]; \
sum += m[2] * p0[bands << 1]; \
sum += m[3] * p1[0]; \
sum += m[4] * p1[bands]; \
sum += m[5] * p1[bands * 2]; \
sum += m[5] * p1[bands << 1]; \
sum += m[6] * p2[0]; \
sum += m[7] * p2[bands]; \
sum += m[8] * p2[bands * 2]; \
sum += m[8] * p2[bands << 1]; \
\
p0 += 1; \
p1 += 1; \
@ -462,13 +462,13 @@ conv_gen( REGION *or, void *vseq, void *a, void *b )
sum = 0; \
sum += m[0] * p0[0]; \
sum += m[1] * p0[bands]; \
sum += m[2] * p0[bands * 2]; \
sum += m[2] * p0[bands << 1]; \
sum += m[3] * p1[0]; \
sum += m[4] * p1[bands]; \
sum += m[5] * p1[bands * 2]; \
sum += m[5] * p1[bands << 1]; \
sum += m[6] * p2[0]; \
sum += m[7] * p2[bands]; \
sum += m[8] * p2[bands * 2]; \
sum += m[8] * p2[bands << 1]; \
\
p0 += 1; \
p1 += 1; \

View File

@ -269,6 +269,9 @@ void im_free_dmat();
int im_invmat( double **, int );
int *im_offsets45( int size );
int *im_offsets90( int size );
int im_conv_f_raw( IMAGE *in, IMAGE *out, DOUBLEMASK *mask );
int im_convsep_f_raw( IMAGE *in, IMAGE *out, DOUBLEMASK *mask );

View File

@ -63,16 +63,16 @@ DOUBLEMASK *im_create_dmaskv( const char *filename, int xsize, int ysize, ... );
INTMASK *im_read_imask( const char *filename );
DOUBLEMASK *im_read_dmask( const char *filename );
void im_print_imask( INTMASK *m );
void im_print_dmask( DOUBLEMASK *m );
void im_print_imask( INTMASK *in );
void im_print_dmask( DOUBLEMASK *in );
int im_write_imask( INTMASK *m );
int im_write_dmask( DOUBLEMASK *m );
int im_write_imask_name( INTMASK *m, const char *filename );
int im_write_dmask_name( DOUBLEMASK *m, const char *filename );
int im_write_imask( INTMASK *in );
int im_write_dmask( DOUBLEMASK *in );
int im_write_imask_name( INTMASK *in, const char *filename );
int im_write_dmask_name( DOUBLEMASK *in, const char *filename );
int im_free_imask( INTMASK *m );
int im_free_dmask( DOUBLEMASK *m );
int im_free_imask( INTMASK *in );
int im_free_dmask( DOUBLEMASK *in );
INTMASK *im_log_imask( const char *filename, double sigma, double min_ampl );
DOUBLEMASK *im_log_dmask( const char *filename, double sigma, double min_ampl );
@ -83,20 +83,19 @@ INTMASK *im_gauss_imask_sep( const char *filename,
DOUBLEMASK *im_gauss_dmask( const char *filename,
double sigma, double min_ampl );
INTMASK *im_dup_imask( INTMASK *m, const char *filename );
DOUBLEMASK *im_dup_dmask( DOUBLEMASK *m, const char *filename );
INTMASK *im_dup_imask( INTMASK *in, const char *filename );
DOUBLEMASK *im_dup_dmask( DOUBLEMASK *in, const char *filename );
INTMASK *im_scale_dmask( DOUBLEMASK *m, const char *filename );
INTMASK *im_scale_dmask( DOUBLEMASK *in, const char *filename );
void im_norm_dmask( DOUBLEMASK *mask );
int *im_offsets45( int size );
int *im_offsets90( int size );
INTMASK *im_rotate_imask90( INTMASK *m, const char *filename );
INTMASK *im_rotate_imask45( INTMASK *m, const char *filename );
DOUBLEMASK *im_rotate_dmask90( DOUBLEMASK *m, const char *filename );
DOUBLEMASK *im_rotate_dmask45( DOUBLEMASK *m, const char *filename );
INTMASK *im_rotate_imask90( INTMASK *in, const char *filename );
INTMASK *im_rotate_imask45( INTMASK *in, const char *filename );
DOUBLEMASK *im_rotate_dmask90( DOUBLEMASK *in, const char *filename );
DOUBLEMASK *im_rotate_dmask45( DOUBLEMASK *in, const char *filename );
DOUBLEMASK *im_mattrn( DOUBLEMASK *in, const char *filename );
DOUBLEMASK *im_matcat( DOUBLEMASK *in1, DOUBLEMASK *in2, const char *filename );
DOUBLEMASK *im_matcat( DOUBLEMASK *top, DOUBLEMASK *bottom,
const char *filename );
DOUBLEMASK *im_matmul( DOUBLEMASK *in1, DOUBLEMASK *in2, const char *filename );
DOUBLEMASK *im_lu_decomp( const DOUBLEMASK *mat, const char *filename );

View File

@ -1,7 +1,6 @@
/* generate gaussian masks
*/
/* Written on: 30/11/1989 by Nicos
*
* Written on: 30/11/1989 by Nicos
* Updated on: 6/12/1991
* 7/8/96 JC
* - ansified, mem leaks plugged

View File

@ -1,27 +1,6 @@
/* @(#) Returns a circularly symmetric difference of Gaussian mask
* @(#) min_amplitude should be greater than 0.0 and less than 1.0
* @(#) min_amplitude determines the size of the mask; if for instance
* @(#) the value .1 is entered this means that the produced mask is clipped
* @(#) at values less than 10 percent of the minimum negative amplitude.
* @(#) If the value of min_amplitude is too small, then the filter coefficients
* @(#) are calculated for masksize equal to the min of 8 * sigma or 256.
* @(#) The mask can be directly used with the vasari convolution programs,
* @(#) the default offset set is 0
* @(#)
* @(#) DOUBLEMASK *im_log_dmask( filename, sigma, min_amplitude )
* @(#) char *filename;
* @(#) double sigma, min_amplitude;
* @(#)
* @(#) Returns a laplacian of Gaussian square double mask or NULL on error
* @(#)
* @(#) DOUBLEMASK *im_log_imask( filename, sigma, min_amplitude )
* @(#) char *filename;
* @(#) double sigma, min_amplitude;
* @(#)
* @(#) Returns a laplacian of Gaussian square int mask or NULL on error
*/
/* Written on: 30/11/1989
/* laplacian of gaussian
*
* Written on: 30/11/1989
* Updated on: 6/12/1991
* 7/8/96 JC
* - ansified, mem leaks plugged
@ -31,6 +10,8 @@
* - ahem, was broken since '96, thanks matt
* 16/7/03 JC
* - makes mask out to zero, not out to minimum, thanks again matt
* 22/10/10
* - gtkdoc
*/
/*
@ -80,6 +61,34 @@
#define IM_MAXMASK 256
/**
* im_log_dmask:
* @filename: the returned mask has this set as the filename
* @sigma: standard deviation of mask
* @min_ampl: minimum amplitude
*
* im_log_dmask() creates a circularly symmetric Laplacian of Gaussian mask
* of radius
* @sigma. The size of the mask is determined by the variable @min_ampl;
* if for instance the value .1 is entered this means that the produced mask
* is clipped at values within 10 persent of zero, and where the change
* between mask elements is less than 10%.
*
* The program uses the following equation: (from Handbook of Pattern
* Recognition and image processing by Young and Fu, AP 1986 pages 220-221):
*
* H(r) = (1 / (2 * M_PI * s4)) *
* (2 - (r2 / s2)) *
* exp(-r2 / (2 * s2))
*
* where s2 = sigma * sigma, s4 = s2 * s2, r2 = r * r.
*
* The generated mask has odd size and its maximum value is normalised to 1.0.
*
* See also: im_log_imask(), im_gauss_dmask(), im_conv().
*
* Returns: the calculated mask on success, or NULL on error.
*/
DOUBLEMASK *
im_log_dmask( const char *filename, double sigma, double min_ampl )
{
@ -135,8 +144,10 @@ im_log_dmask( const char *filename, double sigma, double min_ampl )
return( NULL );
}
xm2 = x; ym2 = x;
xm = xm2 * 2 + 1; ym = ym2 * 2 + 1;
xm2 = x;
ym2 = x;
xm = xm2 * 2 + 1;
ym = ym2 * 2 + 1;
if( !(cfs = IM_ARRAY( NULL, (xm2 + 1) * (ym2 + 1), double )) )
return( NULL );
@ -201,6 +212,19 @@ im_log_dmask( const char *filename, double sigma, double min_ampl )
return( m );
}
/**
* im_log_imask:
* @filename: the returned mask has this set as the filename
* @sigma: standard deviation of mask
* @min_ampl: minimum amplitude
*
* im_log_imask() works exactly as im_log_dmask(), but the returned mask
* is scaled so that it's maximum value it set to 100.
*
* See also: im_log_dmask(), im_gauss_imask(), im_conv().
*
* Returns: the calculated mask on success, or NULL on error.
*/
INTMASK *
im_log_imask( const char *filename, double sigma, double min_ampl )
{

View File

@ -1,13 +1,9 @@
/* @(#) combine two masks. Result mask is made and returned.
* @(#) Pass in the name to set in the creation of the mask.
* @(#) DOUBLEMASK *
* @(#) im_matcat( in1, in2, name );
* @(#) DOUBLEMASK *in1, *in2;
* @(#) char *name;
* @(#)
* @(#) return NULL for error.
/* matrix catenate
*
* 1994, K. Martinez
*
* 22/10/10
* - gtk-doc
*/
/*
@ -50,39 +46,49 @@
#include <dmalloc.h>
#endif /*WITH_DMALLOC*/
/* MATRIX concatenate (join columns ie add mask to bottom of another)
/**
* im_matcat:
* @top: input matrix
* @bottom: input matrix
* @filename: filename for output
*
* Matrix catenations. Returns a new matrix which is the two source matrices
* joined together top-bottom. They must be the same width.
*
* See also: im_mattrn(), im_matmul(), im_matinv().
*
* Returns: the joined mask on success, or NULL on error.
*/
DOUBLEMASK *
im_matcat( DOUBLEMASK *in1, DOUBLEMASK *in2, const char *name )
im_matcat( DOUBLEMASK *top, DOUBLEMASK *bottom, const char *filename )
{
int newxsize, newysize;
DOUBLEMASK *mat;
double *out;
/* matrices must be same width
*/
if( in1->xsize != in2->xsize ) {
im_error( "im_matcat", "%s", _( "matrices must be same width" ) );
if( top->xsize != bottom->xsize ) {
im_error( "im_matcat", "%s",
_( "matrices must be same width" ) );
return( NULL );
}
newxsize = in1->xsize;
newysize = in1->ysize + in2->ysize;
newxsize = top->xsize;
newysize = top->ysize + bottom->ysize;
/* Allocate output matrix.
*/
if( !(mat = im_create_dmask( name, newxsize, newysize )) ) {
im_error( "im_matcat", "%s", _( "unable to allocate output matrix" ) );
if( !(mat = im_create_dmask( filename, newxsize, newysize )) )
return( NULL );
}
/* copy first matrix then add second on the end
*/
memcpy( mat->coeff, in1->coeff,
in1->xsize * in1->ysize * sizeof( double ) );
out = mat->coeff + in1->xsize * in1->ysize;
memcpy( out, in2->coeff,
in2->xsize * in2->ysize * sizeof( double ) );
memcpy( mat->coeff, top->coeff,
top->xsize * top->ysize * sizeof( double ) );
out = mat->coeff + top->xsize * top->ysize;
memcpy( out, bottom->coeff,
bottom->xsize * bottom->ysize * sizeof( double ) );
return( mat );
}

View File

@ -1,26 +1,4 @@
/* @(#) Allocate, and return a pointer to, a DOUBLEMASK representing the LU
* @(#) decomposition of the matrix in DOUBLEMASK *mat. Give it the filename
* @(#) member *name. Returns NULL on error. Scale and offset are ignored.
* @(#)
* @(#) DOUBLEMASK *im_lu_decomp( const DOUBLEMASK *mat, const char *name );
* @(#)
* @(#) Solve the system of linear equations Ax=b, where matrix A has already
* @(#) been decomposed into LU form in DOUBLEMASK *lu. Input vector b is in
* @(#) vec and is overwritten with vector x.
* @(#)
* @(#) int im_lu_solve( const DOUBLEMASK *lu, double *vec );
* @(#)
* @(#) Allocate, and return a pointer to, a DOUBLEMASK representing the
* @(#) inverse of the matrix represented in mat. Give it the filename
* @(#) member *name. Returns NULL on error. Scale and offset are ignored.
* @(#)
* @(#) DOUBLEMASK *im_matinv( const DOUBLEMASK *mat, const char *name );
* @(#)
* @(#) Invert the matrix represented by the DOUBLEMASK *mat, and store
* @(#) it in the place of *mat. Returns -1 on error. Scale and offset
* @(#) are ignored.
* @(#)
* @(#) int im_matinv_inplace( DOUBLEMASK *mat );
/* solve and invert matrices
*
* Author: Tom Vajzovic
* Copyright: 2006, Tom Vajzovic
@ -31,6 +9,9 @@
*
* 2006-09-08 tcv:
* - complete rewrite; algorithm unchanged
*
* 22/10/10
* - gtkdoc
*/
/*
@ -108,29 +89,41 @@ mat_inv_direct(
/** EXPORTED FUNCTION DEFINITIONS **/
DOUBLEMASK *
im_lu_decomp(
const DOUBLEMASK *mat,
const char *name
){
#define FUNCTION_NAME "im_lu_decomp"
/* This function takes any square NxN DOUBLEMASK treats it as a matrix.
* It allocates a DOUBLEMASK which is (N+1)xN.
/**
* im_lu_decomp:
* @mat: matrix to decompose
* @filename: name for output matrix
*
* This function takes any square NxN #DOUBLEMASK.
* It returns a #DOUBLEMASK which is (N+1)xN.
*
* It calculates the PLU decomposition, storing the upper and diagonal parts
* of U, together with the lower parts of L, as an NxN matrix in the first
* N rows of the new matrix. The diagonal parts of L are all set to unity
* and are not stored.
*
* The final row of the new DOUBLEMASK has only integer entries, which
* The final row of the new #DOUBLEMASK has only integer entries, which
* represent the row-wise permutations made by the permuatation matrix P.
*
* The scale and offset members of the input DOUBLEMASK are ignored.
* The scale and offset members of the input #DOUBLEMASK are ignored.
*
* See:
* PRESS, W. et al, 1992. Numerical Recipies in C; The Art of Scientific
* Computing, 2nd ed. Cambridge: Cambridge University Press, pp. 43-50.
*
* PRESS, W. et al, 1992. Numerical Recipies in C; The Art of Scientific
* Computing, 2nd ed. Cambridge: Cambridge University Press, pp. 43-50.
*
* See also: im_mattrn(), im_matinv().
*
* Returns: the decomposed matrix on success, or NULL on error.
*/
DOUBLEMASK *
im_lu_decomp(
const DOUBLEMASK *mat,
const char *name
){
#define FUNCTION_NAME "im_lu_decomp"
int i, j, k;
double *row_scale;
DOUBLEMASK *lu;
@ -244,6 +237,25 @@ im_lu_decomp(
#undef FUNCTION_NAME
}
/**
* im_lu_solve:
* @lu: matrix to solve
* @vec: name for output matrix
*
* Solve the system of linear equations Ax=b, where matrix A has already
* been decomposed into LU form in DOUBLEMASK *lu. Input vector b is in
* vec and is overwritten with vector x.
*
* See:
*
* PRESS, W. et al, 1992. Numerical Recipies in C; The Art of Scientific
* Computing, 2nd ed. Cambridge: Cambridge University Press, pp. 43-50.
*
* See also: im_mattrn(), im_matinv().
*
* Returns: the decomposed matrix on success, or NULL on error.
*/
int
im_lu_solve(
const DOUBLEMASK *lu,
@ -287,10 +299,23 @@ im_lu_solve(
#undef FUNCTION_NAME
}
/**
* im_matinv:
* @mat: matrix to invert
* @filename: name for output matrix
*
* Allocate, and return a pointer to, a DOUBLEMASK representing the
* inverse of the matrix represented in @mat. Give it the filename
* member @filename. Returns NULL on error. Scale and offset are ignored.
*
* See also: im_mattrn().
*
* Returns: the inverted matrix on success, or %NULL on error.
*/
DOUBLEMASK *
im_matinv(
const DOUBLEMASK *mat,
const char *name
const char *filename
){
#define FUNCTION_NAME "im_matinv"
@ -301,7 +326,7 @@ im_matinv(
return NULL;
}
#define N ( mat -> xsize )
inv= im_create_dmask( name, N, N );
inv= im_create_dmask( filename, N, N );
if( ! inv )
return NULL;
@ -328,6 +353,18 @@ im_matinv(
#undef FUNCTION_NAME
}
/**
* im_matinv_inplace:
* @mat: matrix to invert
*
* Invert the matrix represented by the DOUBLEMASK @mat, and store
* it in the place of @mat. Scale and offset
* are ignored.
*
* See also: im_mattrn().
*
* Returns: 0 on success, or -1 on error.
*/
int
im_matinv_inplace(
DOUBLEMASK *mat

View File

@ -1,15 +1,9 @@
/* @(#) Multiplies two DOUBLEMASKs. Result matrix is made and returned.
* @(#) Pass the filename to set for the output.
* @(#)
* @(#) DOUBLEMASK *
* @(#) im_matmul( in1, in2, name )
* @(#) DOUBLEMASK *in1, *in2;
* @(#) char *name;
* @(#)
* @(#) NULL for error.
/* Multiply two matrices.
*
* Copyright: 1990, K. Martinez and J. Cupitt
*
* 23/10/10
* - gtk-doc
*/
/*
@ -51,7 +45,20 @@
#include <dmalloc.h>
#endif /*WITH_DMALLOC*/
/* MATRIX MULTIPLY?
/**
* im_matmul:
* @in1: input matrix
* @in2: input matrix
* @filename: name for output matrix
*
* Multiplies two DOUBLEMASKs. Result matrix is made and returned.
* Pass the filename to set for the output.
*
* The scale and offset members of @in1 and @in2 are ignored.
*
* See also: im_mattrn(), im_matinv().
*
* Returns: the result matrix on success, or %NULL on error.
*/
DOUBLEMASK *
im_matmul( DOUBLEMASK *in1, DOUBLEMASK *in2, const char *name )
@ -71,10 +78,8 @@ im_matmul( DOUBLEMASK *in1, DOUBLEMASK *in2, const char *name )
/* Allocate output matrix.
*/
if( !(mat = im_create_dmask( name, in2->xsize, in1->ysize )) ) {
im_error( "im_matmul", "%s", _( "unable to allocate output mask" ) );
if( !(mat = im_create_dmask( name, in2->xsize, in1->ysize )) )
return( NULL );
}
/* Multiply.
*/

View File

@ -1,12 +1,4 @@
/* @(#) Transpose a mask. Result mask is made and returned. Pass in the name
* @(#) to set for the output mask.
* @(#)
* @(#) DOUBLEMASK *
* @(#) im_mattrn( in, name );
* @(#) DOUBLEMASK *in;
* @(#) char *name;
* @(#)
* @(#) NULL for error.
/* matrix transpose
*
* Copyright: 1990, K. Martinez and J. Cupitt
*
@ -51,7 +43,17 @@
#include <dmalloc.h>
#endif /*WITH_DMALLOC*/
/* MATRIX TRANSPOSE??
/**
* im_mattrn:
* @in: input matrix
* @filename: name for output matrix
*
* Transposes the input matrix.
* Pass the filename to set for the output.
*
* See also: im_matmul(), im_matinv().
*
* Returns: the result matrix on success, or %NULL on error.
*/
DOUBLEMASK *
im_mattrn( DOUBLEMASK *in, const char *name )
@ -62,10 +64,10 @@ im_mattrn( DOUBLEMASK *in, const char *name )
/* Allocate output matrix.
*/
if( !(mat = im_create_dmask( name, in->ysize, in->xsize )) ) {
im_error( "im_mattrn", "%s", _( "unable to allocate output matrix" ) );
if( !(mat = im_create_dmask( name, in->ysize, in->xsize )) )
return( NULL );
}
mat->scale = in->scale;
mat->offset = in->offset;
/* Transpose.
*/

View File

@ -182,7 +182,6 @@ im_offsets45( int size )
return( pnt );
}
/* Creates the offsets to rotate any mask by 90 degrees.
*/
int *
@ -275,38 +274,74 @@ rotimask( offset_fn fn, INTMASK *m, const char *name )
return( out );
}
/* Returns a mask which is the argument mask rotated by 90 degrees. Filename
* of the returned mask is name.
/**
* im_rotate_dmask90:
* @in: input matrix
* @filename: name for output matrix
*
* Returns a mask which is the argument mask rotated by 90 degrees.
* Pass the filename to set for the output.
*
* See also: im_rotate_dmask45().
*
* Returns: the result matrix on success, or %NULL on error.
*/
DOUBLEMASK *
im_rotate_dmask90( DOUBLEMASK *m, const char *name )
im_rotate_dmask90( DOUBLEMASK *in, const char *filename )
{
return( rotdmask( im_offsets90, m, name ) );
return( rotdmask( im_offsets90, in, filename ) );
}
/* Returns a mask which is the argument mask rotated by 45 degrees. Filename
* of the returned mask is name.
/**
* im_rotate_dmask45:
* @in: input matrix
* @filename: name for output matrix
*
* Returns a mask which is the argument mask rotated by 45 degrees.
* Pass the filename to set for the output.
*
* See also: im_rotate_dmask90().
*
* Returns: the result matrix on success, or %NULL on error.
*/
DOUBLEMASK *
im_rotate_dmask45( DOUBLEMASK *m, const char *name )
im_rotate_dmask45( DOUBLEMASK *in, const char *filename )
{
return( rotdmask( im_offsets45, m, name ) );
return( rotdmask( im_offsets45, in, filename ) );
}
/* Returns a mask which is the argument mask rotated by 90 degrees. Filename
* of the returned mask is name.
/**
* im_rotate_imask90:
* @in: input matrix
* @filename: name for output matrix
*
* Returns a mask which is the argument mask rotated by 90 degrees.
* Pass the filename to set for the output.
*
* See also: im_rotate_imask45().
*
* Returns: the result matrix on success, or %NULL on error.
*/
INTMASK *
im_rotate_imask90( INTMASK *m, const char *name )
im_rotate_imask90( INTMASK *in, const char *filename )
{
return( rotimask( im_offsets90, m, name ) );
return( rotimask( im_offsets90, in, filename ) );
}
/* Returns a mask which is the argument mask rotated by 45 degrees. Filename
* of the returned mask is name.
/**
* im_rotate_imask45:
* @in: input matrix
* @filename: name for output matrix
*
* Returns a mask which is the argument mask rotated by 45 degrees.
* Pass the filename to set for the output.
*
* See also: im_rotate_imask90().
*
* Returns: the result matrix on success, or %NULL on error.
*/
INTMASK *
im_rotate_imask45( INTMASK *m, const char *name )
im_rotate_imask45( INTMASK *in, const char *filename )
{
return( rotimask( im_offsets45, m, name ) );
return( rotimask( im_offsets45, in, filename ) );
}

View File

@ -156,7 +156,7 @@
/**
* im_free_imask:
* @m: mask to free
* @in: mask to free
*
* Free mask structure and any attached arrays. Return zero, so we can use
* these functions as close callbacks.
@ -166,23 +166,21 @@
* Returns: zero.
*/
int
im_free_imask( INTMASK *m )
im_free_imask( INTMASK *in )
{
if( ! m )
return 0;
if( !in )
return( 0 );
if( m->coeff )
im_free( m->coeff );
if( m->filename )
im_free( m->filename );
im_free( m );
IM_FREE( in->coeff );
IM_FREE( in->filename );
IM_FREE( in );
return( 0 );
}
/**
* im_free_dmask:
* @m: mask to free
* @in: mask to free
*
* Free mask structure and any attached arrays. Return zero, so we can use
* these functions as close callbacks.
@ -192,16 +190,14 @@ im_free_imask( INTMASK *m )
* Returns: zero.
*/
int
im_free_dmask( DOUBLEMASK *m )
{
if( ! m )
return 0;
im_free_dmask( DOUBLEMASK *in )
{
if( !in )
return( 0 );
if( m->coeff )
im_free( m->coeff );
if( m->filename )
im_free( m->filename );
im_free( m );
IM_FREE( in->coeff );
IM_FREE( in->filename );
IM_FREE( in );
return( 0 );
}
@ -221,7 +217,7 @@ im_free_dmask( DOUBLEMASK *m )
INTMASK *
im_create_imask( const char *filename, int xsize, int ysize )
{
INTMASK *m;
INTMASK *out;
int size = xsize * ysize;
/* Check args.
@ -233,28 +229,28 @@ im_create_imask( const char *filename, int xsize, int ysize )
/* Allocate and initialise structure.
*/
if( !(m = IM_NEW( NULL, INTMASK )) )
if( !(out = IM_NEW( NULL, INTMASK )) )
return( NULL );
m->coeff = NULL;
m->filename = NULL;
m->scale = 1;
m->offset = 0;
m->xsize = 0;
m->ysize = 0;
out->coeff = NULL;
out->filename = NULL;
out->scale = 1;
out->offset = 0;
out->xsize = 0;
out->ysize = 0;
if( !(m->coeff = IM_ARRAY( NULL, size, int )) ) {
im_free_imask( m );
if( !(out->coeff = IM_ARRAY( NULL, size, int )) ) {
im_free_imask( out );
return( NULL );
}
(void) memset( (char *) m->coeff, 0, size * sizeof( int ) );
if( !(m->filename = im_strdup( NULL, filename )) ) {
im_free_imask( m );
(void) memset( (char *) out->coeff, 0, size * sizeof( int ) );
if( !(out->filename = im_strdup( NULL, filename )) ) {
im_free_imask( out );
return( NULL );
}
m->xsize = xsize;
m->ysize = ysize;
out->xsize = xsize;
out->ysize = ysize;
return( m );
return( out );
}
/**
@ -275,18 +271,18 @@ im_create_imaskv( const char *filename, int xsize, int ysize, ... )
{
va_list ap;
INTMASK *m;
INTMASK *out;
int i;
if( !(m = im_create_imask( filename, xsize, ysize )) )
if( !(out = im_create_imask( filename, xsize, ysize )) )
return( NULL );
va_start( ap, ysize );
for( i = 0; i < xsize * ysize; i++ )
m->coeff[i] = va_arg( ap, int );
out->coeff[i] = va_arg( ap, int );
va_end( ap );
return( m );
return( out );
}
/**
@ -304,7 +300,7 @@ im_create_imaskv( const char *filename, int xsize, int ysize, ... )
DOUBLEMASK *
im_create_dmask( const char *filename, int xsize, int ysize )
{
DOUBLEMASK *m;
DOUBLEMASK *out;
int size = xsize * ysize;
/* Check args.
@ -316,28 +312,28 @@ im_create_dmask( const char *filename, int xsize, int ysize )
/* Allocate and initialise structure.
*/
if( !(m = IM_NEW( NULL, DOUBLEMASK )) )
if( !(out = IM_NEW( NULL, DOUBLEMASK )) )
return( NULL );
m->coeff = NULL;
m->filename = NULL;
m->scale = 1.0;
m->offset = 0.0;
m->xsize = 0;
m->ysize = 0;
out->coeff = NULL;
out->filename = NULL;
out->scale = 1.0;
out->offset = 0.0;
out->xsize = 0;
out->ysize = 0;
if( !(m->coeff = IM_ARRAY( NULL, size, double )) ) {
im_free_dmask( m );
if( !(out->coeff = IM_ARRAY( NULL, size, double )) ) {
im_free_dmask( out );
return( NULL );
}
(void) memset( (char *) m->coeff, 0, size * sizeof( double ) );
if( !(m->filename = im_strdup( NULL, filename )) ) {
im_free_dmask( m );
(void) memset( (char *) out->coeff, 0, size * sizeof( double ) );
if( !(out->filename = im_strdup( NULL, filename )) ) {
im_free_dmask( out );
return( NULL );
}
m->xsize = xsize;
m->ysize = ysize;
out->xsize = xsize;
out->ysize = ysize;
return( m );
return( out );
}
/**
@ -358,18 +354,18 @@ im_create_dmaskv( const char *filename, int xsize, int ysize, ... )
{
va_list ap;
DOUBLEMASK *m;
DOUBLEMASK *out;
int i;
if( !(m = im_create_dmask( filename, xsize, ysize )) )
if( !(out = im_create_dmask( filename, xsize, ysize )) )
return( NULL );
va_start( ap, ysize );
for( i = 0; i < xsize * ysize; i++ )
m->coeff[i] = va_arg( ap, double );
out->coeff[i] = va_arg( ap, double );
va_end( ap );
return( m );
return( out );
}
/* Read a line from a file!
@ -476,7 +472,7 @@ im_read_dmask( const char *filename )
FILE *fp;
double sc, off;
int xs, ys;
DOUBLEMASK *m;
DOUBLEMASK *out;
int x, y, i, size;
char buf[IM_MAX_LINE];
@ -488,30 +484,30 @@ im_read_dmask( const char *filename )
return( NULL );
}
if( !(m = im_create_dmask( filename, xs, ys )) ) {
if( !(out = im_create_dmask( filename, xs, ys )) ) {
fclose( fp );
return( NULL );
}
m->scale = sc;
m->offset = off;
out->scale = sc;
out->offset = off;
size = xs * ys;
for( i = 0, y = 0; y < ys; y++ ) {
char *p;
if( get_line( fp, buf ) ) {
im_free_dmask( m );
im_free_dmask( out );
fclose( fp );
return( NULL );
}
for( p = buf, x = 0; p && x < xs;
x++, i++, p = im_break_token( p, " \t,\";" ) )
m->coeff[i] = g_ascii_strtod( p, NULL );
out->coeff[i] = g_ascii_strtod( p, NULL );
}
fclose( fp );
return( m );
return( out );
}
/**
@ -575,7 +571,7 @@ im_read_imask( const char *filename )
/**
* im_scale_dmask:
* @m: mask to scale
* @in: mask to scale
* @filename: filename for returned mask
*
* Scale the dmask to make an imask with a maximum value of 100.
@ -585,34 +581,34 @@ im_read_imask( const char *filename )
* Returns: the converted mask, or NULL on error.
*/
INTMASK *
im_scale_dmask( DOUBLEMASK *m, const char *filename )
im_scale_dmask( DOUBLEMASK *in, const char *filename )
{
const int size = m->xsize * m->ysize;
const int size = in->xsize * in->ysize;
INTMASK *out;
double maxval, dsum;
int i;
int isum;
if( !filename || m->xsize <= 0 || m->ysize <= 0 ) {
if( !filename || in->xsize <= 0 || in->ysize <= 0 ) {
im_error( "im_scale_dmask", "%s", _( "bad arguments" ) );
return( NULL );
}
if( !(out = im_create_imask( filename, m->xsize, m->ysize )) )
if( !(out = im_create_imask( filename, in->xsize, in->ysize )) )
return( NULL );
/* Find mask max.
*/
maxval = m->coeff[0];
maxval = in->coeff[0];
for( i = 0; i < size; i++ )
if( m->coeff[i] > maxval )
maxval = m->coeff[i];
if( in->coeff[i] > maxval )
maxval = in->coeff[i];
/* Copy and scale, setting max to 100.
*/
for( i = 0; i < size; i++ )
out->coeff[i] = IM_RINT( m->coeff[i] * 100.0 / maxval );
out->offset = m->offset;
out->coeff[i] = IM_RINT( in->coeff[i] * 100.0 / maxval );
out->offset = in->offset;
/* Set the scale to match the adjustment to max.
*/
@ -620,15 +616,15 @@ im_scale_dmask( DOUBLEMASK *m, const char *filename )
dsum = 0.0;
for( i = 0; i < size; i++ ) {
isum += out->coeff[i];
dsum += m->coeff[i];
dsum += in->coeff[i];
}
if( dsum == m->scale )
if( dsum == in->scale )
out->scale = isum;
else if( dsum == 0.0 )
out->scale = 1.0;
else
out->scale = IM_RINT( m->scale * isum / dsum );
out->scale = IM_RINT( in->scale * isum / dsum );
return( out );
}
@ -664,7 +660,7 @@ im_norm_dmask( DOUBLEMASK *mask )
/**
* im_dup_imask:
* @m: mask to duplicate
* @in: mask to duplicate
* @filename: filename to set for the new mask
*
* Duplicate an imask.
@ -674,26 +670,26 @@ im_norm_dmask( DOUBLEMASK *mask )
* Returns: the mask copy, or NULL on error.
*/
INTMASK *
im_dup_imask( INTMASK *m, const char *filename )
im_dup_imask( INTMASK *in, const char *filename )
{
INTMASK *new;
INTMASK *out;
int i;
if( !(new = im_create_imask( filename, m->xsize, m->ysize )) )
if( !(out = im_create_imask( filename, in->xsize, in->ysize )) )
return( NULL );
new->offset = m->offset;
new->scale = m->scale;
out->offset = in->offset;
out->scale = in->scale;
for( i = 0; i < m->xsize * m->ysize; i++ )
new->coeff[i] = m->coeff[i];
for( i = 0; i < in->xsize * in->ysize; i++ )
out->coeff[i] = in->coeff[i];
return( new );
return( out );
}
/**
* im_dup_dmask:
* @m: mask to duplicate
* @in: mask to duplicate
* @filename: filename to set for the new mask
*
* Duplicate a dmask.
@ -703,21 +699,21 @@ im_dup_imask( INTMASK *m, const char *filename )
* Returns: the mask copy, or NULL on error.
*/
DOUBLEMASK *
im_dup_dmask( DOUBLEMASK *m, const char *filename )
im_dup_dmask( DOUBLEMASK *in, const char *filename )
{
DOUBLEMASK *new;
DOUBLEMASK *out;
int i;
if( !(new = im_create_dmask( filename, m->xsize, m->ysize )) )
if( !(out = im_create_dmask( filename, in->xsize, in->ysize )) )
return( NULL );
new->offset = m->offset;
new->scale = m->scale;
out->offset = in->offset;
out->scale = in->scale;
for( i = 0; i < m->xsize * m->ysize; i++ )
new->coeff[i] = m->coeff[i];
for( i = 0; i < in->xsize * in->ysize; i++ )
out->coeff[i] = in->coeff[i];
return( new );
return( out );
}
/* Open for write. We can't use im__open_write(), we don't want binary mode.
@ -765,7 +761,7 @@ write_double( FILE *fp, double d )
/**
* im_write_imask_name:
* @m: mask to write
* @in: mask to write
* @filename: filename to write to
*
* Write an imask to a file. See im_read_dmask() for a description of the mask
@ -776,7 +772,7 @@ write_double( FILE *fp, double d )
* Returns: 0 on success, or -1 on error.
*/
int
im_write_imask_name( INTMASK *m, const char *filename )
im_write_imask_name( INTMASK *in, const char *filename )
{
FILE *fp;
int x, y, i;
@ -784,17 +780,17 @@ im_write_imask_name( INTMASK *m, const char *filename )
if( !(fp = open_write( filename )) )
return( -1 );
if( write_line( fp, "%d %d", m->xsize, m->ysize ) ) {
if( write_line( fp, "%d %d", in->xsize, in->ysize ) ) {
fclose( fp );
return( -1 );
}
if( m->scale != 1 || m->offset != 0 )
write_line( fp, " %d %d", m->scale, m->offset );
if( in->scale != 1 || in->offset != 0 )
write_line( fp, " %d %d", in->scale, in->offset );
write_line( fp, "\n" );
for( i = 0, y = 0; y < m->ysize; y++ ) {
for( x = 0; x < m->xsize; x++, i++ )
write_line( fp, "%d ", m->coeff[i] );
for( i = 0, y = 0; y < in->ysize; y++ ) {
for( x = 0; x < in->xsize; x++, i++ )
write_line( fp, "%d ", in->coeff[i] );
if( write_line( fp, "\n" ) ) {
fclose( fp );
@ -808,7 +804,7 @@ im_write_imask_name( INTMASK *m, const char *filename )
/**
* im_write_imask:
* @m: mask to write
* @in: mask to write
*
* Write an imask to a file.
*
@ -817,19 +813,19 @@ im_write_imask_name( INTMASK *m, const char *filename )
* Returns: 0 on success, or -1 on error.
*/
int
im_write_imask( INTMASK *m )
im_write_imask( INTMASK *in )
{
if( !m->filename ) {
if( !in->filename ) {
im_error( "im_write_imask", "%s", _( "filename not set" ) );
return( -1 );
}
return( im_write_imask_name( m, m->filename ) );
return( im_write_imask_name( in, in->filename ) );
}
/**
* im_write_dmask_name:
* @m: mask to write
* @in: mask to write
* @filename: filename to write to
*
* Write a dmask to a file. See im_read_dmask() for a description of the mask
@ -840,7 +836,7 @@ im_write_imask( INTMASK *m )
* Returns: 0 on success, or -1 on error.
*/
int
im_write_dmask_name( DOUBLEMASK *m, const char *filename )
im_write_dmask_name( DOUBLEMASK *in, const char *filename )
{
FILE *fp;
int x, y, i;
@ -848,21 +844,21 @@ im_write_dmask_name( DOUBLEMASK *m, const char *filename )
if( !(fp = open_write( filename )) )
return( -1 );
if( write_line( fp, "%d %d", m->xsize, m->ysize ) ) {
if( write_line( fp, "%d %d", in->xsize, in->ysize ) ) {
fclose( fp );
return( -1 );
}
if( m->scale != 1.0 || m->offset != 0.0 ) {
if( in->scale != 1.0 || in->offset != 0.0 ) {
write_line( fp, " " );
write_double( fp, m->scale );
write_double( fp, in->scale );
write_line( fp, " " );
write_double( fp, m->offset );
write_double( fp, in->offset );
}
write_line( fp, "\n" );
for( i = 0, y = 0; y < m->ysize; y++ ) {
for( x = 0; x < m->xsize; x++, i++ )
write_double( fp, m->coeff[i] );
for( i = 0, y = 0; y < in->ysize; y++ ) {
for( x = 0; x < in->xsize; x++, i++ )
write_double( fp, in->coeff[i] );
write_line( fp, " " );
if( write_line( fp, "\n" ) ) {
@ -877,7 +873,7 @@ im_write_dmask_name( DOUBLEMASK *m, const char *filename )
/**
* im_write_dmask:
* @m: mask to write
* @in: mask to write
*
* Write a dmask to a file. See im_read_dmask() for a description of the mask
* file format.
@ -887,14 +883,14 @@ im_write_dmask_name( DOUBLEMASK *m, const char *filename )
* Returns: 0 on success, or -1 on error.
*/
int
im_write_dmask( DOUBLEMASK *m )
im_write_dmask( DOUBLEMASK *in )
{
if( !m->filename ) {
if( !in->filename ) {
im_error( "im_write_dmask", "%s", _( "filename not set" ) );
return( -1 );
}
return( im_write_dmask_name( m, m->filename ) );
return( im_write_dmask_name( in, in->filename ) );
}
/* Copy an imask into a matrix. Only used internally by matrix package for
@ -953,24 +949,23 @@ im_copy_matrix_dmask( double **matrix, DOUBLEMASK *mask )
/**
* im_print_imask:
* @m: mask to print
* @in: mask to print
*
* Print an imask to stdout.
*
* See also: im_print_dmask().
*/
void
im_print_imask( INTMASK *m )
im_print_imask( INTMASK *in )
{
int i, j, k;
int *pm = m->coeff;
printf( "%s: %d %d %d %d\n",
m->filename, m->xsize, m->ysize, m->scale, m->offset );
in->filename, in->xsize, in->ysize, in->scale, in->offset );
for( k = 0, j = 0; j < m->ysize; j++ ) {
for( i = 0; i < m->xsize; i++, k++ )
printf( "%d\t", pm[k] );
for( k = 0, j = 0; j < in->ysize; j++ ) {
for( i = 0; i < in->xsize; i++, k++ )
printf( "%d\t", in->coeff[k] );
printf( "\n" );
}
@ -978,24 +973,23 @@ im_print_imask( INTMASK *m )
/**
* im_print_dmask:
* @m: mask to print
* @in: mask to print
*
* Print a dmask to stdout.
*
* See also: im_print_imask().
*/
void
im_print_dmask( DOUBLEMASK *m )
im_print_dmask( DOUBLEMASK *in )
{
int i, j, k;
double *pm = m->coeff;
printf( "%s: %d %d %f %f\n",
m->filename, m->xsize, m->ysize, m->scale, m->offset );
in->filename, in->xsize, in->ysize, in->scale, in->offset );
for( k = 0, j = 0; j < m->ysize; j++ ) {
for( i = 0; i < m->xsize; i++, k++ )
printf( "%f\t", pm[k] );
for( k = 0, j = 0; j < in->ysize; j++ ) {
for( i = 0; i < in->xsize; i++, k++ )
printf( "%f\t", in->coeff[k] );
printf( "\n" );
}
@ -1011,7 +1005,7 @@ im_print_dmask( DOUBLEMASK *m )
*
* See also: im_local_imask().
*
* Returns: 0 on success, or -1 on error.
* Returns: the mask, or NULL on error.
*/
DOUBLEMASK *
im_local_dmask( VipsImage *out, DOUBLEMASK *mask )
@ -1038,7 +1032,7 @@ im_local_dmask( VipsImage *out, DOUBLEMASK *mask )
*
* See also: im_local_dmask().
*
* Returns: 0 on success, or -1 on error.
* Returns: the mask, or NULL on error.
*/
INTMASK *
im_local_imask( VipsImage *out, INTMASK *mask )