pike.git / lib / modules / Colors.pmod

version» Context lines:

pike.git/lib/modules/Colors.pmod:59:   }      //! @decl array(int(0..255)) cmyk_to_rgb(array(int(0..100)) cmyk)   //! @decl array(int(0..255)) cmyk_to_rgb(int(0..100) c, int(0..100) m, int(0..100) y, int(0..100) k)   //!   //! This function return the RGB value of the color   //! describe by the provided CMYK value. It is essentially   //! calling Image.Color.cmyk(c,m,y,k)->rgb()   //!   //! @seealso - //! @[Colors.rgb_ro_cmyk()] + //! @[Colors.rgb_to_cmyk()]   //! @[Image.Color.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.cmyk(@c)->rgb();    return Image.Color.cmyk(c,m,y,k)->rgb();   }      //! This function returns the RGB values that corresponds to the   //! color that is provided by name to the function. It is   //! essentially calling @[Image.Color.guess()], but returns the - //! value for black if it failes. + //! default value (or black if none is provided) if it failes.   //! - array(int(0..255)) parse_color(string name) + array(int(0..255)) parse_color(string name, void|array(int) def)   {    Image.Color.Color color; -  if(!name || !strlen(name)) return ({ 0,0,0 }); // Odd color... +  if(!name || !sizeof(name)) return def||({ 0,0,0 }); // Odd color...       if(color=Image.Color.guess(name)) return color->rgb();       name = replace(lower_case(name), "gray", "grey");    if(color=Image.Color.guess(name)) return color->rgb();       // Lets call it black and be happy..... :-) -  return ({ 0,0,0 }); +  return def||({ 0,0,0 });   }      //! Tries to find a name to color described by the provided RGB   //! values. Partially an inverse function to @[Colors.parse_color()],   //! although it can not find all the names that @[Colors.parse_color()] - //! can find RGB values for. Returns "-" upon failure. + //! can find RGB values for. Returns the colors rgb hex value prepended + //! with "#" upon failure.   //!   string color_name(array(int(0..255)) rgb)   {    if(!arrayp(rgb) || sizeof(rgb)!=3) return "-";    string name = Image.Color(@rgb)->name(); -  if(name[0]=='#') return "-"; +     return name;   }