Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Colors.cc
r940 r941 73 73 color c; 74 74 c.label=i->first; 75 if (i->second.size()==6) { 76 c.r= 16*to_decimal(i->second[0]) + to_decimal(i->second[1]); 77 c.g= 16*to_decimal(i->second[2]) + to_decimal(i->second[3]); 78 c.b= 16*to_decimal(i->second[4]) + to_decimal(i->second[5]); 79 } 80 else if (i->second.size()==3) { 81 c.r= 16*to_decimal(i->second[0]) + to_decimal(i->second[0]); 82 c.g= 16*to_decimal(i->second[1]) + to_decimal(i->second[1]); 83 c.b= 16*to_decimal(i->second[2]) + to_decimal(i->second[2]); 84 } 85 else 86 throw std::runtime_error("invalid color format: " + i->second); 75 str2rgb(i->second, c.r, c.g, c.b); 87 76 next_color_=color_map_.insert(next_color_,c); 88 77 author_map_.insert(std::make_pair(c.label, next_color_++)); … … 117 106 118 107 119 int Colors::to_decimal(int hex)108 int to_decimal(int hex) 120 109 { 121 110 hex=toupper(hex); … … 127 116 } 128 117 118 void str2rgb(const std::string& str, unsigned char& r, unsigned char& g, 119 unsigned char& b) 120 { 121 if (str.size()==6) { 122 r = 16*to_decimal(str[0]) + to_decimal(str[1]); 123 g = 16*to_decimal(str[2]) + to_decimal(str[3]); 124 b = 16*to_decimal(str[4]) + to_decimal(str[5]); 125 } 126 else if (str.size()==3) { 127 r = 17*to_decimal(str[0]); 128 g = 17*to_decimal(str[1]); 129 b = 17*to_decimal(str[2]); 130 } 131 else 132 throw std::runtime_error("invalid color format: " + str); 133 } 134 135 129 136 }} // end of namespace svndigest and namespace theplu -
trunk/lib/Colors.h
r929 r941 65 65 Colors(const Colors&); 66 66 67 // Convert char from hexadecimal to decimal, if char is out of68 // range -1 is returned.69 int to_decimal(int);70 71 67 // Assignment not implemented because assignment is always self-assignment 72 68 Colors& operator=(const Colors&); … … 86 82 }; 87 83 84 /** 85 Convert a string to color rgb values. The input str must be 86 either of length 3 or 6 and each character should be a 87 hexadecimal. 88 */ 89 void str2rgb(const std::string& str, unsigned char& r, unsigned char& g, 90 unsigned char& b); 91 92 // Convert char from hexadecimal to decimal, if char is out of 93 // range -1 is returned. 94 int to_decimal(int); 95 88 96 }} // end of namespace svndigest and namespace theplu 89 97
Note: See TracChangeset
for help on using the changeset viewer.