MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/MaterialX / getTexelColor

Method getTexelColor

source/MaterialXRender/Image.cpp:199–366  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

197}
198
199Color4 Image::getTexelColor(unsigned int x, unsigned int y) const
200{
201 if (x >= _width || y >= _height)
202 {
203 throw Exception("Invalid coordinates in getTexelColor");
204 }
205 if (!_resourceBuffer)
206 {
207 throw Exception("Invalid resource buffer in getTexelColor");
208 }
209
210 if (_baseType == BaseType::FLOAT)
211 {
212 float* data = static_cast<float*>(_resourceBuffer) + (y * _width + x) * _channelCount;
213 if (_channelCount == 4)
214 {
215 return Color4(data[0], data[1], data[2], data[3]);
216 }
217 else if (_channelCount == 3)
218 {
219 return Color4(data[0], data[1], data[2], 1.0f);
220 }
221 else if (_channelCount == 2)
222 {
223 return Color4(data[0], data[1], 0.0f, 1.0f);
224 }
225 else if (_channelCount == 1)
226 {
227 return Color4(data[0], data[0], data[0], 1.0f);
228 }
229 else
230 {
231 throw Exception("Unsupported channel count in getTexelColor");
232 }
233 }
234 else if (_baseType == BaseType::HALF)
235 {
236 Half* data = static_cast<Half*>(_resourceBuffer) + (y * _width + x) * _channelCount;
237 if (_channelCount == 4)
238 {
239 return Color4(data[0], data[1], data[2], data[3]);
240 }
241 else if (_channelCount == 3)
242 {
243 return Color4(data[0], data[1], data[2], 1.0f);
244 }
245 else if (_channelCount == 2)
246 {
247 return Color4(data[0], data[1], 0.0f, 1.0f);
248 }
249 else if (_channelCount == 1)
250 {
251 return Color4(data[0], data[0], data[0], 1.0f);
252 }
253 else
254 {
255 throw Exception("Unsupported channel count in getTexelColor");
256 }

Callers 5

Render.cppFile · 0.80
projectEnvironmentFunction · 0.80
normalizeEnvironmentFunction · 0.80
applyGaussianBlurMethod · 0.80

Calls 2

Color4Function · 0.85
maxFunction · 0.50

Tested by

no test coverage detected