mirror of
https://github.com/php/php-src.git
synced 2025-08-18 23:18:56 +02:00
Add gdImageAAline (antialiased line)
Add AA support for gdImagePolygon
This commit is contained in:
parent
221413e5ef
commit
7ec74f64f9
1 changed files with 156 additions and 16 deletions
|
@ -1037,6 +1037,134 @@ gdImageLine (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define BLEND_COLOR(a, nc, c, cc) \
|
||||||
|
nc = (cc) + (((((c) - (cc)) * (a)) + ((((c) - (cc)) * (a)) >> 8) + 0x80) >> 8);
|
||||||
|
|
||||||
|
inline static void gdImageSetAAPixelColor(gdImagePtr im, int x, int y, int color, int t)
|
||||||
|
{
|
||||||
|
int dr,dg,db,p,r,g,b;
|
||||||
|
dr = gdTrueColorGetRed(color);
|
||||||
|
dg = gdTrueColorGetGreen(color);
|
||||||
|
db = gdTrueColorGetBlue(color);
|
||||||
|
|
||||||
|
p = gdImageGetPixel(im,x,y);
|
||||||
|
r = gdTrueColorGetRed(p);
|
||||||
|
g = gdTrueColorGetGreen(p);
|
||||||
|
b = gdTrueColorGetBlue(p);
|
||||||
|
|
||||||
|
BLEND_COLOR(t, dr, r, dr);
|
||||||
|
BLEND_COLOR(t, dg, g, dg);
|
||||||
|
BLEND_COLOR(t, db, b, db);
|
||||||
|
im->tpixels[y][x]=gdTrueColorAlpha(dr, dg, db, gdAlphaOpaque);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gdImageAALine (gdImagePtr im, int x1, int y1, int x2, int y2, int col)
|
||||||
|
{
|
||||||
|
/* keep them as 32bits */
|
||||||
|
long x, y, inc;
|
||||||
|
long dx, dy,tmp;
|
||||||
|
|
||||||
|
if (y1 < 0 && y2 < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (y1 < 0) {
|
||||||
|
x1 += (y1 * (x1 - x2)) / (y2 - y1);
|
||||||
|
y1 = 0;
|
||||||
|
}
|
||||||
|
if (y2 < 0) {
|
||||||
|
x2 += (y2 * (x1 - x2)) / (y2 - y1);
|
||||||
|
y2 = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* bottom edge */
|
||||||
|
if (y1 >= im->sy && y2 >= im->sy) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (y1 >= im->sy) {
|
||||||
|
x1 -= ((im->sy - y1) * (x1 - x2)) / (y2 - y1);
|
||||||
|
y1 = im->sy - 1;
|
||||||
|
}
|
||||||
|
if (y2 >= im->sy) {
|
||||||
|
x2 -= ((im->sy - y2) * (x1 - x2)) / (y2 - y1);
|
||||||
|
y2 = im->sy - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* left edge */
|
||||||
|
if (x1 < 0 && x2 < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (x1 < 0) {
|
||||||
|
y1 += (x1 * (y1 - y2)) / (x2 - x1);
|
||||||
|
x1 = 0;
|
||||||
|
}
|
||||||
|
if (x2 < 0) {
|
||||||
|
y2 += (x2 * (y1 - y2)) / (x2 - x1);
|
||||||
|
x2 = 0;
|
||||||
|
}
|
||||||
|
/* right edge */
|
||||||
|
if (x1 >= im->sx && x2 >= im->sx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (x1 >= im->sx) {
|
||||||
|
y1 -= ((im->sx - x1) * (y1 - y2)) / (x2 - x1);
|
||||||
|
x1 = im->sx - 1;
|
||||||
|
}
|
||||||
|
if (x2 >= im->sx) {
|
||||||
|
y2 -= ((im->sx - x2) * (y1 - y2)) / (x2 - x1);
|
||||||
|
x2 = im->sx - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dx = x2 - x1;
|
||||||
|
dy = y2 - y1;
|
||||||
|
|
||||||
|
if (dx == 0 && dy == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (abs(dx) > abs(dy)) {
|
||||||
|
if (dx < 0) {
|
||||||
|
tmp = x1;
|
||||||
|
x1 = x2;
|
||||||
|
x2 = tmp;
|
||||||
|
tmp = y1;
|
||||||
|
y1 = y2;
|
||||||
|
y2 = tmp;
|
||||||
|
dx = x2 - x1;
|
||||||
|
dy = y2 - y1;
|
||||||
|
}
|
||||||
|
x = x1 << 16;
|
||||||
|
y = y1 << 16;
|
||||||
|
inc = (dy * 65536) / dx;
|
||||||
|
while ((x >> 16) < x2) {
|
||||||
|
gdImageSetAAPixelColor(im, x >> 16, y >> 16, col, (y >> 8) & 0xFF);
|
||||||
|
gdImageSetAAPixelColor(im, x >> 16, (y >> 16) + 1,col, (~y >> 8) & 0xFF);
|
||||||
|
x += (1 << 16);
|
||||||
|
y += inc;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (dy < 0) {
|
||||||
|
tmp = x1;
|
||||||
|
x1 = x2;
|
||||||
|
x2 = tmp;
|
||||||
|
tmp = y1;
|
||||||
|
y1 = y2;
|
||||||
|
y2 = tmp;
|
||||||
|
dx = x2 - x1;
|
||||||
|
dy = y2 - y1;
|
||||||
|
}
|
||||||
|
x = x1 << 16;
|
||||||
|
y = y1 << 16;
|
||||||
|
inc = (dx * 65536) / dy;
|
||||||
|
while ((y>>16) < y2) {
|
||||||
|
gdImageSetAAPixelColor(im, x >> 16, y >> 16, col, (x >> 8) & 0xFF);
|
||||||
|
gdImageSetAAPixelColor(im, (x >> 16) + 1, (y >> 16),col, (~x >> 8) & 0xFF);
|
||||||
|
x += inc;
|
||||||
|
y += (1<<16);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void dashedSet (gdImagePtr im, int x, int y, int color,
|
static void dashedSet (gdImagePtr im, int x, int y, int color,
|
||||||
int *onP, int *dashStepP, int wid, int vert);
|
int *onP, int *dashStepP, int wid, int vert);
|
||||||
|
|
||||||
|
@ -2778,17 +2906,23 @@ gdImagePolygon (gdImagePtr im, gdPointPtr p, int n, int c)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int lx, ly;
|
int lx, ly;
|
||||||
if (!n)
|
typedef void (*image_line)(gdImagePtr im, int x1, int y1, int x2, int y2, int color);
|
||||||
{
|
image_line draw_line;
|
||||||
|
|
||||||
|
if (!n) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if ( im->antialias) {
|
||||||
|
draw_line = gdImageAALine;
|
||||||
|
} else {
|
||||||
|
draw_line = gdImageLine;
|
||||||
|
}
|
||||||
lx = p->x;
|
lx = p->x;
|
||||||
ly = p->y;
|
ly = p->y;
|
||||||
gdImageLine (im, lx, ly, p[n - 1].x, p[n - 1].y, c);
|
draw_line(im, lx, ly, p[n - 1].x, p[n - 1].y, c);
|
||||||
for (i = 1; (i < n); i++)
|
for (i = 1; (i < n); i++) {
|
||||||
{
|
|
||||||
p++;
|
p++;
|
||||||
gdImageLine (im, lx, ly, p->x, p->y, c);
|
draw_line(im, lx, ly, p->x, p->y, c);
|
||||||
lx = p->x;
|
lx = p->x;
|
||||||
ly = p->y;
|
ly = p->y;
|
||||||
}
|
}
|
||||||
|
@ -3082,6 +3216,12 @@ gdImageAlphaBlending (gdImagePtr im, int alphaBlendingArg)
|
||||||
im->alphaBlendingFlag = alphaBlendingArg;
|
im->alphaBlendingFlag = alphaBlendingArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gdImageAntialias (gdImagePtr im, int antialias)
|
||||||
|
{
|
||||||
|
im->antialias = antialias;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gdImageSaveAlpha (gdImagePtr im, int saveAlphaArg)
|
gdImageSaveAlpha (gdImagePtr im, int saveAlphaArg)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue