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

Method createFromFile

Source/Falcor/Utils/Image/Bitmap.cpp:291–449  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

289}
290
291Bitmap::UniqueConstPtr Bitmap::createFromFile(const std::filesystem::path& path, bool isTopDown, ImportFlags importFlags)
292{
293 if (!std::filesystem::exists(path))
294 {
295 logWarning("Error when loading image file. File '{}' does not exist.", path);
296 return nullptr;
297 }
298
299 FREE_IMAGE_FORMAT fifFormat = FIF_UNKNOWN;
300
301 fifFormat = FreeImage_GetFileType(path.string().c_str(), 0);
302 if (fifFormat == FIF_UNKNOWN)
303 {
304 // Can't get the format from the file. Use file extension
305 fifFormat = FreeImage_GetFIFFromFilename(path.string().c_str());
306
307 if (fifFormat == FIF_UNKNOWN)
308 {
309 genWarning("Image type unknown", path);
310 return nullptr;
311 }
312 }
313
314 // Check the library supports loading this image type
315 if (FreeImage_FIFSupportsReading(fifFormat) == false)
316 {
317 genWarning("Library doesn't support the file format", path);
318 return nullptr;
319 }
320
321 // Read file using memory mapped access which is much faster than regular file IO.
322 MemoryMappedFile file(path, MemoryMappedFile::kWholeFile, MemoryMappedFile::AccessHint::SequentialScan);
323 if (!file.isOpen())
324 {
325 genWarning("Can't open image file {}", path);
326 return nullptr;
327 }
328
329 if (fifFormat == FIF_EXR)
330 {
331 if (isFloat16Exr(file))
332 importFlags |= ImportFlags::ConvertToFloat16;
333 }
334
335 FIMEMORY* memory = FreeImage_OpenMemory((BYTE*)file.getData(), file.getSize());
336 FIBITMAP* pDib = FreeImage_LoadFromMemory(fifFormat, memory);
337 FreeImage_CloseMemory(memory);
338 file.close();
339
340 if (pDib == nullptr)
341 {
342 genWarning("Can't read image file", path);
343 return nullptr;
344 }
345
346 // Create the bitmap
347 const uint32_t height = FreeImage_GetHeight(pDib);
348 const uint32_t width = FreeImage_GetWidth(pDib);

Callers

nothing calls this directly

Calls 10

genWarningFunction · 0.85
isFloat16ExrFunction · 0.85
isRGB32fSupportedFunction · 0.85
convertToRGBA16FloatFunction · 0.85
convertToRGBAFFunction · 0.85
logWarningFunction · 0.50
stringMethod · 0.45
getDataMethod · 0.45
getSizeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected