Graphics-Framebuffer
view release on metacpan or search on metacpan
src/Framebuffer.c view on Meta::CPAN
if (col8 != 0) res8 = fb / col8;
break;
default:
break;
}
*p = res8;
} break;
case 1: {
/* Not supported yet; no-op */
} break;
default:
break;
}
}
/* Draws a line */
void c_line(char *framebuffer,
short x1,
short y1,
short x2,
short y2,
short x_clip,
short y_clip,
short xx_clip,
short yy_clip,
unsigned int color,
unsigned int bcolor,
unsigned char alpha,
unsigned char draw_mode,
unsigned char bytes_per_pixel,
unsigned char bits_per_pixel,
unsigned int bytes_per_line,
short xoffset,
short yoffset,
bool antialiased) {
/* If antialiasing is requested, use Xiaolin Wu's algorithm... */
if (antialiased) {
double x0 = (double)x1;
double y0 = (double)y1;
double x1d = (double)x2;
double y1d = (double)y2;
int steep = fabs(y1d - y0) > fabs(x1d - x0);
if (steep) {
swap_(x0, y0);
swap_(x1d, y1d);
}
if (x0 > x1d) {
swap_(x0, x1d);
swap_(y0, y1d);
}
double dx = x1d - x0;
double dy = y1d - y0;
double gradient = (dx == 0.0) ? 1.0 : dy / dx;
/* handle first endpoint */
double xend = roundd(x0);
double yend = y0 + gradient * (xend - x0);
double xgap = rfpart(x0 + 0.5);
long xpxl1 = (long)xend;
long ypxl1 = (long)floor(yend);
/* plot first endpoint */
double intery = yend + gradient; /* first y-intersection for the main loop */
/* First endpoint pixels */
plot_aa_pixel(framebuffer,
color,
bcolor,
alpha,
bytes_per_pixel,
bits_per_pixel,
bytes_per_line,
x_clip,
y_clip,
xx_clip,
yy_clip,
xoffset,
yoffset,
steep,
xpxl1,
ypxl1,
rfpart(yend) * xgap);
plot_aa_pixel(framebuffer,
color,
bcolor,
alpha,
bytes_per_pixel,
bits_per_pixel,
bytes_per_line,
x_clip,
y_clip,
xx_clip,
yy_clip,
xoffset,
yoffset,
steep,
xpxl1,
ypxl1 + 1,
fpart(yend) * xgap);
/* handle second endpoint */
xend = roundd(x1d);
yend = y1d + gradient * (xend - x1d);
xgap = fpart(x1d + 0.5);
long xpxl2 = (long)xend;
long ypxl2 = (long)floor(yend);
plot_aa_pixel(framebuffer,
color,
bcolor,
alpha,
bytes_per_pixel,
bits_per_pixel,
bytes_per_line,
x_clip,
y_clip,
xx_clip,
yy_clip,
xoffset,
yoffset,
steep,
xpxl2,
ypxl2,
rfpart(yend) * xgap);
plot_aa_pixel(framebuffer,
color,
bcolor,
alpha,
bytes_per_pixel,
bits_per_pixel,
bytes_per_line,
x_clip,
y_clip,
xx_clip,
yy_clip,
xoffset,
yoffset,
steep,
xpxl2,
ypxl2 + 1,
fpart(yend) * xgap);
/* main loop */
long x;
if (xpxl1 + 1 <= xpxl2 - 1) {
for (x = xpxl1 + 1; x <= xpxl2 - 1; x++) {
double iy = intery;
long yint = (long)floor(iy);
plot_aa_pixel(framebuffer,
color,
bcolor,
alpha,
bytes_per_pixel,
bits_per_pixel,
bytes_per_line,
x_clip,
y_clip,
xx_clip,
yy_clip,
xoffset,
yoffset,
( run in 0.892 second using v1.01-cache-2.11-cpan-524268b4103 )