?? colorlookup.cpp
字號:
// ==========================================================
// X11 and SVG Color name lookup
//
// Design and implementation by
// - Karl-Heinz Bussian (khbussian@moss.de)
//
// This file is part of FreeImage 3
//
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
// THIS DISCLAIMER.
//
// Use at your own risk!
// ==========================================================
#include "FreeImage.h"
#include "Utilities.h"
// RGB color names ---------------------------------------------------------
typedef struct tagNamedColor {
char *name; // color name
BYTE r; // red value
BYTE g; // green value
BYTE b; // blue value
} NamedColor;
// --------------------------------------------------------------------------
/**
Helper function : perform a binary search on a color array
@param name Color name
@param color_array Color array
@param n Length of the color array
@return Returns the color index in the array if successful, returns -1 otherwise
*/
static int
binsearch(const char *name, const NamedColor *color_array, int n) {
int cond, low, mid, high;
low = 0;
high = n - 1;
while (low <= high) {
mid = (low + high) / 2;
if ((cond = strcmp(name, color_array[mid].name)) < 0)
high = mid - 1;
else if (cond > 0)
low = mid + 1;
else
return mid;
}
return -1;
}
/**
Perform a binary search on a color array
@param szColor Color name
@param color_array Color array
@param ncolors Length of the color array
@return Returns the color index in the array if successful, returns -1 otherwise
*/
static int
FreeImage_LookupNamedColor(const char *szColor, const NamedColor *color_array, int ncolors) {
int i;
char color[64];
// make lower case name, squezze white space
for (i = 0; szColor[i] && i < sizeof(color) - 1; i++) {
if (isspace(szColor[i]))
continue;
if (isupper(szColor[i]))
color[i] = tolower(szColor[i]);
else
color[i] = szColor[i];
}
color[i] = 0;
return (binsearch(color, color_array, ncolors));
}
// ==========================================================
// X11 Color name lookup
/**
This big list of color names was formed from the file: /usr/X11R6/lib/X11/rgb.txt
found on a standard Linux installation.
*/
static NamedColor X11ColorMap[] = {
{ "aliceblue", 240, 248, 255 },
{ "antiquewhite", 250, 235, 215 },
{ "antiquewhite1", 255, 239, 219 },
{ "antiquewhite2", 238, 223, 204 },
{ "antiquewhite3", 205, 192, 176 },
{ "antiquewhite4", 139, 131, 120 },
{ "aquamarine", 127, 255, 212 },
{ "aquamarine1", 127, 255, 212 },
{ "aquamarine2", 118, 238, 198 },
{ "aquamarine3", 102, 205, 170 },
{ "aquamarine4", 69, 139, 116 },
{ "azure", 240, 255, 255 },
{ "azure1", 240, 255, 255 },
{ "azure2", 224, 238, 238 },
{ "azure3", 193, 205, 205 },
{ "azure4", 131, 139, 139 },
{ "beige", 245, 245, 220 },
{ "bisque", 255, 228, 196 },
{ "bisque1", 255, 228, 196 },
{ "bisque2", 238, 213, 183 },
{ "bisque3", 205, 183, 158 },
{ "bisque4", 139, 125, 107 },
{ "black", 0, 0, 0 },
{ "blanchedalmond", 255, 235, 205 },
{ "blue", 0, 0, 255 },
{ "blue1", 0, 0, 255 },
{ "blue2", 0, 0, 238 },
{ "blue3", 0, 0, 205 },
{ "blue4", 0, 0, 139 },
{ "blueviolet", 138, 43, 226 },
{ "brown", 165, 42, 42 },
{ "brown1", 255, 64, 64 },
{ "brown2", 238, 59, 59 },
{ "brown3", 205, 51, 51 },
{ "brown4", 139, 35, 35 },
{ "burlywood", 222, 184, 135 },
{ "burlywood1", 255, 211, 155 },
{ "burlywood2", 238, 197, 145 },
{ "burlywood3", 205, 170, 125 },
{ "burlywood4", 139, 115, 85 },
{ "cadetblue", 95, 158, 160 },
{ "cadetblue1", 152, 245, 255 },
{ "cadetblue2", 142, 229, 238 },
{ "cadetblue3", 122, 197, 205 },
{ "cadetblue4", 83, 134, 139 },
{ "chartreuse", 127, 255, 0 },
{ "chartreuse1", 127, 255, 0 },
{ "chartreuse2", 118, 238, 0 },
{ "chartreuse3", 102, 205, 0 },
{ "chartreuse4", 69, 139, 0 },
{ "chocolate", 210, 105, 30 },
{ "chocolate1", 255, 127, 36 },
{ "chocolate2", 238, 118, 33 },
{ "chocolate3", 205, 102, 29 },
{ "chocolate4", 139, 69, 19 },
{ "coral", 255, 127, 80 },
{ "coral1", 255, 114, 86 },
{ "coral2", 238, 106, 80 },
{ "coral3", 205, 91, 69 },
{ "coral4", 139, 62, 47 },
{ "cornflowerblue", 100, 149, 237 },
{ "cornsilk", 255, 248, 220 },
{ "cornsilk1", 255, 248, 220 },
{ "cornsilk2", 238, 232, 205 },
{ "cornsilk3", 205, 200, 177 },
{ "cornsilk4", 139, 136, 120 },
{ "cyan", 0, 255, 255 },
{ "cyan1", 0, 255, 255 },
{ "cyan2", 0, 238, 238 },
{ "cyan3", 0, 205, 205 },
{ "cyan4", 0, 139, 139 },
{ "darkblue", 0, 0, 139 },
{ "darkcyan", 0, 139, 139 },
{ "darkgoldenrod", 184, 134, 11 },
{ "darkgoldenrod1", 255, 185, 15 },
{ "darkgoldenrod2", 238, 173, 14 },
{ "darkgoldenrod3", 205, 149, 12 },
{ "darkgoldenrod4", 139, 101, 8 },
{ "darkgreen", 0, 100, 0 },
{ "darkkhaki", 189, 183, 107 },
{ "darkmagenta", 139, 0, 139 },
{ "darkolivegreen", 85, 107, 47 },
{ "darkolivegreen1", 202, 255, 112 },
{ "darkolivegreen2", 188, 238, 104 },
{ "darkolivegreen3", 162, 205, 90 },
{ "darkolivegreen4", 110, 139, 61 },
{ "darkorange", 255, 140, 0 },
{ "darkorange1", 255, 127, 0 },
{ "darkorange2", 238, 118, 0 },
{ "darkorange3", 205, 102, 0 },
{ "darkorange4", 139, 69, 0 },
{ "darkorchid", 153, 50, 204 },
{ "darkorchid1", 191, 62, 255 },
{ "darkorchid2", 178, 58, 238 },
{ "darkorchid3", 154, 50, 205 },
{ "darkorchid4", 104, 34, 139 },
{ "darkred", 139, 0, 0 },
{ "darksalmon", 233, 150, 122 },
{ "darkseagreen", 143, 188, 143 },
{ "darkseagreen1", 193, 255, 193 },
{ "darkseagreen2", 180, 238, 180 },
{ "darkseagreen3", 155, 205, 155 },
{ "darkseagreen4", 105, 139, 105 },
{ "darkslateblue", 72, 61, 139 },
{ "darkslategray", 47, 79, 79 },
{ "darkslategray1", 151, 255, 255 },
{ "darkslategray2", 141, 238, 238 },
{ "darkslategray3", 121, 205, 205 },
{ "darkslategray4", 82, 139, 139 },
{ "darkslategrey", 47, 79, 79 },
{ "darkturquoise", 0, 206, 209 },
{ "darkviolet", 148, 0, 211 },
{ "deeppink", 255, 20, 147 },
{ "deeppink1", 255, 20, 147 },
{ "deeppink2", 238, 18, 137 },
{ "deeppink3", 205, 16, 118 },
{ "deeppink4", 139, 10, 80 },
{ "deepskyblue", 0, 191, 255 },
{ "deepskyblue1", 0, 191, 255 },
{ "deepskyblue2", 0, 178, 238 },
{ "deepskyblue3", 0, 154, 205 },
{ "deepskyblue4", 0, 104, 139 },
{ "dimgray", 105, 105, 105 },
{ "dimgrey", 105, 105, 105 },
{ "dodgerblue", 30, 144, 255 },
{ "dodgerblue1", 30, 144, 255 },
{ "dodgerblue2", 28, 134, 238 },
{ "dodgerblue3", 24, 116, 205 },
{ "dodgerblue4", 16, 78, 139 },
{ "firebrick", 178, 34, 34 },
{ "firebrick1", 255, 48, 48 },
{ "firebrick2", 238, 44, 44 },
{ "firebrick3", 205, 38, 38 },
{ "firebrick4", 139, 26, 26 },
{ "floralwhite", 255, 250, 240 },
{ "forestgreen", 176, 48, 96 },
{ "gainsboro", 220, 220, 220 },
{ "ghostwhite", 248, 248, 255 },
{ "gold", 255, 215, 0 },
{ "gold1", 255, 215, 0 },
{ "gold2", 238, 201, 0 },
{ "gold3", 205, 173, 0 },
{ "gold4", 139, 117, 0 },
{ "goldenrod", 218, 165, 32 },
{ "goldenrod1", 255, 193, 37 },
{ "goldenrod2", 238, 180, 34 },
{ "goldenrod3", 205, 155, 29 },
{ "goldenrod4", 139, 105, 20 },
{ "gray", 190, 190, 190 },
{ "green", 0, 255, 0 },
{ "green1", 0, 255, 0 },
{ "green2", 0, 238, 0 },
{ "green3", 0, 205, 0 },
{ "green4", 0, 139, 0 },
{ "greenyellow", 173, 255, 47 },
{ "grey", 190, 190, 190 },
{ "honeydew", 240, 255, 240 },
{ "honeydew1", 240, 255, 240 },
{ "honeydew2", 224, 238, 224 },
{ "honeydew3", 193, 205, 193 },
{ "honeydew4", 131, 139, 131 },
{ "hotpink", 255, 105, 180 },
{ "hotpink1", 255, 110, 180 },
{ "hotpink2", 238, 106, 167 },
{ "hotpink3", 205, 96, 144 },
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -