MCPcopy Create free account
hub / github.com/NVlabs/flip / LoadEXRImageFromFile

Function LoadEXRImageFromFile

src/cpp/tool/tinyexr.h:12892–12944  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12890}
12891
12892int LoadEXRImageFromFile(EXRImage *exr_image, const EXRHeader *exr_header,
12893 const char *filename, const char **err) {
12894 if (exr_image == NULL) {
12895 tinyexr::SetErrorMessage("Invalid argument for LoadEXRImageFromFile", err);
12896 return TINYEXR_ERROR_INVALID_ARGUMENT;
12897 }
12898
12899 FILE *fp = NULL;
12900#ifdef _WIN32
12901#if defined(_MSC_VER) || defined(__MINGW32__) // MSVC, MinGW gcc or clang
12902 errno_t errcode =
12903 _wfopen_s(&fp, tinyexr::UTF8ToWchar(filename).c_str(), L"rb");
12904 if (errcode != 0) {
12905 tinyexr::SetErrorMessage("Cannot read file " + std::string(filename), err);
12906 // TODO(syoyo): return wfopen_s erro code
12907 return TINYEXR_ERROR_CANT_OPEN_FILE;
12908 }
12909#else
12910 // Unknown compiler
12911 fp = fopen(filename, "rb");
12912#endif
12913#else
12914 fp = fopen(filename, "rb");
12915#endif
12916 if (!fp) {
12917 tinyexr::SetErrorMessage("Cannot read file " + std::string(filename), err);
12918 return TINYEXR_ERROR_CANT_OPEN_FILE;
12919 }
12920
12921 size_t filesize;
12922 // Compute size
12923 fseek(fp, 0, SEEK_END);
12924 filesize = static_cast<size_t>(ftell(fp));
12925 fseek(fp, 0, SEEK_SET);
12926
12927 if (filesize < 16) {
12928 tinyexr::SetErrorMessage("File size too short " + std::string(filename),
12929 err);
12930 return TINYEXR_ERROR_INVALID_FILE;
12931 }
12932
12933 std::vector<unsigned char> buf(filesize); // @todo { use mmap }
12934 {
12935 size_t ret;
12936 ret = fread(&buf[0], 1, filesize, fp);
12937 assert(ret == filesize);
12938 fclose(fp);
12939 (void)ret;
12940 }
12941
12942 return LoadEXRImageFromMemory(exr_image, exr_header, &buf.at(0), filesize,
12943 err);
12944}
12945
12946int LoadEXRImageFromMemory(EXRImage *exr_image, const EXRHeader *exr_header,
12947 const unsigned char *memory, const size_t size,

Callers 2

LoadEXRWithLayerFunction · 0.85
hdrLoadFunction · 0.85

Calls 4

SetErrorMessageFunction · 0.85
UTF8ToWcharFunction · 0.85
LoadEXRImageFromMemoryFunction · 0.85
atMethod · 0.80

Tested by

no test coverage detected