00001 {
00002 int n, dx, dy, sx, pp_inc_1, pp_inc_2;
00003 register int a;
00004 register PIXEL *pp;
00005 #if defined(INTERP_RGB)
00006 register unsigned int r, g, b;
00007 #endif
00008 #ifdef INTERP_RGB
00009 register unsigned int rinc, ginc, binc;
00010 #endif
00011 #ifdef INTERP_Z
00012 register ZPOINT *pz;
00013 int zinc;
00014 register int z, zz;
00015 #endif
00016
00017 if (p1->y > p2->y || (p1->y == p2->y && p1->x > p2->x)) {
00018 ZBufferPoint *tmp;
00019 tmp = p1;
00020 p1 = p2;
00021 p2 = tmp;
00022 }
00023 sx = zb->xsize;
00024 pp = (PIXEL *) ((char *) zb->pbuf + zb->linesize * p1->y + p1->x * PSZB);
00025 #ifdef INTERP_Z
00026 pz = zb->zbuf + (p1->y * sx + p1->x);
00027 z = p1->z;
00028 #endif
00029
00030 dx = p2->x - p1->x;
00031 dy = p2->y - p1->y;
00032 #ifdef INTERP_RGB
00033 r = p2->r << 8;
00034 g = p2->g << 8;
00035 b = p2->b << 8;
00036 #endif
00037
00038 #ifdef INTERP_RGB
00039 #define RGB(x) x
00040 #define RGBPIXEL *pp = RGB_TO_PIXEL(r >> 8,g >> 8,b >> 8)
00041 #else
00042 #define RGB(x)
00043 #define RGBPIXEL *pp = color
00044 #endif
00045
00046 #ifdef INTERP_Z
00047 #define ZZ(x) x
00048 #define PUTPIXEL() \
00049 { \
00050 zz=z >> ZB_POINT_Z_FRAC_BITS; \
00051 if (ZCMP(zz,*pz)) { \
00052 RGBPIXEL; \
00053 *pz=zz; \
00054 } \
00055 }
00056 #else
00057 #define ZZ(x)
00058 #define PUTPIXEL() RGBPIXEL
00059 #endif
00060
00061 #define DRAWLINE(dx,dy,inc_1,inc_2) \
00062 n=dx;\
00063 ZZ(zinc=(p2->z-p1->z)/n);\
00064 RGB(rinc=((p2->r-p1->r) << 8)/n;\
00065 ginc=((p2->g-p1->g) << 8)/n;\
00066 binc=((p2->b-p1->b) << 8)/n);\
00067 a=2*dy-dx;\
00068 dy=2*dy;\
00069 dx=2*dx-dy;\
00070 pp_inc_1 = (inc_1) * PSZB;\
00071 pp_inc_2 = (inc_2) * PSZB;\
00072 do {\
00073 PUTPIXEL();\
00074 ZZ(z+=zinc);\
00075 RGB(r+=rinc;g+=ginc;b+=binc);\
00076 if (a>0) { pp=(PIXEL *)((char *)pp + pp_inc_1); ZZ(pz+=(inc_1)); a-=dx; }\
00077 else { pp=(PIXEL *)((char *)pp + pp_inc_2); ZZ(pz+=(inc_2)); a+=dy; }\
00078 } while (--n >= 0);
00079
00080
00081
00082 if (dx == 0 && dy == 0) {
00083 PUTPIXEL();
00084 } else if (dx > 0) {
00085 if (dx >= dy) {
00086 DRAWLINE(dx, dy, sx + 1, 1);
00087 } else {
00088 DRAWLINE(dy, dx, sx + 1, sx);
00089 }
00090 } else {
00091 dx = -dx;
00092 if (dx >= dy) {
00093 DRAWLINE(dx, dy, sx - 1, -1);
00094 } else {
00095 DRAWLINE(dy, dx, sx - 1, sx);
00096 }
00097 }
00098 }
00099
00100 #undef INTERP_Z
00101 #undef INTERP_RGB
00102
00103
00104 #undef DRAWLINE
00105 #undef PUTPIXEL
00106 #undef ZZ
00107 #undef RGB
00108 #undef RGBPIXEL