version 2.8
zline.h
1 {
2  int n, dx, dy, sx, pp_inc_1, pp_inc_2;
3  register int a;
4  register PIXEL *pp;
5 #if defined(INTERP_RGB) || TGL_FEATURE_RENDER_BITS == 24
6  register unsigned int r, g, b;
7 #endif
8 #ifdef INTERP_RGB
9  register unsigned int rinc, ginc, binc;
10 #endif
11 #ifdef INTERP_Z
12  register unsigned short *pz;
13  int zinc;
14  register int z, zz;
15 #endif
16 
17  if (p1->y > p2->y || (p1->y == p2->y && p1->x > p2->x)) {
18  ZBufferPoint *tmp;
19  tmp = p1;
20  p1 = p2;
21  p2 = tmp;
22  }
23  sx = zb->xsize;
24  pp = (PIXEL *) ((char *) zb->pbuf + zb->linesize * p1->y + p1->x * PSZB);
25 #ifdef INTERP_Z
26  pz = zb->zbuf + (p1->y * sx + p1->x);
27  z = p1->z;
28 #endif
29 
30  dx = p2->x - p1->x;
31  dy = p2->y - p1->y;
32 #ifdef INTERP_RGB
33  r = p2->r << 8;
34  g = p2->g << 8;
35  b = p2->b << 8;
36 #elif TGL_FEATURE_RENDER_BITS == 24
37  /* for 24 bits, we store the colors in different variables */
38  r = p2->r >> 8;
39  g = p2->g >> 8;
40  b = p2->b >> 8;
41 #endif
42 
43 #undef RGB
44 #ifdef INTERP_RGB
45 #define RGB(x) x
46 #if TGL_FEATURE_RENDER_BITS == 24
47 #define RGBPIXEL pp[0] = r >> 16, pp[1] = g >> 16, pp[2] = b >> 16
48 #else
49 #define RGBPIXEL *pp = RGB_TO_PIXEL(r >> 8,g >> 8,b >> 8)
50 #endif
51 #else /* INTERP_RGB */
52 #define RGB(x)
53 #if TGL_FEATURE_RENDER_BITS == 24
54 #define RGBPIXEL pp[0] = r, pp[1] = g, pp[2] = b
55 #else
56 #define RGBPIXEL *pp = color
57 #endif
58 #endif /* INTERP_RGB */
59 
60 #ifdef INTERP_Z
61 #define ZZ(x) x
62 #define PUTPIXEL() \
63  { \
64  zz=z >> ZB_POINT_Z_FRAC_BITS; \
65  if (ZCMP(zz,*pz)) { \
66  RGBPIXEL; \
67  *pz=zz; \
68  } \
69  }
70 #else /* INTERP_Z */
71 #define ZZ(x)
72 #define PUTPIXEL() RGBPIXEL
73 #endif /* INTERP_Z */
74 
75 #define DRAWLINE(dx,dy,inc_1,inc_2) \
76  n=dx;\
77  ZZ(zinc=(p2->z-p1->z)/n);\
78  RGB(rinc=((p2->r-p1->r) << 8)/n;\
79  ginc=((p2->g-p1->g) << 8)/n;\
80  binc=((p2->b-p1->b) << 8)/n);\
81  a=2*dy-dx;\
82  dy=2*dy;\
83  dx=2*dx-dy;\
84  pp_inc_1 = (inc_1) * PSZB;\
85  pp_inc_2 = (inc_2) * PSZB;\
86  do {\
87  PUTPIXEL();\
88  ZZ(z+=zinc);\
89  RGB(r+=rinc;g+=ginc;b+=binc);\
90  if (a>0) { pp=(PIXEL *)((char *)pp + pp_inc_1); ZZ(pz+=(inc_1)); a-=dx; }\
91  else { pp=(PIXEL *)((char *)pp + pp_inc_2); ZZ(pz+=(inc_2)); a+=dy; }\
92  } while (--n >= 0);
93 
94 /* fin macro */
95 
96  if (dx == 0 && dy == 0) {
97  PUTPIXEL();
98  } else if (dx > 0) {
99  if (dx >= dy) {
100  DRAWLINE(dx, dy, sx + 1, 1);
101  } else {
102  DRAWLINE(dy, dx, sx + 1, sx);
103  }
104  } else {
105  dx = -dx;
106  if (dx >= dy) {
107  DRAWLINE(dx, dy, sx - 1, -1);
108  } else {
109  DRAWLINE(dy, dx, sx - 1, sx);
110  }
111  }
112 }
113 
114 #undef INTERP_Z
115 #undef INTERP_RGB
116 
117 /* internal defines */
118 #undef DRAWLINE
119 #undef PUTPIXEL
120 #undef ZZ
121 #undef RGB
122 #undef RGBPIXEL