diff --git a/src/Imlib2.h b/src/Imlib2.h index ab0bc25..ee2fc0f 100644 --- a/src/Imlib2.h +++ b/src/Imlib2.h @@ -253,8 +253,8 @@ void imlib_image_fill_polygon(ImlibPolygon poly); 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); +void imlib_image_draw_ellipse(int xc, int yc, int a, int b); +void imlib_image_fill_ellipse(int xc, int yc, int a, int b); Imlib_Color_Range imlib_create_color_range(void); void imlib_free_color_range(void); diff --git a/src/api.c b/src/api.c index 7784cac..f5dae13 100644 --- a/src/api.c +++ b/src/api.c @@ -2866,7 +2866,6 @@ imlib_image_draw_ellipse(int xc, int yc, int a, int b) if (ctxt_cliprect.w) { - /* TODO */ __imlib_draw_ellipse_clipped(im, xc, yc, a, b, ctxt_cliprect.x, ctxt_cliprect.x + ctxt_cliprect.w, ctxt_cliprect.y, @@ -2881,3 +2880,35 @@ imlib_image_draw_ellipse(int xc, int yc, int a, int b) ctxt_color.blue, ctxt_color.alpha, ctxt_operation); } } + +void +imlib_image_fill_ellipse(int xc, int yc, int a, int b) +{ + ImlibImage *im; + + CHECK_PARAM_POINTER("imlib_fill_ellipse", "image", ctxt_image); + CAST_IMAGE(im, ctxt_image); + if ((!(im->data)) && (im->loader) && (im->loader->load)) + im->loader->load(im, NULL, 0, 1); + if (!(im->data)) + return; + __imlib_DirtyImage(im); + __imlib_DirtyPixmapsForImage(im); + + if (ctxt_cliprect.w) + { + __imlib_fill_ellipse_clipped(im, xc, yc, a, b, ctxt_cliprect.x, + ctxt_cliprect.x + ctxt_cliprect.w, + ctxt_cliprect.y, + ctxt_cliprect.y + ctxt_cliprect.h, + ctxt_color.red, ctxt_color.green, + ctxt_color.blue, ctxt_color.alpha, + ctxt_operation); + } + else + { + __imlib_fill_ellipse(im, xc, yc, a, b, ctxt_color.red, ctxt_color.green, + ctxt_color.blue, ctxt_color.alpha, ctxt_operation); + } +} + diff --git a/src/rgbadraw.c b/src/rgbadraw.c index b011187..2379400 100644 --- a/src/rgbadraw.c +++ b/src/rgbadraw.c @@ -1771,6 +1771,91 @@ __imlib_draw_ellipse(ImlibImage * im, int xc, int yc, int aa, int bb, DATA8 r, } } +void +__imlib_fill_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 i; + + int x, y, dec; + + for (x = 0, y = bb, dec = 2 * b2 + a2 * (1 - 2 * bb); b2 * x <= a2 * y; + x++) + { + for (i = yc - y; i <= yc + y; i++) + { + __imlib_draw_set_point(im, xc - x, i, r, g, b, a, op); + __imlib_draw_set_point(im, xc + x, i, 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++) + { + for (i = yc - y; i <= yc + y; i++) + { + __imlib_draw_set_point(im, xc + x, i, r, g, b, a, op); + __imlib_draw_set_point(im, xc - x, i, r, g, b, a, op); + } + + if (dec >= 0) + dec += 4 * b2 * (1 - (x--)); + dec += a2 * (4 * y + 6); + } +} + +void +__imlib_fill_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 i; + + int x, y, dec; + + for (x = 0, y = bb, dec = 2 * b2 + a2 * (1 - 2 * bb); b2 * x <= a2 * y; + x++) + { + for (i = yc - y; i <= yc + y; i++) + { + __imlib_draw_set_point_clipped(im, xc - x, i, clip_xmin, clip_xmax, + clip_ymin, clip_ymax, r, g, b, a, op); + __imlib_draw_set_point_clipped(im, xc + x, i, 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++) + { + for (i = yc - y; i <= yc + y; i++) + { + __imlib_draw_set_point_clipped(im, xc + x, i, clip_xmin, clip_xmax, + clip_ymin, clip_ymax, r, g, b, a, op); + __imlib_draw_set_point_clipped(im, xc - x, i, 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_ellipse_clipped(ImlibImage * im, int xc, int yc, int aa, int bb, int clip_xmin, int clip_xmax, int clip_ymin, diff --git a/src/rgbadraw.h b/src/rgbadraw.h index b4d9cda..5ff4739 100644 --- a/src/rgbadraw.h +++ b/src/rgbadraw.h @@ -115,4 +115,12 @@ __imlib_draw_polygon_filled_clipped(ImlibImage * im, ImlibPoly poly, int clip_xmin, int clip_xmax, int clip_ymin, int clip_ymax, DATA8 r, DATA8 g, DATA8 b, DATA8 a, ImlibOp op); +void +__imlib_fill_ellipse(ImlibImage * im, int xc, int yc, int aa, int bb, DATA8 r, + DATA8 g, DATA8 b, DATA8 a, ImlibOp op); +void +__imlib_fill_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 diff --git a/test/main.c b/test/main.c index 2d27210..f580a09 100644 --- a/test/main.c +++ b/test/main.c @@ -781,7 +781,8 @@ int main (int argc, char **argv) /* 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_ellipse(50,250,30,40); + imlib_image_fill_ellipse(50,300,30,40); imlib_image_draw_rectangle(120,245,70,70); up = imlib_update_append_rect(up, 120,245,70,70);