This commit is contained in:
John Cupitt 2007-10-20 01:00:06 +00:00
parent 335594183d
commit 57f24c63d6
36 changed files with 277 additions and 160 deletions

4
TODO
View File

@ -1,5 +1,9 @@
- test maxpos_avg, quite a few changes
- test maxpos_vec, quite a few changes
also, same problem as maxpos_avg re. uninit data?
Python binding
==============

View File

@ -89,16 +89,16 @@ static maxpos_list *maxpos_list_alloc( int n );
static void maxpos_list_free( maxpos_list *list );
static void maxpos_list_init( maxpos_list *list, int n );
static maxpos_list *maxpos_vec_start( void *unrequired, int *n );
static int maxpos_vec_scan( REGION *reg, maxpos_list *list );
static void *maxpos_vec_start( IMAGE *unrequired, void *, void * );
static int maxpos_vec_scan( REGION *reg, void *seq, void *, void * );
static void add_to_maxpos_list( maxpos_list *list, int x, int y, double val );
static int maxpos_vec_stop( maxpos_list *list, int *n, maxpos_list *master_list );
static int maxpos_vec_stop( void *seq, void *, void * );
static void minpos_list_init( maxpos_list *list, int n );
static maxpos_list *minpos_vec_start( void *unrequired, int *n );
static int minpos_vec_scan( REGION *reg, maxpos_list *list );
static void *minpos_vec_start( IMAGE *unrequired, void *, void * );
static int minpos_vec_scan( REGION *reg, void *seq, void *, void * );
static void add_to_minpos_list( maxpos_list *list, int x, int y, double val );
static int minpos_vec_stop( maxpos_list *list, int *n, maxpos_list *master_list );
static int minpos_vec_stop( void *seq, void *, void * );
/** EXPORTED FUNCTIONS **/
@ -140,7 +140,7 @@ int im_maxpos_vec( IMAGE *im, int *xpos, int *ypos, double *maxima, int n ){
maxpos_list_init( &master_list, n );
result= im_iterate( im, (void*)maxpos_vec_start, maxpos_vec_scan, maxpos_vec_stop, &n, &master_list );
result= im_iterate( im, maxpos_vec_start, maxpos_vec_scan, maxpos_vec_stop, &n, &master_list );
im_free( pointers );
@ -186,7 +186,7 @@ int im_minpos_vec( IMAGE *im, int *xpos, int *ypos, double *minima, int n ){
minpos_list_init( &master_list, n );
result= im_iterate( im, (void*)minpos_vec_start, minpos_vec_scan, minpos_vec_stop, &n, &master_list );
result= im_iterate( im, minpos_vec_start, minpos_vec_scan, minpos_vec_stop, &n, &master_list );
im_free( pointers );
@ -240,8 +240,9 @@ static void maxpos_list_init( maxpos_list *list, int n ){
list-> start= 0;
}
static maxpos_list *maxpos_vec_start( void *unrequired, int *n ){
static void *maxpos_vec_start( IMAGE *unrequired, void *a, void *b ){
int *n = (int *) a;
maxpos_list *list= maxpos_list_alloc( *n );
if( ! list )
@ -252,8 +253,10 @@ static maxpos_list *maxpos_vec_start( void *unrequired, int *n ){
return list;
}
static int maxpos_vec_scan( REGION *reg, maxpos_list *list ){
static int maxpos_vec_scan( REGION *reg, void *seq, void *a, void *b ){
maxpos_list *list = (maxpos_list *) seq;
#define MAXPOS_VEC_SCAN( type ){ \
\
int y= reg-> valid. top; \
@ -307,10 +310,13 @@ static void add_to_maxpos_list( maxpos_list *list, int x, int y, double val ){
}
}
static int maxpos_vec_stop( maxpos_list *list, int *n, maxpos_list *master_list ){
static int maxpos_vec_stop( void *seq, void *a, void *b ){
/* reverse list */
maxpos_list *list = (maxpos_list *) seq;
maxpos_list *master_list = (maxpos_list *) b;
int prev= -1;
int pointer= list-> start;
@ -356,8 +362,9 @@ static void minpos_list_init( maxpos_list *list, int n ){
list-> start= 0;
}
static maxpos_list *minpos_vec_start( void *unrequired, int *n ){
static void *minpos_vec_start( IMAGE *unrequired, void *a, void *b ){
int *n = (int *) a;
maxpos_list *list= maxpos_list_alloc( *n );
if( ! list )
@ -368,8 +375,10 @@ static maxpos_list *minpos_vec_start( void *unrequired, int *n ){
return list;
}
static int minpos_vec_scan( REGION *reg, maxpos_list *list ){
static int minpos_vec_scan( REGION *reg, void *seq, void *a, void *b ){
maxpos_list *list = (maxpos_list *) seq;
#define MINPOS_VEC_SCAN( type ){ \
\
int y= reg-> valid. top; \
@ -423,10 +432,12 @@ static void add_to_minpos_list( maxpos_list *list, int x, int y, double val ){
}
}
static int minpos_vec_stop( maxpos_list *list, int *n, maxpos_list *master_list ){
static int minpos_vec_stop( void *seq, void *a, void *b ){
/* reverse list */
maxpos_list *list = (maxpos_list *) seq;
maxpos_list *master_list = (maxpos_list *) b;
int prev= -1;
int pointer= list-> start;

View File

@ -97,21 +97,25 @@ typedef struct _Seq {
/* New sequence value.
*/
static void *
start_fn( MinInfo *inf )
start_fn( IMAGE *im, void *a, void *b )
{
MinInfo *inf = (MinInfo *) a;
Seq *seq = IM_NEW( NULL, Seq );
seq->inf = inf;
seq->valid = 0;
return( (void *) seq );
return( seq );
}
/* Merge the sequence value back into the per-call state.
*/
static int
stop_fn( Seq *seq, MinInfo *inf )
stop_fn( void *vseq, void *a, void *b )
{
Seq *seq = (Seq *) vseq;
MinInfo *inf = (MinInfo *) a;
if( seq->valid ) {
if( !inf->valid )
/* Just copy.
@ -133,8 +137,9 @@ stop_fn( Seq *seq, MinInfo *inf )
/* Loop over region, adding to seq.
*/
static int
scan_fn( REGION *reg, Seq *seq )
scan_fn( REGION *reg, void *vseq, void *a, void *b )
{
Seq *seq = (Seq *) vseq;
Rect *r = &reg->valid;
IMAGE *im = reg->im;
int le = r->left;

View File

@ -65,7 +65,7 @@
/* Make and initialise a DOUBLEMASK suitable for grabbing statistics.
*/
static void *
make_mask( IMAGE *im )
make_mask( IMAGE *im, void *a, void *b )
{
DOUBLEMASK *out;
@ -79,7 +79,7 @@ make_mask( IMAGE *im )
*/
out->offset = 42;
return( (void *) out );
return( out );
}
/* Merge a temp DOUBLEMASK into the real DOUBLEMASK. Row 0 is unused, row 1
@ -87,8 +87,10 @@ make_mask( IMAGE *im )
* offset of out if 42, then it has not been inited yet and we just copy.
*/
static int
merge_mask( DOUBLEMASK *tmp, DOUBLEMASK *out )
merge_mask( void *seq, void *a, void *b )
{
DOUBLEMASK *tmp = (DOUBLEMASK *) seq;
DOUBLEMASK *out = (DOUBLEMASK *) a;
double *rowi, *rowo;
int z;
@ -133,8 +135,9 @@ merge_mask( DOUBLEMASK *tmp, DOUBLEMASK *out )
* We set max, min, sum, sum of squares. Our caller fills in the rest.
*/
static int
scan_fn( REGION *reg, DOUBLEMASK *tmp )
scan_fn( REGION *reg, void *seq, void *a, void *b )
{
DOUBLEMASK *tmp = (DOUBLEMASK *) seq;
Rect *r = &reg->valid;
IMAGE *im = reg->im;
int bands = im->Bands;
@ -243,7 +246,7 @@ im_stats( IMAGE *in )
*/
pels = (gint64) in->Xsize * in->Ysize;
vals = pels * in->Bands;
if( !(out = make_mask( in )) )
if( !(out = make_mask( in, NULL, NULL )) )
return( NULL );
/* Loop over input, calculating min, max, sum, sum^2 for each band

View File

@ -66,15 +66,16 @@
/* Bandjoin generate function.
*/
static int
bandjoin_gen( REGION *or, REGION **ir )
{
bandjoin_gen( REGION *or, void *seq, void *a, void *b )
{
REGION **ir = (REGION **) seq;
Rect *r = &or->valid;
int le = r->left;
int ri = IM_RECT_RIGHT(r);
int to = r->top;
int bo = IM_RECT_BOTTOM(r);
int x, y, z;
int i1s = IM_IMAGE_SIZEOF_PEL( ir[0]->im ); /* sizeof LHS, RHS pels */
int i1s = IM_IMAGE_SIZEOF_PEL( ir[0]->im );
int i2s = IM_IMAGE_SIZEOF_PEL( ir[1]->im );
/* Ask for input we need.

View File

@ -66,7 +66,7 @@
/* Generate function --- just black out the region.
*/
static int
black_gen( REGION *or )
black_gen( REGION *or, void *seq, void *a, void *b )
{
int y;
int sz = IM_REGION_SIZEOF_LINE( or );

View File

@ -146,8 +146,11 @@ typedef struct {
/* Destroy a sequence value.
*/
static int
stop_clip( ClipSequence *seq, IMAGE *in, Clip *clip )
clip_stop( void *vseq, void *a, void *b )
{
ClipSequence *seq = (ClipSequence *) vseq;
Clip *clip = (Clip *) b;
/* Add to global stats.
*/
clip->underflow += seq->underflow;
@ -166,11 +169,12 @@ stop_clip( ClipSequence *seq, IMAGE *in, Clip *clip )
/* Make a sequence value.
*/
static void *
start_clip( IMAGE *out, IMAGE *in, Clip *clip )
clip_start( IMAGE *out, void *a, void *b )
{
ClipSequence *seq = IM_NEW( out, ClipSequence );
IMAGE *in = (IMAGE *) a;
ClipSequence *seq;
if( !seq )
if( !(seq = IM_NEW( out, ClipSequence )) )
return( NULL );
/* Init!
@ -182,7 +186,7 @@ start_clip( IMAGE *out, IMAGE *in, Clip *clip )
if( !(seq->ir = im_region_create( in )) )
return( NULL );
return( (void *) seq );
return( seq );
}
/* Clip int types to an int type.
@ -306,8 +310,10 @@ start_clip( IMAGE *out, IMAGE *in, Clip *clip )
/* Clip a small area.
*/
static int
clip_gen( REGION *or, ClipSequence *seq, IMAGE *in, Clip *clip )
{
clip_gen( REGION *or, void *vseq, void *a, void *b )
{
ClipSequence *seq = (ClipSequence *) vseq;
Clip *clip = (Clip *) b;
REGION *ir = seq->ir;
Rect *r = &or->valid;
int le = r->left;
@ -415,7 +421,7 @@ im_clip2fmt( IMAGE *in, IMAGE *out, int ofmt )
out->Bbits = im_bits_of_fmt( ofmt );
if( im_demand_hint( out, IM_THINSTRIP, in, NULL ) ||
im_generate( out, start_clip, clip_gen, stop_clip, in, clip ) )
im_generate( out, clip_start, clip_gen, clip_stop, in, clip ) )
return( -1 );
return( 0 );

View File

@ -98,8 +98,9 @@
/* Copy a small area.
*/
static int
copy_gen( REGION *or, REGION *ir )
{
copy_gen( REGION *or, void *seq, void *a, void *b )
{
REGION *ir = (REGION *) seq;
Rect *r = &or->valid;
/* Ask for input we need.

View File

@ -224,8 +224,10 @@ im_exr2vips_header( const char *name, IMAGE *out )
}
static int
fill_region( REGION *out, ImfRgba *imf_buffer, Read *read )
fill_region( REGION *out, void *seq, void *a, void *b )
{
ImfRgba *imf_buffer = (ImfRgba *) seq;
Read *read = (Read *) a;
Rect *r = &out->valid;
const int tw = read->tile_width;
@ -308,15 +310,16 @@ fill_region( REGION *out, ImfRgba *imf_buffer, Read *read )
/* Allocate a tile buffer.
*/
static void *
seq_start( IMAGE *out, Read *read )
seq_start( IMAGE *out, void *a, void *b )
{
Read *read = (Read *) a;
ImfRgba *imf_buffer;
if( !(imf_buffer = IM_ARRAY( out,
read->tile_width * read->tile_height, ImfRgba )) )
return( NULL );
return( (void *) imf_buffer );
return( imf_buffer );
}
/* Read tilewise.

View File

@ -84,9 +84,10 @@
* or->im->Bands.
*/
static int
extract_band( REGION *or, REGION *ir, IMAGE *in, IMAGE_BOX *box )
extract_band( REGION *or, void *seq, void *a, void *b )
{
Rect iarea;
REGION *ir = (REGION *) seq;
IMAGE_BOX *box = (IMAGE_BOX *) b;
Rect *r = &or->valid;
int le = r->left;
int ri = IM_RECT_RIGHT(r);
@ -95,6 +96,7 @@ extract_band( REGION *or, REGION *ir, IMAGE *in, IMAGE_BOX *box )
int es = IM_IMAGE_SIZEOF_ELEMENT( ir->im );
int ipel = IM_IMAGE_SIZEOF_PEL( ir->im );
int opel = IM_IMAGE_SIZEOF_PEL( or->im );
Rect iarea;
char *p, *q;
int x, y, z;
@ -126,8 +128,10 @@ extract_band( REGION *or, REGION *ir, IMAGE *in, IMAGE_BOX *box )
/* Extract an area. Can just use pointers.
*/
static int
extract_area( REGION *or, REGION *ir, IMAGE *in, IMAGE_BOX *box )
extract_area( REGION *or, void *seq, void *a, void *b )
{
REGION *ir = (REGION *) seq;
IMAGE_BOX *box = (IMAGE_BOX *) b;
Rect iarea;
/* Ask for input we need. Translate from demand in or's space to

View File

@ -60,8 +60,9 @@
/* Flip a small area.
*/
static int
flip_gen( REGION *or, REGION *ir )
{
flip_gen( REGION *or, void *seq, void *a, void *b )
{
REGION *ir = (REGION *) seq;
Rect *r = &or->valid;
Rect in;
char *p, *q;
@ -124,7 +125,7 @@ im_fliphor( IMAGE *in, IMAGE *out )
if( im_piocheck( in, out ) )
return( -1 );
if( in->Coding != IM_CODING_NONE && in->Coding != IM_CODING_LABQ ) {
im_errormsg( "im_fliphor: in must be uncoded" );
im_error( "im_fliphor", _( "in must be uncoded" ) );
return( -1 );
}

View File

@ -63,8 +63,9 @@
/* Flip a small area.
*/
static int
flip_gen( REGION *or, REGION *ir )
flip_gen( REGION *or, void *seq, void *a, void *b )
{
REGION *ir = (REGION *) seq;
Rect *r = &or->valid;
Rect in;
PEL *p, *q;

View File

@ -105,8 +105,10 @@ make_join( IMAGE *out, IMAGE **in, int nim )
/* Perform join.
*/
static int
join_bands( REGION *or, REGION **ir, IMAGE **in, Join *jn )
join_bands( REGION *or, void *seq, void *a, void *b )
{
REGION **ir = (REGION **) seq;
Join *jn = (Join *) b;
int x, y, z, i;
Rect *r = &or->valid;
int le = r->left;

View File

@ -63,8 +63,10 @@ typedef struct _Grid {
} Grid;
static int
grid_gen( REGION *or, REGION *ir, IMAGE *in, Grid *grid )
grid_gen( REGION *or, void *seq, void *a, void *b )
{
REGION *ir = (REGION *) seq;
Grid *grid = (Grid *) b;
Rect *r = &or->valid;
int twidth = grid->in->Xsize;
int theight = grid->tile_height;

View File

@ -166,8 +166,10 @@ paste_region( REGION *or, REGION *ir, Rect *pos )
/* Insert generate function.
*/
static int
insert_gen( REGION *or, REGION **ir, IMAGE **vec, InsertState *ins )
insert_gen( REGION *or, void *seq, void *a, void *b )
{
REGION **ir = (REGION **) seq;
InsertState *ins = (InsertState *) b;
Rect ovl;
/* Does the rect we have been asked for fall entirely inside the

View File

@ -534,8 +534,9 @@ get_pixels( Image *image, int left, int top, int width, int height )
}
static int
magick_fill_region( REGION *out, void *dummy, Read *read )
magick_fill_region( REGION *out, void *seq, void *a, void *b )
{
Read *read = (Read *) b;
Rect *r = &out->valid;
int y;

View File

@ -55,8 +55,10 @@
#endif /*WITH_DMALLOC*/
static int
replicate_gen( REGION *or, REGION *ir, IMAGE *in )
replicate_gen( REGION *or, void *seq, void *a, void *b )
{
REGION *ir = (REGION *) seq;
IMAGE *in = (IMAGE *) a;
Rect *r = &or->valid;
int twidth = in->Xsize;
int theight = in->Ysize;

View File

@ -75,7 +75,7 @@
/* function prototype macro */
#define GEN_FUNC( SHIFT_MACRO, FROM_T, TO_T, SUM_T ) \
static int gen_ ## SHIFT_MACRO ## _ ## FROM_T ## _to_ ## TO_T ## _with_ ## SUM_T( \
REGION *to_make, REGION *make_from, void *unrequired, int *params );
REGION *to_make, void *seq, void *a, void *b );
/* macros to call function prototype macro for all possible combinations of types and macros */
#define GEN_FUNCS_TO( SIGN, FROM_T, TO_T ) \
@ -240,8 +240,10 @@ im_rightshift_size( IMAGE *in, IMAGE *out, int xshift, int yshift, int band_fmt
#undef GEN_FUNC
#define GEN_FUNC( SHIFT_MACRO, FROM_T, TO_T, SUM_T ) \
static int gen_ ## SHIFT_MACRO ## _ ## FROM_T ## _to_ ## TO_T ## _with_ ## SUM_T( \
REGION *to_make, REGION *make_from, void *unrequired, int *params ){ \
REGION *to_make, void *seq, void *a, void *b ){ \
\
REGION *make_from = (REGION *) seq; \
int *params = (int *) b; \
int xshift= params[0]; \
int yshift= params[1]; \
int preshift= params[2]; \

View File

@ -69,8 +69,11 @@
/* Rotate a small piece.
*/
static int
rot180_gen( REGION *or, REGION *ir, IMAGE *in )
rot180_gen( REGION *or, void *seq, void *a, void *b )
{
REGION *ir = (REGION *) seq;
IMAGE *in = (IMAGE *) a;
/* Output area.
*/
Rect *r = &or->valid;

View File

@ -70,8 +70,11 @@
/* Rotate a small piece.
*/
static int
rot270_gen( REGION *or, REGION *ir, IMAGE *in )
rot270_gen( REGION *or, void *seq, void *a, void *b )
{
REGION *ir = (REGION *) seq;
IMAGE *in = (IMAGE *) a;
/* Output area.
*/
Rect *r = &or->valid;

View File

@ -70,8 +70,11 @@
/* Rotate a small piece.
*/
static int
rot90_gen( REGION *or, REGION *ir, IMAGE *in )
rot90_gen( REGION *or, void *seq, void *a, void *b )
{
REGION *ir = (REGION *) seq;
IMAGE *in = (IMAGE *) a;
/* Output area.
*/
Rect *r = &or->valid;

View File

@ -70,8 +70,11 @@ typedef struct {
* across the input.
*/
static int
line_shrink_gen( REGION *or, REGION *ir, IMAGE *in, SubsampleInfo *st )
line_shrink_gen( REGION *or, void *seq, void *a, void *b )
{
REGION *ir = (REGION *) seq;
IMAGE *in = (IMAGE *) a;
SubsampleInfo *st = (SubsampleInfo *) b;
Rect *r = &or->valid;
int le = r->left;
@ -85,7 +88,7 @@ line_shrink_gen( REGION *or, REGION *ir, IMAGE *in, SubsampleInfo *st )
Rect s;
int x, y;
int z, b;
int z, k;
/* Loop down the region.
*/
@ -118,8 +121,8 @@ line_shrink_gen( REGION *or, REGION *ir, IMAGE *in, SubsampleInfo *st )
*/
p = IM_REGION_ADDR( ir, s.left, s.top );
for( z = 0; z < ow; z++ ) {
for( b = 0; b < ps; b++ )
q[b] = p[b];
for( k = 0; k < ps; k++ )
q[k] = p[k];
q += ps;
p += ps * st->xshrink;
@ -134,8 +137,11 @@ line_shrink_gen( REGION *or, REGION *ir, IMAGE *in, SubsampleInfo *st )
* pipes.
*/
static int
point_shrink_gen( REGION *or, REGION *ir, IMAGE *in, SubsampleInfo *st )
point_shrink_gen( REGION *or, void *seq, void *a, void *b )
{
REGION *ir = (REGION *) seq;
IMAGE *in = (IMAGE *) a;
SubsampleInfo *st = (SubsampleInfo *) b;
Rect *r = &or->valid;
int le = r->left;
@ -147,7 +153,7 @@ point_shrink_gen( REGION *or, REGION *ir, IMAGE *in, SubsampleInfo *st )
Rect s;
int x, y;
int b;
int k;
/* Loop down the region.
*/
@ -170,8 +176,8 @@ point_shrink_gen( REGION *or, REGION *ir, IMAGE *in, SubsampleInfo *st )
/* Append new pels to output.
*/
p = IM_REGION_ADDR( ir, s.left, s.top );
for( b = 0; b < ps; b++ )
q[b] = p[b];
for( k = 0; k < ps; k++ )
q[k] = p[k];
q += ps;
}
}

View File

@ -1153,8 +1153,9 @@ parse_header( ReadTiff *rtiff, IMAGE *out )
* to vips in parallel.
*/
static void *
seq_start( IMAGE *out, ReadTiff *rtiff )
seq_start( IMAGE *out, void *a, void *b )
{
ReadTiff *rtiff = (ReadTiff *) a;
tdata_t *buf;
if( !(buf = im_malloc( NULL, TIFFTileSize( rtiff->tiff ) )) )
@ -1166,8 +1167,10 @@ seq_start( IMAGE *out, ReadTiff *rtiff )
/* Loop over the output region, painting in tiles from the file.
*/
static int
fill_region( REGION *out, tdata_t *buf, ReadTiff *rtiff )
fill_region( REGION *out, void *seq, void *a, void *b )
{
tdata_t *buf = (tdata_t *) seq;
ReadTiff *rtiff = (ReadTiff *) a;
Rect *r = &out->valid;
/* Find top left of tiles we need.
@ -1232,6 +1235,14 @@ fill_region( REGION *out, tdata_t *buf, ReadTiff *rtiff )
return( 0 );
}
static int
seq_stop( void *seq, void *a, void *b )
{
im_free( seq );
return( 0 );
}
/* Tile-type TIFF reader core - pass in a per-tile transform. Generate into
* the im and do it all partially.
*/
@ -1267,7 +1278,7 @@ read_tilewise( ReadTiff *rtiff, IMAGE *out )
*/
if( im_demand_hint( raw, IM_SMALLTILE, NULL ) ||
im_generate( raw,
seq_start, fill_region, im_free, rtiff, NULL ) )
seq_start, fill_region, seq_stop, rtiff, NULL ) )
return( -1 );
/* Copy to out, adding a cache. Enough tiles for two complete rows.

View File

@ -317,8 +317,9 @@ copy_region( REGION *from, REGION *to, Rect *area )
/* Loop over the output region, filling with data from cache.
*/
static int
fill_region( REGION *out, void *seq, Read *read )
fill_region( REGION *out, void *seq, void *a, void *b )
{
Read *read = (Read *) a;
const int tw = read->tile_width;
const int th = read->tile_height;
Rect *r = &out->valid;

View File

@ -244,8 +244,11 @@ paint_part( REGION *or, REGION *ir, const ZoomInfo *zm,
/* Zoom a REGION.
*/
static int
zoom_gen( REGION *or, REGION *ir, IMAGE *in, ZoomInfo *zm )
zoom_gen( REGION *or, void *seq, void *a, void *b )
{
REGION *ir = (REGION *) seq;
ZoomInfo *zm = (ZoomInfo *) b;
/* Output area we are building.
*/
const Rect *r = &or->valid;

View File

@ -103,8 +103,8 @@ int
im_contrast_surface_raw (IMAGE * in, IMAGE * out, int half_win_size,
int spacing);
static int cont_surf_gen (REGION * to_make, REGION * make_from,
void *unrequired, cont_surf_params_t * params);
static int cont_surf_gen (REGION * to_make, void *seq,
void *a, void * b);
static unsigned int calc_cont (REGION * reg, int win_size_less_one,
int x_left, int y_top);
@ -192,11 +192,13 @@ im_contrast_surface_raw (IMAGE * in, IMAGE * out, int half_win_size,
/** LOCAL FUNCTIONS DEFINITIONS **/
static int
cont_surf_gen (REGION * to_make, REGION * make_from, void *unrequired,
cont_surf_params_t * params)
cont_surf_gen (REGION * to_make, void * seq, void *unrequired, void * b)
{
/* I don't need *in, but I will recieve it anyway since im_start_one() needs it */
REGION * make_from = (REGION *) seq;
cont_surf_params_t * params = (cont_surf_params_t *) b;
unsigned int *row =
(unsigned int *) IM_REGION_ADDR (to_make, to_make->valid.left,
to_make->valid.top);

View File

@ -184,19 +184,17 @@ typedef struct {
/* Free a sequence value.
*/
static int
stop_conv( ConvSequence *seq, IMAGE *in, Conv *conv )
conv_stop( void *vseq, void *a, void *b )
{
ConvSequence *seq = (ConvSequence *) vseq;
Conv *conv = (Conv *) b;
/* Add local under/over counts to global counts.
*/
conv->overflow += seq->overflow;
conv->underflow += seq->underflow;
/* Free attached objects.
*/
if( seq->ir ) {
im_region_free( seq->ir );
seq->ir = NULL;
}
IM_FREEF( im_region_free, seq->ir );
return( 0 );
}
@ -204,11 +202,13 @@ stop_conv( ConvSequence *seq, IMAGE *in, Conv *conv )
/* Convolution start function.
*/
static void *
start_conv( IMAGE *out, IMAGE *in, Conv *conv )
conv_start( IMAGE *out, void *a, void *b )
{
ConvSequence *seq = IM_NEW( out, ConvSequence );
IMAGE *in = (IMAGE *) a;
Conv *conv = (Conv *) b;
ConvSequence *seq;
if( !seq )
if( !(seq = IM_NEW( out, ConvSequence )) )
return( NULL );
/* Init!
@ -225,11 +225,11 @@ start_conv( IMAGE *out, IMAGE *in, Conv *conv )
seq->offsets = IM_ARRAY( out, conv->nnz, int );
seq->pts = IM_ARRAY( out, conv->nnz, PEL * );
if( !seq->ir || !seq->offsets || !seq->pts ) {
stop_conv( seq, in, conv );
conv_stop( seq, in, conv );
return( NULL );
}
return( (void *) seq );
return( seq );
}
#define INNER sum += *t++ * (*p++)[x]
@ -275,8 +275,11 @@ start_conv( IMAGE *out, IMAGE *in, Conv *conv )
/* Convolve!
*/
static int
gen_conv( REGION *or, ConvSequence *seq, IMAGE *in, Conv *conv )
conv_gen( REGION *or, void *vseq, void *a, void *b )
{
ConvSequence *seq = (ConvSequence *) vseq;
IMAGE *in = (IMAGE *) a;
Conv *conv = (Conv *) b;
REGION *ir = seq->ir;
INTMASK *mask = conv->mask;
int rounding = (mask->scale + 1)/2;
@ -397,7 +400,7 @@ im_conv_raw( IMAGE *in, IMAGE *out, INTMASK *mask )
if( im_demand_hint( out, IM_FATSTRIP, in, NULL ) )
return( -1 );
if( im_generate( out, start_conv, gen_conv, stop_conv, in, conv ) )
if( im_generate( out, conv_start, conv_gen, conv_stop, in, conv ) )
return( -1 );
out->Xoffset = -mask->xsize / 2;

View File

@ -146,14 +146,11 @@ typedef struct {
/* Free a sequence value.
*/
static int
stop_conv( ConvSequence *seq, IMAGE *in, Conv *conv )
conv_stop( void *vseq, void *a, void *b )
{
/* Free attached objects.
*/
if( seq->ir ) {
im_region_free( seq->ir );
seq->ir = NULL;
}
ConvSequence *seq = (ConvSequence *) vseq;
IM_FREEF( im_region_free, seq->ir );
return( 0 );
}
@ -161,11 +158,13 @@ stop_conv( ConvSequence *seq, IMAGE *in, Conv *conv )
/* Convolution start function.
*/
static void *
start_conv( IMAGE *out, IMAGE *in, Conv *conv )
conv_start( IMAGE *out, void *a, void *b )
{
ConvSequence *seq = IM_NEW( out, ConvSequence );
IMAGE *in = (IMAGE *) a;
Conv *conv = (Conv *) b;
ConvSequence *seq;
if( !seq )
if( !(seq = IM_NEW( out, ConvSequence )) )
return( NULL );
/* Init!
@ -180,7 +179,7 @@ start_conv( IMAGE *out, IMAGE *in, Conv *conv )
seq->offsets = IM_ARRAY( out, conv->nnz, int );
seq->pts = IM_ARRAY( out, conv->nnz, PEL * );
if( !seq->ir || !seq->offsets || !seq->pts ) {
stop_conv( seq, in, conv );
conv_stop( seq, in, conv );
return( NULL );
}
@ -209,8 +208,11 @@ start_conv( IMAGE *out, IMAGE *in, Conv *conv )
/* Convolve!
*/
static int
gen_conv( REGION *or, ConvSequence *seq, IMAGE *in, Conv *conv )
conv_gen( REGION *or, void *vseq, void *a, void *b )
{
ConvSequence *seq = (ConvSequence *) vseq;
IMAGE *in = (IMAGE *) a;
Conv *conv = (Conv *) b;
REGION *ir = seq->ir;
DOUBLEMASK *mask = conv->mask;
@ -319,7 +321,7 @@ im_convf_raw( IMAGE *in, IMAGE *out, DOUBLEMASK *mask )
if( im_demand_hint( out, IM_FATSTRIP, in, NULL ) )
return( -1 );
if( im_generate( out, start_conv, gen_conv, stop_conv, in, conv ) )
if( im_generate( out, conv_start, conv_gen, conv_stop, in, conv ) )
return( -1 );
out->Xoffset = -mask->xsize / 2;

View File

@ -143,8 +143,11 @@ typedef struct {
/* Free a sequence value.
*/
static int
stop_conv( ConvSequence *seq, IMAGE *in, Conv *conv )
conv_stop( void *vseq, void *a, void *b )
{
ConvSequence *seq = (ConvSequence *) vseq;
Conv *conv = (Conv *) b;
/* Add local under/over counts to global counts.
*/
conv->overflow += seq->overflow;
@ -158,11 +161,13 @@ stop_conv( ConvSequence *seq, IMAGE *in, Conv *conv )
/* Convolution start function.
*/
static void *
start_conv( IMAGE *out, IMAGE *in, Conv *conv )
conv_start( IMAGE *out, void *a, void *b )
{
ConvSequence *seq = IM_NEW( out, ConvSequence );
IMAGE *in = (IMAGE *) a;
Conv *conv = (Conv *) b;
ConvSequence *seq;
if( !seq )
if( !(seq = IM_NEW( out, ConvSequence )) )
return( NULL );
/* Init!
@ -183,7 +188,7 @@ start_conv( IMAGE *out, IMAGE *in, Conv *conv )
seq->sum = (PEL *)
IM_ARRAY( out, IM_IMAGE_N_ELEMENTS( in ), double );
if( !seq->ir || !seq->sum ) {
stop_conv( seq, in, conv );
conv_stop( seq, in, conv );
return( NULL );
}
@ -292,8 +297,11 @@ start_conv( IMAGE *out, IMAGE *in, Conv *conv )
/* Convolve!
*/
static int
gen_conv( REGION *or, ConvSequence *seq, IMAGE *in, Conv *conv )
conv_gen( REGION *or, void *vseq, void *a, void *b )
{
ConvSequence *seq = (ConvSequence *) vseq;
IMAGE *in = (IMAGE *) a;
Conv *conv = (Conv *) b;
REGION *ir = seq->ir;
INTMASK *mask = conv->mask;
int rounding = (mask->scale + 1)/2;
@ -398,7 +406,7 @@ im_convsep_raw( IMAGE *in, IMAGE *out, INTMASK *mask )
/* SMALLTILE seems the fastest in benchmarks.
*/
if( im_demand_hint( out, IM_SMALLTILE, in, NULL ) ||
im_generate( out, start_conv, gen_conv, stop_conv, in, conv ) )
im_generate( out, conv_start, conv_gen, conv_stop, in, conv ) )
return( -1 );
out->Xoffset = -mask->xsize / 2;

View File

@ -123,8 +123,10 @@ typedef struct {
/* Free a sequence value.
*/
static int
stop_conv( ConvSequence *seq, IMAGE *in, Conv *conv )
conv_stop( void *vseq, void *a, void *b )
{
ConvSequence *seq = (ConvSequence *) vseq;
IM_FREEF( im_region_free, seq->ir );
return( 0 );
@ -133,11 +135,13 @@ stop_conv( ConvSequence *seq, IMAGE *in, Conv *conv )
/* Convolution start function.
*/
static void *
start_conv( IMAGE *out, IMAGE *in, Conv *conv )
conv_start( IMAGE *out, void *a, void *b )
{
ConvSequence *seq = IM_NEW( out, ConvSequence );
IMAGE *in = (IMAGE *) a;
Conv *conv = (Conv *) b;
ConvSequence *seq;
if( !seq )
if( !(seq = IM_NEW( out, ConvSequence )) )
return( NULL );
/* Init!
@ -156,7 +160,7 @@ start_conv( IMAGE *out, IMAGE *in, Conv *conv )
seq->sum = (PEL *)
IM_ARRAY( out, IM_IMAGE_N_ELEMENTS( in ), double );
if( !seq->ir || !seq->sum ) {
stop_conv( seq, in, conv );
conv_stop( seq, in, conv );
return( NULL );
}
@ -215,8 +219,11 @@ start_conv( IMAGE *out, IMAGE *in, Conv *conv )
/* Convolve!
*/
static int
gen_conv( REGION *or, ConvSequence *seq, IMAGE *in, Conv *conv )
conv_gen( REGION *or, void *vseq, void *a, void *b )
{
ConvSequence *seq = (ConvSequence *) vseq;
IMAGE *in = (IMAGE *) a;
Conv *conv = (Conv *) b;
REGION *ir = seq->ir;
DOUBLEMASK *mask = conv->mask;
double *coeff = conv->mask->coeff;
@ -316,7 +323,7 @@ im_convsepf_raw( IMAGE *in, IMAGE *out, DOUBLEMASK *mask )
/* SMALLTILE seems fastest.
*/
if( im_demand_hint( out, IM_SMALLTILE, in, NULL ) ||
im_generate( out, start_conv, gen_conv, stop_conv, in, conv ) )
im_generate( out, conv_start, conv_gen, conv_stop, in, conv ) )
return( -1 );
out->Xoffset = -conv->size / 2;

View File

@ -219,8 +219,10 @@ embed_paint_edge( Embed *embed, REGION *or, int i, Rect *r, PEL *p, int plsk )
}
static int
embed_gen( REGION *or, REGION *ir, IMAGE *in, Embed *embed )
embed_gen( REGION *or, void *seq, void *a, void *b )
{
REGION *ir = (REGION *) seq;
Embed *embed = (Embed *) b;
Rect *r = &or->valid;
Rect ovl;

View File

@ -79,8 +79,10 @@
/* Fastcor generate function.
*/
static int
fastcor_gen( REGION *or, REGION *ir, IMAGE *in, IMAGE *ref )
fastcor_gen( REGION *or, void *seq, void *a, void *b )
{
REGION *ir = (REGION *) seq;
IMAGE *ref = (IMAGE *) b;
Rect irect;
Rect *r = &or->valid;
int le = r->left;

View File

@ -80,8 +80,9 @@ typedef struct {
*/
/*ARGSUSED*/
static int
gnoise_gen( REGION *or, void *dummy, GnoiseInfo *gin )
gnoise_gen( REGION *or, void *seq, void *a, void *b )
{
GnoiseInfo *gin = (GnoiseInfo *) a;
int x, y, i;
int sz = IM_REGION_N_ELEMENTS( or );

View File

@ -92,14 +92,11 @@ typedef struct {
/* Free a sequence value.
*/
static int
stop_rank( SeqInfo *seq, IMAGE *in, RankInfo *rnk )
rank_stop( void *vseq, void *a, void *b )
{
/* Free attached objects.
*/
if( seq->ir ) {
im_region_free( seq->ir );
seq->ir = NULL;
}
SeqInfo *seq = (SeqInfo *) vseq;
IM_FREEF( im_region_free, seq->ir );
return( 0 );
}
@ -107,11 +104,13 @@ stop_rank( SeqInfo *seq, IMAGE *in, RankInfo *rnk )
/* Rank start function.
*/
static void *
start_rank( IMAGE *out, IMAGE *in, RankInfo *rnk )
rank_start( IMAGE *out, void *a, void *b )
{
SeqInfo *seq = IM_NEW( out, SeqInfo );
IMAGE *in = (IMAGE *) a;
RankInfo *rnk = (RankInfo *) b;
SeqInfo *seq;
if( !seq )
if( !(seq = IM_NEW( out, SeqInfo )) )
return( NULL );
/* Init!
@ -125,7 +124,7 @@ start_rank( IMAGE *out, IMAGE *in, RankInfo *rnk )
seq->sort = IM_ARRAY( out,
IM_IMAGE_SIZEOF_ELEMENT( in ) * rnk->n, PEL );
if( !seq->ir || !seq->sort ) {
stop_rank( seq, in, rnk );
rank_stop( seq, in, rnk );
return( NULL );
}
@ -302,8 +301,11 @@ start_rank( IMAGE *out, IMAGE *in, RankInfo *rnk )
/* Rank of a REGION.
*/
static int
gen_rank( REGION *or, SeqInfo *seq, IMAGE *in, RankInfo *rnk )
rank_gen( REGION *or, void *vseq, void *a, void *b )
{
SeqInfo *seq = (SeqInfo *) vseq;
IMAGE *in = (IMAGE *) a;
RankInfo *rnk = (RankInfo *) b;
REGION *ir = seq->ir;
Rect *r = &or->valid;
@ -394,7 +396,7 @@ im_rank_raw( IMAGE *in, IMAGE *out, int xsize, int ysize, int order )
/* Generate!
*/
if( im_generate( out, start_rank, gen_rank, stop_rank, in, rnk ) )
if( im_generate( out, rank_start, rank_gen, rank_stop, in, rnk ) )
return( -1 );
out->Xoffset = -xsize / 2;

View File

@ -97,15 +97,14 @@ typedef struct {
/* Free a sequence value.
*/
static int
stop_rank( RankSequence *seq, IMAGE **in, Rank *rank )
rank_stop( void *vseq, void *a, void *b )
{
RankSequence *seq = (RankSequence *) vseq;
Rank *rank = (Rank *) b;
int i;
for( i = 0; i < rank->n; i++ )
if( seq->ir[i] ) {
im_region_free( seq->ir[i] );
seq->ir[i] = NULL;
}
IM_FREEF( im_region_free, seq->ir[i] );
return( 0 );
}
@ -113,8 +112,10 @@ stop_rank( RankSequence *seq, IMAGE **in, Rank *rank )
/* Make a sequence value.
*/
static void *
start_rank( IMAGE *out, IMAGE **in, Rank *rank )
rank_start( IMAGE *out, void *a, void *b )
{
IMAGE **in = (IMAGE **) a;
Rank *rank = (Rank *) b;
RankSequence *seq;
int i;
@ -134,13 +135,13 @@ start_rank( IMAGE *out, IMAGE **in, Rank *rank )
seq->sort = IM_ARRAY( out,
rank->n * IM_IMAGE_SIZEOF_ELEMENT( in[0] ), PEL );
if( !seq->ir || !seq->pts || !seq->sort ) {
stop_rank( seq, in, rank );
rank_stop( seq, in, rank );
return( NULL );
}
for( i = 0; i < rank->n; i++ )
if( !(seq->ir[i] = im_region_create( in[i] )) ) {
stop_rank( seq, in, rank );
rank_stop( seq, in, rank );
return( NULL );
}
seq->ir[i] = NULL;
@ -225,8 +226,10 @@ start_rank( IMAGE *out, IMAGE **in, Rank *rank )
}
static int
find_rank( REGION *or, RankSequence *seq, IMAGE **in, Rank *rank )
rank_gen( REGION *or, void *vseq, void *a, void *b )
{
RankSequence *seq = (RankSequence *) vseq;
Rank *rank = (Rank *) b;
Rect *r = &or->valid;
int le = r->left;
int to = r->top;
@ -314,7 +317,7 @@ im_rank_image( IMAGE **in, IMAGE *out, int n, int index )
im_cp_desc_array( out, rank->in ) ||
im_demand_hint_array( out, IM_THINSTRIP, rank->in ) ||
im_generate( out,
start_rank, find_rank, stop_rank, rank->in, rank ) )
rank_start, rank_gen, rank_stop, rank->in, rank ) )
return( -1 );
return( 0 );

View File

@ -96,12 +96,11 @@ typedef struct {
/* Free a sequence value.
*/
static int
shrink_stop( SeqInfo *seq, IMAGE *in, ShrinkInfo *st )
shrink_stop( void *vseq, void *a, void *b )
{
if( seq->ir ) {
im_region_free( seq->ir );
seq->ir = NULL;
}
SeqInfo *seq = (SeqInfo *) vseq;
IM_FREEF( im_region_free, seq->ir );
return( 0 );
}
@ -109,11 +108,13 @@ shrink_stop( SeqInfo *seq, IMAGE *in, ShrinkInfo *st )
/* Make a sequence value.
*/
static void *
shrink_start( IMAGE *out, IMAGE *in, ShrinkInfo *st )
shrink_start( IMAGE *out, void *a, void *b )
{
SeqInfo *seq = IM_NEW( out, SeqInfo );
IMAGE *in = (IMAGE *) a;
ShrinkInfo *st = (ShrinkInfo *) b;
SeqInfo *seq;
if( !seq )
if( !(seq = IM_NEW( out, SeqInfo )) )
return( NULL );
/* Init!
@ -141,7 +142,7 @@ shrink_start( IMAGE *out, IMAGE *in, ShrinkInfo *st )
int iy = y * st->yshrink; \
TYPE *p = (TYPE *) IM_REGION_ADDR( ir, ix, iy ); \
\
for( b = 0; b < ir->im->Bands; b++ ) { \
for( k = 0; k < ir->im->Bands; k++ ) { \
int sum = 0; \
int *t = seq->off; \
\
@ -165,7 +166,7 @@ shrink_start( IMAGE *out, IMAGE *in, ShrinkInfo *st )
int iy = y * st->yshrink; \
TYPE *p = (TYPE *) IM_REGION_ADDR( ir, ix, iy ); \
\
for( b = 0; b < ir->im->Bands; b++ ) { \
for( k = 0; k < ir->im->Bands; k++ ) { \
double sum = 0; \
int *t = seq->off; \
\
@ -181,10 +182,11 @@ shrink_start( IMAGE *out, IMAGE *in, ShrinkInfo *st )
/* Shrink a REGION.
*/
static int
shrink_gen( REGION *or, SeqInfo *seq, IMAGE *in, ShrinkInfo *st )
shrink_gen( REGION *or, void *vseq, void *a, void *b )
{
SeqInfo *seq = (SeqInfo *) vseq;
ShrinkInfo *st = (ShrinkInfo *) b;
REGION *ir = seq->ir;
Rect *r = &or->valid;
Rect s;
int le = r->left;
@ -192,7 +194,7 @@ shrink_gen( REGION *or, SeqInfo *seq, IMAGE *in, ShrinkInfo *st )
int to = r->top;
int bo = IM_RECT_BOTTOM(r);
int x, y, z, b;
int x, y, z, k;
/* What part of the input image do we need? Very careful: round left
* down, round right up.
@ -209,7 +211,8 @@ shrink_gen( REGION *or, SeqInfo *seq, IMAGE *in, ShrinkInfo *st )
*/
for( z = 0, y = 0; y < st->mh; y++ )
for( x = 0; x < st->mw; x++ )
seq->off[z++] = (IM_REGION_ADDR( ir, x, y ) - IM_REGION_ADDR( ir, 0, 0 )) /
seq->off[z++] = (IM_REGION_ADDR( ir, x, y ) -
IM_REGION_ADDR( ir, 0, 0 )) /
IM_IMAGE_SIZEOF_ELEMENT( ir->im );
switch( ir->im->BandFmt ) {
@ -223,7 +226,7 @@ shrink_gen( REGION *or, SeqInfo *seq, IMAGE *in, ShrinkInfo *st )
case IM_BANDFMT_DOUBLE: fshrink(double); break;
default:
im_errormsg( "im_shrink: unsupported input format" );
im_error( "im_shrink", _( "unsupported input format" ) );
return( -1 );
}
@ -238,11 +241,12 @@ shrink( IMAGE *in, IMAGE *out, double xshrink, double yshrink )
/* Check parameters.
*/
if( !in || im_iscomplex( in ) ) {
im_errormsg( "im_shrink: non-complex input only" );
im_error( "im_shrink", _( "non-complex input only" ) );
return( -1 );
}
if( xshrink < 1.0 || yshrink < 1.0 ) {
im_errormsg( "im_shrink: shrink factors should both be >1" );
im_error( "im_shrink",
_( "shrink factors should both be >1" ) );
return( -1 );
}
if( im_piocheck( in, out ) )
@ -257,7 +261,7 @@ shrink( IMAGE *in, IMAGE *out, double xshrink, double yshrink )
out->Xres = in->Xres / xshrink;
out->Yres = in->Yres / yshrink;
if( out->Xsize <= 0 || out->Ysize <= 0 ) {
im_errormsg( "im_shrink: image has shrunk to nothing" );
im_error( "im_shrink", _( "image has shrunk to nothing" ) );
return( -1 );
}
@ -305,7 +309,7 @@ im_shrink( IMAGE *in, IMAGE *out, double xshrink, double yshrink )
return( -1 );
}
else {
im_errormsg( "im_shrink: unknown coding type" );
im_error( "im_shrink", _( "unknown coding type" ) );
return( -1 );
}