MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/Falcor / setImage

Function setImage

Source/Falcor/Utils/Image/ImageIO.cpp:252–331  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

250// if image compression needs to be maintained.
251template<typename T>
252void setImage(
253 const void* subresourceData,
254 nvtt::Surface& surface,
255 ExportData image,
256 uint32_t srcWidth,
257 uint32_t srcHeight,
258 uint32_t srcDepth
259)
260{
261 std::vector<T> modified;
262 uint32_t pixelCount = srcWidth * srcHeight * srcDepth;
263 uint32_t channelCount = getFormatChannelCount(image.format);
264 T alpha = T(0);
265
266 // Need to flip red and blue channels for all 8 bit formats that aren't BGRA/BGRX as NVTT only supports BGRA inputs for these cases
267 bool reverseRB = getNumChannelBits(image.format, 0) == 8 && image.format != ResourceFormat::BGRA8Unorm &&
268 image.format != ResourceFormat::BGRA8UnormSrgb && image.format != ResourceFormat::BGRX8Unorm &&
269 image.format != ResourceFormat::BGRX8UnormSrgb;
270 // Need to fill the alpha channel with 1's for all formats that do not have an alpha channel
271 bool fillAlpha = channelCount == 2 || channelCount == 3 || image.format == ResourceFormat::BGRX8Unorm ||
272 image.format == ResourceFormat::BGRX8UnormSrgb;
273
274 modified.resize(4 * pixelCount);
275
276 T* src = (T*)subresourceData;
277 T* dst = (T*)modified.data();
278 for (uint32_t h = 0; h < image.height; ++h)
279 {
280 for (uint32_t w = 0; w < image.width; ++w)
281 {
282 uint32_t i = h * srcWidth + w; // Source data index
283 uint32_t j = h * image.width + w; // Destination data index - Same as source index if no clamping is involved
284 if (channelCount == 1)
285 {
286 dst[j] = T(src[i]);
287 }
288 else if (channelCount == 2)
289 {
290 dst[4 * j] = reverseRB ? T(0) : T(src[2 * i]);
291 dst[4 * j + 1] = T(src[2 * i + 1]);
292 dst[4 * j + 2] = reverseRB ? T(src[2 * i]) : T(0);
293 dst[4 * j + 3] = T(0);
294 }
295 else if (channelCount == 3)
296 {
297 dst[4 * j] = reverseRB ? T(src[3 * i + 2]) : T(src[3 * i]);
298 dst[4 * j + 1] = T(src[3 * i + 1]);
299 dst[4 * j + 2] = reverseRB ? T(src[3 * i]) : T(src[3 * i + 2]);
300 dst[4 * j + 3] = T(0);
301 }
302 else if (channelCount == 4)
303 {
304 dst[4 * j] = reverseRB ? T(src[4 * i + 2]) : T(src[4 * i]);
305 dst[4 * j + 1] = T(src[4 * i + 1]);
306 dst[4 * j + 2] = reverseRB ? T(src[4 * i]) : T(src[4 * i + 2]);
307 dst[4 * j + 3] = T(src[4 * i + 3]);
308 }
309 }

Callers

nothing calls this directly

Calls 9

getFormatChannelCountFunction · 0.85
getNumChannelBitsFunction · 0.85
isCompressedFormatFunction · 0.85
convertToNvttInputFormatFunction · 0.85
fillAlphaChannelFunction · 0.85
TFunction · 0.50
resizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected