~ubuntu-branches/ubuntu/jaunty/ghostscript/jaunty-updates

« back to all changes in this revision

Viewing changes to src/gxdda.h

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2009-01-20 16:40:45 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090120164045-lnfhi0n30o5lwhwa
Tags: 8.64.dfsg.1~svn9377-0ubuntu1
* New upstream release (SVN rev 9377)
   o Fixes many bugs concerning PDF rendering, to make the PDF printing
     workflow correctly working.
   o Fixes long-standing bugs in many drivers, like input paper tray and
     duplex options not working for the built-in PCL 4, 5, 5c, 5e, and
     6/XL drivers, PDF input not working for bjc600, bjc800, and cups
     output devices, several options not working and uninitialized
     memory with cups output device.
   o Merged nearly all patches of the Ubuntu and Debian packages upstream.
   o Fixes LP: #317810, LP: #314439, LP: #314018.
* debian/patches/03_libpaper_support.dpatch,
  debian/patches/11_gs-cjk_font_glyph_handling_fix.dpatch,
  debian/patches/12_gs-cjk_vertical_writing_metrics_fix.dpatch,
  debian/patches/13_gs-cjk_cjkps_examples.dpatch,
  debian/patches/20_bbox_segv_fix.dpatch,
  debian/patches/21_brother_7x0_gdi_fix.dpatch,
  debian/patches/22_epsn_margin_workaround.dpatch,
  debian/patches/24_gs_man_fix.dpatch,
  debian/patches/25_toolbin_insecure_tmp_usage_fix.dpatch,
  debian/patches/26_assorted_script_fixes.dpatch,
  debian/patches/29_gs_css_fix.dpatch,
  debian/patches/30_ps2pdf_man_improvement.dpatch,
  debian/patches/31_fix-gc-sigbus.dpatch,
  debian/patches/34_ftbfs-on-hurd-fix.dpatch,
  debian/patches/35_disable_libcairo.dpatch,
  debian/patches/38_pxl-duplex.dpatch,
  debian/patches/39_pxl-resolution.dpatch,
  debian/patches/42_gs-init-ps-delaybind-fix.dpatch,
  debian/patches/45_bjc600-bjc800-pdf-input.dpatch,
  debian/patches/48_cups-output-device-pdf-duplex-uninitialized-memory-fix.dpatch,
  debian/patches/50_lips4-floating-point-exception.dpatch,
  debian/patches/52_cups-device-logging.dpatch,
  debian/patches/55_pcl-input-slot-fix.dpatch,
  debian/patches/57_pxl-input-slot-fix.dpatch,
  debian/patches/60_pxl-cups-driver-pdf.dpatch,
  debian/patches/62_onebitcmyk-pdf.dpatch,
  debian/patches/65_too-big-temp-files-1.dpatch,
  debian/patches/67_too-big-temp-files-2.dpatch,
  debian/patches/70_take-into-account-data-in-stream-buffer-before-refill.dpatch:
  Removed, applied upstream.
* debian/patches/01_docdir_fix_for_debian.dpatch,
  debian/patches/02_gs_man_fix_debian.dpatch,
  debian/patches/01_docdir-fix-for-debian.dpatch,
  debian/patches/02_docdir-fix-for-debian.dpatch: Renamed patches to
  make merging with Debian easier.
* debian/patches/32_improve-handling-of-media-size-changes-from-gv.dpatch, 
  debian/patches/33_bad-params-to-xinitimage-on-large-bitmaps.dpatch:
  regenerated for new source directory structure.
* debian/rules: Corrected paths to remove cidfmap (it is in Resource/Init/
  in GS 8.64) and to install headers (source paths are psi/ and base/ now).
* debian/rules: Remove all fontmaps, as DeFoMa replaces them.
* debian/local/pdftoraster/pdftoraster.c,
  debian/local/pdftoraster/pdftoraster.convs, debian/rules: Removed
  added pdftoraster filter and use the one which comes with Ghostscript.
* debian/ghostscript.links: s/8.63/8.64/

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2001-2006 Artifex Software, Inc.
2
 
   All Rights Reserved.
