Graphics-Framebuffer
view release on metacpan or search on metacpan
lib/Graphics/Framebuffer.pm view on Meta::CPAN
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 which blends
* the endpoints and adjacent pixels using coverage (alpha) values.
* Otherwise fallback to the previous integer-based Bresenham-like routine.
* */
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);
lib/Graphics/Framebuffer.pm view on Meta::CPAN
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);
lib/Graphics/Framebuffer.pm view on Meta::CPAN
($x0, $x1, $y0, $y1) = ($x1, $x0, $y1, $y0);
}
my $dx = $x1 - $x0;
my $dy = $y1 - $y0;
my $gradient = $dy / $dx;
my @xends;
my $intery;
# handle the endpoints
foreach my $xy ([$x0, $y0], [$x1, $y1]) {
my ($x, $y) = @{$xy};
my $xend = int($x + 0.5); # POSIX::lround($x);
my $yend = $y + $gradient * ($xend - $x);
my $xgap = _rfpart($x + 0.5);
my $x_pixel = $xend;
my $y_pixel = int($yend);
push(@xends, $x_pixel);
src/Framebuffer.c view on Meta::CPAN
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 which blends
* the endpoints and adjacent pixels using coverage (alpha) values.
* Otherwise fallback to the previous integer-based Bresenham-like routine.
* */
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);
src/Framebuffer.c view on Meta::CPAN
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);
src/Framebuffer.pm view on Meta::CPAN
($x0, $x1, $y0, $y1) = ($x1, $x0, $y1, $y0);
}
my $dx = $x1 - $x0;
my $dy = $y1 - $y0;
my $gradient = $dy / $dx;
my @xends;
my $intery;
# handle the endpoints
foreach my $xy ([$x0, $y0], [$x1, $y1]) {
my ($x, $y) = @{$xy};
my $xend = int($x + 0.5); # POSIX::lround($x);
my $yend = $y + $gradient * ($xend - $x);
my $xgap = _rfpart($x + 0.5);
my $x_pixel = $xend;
my $y_pixel = int($yend);
push(@xends, $x_pixel);
( run in 0.250 second using v1.01-cache-2.11-cpan-0ffa90cfd1c )