19 #define PIXEL_STRIDE 3
27 static float fpart(
float x)
29 return (x - (
float)floor(x));
33 static void PlotPixel(uint32_t *Image,
int Width,
int Height,
int x,
int y,
34 float Alpha,
const float *Color)
36 if(0 <= x && x < Width && 0 <= y && y < Height)
38 const float CAlpha = 1 - Alpha;
41 ((uint8_t *)Image)[0] = (uint8_t)(
42 CAlpha*((uint8_t *)Image)[0] + Alpha*Color[0] + 0.5f);
43 ((uint8_t *)Image)[1] = (uint8_t)(
44 CAlpha*((uint8_t *)Image)[1] + Alpha*Color[1] + 0.5f);
45 ((uint8_t *)Image)[2] = (uint8_t)(
46 CAlpha*((uint8_t *)Image)[2] + Alpha*Color[2] + 0.5f);
59 void DrawLine(uint32_t *Image,
int Width,
int Height,
60 float x1,
float y1,
float x2,
float y2,
const float *Color)
62 float yend, Gap, dx, dy, Gradient, y, Temp;
63 int xend, ix, iy, ix1, iy1, ix2, iy2, Swapped = 0;
69 if(fabs(dx) < fabs(dy))
88 xend = (int)floor(x1 + 0.5f);
89 yend = y1 + Gradient * (xend - x1);
91 Gap = 1 - fpart(x1 + 0.5f);
93 iy1 = (int)floor(yend);
97 PlotPixel(Image, Width, Height, ix1, iy1, (1 - fpart(yend)) * Gap, Color);
98 PlotPixel(Image, Width, Height, ix1, iy1 + 1, fpart(yend) * Gap, Color);
102 PlotPixel(Image, Width, Height, iy1, ix1, (1 - fpart(yend)) * Gap, Color);
103 PlotPixel(Image, Width, Height, iy1 + 1, ix1, fpart(yend) * Gap, Color);
106 xend = (int)floor(x2 + 0.5f);
107 yend = y2 + Gradient * (xend - x2);
108 Gap = fpart(x2 + 0.5f);
110 iy2 = (int)floor(yend);
114 PlotPixel(Image, Width, Height, ix2, iy2, (1 - fpart(yend)) * Gap, Color);
115 PlotPixel(Image, Width, Height, ix2, iy2 + 1, fpart(yend) * Gap, Color);
117 for(ix = ix1 + 1; ix < ix2; ix++)
120 PlotPixel(Image, Width, Height, ix, iy, 1 - fpart(y), Color);
121 PlotPixel(Image, Width, Height, ix, iy + 1, fpart(y), Color);
127 PlotPixel(Image, Width, Height, iy2, ix2, (1 - fpart(yend)) * Gap, Color);
128 PlotPixel(Image, Width, Height, iy2 + 1, ix2, fpart(yend) * Gap, Color);
130 for(ix = ix1 + 1; ix < ix2; ix++)
133 PlotPixel(Image, Width, Height, iy, ix, 1 - fpart(y), Color);
134 PlotPixel(Image, Width, Height, iy + 1, ix, fpart(y), Color);