/* Like im_similarity(), but return the transform we generated. */ static int apply_similarity( VipsTransformation *trn, IMAGE *in, IMAGE *out, double a, double b, double dx, double dy ) { trn->iarea.left = 0; trn->iarea.top = 0; trn->iarea.width = in->Xsize; trn->iarea.height = in->Ysize; trn->a = a; trn->b = -b; trn->c = b; trn->d = a; trn->idx = 0; trn->idy = 0; trn->odx = dx; trn->ody = dy; vips__transform_set_area( trn ); if( vips__transform_calc_inverse( trn ) ) return( -1 ); if( vips__affine( in, out, trn ) ) return( -1 ); return( 0 ); }
/* Combine two transformations. out can be one of the ins. */ int vips__transform_add( const VipsTransformation *in1, const VipsTransformation *in2, VipsTransformation *out ) { out->a = in1->a * in2->a + in1->c * in2->b; out->b = in1->b * in2->a + in1->d * in2->b; out->c = in1->a * in2->c + in1->c * in2->d; out->d = in1->b * in2->c + in1->d * in2->d; // fixme: do idx/idy as well out->odx = in1->odx * in2->a + in1->ody * in2->b + in2->odx; out->ody = in1->odx * in2->c + in1->ody * in2->d + in2->ody; if( vips__transform_calc_inverse( out ) ) return( -1 ); return( 0 ); }
/* Init a VipsTransform. */ void vips__transform_init( VipsTransformation *trn ) { trn->oarea.left = 0; trn->oarea.top = 0; trn->oarea.width = -1; trn->oarea.height = -1; trn->iarea.left = 0; trn->iarea.top = 0; trn->iarea.width = -1; trn->iarea.height = -1; trn->a = 1.0; /* Identity transform */ trn->b = 0.0; trn->c = 0.0; trn->d = 1.0; trn->idx = 0.0; trn->idy = 0.0; trn->odx = 0.0; trn->ody = 0.0; (void) vips__transform_calc_inverse( trn ); }