From f6dbf601b2a5bbd7d7b25192a4a9fcb7d55f0b44 Mon Sep 17 00:00:00 2001 From: "Mirar (Pontus Hagland)" <pike@sort.mirar.org> Date: Thu, 20 May 1999 19:34:38 +0200 Subject: [PATCH] support for color argument in most functions Rev: src/modules/Image/blit.c:1.32 Rev: src/modules/Image/image.c:1.135 Rev: src/modules/Image/matrix.c:1.19 Rev: src/modules/Image/togif.c:1.34 --- src/modules/Image/blit.c | 54 ++++++++++++++++++++++---------------- src/modules/Image/image.c | 14 ++++++---- src/modules/Image/matrix.c | 20 +++++++++++--- src/modules/Image/togif.c | 22 ++++++++++++---- 4 files changed, 73 insertions(+), 37 deletions(-) diff --git a/src/modules/Image/blit.c b/src/modules/Image/blit.c index 9841e419c9..4531f0195e 100644 --- a/src/modules/Image/blit.c +++ b/src/modules/Image/blit.c @@ -1,10 +1,10 @@ -/* $Id: blit.c,v 1.31 1999/04/16 17:45:05 mirar Exp $ */ +/* $Id: blit.c,v 1.32 1999/05/20 17:34:34 mirar Exp $ */ #include "global.h" /* **! module Image **! note -**! $Id: blit.c,v 1.31 1999/04/16 17:45:05 mirar Exp $ +**! $Id: blit.c,v 1.32 1999/05/20 17:34:34 mirar Exp $ **! class Image */ @@ -80,11 +80,17 @@ static void chrono(char *x) (((x)<0||(y)<0||(x)>=THIS->xsize||(y)>=THIS->ysize)? \ 0:(setpixel(x,y),0)) -static INLINE void getrgb(struct image *img, - INT32 args_start,INT32 args,char *name) +static INLINE int getrgb(struct image *img, + INT32 args_start,INT32 args,char *name) { INT32 i; - if (args-args_start<3) return; + if (args-args_start<1) return 0; + + if (image_color_svalue(sp-args+args_start,&(img->rgb))) + return 1; + + if (args-args_start<3) return 0; + for (i=0; i<3; i++) if (sp[-args+i+args_start].type!=T_INT) error("Illegal r,g,b argument to %s\n",name); @@ -95,11 +101,18 @@ static INLINE void getrgb(struct image *img, if (sp[3-args+args_start].type!=T_INT) error("Illegal alpha argument to %s\n",name); else + { img->alpha=sp[3-args+args_start].u.integer; + return 4; + } else + { img->alpha=0; + return 3; + } } + /*** end internals ***/ @@ -271,7 +284,7 @@ void img_clone(struct image *newimg,struct image *img) void image_paste(INT32 args) { - struct image *img; + struct image *img=NULL; INT32 x1,y1,x2,y2,blitwidth,blitheight; if (args<1 @@ -504,6 +517,8 @@ CHRONO("image_paste_mask end"); **! method object paste_alpha_color(object mask,int x,int y) **! method object paste_alpha_color(object mask,int r,int g,int b) **! method object paste_alpha_color(object mask,int r,int g,int b,int x,int y) +**! method object paste_alpha_color(object mask,Color color) +**! method object paste_alpha_color(object mask,Color color,int x,int y) **! Pastes a given color over the current image, **! using the given mask as opaque channel. **! @@ -535,9 +550,10 @@ void image_paste_alpha_color(INT32 args) rgb_group rgb,*d,*m; INT32 mmod,dmod; float q; + int arg=1; - if (args!=1 && args!=4 && args!=6 && args!=3) - error("illegal number of arguments to image->paste_alpha_color()\n"); + if (args<1) + error("too few arguments to image->paste_alpha_color()\n"); if (sp[-args].type!=T_OBJECT || !sp[-args].u.object || !(mask=(struct image*)get_storage(sp[-args].u.object,image_program))) @@ -545,23 +561,15 @@ void image_paste_alpha_color(INT32 args) if (!THIS->img) return; if (!mask->img) return; - if (args==6 || args==4) /* colors at arg 2..4 */ - getrgb(THIS,1,args,"image->paste_alpha_color()\n"); - if (args==3) /* coords at 2..3 */ - { - if (sp[1-args].type!=T_INT - || sp[2-args].type!=T_INT) - error("illegal coordinate arguments to image->paste_alpha_color()\n"); - x1=sp[1-args].u.integer; - y1=sp[2-args].u.integer; - } - else if (args==6) /* at 5..6 */ + if (args==6 || args==4 || args==2 || args==3) /* color at arg 2.. */ + arg=1+getrgb(THIS,1,args,"image->paste_alpha_color()\n"); + if (args>arg+1) { - if (sp[4-args].type!=T_INT - || sp[5-args].type!=T_INT) + if (sp[arg-args].type!=T_INT + || sp[arg-args].type!=T_INT) error("illegal coordinate arguments to image->paste_alpha_color()\n"); - x1=sp[4-args].u.integer; - y1=sp[5-args].u.integer; + x1=sp[arg-args].u.integer; + y1=sp[arg-args].u.integer; } else x1=y1=0; diff --git a/src/modules/Image/image.c b/src/modules/Image/image.c index b8627dce0d..431e461a9d 100644 --- a/src/modules/Image/image.c +++ b/src/modules/Image/image.c @@ -1,9 +1,9 @@ -/* $Id: image.c,v 1.134 1999/05/20 17:08:01 mirar Exp $ */ +/* $Id: image.c,v 1.135 1999/05/20 17:34:35 mirar Exp $ */ /* **! module Image **! note -**! $Id: image.c,v 1.134 1999/05/20 17:08:01 mirar Exp $ +**! $Id: image.c,v 1.135 1999/05/20 17:34:35 mirar Exp $ **! class Image **! **! The main object of the <ref>Image</ref> module, this object @@ -97,7 +97,7 @@ #include "stralloc.h" #include "global.h" -RCSID("$Id: image.c,v 1.134 1999/05/20 17:08:01 mirar Exp $"); +RCSID("$Id: image.c,v 1.135 1999/05/20 17:34:35 mirar Exp $"); #include "pike_macros.h" #include "object.h" #include "constants.h" @@ -3698,8 +3698,12 @@ void pike_module_init(void) ADD_FUNCTION("paste_mask",image_paste_mask, tFunc(tObj tObj tOr(tInt,tVoid) tOr(tInt,tVoid),tObj),0); ADD_FUNCTION("paste_alpha_color",image_paste_alpha_color, - tFunc(tObj tOr(tVoid,tInt) tOr(tVoid,tInt) - tOr(tVoid,tInt) tOr(tInt,tVoid) tOr(tInt,tVoid),tObj),0); + tOr6(tFunc(tObj tInt tInt,tObj), + tFunc(tObj tInt tInt tInt,tObj), + tFunc(tObj tInt tInt tInt tInt tInt,tObj), + tFunc(tObj tColor tInt tInt,tObj), + tFunc(tObj tColor,tObj), + tFunc(tObj,tObj)),0); ADD_FUNCTION("setcolor",image_setcolor, tFunc(tInt tInt tInt,tObj),0); diff --git a/src/modules/Image/matrix.c b/src/modules/Image/matrix.c index 70da33ca07..ebcd60188c 100644 --- a/src/modules/Image/matrix.c +++ b/src/modules/Image/matrix.c @@ -1,9 +1,9 @@ -/* $Id: matrix.c,v 1.18 1999/04/13 12:32:25 mirar Exp $ */ +/* $Id: matrix.c,v 1.19 1999/05/20 17:34:37 mirar Exp $ */ /* **! module Image **! note -**! $Id: matrix.c,v 1.18 1999/04/13 12:32:25 mirar Exp $ +**! $Id: matrix.c,v 1.19 1999/05/20 17:34:37 mirar Exp $ **! class Image */ @@ -79,10 +79,16 @@ static void chrono(char *x) 0:(setpixel(x,y),0)) static INLINE int getrgb(struct image *img, - INT32 args_start,INT32 args,char *name) + INT32 args_start,INT32 args,char *name) { INT32 i; + if (args-args_start<1) return 0; + + if (image_color_svalue(sp-args+args_start,&(img->rgb))) + return 1; + if (args-args_start<3) return 0; + for (i=0; i<3; i++) if (sp[-args+i+args_start].type!=T_INT) error("Illegal r,g,b argument to %s\n",name); @@ -93,12 +99,18 @@ static INLINE int getrgb(struct image *img, if (sp[3-args+args_start].type!=T_INT) error("Illegal alpha argument to %s\n",name); else + { img->alpha=sp[3-args+args_start].u.integer; + return 4; + } else + { img->alpha=0; - return 1; + return 3; + } } + static INLINE int getrgbl(rgbl_group *rgb,INT32 args_start,INT32 args,char *name) { INT32 i; diff --git a/src/modules/Image/togif.c b/src/modules/Image/togif.c index 1d9c57244c..0c79feeefb 100644 --- a/src/modules/Image/togif.c +++ b/src/modules/Image/togif.c @@ -2,7 +2,7 @@ togif -$Id: togif.c,v 1.33 1999/04/13 12:32:36 mirar Exp $ +$Id: togif.c,v 1.34 1999/05/20 17:34:38 mirar Exp $ old GIF API compat stuff @@ -11,7 +11,7 @@ old GIF API compat stuff /* **! module Image **! note -**! $Id: togif.c,v 1.33 1999/04/13 12:32:36 mirar Exp $ +**! $Id: togif.c,v 1.34 1999/05/20 17:34:38 mirar Exp $ **! class Image */ @@ -307,11 +307,17 @@ static void img_encode_gif(rgb_group *transparent,int fs,INT32 args) else _image_gif_encode(2,fs); } -static INLINE void getrgb(struct image *img, - INT32 args_start,INT32 args,char *name) +static INLINE int getrgb(struct image *img, + INT32 args_start,INT32 args,char *name) { INT32 i; - if (args-args_start<3) return; + if (args-args_start<1) return 0; + + if (image_color_svalue(sp-args+args_start,&(img->rgb))) + return 1; + + if (args-args_start<3) return 0; + for (i=0; i<3; i++) if (sp[-args+i+args_start].type!=T_INT) error("Illegal r,g,b argument to %s\n",name); @@ -322,9 +328,15 @@ static INLINE void getrgb(struct image *img, if (sp[3-args+args_start].type!=T_INT) error("Illegal alpha argument to %s\n",name); else + { img->alpha=sp[3-args+args_start].u.integer; + return 4; + } else + { img->alpha=0; + return 3; + } } void image_togif(INT32 args) -- GitLab