/* Takes a color name in ascii, returns the color number for that color. * returns 0 if color is not known. */ #include "display.h" #include "colors.h" #include "color.h" int D_translate_color(char *str ) { if (! strcmp(str, "red")) return(RED) ; if (! strcmp(str, "orange")) return(ORANGE) ; if (! strcmp(str, "yellow")) return(YELLOW) ; if (! strcmp(str, "green")) return(GREEN) ; if (! strcmp(str, "blue")) return(BLUE) ; if (! strcmp(str, "cyan")) return(BLUE) ; if (! strcmp(str, "indigo")) return(INDIGO) ; if (! strcmp(str, "violet")) return(VIOLET) ; if (! strcmp(str, "purple")) return(VIOLET) ; if (! strcmp(str, "white")) return(WHITE) ; if (! strcmp(str, "black")) return(BLACK) ; if (! strcmp(str, "gray")) return(GRAY) ; if (! strcmp(str, "grey")) return(GRAY) ; if (! strcmp(str, "brown")) return(BROWN) ; if (! strcmp(str, "magenta")) return(MAGENTA) ; if (! strcmp(str, "aqua")) return(AQUA) ; if (! strcmp(str, "gray")) return(GRAY) ; return(0) ; } /* Take a string in format R|G|B or (R,G,B) or somestringRsomestringGsomestringBsomestring or red or magenta or indigo..., * and returns the colors numbers in format RGB as short. R=0-255,G=0-255,B=0-255. *Fernando Pacheco * fpacheco@dinama.gub.uy */ RGB D_translate_color_to_RGB(char *str ) { int ltotal,cont1,esdigito,color; char buf[56]; char buftemp[]="..................."; char one_char[2]; //typedef RGB is defined in color.h //D_translate_color_to_RGB is declared in color.h RGB RGB_ret; //initialize RGB_ret.r=0; RGB_ret.g=0; RGB_ret.b=0; if (! strcmp(str, "red")) { RGB_ret.r=255; RGB_ret.g=0; RGB_ret.b=0; return(RGB_ret) ; } if (! strcmp(str, "orange")) { RGB_ret.r=255; RGB_ret.g=128; RGB_ret.b=0; return(RGB_ret) ; } if (! strcmp(str, "yellow")) { RGB_ret.r=255; RGB_ret.g=255; RGB_ret.b=0; return(RGB_ret) ; } if (! strcmp(str, "green")) { RGB_ret.r=0; RGB_ret.g=255; RGB_ret.b=0; return(RGB_ret) ; } if (! strcmp(str, "blue")) { RGB_ret.r=0; RGB_ret.g=0; RGB_ret.b=255; return(RGB_ret) ; } if (! strcmp(str, "cyan")) { RGB_ret.r=0; RGB_ret.g=255; RGB_ret.b=255; return(RGB_ret) ; } if (! strcmp(str, "indigo")) { RGB_ret.r=0; RGB_ret.g=128; RGB_ret.b=255; return(RGB_ret) ; } if (! strcmp(str, "violet")) { RGB_ret.r=238; RGB_ret.g=130; RGB_ret.b=238; return(RGB_ret) ; } if (! strcmp(str, "purple")) { RGB_ret.r=255; RGB_ret.g=0; RGB_ret.b=255; return(RGB_ret) ; } if (! strcmp(str, "white")) { RGB_ret.r=255; RGB_ret.g=255; RGB_ret.b=255; return(RGB_ret) ; } if (! strcmp(str, "black")) { RGB_ret.r=0; RGB_ret.g=0; RGB_ret.b=0; return(RGB_ret) ; } if (! strcmp(str, "gray")) { RGB_ret.r=175; RGB_ret.g=175; RGB_ret.b=175; return(RGB_ret) ; } if (! strcmp(str, "grey")) { RGB_ret.r=190; RGB_ret.g=190; RGB_ret.b=190; return(RGB_ret) ; } if (! strcmp(str, "brown")) { RGB_ret.r=180; RGB_ret.g=77; RGB_ret.b=25; return(RGB_ret) ; } if (! strcmp(str, "magenta")) { RGB_ret.r=255; RGB_ret.g=0; RGB_ret.b=128; return(RGB_ret) ; } if (! strcmp(str, "aqua")) { RGB_ret.r=100; RGB_ret.g=128; RGB_ret.b=255; return(RGB_ret) ; } if (! strcmp(str, "gray")) { RGB_ret.r=190; RGB_ret.g=190; RGB_ret.b=190; return(RGB_ret) ; } //not a named color then... ltotal=strlen(str); strcpy(buf,str); esdigito=0; color=0; for (cont1=0;cont10) { color=color+1; switch (color) { case 1: RGB_ret.r=atoi(buftemp); if (RGB_ret.r>255) RGB_ret.r=255; break; case 2: RGB_ret.g=atoi(buftemp); if (RGB_ret.g>255) RGB_ret.g=255; break; case 3: RGB_ret.b=atoi(buftemp); if (RGB_ret.b>255) RGB_ret.b=255; break; } strcpy(buftemp,"..................."); esdigito=0; } } } return(RGB_ret) ; }