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

version» Context lines:

pike.git/src/modules/Image/image.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information.   */      /*   **! module Image + **! Image processing, decoding/loading and encoding/saving. + **! + **! Some starting points: + **! <ref>Image.Image</ref> - The main image object <br> + **! <ref>Image.load</ref>, <ref>Image.load_layers</ref> - Loads and decodes data <br> + **! <ref>Image.lay</ref> - The base image layer compositing method <br> + **!   **! class Image   **!   **! The main object of the <ref>Image</ref> module, this object   **! is used as drawing area, mask or result of operations.   **!   **! basic: <br>   **! <ref>clear</ref>,   **! <ref>clone</ref>,   **! <ref>create</ref>,   **! <ref>xsize</ref>,
pike.git/src/modules/Image/image.c:94:   **! see also: Image, Image.Font, Image.Colortable, Image.X   */      #include "global.h"   #include "image_machine.h"      #include <math.h>   #include <ctype.h>      #include "stralloc.h" - #include "global.h" +    #include "pike_macros.h"   #include "object.h"   #include "interpret.h"   #include "svalue.h"   #include "threads.h"   #include "array.h"   #include "pike_error.h"   #include "module_support.h" -  + #include "pike_types.h" + #include "operators.h" + #include "mapping.h" + #include "constants.h" + #include "sprintf.h"    -  +    #include "image.h"   #include "colortable.h"   #include "builtin_functions.h"      #ifdef ASSEMBLY_OK   #include "assembly.h"   #endif         #define sp Pike_sp
pike.git/src/modules/Image/image.c:127:   extern struct program *image_colortable_program;   extern struct program *image_color_program;      #ifdef THIS   #undef THIS /* Needed for NT */   #endif      #define THIS ((struct image *)(Pike_fp->current_storage))   #define THISOBJ (Pike_fp->current_object)    - #define testrange(x) ((COLORTYPE)MAXIMUM(MINIMUM(DOUBLE_TO_INT(x),255),0)) -  +    #define sq(x) ((x)*(x))      #define CIRCLE_STEPS 128   static INT32 circle_sin_table[CIRCLE_STEPS];   #define circle_sin(x) circle_sin_table[((x)+CIRCLE_STEPS)%CIRCLE_STEPS]   #define circle_cos(x) circle_sin((x)-CIRCLE_STEPS/4)      #define circle_sin_mul(x,y) ((circle_sin(x)*(y))/4096)   #define circle_cos_mul(x,y) ((circle_cos(x)*(y))/4096)   
pike.git/src/modules/Image/image.c:168:       rold=r;   }   #else   #define CHRONO(X)   #endif         /***************** init & exit *********************************/    + #ifdef PIKE_NULL_IS_SPECIAL   static void init_image_struct(struct object *UNUSED(obj))   {    THIS->img=NULL;    THIS->rgb.r=0;    THIS->rgb.g=0;    THIS->rgb.b=0;    THIS->xsize=THIS->ysize=0;    THIS->alpha=0; - /* fprintf(stderr,"init %lx (%d)\n",obj,++obj_counter);*/ +    } -  + #endif      static void exit_image_struct(struct object *UNUSED(obj))   { -  if (THIS->img) { free(THIS->img); THIS->img=NULL; } - /* -  fprintf(stderr,"exit %lx (%d) %dx%d=%.1fKb\n",obj,--obj_counter, -  THIS->xsize,THIS->ysize, -  (THIS->xsize*THIS->ysize*sizeof(rgb_group)+sizeof(struct image))/1024.0); -  */ +  if (THIS->img) { +  if( Pike_fp->current_object->flags & OBJECT_CLEAR_ON_EXIT ) +  memset( THIS->img, 0, sizeof(rgb_group)*THIS->xsize*(long)THIS->ysize ); +  free(THIS->img);    } -  + }      /***************** internals ***********************************/    - #define apply_alpha(x,y,alpha) \ -  ((unsigned char)((y*(255L-(alpha))+x*(alpha))/255L)) -  - #define set_rgb_group_alpha(dest,src,alpha) \ -  ((dest).r=apply_alpha((dest).r,(src).r,alpha), \ -  (dest).g=apply_alpha((dest).g,(src).g,alpha), \ -  (dest).b=apply_alpha((dest).b,(src).b,alpha)) -  - #define pixel(_img,x,y) ((_img)->img[((int)(x))+((int)(y))*(int)(_img)->xsize]) -  +    #define setpixel(x,y) \    (THIS->alpha? \    set_rgb_group_alpha(THIS->img[(x)+(y)*THIS->xsize],THIS->rgb,THIS->alpha): \    ((pixel(THIS,x,y)=THIS->rgb),0))      #define color_equal(A,B) (((A).r == (B).r) && ((A).g == (B).g) && ((A).b == (B).b))      #define setpixel_test(x,y) \    ((((int)x)<0||((int)y)<0||((int)x)>=(int)THIS->xsize||((int)y)>=(int)THIS->ysize)? \    0:(setpixel((int)x,(int)y),0))    - static INLINE int getrgb(struct image *img, + static inline int getrgb(struct image *img,    INT32 args_start,INT32 args,INT32 max,char *name)   {    INT32 i;    if (args-args_start<1) return 0;       if (image_color_svalue(sp-args+args_start,&(img->rgb)))    return 1;       if (max<3 || args-args_start<3) return 0;   
pike.git/src/modules/Image/image.c:248:    img->alpha=sp[3-args+args_start].u.integer;    return 4;    }    else    {    img->alpha=0;    return 3;    }   }    - static INLINE void getrgbl(rgbl_group *rgb,INT32 args_start,INT32 args,char *name) + static inline void getrgbl(rgbl_group *rgb,INT32 args_start,INT32 args,char *name)   {    INT32 i;    if (args-args_start<3) return;    for (i=0; i<3; i++)    if (TYPEOF(sp[-args+i+args_start]) != T_INT)    Pike_error("Illegal r,g,b argument to %s\n",name);    rgb->r=sp[-args+args_start].u.integer;    rgb->g=sp[1-args+args_start].u.integer;    rgb->b=sp[2-args+args_start].u.integer;   }    - static INLINE void img_line(INT32 x1,INT32 y1,INT32 x2,INT32 y2) + static inline void img_line(INT32 x1,INT32 y1,INT32 x2,INT32 y2)   {    INT32 pixelstep,pos;    if (x1==x2)    {    if (y1>y2) y1^=y2,y2^=y1,y1^=y2;    if (x1<0||x1>=THIS->xsize||    y2<0||y1>=THIS->ysize) return;    if (y1<0) y1=0;    if (y2>=THIS->ysize) y2=THIS->ysize-1;    for (;y1<=y2;y1++) setpixel_test(x1,y1);
pike.git/src/modules/Image/image.c:309:    pixelstep=((y2-y1)*1024)/(x2-x1);    pos=y1*1024;    for (;x1<=x2;x1++)    {    setpixel_test(x1,(pos+512)/1024);    pos+=pixelstep;    }    }   }    - static INLINE rgb_group _pixel_apply_matrix(struct image *img, + static inline rgb_group _pixel_apply_matrix(struct image *img,    int x,int y,    int width,int height,    rgbd_group *matrix,    rgb_group default_rgb,    double div)   {    rgb_group res;    int i,j,bx,by,xp,yp;    int sumr,sumg,sumb,r,g,b;    double qdiv=1.0/div;
pike.git/src/modules/Image/image.c:336:    sumr=sumg=sumb=0;    r=g=b=0;       bx=width/2;    by=height/2;       for (xp=x-bx,i=0; i<width; i++,xp++)    for (yp=y-by,j=0; j<height; j++,yp++)    if (xp>=0 && xp<img->xsize && yp>=0 && yp<img->ysize)    { -  r += DO_NOT_WARN((int)(matrix[i+j*width].r*img->img[xp+yp*img->xsize].r)); -  g += DO_NOT_WARN((int)(matrix[i+j*width].g*img->img[xp+yp*img->xsize].g)); -  b += DO_NOT_WARN((int)(matrix[i+j*width].b*img->img[xp+yp*img->xsize].b)); +  r += (int)(matrix[i+j*width].r*img->img[xp+yp*img->xsize].r); +  g += (int)(matrix[i+j*width].g*img->img[xp+yp*img->xsize].g); +  b += (int)(matrix[i+j*width].b*img->img[xp+yp*img->xsize].b);   #ifdef MATRIX_DEBUG    fprintf(stderr,"%d,%d %d,%d->%d,%d,%d\n",    i,j,xp,yp,    img->img[x+i+(y+j)*img->xsize].r,    img->img[x+i+(y+j)*img->xsize].g,    img->img[x+i+(y+j)*img->xsize].b);   #endif -  sumr += DO_NOT_WARN((int)matrix[i+j*width].r); -  sumg += DO_NOT_WARN((int)matrix[i+j*width].g); -  sumb += DO_NOT_WARN((int)matrix[i+j*width].b); +  sumr += (int)matrix[i+j*width].r; +  sumg += (int)matrix[i+j*width].g; +  sumb += (int)matrix[i+j*width].b;    }    if (sumr) res.r=testrange(default_rgb.r+r/(sumr*div));    else res.r=testrange(r*qdiv+default_rgb.r);    if (sumg) res.g=testrange(default_rgb.g+g/(sumg*div));    else res.g=testrange(g*qdiv+default_rgb.g); -  if (sumb) res.b=testrange(default_rgb.g+b/(sumb*div)); +  if (sumb) res.b=testrange(default_rgb.b+b/(sumb*div));    else res.b=testrange(b*qdiv+default_rgb.b);   #ifdef MATRIX_DEBUG    fprintf(stderr,"->%d,%d,%d\n",res.r,res.g,res.b);   #endif    return res;    REVEAL_GLOBAL_VARIABLES();   }         static void img_apply_matrix(struct image *dest,
pike.git/src/modules/Image/image.c:377:    rgbd_group *matrix,    double div,    rgb_group default_rgb)   {    rgb_group *d,*ip,*dp;    rgbd_group *mp;    int i,x,y,bx,by,ex,ey,yp;    int widthheight;    double sumr,sumg,sumb;    double qr,qg,qb; -  register double r=0,g=0,b=0; +  double r=0,g=0,b=0;      THREADS_ALLOW();       widthheight=width*height;    sumr=sumg=sumb=0;    for (i=0; i<widthheight;)    {    sumr+=matrix[i].r;    sumg+=matrix[i].g;    sumb+=matrix[i++].b;    }    -  if (!sumr) sumr=1; sumr*=div; qr=1.0/sumr; -  if (!sumg) sumg=1; sumg*=div; qg=1.0/sumg; -  if (!sumb) sumb=1; sumb*=div; qb=1.0/sumb; +  if (!sumr) {sumr=1;} sumr*=div; qr=1.0/sumr; +  if (!sumg) {sumg=1;} sumg*=div; qg=1.0/sumg; +  if (!sumb) {sumb=1;} sumb*=div; qb=1.0/sumb;       bx=width/2;    by=height/2;    ex=width-bx;    ey=height-by;      THREADS_DISALLOW();       d=xalloc(sizeof(rgb_group)*img->xsize*img->ysize + RGB_VEC_PAD);   
pike.git/src/modules/Image/image.c:443:    img->img[x+i+(y+j)*img->xsize].b);   #endif    mp++;    ip++;    }    ip+=img->xsize-width;    }   #ifdef MATRIX_DEBUG    fprintf(stderr,"->%d,%d,%d\n",r/sumr,g/sumg,b/sumb);   #endif -  r=default_rgb.r+DOUBLE_TO_INT(r*qr+0.5); dp->r=testrange(r); -  g=default_rgb.g+DOUBLE_TO_INT(g*qg+0.5); dp->g=testrange(g); -  b=default_rgb.b+DOUBLE_TO_INT(b*qb+0.5); dp->b=testrange(b); +  r=default_rgb.r+(int)(r*qr+0.5); dp->r=testrange(r); +  g=default_rgb.g+(int)(g*qg+0.5); dp->g=testrange(g); +  b=default_rgb.b+(int)(b*qb+0.5); dp->b=testrange(b);    dp++;    }    }      CHRONO("apply_matrix, two");       for (y=0; y<img->ysize; y++)    {    for (x=0; x<bx; x++)    d[x+y*img->xsize]=_pixel_apply_matrix(img,x,y,width,height,
pike.git/src/modules/Image/image.c:515:   **! <pre>   **! channel modes; followed by a number of 1-char-per-pixel strings   **! or image objects (where red channel will be used),   **! or an integer value:   **! "grey" : make a grey image (needs 1 source: grey)   **! "rgb" : make an rgb image (needs 3 sources: red, green and blue)   **! "cmyk" : make a rgb image from cmyk (cyan, magenta, yellow, black)   **! "adjusted_cmyk" : make a rgb image from cmyk   **! (cyan, magenta, yellow, black) where the colors aren't   **! 100% pure (C: 009ee0, M: e2007a, Y: ffec00, K: 1a171b). + **! "raw" : make an image from a binary string   **!   **! generate modes; all extra arguments is given to the   **! generation function. These has the same name as the method:   **! "<ref>test</ref>,"   **! "<ref>gradients</ref>"   **! "<ref>noise</ref>"   **! "<ref>turbulence</ref>"   **! "<ref>random</ref>"   **! "<ref>randomgrey</ref>"   **! specials cases:
pike.git/src/modules/Image/image.c:548:   **! default color is black   **! arg int alpha   **! default alpha channel value   **! see also: copy, clone, Image.Image   **! bugs   **! SIGSEGVS can be caused if the size is too big, due   **! to unchecked overflow -   **! (xsize*ysize)&MAXINT is small enough to allocate.   */    - int image_too_big(INT_TYPE xsize,INT_TYPE ysize) + static int image_size_check(INT_TYPE xsize,INT_TYPE ysize)   { -  register INT_TYPE a,b,c,d; +  INT_TYPE a,b,c,d;       if (xsize<0 || ysize<0) return 1;       if (xsize<0x20000000) xsize*=sizeof(rgb_group);    else if (ysize<0x20000000) ysize*=sizeof(rgb_group);    else return 1;       a=(xsize>>16);    b=xsize&0xffff;    c=(ysize>>16);    d=ysize&0xffff;       /* check for overflow */    if ((a&&c) || ((b*d>>16)&0xffff) + (a*d) + (b*c) > 0x7fff) return 1;       return 0;   }    - void img_read_get_channel(int arg,char *name,INT32 args, + static void img_read_get_channel(int arg,char *name,INT32 args,    int *m,unsigned char **s,COLORTYPE *c)   {    struct image *img;    if (arg>args) -  SIMPLE_TOO_FEW_ARGS_ERROR("create_method",1+arg); +  SIMPLE_WRONG_NUM_ARGS_ERROR("create",1+arg);    switch (TYPEOF(sp[arg-args-1]))    {    case T_INT:    *c=(COLORTYPE)sp[arg-args-1].u.integer;    *s=c;    *m=0;    break;    case T_STRING:    if (sp[arg-args-1].u.string->size_shift) -  Pike_error("create_method: argument %d (%s channel): " +  Pike_error("create: argument %d (%s channel): "    "wide strings are not supported (yet)\n",arg+1,name);    if (sp[arg-args-1].u.string->len!=THIS->xsize*THIS->ysize) -  Pike_error("create_method: argument %d (%s channel): " +  Pike_error("create: argument %d (%s channel): "    "string is %ld characters, expected %ld\n",    arg+1, name, -  DO_NOT_WARN((long)sp[arg-args-1].u.string->len), -  DO_NOT_WARN((long)(THIS->xsize*THIS->ysize))); +  (long)sp[arg-args-1].u.string->len, +  (long)(THIS->xsize*THIS->ysize));    *s=(unsigned char *)sp[arg-args-1].u.string->str;    *m=1;    break;    case T_OBJECT: -  img=(struct image*)get_storage(sp[arg-args-1].u.object,image_program); +  img=get_storage(sp[arg-args-1].u.object,image_program);    if (!img) -  Pike_error("create_method: argument %d (%s channel): " +  Pike_error("create: argument %d (%s channel): "    "not an image object\n",arg+1,name);    if (!img->img) -  Pike_error("create_method: argument %d (%s channel): " +  Pike_error("create: argument %d (%s channel): "    "uninitialized image object\n",arg+1,name);    if (img->xsize!=THIS->xsize || img->ysize!=THIS->ysize) -  Pike_error("create_method: argument %d (%s channel): " +  Pike_error("create: argument %d (%s channel): "    "size is wrong, %"PRINTPIKEINT"dx%"PRINTPIKEINT"d;"    " expected %"PRINTPIKEINT"dx%"PRINTPIKEINT"d\n",    arg+1,name,img->xsize,img->ysize,    THIS->xsize,THIS->ysize);    *s=(COLORTYPE*)img->img;    *m=sizeof(rgb_group);    break;    default: -  Pike_error("create_method: argument %d (%s channel): " +  Pike_error("create: argument %d (%s channel): "    "illegal type\n",arg+1,name);    }   }    - void img_read_grey(INT32 args) + static void img_read_grey(INT32 args)   {    int m1;    COLORTYPE c1;    unsigned char *s1;    int n=THIS->xsize*THIS->ysize;    rgb_group *d; -  +  if(args==0) +  { +  push_int(190); +  img_read_get_channel(1,"grey",1,&m1,&s1,&c1); +  pop_stack(); +  } +  else    img_read_get_channel(1,"grey",args,&m1,&s1,&c1); -  d=THIS->img=(rgb_group*)xalloc(sizeof(rgb_group)*n+RGB_VEC_PAD); +  +  d=THIS->img=xalloc(sizeof(rgb_group)*n+RGB_VEC_PAD);    switch (m1)    { -  case 0: MEMSET(d,c1,n*sizeof(rgb_group)); break; +  case 0: memset(d,c1,n*sizeof(rgb_group)); break;    case 1: while (n--) { d->r=d->g=d->b=*(s1++); d++; } break;    default: while (n--) { d->r=d->g=d->b=*s1; s1+=m1; d++; }    }   }    - void img_read_rgb(INT32 args) + static void img_read_rgb(INT32 args)   {    int m1,m2,m3;    unsigned char *s1,*s2,*s3;    int n=THIS->xsize*THIS->ysize;    rgb_group *d,rgb;    img_read_get_channel(1,"red",args,&m1,&s1,&(rgb.r));    img_read_get_channel(2,"green",args,&m2,&s2,&(rgb.g));    img_read_get_channel(3,"blue",args,&m3,&s3,&(rgb.b)); -  d=THIS->img=(rgb_group*)xalloc(sizeof(rgb_group)*n+RGB_VEC_PAD); +  d=THIS->img=xalloc(sizeof(rgb_group)*n+RGB_VEC_PAD);       switch (m1|(m2<<4)|(m3<<4))    {    case 0: /* all constant */    while (n--) *(d++)=rgb;    break;    case 0x111: /* all is one-byte */    while (n--)    {    d->r=*(s1++);
pike.git/src/modules/Image/image.c:687:    d->b=*s3;    s1+=m1;    s2+=m2;    s3+=m3;    d++;    }    break;    }   }    - void img_read_cmyk(INT32 args) + static void img_read_cmyk(INT32 args)   {    int m1,m2,m3,m4;    unsigned char *s1,*s2,*s3,*s4;    int n=THIS->xsize*THIS->ysize;    rgb_group *d,rgb;    COLORTYPE k;    img_read_get_channel(1,"cyan",args,&m1,&s1,&(rgb.r));    img_read_get_channel(2,"magenta",args,&m2,&s2,&(rgb.g));    img_read_get_channel(3,"yellow",args,&m3,&s3,&(rgb.b));    img_read_get_channel(4,"black",args,&m4,&s4,&k); -  d=THIS->img=(rgb_group*)xalloc(sizeof(rgb_group)*n+RGB_VEC_PAD); +  d=THIS->img=xalloc(sizeof(rgb_group)*n+RGB_VEC_PAD);       while (n--)    {    d->r = ((COLORMAX-*s1)*(COLORMAX-*s4))/COLORMAX;    d->g = ((COLORMAX-*s2)*(COLORMAX-*s4))/COLORMAX;    d->b = ((COLORMAX-*s3)*(COLORMAX-*s4))/COLORMAX;    s1+=m1;    s2+=m2;    s3+=m3;    s4+=m4;
pike.git/src/modules/Image/image.c:726:   #define CMYK_CB 0xe0   #define CMYK_MR 0xe2   #define CMYK_MG 0x00   #define CMYK_MB 0x7a   #define CMYK_YR 0xff   #define CMYK_YG 0xec   #define CMYK_YB 0x00   #define CMYK_KR 0x1a   #define CMYK_KG 0x17   #define CMYK_KB 0x1b - void img_read_adjusted_cmyk(INT32 args) + static void img_read_adjusted_cmyk(INT32 args)   {    int m1,m2,m3,m4;    unsigned char *s1,*s2,*s3,*s4;    int n=THIS->xsize*THIS->ysize;    rgb_group *d,rgb;    COLORTYPE k;    img_read_get_channel(1,"cyan",args,&m1,&s1,&(rgb.r));    img_read_get_channel(2,"magenta",args,&m2,&s2,&(rgb.g));    img_read_get_channel(3,"yellow",args,&m3,&s3,&(rgb.b));    img_read_get_channel(4,"black",args,&m4,&s4,&k); -  d=THIS->img=(rgb_group*)xalloc(sizeof(rgb_group)*n+RGB_VEC_PAD); +  d=THIS->img=xalloc(sizeof(rgb_group)*n+RGB_VEC_PAD);       while (n--)    {    unsigned char c = *s1;    unsigned char m = *s2;    unsigned char y = *s3;    unsigned char k = *s4;    unsigned long tmp;    /* Mix the channels multiplicatively. */    tmp = 255*255;
pike.git/src/modules/Image/image.c:785:    tmp /= 255*255*255;    d->b = tmp;    s1+=m1;    s2+=m2;    s3+=m3;    s4+=m4;    d++;    }   }    - void img_read_cmy(INT32 args) + static void img_read_cmy(INT32 args)   {    int m1,m2,m3;    unsigned char *s1,*s2,*s3;    int n=THIS->xsize*THIS->ysize;    rgb_group *d,rgb;    img_read_get_channel(1,"cyan",args,&m1,&s1,&(rgb.r));    img_read_get_channel(2,"magenta",args,&m2,&s2,&(rgb.g));    img_read_get_channel(3,"yellow",args,&m3,&s3,&(rgb.b)); -  d=THIS->img=(rgb_group*)xalloc(sizeof(rgb_group)*n+RGB_VEC_PAD); +  d=THIS->img=xalloc(sizeof(rgb_group)*n+RGB_VEC_PAD);       while (n--)    {    d->r=COLORMAX-*s1;    d->g=COLORMAX-*s2;    d->b=COLORMAX-*s3;    s1+=m1;    s2+=m2;    s3+=m3;    d++;    }   }      static void image_gradients(INT32 args);   static void image_tuned_box(INT32 args);   static void image_test(INT32 args);      static struct pike_string *s_grey,*s_rgb,*s_cmyk,*s_adjusted_cmyk,*s_cmy;   static struct pike_string *s_test,*s_gradients,*s_noise,*s_turbulence, -  *s_random,*s_randomgrey,*s_tuned_box; +  *s_random,*s_randomgrey,*s_tuned_box, *s_raw;    - void image_create_method(INT32 args) + static void image_create_method(INT32 args)   {    struct image *img;       if (!args) -  SIMPLE_TOO_FEW_ARGS_ERROR("create_method",1); +  SIMPLE_WRONG_NUM_ARGS_ERROR("create",1);       if (TYPEOF(sp[-args]) != T_STRING) -  SIMPLE_BAD_ARG_ERROR("create_method",1,"string"); +  SIMPLE_ARG_TYPE_ERROR("create",1,"string");    -  MAKE_CONST_STRING(s_grey,"grey"); +     MAKE_CONST_STRING(s_rgb,"rgb");    MAKE_CONST_STRING(s_cmyk,"cmyk");    MAKE_CONST_STRING(s_adjusted_cmyk,"adjusted_cmyk");    MAKE_CONST_STRING(s_cmy,"cmy");    MAKE_CONST_STRING(s_test,"test");    MAKE_CONST_STRING(s_gradients,"gradients");    MAKE_CONST_STRING(s_noise,"noise");    MAKE_CONST_STRING(s_turbulence,"turbulence");    MAKE_CONST_STRING(s_random,"random");    MAKE_CONST_STRING(s_randomgrey,"randomgrey");    MAKE_CONST_STRING(s_tuned_box,"tuned_box"); -  +  MAKE_CONST_STRING(s_raw,"raw");       if (THIS->xsize<=0 || THIS->ysize<=0) -  Pike_error("create_method: image size is too small\n"); +  Pike_error("create: image size is too small\n");       if (sp[-args].u.string==s_grey)    {    img_read_grey(args-1); -  pop_n_elems(2); -  ref_push_object(THISOBJ); +     return;    }    if (sp[-args].u.string==s_rgb)    {    img_read_rgb(args-1); -  pop_n_elems(2); -  ref_push_object(THISOBJ); +     return;    }    if (sp[-args].u.string==s_cmyk)    {    img_read_cmyk(args-1); -  pop_n_elems(2); -  ref_push_object(THISOBJ); +     return;    }    if (sp[-args].u.string==s_adjusted_cmyk)    {    img_read_adjusted_cmyk(args-1); -  pop_n_elems(2); -  ref_push_object(THISOBJ); +     return;    }    if (sp[-args].u.string==s_cmy)    {    img_read_cmy(args-1); -  pop_n_elems(2); -  ref_push_object(THISOBJ); +     return;    }       if (sp[-args].u.string==s_test)    image_test(args-1);    else if (sp[-args].u.string==s_gradients) {    if(args<2) {    push_int(THIS->xsize/2);    push_int(0);    push_int(0); push_int(0); push_int(0);
pike.git/src/modules/Image/image.c:906:    else if (sp[-args].u.string==s_turbulence)    image_turbulence(args-1);    else if (sp[-args].u.string==s_random)    image_random(args-1);    else if (sp[-args].u.string==s_randomgrey)    image_randomgrey(args-1);    else if (sp[-args].u.string==s_tuned_box)    {    if (args<2) push_int(0);    -  THIS->img=(rgb_group*) +  THIS->img=    xalloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);       if (args>2) pop_n_elems(args-2);    push_int(0); stack_swap();    push_int(0); stack_swap();    push_int(THIS->xsize-1); stack_swap();    push_int(THIS->ysize-1); stack_swap();    image_tuned_box(5);    return;    } -  +  else if (sp[-args].u.string==s_raw) +  { +  struct pike_string *s; +  int size; +  char *dst; +  if( args!=2 || TYPEOF(sp[1-args])!=T_STRING || +  sp[1-args].u.string->size_shift) +  SIMPLE_ARG_TYPE_ERROR("create",2,"string(8bit)"); +  +  s = sp[1-args].u.string; +  size = sizeof(rgb_group)*THIS->xsize*THIS->ysize; +  if( s->len > size ) +  SIMPLE_ARG_ERROR("create",2,"String size too large."); +  +  THIS->img = xalloc(size+RGB_VEC_PAD); +  dst = (char*)THIS->img; +  memcpy(THIS->img, s->str, s->len); +  memset(dst+s->len, 0, size - s->len); +  return; +  }    else -  Pike_error("create_method: unknown method\n"); +  Pike_error("create: unknown method\n");       /* on stack: "string" image */    /* want: put that image in this, crap that image */ -  img=(struct image*)get_storage(sp[-1].u.object,image_program); +  img=get_storage(sp[-1].u.object,image_program);    THIS->img=img->img;    img->img=NULL; -  pop_n_elems(2); -  ref_push_object(THISOBJ); +    }      void image_create(INT32 args)   {    if ((args >= 1) && (TYPEOF(sp[-args]) == T_OBJECT)) {    struct object *o = sp[-args].u.object;    pop_n_elems(args - 1);    apply(o, "xsize", 0);    apply(o, "ysize", 0);    image_create(2);    image_paste(1); -  +  pop_stack();    return;    }    if (args<2) return; -  if (TYPEOF(sp[-args]) != T_INT|| -  TYPEOF(sp[1-args]) != T_INT) -  bad_arg_error("Image.Image->create",sp-args,args,0,"",sp-args, -  "Bad arguments to Image.Image->create()\n"); +     -  +  get_all_args(NULL, args, "%i%i", &THIS->xsize, &THIS->ysize); +  if (image_size_check(THIS->xsize,THIS->ysize)) +  Pike_error("create: image too small or large (>2Gpixels)\n"); +     if (THIS->img) { free(THIS->img); THIS->img=NULL; }    -  THIS->xsize=sp[-args].u.integer; -  THIS->ysize=sp[1-args].u.integer; - #if 0 -  if (THIS->xsize<0) THIS->xsize=0; -  if (THIS->ysize<0) THIS->ysize=0; - #endif -  if (image_too_big(THIS->xsize,THIS->ysize)) -  Pike_error("Image.Image->create(): image too large (>2Gpixels)\n"); -  +  MAKE_CONST_STRING(s_grey,"grey");    if (args>2 && TYPEOF(sp[2-args]) == T_STRING && -  !image_color_svalue(sp+2-args,&(THIS->rgb))) +  (!image_color_svalue(sp+2-args,&(THIS->rgb)) || +  sp[2-args].u.string==s_grey))    /* don't try method "lightblue", etc */    { -  +  struct svalue *stack = Pike_sp;    image_create_method(args-2); -  pop_n_elems(3); -  return ; +  pop_n_elems(args+Pike_sp-stack); +  return;    }    else -  getrgb(THIS,2,args,args,"Image.Image->create()"); +  { +  getrgb(THIS,2,args,args,"create"); +  pop_n_elems(args); +  }       THIS->img=xalloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD); -  +     img_clear(THIS->img,THIS->rgb,THIS->xsize*THIS->ysize); -  pop_n_elems(args); +    }      /*   **! method object clone()   **! method object clone(int xsize,int ysize)   **! method object clone(int xsize,int ysize,int r,int g,int b)   **! method object clone(int xsize,int ysize,int r,int g,int b,int alpha)   **! Copies to or initialize a new image object.   **!   **! <table><tr valign=center>
pike.git/src/modules/Image/image.c:1018:   static void my_free_object(struct object *o)   {    free_object(o);   }      void image_clone(INT32 args)   {    struct object *o;    struct image *img;    ONERROR err; +  INT_TYPE x,y;    -  if (args) -  if (args<2|| -  TYPEOF(sp[-args]) != T_INT|| -  TYPEOF(sp[1-args]) != T_INT) -  bad_arg_error("Image",sp-args,args,0,"",sp-args, -  "Bad arguments to Image()\n"); +  if( args ) +  get_all_args(NULL, args, "%+%+", &x, &y); +  else +  { +  x = THIS->xsize; +  y = THIS->ysize; +  } +  if( x<0 ) x = 1; +  if( y<0 ) y = 1;       o=clone_object(image_program,0);    SET_ONERROR(err, my_free_object, o);    img=(struct image*)(o->storage);    *img=*THIS;    -  if (args) -  { -  if(sp[-args].u.integer < 0 || -  sp[1-args].u.integer < 0) -  Pike_error("Illegal size to Image.Image->clone()\n"); -  img->xsize=sp[-args].u.integer; -  img->ysize=sp[1-args].u.integer; -  } +  getrgb(img,2,args,args,"clone");    -  getrgb(img,2,args,args,"Image.Image->clone()"); -  -  if (img->xsize<0) img->xsize=1; -  if (img->ysize<0) img->ysize=1; -  -  img->img=xalloc(sizeof(rgb_group)*img->xsize*img->ysize+RGB_VEC_PAD); +  img->xsize = x; +  img->ysize = y; +  img->img=xalloc(sizeof(rgb_group)*x*y+RGB_VEC_PAD);    if (THIS->img)    { -  if (img->xsize==THIS->xsize -  && img->ysize==THIS->ysize) -  MEMCPY(img->img,THIS->img,sizeof(rgb_group)*img->xsize*img->ysize); +  if (x==THIS->xsize +  && y==THIS->ysize) +  memcpy(img->img,THIS->img,sizeof(rgb_group)*x*y);    else -  img_crop(img,THIS, -  0,0,img->xsize-1,img->ysize-1); +  img_crop(img,THIS,0,0,x-1,y-1);       }    else -  img_clear(img->img,img->rgb,img->xsize*img->ysize); +  img_clear(img->img,img->rgb,x*y);       UNSET_ONERROR(err);    pop_n_elems(args);    push_object(o);   }         /* - **! method void clear() - **! method void clear(int r,int g,int b) - **! method void clear(int r,int g,int b,int alpha) + **! method object clear() + **! method object clear(int r,int g,int b) + **! method object clear(int r,int g,int b,int alpha)   **! gives a new, cleared image with the same size of drawing area   **!   **! <table><tr valign=center>   **! <td><illustration> return lena(); </illustration></td>   **! <td><illustration> return lena()->clear(0,128,255); </illustration></td>   **! </tr><tr>   **! <td>original</td>   **! <td>->clear<wbr>(0,128,255)</td>   **! </tr></table>   **!
pike.git/src/modules/Image/image.c:1097:      void image_clear(INT32 args)   {    struct object *o;    struct image *img;       o=clone_object(image_program,0);    img=(struct image*)(o->storage);    *img=*THIS;    -  getrgb(img,0,args,args,"Image.Image->clear()"); +  getrgb(img,0,args,args,"clear");       img->img=malloc(sizeof(rgb_group)*img->xsize*img->ysize+RGB_VEC_PAD);    if (!img->img)    {    free_object(o);    SIMPLE_OUT_OF_MEMORY_ERROR("clear",    sizeof(rgb_group)*img->xsize*img->ysize+RGB_VEC_PAD);    }       img_clear(img->img,img->rgb,img->xsize*img->ysize);
pike.git/src/modules/Image/image.c:1156:   **! color of the new image   **! arg int alpha   **! new default alpha channel value   **! see also: clone, autocrop   */      void image_copy(INT32 args)   {    struct object *o;    struct image *img; +  int x1,y1,x2,y2;       if (!args)    {    o=clone_object(image_program,0);    if (THIS->img) img_clone((struct image*)o->storage,THIS);    pop_n_elems(args);    push_object(o);    return;    } -  if (args<4|| -  TYPEOF(sp[-args]) != T_INT|| -  TYPEOF(sp[1-args]) != T_INT|| -  TYPEOF(sp[2-args]) != T_INT|| -  TYPEOF(sp[3-args]) != T_INT) -  bad_arg_error("Image",sp-args,args,0,"",sp-args, -  "Bad arguments to Image()\n"); +     -  if (!THIS->img) Pike_error("Called Image.Image object is not initialized\n");; +  get_all_args(NULL, args, "%d%d%d%d", &x1,&y1,&x2,&y2);    -  getrgb(THIS,4,args,args,"Image.Image->copy()"); +  CHECK_INIT();    -  +  getrgb(THIS,4,args,args,"copy"); +     o=clone_object(image_program,0);    img=(struct image*)(o->storage);    -  img_crop(img,THIS, -  sp[-args].u.integer,sp[1-args].u.integer, -  sp[2-args].u.integer,sp[3-args].u.integer); +  img_crop(img,THIS, x1,y1,x2,y2);       pop_n_elems(args);    push_object(o);   }      /*   **! method object change_color(int tor,int tog,int tob)   **! method object change_color(int fromr,int fromg,int fromb,int tor,int tog,int tob)   **! Changes one color (exact match) to another.   **! If non-exact-match is preferred, check <ref>distancesq</ref>
pike.git/src/modules/Image/image.c:1216:   static void image_change_color(INT32 args)      {    /* ->change_color([int from-r,g,b,] int to-r,g,b); */    rgb_group from,to,*s,*d;    INT32 left;    struct object *o;    struct image *img;    int arg;    -  if (!THIS->img) Pike_error("Called Image.Image object is not initialized\n");; +  CHECK_INIT();       to=THIS->rgb; -  if (!(arg=getrgb(THIS,0,args,3,"Image.Image->change_color()"))) -  SIMPLE_TOO_FEW_ARGS_ERROR("Image",1); +  if (!(arg=getrgb(THIS,0,args,3,"change_color"))) +  SIMPLE_WRONG_NUM_ARGS_ERROR("Image",1);    from=THIS->rgb; -  if (getrgb(THIS,arg,args,args,"Image.Image->change_color()")) +  if (getrgb(THIS,arg,args,args,"change_color"))    to=THIS->rgb;       o=clone_object(image_program,0);    img=(struct image*)(o->storage);    *img=*THIS;       if (!(img->img=malloc(sizeof(rgb_group)*img->xsize*img->ysize+RGB_VEC_PAD)))    {    free_object(o);    SIMPLE_OUT_OF_MEMORY_ERROR("change_color",
pike.git/src/modules/Image/image.c:1261:      /*   **! method object autocrop()   **! method object autocrop(int border)   **! method object autocrop(int border,Color color)   **! method object autocrop(int border,int left,int right,int top,int bottom)   **! method object autocrop(int border,int left,int right,int top,int bottom,Color color)   **! method array(int) find_autocrop()   **! method array(int) find_autocrop(int border)   **! method array(int) find_autocrop(int border,int left,int right,int top,int bottom) - **! Removes "unneccesary" borders around the image, adds one of + **! Removes "unnecessary" borders around the image, adds one of   **! its own if wanted to, in selected directions.   **! - **! "Unneccesary" is all pixels that are equal -- ie if all the same pixels + **! "Unnecessary" is all pixels that are equal -- ie if all the same pixels   **! to the left are the same color, that column of pixels are removed.   **!   **! The find_autocrop() function simply returns x1,y1,x2,y2 for the   **! kept area. (This can be used with <ref>copy</ref> later.)   **!   **! returns the new image object   **!   **! arg int border   **! added border size in pixels   **! arg int left   **! arg int right   **! arg int top   **! arg int bottom   **! which borders to scan and cut the image; - **! a typical example is removing the top and bottom unneccesary + **! a typical example is removing the top and bottom unnecessary   **! pixels:   **! <pre>img=img->autocrop(0, 0,0,1,1);</pre>   **!   **! see also: copy   */    - static INLINE int try_autocrop_vertical(struct image *this, + static inline int try_autocrop_vertical(struct image *this,    INT32 x,INT32 y,INT32 y2,    INT32 rgb_set,rgb_group *rgb)   {    if (!rgb_set) *rgb=pixel(THIS,x,y);    for (;y<=y2; y++)    if (pixel(this,x,y).r!=rgb->r ||    pixel(this,x,y).g!=rgb->g ||    pixel(this,x,y).b!=rgb->b) return 0;    return 1;   }    - static INLINE int try_autocrop_horisontal(struct image *this, + static inline int try_autocrop_horisontal(struct image *this,    INT32 y,INT32 x,INT32 x2,    INT32 rgb_set,rgb_group *rgb)   {    if (!rgb_set) *rgb=pixel(THIS,x,y);    for (;x<=x2; x++)    if (pixel(this,x,y).r!=rgb->r ||    pixel(this,x,y).g!=rgb->g ||    pixel(this,x,y).b!=rgb->b) return 0;    return 1;   }
pike.git/src/modules/Image/image.c:1352:    y2+=border;    x1-=border;    y1-=border;       if (x2<x1||y2<y1) px1[0]=py1[0]=0,px2[0]=py2[0]=-1;    else px1[0]=x1,py1[0]=y1,px2[0]=x2,py2[0]=y2;   }      static void image_find_autocrop(INT32 args)   { -  INT32 border=0,x1,y1,x2,y2; +  int border=0,x1,y1,x2,y2;    rgb_group rgb={0,0,0};    int left=1,right=1,top=1,bottom=1;    -  if (args) { -  if (TYPEOF(sp[-args]) != T_INT) -  bad_arg_error("find_autocrop",sp-args,args,0,"",sp-args, -  "Bad arguments to find_autocrop()\n"); -  else -  border=sp[-args].u.integer; -  } +  if (args) +  get_all_args(NULL, args, "%d.%d%d%d%d", +  &border, &left, &right, &top, &bottom);    -  if (args>=5) -  { -  left=!(TYPEOF(sp[1-args]) == T_INT && sp[1-args].u.integer==0); -  right=!(TYPEOF(sp[2-args]) == T_INT && sp[2-args].u.integer==0); -  top=!(TYPEOF(sp[3-args]) == T_INT && sp[3-args].u.integer==0); -  bottom=!(TYPEOF(sp[4-args]) == T_INT && sp[4-args].u.integer==0); -  } +  CHECK_INIT();    -  if (!THIS->img) -  Pike_error("Called Image.Image object is not initialized\n");; -  +     img_find_autocrop(THIS,&x1,&y1,&x2,&y2,    border,left,right,top,bottom,0,rgb);    -  +     pop_n_elems(args);    push_int(x1);    push_int(y1);    push_int(x2);    push_int(y2);    f_aggregate(4);   }      void image_autocrop(INT32 args)   {    INT32 border=0,x1,y1,x2,y2;    int rgb_set=0;    struct object *o;    struct image *img;    int left=1,right=1,top=1,bottom=1;       if (args>=5) -  getrgb(THIS,5,args,args,"Image.Image->autocrop()"); +  getrgb(THIS,5,args,args,"autocrop");    else -  getrgb(THIS,1,args,args,"Image.Image->autocrop()"); +  getrgb(THIS,1,args,args,"autocrop");       image_find_autocrop(args);    args++;       x1=sp[-1].u.array->item[0].u.integer;    y1=sp[-1].u.array->item[1].u.integer;    x2=sp[-1].u.array->item[2].u.integer;    y2=sp[-1].u.array->item[3].u.integer;       push_object(o=clone_object(image_program,0));
pike.git/src/modules/Image/image.c:1435:   **! arg int r   **! arg int g   **! arg int b   **! new color   **! arg int alpha   **! new alpha value   */   void image_setcolor(INT32 args)   {    if (args<3) -  bad_arg_error("Image.Image->setcolor",sp-args,args,0,"",sp-args, -  "Bad arguments to Image.Image->setcolor()\n"); -  getrgb(THIS,0,args,args,"Image.Image->setcolor()"); +  SIMPLE_WRONG_NUM_ARGS_ERROR("setcolor", 3); +  getrgb(THIS,0,args,args,"setcolor");    pop_n_elems(args);    ref_push_object(THISOBJ);   }      /*   **! method object setpixel(int x,int y)   **! method object setpixel(int x,int y,Image.Color c)   **! method object setpixel(int x,int y,int r,int g,int b)   **! method object setpixel(int x,int y,int r,int g,int b,int alpha)   **!
pike.git/src/modules/Image/image.c:1470:   **! position of the pixel   **! arg int r   **! arg int g   **! arg int b   **! color   **! arg int alpha   **! alpha value   */   void image_setpixel(INT32 args)   { -  INT32 x,y; -  if (args<2|| -  TYPEOF(sp[-args]) != T_INT|| -  TYPEOF(sp[1-args]) != T_INT) -  bad_arg_error("setpixel",sp-args,args,0,"",sp-args, -  "Bad arguments to setpixel()\n"); -  getrgb(THIS,2,args,args,"Image.Image->setpixel()"); +  int x,y; +  get_all_args(NULL, args, "%d%d", &x, &y); +  getrgb(THIS,2,args,args,"setpixel");    if (!THIS->img) return; -  x=sp[-args].u.integer; -  y=sp[1-args].u.integer; -  if (!THIS->img) return; +     setpixel_test(x,y);    pop_n_elems(args);    ref_push_object(THISOBJ);   }      /*   **! method array(int) getpixel(int x,int y)   **!   **! returns color of the requested pixel -- ({int red,int green,int blue})   **!   **! arg int x   **! arg int y   **! position of the pixel   */   void image_getpixel(INT32 args)   { -  INT32 x,y; +  int x,y;    rgb_group rgb;    -  if (args<2|| -  TYPEOF(sp[-args]) != T_INT|| -  TYPEOF(sp[1-args]) != T_INT) -  bad_arg_error("Image",sp-args,args,0,"",sp-args, -  "Bad arguments to Image()\n"); -  -  if (!THIS->img) Pike_error("Called Image.Image object is not initialized\n");; -  -  x=sp[-args].u.integer; -  y=sp[1-args].u.integer; +  get_all_args(NULL, args, "%d%d", &x, &y);    if (!THIS->img) return;    if(x<0||y<0||x>=THIS->xsize||y>=THIS->ysize)    rgb=THIS->rgb;    else    rgb=pixel(THIS,x,y);       pop_n_elems(args);    push_int(rgb.r);    push_int(rgb.g);    push_int(rgb.b);
pike.git/src/modules/Image/image.c:1553:   **! line endpoints   **! arg int r   **! arg int g   **! arg int b   **! color   **! arg int alpha   **! alpha value   */   void image_line(INT32 args)   { -  if (args<4|| -  TYPEOF(sp[-args]) != T_INT|| -  TYPEOF(sp[1-args]) != T_INT|| -  TYPEOF(sp[2-args]) != T_INT|| -  TYPEOF(sp[3-args]) != T_INT) -  bad_arg_error("Image",sp-args,args,0,"",sp-args, -  "Bad arguments to Image()\n"); -  getrgb(THIS,4,args,args,"Image.Image->line()"); +  int x1,y1,x2,y2; +  get_all_args(NULL, args, "%d%d%d%d", &x1,&y1,&x2,&y2); +  getrgb(THIS,4,args,args,"line");    if (!THIS->img) return;    -  img_line(sp[-args].u.integer, -  sp[1-args].u.integer, -  sp[2-args].u.integer, -  sp[3-args].u.integer); +  img_line(x1, y1, x2, y2);    pop_n_elems(args);    ref_push_object(THISOBJ);   }      /*   **! method object box(int x1,int y1,int x2,int y2)   **! method object box(int x1,int y1,int x2,int y2,int r,int g,int b)   **! method object box(int x1,int y1,int x2,int y2,int r,int g,int b,int alpha)   **! Draws a filled rectangle on the image.   **!
pike.git/src/modules/Image/image.c:1603:   **! box corners   **! arg int r   **! arg int g   **! arg int b   **! color of the box   **! arg int alpha   **! alpha value   */   void image_box(INT32 args)   { -  if (args<4|| -  TYPEOF(sp[-args]) != T_INT|| -  TYPEOF(sp[1-args]) != T_INT|| -  TYPEOF(sp[2-args]) != T_INT|| -  TYPEOF(sp[3-args]) != T_INT) -  bad_arg_error("Image",sp-args,args,0,"",sp-args, -  "Bad arguments to Image()\n"); -  getrgb(THIS,4,args,args,"Image.Image->box()"); +  int x1,y1,x2,y2; +  get_all_args(NULL, args, "%d%d%d%d", &x1, &y1, &x2, &y2); +  getrgb(THIS,4,args,args,"box");    if (!THIS->img) return;    -  img_box(sp[-args].u.integer, -  sp[1-args].u.integer, -  sp[2-args].u.integer, -  sp[3-args].u.integer); +  img_box(x1, y1, x2, y2);    ref_push_object(THISOBJ);    stack_pop_n_elems_keep_top(args);   }      /*   **! method object circle(int x,int y,int rx,int ry)   **! method object circle(int x,int y,int rx,int ry,int r,int g,int b)   **! method object circle(int x,int y,int rx,int ry,int r,int g,int b,int alpha)   **! Draws a circle on the image. The circle is <i>not</i> antialiased.   **!
pike.git/src/modules/Image/image.c:1652:   **! circle radius in pixels   **! arg int r   **! arg int g   **! arg int b   **! color   **! arg int alpha   **! alpha value   */   void image_circle(INT32 args)   { -  INT32 x,y,rx,ry; +  int x,y,rx,ry;    INT32 i;    -  if (args<4|| -  TYPEOF(sp[-args]) != T_INT|| -  TYPEOF(sp[1-args]) != T_INT|| -  TYPEOF(sp[2-args]) != T_INT|| -  TYPEOF(sp[3-args]) != T_INT) -  bad_arg_error("Image",sp-args,args,0,"",sp-args, -  "Bad arguments to Image()\n"); -  getrgb(THIS,4,args,args,"Image.Image->circle()"); +  get_all_args(NULL, args, "%d%d%d%d", &x,&y,&rx,&ry); +  getrgb(THIS,4,args,args,"circle");    if (!THIS->img) return;    -  x=sp[-args].u.integer; -  y=sp[1-args].u.integer; -  rx=sp[2-args].u.integer; -  ry=sp[3-args].u.integer; -  +     for (i=0; i<CIRCLE_STEPS; i++)    img_line(x+circle_sin_mul(i,rx),    y+circle_cos_mul(i,ry),    x+circle_sin_mul(i+1,rx),    y+circle_cos_mul(i+1,ry));       pop_n_elems(args);    ref_push_object(THISOBJ);   }    - static INLINE int image_color_svalue_rgba(struct svalue *s, + static inline int image_color_svalue_rgba(struct svalue *s,    rgba_group *d)   {    rgb_group rgb;    if (TYPEOF(*s) == T_ARRAY && s->u.array->size>=4)    {    struct array *a = s->u.array;    if( (a->type_field!=BIT_INT) &&    (array_fix_type_field(a)!=BIT_INT) )    return 0;   
pike.git/src/modules/Image/image.c:1708:    {    d->r=rgb.r;    d->g=rgb.g;    d->b=rgb.b;    d->alpha=0;    return 1;    }    return 0;   }    - static INLINE void + static inline void    add_to_rgbda_sum_with_factor(rgbda_group *sum,    rgba_group rgba,    double factor)   {    /* NOTE:    * This code MUST be MT-SAFE! (but also fast /per)    */   /* HIDE_GLOBAL_VARIABLES(); */ -  sum->r = DO_NOT_WARN((float)(sum->r + rgba.r*factor)); -  sum->g = DO_NOT_WARN((float)(sum->g + rgba.g*factor)); -  sum->b = DO_NOT_WARN((float)(sum->b + rgba.b*factor)); -  sum->alpha = DO_NOT_WARN((float)(sum->alpha + rgba.alpha*factor)); +  sum->r = (float)(sum->r + rgba.r*factor); +  sum->g = (float)(sum->g + rgba.g*factor); +  sum->b = (float)(sum->b + rgba.b*factor); +  sum->alpha = (float)(sum->alpha + rgba.alpha*factor);   /* REVEAL_GLOBAL_VARIABLES(); */   }    - static INLINE void + static inline void    add_to_rgbd_sum_with_factor(rgbd_group *sum,    rgba_group rgba,    double factor)   {    /* NOTE:    * This code MUST be MT-SAFE! (but also fast /per)    */   /* HIDE_GLOBAL_VARIABLES(); */ -  sum->r = DO_NOT_WARN((float)(sum->r+rgba.r*factor)); -  sum->g = DO_NOT_WARN((float)(sum->g+rgba.g*factor)); -  sum->b = DO_NOT_WARN((float)(sum->b+rgba.b*factor)); +  sum->r = (float)(sum->r+rgba.r*factor); +  sum->g = (float)(sum->g+rgba.g*factor); +  sum->b = (float)(sum->b+rgba.b*factor);   /* REVEAL_GLOBAL_VARIABLES(); */   }      /*   **! method object tuned_box(int x1,int y1,int x2,int y2,array(array(int)) corner_color)   **! Draws a filled rectangle with colors (and alpha values) tuned   **! between the corners.   **!   **! Tuning function is (1.0-x/xw)*(1.0-y/yw) where x and y is   **! the distance to the corner and xw and yw are the sides of the
pike.git/src/modules/Image/image.c:1778:   **! colors of the corners:   **! <pre>   **! ({x1y1,x2y1,x1y2,x2y2})   **! </pre>   **! each of these is an array of integeres:   **! <pre>   **! ({r,g,b}) or ({r,g,b,alpha})   **! </pre>   **! Default alpha channel value is 0 (opaque).   */ - INLINE static void + inline static void   image_tuned_box_leftright(const rgba_group left, const rgba_group right,    rgb_group *dest,    const int length, const int maxlength,    const int xsize, const int height)   {    int x, y=height;    rgb_group *from = dest;    if(!xsize || !height) return;    for(x=0; x<maxlength; x++)    { -  (dest+x)->r = DO_NOT_WARN((COLORTYPE)((((long)left.r)*(length-x)+((long)right.r)*(x))/length)); -  (dest+x)->g = DO_NOT_WARN((COLORTYPE)((((long)left.g)*(length-x)+((long)right.g)*(x))/length)); -  (dest+x)->b = DO_NOT_WARN((COLORTYPE)((((long)left.b)*(length-x)+((long)right.b)*(x))/length)); +  (dest+x)->r = (COLORTYPE)((((long)left.r)*(length-x)+((long)right.r)*(x))/length); +  (dest+x)->g = (COLORTYPE)((((long)left.g)*(length-x)+((long)right.g)*(x))/length); +  (dest+x)->b = (COLORTYPE)((((long)left.b)*(length-x)+((long)right.b)*(x))/length);    } -  while(--y) MEMCPY((dest+=xsize), from, maxlength*sizeof(rgb_group)); +  while(--y) memcpy((dest+=xsize), from, maxlength*sizeof(rgb_group));   }          - INLINE static void + inline static void   image_tuned_box_topbottom(const rgba_group left, const rgba_group right,    rgb_group *dest,    const int length, const int xsize,    const int height,    const int maxheight)   {    int x,y;    rgb_group color, *from, old;    if(!xsize || !maxheight) return; - #ifdef HIDE_WARNINGS +     old.r = old.g = old.b = 0; - #endif +     if(length > 128)    {    for(y=0; y<maxheight; y++)    { -  color.r = DO_NOT_WARN((COLORTYPE)((((long)left.r)*(height-y)+((long)right.r)*(y))/height)); -  color.g = DO_NOT_WARN((COLORTYPE)((((long)left.g)*(height-y)+((long)right.g)*(y))/height)); -  color.b = DO_NOT_WARN((COLORTYPE)((((long)left.b)*(height-y)+((long)right.b)*(y))/height)); +  color.r = (COLORTYPE)((((long)left.r)*(height-y)+((long)right.r)*(y))/height); +  color.g = (COLORTYPE)((((long)left.g)*(height-y)+((long)right.g)*(y))/height); +  color.b = (COLORTYPE)((((long)left.b)*(height-y)+((long)right.b)*(y))/height);    if(y && color_equal(old, color))    { -  MEMCPY(dest,dest-xsize,length*sizeof(rgb_group)); +  memcpy(dest,dest-xsize,length*sizeof(rgb_group));    dest+=xsize;    } else {    from = dest;    for(x=0; x<64; x++) *(dest++) = color;    for(;x<length-64;x+=64,dest+=64) -  MEMCPY(dest, from, 64*sizeof(rgb_group)); +  memcpy(dest, from, 64*sizeof(rgb_group));    for(;x<length; x++) *(dest++) = color;    dest += xsize-length;    old = color;    }    }    } else {    for(y=0; y<maxheight; y++)    { -  color.r = DO_NOT_WARN((COLORTYPE)((((long)left.r)*(height-y)+((long)right.r)*(y))/height)); -  color.g = DO_NOT_WARN((COLORTYPE)((((long)left.g)*(height-y)+((long)right.g)*(y))/height)); -  color.b = DO_NOT_WARN((COLORTYPE)((((long)left.b)*(height-y)+((long)right.b)*(y))/height)); +  color.r = (COLORTYPE)((((long)left.r)*(height-y)+((long)right.r)*(y))/height); +  color.g = (COLORTYPE)((((long)left.g)*(height-y)+((long)right.g)*(y))/height); +  color.b = (COLORTYPE)((((long)left.b)*(height-y)+((long)right.b)*(y))/height);    if(y && color_equal(old, color))    { -  MEMCPY(dest,dest-xsize,length*sizeof(rgb_group)); +  memcpy(dest,dest-xsize,length*sizeof(rgb_group));    dest+=xsize;    } else {    for(x=0; x<length; x++) *(dest++) = color;    dest += xsize-length;    old = color;    }    }    }   }   
pike.git/src/modules/Image/image.c:1865:    rgb_group *img;    INT32 ymax;    struct image *this;    double dxw, dyw;       if (args<5||    TYPEOF(sp[-args]) != T_INT||    TYPEOF(sp[1-args]) != T_INT||    TYPEOF(sp[2-args]) != T_INT||    TYPEOF(sp[3-args]) != T_INT) -  SIMPLE_TOO_FEW_ARGS_ERROR("Image.Image->tuned_box",5); +  SIMPLE_WRONG_NUM_ARGS_ERROR("tuned_box",5);    -  if (!THIS->img) -  Pike_error("Called Image.Image object is not initialized\n");; +  CHECK_INIT();       x1=sp[-args].u.integer;    y1=sp[1-args].u.integer;    x2=sp[2-args].u.integer;    y2=sp[3-args].u.integer;       if (TYPEOF(sp[4-args]) == T_ARRAY)    {    if (args>5) pop_n_elems(args-5);    args+=sp[-1].u.array->size-1;    sp--;    push_array_items(sp->u.array); /* frees */    }       if (args<8) -  SIMPLE_TOO_FEW_ARGS_ERROR("Image.Image->tuned_box",8); +  SIMPLE_WRONG_NUM_ARGS_ERROR("tuned_box",8);       if (!image_color_svalue_rgba(sp-4,&topleft)) -  SIMPLE_BAD_ARG_ERROR("Image.Image->tuned_box",5,"color"); +  SIMPLE_ARG_TYPE_ERROR("tuned_box",5,"color");    if (!image_color_svalue_rgba(sp-3,&topright)) -  SIMPLE_BAD_ARG_ERROR("Image.Image->tuned_box",6,"color"); +  SIMPLE_ARG_TYPE_ERROR("tuned_box",6,"color");    if (!image_color_svalue_rgba(sp-2,&bottomleft)) -  SIMPLE_BAD_ARG_ERROR("Image.Image->tuned_box",7,"color"); +  SIMPLE_ARG_TYPE_ERROR("tuned_box",7,"color");    if (!image_color_svalue_rgba(sp-1,&bottomright)) -  SIMPLE_BAD_ARG_ERROR("Image.Image->tuned_box",8,"color"); +  SIMPLE_ARG_TYPE_ERROR("tuned_box",8,"color");       if (x1>x2) x1^=x2,x2^=x1,x1^=x2,    sum=topleft,topleft=topright,topright=sum,    sum=bottomleft,bottomleft=bottomright,bottomright=sum;    if (y1>y2) y1^=y2,y2^=y1,y1^=y2,    sum=topleft,topleft=bottomleft,bottomleft=sum,    sum=topright,topright=bottomright,bottomright=sum;       pop_n_elems(args);    ref_push_object(THISOBJ);
pike.git/src/modules/Image/image.c:1957:    rgbda_group sum={0.0,0.0,0.0,0.0};    rgbd_group rgb;       add_to_rgbda_sum_with_factor(&sum, topleft,    (tfy=tune_factor(y,dyw))*tfx1);    add_to_rgbda_sum_with_factor(&sum, topright, tfy*tfx2);    add_to_rgbda_sum_with_factor(&sum, bottomleft,    (tfy=tune_factor(yw-y,dyw))*tfx1);    add_to_rgbda_sum_with_factor(&sum, bottomright, tfy*tfx2);    -  sum.alpha *= DO_NOT_WARN((float)(1.0/255.0)); +  sum.alpha *= (float)(1.0/255.0);    -  rgb.r = DO_NOT_WARN((float)(sum.r*(1.0-sum.alpha)+img->r*sum.alpha)); -  rgb.g = DO_NOT_WARN((float)(sum.g*(1.0-sum.alpha)+img->g*sum.alpha)); -  rgb.b = DO_NOT_WARN((float)(sum.b*(1.0-sum.alpha)+img->b*sum.alpha)); +  rgb.r = (float)(sum.r*(1.0-sum.alpha)+img->r*sum.alpha); +  rgb.g = (float)(sum.g*(1.0-sum.alpha)+img->g*sum.alpha); +  rgb.b = (float)(sum.b*(1.0-sum.alpha)+img->b*sum.alpha);       img->r = testrange(rgb.r+0.5);    img->g = testrange(rgb.g+0.5);    img->b = testrange(rgb.b+0.5);       img += this->xsize;    }    else    for (y=MAXIMUM(0,-y1); y<=ymax; y++)    {
pike.git/src/modules/Image/image.c:2058:    INT32 n;    INT32 x,y,xz;    struct object *o;    struct image *img;    rgb_group *d;    double grad=0.0;       push_int(THIS->xsize);    push_int(THIS->ysize);    o=clone_object(image_program,2); -  img=(struct image*)get_storage(o,image_program); +  img=get_storage(o,image_program);    d=img->img;       if (args && TYPEOF(sp[-1]) == T_FLOAT)    {    args--;    grad=sp[-1].u.float_number;    pop_n_elems(1);    }       n=args;       while (args--)    {    struct array *a = NULL;    if (TYPEOF(sp[-1]) != T_ARRAY ||    (a=sp[-1].u.array)->size!=5 ||    ( (a->type_field & ~BIT_INT) &&    (array_fix_type_field(a) & ~BIT_INT) ))    {    while (first) { c=first; first=c->next; free(c); } -  bad_arg_error("Image.Image->gradients",sp-args,args,0,"",sp-args, -  "Bad arguments to Image.Image->gradients()\n"); +  bad_arg_error("gradients",args,0,"",sp-args, +  "Bad arguments to gradients.\n");    }    c=malloc(sizeof(struct gr_point));    if (!c)    {    while (first) { c=first; first=c->next; free(c); }    SIMPLE_OUT_OF_MEMORY_ERROR("gradients", sizeof(struct gr_point));    }    c->next=first;    c->x=a->item[0].u.integer;    c->y=a->item[1].u.integer;    c->r=(double)a->item[2].u.integer;    c->g=(double)a->item[3].u.integer;    c->b=(double)a->item[4].u.integer;    first=c;    n--;    pop_n_elems(1);    }       if (!first) -  SIMPLE_TOO_FEW_ARGS_ERROR("Image.Image->gradients",1); +  SIMPLE_WRONG_NUM_ARGS_ERROR("gradients",1);       THREADS_ALLOW();       xz=img->xsize;    for (y=0; y<img->ysize; y++)    {    c=first;    while (c)    {    c->yd=y-c->y;
pike.git/src/modules/Image/image.c:2165:    r+=c->r*di;    g+=c->g*di;    b+=c->b*di;    z+=di;       c=c->next;    }       z=1.0/z;    -  d->r=DOUBLE_TO_COLORTYPE(r*z); -  d->g=DOUBLE_TO_COLORTYPE(g*z); -  d->b=DOUBLE_TO_COLORTYPE(b*z); +  d->r=(COLORTYPE)(r*z); +  d->g=(COLORTYPE)(g*z); +  d->b=(COLORTYPE)(b*z);    d++;    }    }       while (first) { c=first; first=c->next; free(c); }       THREADS_DISALLOW();       push_object(o);   }    -  + static void select_random(INT32 args) + { +  if(args>1) +  Pike_error("Too may arguments.\n"); +  if(!args) +  { +  struct svalue *random = +  simple_mapping_string_lookup(get_builtin_constants(), "random"); +  if(!random || (TYPEOF(*random) != T_FUNCTION)) +  Pike_error("Unable to resolve random function.\n"); +  push_svalue(random); +  } +  else if(TYPEOF(sp[-1])==T_INT) +  { +  struct program *o; +  push_constant_text("Random.Deterministic"); +  SAFE_APPLY_MASTER("resolv_or_error",1); +  if(TYPEOF(sp[-1])!=T_PROGRAM) +  Pike_error("Unable to resolve Random.Deterministic program.\n"); +  o = sp[-1].u.program; +  stack_swap(); +  push_object(clone_object(o, 1)); +  push_constant_text("random"); +  o_index(); +  if(TYPEOF(sp[-1])!=T_FUNCTION) +  Pike_error("random is not a function.\n"); +  } +  else if(TYPEOF(sp[-1])!=T_FUNCTION) +  { +  Pike_error("Expected seed or random function.\n"); +  } + } +    /*   **! method object test()   **! method object test(int seed) -  + **! method object test(function(int:string) random)   **! Generates a test image, currently random gradients.   **!   **! <table><tr valign=center>   **! <td><illustration> return lena(); </illustration></td>   **! <td><illustration> return lena()->test()</illustration></td>   **! <td><illustration> return lena()->test()</illustration></td>   **! </tr><tr>   **! <td>original</td>   **! <td>->test()</td>   **! <td>...and again</td>
pike.git/src/modules/Image/image.c:2204:   **! returns the new image   **! note   **! May be subject to change or cease without prior warning.   **!   **! see also: gradients, tuned_box   */      static void image_test(INT32 args)   {    int i; +  struct svalue *s; +  select_random(args); +  s = &Pike_sp[-1];    -  if (args) f_random_seed(args); -  +     for (i=0; i<5; i++)    { -  push_int(THIS->xsize); f_random(1); -  push_int(THIS->ysize); f_random(1); -  push_int((i!=0)?255:0); f_random(1); -  push_int((i!=1)?255:0); if (i!=4) f_random(1); -  push_int((i!=2)?255:0); if (i!=3) f_random(1); +  push_int(THIS->xsize); apply_svalue(s, 1); +  push_int(THIS->ysize); apply_svalue(s, 1); +  push_int((i!=0)?255:0); apply_svalue(s, 1); +  push_int((i!=1)?255:0); if (i!=4) apply_svalue(s, 1); +  push_int((i!=2)?255:0); if (i!=3) apply_svalue(s, 1);    f_aggregate(5);    }    push_float(2.0);    image_gradients(6); -  +  // Let apply clean the stack.   }      /*   **! method int xsize()   **! returns the width of the image   */      void image_xsize(INT32 args)   {    pop_n_elems(args);
pike.git/src/modules/Image/image.c:2283:    struct object *o;    struct image *img;       if (args<3)    {    rgb.r=87;    rgb.g=127;    rgb.b=41;    }    else -  getrgbl(&rgb,0,args,"Image.Image->grey()"); +  getrgbl(&rgb,0,args,"grey");    div=rgb.r+rgb.g+rgb.b;       o=clone_object(image_program,0);    img=(struct image*)o->storage;    *img=*THIS;    if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))    {    free_object(o);    SIMPLE_OUT_OF_MEMORY_ERROR("grey",    sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);
pike.git/src/modules/Image/image.c:2358:   */      void image_color(INT32 args)   {    INT32 x;    rgbl_group rgb;    rgb_group *s,*d;    struct object *o;    struct image *img;    -  if (!THIS->img) Pike_error("Called Image.Image object is not initialized\n");; +  CHECK_INIT();    if (args<3)    {    struct color_struct *cs;    if (args>0 && TYPEOF(sp[-args]) == T_INT)    rgb.r=rgb.b=rgb.g=sp[-args].u.integer;    else if (args>0 && TYPEOF(sp[-args]) == T_OBJECT && -  (cs = (struct color_struct *)get_storage(sp[-args].u.object, -  image_color_program))) +  (cs =get_storage(sp[-args].u.object, image_color_program)))    rgb.r=cs->rgb.r,    rgb.g=cs->rgb.g,    rgb.b=cs->rgb.b;    else    rgb.r=THIS->rgb.r,    rgb.g=THIS->rgb.g,    rgb.b=THIS->rgb.b;    }    else -  getrgbl(&rgb,0,args,"Image.Image->color()"); +  getrgbl(&rgb,0,args,"color");       o=clone_object(image_program,0);    img=(struct image*)o->storage;    *img=*THIS;    if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))    {    free_object(o);    SIMPLE_OUT_OF_MEMORY_ERROR("color",    sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);    }
pike.git/src/modules/Image/image.c:2405: Inside #if 0 and #if defined(ASSEMBLY_OK)
  #ifdef ASSEMBLY_OK    if( (image_cpuid & IMAGE_MMX) && x>>2 )    {    image_mult_buffer_mmx_x86asm( d,s,x>>2, RGB2ASMCOL( rgb ) );    s += x; x = x%4; s -= x;    }   #endif   #endif    while (x--)    { -  d->r = DO_NOT_WARN((COLORTYPE)( (((long)rgb.r*s->r)/255) )); -  d->g = DO_NOT_WARN((COLORTYPE)( (((long)rgb.g*s->g)/255) )); -  d->b = DO_NOT_WARN((COLORTYPE)( (((long)rgb.b*s->b)/255) )); +  d->r = (COLORTYPE)( (((long)rgb.r*s->r)/255) ); +  d->g = (COLORTYPE)( (((long)rgb.g*s->g)/255) ); +  d->b = (COLORTYPE)( (((long)rgb.b*s->b)/255) );    d++;    s++;    }    THREADS_DISALLOW();       pop_n_elems(args);    push_object(o);   }      /*
pike.git/src/modules/Image/image.c:2442:   **! returns the new image object   */      void image_invert(INT32 args)   {    size_t sz;    char *s,*d;    struct object *o;    struct image *img;    -  if (!THIS->img) -  Pike_error("Called Image.Image object is not initialized\n"); +  CHECK_INIT();       o=clone_object(image_program,0);    img=(struct image*)o->storage;    *img=*THIS;    sz = sizeof(rgb_group)*THIS->xsize * THIS->ysize;    if (!(img->img=malloc(sz + RGB_VEC_PAD)))    {    free_object(o);    SIMPLE_OUT_OF_MEMORY_ERROR("invert", sz + RGB_VEC_PAD);    }
pike.git/src/modules/Image/image.c:2525:         void image_threshold(INT32 args)   {    INT_TYPE x;    rgb_group *s,*d,rgb;    struct object *o;    struct image *img;    INT_TYPE level=-1;    -  if (!THIS->img) Pike_error("Called Image.Image object is not initialized\n"); +  CHECK_INIT();       if (args==1 && TYPEOF(sp[-args]) == T_INT) { -  get_all_args("threshold",args,"%i",&level); +  get_all_args(NULL,args,"%i",&level);    level*=3;    rgb.r=rgb.g=rgb.b=0;    } -  else if (!getrgb(THIS,0,args,args,"Image.Image->threshold()")) +  else if (!getrgb(THIS,0,args,args,"threshold"))    rgb.r=rgb.g=rgb.b=0;    else    rgb=THIS->rgb;       o=clone_object(image_program,0);    img=(struct image*)o->storage;    *img=*THIS;    if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))    {    free_object(o);
pike.git/src/modules/Image/image.c:2658:   **! returns the new image object   */      void image_hsv_to_rgb(INT32 args)   {    INT32 i;    rgb_group *s,*d;    struct object *o;    struct image *img;    char *err = NULL; -  if (!THIS->img) Pike_error("Called Image.Image object is not initialized\n");; +     -  +  CHECK_INIT(); +     o=clone_object(image_program,0);    img=(struct image*)o->storage;    *img=*THIS;       if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))    {    free_object(o);    SIMPLE_OUT_OF_MEMORY_ERROR("hsv_to_rgb",    sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);    }
pike.git/src/modules/Image/image.c:2693:       if(sat==0.0)    {    r = g = b = v;    } else {   #define i floor(h)   #define f (h-i)   #define p (v * (1 - sat))   #define q (v * (1 - (sat * f)))   #define t (v * (1 - (sat * (1 -f)))) -  switch(DOUBLE_TO_INT(i)) +  switch((int)(i))    {    case 6: /* 360 degrees. Same as 0.. */    case 0: r = v; g = t; b = p; break;    case 1: r = q; g = v; b = p; break;    case 2: r = p; g = v; b = t; break;    case 3: r = p; g = q; b = v; break;    case 4: r = t; g = p; b = v; break;    case 5: r = v; g = p; b = q; break;    default:    err = "Nope. Not possible";    goto exit_loop;    }    }   #undef i   #undef f   #undef p   #undef q   #undef t - #define FIX(X) ((X)<0.0?0:(X)>=1.0?255:DOUBLE_TO_INT((X)*255.0)) + #define FIX(X) ((X)<0.0?0:(X)>=1.0?255:(int)((X)*255.0))    d->r = FIX(r);    d->g = FIX(g);    d->b = FIX(b);    s++; d++;    }   exit_loop:    ; /* Needed to keep some compilers happy. */    THREADS_DISALLOW();       if (err) {
pike.git/src/modules/Image/image.c:2744:   #ifndef MIN3   #define MIN3(X,Y,Z) MINIMUM(MINIMUM(X,Y),Z)   #endif      void image_rgb_to_hsv(INT32 args)   {    INT32 i;    rgb_group *s,*d;    struct object *o;    struct image *img; -  if (!THIS->img) -  Pike_error("Called Image.Image object is not initialized\n"); +     -  +  CHECK_INIT(); +     o=clone_object(image_program,0);    img=(struct image*)o->storage;    *img=*THIS;       if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))    {    free_object(o);    SIMPLE_OUT_OF_MEMORY_ERROR("rgb_to_hsv",    sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);    }       d=img->img;    s=THIS->img;       THREADS_ALLOW();    i=img->xsize*img->ysize;    while (i--)    { -  register int r,g,b; -  register int v, delta; -  register int h; +  int r,g,b; +  int v, delta; +  int h;       r = s->r; g = s->g; b = s->b;    v = MAX3(r,g,b);    delta = v - MIN3(r,g,b);    -  if(r==v) h = DOUBLE_TO_INT(((g-b)/(double)delta)*(255.0/6.0)); -  else if(g==v) h = DOUBLE_TO_INT((2.0+(b-r)/(double)delta)*(255.0/6.0)); -  else h = DOUBLE_TO_INT((4.0+(r-g)/(double)delta)*(255.0/6.0)); +  if(r==v) h = (int)(((g-b)/(double)delta)*(255.0/6.0)); +  else if(g==v) h = (int)((2.0+(b-r)/(double)delta)*(255.0/6.0)); +  else h = (int)((4.0+(r-g)/(double)delta)*(255.0/6.0));    if(h<0) h+=255;       /* printf("hsv={ %d,%d,%d }\n", h, (int)((delta/(float)v)*255), v);*/ -  d->r = DOUBLE_TO_INT(h); -  d->g = DOUBLE_TO_INT((delta/(double)v)*255.0); +  d->r = (int)h; +  d->g = (int)((delta/(double)v)*255.0);    d->b = v;    s++; d++;    }    THREADS_DISALLOW();       pop_n_elems(args);    push_object(o);   }      
pike.git/src/modules/Image/image.c:2872:      #define NORM_Y(y) ((((y)-16)*256)/220)   #define NORM_C(c) ((((c)-128)*128)/112)      void image_yuv_to_rgb(INT32 args)   {    INT32 i;    rgb_group *s,*d;    struct object *o;    struct image *img; -  if (!THIS->img) Pike_error("Called Image.Image object is not initialized\n");; +     -  +  CHECK_INIT(); +     o=clone_object(image_program,0);    img=(struct image*)o->storage;    *img=*THIS;       if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))    {    free_object(o);    SIMPLE_OUT_OF_MEMORY_ERROR("yuv_to_rgb",    sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);    }
pike.git/src/modules/Image/image.c:2922:    pop_n_elems(args);    push_object(o);   }      void image_rgb_to_yuv(INT32 args)   {    INT32 i;    rgb_group *s,*d;    struct object *o;    struct image *img; -  if (!THIS->img) -  Pike_error("Called Image.Image object is not initialized\n"); +     -  +  CHECK_INIT();    o=clone_object(image_program,0);    img=(struct image*)o->storage;    *img=*THIS;       if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))    {    free_object(o);    SIMPLE_OUT_OF_MEMORY_ERROR("rgb_to_yuv",    sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);    }
pike.git/src/modules/Image/image.c:3015:   **! see also: select_from   */      void image_distancesq(INT32 args)   {    INT32 i;    rgb_group *s,*d,rgb;    struct object *o;    struct image *img;    -  if (!THIS->img) -  Pike_error("Called Image.Image object is not initialized\n"); +  CHECK_INIT();    -  getrgb(THIS,0,args,args,"Image.Image->distancesq()"); +  getrgb(THIS,0,args,args,"distancesq");       o=clone_object(image_program,0);    img=(struct image*)o->storage;    *img=*THIS;    if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))    {    free_object(o);    SIMPLE_OUT_OF_MEMORY_ERROR("distancesq",    sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);    }
pike.git/src/modules/Image/image.c:3212:   **! arg int y   **! originating pixel in the image   **!   **! see also: distancesq   */      void image_select_from(INT32 args)   {    struct object *o;    struct image *img; -  INT32 low_limit=0; +  int x,y,low_limit=30;    -  if (!THIS->img) -  Pike_error("Called Image.Image object is not initialized\n"); -  -  if (args<2 -  || TYPEOF(sp[-args]) != T_INT -  || TYPEOF(sp[1-args]) != T_INT) -  bad_arg_error("Image",sp-args,args,0,"",sp-args, -  "Bad arguments to Image()\n"); -  -  if (args>=3) -  if (TYPEOF(sp[2-args]) != T_INT) -  bad_arg_error("Image",sp-args,args,3,"",sp+3-1-args, -  "Bad argument 3 (edge value) to Image()\n"); -  else -  low_limit=MAXIMUM(0,sp[2-args].u.integer); -  else -  low_limit=30; +  CHECK_INIT(); +  get_all_args(NULL, args, "%d%d.%d", &x, &y, &low_limit); +  if( low_limit<0 ) low_limit=0;    low_limit=low_limit*low_limit;       o=clone_object(image_program,0);    img=(struct image*)o->storage;    *img=*THIS;    if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))    {    free_object(o);    SIMPLE_OUT_OF_MEMORY_ERROR("select_from",    sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);    } -  MEMSET(img->img,0,sizeof(rgb_group)*img->xsize*img->ysize); +  memset(img->img,0,sizeof(rgb_group)*img->xsize*img->ysize);    -  if (sp[-args].u.integer>=0 && sp[-args].u.integer<img->xsize -  && sp[1-args].u.integer>=0 && sp[1-args].u.integer<img->ysize) +  if (x>=0 && x<img->xsize && y>=0 && y<img->ysize)    { -  isf_seek(ISF_LEFT|ISF_RIGHT,1,low_limit, -  sp[-args].u.integer,sp[-args].u.integer, -  sp[1-args].u.integer, +  isf_seek(ISF_LEFT|ISF_RIGHT,1,low_limit,x,x,y,    THIS->img,img->img,img->xsize,img->ysize, -  pixel(THIS,sp[-args].u.integer,sp[1-args].u.integer),0); -  isf_seek(ISF_LEFT|ISF_RIGHT,-1,low_limit, -  sp[-args].u.integer,sp[-args].u.integer, -  sp[1-args].u.integer, +  pixel(THIS,x,y),0); +  isf_seek(ISF_LEFT|ISF_RIGHT,-1,low_limit,x,x,y,    THIS->img,img->img,img->xsize,img->ysize, -  pixel(THIS,sp[-args].u.integer,sp[1-args].u.integer),0); +  pixel(THIS,x,y),0);    -  MARK_DISTANCE(pixel(img,sp[-args].u.integer,sp[1-args].u.integer),0); +  MARK_DISTANCE(pixel(img,x,y),0);    }       pop_n_elems(args);    push_object(o);   }         /*   **! method object bitscale(float factor)   **! method object bitscale(float xfactor,float yfactor)
pike.git/src/modules/Image/image.c:3321:    oldx = THIS->xsize;    oldy = THIS->ysize;       if( args == 1 )    {    if( TYPEOF(sp[-1]) == T_INT )    {    newx = oldx * sp[-1].u.integer;    newy = oldy * sp[-1].u.integer;    } else if( TYPEOF(sp[-1]) == T_FLOAT ) { -  newx = DOUBLE_TO_INT(oldx * sp[-1].u.float_number); -  newy = DOUBLE_TO_INT(oldy * sp[-1].u.float_number); +  newx = (int)(oldx * sp[-1].u.float_number); +  newy = (int)(oldy * sp[-1].u.float_number);    } else    Pike_error("The scale factor must be an integer less than 2^32, or a float\n");    } else if( args == 2 ) {    if( TYPEOF(sp[-1]) != TYPEOF(sp[-2]) )    Pike_error("Wrong type of argument\n");    if( TYPEOF(sp[-2]) == T_INT )    (newx = sp[-2].u.integer),(newy = sp[-1].u.integer);    else if( TYPEOF(sp[-2]) == T_FLOAT )    { -  newx = DOUBLE_TO_INT(oldx*sp[-2].u.float_number); -  newy = DOUBLE_TO_INT(oldy*sp[-1].u.float_number); +  newx = (int)(oldx*sp[-2].u.float_number); +  newy = (int)(oldy*sp[-1].u.float_number);       } else    Pike_error( "Wrong type of arguments\n");    }       /* Not really nessesary if I use floats below.. */    /* FIXME */    if( newx > 65536 || newy > 65536 || oldx > 65536 || oldy > 65536)    Pike_error("Image too big.\n");   
pike.git/src/modules/Image/image.c:3505:    rgbd_group *matrix;    rgb_group default_rgb;    struct object *o;    double div;    ONERROR o_err, matrix_err;      CHRONO("apply_matrix");       if (args<1 ||    TYPEOF(sp[-args]) != T_ARRAY) -  bad_arg_error("Image",sp-args,args,0,"",sp-args, -  "Bad arguments to Image()\n"); +  SIMPLE_ARG_TYPE_ERROR("apply_matrix", 1, "array");       if (args>3) -  if (TYPEOF(sp[1-args]) != T_INT || -  TYPEOF(sp[2-args]) != T_INT || -  TYPEOF(sp[3-args]) != T_INT) -  Pike_error("Illegal argument(s) (2,3,4) to Image.Image->apply_matrix()\n"); -  else +     { -  default_rgb.r=sp[1-args].u.integer; -  default_rgb.g=sp[1-args].u.integer; -  default_rgb.b=sp[1-args].u.integer; +  struct array *a; +  int r, g, b; +  get_all_args(NULL, args, "%a%d%d%d", &a, &r, &g, &b); +  default_rgb.r = r; +  default_rgb.g = g; +  default_rgb.b = b;    }    else    {    default_rgb.r=0;    default_rgb.g=0;    default_rgb.b=0;    }       if (args>4    && TYPEOF(sp[4-args]) == T_INT)
pike.git/src/modules/Image/image.c:3546:    if (!div) div=1;    }    else div=1;       height=sp[-args].u.array->size;    width=-1;    for (i=0; i<height; i++)    {    struct svalue *s = sp[-args].u.array->item + i;    if (TYPEOF(*s) != T_ARRAY) -  Pike_error("Illegal contents of (root) array (Image.Image->apply_matrix)\n"); +  Pike_error("Illegal contents of (root) array.\n");    if (width==-1)    width = s->u.array->size;    else    if (width != s->u.array->size) -  Pike_error("Arrays has different size (Image.Image->apply_matrix)\n"); +  Pike_error("Arrays has different size.\n");    }    if (width==-1) width=0;       matrix=xalloc(sizeof(rgbd_group)*width*height+1);       for (i=0; i<height; i++)    {    struct svalue *s = sp[-args].u.array->item + i;    for (j=0; j<width; j++)    {
pike.git/src/modules/Image/image.c:3674:    int height=3;    int width=3;    unsigned char *tmp,*d;    INT32 ai=0;    rgb_group *s,*di;    int x,y,xz;    rgbl_group bkgl={0,0,0};    struct object *o;    struct image *img;    -  if (!THIS->img || !THIS->xsize || !THIS->ysize) -  Pike_error("Called Image.Image object is not initialized\n");; +  CHECK_INIT();       if (args && TYPEOF(sp[-args]) == T_ARRAY)    {    int i,j;    height=sp[-args].u.array->size;    width=-1;    for (i=0; i<height; i++)    {    struct svalue *s = sp[-args].u.array->item + i;    if (TYPEOF(*s) != T_ARRAY) -  Pike_error("Image.Image->outline: Illegal contents of (root) array\n"); +  Pike_error("Illegal contents of (root) array.\n");    if (width==-1)    width=s->u.array->size;    else    if (width!=s->u.array->size) -  Pike_error("Image.Image->outline: Arrays has different size\n"); +  Pike_error("Arrays have different size.\n");    }    if (width==-1) width=0;       matrix=xalloc(sizeof(int)*width*height+1);       for (i=0; i<height; i++)    {    struct svalue *s=sp[-args].u.array->item + i;    for (j=0; j<width; j++)    {
pike.git/src/modules/Image/image.c:3718:    }    ai=1;    }       push_int(THIS->xsize);    push_int(THIS->ysize);    o=clone_object(image_program,2);    img=(struct image*)(o->storage);    img->rgb=THIS->rgb;    -  tmp=malloc((THIS->xsize+width)*(THIS->ysize+height+1)); +  tmp=calloc((THIS->xsize+width),(THIS->ysize+height+1));    if (!tmp) {    free_object(o);    if (matrix!=defaultmatrix) free(matrix);    SIMPLE_OUT_OF_MEMORY_ERROR("outline",    (THIS->xsize+width)*(THIS->ysize+height)+1);    } -  MEMSET(tmp,0,(THIS->xsize+width)*(THIS->ysize+height)); +        s=THIS->img;       if (!mask)    {    if (args-ai==6)    { -  getrgbl(&bkgl,ai+3,args,"Image.Image->outline"); +  getrgbl(&bkgl,ai+3,args,"outline");    pop_n_elems(args-(ai+3));    args=ai+3;    }    else if (args-ai==7)    { -  getrgbl(&bkgl,ai+4,args,"Image.Image->outline"); +  getrgbl(&bkgl,ai+4,args,"outline");    pop_n_elems(args-(ai+4));    args=ai+4;    }    else    {    bkgl.r=s->r;    bkgl.g=s->g;    bkgl.b=s->b;    } -  getrgb(img,ai,args,args,"Image.Image->outline"); +  getrgb(img,ai,args,args,"outline");    }    else    {    if (args-ai==4)    { -  getrgbl(&bkgl,ai,args,"Image.Image->outline_mask"); +  getrgbl(&bkgl,ai,args,"outline_mask");    pop_n_elems(args-(ai+3));    args=ai+3;    }    else    {    bkgl.r=s->r;    bkgl.g=s->g;    bkgl.b=s->b;    }    }
pike.git/src/modules/Image/image.c:3886:         void image_modify_by_intensity(INT32 args)   {    INT32 x,y;    rgbl_group rgb;    rgb_group *list;    rgb_group *s,*d;    struct object *o;    struct image *img; -  long div; +  unsigned int div;    -  if (!THIS->img) -  Pike_error("Called Image.Image object is not initialized\n"); +  CHECK_INIT();    if (args<5) -  SIMPLE_TOO_FEW_ARGS_ERROR("Image.Image->modify_by_intensity()",5); +  SIMPLE_WRONG_NUM_ARGS_ERROR("modify_by_intensity",5);    -  getrgbl(&rgb,0,args,"Image.Image->modify_by_intensity()"); +  getrgbl(&rgb,0,args,"modify_by_intensity");    div=rgb.r+rgb.g+rgb.b;    if (!div) div=1;       s=xalloc(sizeof(rgb_group)*(args-3)+RGB_VEC_PAD);       for (x=0; x<args-3; x++)    {    if (TYPEOF(sp[3-args+x]) == T_INT)    s[x].r=s[x].g=s[x].b=testrange( sp[3-args+x].u.integer );    else if (TYPEOF(sp[3-args+x]) == T_ARRAY &&
pike.git/src/modules/Image/image.c:3936:    sizeof(rgb_group)*256+RGB_VEC_PAD);    }    for (x=0; x<args-4; x++)    {    INT32 p1,p2,r;    p1=(255L*x)/(args-4);    p2=(255L*(x+1))/(args-4);    r=p2-p1;    for (y=0; y<r; y++)    { -  list[y+p1].r = DO_NOT_WARN((COLORTYPE)((((long)s[x].r)*(r-y)+((long)s[x+1].r)*(y))/r)); -  list[y+p1].g = DO_NOT_WARN((COLORTYPE)((((long)s[x].g)*(r-y)+((long)s[x+1].g)*(y))/r)); -  list[y+p1].b = DO_NOT_WARN((COLORTYPE)((((long)s[x].b)*(r-y)+((long)s[x+1].b)*(y))/r)); +  list[y+p1].r = (COLORTYPE)((((long)s[x].r)*(r-y)+((long)s[x+1].r)*(y))/r); +  list[y+p1].g = (COLORTYPE)((((long)s[x].g)*(r-y)+((long)s[x+1].g)*(y))/r); +  list[y+p1].b = (COLORTYPE)((((long)s[x].b)*(r-y)+((long)s[x+1].b)*(y))/r);    }    }    list[255]=s[x];    free(s);       o=clone_object(image_program,0);    img=(struct image*)o->storage;    *img=*THIS;    if (!(img->img=malloc(sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD)))    {
pike.git/src/modules/Image/image.c:3962:    sizeof(rgb_group)*THIS->xsize*THIS->ysize+RGB_VEC_PAD);    }       d=img->img;    s=THIS->img;       x=THIS->xsize*THIS->ysize;    THREADS_ALLOW();    while (x--)    { -  int q = ((((int)s->r)*rgb.r+((int)s->g)*rgb.g+((int)s->b)*rgb.b)/div); +  unsigned int q = (s->r*rgb.r + s->g*rgb.g + s->b*rgb.b)/div;    *(d++)=list[testrange( q )];    s++;    }    THREADS_DISALLOW();       free(list);       pop_n_elems(args);    push_object(o);   }
pike.git/src/modules/Image/image.c:4008:   */      static void image_apply_curve_3( unsigned char curve[3][256] )   {    int i;    struct object *o;    rgb_group *s = THIS->img, *d;    push_int( THIS->xsize );    push_int( THIS->ysize );    o = clone_object( image_program, 2 ); -  d = ((struct image *)get_storage( o, image_program ))->img; +  d = ((struct image*)get_storage( o, image_program ))->img;    i = THIS->xsize*THIS->ysize;       THREADS_ALLOW();    for( ; i>0; i-- )    {    d->r = curve[0][s->r];    d->g = curve[1][s->g];    (d++)->b = curve[2][(s++)->b];    }    THREADS_DISALLOW();
pike.git/src/modules/Image/image.c:4031:   }      static void image_apply_curve_1( unsigned char curve[256] )   {    int i;    struct object *o;    rgb_group *s = THIS->img, *d;    push_int( THIS->xsize );    push_int( THIS->ysize );    o = clone_object( image_program, 2 ); -  d = ((struct image *)get_storage( o, image_program ))->img; +  d = ((struct image*)get_storage( o, image_program ))->img;    i = THIS->xsize*THIS->ysize;    THREADS_ALLOW();    for( ; i>0; i-- )    {    d->r = curve[s->r];    d->g = curve[s->g];    (d++)->b = curve[(s++)->b];    }    THREADS_DISALLOW();    push_object( o );   }         static void image_apply_curve_2( struct object *o,    int channel,    unsigned char curve[256] )   {    int i;    rgb_group *d; -  d = ((struct image *)get_storage(o,image_program))->img; +  d = ((struct image*)get_storage(o,image_program))->img;    i = THIS->xsize*THIS->ysize;       THREADS_ALLOW();    switch( channel )    {    case 0: for( ; i>0; i--,d++ ) d->r = curve[d->r]; break;    case 1: for( ; i>0; i--,d++ ) d->g = curve[d->g]; break;    case 2: for( ; i>0; i--,d++ ) d->b = curve[d->b]; break;    }    THREADS_DISALLOW();
pike.git/src/modules/Image/image.c:4081:   {    int i, j;    switch( args )    {    case 3:    {    unsigned char curve[3][256];    for( i = 0; i<3; i++ )    if( TYPEOF(sp[-args+i]) != T_ARRAY ||    sp[-args+i].u.array->size != 256 ) -  bad_arg_error("Image.Image->apply_curve", -  sp-args, args, 0, "", sp-args, -  "Bad arguments to apply_curve()\n"); +  bad_arg_error("apply_curve", +  args, i+1, "array(int(8bit))", sp-args, +  "Bad argument to apply_curve.\n");    else -  for( j = 0; j<256; j++ ) -  if( TYPEOF(sp[-args+i].u.array->item[j]) == T_INT ) +  for( j = 0; j<256; j++ ) { +  if( TYPEOF(sp[-args+i].u.array->item[j]) != T_INT ) { +  bad_arg_error("apply_curve", +  args, i+1, "array(int(8bit))", sp-args, +  "Bad argument to apply_curve.\n"); +  }    curve[i][j]=MINIMUM(sp[-args+i].u.array->item[j].u.integer,255); -  +  }    pop_n_elems( args );    image_apply_curve_3( curve );    return;    }    case 2:    {    unsigned char curve[256];    int chan = 0, co = 0;    struct object *o;       if( TYPEOF(sp[-args]) != T_STRING ) -  SIMPLE_BAD_ARG_ERROR("Image.Image->apply_curve()", 1, -  "string"); +  SIMPLE_ARG_TYPE_ERROR("apply_curve", 1, "string");    if( TYPEOF(sp[-args+1]) != T_ARRAY ||    sp[-args+1].u.array->size != 256 ) -  SIMPLE_BAD_ARG_ERROR("Image.Image->apply_curve()", 2, -  "256 element array"); +  bad_arg_error("apply_curve", +  args, 2, "array(int(8bit))", sp-args, +  "Bad argument to apply_curve.\n");    -  for( j = 0; j<256; j++ ) -  if( TYPEOF(sp[-args+1].u.array->item[j]) == T_INT ) +  for( j = 0; j<256; j++ ) { +  if( TYPEOF(sp[-args+1].u.array->item[j]) != T_INT ) { +  bad_arg_error("apply_curve", +  args, 2, "array(int(8bit))", sp-args, +  "Bad argument to apply_curve.\n"); +  }    curve[j] = MINIMUM(sp[-args+1].u.array->item[j].u.integer,255); -  +  }       MAKE_CONST_STRING(s_red,"red");    MAKE_CONST_STRING(s_green,"green");    MAKE_CONST_STRING(s_blue,"blue");    MAKE_CONST_STRING(s_saturation,"saturation");    MAKE_CONST_STRING(s_value,"value");    MAKE_CONST_STRING(s_hue,"hue");       if( sp[-args].u.string == s_red )    {
pike.git/src/modules/Image/image.c:4155:    co = 0;    }    else    Pike_error("Unknown channel in argument 1.\n");       if( co )    {    push_int( THIS->xsize );    push_int( THIS->ysize );    o = clone_object( image_program, 2 ); -  MEMCPY( ((struct image *)get_storage(o,image_program))->img, +  memcpy( ((struct image*)get_storage(o,image_program))->img,    THIS->img,    THIS->xsize*THIS->ysize*sizeof(rgb_group) );    }    else    {    image_rgb_to_hsv( 0 );    o = sp[-1].u.object;    sp--;    }    image_apply_curve_2( o, chan, curve );
pike.git/src/modules/Image/image.c:4179:    stack_swap();    pop_stack();    }    return;    }    case 1:    {    unsigned char curve[256];    if( TYPEOF(sp[-args]) != T_ARRAY ||    sp[-args].u.array->size != 256 ) -  bad_arg_error("Image.Image->apply_curve", -  sp-args, args, 0, "", sp-args, -  "Bad arguments to apply_curve()\n" ); +  bad_arg_error("apply_curve", +  args, 0, "array(int(8bit))", sp-args, +  "Bad argument to apply_curve.\n" );    else -  for( j = 0; j<256; j++ ) -  if( TYPEOF(sp[-args].u.array->item[j]) == T_INT ) +  for( j = 0; j<256; j++ ) { +  if(TYPEOF(sp[-args].u.array->item[j]) != T_INT) { +  bad_arg_error("apply_curve", +  args, 0, "array(int(8bit))", sp-args, +  "Bad argument to apply_curve.\n"); +  }    curve[j] = MINIMUM(sp[-args].u.array->item[j].u.integer,255); -  +  }    pop_n_elems( args );    image_apply_curve_1( curve );    return;    }    }   }         /*   **! method object gamma(float g)
pike.git/src/modules/Image/image.c:4226:   **! see also: grey, `*, color   */      static void img_make_gammatable(COLORTYPE *d,double gamma)   {    static COLORTYPE last_gammatable[256];    static double last_gamma;    static int had_gamma=0;       if (had_gamma && last_gamma==gamma) -  MEMCPY(d,last_gammatable,sizeof(COLORTYPE)*256); +  memcpy(d,last_gammatable,sizeof(COLORTYPE)*256);    else    {    int i;    COLORTYPE *dd=d;    double q=1/255.0;    for (i=0; i<256; i++)    {    double d=pow(i*q,gamma)*255;    *(dd++)=testrange(d);    } -  MEMCPY(last_gammatable,d,sizeof(COLORTYPE)*256); +  memcpy(last_gammatable,d,sizeof(COLORTYPE)*256);    last_gamma=gamma;    had_gamma=1;    }   }      void image_gamma(INT32 args)   {    INT32 x;    rgb_group *s,*d;    struct object *o;    struct image *img;    COLORTYPE _newg[256],_newb[256],*newg,*newb;    double gammar=0.0, gammab=0.0, gammag=0.0;    COLORTYPE newr[256];    -  if (!THIS->img) -  Pike_error("Called Image.Image object is not initialized\n"); +  CHECK_INIT();    if (args==1) {    if (TYPEOF(sp[-args]) == T_INT)    gammar=gammab=gammag=(double)sp[-args].u.integer;    else if (TYPEOF(sp[-args]) == T_FLOAT)    gammar=gammab=gammag=sp[-args].u.float_number;    else -  SIMPLE_BAD_ARG_ERROR("Image.Image->gamma",1,"int|float"); +  SIMPLE_ARG_TYPE_ERROR("gamma",1,"int|float");    }    else if (args==3)    {    if (TYPEOF(sp[-args]) == T_INT) gammar=(double)sp[-args].u.integer;    else if (TYPEOF(sp[-args]) == T_FLOAT) gammar=sp[-args].u.float_number; -  else SIMPLE_BAD_ARG_ERROR("Image.Image->gamma",1,"int|float"); +  else SIMPLE_ARG_TYPE_ERROR("gamma",1,"int|float");       if (TYPEOF(sp[1-args]) == T_INT) gammag=(double)sp[1-args].u.integer;    else if (TYPEOF(sp[1-args]) == T_FLOAT) gammag=sp[1-args].u.float_number; -  else SIMPLE_BAD_ARG_ERROR("Image.Image->gamma",2,"int|float"); +  else SIMPLE_ARG_TYPE_ERROR("gamma",2,"int|float");       if (TYPEOF(sp[2-args]) == T_INT) gammab=(double)sp[2-args].u.integer;    else if (TYPEOF(sp[2-args]) == T_FLOAT) gammab=sp[2-args].u.float_number; -  else SIMPLE_BAD_ARG_ERROR("Image.Image->gamma",3,"int|float"); +  else SIMPLE_ARG_TYPE_ERROR("gamma",3,"int|float");    }    else -  Pike_error("Image.Image->gamma(): illegal number of arguments\n"); +  Pike_error("Illegal number of arguments.\n");       if (gammar==gammab && gammab==gammag)    {    if (gammar==1.0) /* just copy */    {    pop_n_elems(args);    image_clone(0);    return;    }    img_make_gammatable(newb=newg=newr,gammar);
pike.git/src/modules/Image/image.c:4351:   **! the hidden message   */      void image_write_lsb_rgb(INT32 args)   {    int n,b;    ptrdiff_t l;    rgb_group *d;    char *s;    -  if (args<1 -  || TYPEOF(sp[-args]) != T_STRING) -  bad_arg_error("Image",sp-args,args,0,"",sp-args, -  "Bad arguments to Image()\n"); -  -  s=sp[-args].u.string->str; +  get_all_args(NULL, args, "%c", &s);    l=sp[-args].u.string->len;       n=THIS->xsize * THIS->ysize;    d=THIS->img;       b=128;       if (d)    while (n--)    {
pike.git/src/modules/Image/image.c:4397:       ps=begin_shared_string((THIS->xsize*THIS->ysize*sizeof(rgb_group)+7)>>3);       d=ps->str;       n=THIS->xsize * THIS->ysize;    s=THIS->img;       b=128;    -  MEMSET(d,0,(THIS->xsize*THIS->ysize*sizeof(rgb_group)+7)>>3); +  memset(d,0,(THIS->xsize*THIS->ysize*sizeof(rgb_group)+7)>>3);       if (s)    while (n--)    {    if (b==0) { b=128; d++; }    *d|=(s->r&1)*b; b>>=1;    if (b==0) { b=128; d++; }    *d|=(s->g&1)*b; b>>=1;    if (b==0) { b=128; d++; }    *d|=(s->b&1)*b; b>>=1;
pike.git/src/modules/Image/image.c:4422:    push_string(end_shared_string(ps));   }      void image_write_lsb_grey(INT32 args)   {    int n,b;    ptrdiff_t l;    rgb_group *d;    char *s;    -  if (args<1 -  || TYPEOF(sp[-args]) != T_STRING) -  bad_arg_error("Image",sp-args,args,0,"",sp-args, -  "Bad arguments to Image()\n"); -  -  s=sp[-args].u.string->str; +  get_all_args(NULL, args, "%c", &s);    l=sp[-args].u.string->len;       n=THIS->xsize * THIS->ysize;    d=THIS->img;       b=128;       if (d)    while (n--)    {
pike.git/src/modules/Image/image.c:4476:       ps=begin_shared_string((THIS->xsize*THIS->ysize+7)>>3);       d=ps->str;       n=THIS->xsize * THIS->ysize;    s=THIS->img;       b=128;    -  MEMSET(d,0,(THIS->xsize*THIS->ysize+7)>>3); +  memset(d,0,(THIS->xsize*THIS->ysize+7)>>3);       if (s)    while (n--)    {    int q=(s->r&1)+(s->g&1)+(s->b&1); /* vote */    if (b==0) { b=128; d++; }    *d|=(q>1)*b; b>>=1;    s++;    }       pop_n_elems(args);    push_string(end_shared_string(ps));   }      /* - **! method string cast(string type) + **! method string|array cast(string type)   **! Cast the image to another datatype. Currently supported   **! are string ("rgbrgbrgb...") and array (double array   **! of <ref>Image.Color</ref> objects).   **! see also: Image.Color,Image.X   */      void image_cast(INT32 args)   { -  if (!args) -  SIMPLE_TOO_FEW_ARGS_ERROR("Image.Image->cast",1); -  if (TYPEOF(sp[-args]) == T_STRING || sp[-args].u.string->size_shift) -  { -  if (!THIS->img) -  Pike_error("Called Image.Image object is not initialized\n"); +  struct pike_string *type;    -  if (strncmp(sp[-args].u.string->str,"array",5)==0) +  get_all_args(NULL, args, "%n", &type); +  CHECK_INIT(); +  +  if (type == literal_array_string)    {    int i,j;    rgb_group *s=THIS->img;    -  pop_n_elems(args); -  +     for (i=0; i<THIS->ysize; i++)    {    for (j=0; j<THIS->xsize; j++)    {    _image_make_rgb_color(s->r,s->g,s->b);    s++;    }    f_aggregate(THIS->xsize);    }    f_aggregate(THIS->ysize); -  -  return; +     } -  if (strncmp(sp[-args].u.string->str,"string",6)==0) +  else if (type == literal_string_string)    { -  pop_n_elems(args); +     push_string(make_shared_binary_string((char *)THIS->img,    THIS->xsize*THIS->ysize    *sizeof(rgb_group))); -  return; +     } -  +  else +  push_undefined();   } -  SIMPLE_BAD_ARG_ERROR("Image.Image->cast",1,"string(\"array\"|\"string\")"); - } +       static void image__sprintf( INT32 args )   {    int x; -  if (args != 2 ) -  SIMPLE_TOO_FEW_ARGS_ERROR("_sprintf",2); -  if (TYPEOF(sp[-args]) != T_INT) -  SIMPLE_BAD_ARG_ERROR("_sprintf",0,"integer"); -  if (TYPEOF(sp[1-args]) != T_MAPPING) -  SIMPLE_BAD_ARG_ERROR("_sprintf",1,"mapping"); +  get_all_args(NULL, args, "%d", &x);    -  x = sp[-2].u.integer; -  +     pop_n_elems( 2 );    switch( x )    {    case 't': -  push_constant_text("Image.Image"); +  push_static_text("Image.Image");    return;    case 'O': -  push_constant_text( "Image.Image( %d x %d /* %.1fKb */)" ); +  push_static_text( "Image.Image( %d x %d /* %.1fKb */)" );    push_int( THIS->xsize );    push_int( THIS->ysize ); -  push_float( DO_NOT_WARN((FLOAT_TYPE)((THIS->xsize * THIS->ysize) / -  1024.0 * 3.0)) ); +  push_float( (FLOAT_TYPE)((THIS->xsize * THIS->ysize) / +  1024.0 * 3.0) );    f_sprintf( 4 );    return;    default:    push_int(0);    return;    }   }      /*   **! method object grey_blur(int no_pass)
pike.git/src/modules/Image/image.c:4600:   */      static void image_grey_blur( INT32 args )   {    /* Basically a exactly like blur, but only uses the r color channel. */    INT_TYPE t;    int x, y, cnt;    int xe = THIS->xsize;    int ye = THIS->ysize;    rgb_group *rgb = THIS->img; -  if( args != 1 ) -  SIMPLE_TOO_FEW_ARGS_ERROR("grey_blur",1); +     -  if( !rgb ) -  Pike_error("This object is not initialized\n"); +  get_all_args(NULL, args, "%I", &t); +  CHECK_INIT();    -  if (TYPEOF(sp[-args]) != T_INT) SIMPLE_BAD_ARG_ERROR("grey_blur",0,"integer"); -  -  t = sp[-args].u.integer; /* times */ -  +     for( cnt=0; cnt<t; cnt++ )    {    rgb_group *ro1=NULL, *ro2=NULL, *ro3=rgb;    for( y=0; y<ye; y++ )    {    ro1 = ro2;    ro2 = ro3;    ro3 = ( y < ye-1 ) ? rgb+xe*(y+1) : 0;       for( x=0; x<xe; x++ )
pike.git/src/modules/Image/image.c:4675:   static void image_blur( INT32 args )   /* about four times faster than the generic apply matrix for this    * special case. */   {    INT_TYPE t;    int x, y, cnt;    int xe = THIS->xsize;    int ye = THIS->ysize;    rgb_group *rgb = THIS->img;    if( args != 1 ) -  SIMPLE_TOO_FEW_ARGS_ERROR("blur",1); +  SIMPLE_WRONG_NUM_ARGS_ERROR("blur",1);       if( !rgb )    Pike_error("This object is not initialized\n");    -  if (TYPEOF(sp[-args]) != T_INT) SIMPLE_BAD_ARG_ERROR("blur",0,"integer"); +  if (TYPEOF(sp[-args]) != T_INT) +  SIMPLE_ARG_TYPE_ERROR("blur", 0, "int");       t = sp[-args].u.integer; /* times */       for( cnt=0; cnt<t; cnt++ )    {    rgb_group *ro1=NULL, *ro2=NULL, *ro3=rgb;    for( y=0; y<ye; y++ )    {    ro1 = ro2;    ro2 = ro3;
pike.git/src/modules/Image/image.c:4777:         void image_tobitmap(INT32 args)   {    int xs;    int i,j,left,bit,dbits;    struct pike_string *res;    unsigned char *d;    rgb_group *s;    +  CHECK_INIT();    pop_n_elems(args); -  if (!THIS->img) -  Pike_error("Called Image.Image object is not initialized\n"); +        xs=(THIS->xsize+7)>>3;       res=begin_shared_string(xs*THIS->ysize);    d=(unsigned char *)res->str;       s=THIS->img;       j=THIS->ysize;    while (j--)
pike.git/src/modules/Image/image.c:4850:    Pike_error("Illegal image data\n");       if( THIS->img )    free( THIS->img );       THIS->xsize = w;    THIS->ysize = h;    THIS->img = xalloc( sizeof(rgb_group)*w*h+RGB_VEC_PAD );       memcpy( THIS->img, a->item[2].u.string->str, a->item[2].u.string->len ); -  pop_stack(); +    }    - static void image__size_object(INT32 args) + static void image__size_object(INT32 UNUSED(args))   {    INT_TYPE sz = 0;    if( THIS->img )    sz = THIS->xsize*THIS->ysize*sizeof(rgb_group)+RGB_VEC_PAD;    push_int(sz);   }      /***************** global init etc *****************************/      #define tRGB tOr3(tColor,tVoid,tInt) tOr(tInt,tVoid) tOr(tInt,tVoid)      void init_image_image(void)   {    int i;    for (i=0; i<CIRCLE_STEPS; i++) -  circle_sin_table[i]=DOUBLE_TO_INT(4096*sin(((double)i)*2.0* +  circle_sin_table[i]=(int)(4096*sin(((double)i)*2.0*    3.141592653589793/    (double)CIRCLE_STEPS));       ADD_STORAGE(struct image);       ADD_FUNCTION("_sprintf", image__sprintf, tFunc(tInt , tString), 0 );    ADD_FUNCTION("_size_object", image__size_object, tFunc(tVoid,tInt), 0);       ADD_FUNCTION("_encode", image__encode, tFunc(tVoid,tArray), 0 );    ADD_FUNCTION("_decode", image__decode, tFunc(tArray,tVoid), 0 );
pike.git/src/modules/Image/image.c:4895:    ADD_FUNCTION("clone",image_clone,    tOr3(tFunc(tInt tInt tInt tInt tRGB,tObj),    tFunc(tRGB,tObj),    tFunc(tNone,tObj)),0);    ADD_FUNCTION("new",image_clone, /* alias */    tFunc(tOr(tInt,tVoid) tOr(tInt,tVoid) tRGB,tObj),0);    ADD_FUNCTION("clear",image_clear,    tFunc(tRGB,tObj),0);       ADD_FUNCTION("cast",image_cast, -  tFunc(tStr,tStr),0); +  tFunc(tStr,tOr(tArray,tStr)),ID_PROTECTED);    ADD_FUNCTION("tobitmap",image_tobitmap,tFunc(tNone,tStr),0);          ADD_FUNCTION("copy",image_copy,    tFunc(tOr(tVoid,tInt) tOr(tVoid,tInt) tOr(tVoid,tInt)    tOr(tVoid,tInt) tRGB,tObj),0);    ADD_FUNCTION("autocrop",image_autocrop,    tFuncV(tNone,tOr(tVoid,tInt),tObj),0);    ADD_FUNCTION("find_autocrop",image_find_autocrop,    tFuncV(tNone,tOr(tVoid,tInt),tArr(tInt)),0);
pike.git/src/modules/Image/image.c:5141:       ADD_FUNCTION("apply_max",image_apply_max,    tFuncV(tArr(tArr(tOr(tInt,tArr(tInt)))),    tOr(tVoid,tInt),tObj),0);    ADD_FUNCTION("make_ascii",image_make_ascii,    tFunc(tObj tObj tObj tObj tOr(tInt,tVoid),tStr),0);       ADD_FUNCTION("test",image_test,    tFunc(tOr(tVoid,tInt),tObj),0);    + #ifdef PIKE_NULL_IS_SPECIAL    set_init_callback(init_image_struct); -  + #endif    set_exit_callback(exit_image_struct);         #ifndef FAKE_DYNAMIC_LOAD    /* Added by per: Export all functions needed by _Image_GIF */    PIKE_MODULE_EXPORT(Image, image_lay );    PIKE_MODULE_EXPORT(Image, image_colortable_write_rgb );    PIKE_MODULE_EXPORT(Image, image_colortable_size );    PIKE_MODULE_EXPORT(Image, image_colortable_index_8bit_image );    PIKE_MODULE_EXPORT(Image, image_colortable_internal_floyd_steinberg );