3
 
  
4
 
   This software is provided AS-IS with no warranty, either express or
5
 
   implied.
6
 
 
7
 
   This software is distributed under license and may not be copied, modified
8
 
   or distributed except as expressly authorized under the terms of that
9
 
   license.  Refer to licensing information at http://www.artifex.com/
10
 
   or contact Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134,
11
 
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12
 
*/
13
 
 
14
 
/* $Id: gxdda.h 8522 2008-02-12 20:30:17Z leonardo $ */
15
 
/* Definitions for DDAs */
16
 
/* Requires gxfixed.h */
17
 
 
18
 
#ifndef gxdda_INCLUDED
19
 
#  define gxdda_INCLUDED
20
 
 
21
 
/*
22
 
 * We use the familiar Bresenham DDA algorithm for several purposes:
23
 
 *      - tracking the edges when filling trapezoids;
24
 
 *      - tracking the current pixel corner coordinates when rasterizing
25
 
 *      skewed or rotated images;
26
 
 *      - converting curves to sequences of lines (this is a 3rd-order
27
 
 *      DDA, the others are 1st-order);
28
 
 *      - perhaps someday for drawing single-pixel lines.
29
 
 * In the case of trapezoids, lines, and curves, we need to use
30
 
 * the DDA to find the integer X values at integer+0.5 values of Y;
31
 
 * in the case of images, we use DDAs to compute the (fixed)
32
 
 * X and Y values at (integer) source pixel corners.
33
 
 *
34
 
 * The purpose of the DDA is to compute the exact values Q(i) = floor(i*D/N)
35
 
 * for increasing integers i, 0 <= i <= N.  D is considered to be an
36
 
 * integer, although it may actually be a fixed.  For the algorithm,
37
 
 * we maintain i*D/N as Q + (N-R)/N where Q and R are integers, 0 < R <= N,
38
 
 * with the following auxiliary values:
39
 
 *      dQ = floor(D/N)
40
 
 *      dR = D mod N (0 <= dR < N)
41
 
 *      NdR = N - dR
42
 
 * Then at each iteration we do:
43
 
 *      Q += dQ;
44
 
 *      if ( R > dR ) R -= dR; else ++Q, R += NdR;
45
 
 * These formulas work regardless of the sign of D, and never let R go
46
 
 * out of range.
47
 
 */
48
 
/* In the following structure definitions, ntype must be an unsigned type. */
49
 
#define dda_state_struct(sname, dtype, ntype)\
50
 
  struct sname { dtype Q; ntype R; }
51
 
#define dda_step_struct(sname, dtype, ntype)\
52
 
  struct sname { dtype dQ; ntype dR, NdR; }
53
 
 
54
 
/* DDA with int Q and uint N */
55
 
typedef struct gx_dda_int_s {
56
 
    dda_state_struct(ia_, int, uint) state;
57
 
    dda_step_struct(ie_, int, uint) step;
58
 
} gx_dda_int_t;
59
 
 
60
 
/* DDA with fixed Q and (unsigned) integer N */
61
 
typedef 
62
 
dda_state_struct(_a, fixed, uint) gx_dda_state_fixed;
63
 
     typedef dda_step_struct(_e, fixed, uint) gx_dda_step_fixed;
64
 
     typedef struct gx_dda_fixed_s {
65
 
         gx_dda_state_fixed state;
66
 
         gx_dda_step_fixed step;
67
 
     } gx_dda_fixed;
68
 
/*
69
 
 * Define a pair of DDAs for iterating along an arbitrary line.
70
 
 */
71
 
     typedef struct gx_dda_fixed_point_s {
72
 
         gx_dda_fixed x, y;
73
 
     } gx_dda_fixed_point;
74
 
/*
75
 
 * Initialize a DDA.  The sign test is needed only because C doesn't
76
 
 * provide reliable definitions of / and % for integers (!!!).
77
 
 */
78
 
#define dda_init_state(dstate, init, N)\
79
 
  (dstate).Q = (init), (dstate).R = (N)
80
 
#define dda_init_step(dstep, D, N)\
81
 
  if ( (N) == 0 )\
82
 
    (dstep).dQ = 0, (dstep).dR = 0;\
83
 
  else if ( (D) < 0 )\
84
 
   { (dstep).dQ = -(int)((uint)-(D) / (N));\
85
 
     if ( ((dstep).dR = -(D) % (N)) != 0 )\
86
 
       --(dstep).dQ, (dstep).dR = (N) - (dstep).dR;\
87
 
   }\
88
 
  else\
89
 
   { (dstep).dQ = (D) / (N); (dstep).dR = (D) % (N); }\
90
 
  (dstep).NdR = (N) - (dstep).dR
91
 
#define dda_init(dda, init, D, N)\
92
 
  dda_init_state((dda).state, init, N);\
93
 
  dda_init_step((dda).step, D, N)
94
 
/*
95
 
 * Compute the sum of two DDA steps with the same D and N.
96
 
 * Note that since dR + NdR = N, this quantity must be the same in both
97
 
 * fromstep and tostep.
98
 
 */
99
 
#define dda_step_add(tostep, fromstep)\
100
 
  (tostep).dQ +=\
101
 
    ((tostep).dR < (fromstep).NdR ?\
102
 
     ((tostep).dR += (fromstep).dR, (tostep).NdR -= (fromstep).dR,\
103
 
      (fromstep).dQ) :\
104
 
     ((tostep).dR -= (fromstep).NdR, (tostep).NdR += (fromstep).NdR,\
105
 
      (fromstep).dQ + 1))
106
 
/*
107
 
 * Return the current value in a DDA.
108
 
 */
109
 
#define dda_state_current(dstate) (dstate).Q
110
 
#define dda_current(dda) dda_state_current((dda).state)
111
 
#define dda_current_fixed2int(dda)\
112
 
  fixed2int_var(dda_state_current((dda).state))
113
 
/*
114
 
 * Increment a DDA to the next point.
115
 
 * Returns the updated current value.
116
 
 */
117
 
#define dda_state_next(dstate, dstep)\
118
 
  (dstate).Q +=\
119
 
    ((dstate).R > (dstep).dR ?\
120
 
     ((dstate).R -= (dstep).dR, (dstep).dQ) :\
121
 
     ((dstate).R += (dstep).NdR, (dstep).dQ + 1))
122
 
#define dda_next(dda) dda_state_next((dda).state, (dda).step)
123
 
/*
124
 
 * Back up a DDA to the previous point.
125
 
 * Returns the updated current value.
126
 
 */
127
 
#define dda_state_previous(dstate, dstep)\
128
 
  (dstate).Q -=\
129
 
    ((dstate).R <= (dstep).NdR ?\
130
 
     ((dstate).R += (dstep).dR, (dstep).dQ) :\
131
 
     ((dstate).R -= (dstep).NdR, (dstep).dQ + 1))
132
 
#define dda_previous(dda) dda_state_previous((dda).state, (dda).step)
133
 
/*
134
 
 * Advance a DDA by an arbitrary number of steps.
135
 
 * This implementation is very inefficient; we'll improve it if needed.
136
 
 */
137
 
#define dda_state_advance(dstate, dstep, nsteps)\
138
 
  BEGIN\
139
 
    uint n_ = (nsteps);\
140
 
    (dstate).Q += (dstep).dQ * (nsteps);\
141
 
    while ( n_-- )\
142
 
      if ( (dstate).R > (dstep).dR ) (dstate).R -= (dstep).dR;\
143
 
      else (dstate).R += (dstep).NdR, (dstate).Q++;\
144
 
  END
145
 
#define dda_advance(dda, nsteps)\
146
 
  dda_state_advance((dda).state, (dda).step, nsteps)
147
 
/*
148
 
 * Translate the position of a DDA by a given amount.
149
 
 */
150
 
#define dda_state_translate(dstate, delta)\
151
 
  ((dstate).Q += (delta))
152
 
#define dda_translate(dda, delta)\
153
 
  dda_state_translate((dda).state, delta)
154
 
  
155
 
#endif /* gxdda_INCLUDED */