MCPcopy Create free account
hub / github.com/assimp/assimp / parseColor

Function parseColor

code/AssetLib/3MF/XmlSerializer.cpp:160–190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

158}
159
160bool parseColor(const std::string &color, aiColor4D &diffuse) {
161 if (color.empty()) {
162 return false;
163 }
164
165 if (!validateColorString(color)) {
166 return false;
167 }
168
169 if ('#' != color[0]) {
170 return false;
171 }
172
173 char r[3] = { color[1], color[2], '\0' };
174 diffuse.r = static_cast<ai_real>(strtol(r, nullptr, 16)) / ai_real(255.0);
175
176 char g[3] = { color[3], color[4], '\0' };
177 diffuse.g = static_cast<ai_real>(strtol(g, nullptr, 16)) / ai_real(255.0);
178
179 char b[3] = { color[5], color[6], '\0' };
180 diffuse.b = static_cast<ai_real>(strtol(b, nullptr, 16)) / ai_real(255.0);
181 const size_t len = color.size();
182 if (ColRGB_Len == len) {
183 return true;
184 }
185
186 char a[3] = { color[7], color[8], '\0' };
187 diffuse.a = static_cast<ai_real>(strtol(a, nullptr, 16)) / ai_real(255.0);
188
189 return true;
190}
191
192void assignDiffuseColor(XmlNode &node, aiMaterial *mat) {
193 const char *color = node.attribute(XmlTag::basematerials_displaycolor).as_string();

Callers 2

assignDiffuseColorFunction · 0.85
ReadColorMethod · 0.85

Calls 3

validateColorStringFunction · 0.85
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected