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.15 1999/04/25 20:34:51 grubba Exp $ + **! $Id: colors.c,v 1.16 1999/05/20 17:07:00 mirar 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:90:   **! 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"   #include <config.h>    - RCSID("$Id: colors.c,v 1.15 1999/04/25 20:34:51 grubba Exp $"); + RCSID("$Id: colors.c,v 1.16 1999/05/20 17:07:00 mirar Exp $");      #include "config.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:357:    else    {    get_all_args("Image.Color.Color->greylevel()",args,"%i%i%i",&r,&g,&b);    }    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;       pop_n_elems(args);       if((THIS->rgb.r==THIS->rgb.g) && (THIS->rgb.g==THIS->rgb.b))    { -  push_float(0); -  push_float(0); +  push_float(0.0); +  push_float(0.0);    push_float(COLORL_TO_FLOAT(THIS->rgbl.r));    f_aggregate(3);    return;    }       r = COLORL_TO_FLOAT(THIS->rgbl.r);    g = COLORL_TO_FLOAT(THIS->rgbl.g);    b = COLORL_TO_FLOAT(THIS->rgbl.b); -  +     max = MAX3(r,g,b); -  min = -(MAX3(-r,-g,-b)); +  min = MIN3(r,g,b);       v = max;       if(max != 0.0)    s = (max - min)/max;    else    error("internal error, max==0.0\n");       delta = max-min;   
pike.git/src/modules/Image/colors.c:790:   **! <td><illustration>return Image(20,20,@(array)Color.red)</illustration>   **! <illustration>return Image(20,20,@(array)Color.red->dull())</illustration>   **! <illustration>return Image(20,20,@(array)Color.red->dull()->dull())</illustration>   **! <illustration>return Image(20,20,@(array)Color.red->dull()->dull()->dull())</illustration></td></tr>   **!   **! <tr><td>neon </td><td>set to extreme </td><td>±0</td><td>max</td><td>max</td>   **! <td><illustration>return Image(20,20,@(array)Color["#693e3e"])</illustration>   **! <illustration>return Image(20,20,@(array)Color["#693e3e"]->neon())</illustration></td></tr>   **!   **! </table> + **! + **! <ref>light</ref> and <ref>dark</ref> lower/highers saturation + **! when value is min-/maximised respective. + **!   **! returns the new color object   **! note:   **! The opposites may not always take each other out.   **! The color is maximised at white and black levels,   **! so, for instance   **! <ref>Image.Color</ref>.white-><ref>light</ref>()-><ref>dark</ref>()   **! doesn't give the white color back, but the equal to   **! <ref>Image.Color</ref>.white-><ref>dark</ref>(), since   **! white can't get any <ref>light</ref>er.   */         static void image_color_light(INT32 args)   {    pop_n_elems(args);    image_color_hsvf(0);    sp--;    push_array_items(sp->u.array); /* frees */    sp[-1].u.float_number+=+0.2; -  +  if (sp[-1].u.float_number>=1.0) +  sp[-2].u.float_number-=sp[-1].u.float_number-1.0; +     image_make_hsv_color(3);   }      static void image_color_dark(INT32 args)   {    pop_n_elems(args);    image_color_hsvf(0);    sp--;    push_array_items(sp->u.array); /* frees */    sp[-1].u.float_number-=0.2; -  +  if (sp[-1].u.float_number<0.0) +  sp[-2].u.float_number-=sp[-1].u.float_number;    image_make_hsv_color(3);   }      static void image_color_neon(INT32 args)   {    pop_n_elems(args);    image_color_hsvf(0);    sp--;    push_array_items(sp->u.array); /* frees */   
pike.git/src/modules/Image/colors.c:861:    push_array_items(sp->u.array); /* frees */       if (sp[-1].u.float_number==0.0)    {    pop_n_elems(3);    ref_push_object(THISOBJ);    return;    }       sp[-2].u.float_number-=0.2; +  sp[-1].u.float_number-=0.2;    image_make_hsv_color(3);   }      static void image_color_bright(INT32 args)   {    pop_n_elems(args);    image_color_hsvf(0);    sp--;    push_array_items(sp->u.array); /* frees */       if (sp[-1].u.float_number==0.0)    {    pop_n_elems(3);    ref_push_object(THISOBJ);    return;    }       sp[-2].u.float_number+=0.2; -  +  sp[-1].u.float_number+=0.2;    image_make_hsv_color(3);   }         static void image_color_mult(INT32 args)   {    float x=0.0;    get_all_args("Image.Color.Color->`*",args,"%f",&x);    pop_n_elems(args);    _image_make_rgb_color((int)(THIS->rgb.r*x),
pike.git/src/modules/Image/colors.c:1302:   #define t (v * (1 - (s * (1 -f))))    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: error("internal error\n"); +  default: error("internal error (hue=%d <= hsv[%f,%f,%f])\n",(int)i,h,s,v);    }    }   #undef i   #undef f   #undef p   #undef q   #undef t       _image_make_rgbf_color(r,g,b);   }