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

version» Context lines:

pike.git/src/modules/Image/colors.c:752:   **! cast the object to an array, representing red, green   **! and blue (equal to <tt>-><ref>rgb</ref>()</tt>), or   **! to a string, giving the name (equal to <tt>-><ref>name</ref>()</tt>).   **! returns the name as string or rgb as array   **! see also: rgb, name   */      static void image_color_cast(INT32 args)   {    if (args!=1 || -  sp[-1].type!=T_STRING) +  TYPEOF(sp[-1]) != T_STRING)    bad_arg_error("Image.Color.Color->cast",sp-args,args,0,"",sp-args,    "Bad arguments to Image.Color.Color->cast()\n");       if (sp[-1].u.string==str_array)    {    image_color_rgb(args);    return;    }    if (sp[-1].u.string==str_string)    {
pike.git/src/modules/Image/colors.c:782:    Pike_error("Image.Color.Color->cast(): Can't cast to that\n");   }      static void image_color__sprintf(INT32 args)   {    int prec,x;       if (args<2)    SIMPLE_TOO_FEW_ARGS_ERROR("_sprintf",2);    -  if (sp[-args].type!=T_INT) +  if (TYPEOF(sp[-args]) != T_INT)    SIMPLE_BAD_ARG_ERROR("_sprintf",0,"integer"); -  if (sp[1-args].type!=T_MAPPING) +  if (TYPEOF(sp[1-args]) != T_MAPPING)    SIMPLE_BAD_ARG_ERROR("_sprintf",1,"mapping");       pop_n_elems(args-2);       push_text("precision");    f_index(2); -  if (sp[-1].type!=T_INT) +  if (TYPEOF(sp[-1]) != T_INT)    SIMPLE_BAD_ARG_ERROR("_sprintf",1,"mapping(\"precision\":int)");    prec=sp[-1].u.integer;    x=sp[-2].u.integer;    pop_n_elems(2);       switch (x)    {   /* case 'c': */   /* case 'd': */    case 't':
pike.git/src/modules/Image/colors.c:864:   }      static void image_color_index(INT32 args)   {    struct svalue s;       if (args!=1)    Pike_error("Image.Color[]: illegal number of arguments\n");       object_index_no_free2(&s, THISOBJ, 0, sp-1); -  if (s.type==T_INT && sp[-1].type==T_STRING) +  if (TYPEOF(s) == T_INT && TYPEOF(sp[-1]) == T_STRING)    {    if (sp[-1].u.string==str_r)    {    pop_stack();    push_int(THIS->rgb.r);    return;    }    if (sp[-1].u.string==str_g)    {    pop_stack();
pike.git/src/modules/Image/colors.c:943:   **! see also: rgb, grey, name   **! note:   **! The other datatype (not color object) must be to the right!   */      static void image_color_equal(INT32 args)   {    if (args!=1)    Pike_error("Image.Color.Color->`==: illegal number of arguments\n");    -  if (sp[-1].type==T_OBJECT) +  if (TYPEOF(sp[-1]) == T_OBJECT)    {    struct color_struct *other;    other=(struct color_struct*)    get_storage(sp[-1].u.object,image_color_program);    if (other&&    other->rgbl.r==THIS->rgbl.r &&    other->rgbl.g==THIS->rgbl.g &&    other->rgbl.b==THIS->rgbl.b)    {    pop_stack();    push_int(1);    return;    }    } -  else if (sp[-1].type==T_ARRAY) +  else if (TYPEOF(sp[-1]) == T_ARRAY)    {    if (sp[-1].u.array->size==3 && -  sp[-1].u.array->item[0].type==T_INT && -  sp[-1].u.array->item[1].type==T_INT && -  sp[-1].u.array->item[2].type==T_INT && +  TYPEOF(sp[-1].u.array->item[0]) == T_INT && +  TYPEOF(sp[-1].u.array->item[1]) == T_INT && +  TYPEOF(sp[-1].u.array->item[2]) == T_INT &&    sp[-1].u.array->item[0].u.integer == THIS->rgb.r &&    sp[-1].u.array->item[1].u.integer == THIS->rgb.g &&    sp[-1].u.array->item[2].u.integer == THIS->rgb.b)    {    pop_stack();    push_int(1);    return;    }    } - /* else if (sp[-1].type==T_INT) */ + /* else if (TYPEOF(sp[-1]) == T_INT) */   /* { */   /* if (sp[-1].u.integer == THIS->rgb.r && */   /* THIS->rgb.r==THIS->rgb.g && */   /* THIS->rgb.r==THIS->rgb.b) */   /* { */   /* pop_stack(); */   /* push_int(1); */   /* return; */   /* } */   /* } */ -  else if (sp[-1].type==T_STRING) +  else if (TYPEOF(sp[-1]) == T_STRING)    {    if (!THIS->name)    try_find_name(THIS);    if (sp[-1].u.string==THIS->name && THIS->name!=no_name)    {    pop_stack();    push_int(1);    return;    }    }
pike.git/src/modules/Image/colors.c:1169:    FLOAT_TYPE x=0.0;    get_all_args("Image.Color.Color->`*",args,"%f",&x);    pop_n_elems(args);    _image_make_rgb_color(DOUBLE_TO_INT(THIS->rgb.r*x),    DOUBLE_TO_INT(THIS->rgb.g*x),    DOUBLE_TO_INT(THIS->rgb.b*x));   }      int image_color_svalue(struct svalue *v,rgb_group *rgb)   { -  if (v->type==T_OBJECT) +  if (TYPEOF(*v) == T_OBJECT)    {    struct color_struct *cs=(struct color_struct*)    get_storage(v->u.object,image_color_program);       if (cs)    {    *rgb=cs->rgb;    return 1;    }    } -  else if (v->type==T_ARRAY) +  else if (TYPEOF(*v) == T_ARRAY)    {    if (v->u.array->size==3 && -  v->u.array->item[0].type==T_INT && -  v->u.array->item[1].type==T_INT && -  v->u.array->item[2].type==T_INT) +  TYPEOF(v->u.array->item[0]) == T_INT && +  TYPEOF(v->u.array->item[1]) == T_INT && +  TYPEOF(v->u.array->item[2]) == T_INT)    {    rgb->r=(COLORTYPE)(v->u.array->item[0].u.integer);    rgb->g=(COLORTYPE)(v->u.array->item[1].u.integer);    rgb->b=(COLORTYPE)(v->u.array->item[2].u.integer);    return 1;    }    } -  else if (v->type==T_STRING) +  else if (TYPEOF(*v) == T_STRING)    {    push_svalue(v);    image_make_color(1); -  if (sp[-1].type==T_OBJECT) +  if (TYPEOF(sp[-1]) == T_OBJECT)    {    struct color_struct *cs=(struct color_struct*)    get_storage(sp[-1].u.object,image_color_program);    *rgb=cs->rgb;    pop_stack();    return 1;    }    pop_stack();    }    return 0;
pike.git/src/modules/Image/colors.c:1249:    struct svalue s;    int n;    static const char *callables[]={"light","dark","neon","dull","bright"};       if (args!=1)    Pike_error("Image.Color[]: illegal number of args.\n");       if (!colors)    make_colors();    -  if (sp[-1].type==T_STRING) +  if (TYPEOF(sp[-1]) == T_STRING)    {    mapping_index_no_free(&s,colors,sp-1); -  if (s.type==T_OBJECT) +  if (TYPEOF(s) == T_OBJECT)    {    pop_stack();    *(sp++)=s;    return;    }    else    free_svalue(&s);    }    -  if (sp[-1].type==T_STRING && +  if (TYPEOF(sp[-1]) == T_STRING &&    sp[-1].u.string->size_shift==0)    {    if (sp[-1].u.string->len>=4 &&    sp[-1].u.string->str[0]=='#')    {    /* #rgb, #rrggbb, #rrrgggbbb, etc */       size_t i = sp[-1].u.string->len-1, j, k;    unsigned INT32 rgb[3];    unsigned char *src=(unsigned char *)sp[-1].u.string->str+1;
pike.git/src/modules/Image/colors.c:1322:    return;    }    }    if (sp[-1].u.string->len>=4 &&    sp[-1].u.string->str[0]=='@')    {    /* @h,s,v; h=0..359, s,v=0..100 */    stack_dup();    push_text("@%f,%f,%f\n");    f_sscanf(2); -  if (sp[-1].type==T_ARRAY && +  if (TYPEOF(sp[-1]) == T_ARRAY &&    sp[-1].u.array->size==3)    {    FLOAT_TYPE h,s,v;    stack_swap();    pop_stack();    sp--;    dmalloc_touch_svalue(sp);    push_array_items(sp->u.array);    get_all_args("Image.Color()",3,"%f%f%f",&h,&s,&v);    pop_n_elems(3);
pike.git/src/modules/Image/colors.c:1348:    }    pop_stack();    }    if (sp[-1].u.string->len>=4 &&    sp[-1].u.string->str[0]=='%')    {    /* @c,m,y,k; 0..100 */    stack_dup();    push_text("%%%f,%f,%f,%f\n");    f_sscanf(2); -  if (sp[-1].type==T_ARRAY && +  if (TYPEOF(sp[-1]) == T_ARRAY &&    sp[-1].u.array->size==4)    {    stack_swap();    pop_stack();    sp--;    dmalloc_touch_svalue(sp);    push_array_items(sp->u.array);    image_make_cmyk_color(4);    return;    }    pop_stack();    }    for (n=0; (size_t)n<sizeof(callables)/sizeof(callables[0]); n++)    if (sp[-1].u.string->len>(ptrdiff_t)strlen(callables[n]) &&    memcmp(sp[-1].u.string->str,callables[n],strlen(callables[n]))==0)    {    push_int(DO_NOT_WARN((INT32)strlen(callables[n])));    push_int(1000000);    f_index(3);    image_get_color(1); -  if (sp[-1].type!=T_OBJECT) return; /* no way */ +  if (TYPEOF(sp[-1]) != T_OBJECT) return; /* no way */    safe_apply(sp[-1].u.object,callables[n],0);    stack_swap();    pop_stack();    return;    }    if (sp[-1].u.string->len>=4 &&    sp[-1].u.string->str[0]=='g')    {    /* greyx; x=0..99 */    stack_dup();    push_text("gr%*[ea]y%f\n");    f_sscanf(2); -  if (sp[-1].type==T_ARRAY && +  if (TYPEOF(sp[-1]) == T_ARRAY &&    sp[-1].u.array->size==1)    {    double f;    f = sp[-1].u.array->item[0].u.float_number;    pop_stack();    pop_stack();    push_int( DO_NOT_WARN((int)(255*f/100)) );    /* grey100 is white, grey0 is black */    stack_dup();    stack_dup();
pike.git/src/modules/Image/colors.c:1410:       /* try other stuff here */       pop_stack();    push_undefined();    return;   }      static void image_guess_color(INT32 args)   { -  if (args!=1 && sp[-args].type!=T_STRING) +  if (args!=1 && TYPEOF(sp[-args]) != T_STRING)    bad_arg_error("Image.Color->guess",sp-args,args,0,"",sp-args,    "Bad arguments to Image.Color->guess()\n");       f_lower_case(1);    push_constant_text(" ");    o_subtract();       stack_dup();    image_get_color(1); -  if (sp[-1].type==T_OBJECT) +  if (TYPEOF(sp[-1]) == T_OBJECT)    {    stack_swap();    pop_stack();    return;    }    pop_stack();    push_constant_text("#");    stack_swap();    f_add(2);       image_get_color(1);   }      static void image_colors_index(INT32 args)   {    struct svalue s;    object_index_no_free2(&s, THISOBJ, 0, sp-1); -  if (s.type!=T_INT) +  if (TYPEOF(s) != T_INT)    {    pop_stack();    *(sp++)=s;    return;    }    image_get_color(args);   }      static void image_make_color(INT32 args)   { -  if (args==1 && sp[-args].type==T_STRING) +  if (args==1 && TYPEOF(sp[-args]) == T_STRING)    {    image_get_color(args);    return;    }    image_make_rgb_color(args);   }         /*   **! module Image
pike.git/src/modules/Image/colors.c:1517:   {    push_int( THIS->rgbl.r );    push_int( THIS->rgbl.g );    push_int( THIS->rgbl.b );    f_aggregate( 3 );   }      static void image_color__decode( INT32 args )   {    struct svalue *a; -  if( Pike_sp[-1].type != PIKE_T_ARRAY || Pike_sp[-1].u.array->size != 3 ) +  if( TYPEOF(Pike_sp[-1]) != PIKE_T_ARRAY || Pike_sp[-1].u.array->size != 3 )    Pike_error("Illegal argument to _decode\n");    a=Pike_sp[-1].u.array->item;    THIS->rgbl.r = a[0].u.integer;    THIS->rgbl.g = a[1].u.integer;    THIS->rgbl.b = a[2].u.integer;    RGBL_TO_RGB(THIS->rgb,THIS->rgbl);    pop_stack();   }      static void _image_make_rgbf_color(double r, double g, double b)
pike.git/src/modules/Image/colors.c:1557:    cs->rgb.r=(COLORTYPE)r;    cs->rgb.g=(COLORTYPE)g;    cs->rgb.b=(COLORTYPE)b;    RGB_TO_RGBL(cs->rgbl,cs->rgb);   }      static void image_make_rgb_color(INT32 args)   {    INT_TYPE r=0,g=0,b=0;    -  if( args==1 && sp[-1].type==T_INT ) +  if( args==1 && TYPEOF(sp[-1]) == T_INT )    {    r = sp[-1].u.integer;    b = r & 0xff;    r >>= 8;    g = r & 0xff;    r >>= 8;    r &= 0xff;    }    else    get_all_args("Image.Color.rgb()",args,"%i%i%i",&r,&g,&b);       _image_make_rgb_color(r,g,b);   }      static void image_make_hsv_color(INT32 args)   {    FLOAT_TYPE h,s,v;    FLOAT_TYPE r=0,g=0,b=0; /* to avoid warning */    -  if (args && sp[-args].type==T_INT) +  if (args && TYPEOF(sp[-args]) == T_INT)    {    INT_TYPE hi,si,vi;    get_all_args("Image.Color.hsv()",args,"%i%i%i",    &hi,&si,&vi);    pop_n_elems(args);       if (hi<0) hi=(hi%COLORMAX)+COLORMAX;    else if (hi>COLORMAX) hi%=COLORMAX; /* repeating */    if (si<0) si=0; else if (si>COLORMAX) si=COLORMAX;    if (vi<0) vi=0; else if (vi>COLORMAX) vi=COLORMAX;
pike.git/src/modules/Image/colors.c:1663:    pop_n_elems(args);       _image_make_rgb_color(i,i,i);   }      static void image_make_html_color(INT32 args)   {    int i;       if (args!=1 || -  sp[-1].type!=T_STRING) +  TYPEOF(sp[-1]) != T_STRING)    {    bad_arg_error("Image.Color.html",sp-args,args,0,"",sp-args,    "Bad arguments to Image.Color.html()\n");    return;    }       f_lower_case(1);    for (i=0; (size_t)i<sizeof(html_color)/sizeof(html_color[0]); i++)    if (html_color[i].pname==sp[-1].u.string)    {