68 #define PI 3.14159265358979323846
77 #define FRAC(x) ((x) - ((int) floor(x)))
78 #define ROUND(x) ((int)((x) + 0.5
))
79 #define DEG(x) ((x) * PI / 180.0
)
82 #define MIN(x,y) ((x) < (y) ? (x) : (y))
83 #define MAX(x,y) ((x) > (y) ? (x) : (y))
124 char *infilename = NULL,
142 FILE *outfile = stdout;
156 "% s%-xscale!Fyscale!F S%-xsize!Fysize!F c%- a%-angle!F b%-blur!F v%- \
157 p%-xorg!dyorg!d t%-xoff!Fyoff!F \to%-outfile!s infile%s",
158 &scaleflag
, &xscale
, &yscale
,
159 &sizeflag
, &xsize
, &ysize
, ¢erflag
,
163 &translateflag
, &xtrans
, &ytrans
,
164 &oflag
, &out_fname
, &infilename
) == 0)
174 if (fabs(angle) > 45.0)
176 "fant: Warning: angle larger than 45 degrees, image will blur.\n");
178 if (sizeflag && (angleflag || scaleflag ||
originflag || translateflag))
181 "%s: size option (-S) is incompatible with the angle (-a), scale (-s),\n\
182 \ttranslate (-t) and origin (-p) options\n",
186 if ( !sizeflag && centerflag )
188 "%s: center option (-c) ignored without size option (-S)\n",
193 fprintf( stderr,
"fant: blur factor must be positive\n" );
197 if ((scaleflag && xscale == 1.0) && (angle == 0.0))
201 fprintf(stderr,
"fant: Only performing vertical pass\n");
237 xscale = xsize / (p[2]
.x - p[1]
.x);
238 yscale = ysize / (p[3]
.y - p[2]
.y);
244 if ( xscale < yscale )
248 ytrans = (ysize - (p[3]
.y - p[2]
.y) * yscale) / 2;
253 xtrans = (xsize - (p[2]
.x - p[1]
.x) * xscale) / 2;
302 for (i = 1; i <= 4; i++)
344 double real_outpos, sizefac, delta;
345 int i1, i2, ystart, yend;
350 fprintf(stderr,
"transforming channel %d...\n",
357 real_outpos = p[1]
.y;
359 sizefac = (p[4]
.y-p[1]
.y) / (yinlen);
360 delta = (p[2]
.y - p[1]
.y) / (xinlen);
368 real_outpos += delta;
376 real_outpos = ( ((p[2]
.y - p[4]
.y) * (p[1]
.x - p[4]
.x))
377 / (p[1]
.y - p[4]
.y) ) + p[4]
.x;
378 sizefac = (p[2]
.x - real_outpos) / (xinlen);
379 delta = (p[4]
.x - real_outpos)
380 / ((
double) ((
int) p[4]
.y) - ((
int) p[2]
.y));
384 real_outpos = p[1]
.x;
396 real_outpos += delta * abs(ystart);
405 real_outpos += delta;
419 double xscale, yscale, angle, xtrans, ytrans;
421 double s, c, xoff, yoff;
442 fprintf(stderr,
"Output rectangle:\n");
444 for ( i = 1; i <= 4; i++ )
449 tmp = p[i]
.x * c + p[i]
.y * s;
450 p[i]
.y = -p[i]
.x * s + p[i]
.y * c;
456 p[i]
.x += ( xoff + xtrans );
457 p[i]
.y += ( yoff + ytrans );
460 fprintf(stderr,
" %4.1f\t%4.1f\n", p[i]
.x, p[i]
.y);
485 register rle_pixel *pin, *pout, *pend, *p;
490 radius = (sizefac > 1.0) ? 1.0 : delta;
501 xmin = (
int) floor((-radius)*sizefac + real_outpos);
502 if (xmin < 0) xmin = 0;
503 if (xmin > outmax) xmin = outmax;
504 xmax = floor(inmax - inmin + 1.0 + radius);
505 xmax = floor((xmax + 0.5)*sizefac + real_outpos);
506 if (xmax < 0) xmax = 0;
507 if (xmax > outmax) xmax = outmax;
509 inlen = inmax - inmin + 1;
529 pend =
bufin + inlen;
539 pend = p + stride*xmin;
541 { *p = 0; p += stride; }
542 p = pout + stride*(xmax+1);
543 pend = pout + stride*(outmax+1);
545 { *p = 0; p += stride; }
549 pos = (xmin + 0.5 - real_outpos)*delta;
572 register long pxl, fpos, weight, sum, accum;
573 register int i, i0, i1, x;
574 long rpos, rradius, rdelta ;
584 rpos = (
long) (pos*
SCALE + 0.5);
585 rradius = (
long) (radius*
SCALE + 0.5);
586 rdelta = (
long) (delta*
SCALE + 0.5);
590 for (x=xmin; x<=xmax; x++)
601 for(i=i0; i<=i1; i++)
604 pxl = (i < 0 || i >= inlen) ? 0 : pin[i];
608 if (fpos < 0) fpos = -fpos;
610 weight = rradius - fpos;
611 accum += pxl * weight;
638 register long pv, nv, inseg;
639 register long rdelta;
644 rpos = (
long) (pos*
SCALE + 0.5);
645 rdelta = (
long) (delta*
SCALE + 0.5);
650 inseg = (rpos - (i <<
SHIFT));
651 if (inseg < 0) { i++; inseg +=
SCALE; }
655 if (i < 0 || i >= inlen) pv = 0;
else { pv = *pin; pin++; }
657 if (i < 0 || i >= inlen) nv = 0;
else { nv = *pin; pin++; }
660 pend = pout + (xmax-xmin)*stride + 1;
672 if (i < 0 || i >= inlen)
675 { nv = *pin; pin++; }
695 for ( chan = 0; chan <
nchan; chan++ )
696 ptrs[chan] = ras_ptrs[chan][0];
700 for ( chan = 0; chan <
nchan; chan++ )
701 rows[chan] = ptrs[chan];
706 for ( chan = 0; chan <
nchan; chan++ )
727 for ( chan = 0; chan <
nchan; chan++ )
730 for ( chan = 0; chan <
nchan; chan++ )
731 ptrs[chan] = ras_ptrs[chan][0];
735 for ( chan = 0; chan <
nchan; chan++ )
740 for ( chan = 0; chan <
nchan; chan++ )
759 rle_pixel ***ras_ptrs;
761 int x, y, xmin, ymin, xmax, ymax, chan;
763 ymin = MIN(out_hdr.ymin,in_hdr.ymin);
764 ymax = MAX(out_hdr.ymax,in_hdr.ymax) - ymin;
765 xmin = MIN(out_hdr.xmin,in_hdr.xmin);
766 xmax = MAX(out_hdr.xmax,in_hdr.xmax);
768 for ( chan = 0; chan < nchan; chan++ )
769 for (y = ymax; y >=0 ; y--)
771 for (x=xmin; x<=xmax; x++)
773 fprintf(stderr,
"%2x ", ras_ptrs[chan][y][x]);
775 fprintf(stderr,
"\n");
FILE * rle_open_f(char *prog_name, char *file_name, char *mode)
rle_hdr * rle_hdr_cp(rle_hdr *from_hdr, rle_hdr *to_hdr)
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
void xform_points(point *p, double xscale, double yscale, double angle, double xtrans, double ytrans)
char * cmd_name(char **argv)
void main(int argc, char **argv)
int rle_get_setup(rle_hdr *the_hdr)
int rle_getrow(rle_hdr *the_hdr, scanline)
int rle_get_error(int code, const char *pgmname, const char *fname)
void clear_raster(rle_pixel ***ras_ptr)
int scanargs(int argc, char **argv, const char *format,...)
void rle_puteof(rle_hdr *the_hdr)
void putraster(rle_pixel ***ras_ptrs)
void rle_putrow(rows, int rowlen, rle_hdr *the_hdr)
void general_interp_row(rle_pixel *pin, int inlen, rle_pixel *pout, int stride, int xmin, int xmax, double pos, double radius, double delta)
void rle_addhist(argv, rle_hdr *in_hdr, rle_hdr *out_hdr)
void xform_image(point *p, double blur)
char * mallocNd(unsigned int nDim, Dims, unsigned int sizeofelt)
void rle_put_setup(rle_hdr *the_hdr)
void interp_row(double sizefac, double blur, int inmin, double real_outpos, int inmax, int outmax)
void fast_interp_row(rle_pixel *pin, int inlen, rle_pixel *pout, int stride, int xmin, int xmax, double pos, double delta)
void getraster(rle_pixel ***ras_ptrs)
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
#define RLE_CHECK_ALLOC(pgm, ptr, name)