imlib_image_draw_ellipse()

Check test/imlib2 for example. Clipped too.

TODO: Not antialiased. yet. point drawing needs to be inlined, or something.


SVN revision: 3287
This commit is contained in:
Tom Gilbert 2000-08-31 22:49:06 +00:00
parent 1250f13969
commit 0794fb0f14
5 changed files with 783 additions and 484 deletions

View File

@ -251,6 +251,10 @@ void imlib_polygon_add_point(ImlibPolygon poly, int x, int y);
void imlib_image_draw_polygon(ImlibPolygon poly); void imlib_image_draw_polygon(ImlibPolygon poly);
void imlib_polygon_get_bounds(ImlibPolygon poly, int *px1, int *py1, int *px2, int *py2); void imlib_polygon_get_bounds(ImlibPolygon poly, int *px1, int *py1, int *px2, int *py2);
/* ellipses */
void
imlib_image_draw_ellipse(int xc, int yc, int a, int b);
Imlib_Color_Range imlib_create_color_range(void); Imlib_Color_Range imlib_create_color_range(void);
void imlib_free_color_range(void); void imlib_free_color_range(void);
void imlib_add_color_to_color_range(int distance_away); void imlib_add_color_to_color_range(int distance_away);

832
src/api.c

File diff suppressed because it is too large Load Diff

View File

@ -9,11 +9,14 @@
#include "updates.h" #include "updates.h"
#include "rgbadraw.h" #include "rgbadraw.h"
#define XY_IN_RECT(x, y, rx, ry, rw, rh) \
(((x) >= (rx)) && ((y) >= (ry)) && ((x) <= ((rx) + (rw))) && ((y) <= ((ry) + (rh))))
void void
__imlib_FlipImageHoriz(ImlibImage * im) __imlib_FlipImageHoriz(ImlibImage * im)
{ {
DATA32 *p1, *p2, tmp; DATA32 *p1, *p2, tmp;
int x, y; int x, y;
for (y = 0; y < im->h; y++) for (y = 0; y < im->h; y++)
{ {
@ -36,8 +39,8 @@ __imlib_FlipImageHoriz(ImlibImage * im)
void void
__imlib_FlipImageVert(ImlibImage * im) __imlib_FlipImageVert(ImlibImage * im)
{ {
DATA32 *p1, *p2, tmp; DATA32 *p1, *p2, tmp;
int x, y; int x, y;
for (y = 0; y < (im->h >> 1); y++) for (y = 0; y < (im->h >> 1); y++)
{ {
@ -60,8 +63,8 @@ __imlib_FlipImageVert(ImlibImage * im)
void void
__imlib_FlipImageBoth(ImlibImage * im) __imlib_FlipImageBoth(ImlibImage * im)
{ {
DATA32 *p1, *p2, tmp; DATA32 *p1, *p2, tmp;
int x; int x;
p1 = im->data; p1 = im->data;
p2 = im->data + (im->h * im->w) - 1; p2 = im->data + (im->h * im->w) - 1;
@ -90,8 +93,8 @@ __imlib_FlipImageBoth(ImlibImage * im)
void void
__imlib_FlipImageDiagonal(ImlibImage * im, int direction) __imlib_FlipImageDiagonal(ImlibImage * im, int direction)
{ {
DATA32 *data, *to, *from; DATA32 *data, *to, *from;
int x, y, w, hw, tmp; int x, y, w, hw, tmp;
data = malloc(im->w * im->h * sizeof(DATA32)); data = malloc(im->w * im->h * sizeof(DATA32));
from = im->data; from = im->data;
@ -161,10 +164,10 @@ __imlib_FlipImageDiagonal(ImlibImage * im, int direction)
void void
__imlib_BlurImage(ImlibImage * im, int rad) __imlib_BlurImage(ImlibImage * im, int rad)
{ {
DATA32 *p1, *p2, *data; DATA32 *p1, *p2, *data;
int x, y, mx, my, mw, mh, mt, xx, yy; int x, y, mx, my, mw, mh, mt, xx, yy;
int a, r, g, b; int a, r, g, b;
int *as, *rs, *gs, *bs; int *as, *rs, *gs, *bs;
if (rad < 1) if (rad < 1)
return; return;
@ -252,8 +255,8 @@ __imlib_BlurImage(ImlibImage * im, int rad)
void void
__imlib_SharpenImage(ImlibImage * im, int rad) __imlib_SharpenImage(ImlibImage * im, int rad)
{ {
DATA32 *data, *p1, *p2; DATA32 *data, *p1, *p2;
int a, r, g, b, x, y; int a, r, g, b, x, y;
/* FIXME: impliment */ /* FIXME: impliment */
@ -262,7 +265,7 @@ __imlib_SharpenImage(ImlibImage * im, int rad)
return; return;
else else
{ {
int mul, mul2, tot; int mul, mul2, tot;
mul = (rad * 4) + 1; mul = (rad * 4) + 1;
mul2 = rad; mul2 = rad;
@ -273,26 +276,26 @@ __imlib_SharpenImage(ImlibImage * im, int rad)
p2 = data + 1 + (y * im->w); p2 = data + 1 + (y * im->w);
for (x = 1; x < (im->w - 1); x++) for (x = 1; x < (im->w - 1); x++)
{ {
b = (int)((p1[0]) & 0xff) * 5; b = (int) ((p1[0]) & 0xff) * 5;
g = (int)((p1[0] >> 8) & 0xff) * 5; g = (int) ((p1[0] >> 8) & 0xff) * 5;
r = (int)((p1[0] >> 16) & 0xff) * 5; r = (int) ((p1[0] >> 16) & 0xff) * 5;
a = (int)((p1[0] >> 24) & 0xff) * 5; a = (int) ((p1[0] >> 24) & 0xff) * 5;
b -= (int)((p1[-1]) & 0xff); b -= (int) ((p1[-1]) & 0xff);
g -= (int)((p1[-1] >> 8) & 0xff); g -= (int) ((p1[-1] >> 8) & 0xff);
r -= (int)((p1[-1] >> 16) & 0xff); r -= (int) ((p1[-1] >> 16) & 0xff);
a -= (int)((p1[-1] >> 24) & 0xff); a -= (int) ((p1[-1] >> 24) & 0xff);
b -= (int)((p1[1]) & 0xff); b -= (int) ((p1[1]) & 0xff);
g -= (int)((p1[1] >> 8) & 0xff); g -= (int) ((p1[1] >> 8) & 0xff);
r -= (int)((p1[1] >> 16) & 0xff); r -= (int) ((p1[1] >> 16) & 0xff);
a -= (int)((p1[1] >> 24) & 0xff); a -= (int) ((p1[1] >> 24) & 0xff);
b -= (int)((p1[-im->w]) & 0xff); b -= (int) ((p1[-im->w]) & 0xff);
g -= (int)((p1[-im->w] >> 8) & 0xff); g -= (int) ((p1[-im->w] >> 8) & 0xff);
r -= (int)((p1[-im->w] >> 16) & 0xff); r -= (int) ((p1[-im->w] >> 16) & 0xff);
a -= (int)((p1[-im->w] >> 24) & 0xff); a -= (int) ((p1[-im->w] >> 24) & 0xff);
b -= (int)((p1[im->w]) & 0xff); b -= (int) ((p1[im->w]) & 0xff);
g -= (int)((p1[im->w] >> 8) & 0xff); g -= (int) ((p1[im->w] >> 8) & 0xff);
r -= (int)((p1[im->w] >> 16) & 0xff); r -= (int) ((p1[im->w] >> 16) & 0xff);
a -= (int)((p1[im->w] >> 24) & 0xff); a -= (int) ((p1[im->w] >> 24) & 0xff);
a = (a & ((~a) >> 16)); a = (a & ((~a) >> 16));
a = ((a | ((a & 256) - ((a & 256) >> 8)))); a = ((a | ((a & 256) - ((a & 256) >> 8))));
@ -316,9 +319,8 @@ __imlib_SharpenImage(ImlibImage * im, int rad)
void void
__imlib_TileImageHoriz(ImlibImage * im) __imlib_TileImageHoriz(ImlibImage * im)
{ {
DATA32 *p1, *p2, *p3, *p, *data; DATA32 *p1, *p2, *p3, *p, *data;
int x, y, per, tmp, na, nr, ng, nb, mix, a, r, g, b, aa, rr, int x, y, per, tmp, na, nr, ng, nb, mix, a, r, g, b, aa, rr, gg, bb;
gg, bb;
data = malloc(im->w * im->h * sizeof(DATA32)); data = malloc(im->w * im->h * sizeof(DATA32));
p1 = im->data; p1 = im->data;
@ -390,10 +392,8 @@ __imlib_TileImageHoriz(ImlibImage * im)
void void
__imlib_TileImageVert(ImlibImage * im) __imlib_TileImageVert(ImlibImage * im)
{ {
DATA32 *p1, *p2, *p, *data; DATA32 *p1, *p2, *p, *data;
int x, y, tmp, na, nr, ng, nb, mix, a, r, g, b, aa, rr, gg, int x, y, tmp, na, nr, ng, nb, mix, a, r, g, b, aa, rr, gg, bb;
bb;
data = malloc(im->w * im->h * sizeof(DATA32)); data = malloc(im->w * im->h * sizeof(DATA32));
p = data; p = data;
@ -440,13 +440,13 @@ __imlib_TileImageVert(ImlibImage * im)
im->data = data; im->data = data;
} }
ImlibUpdate * ImlibUpdate *
__imlib_draw_line(ImlibImage * im, int x1, int y1, int x2, int y2, DATA8 r, __imlib_draw_line(ImlibImage * im, int x1, int y1, int x2, int y2, DATA8 r,
DATA8 g, DATA8 b, DATA8 a, ImlibOp op, char make_updates) DATA8 g, DATA8 b, DATA8 a, ImlibOp op, char make_updates)
{ {
int x, y, dx, dy, yy, xx, am, tmp; int x, y, dx, dy, yy, xx, am, tmp;
DATA32 *p; DATA32 *p;
DATA8 aaa, nr, ng, nb, rr, gg, bb, aa, na; DATA8 aaa, nr, ng, nb, rr, gg, bb, aa, na;
/* clip to top edge */ /* clip to top edge */
if ((y1 < 0) && (y2 < 0)) if ((y1 < 0) && (y2 < 0))
@ -504,7 +504,7 @@ __imlib_draw_line(ImlibImage * im, int x1, int y1, int x2, int y2, DATA8 r,
dy = y2 - y1; dy = y2 - y1;
if (x1 > x2) if (x1 > x2)
{ {
int tmp; int tmp;
tmp = x1; tmp = x1;
x1 = x2; x1 = x2;
@ -1228,13 +1228,15 @@ __imlib_draw_line(ImlibImage * im, int x1, int y1, int x2, int y2, DATA8 r,
} }
void void
__imlib_draw_box(ImlibImage * im, int x, int y, int w, int h, DATA8 r, DATA8 g, __imlib_draw_box(ImlibImage * im, int x, int y, int w, int h, DATA8 r,
DATA8 b, DATA8 a, ImlibOp op) DATA8 g, DATA8 b, DATA8 a, ImlibOp op)
{ {
__imlib_draw_line(im, x, y, x + w - 1, y, r, g, b, a, op, 0); __imlib_draw_line(im, x, y, x + w - 1, y, r, g, b, a, op, 0);
__imlib_draw_line(im, x, y, x, y + h - 1, r, g, b, a, op, 0); __imlib_draw_line(im, x, y, x, y + h - 1, r, g, b, a, op, 0);
__imlib_draw_line(im, x, y + h - 1, x + w - 1, y + h - 1, r, g, b, a, op, 0); __imlib_draw_line(im, x, y + h - 1, x + w - 1, y + h - 1, r, g, b, a, op,
__imlib_draw_line(im, x + w - 1, y, x + w - 1, y + h - 1, r, g, b, a, op, 0); 0);
__imlib_draw_line(im, x + w - 1, y, x + w - 1, y + h - 1, r, g, b, a, op,
0);
} }
void void
@ -1247,21 +1249,21 @@ __imlib_draw_box_clipped(ImlibImage * im, int x, int y, int w, int h,
clip_ymin, clip_ymax, r, g, b, a, op, 0); clip_ymin, clip_ymax, r, g, b, a, op, 0);
__imlib_draw_line_clipped(im, x, y, x, y + h - 1, clip_xmin, clip_xmax, __imlib_draw_line_clipped(im, x, y, x, y + h - 1, clip_xmin, clip_xmax,
clip_ymin, clip_ymax, r, g, b, a, op, 0); clip_ymin, clip_ymax, r, g, b, a, op, 0);
__imlib_draw_line_clipped(im, x, y + h - 1, x + w - 1, y + h - 1, clip_xmin, __imlib_draw_line_clipped(im, x, y + h - 1, x + w - 1, y + h - 1,
clip_xmax, clip_ymin, clip_ymax, r, g, b, a, op, clip_xmin, clip_xmax, clip_ymin, clip_ymax, r, g,
0); b, a, op, 0);
__imlib_draw_line_clipped(im, x + w - 1, y, x + w - 1, y + h - 1, clip_xmin, __imlib_draw_line_clipped(im, x + w - 1, y, x + w - 1, y + h - 1,
clip_xmax, clip_ymin, clip_ymax, r, g, b, a, op, clip_xmin, clip_xmax, clip_ymin, clip_ymax, r, g,
0); b, a, op, 0);
} }
void void
__imlib_draw_filled_box(ImlibImage * im, int x, int y, int w, int h, DATA8 r, __imlib_draw_filled_box(ImlibImage * im, int x, int y, int w, int h, DATA8 r,
DATA8 g, DATA8 b, DATA8 a, ImlibOp op) DATA8 g, DATA8 b, DATA8 a, ImlibOp op)
{ {
int yy, xx, tmp; int yy, xx, tmp;
DATA32 *p; DATA32 *p;
DATA8 nr, ng, nb, rr, gg, bb, aa, na; DATA8 nr, ng, nb, rr, gg, bb, aa, na;
if (x < 0) if (x < 0)
{ {
@ -1340,8 +1342,8 @@ void
__imlib_copy_image_data(ImlibImage * im, int x, int y, int w, int h, int nx, __imlib_copy_image_data(ImlibImage * im, int x, int y, int w, int h, int nx,
int ny) int ny)
{ {
int xx, yy, jump; int xx, yy, jump;
DATA32 *p1, *p2; DATA32 *p1, *p2;
/* clip horizontal co-ordinates so that both dest and src fit inside */ /* clip horizontal co-ordinates so that both dest and src fit inside */
/* the image */ /* the image */
@ -1439,11 +1441,11 @@ __imlib_copy_image_data(ImlibImage * im, int x, int y, int w, int h, int nx,
} }
void void
__imlib_copy_alpha_data(ImlibImage * src, ImlibImage * dst, int x, int y, int w, __imlib_copy_alpha_data(ImlibImage * src, ImlibImage * dst, int x, int y,
int h, int nx, int ny) int w, int h, int nx, int ny)
{ {
int xx, yy, jump, jump2; int xx, yy, jump, jump2;
DATA32 *p1, *p2; DATA32 *p1, *p2;
/* clip horizontal co-ordinates so that both dest and src fit inside */ /* clip horizontal co-ordinates so that both dest and src fit inside */
/* the image */ /* the image */
@ -1522,17 +1524,17 @@ __imlib_copy_alpha_data(ImlibImage * src, ImlibImage * dst, int x, int y, int w,
} }
} }
ImlibUpdate * ImlibUpdate *
__imlib_draw_line_clipped(ImlibImage * im, int x1, int y1, int x2, int y2, __imlib_draw_line_clipped(ImlibImage * im, int x1, int y1, int x2, int y2,
int clip_xmin, int clip_xmax, int clip_ymin, int clip_xmin, int clip_xmax, int clip_ymin,
int clip_ymax, DATA8 r, DATA8 g, DATA8 b, DATA8 a, int clip_ymax, DATA8 r, DATA8 g, DATA8 b, DATA8 a,
ImlibOp op, char make_updates) ImlibOp op, char make_updates)
{ {
int cx0, cx1, cy0, cy1; int cx0, cx1, cy0, cy1;
if (imlib_clip_line if (imlib_clip_line
(x1, y1, x2, y2, clip_xmin, clip_xmax, clip_ymin, clip_ymax, &cx0, &cy0, (x1, y1, x2, y2, clip_xmin, clip_xmax, clip_ymin, clip_ymax, &cx0,
&cx1, &cy1)) &cy0, &cx1, &cy1))
{ {
return __imlib_draw_line(im, cx0, cy0, cx1, cy1, r, g, b, a, op, return __imlib_draw_line(im, cx0, cy0, cx1, cy1, r, g, b, a, op,
make_updates); make_updates);
@ -1543,11 +1545,11 @@ __imlib_draw_line_clipped(ImlibImage * im, int x1, int y1, int x2, int y2,
int int
imlib_clip_line(int x0, int y0, int x1, int y1, int xmin, int xmax, int ymin, imlib_clip_line(int x0, int y0, int x1, int y1, int xmin, int xmax, int ymin,
int ymax, int *clip_x0, int *clip_y0, int *clip_x1, int ymax, int *clip_x0, int *clip_y0, int *clip_x1,
int *clip_y1) int *clip_y1)
{ {
ImlibOutCode outcode0, outcode1, outcode_out; ImlibOutCode outcode0, outcode1, outcode_out;
unsigned char accept = FALSE, done = FALSE; unsigned char accept = FALSE, done = FALSE;
outcode0 = __imlib_comp_outcode(x0, y0, xmin, xmax, ymin, ymax); outcode0 = __imlib_comp_outcode(x0, y0, xmin, xmax, ymin, ymax);
outcode1 = __imlib_comp_outcode(x1, y1, xmin, xmax, ymin, ymax); outcode1 = __imlib_comp_outcode(x1, y1, xmin, xmax, ymin, ymax);
@ -1563,7 +1565,7 @@ imlib_clip_line(int x0, int y0, int x1, int y1, int xmin, int xmax, int ymin,
done = TRUE; done = TRUE;
else else
{ {
double x, y; double x, y;
outcode_out = outcode0 ? outcode0 : outcode1; outcode_out = outcode0 ? outcode0 : outcode1;
if (outcode_out & TOP) if (outcode_out & TOP)
@ -1611,10 +1613,10 @@ imlib_clip_line(int x0, int y0, int x1, int y1, int xmin, int xmax, int ymin,
} }
ImlibOutCode ImlibOutCode
__imlib_comp_outcode(double x, double y, double xmin, double xmax, double ymin, __imlib_comp_outcode(double x, double y, double xmin, double xmax,
double ymax) double ymin, double ymax)
{ {
ImlibOutCode code = 0; ImlibOutCode code = 0;
if (y > ymax) if (y > ymax)
code |= TOP; code |= TOP;
@ -1630,11 +1632,12 @@ __imlib_comp_outcode(double x, double y, double xmin, double xmax, double ymin,
ImlibPoly __imlib_polygon_new(int type) ImlibPoly __imlib_polygon_new(int type)
{ {
ImlibPoly poly; ImlibPoly poly;
poly = malloc(sizeof(_ImlibPoly)); poly = malloc(sizeof(_ImlibPoly));
if(!poly) if (!poly)
return NULL; return NULL;
memset(poly, 0, sizeof(_ImlibPoly)); memset(poly, 0, sizeof(_ImlibPoly));
switch(type) switch (type)
{ {
case P_OPEN: case P_OPEN:
break; break;
@ -1650,18 +1653,21 @@ ImlibPoly __imlib_polygon_new(int type)
return poly; return poly;
} }
void __imlib_polygon_add_point(ImlibPoly poly, int x, int y) void
__imlib_polygon_add_point(ImlibPoly poly, int x, int y)
{ {
poly->pointcount++; poly->pointcount++;
if(!poly->points) if (!poly->points)
poly->points = malloc(sizeof(ImlibPoint)); poly->points = malloc(sizeof(ImlibPoint));
else else
poly->points = realloc(poly->points, (poly->pointcount * sizeof(ImlibPoint))); poly->points =
realloc(poly->points, (poly->pointcount * sizeof(ImlibPoint)));
poly->points[poly->pointcount - 1].x = x; poly->points[poly->pointcount - 1].x = x;
poly->points[poly->pointcount - 1].y = y; poly->points[poly->pointcount - 1].y = y;
} }
void __imlib_polygon_free(ImlibPoly poly) void
__imlib_polygon_free(ImlibPoly poly)
{ {
free(poly->points); free(poly->points);
free(poly); free(poly);
@ -1670,53 +1676,219 @@ void __imlib_polygon_free(ImlibPoly poly)
void void
__imlib_draw_polygon(ImlibImage * im, ImlibPoly poly, DATA8 r, DATA8 g, __imlib_draw_polygon(ImlibImage * im, ImlibPoly poly, DATA8 r, DATA8 g,
DATA8 b, DATA8 a, ImlibOp op) DATA8 b, DATA8 a, ImlibOp op)
{ {
int i; int i;
if(!poly || !poly->points || (poly->pointcount < 2))
if (!poly || !poly->points || (poly->pointcount < 2))
return; return;
for(i = 0; i < poly->pointcount; i++) for (i = 0; i < poly->pointcount; i++)
{ {
if(i < poly->pointcount - 1) if (i < poly->pointcount - 1)
__imlib_draw_line(im, poly->points[i].x, poly->points[i].y, poly->points[i+1].x, poly->points[i+1].y, r, g, b, a, op, 0); __imlib_draw_line(im, poly->points[i].x, poly->points[i].y,
else if(poly->closed) poly->points[i + 1].x, poly->points[i + 1].y, r, g,
__imlib_draw_line(im, poly->points[i].x, poly->points[i].y, poly->points[0].x, poly->points[0].y, r, g, b, a, op, 0); b, a, op, 0);
else break; else if (poly->closed)
__imlib_draw_line(im, poly->points[i].x, poly->points[i].y,
poly->points[0].x, poly->points[0].y, r, g, b, a,
op, 0);
else
break;
} }
} }
void void
__imlib_draw_polygon_clipped(ImlibImage * im, ImlibPoly poly, int clip_xmin, __imlib_draw_polygon_clipped(ImlibImage * im, ImlibPoly poly, int clip_xmin,
int clip_xmax, int clip_ymin, int clip_ymax, DATA8 r, DATA8 g, DATA8 b, int clip_xmax, int clip_ymin, int clip_ymax,
DATA8 a, ImlibOp op) DATA8 r, DATA8 g, DATA8 b, DATA8 a, ImlibOp op)
{ {
int i; int i;
if(!poly || !poly->points || (poly->pointcount < 2))
if (!poly || !poly->points || (poly->pointcount < 2))
return; return;
for(i = 0; i < poly->pointcount; i++) for (i = 0; i < poly->pointcount; i++)
{ {
if(i < poly->pointcount - 1) if (i < poly->pointcount - 1)
__imlib_draw_line_clipped(im, poly->points[i].x, poly->points[i].y, poly->points[i+1].x, poly->points[i+1].y, clip_xmin, clip_xmax, clip_ymin, clip_ymax, r, g, b, a, op, 0); __imlib_draw_line_clipped(im, poly->points[i].x, poly->points[i].y,
else if(poly->closed) poly->points[i + 1].x,
__imlib_draw_line_clipped(im, poly->points[i].x, poly->points[i].y, poly->points[0].x, poly->points[0].y, clip_xmin, clip_xmax, clip_ymin, clip_ymax, r, g, b, a, op, 0); poly->points[i + 1].y, clip_xmin,
else break; clip_xmax, clip_ymin, clip_ymax, r, g, b,
a, op, 0);
else if (poly->closed)
__imlib_draw_line_clipped(im, poly->points[i].x, poly->points[i].y,
poly->points[0].x, poly->points[0].y,
clip_xmin, clip_xmax, clip_ymin, clip_ymax,
r, g, b, a, op, 0);
else
break;
} }
} }
void __imlib_polygon_get_bounds(ImlibPoly poly, int *px1, int *py1, int *px2, int *py2) void
__imlib_polygon_get_bounds(ImlibPoly poly, int *px1, int *py1, int *px2,
int *py2)
{ {
int x1,y1,x2,y2; int x1, y1, x2, y2;
int i; int i;
if(!poly || !poly->points || (poly->pointcount < 2))
return;
for(i = 0; i < poly->pointcount; i++)
GROW_BOUNDS (x1, y1, x2, y2, poly->points[i].x, poly->points[i].y);
*px1 = x1; if (!poly || !poly->points || (poly->pointcount < 2))
*py1 = y1; return;
*px2 = x2;
*py2 = y2; for (i = 0; i < poly->pointcount; i++)
GROW_BOUNDS(x1, y1, x2, y2, poly->points[i].x, poly->points[i].y);
*px1 = x1;
*py1 = y1;
*px2 = x2;
*py2 = y2;
}
void
__imlib_draw_ellipse(ImlibImage * im, int xc, int yc, int aa, int bb, DATA8 r,
DATA8 g, DATA8 b, DATA8 a, ImlibOp op)
{
int a2 = aa * aa;
int b2 = bb * bb;
int x, y, dec;
for (x = 0, y = bb, dec = 2 * b2 + a2 * (1 - 2 * bb); b2 * x <= a2 * y;
x++)
{
__imlib_draw_set_point(im, xc + x, yc + y, r, g, b, a, op);
__imlib_draw_set_point(im, xc - x, yc + y, r, g, b, a, op);
__imlib_draw_set_point(im, xc + x, yc - y, r, g, b, a, op);
__imlib_draw_set_point(im, xc - x, yc - y, r, g, b, a, op);
if (dec >= 0)
dec += 4 * a2 * (1 - (y--));
dec += b2 * (4 * x + 6);
}
for (x = aa, y = 0, dec = 2 * a2 + b2 * (1 - 2 * aa); a2 * y <= b2 * x;
y++)
{
__imlib_draw_set_point(im, xc + x, yc + y, r, g, b, a, op);
__imlib_draw_set_point(im, xc - x, yc + y, r, g, b, a, op);
__imlib_draw_set_point(im, xc + x, yc - y, r, g, b, a, op);
__imlib_draw_set_point(im, xc - x, yc - y, r, g, b, a, op);
if (dec >= 0)
dec += 4 * b2 * (1 - (x--));
dec += a2 * (4 * y + 6);
}
}
void
__imlib_draw_ellipse_clipped(ImlibImage * im, int xc, int yc, int aa, int bb,
int clip_xmin, int clip_xmax, int clip_ymin,
int clip_ymax, DATA8 r, DATA8 g, DATA8 b,
DATA8 a, ImlibOp op)
{
int a2 = aa * aa;
int b2 = bb * bb;
int x, y, dec;
for (x = 0, y = bb, dec = 2 * b2 + a2 * (1 - 2 * bb); b2 * x <= a2 * y;
x++)
{
__imlib_draw_set_point_clipped(im, xc + x, yc + y, clip_xmin, clip_xmax,
clip_ymin, clip_ymax, r, g, b, a, op);
__imlib_draw_set_point_clipped(im, xc - x, yc + y, clip_xmin, clip_xmax,
clip_ymin, clip_ymax, r, g, b, a, op);
__imlib_draw_set_point_clipped(im, xc + x, yc - y, clip_xmin, clip_xmax,
clip_ymin, clip_ymax, r, g, b, a, op);
__imlib_draw_set_point_clipped(im, xc - x, yc - y, clip_xmin, clip_xmax,
clip_ymin, clip_ymax, r, g, b, a, op);
if (dec >= 0)
dec += 4 * a2 * (1 - (y--));
dec += b2 * (4 * x + 6);
}
for (x = aa, y = 0, dec = 2 * a2 + b2 * (1 - 2 * aa); a2 * y <= b2 * x;
y++)
{
__imlib_draw_set_point_clipped(im, xc + x, yc + y, clip_xmin, clip_xmax,
clip_ymin, clip_ymax, r, g, b, a, op);
__imlib_draw_set_point_clipped(im, xc - x, yc + y, clip_xmin, clip_xmax,
clip_ymin, clip_ymax, r, g, b, a, op);
__imlib_draw_set_point_clipped(im, xc + x, yc - y, clip_xmin, clip_xmax,
clip_ymin, clip_ymax, r, g, b, a, op);
__imlib_draw_set_point_clipped(im, xc - x, yc - y, clip_xmin, clip_xmax,
clip_ymin, clip_ymax, r, g, b, a, op);
if (dec >= 0)
dec += 4 * b2 * (1 - (x--));
dec += a2 * (4 * y + 6);
}
}
void
__imlib_draw_set_point(ImlibImage * im, int x, int y, DATA8 r, DATA8 g,
DATA8 b, DATA8 a, ImlibOp op)
{
DATA32 *p;
int tmp;
if ((x >= 0 && x < im->w) && (y >= 0 && y <= im->h))
{
p = &(im->data[(im->w * y) + x]);
switch (op)
{
case OP_RESHADE:
BLEND_RE(r, g, b, a, p);
break;
case OP_SUBTRACT:
BLEND_SUB(r, g, b, a, p);
break;
case OP_ADD:
BLEND_ADD(r, g, b, a, p);
break;
case OP_COPY:
BLEND(r, g, b, a, p);
break;
default:
break;
}
}
}
void
__imlib_draw_set_point_clipped(ImlibImage * im, int x, int y, int clip_xmin,
int clip_xmax, int clip_ymin, int clip_ymax,
DATA8 r, DATA8 g, DATA8 b, DATA8 a, ImlibOp op)
{
DATA32 *p;
int tmp;
if ((x >= 0 && x < im->w) && (y >= 0 && y <= im->h))
{
if (XY_IN_RECT
(x, y, clip_xmin, clip_ymin, clip_xmax - clip_xmin, clip_ymax - clip_ymin))
{
p = &(im->data[(im->w * y) + x]);
switch (op)
{
case OP_RESHADE:
BLEND_RE(r, g, b, a, p);
break;
case OP_SUBTRACT:
BLEND_SUB(r, g, b, a, p);
break;
case OP_ADD:
BLEND_ADD(r, g, b, a, p);
break;
case OP_COPY:
BLEND(r, g, b, a, p);
break;
default:
break;
}
}
}
} }

View File

@ -93,4 +93,19 @@ __imlib_draw_polygon_clipped(ImlibImage * im, ImlibPoly poly, int clip_xmin,
int clip_xmax, int clip_ymin, int clip_ymax, DATA8 r, DATA8 g, DATA8 b, int clip_xmax, int clip_ymin, int clip_ymax, DATA8 r, DATA8 g, DATA8 b,
DATA8 a, ImlibOp op); DATA8 a, ImlibOp op);
void __imlib_polygon_get_bounds(ImlibPoly poly, int *px1, int *py1, int *px2, int *py2); void __imlib_polygon_get_bounds(ImlibPoly poly, int *px1, int *py1, int *px2, int *py2);
void
__imlib_draw_set_point(ImlibImage * im, int x, int y, DATA8 r, DATA8 g,
DATA8 b, DATA8 a, ImlibOp op);
void
__imlib_draw_set_point_clipped(ImlibImage * im, int x, int y, int clip_xmin,
int clip_xmax, int clip_ymin, int clip_ymax,
DATA8 r, DATA8 g, DATA8 b, DATA8 a, ImlibOp op);
void
__imlib_draw_ellipse(ImlibImage * im, int xc, int yc, int aa, int bb, DATA8 r,
DATA8 g, DATA8 b, DATA8 a, ImlibOp op);
void
__imlib_draw_ellipse_clipped(ImlibImage * im, int xc, int yc, int aa, int bb,
int clip_xmin, int clip_xmax, int clip_ymin,
int clip_ymax, DATA8 r, DATA8 g, DATA8 b,
DATA8 a, ImlibOp op);
#endif #endif

View File

@ -773,11 +773,24 @@ int main (int argc, char **argv)
imlib_image_get_height()); imlib_image_get_height());
{ {
Imlib_Updates uu; Imlib_Updates uu;
imlib_context_set_color(255, 255, 255, 255); imlib_context_set_color(255, 255, 255, 255);
uu = imlib_image_draw_line(200, 200, x, y, 1); uu = imlib_image_draw_line(200, 200, x, y, 1);
up = imlib_updates_append_updates(up, uu); up = imlib_updates_append_updates(up, uu);
/* test ellipses */
imlib_context_set_cliprect(0,0,0,0);
imlib_context_set_color(255, 255, 255, 255);
imlib_image_draw_ellipse(50,280,30,40);
imlib_image_draw_rectangle(120,245,70,70);
up = imlib_update_append_rect(up, 120,245,70,70);
imlib_image_draw_ellipse(160,280,50,20);
imlib_context_set_cliprect(120,245,70,70);
imlib_context_set_color(255, 55, 55, 255);
imlib_image_draw_ellipse(160,280,50,20);
/* test line clipping */ /* test line clipping */
imlib_context_set_cliprect(0,0,0,0); imlib_context_set_cliprect(0,0,0,0);
imlib_image_draw_rectangle(50,50,100,100); imlib_image_draw_rectangle(50,50,100,100);
@ -846,7 +859,6 @@ int main (int argc, char **argv)
imlib_image_draw_polygon(poly3); imlib_image_draw_polygon(poly3);
imlib_context_set_cliprect(0,0,0,0); imlib_context_set_cliprect(0,0,0,0);
} }
{ {
static Imlib_Color_Range rg = NULL; static Imlib_Color_Range rg = NULL;