more gen/it hacks

This commit is contained in:
John Cupitt 2007-10-20 21:12:50 +00:00
parent 57f24c63d6
commit 20d83b9af2
4 changed files with 44 additions and 28 deletions

4
TODO
View File

@ -4,6 +4,10 @@
also, same problem as maxpos_avg re. uninit data?
- im_spcor2() has a potential leak in the start function
- zerox_gen() passes an int as a void*, hmm
Python binding
==============

View File

@ -109,9 +109,9 @@ typedef struct {
} spcor2_w_inf;
static spcor2_seq *spcor2_start( IMAGE *r, IMAGE *f );
static int spcor2_gen( REGION *r, spcor2_seq *seq, void *unrequired, spcor2_w_inf *w_inf );
static int spcor2_stop( spcor2_seq *seq );
static void *spcor2_start( IMAGE *r, void *a, void *b );
static int spcor2_gen( REGION *r, void *seq, void *a, void *b );
static int spcor2_stop( void *seq, void *a, void *b );
#define LOOP(IN) \
{ \
@ -156,8 +156,10 @@ static int spcor2_stop( spcor2_seq *seq );
/* spcor generate function.
*/
static int
spcor_gen( REGION *or, REGION *ir, IMAGE *in, SpcorInfo *inf )
spcor_gen( REGION *or, void *seq, void *a, void *b )
{
REGION *ir = (REGION *) seq;
SpcorInfo *inf = (SpcorInfo *) b;
IMAGE *ref = inf->ref;
Rect irect;
Rect *r = &or->valid;
@ -399,14 +401,15 @@ im_spcor2_raw(
im_free_dmask( w_stats );
return im_generate( r, (void*)spcor2_start, spcor2_gen, spcor2_stop, f, w_inf );
return im_generate( r, spcor2_start, spcor2_gen, spcor2_stop, f, w_inf );
#undef FUNCTION_NAME
}
static spcor2_seq *
spcor2_start( IMAGE *r, IMAGE *f ){
static void *
spcor2_start( IMAGE *r, void *a, void *b ){
IMAGE *f= (IMAGE *) a;
REGION *reg= im_region_create( f );
spcor2_seq *seq;
@ -427,11 +430,11 @@ spcor2_start( IMAGE *r, IMAGE *f ){
static int
spcor2_gen(
REGION *r,
spcor2_seq *seq,
void *unrequired,
spcor2_w_inf *w_inf
void *vseq, void *a, void *b
){
spcor2_seq *seq= (spcor2_seq *) vseq;
spcor2_w_inf *w_inf= (spcor2_w_inf *) b;
Rect need= {
r-> valid. left,
r-> valid. top,
@ -521,7 +524,9 @@ spcor2_gen(
}
static int
spcor2_stop( spcor2_seq *seq ){
spcor2_stop( void *vseq, void *a, void *b ){
spcor2_seq *seq= (spcor2_seq *) vseq;
im_region_free( seq-> f );
im_free( seq-> f_cols );

View File

@ -86,22 +86,23 @@ typedef struct seq_info {
} SeqInfo;
static int
stop_stretch( SeqInfo *seq )
stretch_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 );
}
static void *
start_stretch( IMAGE *out, IMAGE *in, StretchInfo *sin )
stretch_start( IMAGE *out, void *a, void *b )
{
SeqInfo *seq = IM_NEW( out, SeqInfo );
IMAGE *in = (IMAGE *) a;
StretchInfo *sin = (StretchInfo *) b;
SeqInfo *seq;
if( !seq )
if( !(seq = IM_NEW( out, SeqInfo )) )
return( NULL );
seq->sin = sin;
@ -110,7 +111,7 @@ start_stretch( IMAGE *out, IMAGE *in, StretchInfo *sin )
seq->buf = IM_ARRAY( out, 4*seq->lsk, unsigned short );
if( !seq->buf || !seq->ir ) {
stop_stretch( seq );
stretch_stop( seq, NULL, NULL );
return( NULL );
}
@ -191,8 +192,10 @@ make_yline( StretchInfo *sin, int lsk, int boff,
}
static int
stretch_gen( REGION *or, SeqInfo *seq, IMAGE *in, StretchInfo *sin )
stretch_gen( REGION *or, void *vseq, void *a, void *b )
{
SeqInfo *seq = (SeqInfo *) vseq;
StretchInfo *sin = (StretchInfo *) b;
REGION *ir = seq->ir;
Rect *r = &or->valid;
Rect r1;
@ -265,11 +268,12 @@ im_stretch3( IMAGE *in, IMAGE *out, double dx, double dy )
/* Check our args.
*/
if( in->Coding != IM_CODING_NONE || in->BandFmt != IM_BANDFMT_USHORT ) {
im_errormsg( "im_stretch3: not uncoded unsigned short" );
im_error( "im_stretch3", _( "not uncoded unsigned short" ) );
return( -1 );
}
if( dx < 0 || dx >= 1.0 || dy < 0 || dy >= 1.0 ) {
im_errormsg( "im_stretch3: displacements out of range [0,1)" );
im_error( "im_stretch3",
_( "displacements out of range [0,1)" ) );
return( -1 );
}
if( im_piocheck( in, out ) )
@ -316,7 +320,7 @@ im_stretch3( IMAGE *in, IMAGE *out, double dx, double dy )
sin->yoff = (dy * 33.0) + 0.5;
if( im_generate( out,
start_stretch, stretch_gen, stop_stretch, in, sin ) )
stretch_start, stretch_gen, stretch_stop, in, sin ) )
return( -1 );
return( 0 );

View File

@ -67,7 +67,7 @@
#define loop( TYPE ) \
for( i = 0; i < ne; i++ ) { \
TYPE p1 = ((TYPE *)p)[i]; \
TYPE p2 = ((TYPE *)p)[i + b]; \
TYPE p2 = ((TYPE *)p)[i + ba]; \
\
if( flag == 1 && p1 > 0 && p2 <= 0 ) \
q[i] = 255; \
@ -80,8 +80,11 @@
/* Zerox generate function.
*/
static int
zerox_gen( REGION *or, REGION *ir, IMAGE *in, int flag )
zerox_gen( REGION *or, void *seq, void *a, void *b )
{
REGION *ir = (REGION *) seq;
IMAGE *in = (IMAGE *) a;
int flag = (int) b;
Rect irect;
Rect *r = &or->valid;
@ -90,8 +93,8 @@ zerox_gen( REGION *or, REGION *ir, IMAGE *in, int flag )
int le = r->left;
int to = r->top;
int bo = IM_RECT_BOTTOM( r );
int b = in->Bands;
int ne = b * r->width;
int ba = in->Bands;
int ne = ba * r->width;
int i, y;