home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / sharewar / dos / program / gs300sr1 / gs300sr1.exe / GXDDA.H < prev    next >
Text File  |  1994-07-27  |  2KB  |  56 lines

  1. /* Copyright (C) 1994 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* gxdda.h */
  20. /* DDA definitions for Ghostscript line drawing */
  21. /* Requires gxfixed.h */
  22.  
  23. /*
  24.  * We use the familiar Bresenham DDA algorithm for several purposes:
  25.  *    - tracking the edges when filling trapezoids;
  26.  *    - tracking the current pixel corner coordinates when rasterizing
  27.  *    skewed or rotated images;
  28.  *    - converting curves to sequences of lines (this is a 3rd-order
  29.  *    DDA, the others are 1st-order);
  30.  *    - perhaps someday for drawing single-pixel lines.
  31.  * In the case of trapezoids, lines, and curves, we need to use
  32.  * the DDA to find the integer X values at integer+0.5 values of Y;
  33.  * in the case of images, we use the DDA to compute both the (fixed)
  34.  * X and Y values at (integer) source pixel corners.
  35.  */
  36. typedef struct gx_dda_int_s {
  37.     int current, dq;
  38.     fixed r, dr, max_r;
  39. } gx_dda_int;
  40. typedef struct gx_dda_fixed_s {
  41.     fixed current, dq;
  42.     uint r, dr, max_r;
  43. } gx_dda_fixed;
  44. #define dda_fixed_init(dda, v, d, n)\
  45.   (dda).current = (v);\
  46.   if ( (d) < 0 )\
  47.  
  48. /*
  49.  * The incrementing algorithm is the same in all cases.
  50.  * Note that this requires some adjustment if the difference is negative.
  51.  */
  52. #define dda_next(dda)\
  53.   (dda).current +=\
  54.     (((dda).r += (dda).dr) > (dda).max_r ?\
  55.      ((dda).r -= (dda).dr, (dda).dq + 1) : (dda).dq)
  56.