pike.git / src / modules / Image / layers.c

version» Context lines:

pike.git/src/modules/Image/layers.c:18:      #include "stralloc.h"   #include "pike_macros.h"   #include "object.h"   #include "interpret.h"   #include "svalue.h"   #include "array.h"   #include "mapping.h"   #include "threads.h"   #include "builtin_functions.h" - #include "dmalloc.h" +    #include "operators.h"   #include "module_support.h" -  + #include "pike_types.h" + #include "sprintf.h"      #include "image.h"    - #ifdef TRY_USE_MMX - #ifdef HAVE_MMX_H - #include <mmx.h> - #else - #include <asm/mmx.h> - #endif - #endif -  -  +    extern struct program *image_program;   extern struct program *image_layer_program;   extern struct program *image_colortable_program;      static struct mapping *colors=NULL;   static struct object *colortable=NULL;   static struct array *colornames=NULL;      static const rgb_group black={0,0,0};   static const rgb_group white={COLORMAX,COLORMAX,COLORMAX};
pike.git/src/modules/Image/layers.c:340:      /*** layer helpers ****************************************/      #define COMBINE_METHOD_INT   #define CCUT_METHOD_INT      #define qMAX (1.0/COLORMAX)   #define C2F(Z) (qMAX*(Z))      #ifdef CCUT_METHOD_FLOAT - #define CCUT(Z) (DOUBLE_TO_COLORTYPE(qMAX*Z)) + #define CCUT(Z) ((COLORTYPE)(qMAX*Z))   #else /* CCUT_METHOD_INT */ - #define CCUT(Z) (DOUBLE_TO_COLORTYPE((Z)/COLORMAX)) + #define CCUT(Z) ((COLORTYPE)((Z)/COLORMAX))   #endif      #ifdef COMBINE_METHOD_INT         #define COMBINE_ALPHA_SUM(aS,aL) \ -  CCUT((COLORMAX*DOUBLE_TO_INT(aL))+(COLORMAX-DOUBLE_TO_INT(aL))*(aS)) +  CCUT((COLORMAX*(int)(aL))+(COLORMAX-(int)(aL))*(aS))   #define COMBINE_ALPHA_SUM_V(aS,aL,V) \    COMBINE_ALPHA_SUM(aS,(aL)*(V))      #define COMBINE_ALPHA(S,L,aS,aL) \ -  ( (COLORTYPE)((((S)*(DOUBLE_TO_INT(COLORMAX-(aL)))*(aS))+ \ -  ((L)*(DOUBLE_TO_INT(aL))*COLORMAX))/ \ -  (((COLORMAX*DOUBLE_TO_INT(aL))+(COLORMAX-DOUBLE_TO_INT(aL))*(aS))) ) ) +  ( (COLORTYPE)((((S)*((int)(COLORMAX-(aL)))*(aS))+ \ +  ((L)*((int)(aL))*COLORMAX))/ \ +  (((COLORMAX*(int)(aL))+(COLORMAX-(int)(aL))*(aS))) ) )      #define COMBINE_ALPHA_V(S,L,aS,aL,V) \    COMBINE_ALPHA((S),(L),(aS),((aL)*(V)))      #else   #ifdef COMBINE_METHOD_FLOAT      #define COMBINE_ALPHA(S,L,aS,aL) \    ( (COLORTYPE)( ( (S)*(1.0-C2F(aL))*C2F(aS) + (L)*C2F(aL) ) / \    ( (C2F(aL)+(1-C2F(aL))*C2F(aS))) ) )
pike.git/src/modules/Image/layers.c:382:    ((COLORTYPE)(COLORMAX*(C2F(aL)+(1.0-C2F(aL))*C2F(aS))))   #define COMBINE_ALPHA_SUM_V(aS,aL,V) \    COMBINE_ALPHA_SUM(aS,(aL)*(V))      #else /* unknown COMBINE_METHOD */   #error unknown COMBINE_METHOD   #endif /* COMBINE_METHOD_FLOAT */      #endif    - #define COMBINE(P,A) CCUT((DOUBLE_TO_INT(P))*(A)) - #define COMBINE_A(P,A) (DOUBLE_TO_COLORTYPE((P)*(A))) + #define COMBINE(P,A) CCUT(((int)(P))*(A)) + #define COMBINE_A(P,A) ((COLORTYPE)((P)*(A)))   #define COMBINE_V(P,V,A) CCUT((V)*(P)*(A))    - #define F2C(Z) (DOUBLE_TO_COLORTYPE(COLORMAX*(Z))) + #define F2C(Z) ((COLORTYPE)(COLORMAX*(Z)))      #define ALPHA_ADD(S,L,D,SA,LA,DA,C) \    if (!(LA)->C) (D)->C=(S)->C,(DA)->C=(SA)->C; \    else if (!(SA)->C) (D)->C=(L)->C,(DA)->C=(LA)->C; \    else if ((LA)->C==COLORMAX) (D)->C=(L)->C,(DA)->C=(LA)->C; \    else \    (D)->C=COMBINE_ALPHA((S)->C,(L)->C,(SA)->C,(LA)->C), \    (DA)->C=COMBINE_ALPHA_SUM((SA)->C,(LA)->C);      #define ALPHA_ADD_V_NOLA(L,S,D,SA,DA,V,C) \
pike.git/src/modules/Image/layers.c:459:    { \    (D)->C=COMBINE_ALPHA_V((S)->C,(L)->C,0,(LA)->C,V); \    } \    else \    { \    (D)->C=COMBINE_ALPHA_V((S)->C,(L)->C,(SA)->C,(LA)->C,V); \    } \    } while (0)       - static INLINE void smear_color(rgb_group *d,rgb_group s,int len) + static inline void smear_color(rgb_group *d,rgb_group s,int len)   {    while (len--)    *(d++)=s;   }      #define MAX3(X,Y,Z) MAXIMUM(MAXIMUM(X,Y),Z)   #define MIN3(X,Y,Z) MINIMUM(MINIMUM(X,Y),Z)      /* Pike_sp was renamed to not_sp by hubbe */ - static INLINE void rgb_to_hsv(rgb_group color, + static inline void rgb_to_hsv(rgb_group color,    double *hp,    double *not_sp,    double *vp)   {    double max,min,delta;    double r,g,b;       if (color.r==color.g && color.g==color.b)    {    *hp=*not_sp=0.0;
pike.git/src/modules/Image/layers.c:502:       *not_sp = (max - min)/max;       delta = max-min;       if(r==max) *hp = 6+(g-b)/delta;    else if(g==max) *hp = 2+(b-r)/delta;    else /*if(b==max)*/ *hp = 4+(r-g)/delta;   }    - static INLINE void hsv_to_rgb(double h,double s,double v,rgb_group *colorp) + static inline void hsv_to_rgb(double h,double s,double v,rgb_group *colorp)   {    if (s==0.0)    {    colorp->r=colorp->g=colorp->b=F2C(v);    return;    }      #define i floor(h)   #define f (h-i)   #define p F2C(v * (1 - s))   #define q F2C(v * (1 - (s * f)))   #define t F2C(v * (1 - (s * (1 -f))))   #define V F2C(v) -  switch(DOUBLE_TO_INT(i)) +  switch((int)(i))    {    case 6:    case 0: colorp->r = V; colorp->g = t; colorp->b = p; break;    case 7:    case 1: colorp->r = q; colorp->g = V; colorp->b = p; break;    case 2: colorp->r = p; colorp->g = V; colorp->b = t; break;    case 3: colorp->r = p; colorp->g = q; colorp->b = V; break;    case 4: colorp->r = t; colorp->g = p; colorp->b = V; break;    case 5: colorp->r = V; colorp->g = p; colorp->b = q; break;    default: Pike_fatal("unhandled case\n");    }   #undef V   #undef i   #undef f   #undef p   #undef q   #undef t   }    - static INLINE int hls_value(double n1, double n2, double hue) + static inline int hls_value(double n1, double n2, double hue)   {    double value;       if (hue > 255)    hue -= 255;    else if (hue < 0)    hue += 255;    if (hue < 42.5)    value = n1 + (n2 - n1) * (hue / 42.5);    else if (hue < 127.5)    value = n2;    else if (hue < 170)    value = n1 + (n2 - n1) * ((170 - hue) / 42.5);    else    value = n1;       return (int) (value * 255);   }       - static INLINE void hls_to_rgb(double h,double l,double s,rgb_group *rgb) + static inline void hls_to_rgb(double h,double l,double s,rgb_group *rgb)   {    double m1, m2;       if (s == 0)    {   /* achromatic case */    rgb->r = (COLORTYPE)l;    rgb->g = (COLORTYPE)l;    rgb->b = (COLORTYPE)l;    }
pike.git/src/modules/Image/layers.c:584:       m1 = (l / 127.5) - m2;      /* chromatic case */    rgb->r = hls_value (m1, m2, h + 85);    rgb->g = hls_value (m1, m2, h);    rgb->b = hls_value (m1, m2, h - 85);    }   }    - static INLINE void rgb_to_hls(rgb_group color, + static inline void rgb_to_hls(rgb_group color,    double *hue,    double *lightness,    double *saturation)   {    int r, g, b;    double h, l, s;    int min, max;    int delta;       r = color.r;
pike.git/src/modules/Image/layers.c:690:       smear_color(THIS->sfill,THIS->fill,SNUMPIXS);    smear_color(THIS->sfill_alpha,THIS->fill_alpha,SNUMPIXS);   }      static void free_layer(struct layer *UNUSED(l))   {    if (THIS->image) free_object(THIS->image);    if (THIS->alpha) free_object(THIS->alpha);    if (THIS->misc) free_mapping(THIS->misc); -  THIS->image=NULL; -  THIS->alpha=NULL; -  THIS->img=NULL; -  THIS->alp=NULL; +    }      static void exit_layer(struct object *UNUSED(dummy))   {    free_layer(THIS);   }      /*   **! method object set_image(object(Image.Image) image)   **! method object set_image(object(Image.Image) image,object(Image.Image) alpha_channel)
pike.git/src/modules/Image/layers.c:733:    if (THIS->alpha)    free_object(THIS->alpha);    THIS->alpha=NULL;    THIS->alp=NULL;       if (args>=1) {    if ( TYPEOF(Pike_sp[-args]) != T_OBJECT )    {    if (TYPEOF(Pike_sp[-args]) != T_INT ||    Pike_sp[-args].u.integer!=0) -  SIMPLE_BAD_ARG_ERROR("Image.Layer->set_image",1, -  "object(Image)|int(0)"); +  SIMPLE_ARG_TYPE_ERROR("set_image",1,"Image.Image|int(0..0)");    } -  else if ((img=(struct image*) -  get_storage(Pike_sp[-args].u.object,image_program))) +  else if ((img=get_storage(Pike_sp[-args].u.object,image_program)))    {    THIS->image=Pike_sp[-args].u.object;    add_ref(THIS->image);    THIS->img=img;    THIS->xsize=img->xsize;    THIS->ysize=img->ysize;    }    else -  SIMPLE_BAD_ARG_ERROR("Image.Layer->set_image",1, -  "object(Image)|int(0)"); +  SIMPLE_ARG_TYPE_ERROR("set_image",1, "Image.Image|int(0..0)");    }       if (args>=2) {    if ( TYPEOF(Pike_sp[1-args]) != T_OBJECT )    {    if (TYPEOF(Pike_sp[1-args]) != T_INT ||    Pike_sp[1-args].u.integer!=0) -  SIMPLE_BAD_ARG_ERROR("Image.Layer->set_image",2, -  "object(Image)|int(0)"); +  SIMPLE_ARG_TYPE_ERROR("set_image",2, "Image.Image|int(0..0)");    } -  else if ((img=(struct image*) -  get_storage(Pike_sp[1-args].u.object,image_program))) +  else if ((img=get_storage(Pike_sp[1-args].u.object,image_program)))    {    if (THIS->img &&    (img->xsize!=THIS->xsize ||    img->ysize!=THIS->ysize)) -  SIMPLE_BAD_ARG_ERROR("Image.Layer->set_image",2, -  "image of same size"); +  SIMPLE_ARG_TYPE_ERROR("set_image",2, "image of same size");    if (!THIS->img)    {    THIS->xsize=img->xsize;    THIS->ysize=img->ysize;    }    THIS->alpha=Pike_sp[1-args].u.object;    add_ref(THIS->alpha);    THIS->alp=img;    }    else -  SIMPLE_BAD_ARG_ERROR("Image.Layer->set_image",2, -  "object(Image)|int(0)"); +  SIMPLE_ARG_TYPE_ERROR("set_image",2,"Image.Image|int(0..0)");    }       pop_n_elems(args);    ref_push_object(THISOBJ);   }      static void image_layer_get_misc_value( INT32 args )   {    if( args != 1 )    Pike_error("Wrong number of arguments to get_misc_value\n");
pike.git/src/modules/Image/layers.c:849:   **! method object set_alpha_value(float value)   **! method float alpha_value()   **! Set/get the general alpha value of this layer.   **! This is a float value between 0 and 1,   **! and is multiplied with the alpha channel.   */      static void image_layer_set_alpha_value(INT32 args)   {    FLOAT_TYPE f; -  get_all_args("Image.Layer->set_alpha_value",args,"%F",&f); +  get_all_args(NULL,args,"%F",&f);    if (f<0.0 || f>1.0) -  SIMPLE_BAD_ARG_ERROR("Image.Layer->set_alpha_value",1,"float(0..1)"); +  SIMPLE_ARG_TYPE_ERROR("set_alpha_value",1,"float(0..1)");    THIS->alpha_value=f;    pop_n_elems(args);    ref_push_object(THISOBJ);   }      static void image_layer_alpha_value(INT32 args)   {    pop_n_elems(args);    push_float(THIS->alpha_value);   }
pike.git/src/modules/Image/layers.c:1062:   **!   **! note:   **! image and alpha channel must be of the same size,   **! or canceled.   */      static void image_layer_set_mode(INT32 args)   {    int i;    if (args!=1) -  SIMPLE_TOO_FEW_ARGS_ERROR("Image.Layer->set_mode",1); +  SIMPLE_WRONG_NUM_ARGS_ERROR("set_mode",1);    if (TYPEOF(Pike_sp[-args]) != T_STRING) -  SIMPLE_BAD_ARG_ERROR("Image.Layer->set_mode",1,"string"); +  SIMPLE_ARG_TYPE_ERROR("set_mode",1,"string");       for (i=0; i<LAYER_MODES; i++)    if (Pike_sp[-args].u.string==layer_mode[i].ps)    {    THIS->row_func=layer_mode[i].func;    THIS->optimize_alpha=layer_mode[i].optimize_alpha;    THIS->really_optimize_alpha=really_optimize_p(THIS);       pop_n_elems(args);    ref_push_object(THISOBJ);    return;    }    -  SIMPLE_BAD_ARG_ERROR("Image.Layer->set_mode",1,"existing mode"); +  SIMPLE_ARG_TYPE_ERROR("set_mode",1,"existing mode");   }      static void image_layer_mode(INT32 args)   {    int i;    pop_n_elems(args);       for (i=0; i<LAYER_MODES; i++)    if (THIS->row_func==layer_mode[i].func)    {
pike.git/src/modules/Image/layers.c:1135:   **! method object fill()   **! method object fill_alpha()   **! Set/query fill color and alpha, ie the color used "outside" the   **! image. This is mostly useful if you want to "frame"   **! a layer.   */      static void image_layer_set_fill(INT32 args)   {    if (!args) -  SIMPLE_TOO_FEW_ARGS_ERROR("Image.Layer->set_fill",1); +  SIMPLE_WRONG_NUM_ARGS_ERROR("set_fill",1);       if (TYPEOF(Pike_sp[-args]) == T_INT && !Pike_sp[-args].u.integer)    THIS->fill=black;    else    if (!image_color_arg(-args,&(THIS->fill))) -  SIMPLE_BAD_ARG_ERROR("Image.Layer->set_fill",1,"color"); +  SIMPLE_ARG_TYPE_ERROR("set_fill",1,"Image.Color");       smear_color(THIS->sfill,THIS->fill,SNUMPIXS);       THIS->fill_alpha=white;    if (args>1) {    if (TYPEOF(Pike_sp[1-args]) == T_INT && !Pike_sp[1-args].u.integer)    ; /* white is good */    else    if (!image_color_arg(1-args,&(THIS->fill_alpha)))    {    smear_color(THIS->sfill_alpha,THIS->fill_alpha,SNUMPIXS); -  SIMPLE_BAD_ARG_ERROR("Image.Layer->set_fill",2,"color"); +  SIMPLE_ARG_TYPE_ERROR("set_fill",2,"Image.Color");    }    }    smear_color(THIS->sfill_alpha,THIS->fill_alpha,SNUMPIXS);      #if 0    {    int i;    for (i=0; i<SNUMPIXS; i++)    fprintf(stderr,"#%02x%02x%02x ",THIS->sfill_alpha[i].r,THIS->sfill_alpha[i].g,THIS->sfill_alpha[i].b);    fprintf(stderr,"\n");
pike.git/src/modules/Image/layers.c:1204:   **! Set/query layer offset.   **!   **! method int xsize()   **! method int ysize()   **! Query layer offset. This is the same as layer   **! image/alpha image size.   */      static void image_layer_set_offset(INT32 args)   { -  get_all_args("Image.Layer->set_offset",args,"%d%d", /* INT32! */ +  get_all_args(NULL,args,"%d%d", /* INT32! */    &(THIS->xoffs),&(THIS->yoffs));    pop_n_elems(args);    ref_push_object(THISOBJ);   }      static void image_layer_xoffset(INT32 args)   {    pop_n_elems(args);    push_int(THIS->xoffs);   }
pike.git/src/modules/Image/layers.c:1245:   **! method object set_tiled(int yes)   **! method int tiled()   **! Set/query <i>tiled</i> flag. If set, the   **! image and alpha channel will be tiled rather   **! then framed by the <ref>fill</ref> values.   */      static void image_layer_set_tiled(INT32 args)   {    INT_TYPE tiled; -  get_all_args("Image.Layer->set_offset",args,"%i",&tiled); +  get_all_args(NULL,args,"%i",&tiled);    THIS->tiled=!!tiled;    THIS->really_optimize_alpha=really_optimize_p(THIS);    pop_n_elems(args);    ref_push_object(THISOBJ);   }      static void image_layer_tiled(INT32 args)   {    pop_n_elems(args);    push_int(THIS->tiled);
pike.git/src/modules/Image/layers.c:1313:   **! values and fill the whole layer with an   **! opaque color.   **!   **! All values can be modified after object creation.   **!   **! note:   **! image and alpha channel must be of the same size.   **!   */    - static INLINE void try_parameter(char *a,void (*f)(INT32)) + static inline void try_parameter(char *a,void (*f)(INT32))   {    stack_dup();    push_text(a);    f_index(2);       if (!IS_UNDEFINED(Pike_sp-1))    f(1);    pop_stack();   }    - static INLINE void try_parameter_pair(char *a,char *b,void (*f)(INT32)) + static inline void try_parameter_pair(char *a,char *b,void (*f)(INT32))   {    stack_dup(); /* map map */    stack_dup(); /* map map map */    push_text(a); /* map map map a */    f_index(2); /* map map map[a] */    stack_swap(); /* map map[a] map */    push_text(b); /* map map[a] map b */    f_index(2); /* map map[a] map[b] */       if (!IS_UNDEFINED(Pike_sp-2) ||
pike.git/src/modules/Image/layers.c:1360:    pop_n_elems(args-1);    try_parameter_pair("image","alpha",image_layer_set_image);       try_parameter("mode",image_layer_set_mode);    try_parameter("alpha_value",image_layer_set_alpha_value);       try_parameter_pair("xoffset","yoffset",image_layer_set_offset);    try_parameter_pair("fill","fill_alpha",image_layer_set_fill);    try_parameter("tiled",image_layer_set_tiled);    pop_stack(); -  return; +     }    else if (TYPEOF(Pike_sp[-args]) == T_INT && args>1    && TYPEOF(Pike_sp[1-args]) == T_INT)    {    rgb_group col=black,alpha=white;    -  get_all_args("Image.Layer",args,"%d%d", /* watch the type: INT32 */ +  get_all_args(NULL,args,"%d%d", /* watch the type: INT32 */    &(THIS->xsize),&(THIS->ysize));    if (args>2)    if (!image_color_arg(2-args,&col)) -  SIMPLE_BAD_ARG_ERROR("Image.Layer",3,"Image.Color"); +  SIMPLE_ARG_TYPE_ERROR("create",3,"Image.Color");       if (args>3)    if (!image_color_arg(3-args,&alpha)) -  SIMPLE_BAD_ARG_ERROR("Image.Layer",4,"Image.Color"); +  SIMPLE_ARG_TYPE_ERROR("create",4,"Image.Color"); +  pop_n_elems(args);       push_int(THIS->xsize);    push_int(THIS->ysize);    push_int(col.r);    push_int(col.g);    push_int(col.b);    push_object(clone_object(image_program,5));       push_int(THIS->xsize);    push_int(THIS->ysize);    push_int(alpha.r);    push_int(alpha.g);    push_int(alpha.b);    push_object(clone_object(image_program,5));       image_layer_set_image(2); -  -  pop_n_elems(args); +  pop_stack();    }    else if (TYPEOF(Pike_sp[-args]) == T_OBJECT || args>1)    {    if (args>2)    {    image_layer_set_mode(args-2); -  pop_stack(); +  pop_n_elems(args-2);    args=2;    }    image_layer_set_image(args);    pop_stack();    }    else -  SIMPLE_BAD_ARG_ERROR("Image.Layer",1,"mapping|int|Image.Image"); +  SIMPLE_ARG_TYPE_ERROR("create",1,"mapping|int|Image.Image");   }      /*** layer object *****************************************/      /*   **! method mapping(string:mixed)|string cast()   **! ([ "xsize":int,   **! "ysize":int,   **! "image":image,   **! "alpha":image,   **! "xoffset":int,   **! "yoffset":int,   **! "fill":image,   **! "fill_alpha":image   **! "tiled":int,   **! "mode":string   **! ])    */   static void image_layer_cast(INT32 args)   { -  +  struct pike_string *type; +     if (!args) -  SIMPLE_TOO_FEW_ARGS_ERROR("Image.Layer->cast",1); -  if (TYPEOF(Pike_sp[-args]) == T_STRING || -  Pike_sp[-args].u.string->size_shift) +  SIMPLE_WRONG_NUM_ARGS_ERROR("cast",1); +  +  type = Pike_sp[-args].u.string; +  pop_n_elems(args); /* type have at least one more reference. */ +  +  if (type == literal_mapping_string)    { -  if (strncmp(Pike_sp[-args].u.string->str,"mapping",7)==0) -  { +     int n=0; -  pop_n_elems(args); +     -  push_constant_text("xsize"); push_int(THIS->xsize); n++; -  push_constant_text("ysize"); push_int(THIS->ysize); n++; -  push_constant_text("image"); image_layer_image(0); n++; -  push_constant_text("alpha"); image_layer_alpha(0); n++; -  push_constant_text("xoffset"); push_int(THIS->xoffs); n++; -  push_constant_text("yoffset"); push_int(THIS->yoffs); n++; -  push_constant_text("alpha_value"); push_float(THIS->alpha_value); n++; -  push_constant_text("fill"); image_layer_fill(0); n++; -  push_constant_text("fill_alpha"); image_layer_fill_alpha(0); n++; -  push_constant_text("tiled"); push_int(THIS->tiled); n++; -  push_constant_text("mode"); image_layer_mode(0); n++; +  push_static_text("xsize"); push_int(THIS->xsize); n++; +  push_static_text("ysize"); push_int(THIS->ysize); n++; +  push_static_text("image"); image_layer_image(0); n++; +  push_static_text("alpha"); image_layer_alpha(0); n++; +  push_static_text("xoffset"); push_int(THIS->xoffs); n++; +  push_static_text("yoffset"); push_int(THIS->yoffs); n++; +  push_static_text("alpha_value"); push_float(THIS->alpha_value); n++; +  push_static_text("fill"); image_layer_fill(0); n++; +  push_static_text("fill_alpha"); image_layer_fill_alpha(0); n++; +  push_static_text("tiled"); push_int(THIS->tiled); n++; +  push_static_text("mode"); image_layer_mode(0); n++;       f_aggregate_mapping(n*2); -  -  return; +     } -  else if (strncmp(Pike_sp[-args].u.string->str,"string",6)==0) +  else if (type == literal_string_string)    {    size_t size = THIS->xsize*THIS->ysize, i;    struct pike_string *s = begin_shared_string(size*4);    rgb_group *img = 0;    rgb_group *alp = 0;    -  pop_n_elems(args); +     if(THIS->img)    img = THIS->img->img;    if(THIS->alp)    alp = THIS->alp->img;       if(img && alp)    for(i=0; i<size; i++) {    s->str[i*4+0] = img[i].r;    s->str[i*4+1] = img[i].g;    s->str[i*4+2] = img[i].b;
pike.git/src/modules/Image/layers.c:1492:    for(i=0; i<size; i++) {    s->str[i*4+0] = 255;    s->str[i*4+1] = 255;    s->str[i*4+2] = 255;    s->str[i*4+3] = alp[i].r;    }    else    memset(s->str, 0, size*4);       push_string(end_shared_string(s)); -  return; +     } -  +  else +  push_undefined();   } -  SIMPLE_BAD_ARG_ERROR("Image.Colortable->cast",1, -  "string(\"mapping\"|\"string\")"); +     - } -  +    /*** layer mode definitions ***************************/      static void lm_normal(rgb_group *s,rgb_group *l,rgb_group *d,    rgb_group *sa,rgb_group *la,rgb_group *da,    int len,double alpha)   {    /* la may be NULL, no other */       if (alpha==0.0) /* optimized */    {   #ifdef LAYERS_DUAL -  MEMCPY(d,s,sizeof(rgb_group)*len); -  MEMCPY(da,sa,sizeof(rgb_group)*len); +  memcpy(d,s,sizeof(rgb_group)*len); +  memcpy(da,sa,sizeof(rgb_group)*len);   #endif    return;    }    else if (alpha==1.0)    {    if (!la) /* no layer alpha => full opaque */    { -  MEMCPY(d,l,sizeof(rgb_group)*len); +  memcpy(d,l,sizeof(rgb_group)*len);    smear_color(da,white,len);    }    else    {    while (len--)    {    if (la->r==0 && la->g==0 && la->b==0)    {    *d=*s;    *da=*sa;
pike.git/src/modules/Image/layers.c:1577:    ALPHA_ADD_V(s,l,d,sa,la,da,alpha,r);    ALPHA_ADD_V(s,l,d,sa,la,da,alpha,g);    ALPHA_ADD_V(s,l,d,sa,la,da,alpha,b);       l++; s++; la++; sa++; da++; d++;    }    return;    }   }    -  - #if defined(__ECL) && 0 - #define WARN_TRACE(X) static char PIKE_CONCAT(foo__, X) (double d) { return (char)d; }; - #else /* !__ECL */ - #define WARN_TRACE(X) - #endif /* __ECL */ -  +    /* operators from template */      #define L_COPY_ALPHA      #define LM_FUNC lm_add   #define L_TRUNC(X) MINIMUM(255,(X))   #define L_OPER(A,B) ((A)+(int)(B))   #define L_MMX_OPER(A,MMXR) paddusb_m2r(A,MMXR) - WARN_TRACE(1) +    #include "layer_oper.h"   #undef L_MMX_OPER   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER    -  + #if 0   #define LM_FUNC lm_a_add   #define L_TRUNC(X) MINIMUM(255,(X))   #define L_OPER(A,B) ((A)+(int)(B))   #define L_MMX_OPER(A,MMXR) paddusb_m2r(A,MMXR) - WARN_TRACE(1) +    #include "layer_oper.h"   #undef L_MMX_OPER   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER -  + #endif      #define LM_FUNC lm_subtract   #define L_TRUNC(X) MAXIMUM(0,(X))   #define L_OPER(A,B) ((A)-(int)(B))   #define L_MMX_OPER(A,MMXR) psubusb_m2r(A,MMXR) - WARN_TRACE(2) +    #include "layer_oper.h"   #undef L_MMX_OPER   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_multiply   #define L_TRUNC(X) (X)   #define L_OPER(A,B) CCUT((A)*(int)(B)) - WARN_TRACE(3) +    #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_divide   #define L_TRUNC(X) MINIMUM(255,(X)) - #define L_OPER(A,B) MINIMUM( DOUBLE_TO_INT((A)/C2F(1+(int)(B))), COLORMAX) - WARN_TRACE(4) + #define L_OPER(A,B) MINIMUM( (int)((A)/C2F(1+(int)(B))), COLORMAX)   #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_negdivide   #define L_TRUNC(X) MINIMUM(255,(X)) - #define L_OPER(A,B) 1.0-MINIMUM( DOUBLE_TO_INT((A)/C2F(1+(int)(B))), COLORMAX) - WARN_TRACE(4) + #define L_OPER(A,B) 1.0-MINIMUM( (int)((A)/C2F(1+(int)(B))), COLORMAX) +    #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_modulo - #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X)) + #define L_TRUNC(X) ((COLORTYPE)(X))   #define L_OPER(A,B) ((A)%((B)?(B):1)) - WARN_TRACE(5) +    #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define L_USE_SA      #define LM_FUNC lm_invsubtract   #define L_TRUNC(X) MAXIMUM(0,(X))   #define L_OPER(A,B) ((B)-(int)(A)) - WARN_TRACE(6) +    #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_invdivide   #define L_TRUNC(X) MINIMUM(255,(X)) - #define L_OPER(A,B) MINIMUM( DOUBLE_TO_INT((B)/C2F(1+(int)(A))), COLORMAX) - WARN_TRACE(7) + #define L_OPER(A,B) MINIMUM( (int)((B)/C2F(1+(int)(A))), COLORMAX)   #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_invmodulo - #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X)) + #define L_TRUNC(X) ((COLORTYPE)(X))   #define L_OPER(A,B) ((B)%((A)?(A):1)) - WARN_TRACE(8) +    #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_idivide   #define L_TRUNC(X) MINIMUM(255,(X)) - #define L_OPER(A,B) MINIMUM( DOUBLE_TO_INT((A)/C2F(COLORMAX+1-(int)(B))), COLORMAX) - WARN_TRACE(4) + #define L_OPER(A,B) MINIMUM( (int)((A)/C2F(COLORMAX+1-(int)(B))), COLORMAX)   #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_imultiply   #define L_TRUNC(X) (X)   #define L_OPER(A,B) CCUT((A)*(COLORMAX-(int)(B))) - WARN_TRACE(3) +    #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_invidivide   #define L_TRUNC(X) MINIMUM(255,(X)) - #define L_OPER(A,B) MINIMUM( DOUBLE_TO_INT((B)/C2F(COLORMAX+1-(int)(A))), COLORMAX) - WARN_TRACE(7) + #define L_OPER(A,B) MINIMUM( (int)((B)/C2F(COLORMAX+1-(int)(A))), COLORMAX)   #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #undef L_USE_SA      #define LM_FUNC lm_difference - #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X)) + #define L_TRUNC(X) ((COLORTYPE)(X))   #define L_OPER(A,B) abs((A)-(B)) - WARN_TRACE(9) +    #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_max - #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X)) + #define L_TRUNC(X) ((COLORTYPE)(X))   #define L_OPER(A,B) MAXIMUM((A),(B)) - WARN_TRACE(10) +    #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_min - #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X)) + #define L_TRUNC(X) ((COLORTYPE)(X))   #define L_OPER(A,B) MINIMUM((A),(B)) - WARN_TRACE(11) +    #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_bitwise_and - #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X)) + #define L_TRUNC(X) ((COLORTYPE)(X))   #define L_OPER(A,B) ((A)&(B)) - WARN_TRACE(12) +    #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_bitwise_or - #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X)) + #define L_TRUNC(X) ((COLORTYPE)(X))   #define L_OPER(A,B) ((A)|(B)) - WARN_TRACE(13) +    #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_bitwise_xor - #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X)) + #define L_TRUNC(X) ((COLORTYPE)(X))   #define L_OPER(A,B) ((A)^(B)) - WARN_TRACE(14) +    #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #undef L_COPY_ALPHA      #define LM_FUNC lm_equal - #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X)) + #define L_TRUNC(X) ((COLORTYPE)(X))   #define L_OPER(A,B) (((A)==(B))?COLORMAX:0) - WARN_TRACE(15) +    #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_not_equal - #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X)) + #define L_TRUNC(X) ((COLORTYPE)(X))   #define L_OPER(A,B) (((A)!=(B))?COLORMAX:0) - WARN_TRACE(16) +    #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_less - #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X)) + #define L_TRUNC(X) ((COLORTYPE)(X))   #define L_OPER(A,B) (((A)>(B))?COLORMAX:0) - WARN_TRACE(17) +    #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_more - #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X)) + #define L_TRUNC(X) ((COLORTYPE)(X))   #define L_OPER(A,B) (((A)<(B))?COLORMAX:0) - WARN_TRACE(18) +    #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_less_or_equal - #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X)) + #define L_TRUNC(X) ((COLORTYPE)(X))   #define L_OPER(A,B) (((A)>=(B))?COLORMAX:0) - WARN_TRACE(19) +    #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      #define LM_FUNC lm_more_or_equal - #define L_TRUNC(X) (DOUBLE_TO_COLORTYPE(X)) + #define L_TRUNC(X) ((COLORTYPE)(X))   #define L_OPER(A,B) (((A)<=(B))?COLORMAX:0) - WARN_TRACE(20) +    #include "layer_oper.h"   #undef LM_FUNC   #undef L_TRUNC   #undef L_OPER      /* logic functions */      #define L_LOGIC(A,B,C) (((A)&&(B)&&(C))?white:black)   #define LM_FUNC lm_logic_equal   #define L_OPER(A,B) ((A)==(B))   #define L_TRANS white - WARN_TRACE(21) +    #include "layer_oper.h"   #undef L_TRANS   #undef L_OPER   #undef LM_FUNC   #undef L_LOGIC      #define L_LOGIC(A,B,C) (((A)||(B)||(C))?white:black)   #define LM_FUNC lm_logic_not_equal   #define L_OPER(A,B) ((A)!=(B))   #define L_TRANS black - WARN_TRACE(22) +    #include "layer_oper.h"   #undef L_TRANS   #undef L_OPER   #undef LM_FUNC   #undef L_LOGIC      #define L_LOGIC(A,B,C) (((A)&&(B)&&(C))?white:black)   #define LM_FUNC lm_logic_strict_less   #define L_OPER(A,B) ((A)>(B))   #define L_TRANS white - WARN_TRACE(23) +    #include "layer_oper.h"   #undef L_TRANS   #undef L_OPER   #undef LM_FUNC   #undef L_LOGIC      #define L_LOGIC(A,B,C) (((A)&&(B)&&(C))?white:black)   #define LM_FUNC lm_logic_strict_more   #define L_OPER(A,B) ((A)<(B))   #define L_TRANS white - WARN_TRACE(24) +    #include "layer_oper.h"   #undef L_TRANS   #undef L_OPER   #undef LM_FUNC   #undef L_LOGIC      #define L_LOGIC(A,B,C) (((A)&&(B)&&(C))?white:black)   #define LM_FUNC lm_logic_strict_less_or_equal   #define L_OPER(A,B) ((A)>=(B))   #define L_TRANS white - WARN_TRACE(25) +    #include "layer_oper.h"   #undef L_TRANS   #undef L_OPER   #undef LM_FUNC   #undef L_LOGIC      #define L_LOGIC(A,B,C) (((A)&&(B)&&(C))?white:black)   #define LM_FUNC lm_logic_strict_more_or_equal   #define L_OPER(A,B) ((A)<=(B))   #define L_TRANS white - WARN_TRACE(26) +    #include "layer_oper.h"   #undef L_TRANS   #undef L_OPER   #undef LM_FUNC   #undef L_LOGIC      /* channels from template */      /* replace rgb by alpha channel */   
pike.git/src/modules/Image/layers.c:2218:      /* special modes */      static void lm_dissolve(rgb_group *s,rgb_group *l,rgb_group *d,    rgb_group *sa,rgb_group *la,rgb_group *da,    int len,double alpha)   {    if (alpha==0.0)    {   #ifdef LAYERS_DUAL -  MEMCPY(d,s,sizeof(rgb_group)*len); -  MEMCPY(da,sa,sizeof(rgb_group)*len); +  memcpy(d,s,sizeof(rgb_group)*len); +  memcpy(da,sa,sizeof(rgb_group)*len);   #endif    return;    }    else if (alpha==1.0)    {    if (!la) /* no layer alpha => full opaque */    { -  MEMCPY(d,l,sizeof(rgb_group)*len); +  memcpy(d,l,sizeof(rgb_group)*len);    smear_color(da,white,len);    }    else -  +  { +  UINT64 *rnd; +  push_random_string(len*8); +  rnd = (UINT64*)Pike_sp[-1].u.string->str;    while (len--)    { -  if ((my_rand()%(255*255)) < +  if (rnd[len]%(255*255) <    (unsigned)(la->r*87 + la->g*127 + la->b*41))    *d=*l,*da=white;    else    *d=*s,*da=*sa;    l++; s++; la++; sa++; da++; d++;    } -  +  pop_stack();    } -  +  }    else    { -  int v = DOUBLE_TO_INT(COLORMAX*alpha); +  int v = (int)(COLORMAX*alpha);    if (!la) /* no layer alpha => full opaque */ -  +  { +  unsigned char *rnd; +  push_random_string(len); +  rnd = (unsigned char*)Pike_sp[-1].u.string->str;    while (len--)    { -  if ((my_rand()&255) < (unsigned)v) +  if (rnd[len] < (unsigned)v)    *d=*l,*da=white;    else    *d=*s,*da=*sa;    l++; s++; sa++; da++; d++;    } -  +  pop_stack(); +  }    else    { -  +  UINT64 *rnd; +  push_random_string(len*8); +  rnd = (UINT64*)Pike_sp[-1].u.string->str;    while (len--)    { -  if ((my_rand()%(255*255)) < +  if (rnd[len]%(255*255) <    (unsigned)((la->r*87 + la->g*127 + la->b*41)>>8)*v)    *d=*l,*da=white;    else    *d=*s,*da=*sa;    l++; s++; la++; sa++; da++; d++;    } -  +  pop_stack();    }    }   }      static void lm_behind(rgb_group *s,rgb_group *l,rgb_group *d,    rgb_group *sa,rgb_group *la,rgb_group *da,    int len,double alpha)   {    /* la may be NULL, no other */       if (alpha==0.0) /* optimized */    {   #ifdef LAYERS_DUAL -  MEMCPY(d,s,sizeof(rgb_group)*len); -  MEMCPY(da,sa,sizeof(rgb_group)*len); +  memcpy(d,s,sizeof(rgb_group)*len); +  memcpy(da,sa,sizeof(rgb_group)*len);   #endif    return;    }    else if (alpha==1.0)    while (len--)    {    if (sa->r==COLORMAX && sa->g==COLORMAX && sa->b==COLORMAX)    {    *d=*s;    *da=*sa;
pike.git/src/modules/Image/layers.c:2340:    {    ALPHA_ADD_V(l,s,d,(&white),sa,da,alpha,r);    ALPHA_ADD_V(l,s,d,(&white),sa,da,alpha,g);    ALPHA_ADD_V(l,s,d,(&white),sa,da,alpha,b);    }    l++; s++; sa++; d++; da++;    if (la) la++;    }   }    - static void lm_erase(rgb_group *s,rgb_group *l,rgb_group *d, + static void lm_erase(rgb_group *UNUSED(s),rgb_group *UNUSED(l),rgb_group *UNUSED(d),    rgb_group *sa,rgb_group *la,rgb_group *da,    int len,double alpha)   {    /* la may be NULL, no other */      #ifdef LAYERS_DUAL -  MEMCPY(d,s,sizeof(rgb_group)*len); +  memcpy(d,s,sizeof(rgb_group)*len);   #endif       if (alpha==1.0)    if (!la) /* full opaque */    smear_color(da,black,len);    else    while (len--)    {    da->r=CCUT(sa->r*(int)(COLORMAX-la->r));    da->g=CCUT(sa->g*(int)(COLORMAX-la->g));    da->b=CCUT(sa->b*(int)(COLORMAX-la->b));       la++; sa++; da++;    }    else    if (!la) /* full opaque */    {    rgb_group a; -  a.r=a.g=a.b=COLORMAX-DOUBLE_TO_COLORTYPE(alpha*COLORMAX); +  a.r=a.g=a.b=COLORMAX-(COLORTYPE)(alpha*COLORMAX);    smear_color(da,a,len);    }    else    while (len--)    { -  da->r=CCUT(sa->r*DOUBLE_TO_INT(COLORMAX-alpha*la->r)); -  da->g=CCUT(sa->g*DOUBLE_TO_INT(COLORMAX-alpha*la->g)); -  da->b=CCUT(sa->b*DOUBLE_TO_INT(COLORMAX-alpha*la->b)); +  da->r=CCUT(sa->r*(int)(COLORMAX-alpha*la->r)); +  da->g=CCUT(sa->g*(int)(COLORMAX-alpha*la->g)); +  da->b=CCUT(sa->b*(int)(COLORMAX-alpha*la->b));       la++; sa++; da++;    }   }      static void lm_spec_burn_alpha(struct layer *ly,    rgb_group *l, rgb_group *la,    rgb_group *s, rgb_group *sa,    rgb_group *d, rgb_group *da,    int len)      {    /* special optimized */    if (!la)    {   #ifdef LAYERS_DUAL -  MEMCPY(d,s,len*sizeof(rgb_group)); -  MEMCPY(da,sa,len*sizeof(rgb_group)); +  memcpy(d,s,len*sizeof(rgb_group)); +  memcpy(da,sa,len*sizeof(rgb_group));   #endif    return;    }       if (ly->alpha_value==1.0)    if (!l)    if (ly->fill.r!=0 ||    ly->fill.g!=0 ||    ly->fill.b!=0)    {
pike.git/src/modules/Image/layers.c:2417:    d->b=MINIMUM(s->b+la->b,COLORMAX);    da->r=MINIMUM(sa->r+la->r,COLORMAX);    da->g=MINIMUM(sa->g+la->g,COLORMAX);    da->b=MINIMUM(sa->b+la->b,COLORMAX);    da++; sa++; la++; d++; s++;    }    }    else    {   #ifdef LAYERS_DUAL -  MEMCPY(d,s,len*sizeof(rgb_group)); +  memcpy(d,s,len*sizeof(rgb_group));   #endif    while (len--)    {    da->r=MINIMUM(sa->r+la->r,COLORMAX);    da->g=MINIMUM(sa->g+la->g,COLORMAX);    da->b=MINIMUM(sa->b+la->b,COLORMAX);    da++; sa++; la++;    }    }    else
pike.git/src/modules/Image/layers.c:2459:    {    double alpha=ly->alpha_value;    while (len--)    {    if ((s->r==COLORMAX &&    s->g==COLORMAX &&    s->b==COLORMAX)    || !l)    {    *d=*s; -  da->r=MINIMUM(sa->r+DOUBLE_TO_COLORTYPE(alpha*la->r),COLORMAX); -  da->g=MINIMUM(sa->g+DOUBLE_TO_COLORTYPE(alpha*la->g),COLORMAX); -  da->b=MINIMUM(sa->b+DOUBLE_TO_COLORTYPE(alpha*la->b),COLORMAX); +  da->r=MINIMUM(sa->r+(COLORTYPE)(alpha*la->r),COLORMAX); +  da->g=MINIMUM(sa->g+(COLORTYPE)(alpha*la->g),COLORMAX); +  da->b=MINIMUM(sa->b+(COLORTYPE)(alpha*la->b),COLORMAX);    }    else    { -  d->r=s->r+DOUBLE_TO_COLORTYPE(alpha*l->r); -  d->g=s->g+DOUBLE_TO_COLORTYPE(alpha*l->g); -  d->b=s->b+DOUBLE_TO_COLORTYPE(alpha*l->b); +  d->r=s->r+(COLORTYPE)(alpha*l->r); +  d->g=s->g+(COLORTYPE)(alpha*l->g); +  d->b=s->b+(COLORTYPE)(alpha*l->b);    -  da->r=MINIMUM(sa->r+DOUBLE_TO_COLORTYPE(alpha*l->r),COLORMAX); -  da->g=MINIMUM(sa->g+DOUBLE_TO_COLORTYPE(alpha*l->g),COLORMAX); -  da->b=MINIMUM(sa->b+DOUBLE_TO_COLORTYPE(alpha*l->b),COLORMAX); +  da->r=MINIMUM(sa->r+(COLORTYPE)(alpha*l->r),COLORMAX); +  da->g=MINIMUM(sa->g+(COLORTYPE)(alpha*l->g),COLORMAX); +  da->b=MINIMUM(sa->b+(COLORTYPE)(alpha*l->b),COLORMAX);    }    da++; sa++; la++; s++; d++;    }    }   }      /*** the add-layer function ***************************/    - static INLINE void img_lay_first_line(struct layer *l, + static inline void img_lay_first_line(struct layer *l,    int xoffs,int xsize,    int y, /* in _this_ layer */    rgb_group *d,rgb_group *da)   {    if (!l->tiled)    {    rgb_group *s,*sa;    int len;       if (y<0 ||
pike.git/src/modules/Image/layers.c:2522:    da+=l->xoffs-xoffs;    }    else    {    if (s) s+=xoffs-l->xoffs;    if (sa) sa+=xoffs-l->xoffs;    len-=xoffs-l->xoffs;    }    if (len<xsize) /* copy bit, fill right */    { -  if (s) MEMCPY(d,s,len*sizeof(rgb_group)); +  if (s) memcpy(d,s,len*sizeof(rgb_group));    else smear_color(d,l->fill,len); -  if (sa) MEMCPY(da,sa,len*sizeof(rgb_group)); +  if (sa) memcpy(da,sa,len*sizeof(rgb_group));    else smear_color(da,white,len);       smear_color(d+len,l->fill,xsize-len);    smear_color(da+len,l->fill_alpha,xsize-len);    }    else /* copy rest */    { -  if (s) MEMCPY(d,s,xsize*sizeof(rgb_group)); +  if (s) memcpy(d,s,xsize*sizeof(rgb_group));    else smear_color(d,l->fill,xsize); -  if (sa) MEMCPY(da,sa,xsize*sizeof(rgb_group)); +  if (sa) memcpy(da,sa,xsize*sizeof(rgb_group));    else smear_color(da,white,xsize);    }    return;    }    else    {    rgb_group *s,*sa;       y%=l->ysize;    if (y<0) y+=l->ysize;
pike.git/src/modules/Image/layers.c:2559:    if (l->alp) sa=l->alp->img+y*l->xsize;    else smear_color(da,white,xsize),sa=NULL;       xoffs-=l->xoffs; /* position in source */    xoffs%=l->xsize;    if (xoffs<0) xoffs+=l->xsize;    if (xoffs)    {    int len=l->xsize-xoffs;    if (len>l->xsize) len=l->xsize; -  if (s) MEMCPY(d,s+xoffs,len*sizeof(rgb_group)); -  if (sa) MEMCPY(da,sa+xoffs,len*sizeof(rgb_group)); +  if (s) memcpy(d,s+xoffs,len*sizeof(rgb_group)); +  if (sa) memcpy(da,sa+xoffs,len*sizeof(rgb_group));    da+=len;    d+=len;    xsize-=len;    }    while (xsize>l->xsize)    { -  if (s) MEMCPY(d,s,l->xsize*sizeof(rgb_group)); -  if (sa) MEMCPY(d,sa,l->xsize*sizeof(rgb_group)); +  if (s) memcpy(d,s,l->xsize*sizeof(rgb_group)); +  if (sa) memcpy(d,sa,l->xsize*sizeof(rgb_group));    da+=l->xsize;    d+=l->xsize;    xsize-=l->xsize;    } -  if (s) MEMCPY(d,s,xsize*sizeof(rgb_group)); -  if (sa) MEMCPY(d,sa,xsize*sizeof(rgb_group)); +  if (s) memcpy(d,s,xsize*sizeof(rgb_group)); +  if (sa) memcpy(d,sa,xsize*sizeof(rgb_group));    }   }    - static INLINE void img_lay_stroke(struct layer *ly, + static inline void img_lay_stroke(struct layer *ly,    rgb_group *l,    rgb_group *la,    rgb_group *s,    rgb_group *sa,    rgb_group *d,    rgb_group *da,    int len)   {    if (len<0) Pike_error("internal error: stroke len < 0\n");    if (!ly->row_func) Pike_error("internal error: row_func=NULL\n");
pike.git/src/modules/Image/layers.c:2605:       if (l)    {    (ly->row_func)(s,l,d,sa,la,da,len,ly->alpha_value);    return;    }    if (!la && ly->really_optimize_alpha)    {   /* fprintf(stderr,"fast skip ly->yoffs=%d\n",ly->yoffs); */   #ifdef LAYERS_DUAL -  MEMCPY(d,s,len*sizeof(rgb_group)); -  MEMCPY(da,sa,len*sizeof(rgb_group)); +  memcpy(d,s,len*sizeof(rgb_group)); +  memcpy(da,sa,len*sizeof(rgb_group));   #endif    return;    }       if (!la &&    ly->fill_alpha.r==COLORMAX &&    ly->fill_alpha.g==COLORMAX &&    ly->fill_alpha.b==COLORMAX)    {    while (len>SNUMPIXS)    { -  (ly->row_func)(s,l?l:ly->sfill,d,sa,NULL,da, -  SNUMPIXS,ly->alpha_value); +  (ly->row_func)(s, ly->sfill, d, sa, NULL, da, +  SNUMPIXS, ly->alpha_value);    s+=SNUMPIXS; d+=SNUMPIXS;    sa+=SNUMPIXS;da+=SNUMPIXS; -  if (l) l+=SNUMPIXS; +     len-=SNUMPIXS;    }    if (len) -  (ly->row_func)(s,l?l:ly->sfill,d,sa,NULL,da,len,ly->alpha_value); +  (ly->row_func)(s, ly->sfill, d, sa, NULL, da, len, ly->alpha_value);    }    else    {   /* fprintf(stderr,"ly=%p len=%d\n",ly,len); */       while (len>SNUMPIXS)    { -  (ly->row_func)(s,l?l:ly->sfill,d,sa,la?la:ly->sfill_alpha,da, -  SNUMPIXS,ly->alpha_value); +  (ly->row_func)(s, ly->sfill, d, sa, la?la: ly->sfill_alpha, da, +  SNUMPIXS, ly->alpha_value);    s+=SNUMPIXS; d+=SNUMPIXS;    sa+=SNUMPIXS; da+=SNUMPIXS; -  if (l) l+=SNUMPIXS; +     if (la) la+=SNUMPIXS;    len-=SNUMPIXS;    }    if (len) -  (ly->row_func)(s,l?l:ly->sfill,d,sa,la?la:ly->sfill_alpha, -  da,len,ly->alpha_value); +  (ly->row_func)(s, ly->sfill, d, sa, la?la: ly->sfill_alpha, +  da, len, ly->alpha_value);    }   }    - static INLINE void img_lay_line(struct layer *ly, + static inline void img_lay_line(struct layer *ly,    rgb_group *s,rgb_group *sa,    int xoffs,int xsize,    int y, /* y in ly layer */    rgb_group *d,rgb_group *da)   {   /* fprintf(stderr,"tiled:%d xoffs:%d xsize:%d y:%d\n", */   /* ly->tiled,xoffs,xsize,y); */       if (!ly->tiled)    {
pike.git/src/modules/Image/layers.c:2778: Inside #if defined(LAYERS_DUAL)
   aline1=malloc(sizeof(rgb_group)*width + RGB_VEC_PAD);    line2=malloc(sizeof(rgb_group)*width + RGB_VEC_PAD);    aline2=malloc(sizeof(rgb_group)*width + RGB_VEC_PAD);    if (!line1 || !aline1    !line2 || !aline2)    {    if (line1) free(line1);    if (aline1) free(aline1);    if (line2) free(line2);    if (aline2) free(aline2); -  resource_error(NULL,0,0,"memory",4*(sizeof(rgb_group)*width + RGB_VEC_PAD), -  "Out of memory.\n"); +  out_of_memory_error(NULL, -1, 4*(sizeof(rgb_group)*width + RGB_VEC_PAD));    }   #endif       da=dest->alp->img;    d=dest->img->img;       /* loop over lines */    for (y=0; y<dest->ysize; y++)    {    if (layers>1 || layer[0]->row_func!=lm_normal ||
pike.git/src/modules/Image/layers.c:2906:   {    int layers,i,j;    struct layer **l;    struct object *o;    struct layer *dest;    struct array *a;    INT_TYPE xoffset=0,yoffset=0,xsize=0,ysize=0;    ONERROR err;       if (!args) -  SIMPLE_TOO_FEW_ARGS_ERROR("Image.lay",1); +  SIMPLE_WRONG_NUM_ARGS_ERROR("lay",1);       if (TYPEOF(Pike_sp[-args]) != T_ARRAY) -  SIMPLE_BAD_ARG_ERROR("Image.lay",1, -  "array(Image.Layer|mapping)"); +  SIMPLE_ARG_TYPE_ERROR("lay",1,"array(Image.Layer|mapping)");       if (args>1)    { -  get_all_args("Image.lay",args-1,"%i%i%i%i", +  get_all_args(NULL,args-1,"%i%i%i%i",    &xoffset,&yoffset,&xsize,&ysize);    if (xsize<1) -  SIMPLE_BAD_ARG_ERROR("Image.lay",4,"int(1..)"); +  SIMPLE_ARG_TYPE_ERROR("lay",4,"int(1..)");    if (ysize<1) -  SIMPLE_BAD_ARG_ERROR("Image.lay",5,"int(1..)"); +  SIMPLE_ARG_TYPE_ERROR("lay",5,"int(1..)");    }       layers=(a=Pike_sp[-args].u.array)->size;       if (!layers) /* dummy return empty layer */    {    pop_n_elems(args);    push_object(clone_object(image_layer_program,0));    return;    }       l=(struct layer**)xalloc(sizeof(struct layer *)*layers);       SET_ONERROR(err, free, l);       for (i=j=0; i<layers; i++)    {    if (TYPEOF(a->item[i]) == T_OBJECT)    { -  if (!(l[j]=(struct layer*)get_storage(a->item[i].u.object, +  if (!(l[j]=get_storage(a->item[i].u.object,    image_layer_program))) -  SIMPLE_BAD_ARG_ERROR("Image.lay",1, +  SIMPLE_ARG_TYPE_ERROR("lay",1,    "array(Image.Layer|mapping)");    }    else if (TYPEOF(a->item[i]) == T_MAPPING)    {    push_svalue(a->item+i);    push_object(o=clone_object(image_layer_program,1));    args++; -  l[j]=(struct layer*)get_storage(o,image_layer_program); +  l[j]=get_storage(o,image_layer_program);    }    else -  SIMPLE_BAD_ARG_ERROR("Image.lay",1, +  SIMPLE_ARG_TYPE_ERROR("lay",1,    "array(Image.Layer|mapping)");    if (l[j]->xsize && l[j]->ysize)    j++;    }       if (!(layers = j)) /* dummy return empty layer */    {    CALL_AND_UNSET_ONERROR(err);    pop_n_elems(args);    push_object(clone_object(image_layer_program,0));
pike.git/src/modules/Image/layers.c:3005:    if (l[i]->ysize+l[i]->yoffs-yoffset>ysize)    ysize=l[i]->ysize+l[i]->yoffs-yoffset;    }    }       /* get destination layer */    push_int(xsize);    push_int(ysize);    push_object(o=clone_object(image_layer_program,2));    -  dest=(struct layer*)get_storage(o,image_layer_program); +  dest=get_storage(o,image_layer_program);    dest->xoffs=xoffset;    dest->yoffs=yoffset;       /* ok, do it! */    img_lay(l,layers,dest);       CALL_AND_UNSET_ONERROR(err);       Pike_sp--;    pop_n_elems(args);    push_object(o);   }      /** image-object operations *************************/    - static INLINE struct layer *push_new_layer(void) + static inline struct layer *push_new_layer(void)   {    push_object(clone_object(image_layer_program,0)); -  return (struct layer*)get_storage(Pike_sp[-1].u.object,image_layer_program); +  return get_storage(Pike_sp[-1].u.object,image_layer_program);   }    - static INLINE struct layer *clone_this_layer(void) + static inline struct layer *clone_this_layer(void)   {    struct layer *l;    l=push_new_layer();    l->xsize=THIS->xsize;    l->ysize=THIS->ysize;    l->xoffs=THIS->xoffs;    l->yoffs=THIS->yoffs;    l->image=THIS->image;    l->alpha=THIS->alpha;    l->img=THIS->img;    l->alp=THIS->alp;    if (l->image) add_ref(l->image);    if (l->alpha) add_ref(l->alpha);    l->alpha_value=THIS->alpha_value;    l->fill=THIS->fill;    l->fill_alpha=THIS->fill_alpha; -  MEMCPY(l->sfill,THIS->sfill,sizeof(rgb_group)*SNUMPIXS); -  MEMCPY(l->sfill_alpha,THIS->sfill_alpha,sizeof(rgb_group)*SNUMPIXS); +  memcpy(l->sfill,THIS->sfill,sizeof(rgb_group)*SNUMPIXS); +  memcpy(l->sfill_alpha,THIS->sfill_alpha,sizeof(rgb_group)*SNUMPIXS);    l->tiled=THIS->tiled;    l->row_func=THIS->row_func;    l->optimize_alpha=THIS->optimize_alpha;    l->really_optimize_alpha=THIS->really_optimize_alpha;    if (THIS->misc) l->misc = copy_mapping( THIS->misc );    return l;   }      /*   **! module Image
pike.git/src/modules/Image/layers.c:3091:   **! if there was no cropping to be done.   */      static void image_layer_crop(INT32 args)   {    struct layer *l;    INT_TYPE x,y,xz,yz,xi,yi;    int zot=0;    struct image *img = NULL;    -  get_all_args("Image.Layer->crop",args,"%i%i%i%i",&x,&y,&xz,&yz); +  get_all_args(NULL,args,"%i%i%i%i",&x,&y,&xz,&yz);       l=clone_this_layer();    if (x<=l->xoffs) x=l->xoffs; else zot++;    if (y<=l->yoffs) y=l->yoffs; else zot++;    if (l->xsize+l->xoffs<=x+xz) xz=l->xsize-(x-l->xoffs); else zot++;    if (l->ysize+l->yoffs<=y+yz) yz=l->ysize-(y-l->yoffs); else zot++;       xi=x-l->xoffs;    yi=y-l->yoffs;    l->xoffs=x;
pike.git/src/modules/Image/layers.c:3118:    f_index(2);    push_int(xi);    push_int(yi);    push_int(xz+xi-1);    push_int(yz+yi-1);    push_int(THIS->fill.r);    push_int(THIS->fill.g);    push_int(THIS->fill.b);    f_call_function(8);    if (TYPEOF(Pike_sp[-1]) != T_OBJECT || -  !(img=(struct image*)get_storage(Pike_sp[-1].u.object,image_program))) +  !(img=get_storage(Pike_sp[-1].u.object,image_program)))    Pike_error("No image returned from image->copy\n");    if (img->xsize!=xz || img->ysize!=yz)    Pike_error("Image returned from image->copy had "    "unexpected size (%"PRINTPIKEINT"d,%"PRINTPIKEINT"d,"    " expected %"PRINTPIKEINT"d,%"PRINTPIKEINT"d)\n",    img->xsize,img->ysize,xz,yz);       free_object(l->image);    l->image=Pike_sp[-1].u.object;    Pike_sp--;
pike.git/src/modules/Image/layers.c:3147:    f_index(2);    push_int(xi);    push_int(yi);    push_int(xz+xi-1);    push_int(yz+yi-1);    push_int(THIS->fill_alpha.r);    push_int(THIS->fill_alpha.g);    push_int(THIS->fill_alpha.b);    f_call_function(8);    if (TYPEOF(Pike_sp[-1]) != T_OBJECT || -  !(img=(struct image*)get_storage(Pike_sp[-1].u.object,image_program))) +  !(img=get_storage(Pike_sp[-1].u.object,image_program)))    Pike_error("No image returned from alpha->copy\n");    if (img->xsize!=xz || img->ysize!=yz)    Pike_error("Image returned from alpha->copy had "    "unexpected size (%"PRINTPIKEINT"d,%"PRINTPIKEINT"d, "    "expected %"PRINTPIKEINT"d,%"PRINTPIKEINT"d)\n",    img->xsize,img->ysize,xz,yz);    free_object(l->alpha);    l->alpha=Pike_sp[-1].u.object;    Pike_sp--;    dmalloc_touch_svalue(Pike_sp);
pike.git/src/modules/Image/layers.c:3199:   **!   **! see also: crop, Image.Image->autocrop   */      static void image_layer_find_autocrop(INT32 args)   {    INT32 x1=0,y1=0,x2=THIS->xsize-1,y2=THIS->ysize-1;    INT_TYPE l=1,r=1,t=1,b=1;       if (args>3) -  get_all_args("find_autocrop",args,"%i%i%i%i",&l,&r,&t,&b); +  get_all_args(NULL,args,"%i%i%i%i",&l,&r,&t,&b);       if (!THIS->tiled) {    if (THIS->alpha)    {    img_find_autocrop(THIS->alp, &x1,&y1,&x2,&y2,    0,l,r,t,b,1,THIS->fill_alpha);    if (THIS->image &&    (THIS->fill_alpha.r!=0 ||    THIS->fill_alpha.g!=0 || /* non-transparent fill */    THIS->fill_alpha.b!=0)) /* check image too */
pike.git/src/modules/Image/layers.c:3250:    dmalloc_touch_svalue(Pike_sp);    push_array_items(Pike_sp->u.array); /* frees */    image_layer_crop(4);   }         static void image_layer__sprintf( INT32 args )   {    int x;    if (args != 2 ) -  SIMPLE_TOO_FEW_ARGS_ERROR("_sprintf",2); +  SIMPLE_WRONG_NUM_ARGS_ERROR("_sprintf",2);    if (TYPEOF(Pike_sp[-args]) != T_INT) -  SIMPLE_BAD_ARG_ERROR("_sprintf",0,"integer"); +  SIMPLE_ARG_TYPE_ERROR("_sprintf",0,"int");    if (TYPEOF(Pike_sp[1-args]) != T_MAPPING) -  SIMPLE_BAD_ARG_ERROR("_sprintf",1,"mapping"); +  SIMPLE_ARG_TYPE_ERROR("_sprintf",1,"mapping");       x = Pike_sp[-2].u.integer;       pop_n_elems( 2 );    switch( x )    {    case 't': -  push_constant_text("Image.Layer"); +  push_static_text("Image.Layer");    return;    case 'O': -  push_constant_text( "Image.Layer(%O i=%O a=%O)" ); +  push_static_text( "Image.Layer(%O i=%O a=%O)" );    image_layer_mode(0);    if( THIS->image ) ref_push_object( THIS->image ); else push_int( 0 );    if( THIS->alpha ) ref_push_object( THIS->alpha ); else push_int( 0 );    f_sprintf( 4 );    return;    default:    push_int(0);    return;    }   }
pike.git/src/modules/Image/layers.c:3304:    tOr4(tFunc(tNone,tVoid),    tFunc(tObj tOr(tObj,tVoid) tOr(tString,tVoid),tVoid),    tFunc(tLayerMap,tVoid),    tFunc(tInt tInt    tOr(tColor,tVoid) tOr(tColor,tVoid),tVoid)),0);          ADD_FUNCTION("_sprintf",image_layer__sprintf,    tFunc(tInt tMapping,tString),0);    ADD_FUNCTION("cast",image_layer_cast, -  tFunc(tString,tMapping),0); +  tFunc(tString,tOr(tMapping,tString)),ID_PROTECTED);          ADD_FUNCTION("clone",image_layer_clone,    tFunc(tNone,tObj),0);       /* set */       ADD_FUNCTION("set_offset",image_layer_set_offset,tFunc(tInt tInt,tObj),0);    ADD_FUNCTION("set_image",image_layer_set_image,    tFunc(tOr(tObj,tVoid) tOr(tObj,tVoid),tObj),0);