From 830b576dd1ea76402fff0d188281ba39380605e5 Mon Sep 17 00:00:00 2001 From: Franz Marini Date: Tue, 28 Aug 2001 12:50:15 +0000 Subject: [PATCH] ok, just wrote this little function to do pixel drawing with blending. In fact, I wrote it just for the Bezier drawing function, but I thought it could be useful in other cases too. Have fun, Lightman :) SVN revision: 5302 --- src/Imlib2.h | 1 + src/api.c | 24 ++++++++++++++++++++++++ src/rgbadraw.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/rgbadraw.h | 3 +++ 4 files changed, 76 insertions(+) diff --git a/src/Imlib2.h b/src/Imlib2.h index 634403c..9b51088 100644 --- a/src/Imlib2.h +++ b/src/Imlib2.h @@ -354,6 +354,7 @@ extern "C" int height); /* drawing on images */ + Imlib_Updates imlib_image_draw_pixel(int x, int y, char make_updates); Imlib_Updates imlib_image_draw_line(int x1, int y1, int x2, int y2, char make_updates); int imlib_clip_line(int x0, int y0, int x1, int y1, int xmin, int xmax, diff --git a/src/api.c b/src/api.c index 906bdfb..fbaf49c 100644 --- a/src/api.c +++ b/src/api.c @@ -3221,6 +3221,30 @@ imlib_apply_color_modifier_to_rectangle(int x, int y, int width, int height) (ImlibColorModifier *) ctx->color_modifier); } +Imlib_Updates +imlib_image_draw_pixel(int x, int y, char make_updates) +{ + ImlibImage *im; + + if (!ctx) ctx = imlib_context_new(); + CHECK_PARAM_POINTER_RETURN("imlib_image_draw_pixel", "image", ctx->image, + NULL); + CAST_IMAGE(im, ctx->image); + if ((!(im->data)) && (im->loader) && (im->loader->load)) + im->loader->load(im, NULL, 0, 1); + if (!(im->data)) + return NULL; + __imlib_DirtyImage(im); + __imlib_DirtyPixmapsForImage(im); + return (Imlib_Updates) __imlib_draw_pixel(im, x, y, + (DATA8) ctx->color.red, + (DATA8) ctx->color.green, + (DATA8) ctx->color.blue, + (DATA8) ctx->color.alpha, + ctx->operation, + (char) make_updates); +} + Imlib_Updates imlib_image_draw_line(int x1, int y1, int x2, int y2, char make_updates) { diff --git a/src/rgbadraw.c b/src/rgbadraw.c index e152698..e5f71c0 100644 --- a/src/rgbadraw.c +++ b/src/rgbadraw.c @@ -441,6 +441,54 @@ __imlib_TileImageVert(ImlibImage * im) im->data = data; } +ImlibUpdate * +__imlib_draw_pixel(ImlibImage *im, int x, int y, DATA8 r, DATA8 g, DATA8 b, + DATA8 a, ImlibOp op, char make_updates) +{ + int tmp; + DATA32 *p; + + /*clip to edges */ + if ((x < 0) || (x >= im->w) || (y < 0) || (y >= im->h)) + return NULL; + + switch(op) + { + case OP_COPY: + p = &(im->data[im->w * y + x]); + BLEND(r, g, b, a, p); + if (!make_updates) + return NULL; + return __imlib_AddUpdate(NULL, x, y, 1, 1); + break; + case OP_ADD: + p = &(im->data[im->w * y + x]); + BLEND_ADD(r, g, b, a, p); + if (!make_updates) + return NULL; + return __imlib_AddUpdate(NULL, x, y, 1, 1); + break; + case OP_SUBTRACT: + p = &(im->data[im->w * y + x]); + BLEND_SUB(r, g, b, a, p); + if (!make_updates) + return NULL; + return __imlib_AddUpdate(NULL, x, y, 1, 1); + break; + case OP_RESHADE: + p = &(im->data[im->w * y + x]); + BLEND_RE(r, g, b, a, p); + if (!make_updates) + return NULL; + return __imlib_AddUpdate(NULL, x, y, 1, 1); + break; + default: + break; + } + return NULL; +} + + ImlibUpdate * __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) diff --git a/src/rgbadraw.h b/src/rgbadraw.h index 3d14c7b..1125231 100644 --- a/src/rgbadraw.h +++ b/src/rgbadraw.h @@ -136,6 +136,9 @@ void __imlib_BlurImage(ImlibImage * im, int rad); void __imlib_SharpenImage(ImlibImage * im, int rad); void __imlib_TileImageHoriz(ImlibImage * im); void __imlib_TileImageVert(ImlibImage * im); +ImlibUpdate *__imlib_draw_pixel(ImlibImage *im, int x, int y, DATA8 r, + DATA8 g, DATA8 b, DATA8 a, ImlibOp op, + char make_updates); ImlibUpdate *__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);