int im__tbcalcon( IMAGE *ref, TIE_POINTS *points ) { /* Geometry: border we must leave around each area. */ const int border = points->halfareasize; /* Width of an area. */ const int awidth = ref->Xsize / AREAS; /* Number of points we find in each area. */ const int len = points->nopoints / AREAS; int i; Rect area; /* Make sure we can read image. */ if( im_incheck( ref ) ) return( -1 ); if( ref->Bands != 1 || ref->BandFmt != IM_BANDFMT_UCHAR ) { im_error( "im__tbcalcon", "%s", _( "help!" ) ); return( -1 ); } /* Define bits to search for high-contrast areas. */ area.width = awidth; area.height = ref->Ysize; area.left = 0; area.top = 0; im_rect_marginadjust( &area, -border ); area.width--; area.height--; if( area.width < 0 || area.height < 0 ) { im_error( "im__tbcalcon", "%s", _( "overlap too small" ) ); return( -1 ); } /* Loop over areas, finding points. */ for( i = 0; area.left < ref->Xsize; area.left += awidth, i++ ) if( im__find_best_contrast( ref, area.left, area.top, area.width, area.height, points->x_reference + i*len, points->y_reference + i*len, points->contrast + i*len, len, points->halfcorsize ) ) return( -1 ); return( 0 ); }
static int affinei_gen( REGION *or, void *seq, void *a, void *b ) { REGION *ir = (REGION *) seq; const IMAGE *in = (IMAGE *) a; const Affine *affine = (Affine *) b; const int window_offset = vips_interpolate_get_window_offset( affine->interpolate ); const VipsInterpolateMethod interpolate = vips_interpolate_get_method( affine->interpolate ); /* Area we generate in the output image. */ const Rect *r = &or->valid; const int le = r->left; const int ri = IM_RECT_RIGHT( r ); const int to = r->top; const int bo = IM_RECT_BOTTOM( r ); const Rect *iarea = &affine->trn.iarea; const Rect *oarea = &affine->trn.oarea; int ps = IM_IMAGE_SIZEOF_PEL( in ); int x, y, z; Rect image, want, need, clipped; #ifdef DEBUG printf( "affine: generating left=%d, top=%d, width=%d, height=%d\n", r->left, r->top, r->width, r->height ); #endif /*DEBUG*/ /* We are generating this chunk of the transformed image. */ want = *r; want.left += oarea->left; want.top += oarea->top; /* Find the area of the input image we need. */ im__transform_invert_rect( &affine->trn, &want, &need ); /* Now go to space (2) above. */ need.left += iarea->left; need.top += iarea->top; /* Add a border for interpolation. Plus one for rounding errors. */ im_rect_marginadjust( &need, window_offset + 1 ); /* Clip against the size of (2). */ image.left = 0; image.top = 0; image.width = in->Xsize; image.height = in->Ysize; im_rect_intersectrect( &need, &image, &clipped ); /* Outside input image? All black. */ if( im_rect_isempty( &clipped ) ) { im_region_black( or ); return( 0 ); } /* We do need some pixels from the input image to make our output - * ask for them. */ if( im_prepare( ir, &clipped ) ) return( -1 ); #ifdef DEBUG printf( "affine: preparing left=%d, top=%d, width=%d, height=%d\n", clipped.left, clipped.top, clipped.width, clipped.height ); #endif /*DEBUG*/ /* Resample! x/y loop over pixels in the output image (5). */ for( y = to; y < bo; y++ ) { /* Input clipping rectangle. */ const int ile = iarea->left; const int ito = iarea->top; const int iri = iarea->left + iarea->width; const int ibo = iarea->top + iarea->height; /* Derivative of matrix. */ const double ddx = affine->trn.ia; const double ddy = affine->trn.ic; /* Continuous cods in transformed space. */ const double ox = le + oarea->left - affine->trn.dx; const double oy = y + oarea->top - affine->trn.dy; /* Continuous cods in input space. */ double ix, iy; PEL *q; /* To (3). */ ix = affine->trn.ia * ox + affine->trn.ib * oy; iy = affine->trn.ic * ox + affine->trn.id * oy; /* Now move to (2). */ ix += iarea->left; iy += iarea->top; q = (PEL *) IM_REGION_ADDR( or, le, y ); for( x = le; x < ri; x++ ) { int fx, fy; fx = FLOOR( ix ); fy = FLOOR( iy ); /* Clipping! */ if( fx < ile || fx >= iri || fy < ito || fy >= ibo ) { for( z = 0; z < ps; z++ ) q[z] = 0; } else { interpolate( affine->interpolate, q, ir, ix, iy ); } ix += ddx; iy += ddy; q += ps; } } return( 0 ); }
/* Smear a section of an IMAGE. As above, but shift it left a bit. */ int im_smear( IMAGE *im, int ix, int iy, Rect *r ) { int x, y, a, b, c; int ba = im->Bands; int el = ba * im->Xsize; Rect area, image, clipped; double total[ 256 ]; if( im_rwcheck( im ) ) return( -1 ); /* Don't do the margins. */ area = *r; area.left += ix; area.top += iy; image.left = 0; image.top = 0; image.width = im->Xsize; image.height = im->Ysize; im_rect_marginadjust( &image, -1 ); image.left--; im_rect_intersectrect( &area, &image, &clipped ); /* Any left? */ if( im_rect_isempty( &clipped ) ) return( 0 ); /* What we do for each type. */ #define SMEAR(TYPE) \ for( y = clipped.top; y < clipped.top + clipped.height; y++ ) \ for( x = clipped.left; \ x < clipped.left + clipped.width; x++ ) { \ TYPE *to = (TYPE *) im->data + x * ba + y * el; \ TYPE *from = to - el; \ TYPE *f; \ \ for( a = 0; a < ba; a++ ) \ total[a] = 0.0; \ \ for( a = 0; a < 3; a++ ) { \ f = from; \ for( b = 0; b < 3; b++ ) \ for( c = 0; c < ba; c++ ) \ total[c] += *f++; \ from += el; \ } \ \ for( a = 0; a < ba; a++ ) \ to[a] = (40 * (double) to[a+ba] + total[a]) \ / 49.0; \ } /* Loop through the remaining pixels. */ switch( im->BandFmt ) { case IM_BANDFMT_UCHAR: SMEAR(unsigned char); break; case IM_BANDFMT_CHAR: SMEAR(char); break; case IM_BANDFMT_USHORT: SMEAR(unsigned short); break; case IM_BANDFMT_SHORT: SMEAR(short); break; case IM_BANDFMT_UINT: SMEAR(unsigned int); break; case IM_BANDFMT_INT: SMEAR(int); break; case IM_BANDFMT_FLOAT: SMEAR(float); break; case IM_BANDFMT_DOUBLE: SMEAR(double); break; /* Do complex types too. Just treat as float and double, but with * twice the number of bands. */ case IM_BANDFMT_COMPLEX: /* Twice number of bands: double size and bands. */ ba *= 2; el *= 2; SMEAR(float); break; case IM_BANDFMT_DPCOMPLEX: /* Twice number of bands: double size and bands. */ ba *= 2; el *= 2; SMEAR(double); break; default: im_error( "im_smear", "%s", _( "unknown band format" ) ); return( -1 ); } return( 0 ); }