MCPcopy Create free account
hub / github.com/OpenPathGuidingLibrary/openpgl / LoadEXRFromMemory

Function LoadEXRFromMemory

third-party/tinyexr/tinyexr.h:6520–6725  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6518}
6519
6520int LoadEXRFromMemory(float **out_rgba, int *width, int *height,
6521 const unsigned char *memory, size_t size,
6522 const char **err) {
6523 if (out_rgba == NULL || memory == NULL) {
6524 tinyexr::SetErrorMessage("Invalid argument for LoadEXRFromMemory", err);
6525 return TINYEXR_ERROR_INVALID_ARGUMENT;
6526 }
6527
6528 EXRVersion exr_version;
6529 EXRImage exr_image;
6530 EXRHeader exr_header;
6531
6532 InitEXRHeader(&exr_header);
6533
6534 int ret = ParseEXRVersionFromMemory(&exr_version, memory, size);
6535 if (ret != TINYEXR_SUCCESS) {
6536 std::stringstream ss;
6537 ss << "Failed to parse EXR version. code(" << ret << ")";
6538 tinyexr::SetErrorMessage(ss.str(), err);
6539 return ret;
6540 }
6541
6542 ret = ParseEXRHeaderFromMemory(&exr_header, &exr_version, memory, size, err);
6543 if (ret != TINYEXR_SUCCESS) {
6544 return ret;
6545 }
6546
6547 // Read HALF channel as FLOAT.
6548 for (int i = 0; i < exr_header.num_channels; i++) {
6549 if (exr_header.pixel_types[i] == TINYEXR_PIXELTYPE_HALF) {
6550 exr_header.requested_pixel_types[i] = TINYEXR_PIXELTYPE_FLOAT;
6551 }
6552 }
6553
6554 InitEXRImage(&exr_image);
6555 ret = LoadEXRImageFromMemory(&exr_image, &exr_header, memory, size, err);
6556 if (ret != TINYEXR_SUCCESS) {
6557 return ret;
6558 }
6559
6560 // RGBA
6561 int idxR = -1;
6562 int idxG = -1;
6563 int idxB = -1;
6564 int idxA = -1;
6565 for (int c = 0; c < exr_header.num_channels; c++) {
6566 if (strcmp(exr_header.channels[c].name, "R") == 0) {
6567 idxR = c;
6568 } else if (strcmp(exr_header.channels[c].name, "G") == 0) {
6569 idxG = c;
6570 } else if (strcmp(exr_header.channels[c].name, "B") == 0) {
6571 idxB = c;
6572 } else if (strcmp(exr_header.channels[c].name, "A") == 0) {
6573 idxA = c;
6574 }
6575 }
6576
6577 // TODO(syoyo): Refactor removing same code as used in LoadEXR().

Callers

nothing calls this directly

Calls 8

SetErrorMessageFunction · 0.85
InitEXRHeaderFunction · 0.85
ParseEXRHeaderFromMemoryFunction · 0.85
InitEXRImageFunction · 0.85
LoadEXRImageFromMemoryFunction · 0.85
FreeEXRHeaderFunction · 0.85
FreeEXRImageFunction · 0.85

Tested by

no test coverage detected