MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / fromHexString

Method fromHexString

src/Base/Color.cpp:141–185  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139}
140
141bool Color::fromHexString(const std::string& hex)
142{
143 if (hex.size() < 7 || hex[0] != '#') {
144 return false;
145 }
146
147 // #RRGGBB
148 if (hex.size() == 7) {
149 std::stringstream ss(hex);
150 unsigned int rgb;
151 char ch {};
152
153 ss >> ch >> std::hex >> rgb;
154 int rc = (rgb >> 16) & 0xff;
155 int gc = (rgb >> 8) & 0xff;
156 int bc = rgb & 0xff;
157
158 r = rc / 255.0F;
159 g = gc / 255.0F;
160 b = bc / 255.0F;
161
162 return true;
163 }
164 // #RRGGBBAA
165 if (hex.size() == 9) {
166 std::stringstream ss(hex);
167 unsigned int rgba;
168 char ch {};
169
170 ss >> ch >> std::hex >> rgba;
171 int rc = (rgba >> 24) & 0xff;
172 int gc = (rgba >> 16) & 0xff;
173 int bc = (rgba >> 8) & 0xff;
174 int ac = rgba & 0xff;
175
176 r = rc / 255.0F;
177 g = gc / 255.0F;
178 b = bc / 255.0F;
179 a = ac / 255.0F;
180
181 return true;
182 }
183
184 return false;
185}
186// NOLINTEND(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)

Callers 5

RestoreMethod · 0.80
RestoreMethod · 0.80
RestoreMethod · 0.80
highlightSegmentsMethod · 0.80
TESTFunction · 0.80

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected