pike.git / lib / modules / Colors.pmod

version» Context lines:

pike.git/lib/modules/Colors.pmod:448:   COLOR(white,255,255,255);   COLOR(whitesmoke,245,245,245);   COLOR(yellow,255,255,0);   COLOR(yellow1,255,255,0);   COLOR(yellow2,238,238,0);   COLOR(yellow3,205,205,0);   COLOR(yellow4,139,139,0);   COLOR(yellowgreen,154,205,50);       - #ifdef ROXEN - mapping (string:string) html_32_colors = -  ([ "green":"#008000", "maroon":"#800000", "purple":"#800080" ]); - #endif -  -  +    array(int) rgb_to_hsv(array(int)|int ri, int|void gi, int|void bi)   {    if(arrayp(ri)) return Image.Color(@ri)->hsv();    return Image.Color(ri,gi,bi)->hsv();   }      array(int) hsv_to_rgb(array(int)|int hv, int|void sv, int|void vv)   {    if(arrayp(hv)) return Image.Color(sprintf("@%d,%d,%d", @hv))->rgb();    return Image.Color(sprintf("@%d,%d,%d", hv,sv,vv))->rgb();   }    -  + array(int) rgb_to_cmyk(array(int)|int ri, int|void gi, int|void bi) + { +  if(arrayp(ri)) return Image.Color(@ri)->cmyk(); +  return Image.Color(ri,gi,bi)->cmyk(); + } +  + array(int) cmyk_to_rgb(array(int)|int c, int|void m, int|void y, int|void k) + { +  if(arrayp(c)) return Image.Color(sprintf("%%%d,%d,%d,%d", @c))->rgb(); +  return Image.Color(sprintf("%%%d,%d,%d,%d", c,m,y,k))->rgb(); + } +    array(int) parse_color(string from)   {    object color;    if(!from || !strlen(from)) return ({ 0,0,0 }); // Odd color...    -  from = lower_case(from-" "); +  if(color=Image.Color.guess(from)) return color->rgb();    - #ifdef ROXEN -  if(html_32_colors[from]) from = html_32_colors[from]; - #endif +  from = replace(lower_case(from), "gray", "grey"); +  if(color=Image.Color.guess(from)) return color->rgb();    -  if(color=Image.Color(from)) return color->rgb(); -  -  from = replace(from, "gray", "grey"); -  if(color=Image.Color(from)) return color->rgb(); -  -  from = "#" + from; -  if(color=Image.Color(from)) return color->rgb(); -  +     // Lets call it black and be happy..... :-)    return ({ 0,0,0 });   }      // Mostly used for debug. Not really all that perfect..   string color_name(array (int) from)   {    if(!arrayp(from) || sizeof(from)!=3) return "-";    return Image.Color(@from)->name();   }