Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
Data Structures | Macros | Typedefs | Functions | Variables
fant.c File Reference
#include <stdio.h>
#include <math.h>
#include "rle.h"
Include dependency graph for fant.c:

Go to the source code of this file.

Data Structures

struct  point
 

Macros

#define MAXCHAN   256
 
#define PI   3.14159265358979323846
 
#define H_PASS   0
 
#define V_PASS   1
 
#define FRAC(x)   ((x) - ((int) floor(x)))
 
#define ROUND(x)   ((int)((x) + 0.5))
 
#define DEG(x)   ((x) * PI / 180.0)
 
#define EPSILON   .0001
 
#define MIN(x, y)   ((x) < (y) ? (x) : (y))
 
#define MAX(x, y)   ((x) > (y) ? (x) : (y))
 
#define SHIFT   16
 
#define SCALE   (1 << SHIFT)
 

Typedefs

typedef struct point point
 

Functions

void * mallocNd ()
 
void interp_row ()
 
void fast_interp_row ()
 
void general_interp_row ()
 
void getraster ()
 
void xform_image ()
 
void putraster ()
 
void clear_raster ()
 
void xform_points ()
 
void main (int argc, argv)
 
void xform_image (point *p, double blur)
 
void xform_points (point *p, double xscale, double yscale, double angle, double xtrans, double ytrans)
 
void interp_row (double sizefac, double blur, int inmin, double real_outpos, int inmax, int outmax)
 
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 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)
 
void putraster (rle_pixel ***ras_ptrs)
 
void clear_raster (rle_pixel ***ras_ptr)
 

Variables

rle_pixel *** rast
 
rle_pixelbufin
 
int const_ind
 
int cur_chan
 
int pass
 
rle_hdr in_hdr
 
rle_hdr out_hdr
 
int nchan
 
int array_width
 
int outlinewidth
 
int array_lines
 
int verboseflag
 
int originflag
 
int X_origin
 
int Y_origin
 
int vpassonlyflag
 

Macro Definition Documentation

#define DEG (   x)    ((x) * PI / 180.0)

Definition at line 79 of file fant.c.

#define EPSILON   .0001

Definition at line 80 of file fant.c.

#define FRAC (   x)    ((x) - ((int) floor(x)))

Definition at line 77 of file fant.c.

#define H_PASS   0

Definition at line 72 of file fant.c.

#define MAX (   x,
  y 
)    ((x) > (y) ? (x) : (y))

Definition at line 83 of file fant.c.

#define MAXCHAN   256

Definition at line 65 of file fant.c.

#define MIN (   x,
  y 
)    ((x) < (y) ? (x) : (y))

Definition at line 82 of file fant.c.

#define PI   3.14159265358979323846

Definition at line 68 of file fant.c.

#define ROUND (   x)    ((int)((x) + 0.5))

Definition at line 78 of file fant.c.

#define SCALE   (1 << SHIFT)

Definition at line 469 of file fant.c.

#define SHIFT   16

Definition at line 468 of file fant.c.

#define V_PASS   1

Definition at line 73 of file fant.c.

Typedef Documentation

typedef struct point point

Function Documentation

void clear_raster ( )
void clear_raster ( rle_pixel ***  ras_ptr)

Definition at line 747 of file fant.c.

749 {
750  bzero( &(ras_ptr[cur_chan][0][0]), array_width * array_lines );
751 }
int array_lines
Definition: fant.c:106
int cur_chan
Definition: fant.c:101
int array_width
Definition: fant.c:105
void fast_interp_row ( )
void fast_interp_row ( rle_pixel pin,
int  inlen,
rle_pixel pout,
int  stride,
int  xmin,
int  xmax,
double  pos,
double  delta 
)

Definition at line 629 of file fant.c.

637 {
638  register long pv, nv, inseg;
639  register long rdelta;
640  register rle_pixel *pend;
641  long rpos;
642  int i;
643 
644  rpos = (long) (pos*SCALE + 0.5); /* fixed point forms */
645  rdelta = (long) (delta*SCALE + 0.5);
646 
647  /* find starting point in input array */
648  rpos -= SCALE/2;
649  i = (rpos >> SHIFT);
650  inseg = (rpos - (i << SHIFT));
651  if (inseg < 0) { i++; inseg += SCALE; }
652  if (i > 0) pin+= i;
653 
654  /* Lookup initial pixel values */
655  if (i < 0 || i >= inlen) pv = 0; else { pv = *pin; pin++; }
656  i++;
657  if (i < 0 || i >= inlen) nv = 0; else { nv = *pin; pin++; }
658 
659  /* Loop over output pixels */
660  pend = pout + (xmax-xmin)*stride + 1;
661  while (pout < pend)
662  {
663  /* Simple linear interpolation */
664  *pout = (pv*(SCALE-inseg) + nv*inseg + SCALE/2) >> SHIFT;
665 
666  /* advance to next input pixel (in src coordinates) */
667  inseg += rdelta;
668  if (inseg > SCALE)
669  {
670  pv = nv;
671  i++;
672  if (i < 0 || i >= inlen)
673  nv = 0;
674  else
675  { nv = *pin; pin++; }
676  inseg -= SCALE;
677  }
678  pout += stride;
679  }
680 }
#define SHIFT
Definition: fant.c:468
unsigned char rle_pixel
Definition: rle.h:56
int i
Definition: rletorla.c:82
#define SCALE
Definition: fant.c:469
void general_interp_row ( )
void general_interp_row ( rle_pixel pin,
int  inlen,
rle_pixel pout,
int  stride,
int  xmin,
int  xmax,
double  pos,
double  radius,
double  delta 
)

Definition at line 562 of file fant.c.

571 {
572  register long pxl, fpos, weight, sum, accum;
573  register int i, i0, i1, x;
574  long rpos, rradius, rdelta ;
575 
576 
577  /* This is the general case. We walk through all the output points.
578  * for each output point we map back into the input coordinate system
579  * to figure out which pixels affect it. We sum over all input pixels
580  * that overlap the filter support. A triangle filter is hardwired at
581  * present for speed.
582  */
583 
584  rpos = (long) (pos*SCALE + 0.5); /* fixed point forms */
585  rradius = (long) (radius*SCALE + 0.5);
586  rdelta = (long) (delta*SCALE + 0.5);
587 
588 
589  /* For each output pixel */
590  for (x=xmin; x<=xmax; x++)
591  {
592  /* find bounds in input array */
593 
594  i0 = (rpos - rradius + SCALE/2) >>SHIFT; /* floor(pos -radius +0.5); */
595  i1 = (rpos + rradius - SCALE/2) >>SHIFT; /* floor(pos +radius -0.5); */
596 
597  /* sum over each input pixel which effects this output pixel
598  * weights are taken from a triangle filter of width radius.
599  */
600  sum = accum = 0;
601  for(i=i0; i<=i1; i++)
602  {
603  /* lookup input pixel (zero's at boundaries) */
604  pxl = (i < 0 || i >= inlen) ? 0 : pin[i];
605 
606  /* map to filter coordinate system */
607  fpos = (i<<SHIFT) + SCALE/2 - rpos; /* fabs(i+0.5-pos); */
608  if (fpos < 0) fpos = -fpos;
609 
610  weight = rradius - fpos;
611  accum += pxl * weight;
612  sum += weight;
613  }
614  if (sum > 0)
615  *pout = accum/sum;
616 
617  /* advance to next input pixel (in src coordinates) */
618  rpos += rdelta; /* pos += delta */
619  pout += stride;
620  }
621 }
static int x
Definition: getami.c:691
#define SHIFT
Definition: fant.c:468
int i
Definition: rletorla.c:82
#define SCALE
Definition: fant.c:469
void getraster ( )
void getraster ( rle_pixel ***  ras_ptrs)

Definition at line 688 of file fant.c.

690 {
691  int i, chan;
692  rle_pixel *ptrs[MAXCHAN];
693  rle_pixel *rows[MAXCHAN]; /* Pointers for getrow/putrow */
694 
695  for ( chan = 0; chan < nchan; chan++ )
696  ptrs[chan] = ras_ptrs[chan][0];
697 
698  for (i = in_hdr.ymin; i <= in_hdr.ymax; i++)
699  {
700  for ( chan = 0; chan < nchan; chan++ )
701  rows[chan] = ptrs[chan];
702  rle_getrow( &in_hdr, &(rows[in_hdr.alpha]) );
703 
704 
705  /* Bump pointers */
706  for ( chan = 0; chan < nchan; chan++ )
707  ptrs[chan] += array_width;
708  }
709 }
int ymin
Definition: rle.h:100
#define MAXCHAN
Definition: fant.c:65
rle_hdr in_hdr
Definition: fant.c:103
rle_pixel ** rows
Definition: rletopaint.c:57
int ymax
Definition: rle.h:100
unsigned char rle_pixel
Definition: rle.h:56
int array_width
Definition: fant.c:105
int i
Definition: rletorla.c:82
int alpha
Definition: rle.h:100
int nchan
Definition: fant.c:104
int rle_getrow(rle_hdr *the_hdr, rle_pixel *scanline[])
void interp_row ( )
void interp_row ( double  sizefac,
double  blur,
int  inmin,
double  real_outpos,
int  inmax,
int  outmax 
)

Definition at line 472 of file fant.c.

478 {
479  double pos, /* input coordinate of first output point */
480  delta, /* delta (in input coords) between output points */
481  radius; /* filter radius (in input coords) */
482  int xmin, xmax, /* index bounds in output array */
483  stride, /* stride between output array positions */
484  inlen; /* length of input buffer; */
485  register rle_pixel *pin, *pout, *pend, *p;
486 
487 
488  delta = 1/sizefac;
489 
490  radius = (sizefac > 1.0) ? 1.0 : delta; /* filter radius */
491  radius *= blur;
492  /* clamp the filter radius on the bottom end to make sure we get complete
493  coverage. */
494  if (radius < 0.5+EPSILON) radius = 0.5+EPSILON;
495 
496 
497  /*
498  * Find the bounds in the output array
499  */
500  /* min in output coords */
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); /* max in input coordinates */
505  xmax = floor((xmax + 0.5)*sizefac + real_outpos); /* -> output coords */
506  if (xmax < 0) xmax = 0;
507  if (xmax > outmax) xmax = outmax;
508 
509  inlen = inmax - inmin + 1;
510  if (pass == V_PASS)
511  {
512  pin = rast[cur_chan][inmin]+const_ind;
513  pout = rast[cur_chan][0]+const_ind;
514  stride = array_width;
515  }
516  else
517  {
518  pin = rast[cur_chan][const_ind] + inmin;
519  pout = rast[cur_chan][const_ind] + 0;
520  stride = 1;
521  }
522 
523 
524  /*
525  * Copy the input into a row buffer. This saves us some memory so
526  * we don't need a separate output array for the whole image.
527  */
528  p = bufin;
529  pend = bufin + inlen;
530  while (p < pend)
531  {
532  *p++ = *pin;
533  pin += stride;
534  }
535  pin = bufin;
536 
537  /* zero out the part of the output array we aren't going to touch */
538  p = pout;
539  pend = p + stride*xmin;
540  while (p < pend)
541  { *p = 0; p += stride; }
542  p = pout + stride*(xmax+1);
543  pend = pout + stride*(outmax+1);
544  while (p < pend)
545  { *p = 0; p += stride; }
546  pout += stride*xmin;
547 
548  /* input coordinate of first output pixel center */
549  pos = (xmin + 0.5 - real_outpos)*delta;
550 
551  if (radius != 1.0)
552  general_interp_row(pin,inlen,pout,stride,xmin,xmax,pos,radius,delta);
553  else
554  fast_interp_row(pin,inlen,pout,stride,xmin,xmax, pos,delta);
555 }
int pass
Definition: fant.c:102
rle_pixel * bufin
Definition: fant.c:98
#define V_PASS
Definition: fant.c:73
int cur_chan
Definition: fant.c:101
void general_interp_row()
#define EPSILON
Definition: fant.c:80
void fast_interp_row()
rle_pixel *** rast
Definition: fant.c:97
int
Definition: getami.c:848
unsigned char rle_pixel
Definition: rle.h:56
int array_width
Definition: fant.c:105
int const_ind
Definition: fant.c:100
void main ( int  argc,
argv   
)

Definition at line 120 of file fant.c.

123 {
124  char *infilename = NULL,
125  *out_fname = NULL;
126  int oflag = 0;
127  int rle_cnt;
128  int scaleflag = 0,
129  sizeflag = 0,
130  centerflag = 0,
131  angleflag = 0,
132  translateflag = 0,
133  blurflag = 0;
134  double xscale = 1.0,
135  yscale = 1.0,
136  xsize,
137  ysize,
138  blur = 1.0,
139  angle = 0.0,
140  xtrans = 0.0,
141  ytrans = 0.0;
142  FILE *outfile = stdout;
143  int rle_err;
144  int i, i1, i2;
145  point p[5]; /* "5" so we can use 1-4 indices Fant does. */
146  int dims[3];
147 
148 
149  X_origin = 0;
150  Y_origin = 0;
151  verboseflag = 0;
152  originflag = 0;
153  vpassonlyflag = 0;
154 
155  if (scanargs( argc, argv,
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, &centerflag,
160  &angleflag, &angle,
161  &blurflag, &blur,
163  &translateflag, &xtrans, &ytrans,
164  &oflag, &out_fname, &infilename ) == 0)
165  exit(-1);
166 
167  in_hdr = *rle_hdr_init( NULL );
168  out_hdr = *rle_hdr_init( NULL );
169 
170  in_hdr.rle_file = rle_open_f(cmd_name( argv ), infilename, "r");
171  rle_names( &in_hdr, cmd_name( argv ), infilename, 0 );
172  rle_names( &out_hdr, in_hdr.cmd, out_fname, 0 );
173 
174  if (fabs(angle) > 45.0)
175  fprintf(stderr,
176  "fant: Warning: angle larger than 45 degrees, image will blur.\n");
177 
178  if (sizeflag && (angleflag || scaleflag || originflag || translateflag))
179  {
180  fprintf( stderr,
181  "%s: size option (-S) is incompatible with the angle (-a), scale (-s),\n\
182  \ttranslate (-t) and origin (-p) options\n",
183  cmd_name( argv ) );
184  exit(-1);
185  }
186  if ( !sizeflag && centerflag )
187  fprintf( stderr,
188  "%s: center option (-c) ignored without size option (-S)\n",
189  cmd_name( argv ) );
190 
191  if (blur < 0)
192  {
193  fprintf( stderr, "fant: blur factor must be positive\n" );
194  exit(-1);
195  }
196 
197  if ((scaleflag && xscale == 1.0) && (angle == 0.0))
198  {
199  vpassonlyflag = 1;
200  if (verboseflag)
201  fprintf(stderr, "fant: Only performing vertical pass\n");
202  }
203 
204  for ( rle_cnt = 0;
205  (rle_err = rle_get_setup( &in_hdr )) == RLE_SUCCESS;
206  rle_cnt++ )
207  {
209 
210  (void)rle_hdr_cp( &in_hdr, &out_hdr );
211  if ( rle_cnt == 0 )
212  outfile = rle_open_f( cmd_name( argv ), out_fname, "w" );
214 
215  rle_addhist( argv, &in_hdr, &out_hdr );
216 
217  /*
218  * To define the output rectangle, we start with a set of points
219  * defined by the original image, and then rotate and scale them
220  * as desired. Note that we use a continuous coordinate system:
221  * min to max+1 with pixel centers at the midpoints of each unit
222  * square.
223  *
224  * Mapping between coordinate systems:
225  * if c = continuous coord and d = discrete coord, then
226  * c = d+.5
227  * d = floor(c)
228  */
229  p[1].x = in_hdr.xmin; p[1].y = in_hdr.ymin;
230  p[2].x = in_hdr.xmax+1; p[2].y = in_hdr.ymin;
231  p[3].x = in_hdr.xmax+1; p[3].y = in_hdr.ymax+1;
232  p[4].x = in_hdr.xmin; p[4].y = in_hdr.ymax+1;
233 
234  if (sizeflag)
235  {
236  /* Compute the scale factors from the desired destination size*/
237  xscale = xsize / (p[2].x - p[1].x);
238  yscale = ysize / (p[3].y - p[2].y);
239  X_origin = p[1].x;
240  Y_origin = p[1].y;
241  /* If centering, adjust scale factors and origin. */
242  if ( centerflag )
243  {
244  if ( xscale < yscale )
245  {
246  yscale = xscale;
247  xtrans = 0;
248  ytrans = (ysize - (p[3].y - p[2].y) * yscale) / 2;
249  }
250  else
251  {
252  xscale = yscale;
253  xtrans = (xsize - (p[2].x - p[1].x) * xscale) / 2;
254  ytrans = 0;
255  }
256  }
257  originflag = 1;
258  }
259  xform_points(p, xscale, yscale, angle, xtrans, ytrans );
260 
261 
262 
263  /* Map the continous coordinates back to discrete coordinates to
264  * determine the output image size. We only output a pixel if it's
265  * a least partially covered. Partial, for us, means at least
266  * EPSILON coverage. This is a little arbitrary but ensures that
267  * extra pixels aren't included on the ends.
268  */
269 
270 
271  i1 = (int) (p[1].x + EPSILON);
272  i2 = (int) (p[4].x + EPSILON);
273  out_hdr.xmin = MAX(0,MIN(i1,i2));
274 
275  i1 = (int) (p[1].y + EPSILON);
276  i2 = (int) (p[2].y + EPSILON);
277  out_hdr.ymin = MAX(0,MIN(i1,i2));
278 
279  i1 = (int) (p[2].x - EPSILON);
280  i2 = (int) (p[3].x - EPSILON);
281  out_hdr.xmax = MAX(i1,i2);
282 
283  i1 = (int) (p[3].y - EPSILON);
284  i2 = (int) (p[4].y - EPSILON);
285  out_hdr.ymax = MAX(i1,i2);
286 
287 
288  /*
289  * Need to grab the largest dimensions so the buffers will hold the
290  * picture. The arrays for storing the pictures extend from 0
291  * to xmax in width and from ymin to ymax in height.
292  */
295  MIN(out_hdr.ymin,in_hdr.ymin) + 1;
297 
298  /*
299  * Since the array begins at ymin, the four output corner points must be
300  * translated to this coordinate system.
301  */
302  for (i = 1; i <= 4; i++)
303  p[i].y -= MIN(out_hdr.ymin,in_hdr.ymin);
304 
305  /* Oink. */
306 
307  dims[0] = nchan;
308  dims[1] = array_lines;
309  dims[2] = array_width;
310  rast = (rle_pixel ***) mallocNd(3,dims,sizeof(rle_pixel));
311  bufin = (rle_pixel *)
313  RLE_CHECK_ALLOC( cmd_name( argv ), rast && bufin, "raster" );
314 
315  getraster(rast);
316 
317  /* Transform each channel */
318  cur_chan = 0;
319  for (cur_chan = 0; cur_chan < nchan; cur_chan++)
320  xform_image(p,blur);
321 
322  putraster(rast);
323 
324  rle_puteof( &out_hdr );
325  free(rast);
326  free(bufin);
327  }
328 
329  if ( rle_cnt == 0 || (rle_err != RLE_EOF && rle_err != RLE_EMPTY) )
330  rle_get_error( rle_err, cmd_name( argv ), infilename );
331  exit( 0 );
332 }
int xmin
Definition: rle.h:100
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
FILE * outfile
Definition: giftorle.c:61
#define RLE_EMPTY
Definition: rle.h:73
void putraster()
void xform_points()
void * mallocNd()
rle_hdr out_hdr
Definition: fant.c:103
int array_lines
Definition: fant.c:106
int sizeflag
Definition: get4d.c:41
rle_pixel * bufin
Definition: fant.c:98
void rle_addhist(char *argv[], rle_hdr *in_hdr, rle_hdr *out_hdr)
#define RLE_SUCCESS
Definition: rle.h:70
int xsize
Definition: read98721.c:58
int vpassonlyflag
Definition: fant.c:110
int Y_origin
Definition: fant.c:109
int ymin
Definition: rle.h:100
void rle_puteof(rle_hdr *the_hdr)
Definition: rle_putrow.c:474
int X_origin
Definition: fant.c:109
static int y
Definition: getami.c:691
int verboseflag
Definition: fant.c:107
int cur_chan
Definition: fant.c:101
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
const char * cmd
Definition: rle.h:133
int rle_get_setup(rle_hdr *the_hdr)
Definition: rle_getrow.c:74
#define EPSILON
Definition: fant.c:80
rle_hdr in_hdr
Definition: fant.c:103
#define MIN(x, y)
Definition: fant.c:82
int xmax
Definition: rle.h:100
double y
Definition: fant.c:89
static int x
Definition: getami.c:691
int rle_get_error(int code, const char *pgmname, const char *fname)
#define RLE_EOF
Definition: rle.h:74
rle_pixel *** rast
Definition: fant.c:97
int
Definition: getami.c:848
double x
Definition: fant.c:89
Definition: fant.c:87
int ymax
Definition: rle.h:100
int ysize
Definition: read98721.c:59
#define MAX(x, y)
Definition: fant.c:83
unsigned char rle_pixel
Definition: rle.h:56
int array_width
Definition: fant.c:105
rle_hdr * rle_hdr_cp(rle_hdr *from_hdr, rle_hdr *to_hdr)
Definition: rle_hdr.c:119
void * malloc()
int i
Definition: rletorla.c:82
int alpha
Definition: rle.h:100
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
int outlinewidth
Definition: fant.c:106
int nchan
Definition: fant.c:104
void xform_image()
char * cmd_name(char **argv)
Definition: cmd_name.c:31
void getraster()
int oflag
Definition: painttorle.c:45
FILE * rle_file
Definition: rle.h:114
int ncolors
Definition: rle.h:100
int originflag
Definition: fant.c:108
#define RLE_CHECK_ALLOC(pgm, ptr, name)
Definition: rle.h:86
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267
void* mallocNd ( )
void putraster ( )
void putraster ( rle_pixel ***  ras_ptrs)

Definition at line 713 of file fant.c.

715 {
716  int i, chan;
717  rle_pixel *ptrs[MAXCHAN];
718  rle_pixel *rows[MAXCHAN]; /* Pointers for getrow/putrow */
719 
721 
722  /*
723  * If the output image is smaller than the input, we must offset
724  * into the pixel array by the difference between the two.
725  */
726  if (in_hdr.ymin < out_hdr.ymin)
727  for ( chan = 0; chan < nchan; chan++ )
728  ptrs[chan] = ras_ptrs[chan][(out_hdr.ymin - in_hdr.ymin)];
729  else
730  for ( chan = 0; chan < nchan; chan++ )
731  ptrs[chan] = ras_ptrs[chan][0];
732 
733  for (i = out_hdr.ymin; i <= out_hdr.ymax; i++)
734  {
735  for ( chan = 0; chan < nchan; chan++ )
736  rows[chan] = &((ptrs[chan])[out_hdr.xmin]);
738 
739  /* Bump pointers */
740  for ( chan = 0; chan < nchan; chan++ )
741  ptrs[chan] += array_width;
742  }
743 }
int xmin
Definition: rle.h:100
rle_hdr out_hdr
Definition: fant.c:103
void rle_putrow(rle_pixel *rows[], int rowlen, rle_hdr *the_hdr)
int ymin
Definition: rle.h:100
#define MAXCHAN
Definition: fant.c:65
rle_hdr in_hdr
Definition: fant.c:103
rle_pixel ** rows
Definition: rletopaint.c:57
int ymax
Definition: rle.h:100
unsigned char rle_pixel
Definition: rle.h:56
int array_width
Definition: fant.c:105
int i
Definition: rletorla.c:82
int alpha
Definition: rle.h:100
int outlinewidth
Definition: fant.c:106
int nchan
Definition: fant.c:104
void rle_put_setup(rle_hdr *the_hdr)
Definition: rle_putrow.c:453
void xform_image ( )
void xform_image ( point p,
double  blur 
)

Definition at line 340 of file fant.c.

343 {
344  double real_outpos, sizefac, delta;
345  int i1, i2, ystart, yend;
346  int xinlen = in_hdr.xmax - in_hdr.xmin + 1;
347  int yinlen = in_hdr.ymax - in_hdr.ymin + 1;
348 
349  if (verboseflag)
350  fprintf(stderr, "transforming channel %d...\n",
351  cur_chan - in_hdr.alpha);
352 
353  /* Vertical pass */
354  pass = V_PASS;
355 /* clear_raster( rast ); */
356 
357  real_outpos = p[1].y;
358 
359  sizefac = (p[4].y-p[1].y) / (yinlen);
360  delta = (p[2].y - p[1].y) / (xinlen);
361 
362  for ( const_ind = in_hdr.xmin;
364  {
365  interp_row( sizefac, blur, 0, real_outpos,
366  in_hdr.ymax - in_hdr.ymin ,
367  array_lines-1 );
368  real_outpos += delta;
369  }
370 
371  if (! vpassonlyflag )
372  {
373  /* Horizontal pass */
374  pass = H_PASS;
375 
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));
381 
382  /* If we're moving backwards, start at p1 (needs more thought...) */
383  if (delta < 0)
384  real_outpos = p[1].x;
385 
386  i1 = (int) (p[1].y + EPSILON);
387  i2 = (int) (p[2].y + EPSILON);
388  ystart = MIN(i1,i2);
389 
390  i1 = (int) (p[3].y - EPSILON);
391  i2 = (int) (p[4].y - EPSILON);
392  yend = MAX(i1,i2);
393 
394  if (ystart < 0) /* Ensure start isn't negative */
395  {
396  real_outpos += delta * abs(ystart);
397  ystart = 0;
398  }
399 
400  for ( const_ind = ystart; const_ind <= yend; const_ind++ )
401  {
402  interp_row( sizefac, blur, in_hdr.xmin, real_outpos,
403  in_hdr.xmax,
404  out_hdr.xmax );
405  real_outpos += delta;
406  }
407  }
408 }
int xmin
Definition: rle.h:100
int pass
Definition: fant.c:102
#define H_PASS
Definition: fant.c:72
rle_hdr out_hdr
Definition: fant.c:103
int array_lines
Definition: fant.c:106
int vpassonlyflag
Definition: fant.c:110
#define V_PASS
Definition: fant.c:73
int ymin
Definition: rle.h:100
int ystart
Definition: read98721.c:51
static int y
Definition: getami.c:691
int verboseflag
Definition: fant.c:107
int cur_chan
Definition: fant.c:101
#define EPSILON
Definition: fant.c:80
rle_hdr in_hdr
Definition: fant.c:103
#define MIN(x, y)
Definition: fant.c:82
int xmax
Definition: rle.h:100
double y
Definition: fant.c:89
static int x
Definition: getami.c:691
int
Definition: getami.c:848
double x
Definition: fant.c:89
int ymax
Definition: rle.h:100
#define MAX(x, y)
Definition: fant.c:83
int alpha
Definition: rle.h:100
void interp_row()
int const_ind
Definition: fant.c:100
void xform_points ( )
void xform_points ( point p,
double  xscale,
double  yscale,
double  angle,
double  xtrans,
double  ytrans 
)

Definition at line 417 of file fant.c.

420 {
421  double s, c, xoff, yoff;
422  double tmp;
423  int i;
424 
425  /* Sleazy - should build real matrix */
426 
427  c = cos(DEG(angle));
428  s = sin(DEG(angle));
429  if (!originflag)
430  {
431  xoff = ((double) (in_hdr.xmax - in_hdr.xmin + 1) / 2.0
432  + in_hdr.xmin);
433  yoff = ((double) (in_hdr.ymax - in_hdr.ymin + 1) / 2.0
434  + in_hdr.ymin);
435  }
436  else
437  {
438  xoff = X_origin;
439  yoff = Y_origin;
440  }
441  if (verboseflag)
442  fprintf(stderr, "Output rectangle:\n");
443 
444  for ( i = 1; i <= 4; i++ )
445  {
446  p[i].x -= xoff; /* translate to origin */
447  p[i].y -= yoff;
448 
449  tmp = p[i].x * c + p[i].y * s; /* Rotate... */
450  p[i].y = -p[i].x * s + p[i].y * c;
451  p[i].x = tmp;
452 
453  p[i].x *= xscale; /* Scale */
454  p[i].y *= yscale;
455 
456  p[i].x += ( xoff + xtrans ); /* translate back from origin */
457  p[i].y += ( yoff + ytrans );
458 
459  if (verboseflag)
460  fprintf(stderr, " %4.1f\t%4.1f\n", p[i].x, p[i].y);
461  }
462 }
int xmin
Definition: rle.h:100
_urt_stack * s
Definition: rleClock.c:919
#define DEG(x)
Definition: fant.c:79
int Y_origin
Definition: fant.c:109
int ymin
Definition: rle.h:100
int X_origin
Definition: fant.c:109
static int y
Definition: getami.c:691
int verboseflag
Definition: fant.c:107
rle_hdr in_hdr
Definition: fant.c:103
int xmax
Definition: rle.h:100
double y
Definition: fant.c:89
static int x
Definition: getami.c:691
double x
Definition: fant.c:89
int ymax
Definition: rle.h:100
int i
Definition: rletorla.c:82
int originflag
Definition: fant.c:108

Variable Documentation

int array_lines

Definition at line 106 of file fant.c.

int array_width

Definition at line 105 of file fant.c.

rle_pixel* bufin

Definition at line 98 of file fant.c.

int const_ind

Definition at line 100 of file fant.c.

int cur_chan

Definition at line 101 of file fant.c.

rle_hdr in_hdr

Definition at line 103 of file fant.c.

int nchan

Definition at line 104 of file fant.c.

int originflag

Definition at line 108 of file fant.c.

rle_hdr out_hdr

Definition at line 103 of file fant.c.

int outlinewidth

Definition at line 106 of file fant.c.

int pass

Definition at line 102 of file fant.c.

rle_pixel*** rast

Definition at line 97 of file fant.c.

int verboseflag

Definition at line 107 of file fant.c.

int vpassonlyflag

Definition at line 110 of file fant.c.

int X_origin

Definition at line 109 of file fant.c.

int Y_origin

Definition at line 109 of file fant.c.