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

version» Context lines:

pike.git/src/modules/Image/colors.c:1:   /*   **! module Image   **! note - **! $Id: colors.c,v 1.32 2000/07/28 07:12:44 hubbe Exp $ + **! $Id: colors.c,v 1.33 2000/08/09 17:39:19 grubba Exp $   **! submodule Color   **!   **! This module keeps names and easy handling   **! for easy color support. It gives you an easy   **! way to get colors from names.   **!   **! A color is here an object, containing color   **! information and methods for conversion, see below.   **!   **! <ref>Image.Color</ref> can be called to make a color object.
pike.git/src/modules/Image/colors.c:172:   **! class Color   **! This is the color object. It has six readable variables,   **! <tt>r</tt>, <tt>g</tt>, <tt>b</tt>, for the <i>red</i>,   **! <i>green</i> and <i>blue</i> values,   **! and <tt>h</tt>, <tt>s</tt>, <tt>v</tt>, for   **! the <i>hue</i>, <i>saturation</i> anv <i>value</i> values.   */      #include "global.h"    - RCSID("$Id: colors.c,v 1.32 2000/07/28 07:12:44 hubbe Exp $"); + RCSID("$Id: colors.c,v 1.33 2000/08/09 17:39:19 grubba Exp $");      #include "image_machine.h"      #include <math.h>      #include "stralloc.h"   #include "pike_macros.h"   #include "object.h"   #include "constants.h"   #include "interpret.h"
pike.git/src/modules/Image/colors.c:448:    pop_n_elems(args);    if (r+g+b==0) r=g=b=1;    push_int((r*THIS->rgb.r+g*THIS->rgb.g+b*THIS->rgb.b)/(r+g+b));   }      #define MAX3(X,Y,Z) MAXIMUM(MAXIMUM(X,Y),Z)   #define MIN3(X,Y,Z) MINIMUM(MINIMUM(X,Y),Z)      static void image_color_hsvf(INT32 args)   { -  float max, min; -  float r,g,b, delta; -  float h, s, v; +  double max, min; +  double r,g,b, delta; +  double h, s, v;       pop_n_elems(args);       if((THIS->rgb.r==THIS->rgb.g) && (THIS->rgb.g==THIS->rgb.b))    {    push_float(0.0);    push_float(0.0);    push_float(COLORL_TO_FLOAT(THIS->rgbl.r));    f_aggregate(3);    return;
pike.git/src/modules/Image/colors.c:493:    if(h<0) h+=360;       push_float(h);    push_float(s);    push_float(v);    f_aggregate(3);   }      static void image_color_hsv(INT32 args)   { -  float h,s,v; +  double h,s,v;    image_color_hsvf(args);    h=sp[-1].u.array->item[0].u.float_number;    s=sp[-1].u.array->item[1].u.float_number;    v=sp[-1].u.array->item[2].u.float_number;       pop_stack();    push_int(FLOAT_TO_COLOR(h/360.0));    push_int(FLOAT_TO_COLOR(s));    push_int(FLOAT_TO_COLOR(v));    f_aggregate(3);   }      static void image_color_cmyk(INT32 args)   { -  float c,m,y,k; -  float r,g,b; +  double c,m,y,k; +  double r,g,b;    pop_n_elems(args);       r=COLORL_TO_FLOAT(THIS->rgbl.r);    g=COLORL_TO_FLOAT(THIS->rgbl.g);    b=COLORL_TO_FLOAT(THIS->rgbl.b);       k=1.0-MAX3(r,g,b);       c=1.0-r-k;    m=1.0-g-k;
pike.git/src/modules/Image/colors.c:1188:    }       if (sp[-1].type==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 */    -  unsigned long i=sp[-1].u.string->len-1,j,k,rgb[3]; +  size_t i = sp[-1].u.string->len-1, j, k, rgb[3];    unsigned char *src=(unsigned char *)sp[-1].u.string->str+1;    if (!(i%3))    {    i/=3;    for (j=0; j<3; j++)    {    unsigned INT32 z=0;    for (k=0; k<i; k++)    {    if (HEXTONUM(*src)==-1)
pike.git/src/modules/Image/colors.c:1283:    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>(INT32)strlen(callables[n]) &&    memcmp(sp[-1].u.string->str,callables[n],strlen(callables[n]))==0)    { -  push_int(strlen(callables[n])); +  push_int(DO_NOT_WARN(strlen(callables[n])));    push_int(1000000);    f_index(3);    image_get_color(1);    if (sp[-1].type!=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("grey%f\n");    f_sscanf(2);    if (sp[-1].type==T_ARRAY &&    sp[-1].u.array->size==1)    { -  float f; -  f=sp[-1].u.array->item[0].u.float_number; +  double f; /* FIXME: What is f used for? */ +  f = sp[-1].u.array->item[0].u.float_number;    pop_stack();    sp--;       return;    }    pop_stack();    }    }       /* try other stuff here */
pike.git/src/modules/Image/colors.c:1461:   {    INT32 r=0,g=0,b=0;       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 h,s,v; -  float r=0,g=0,b=0; /* to avoid warning */ +  double h,s,v; +  double r=0,g=0,b=0; /* to avoid warning */       if (args && sp[-args].type==T_INT)    {    INT32 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;    -  h = (hi/((float)COLORMAX))*(360.0/60.0); -  s = si/((float)COLORMAX); -  v = vi/((float)COLORMAX); +  h = (hi/((double)COLORMAX))*(360.0/60.0); +  s = si/((double)COLORMAX); +  v = vi/((double)COLORMAX);    }    else    {    get_all_args("Image.Color.hsv()",args,"%f%f%f",    &h,&s,&v);    pop_n_elems(args);    if (h<0) h=360+h-(((int)h/360)*360);    if (h>360.0) h-=(((int)h/360)*360);    h/=60;    }