MCPcopy Create free account
hub / github.com/RenderKit/embree / LoadEXRFromMemory

Function LoadEXRFromMemory

tutorials/common/image/tinyexr.h:6599–6809  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6597}
6598
6599int LoadEXRFromMemory(float **out_rgba, int *width, int *height,
6600 const unsigned char *memory, size_t size,
6601 const char **err) {
6602 if (out_rgba == NULL || memory == NULL) {
6603 tinyexr::SetErrorMessage("Invalid argument for LoadEXRFromMemory", err);
6604 return TINYEXR_ERROR_INVALID_ARGUMENT;
6605 }
6606
6607 EXRVersion exr_version;
6608 EXRImage exr_image;
6609 EXRHeader exr_header;
6610
6611 InitEXRHeader(&exr_header);
6612
6613 int ret = ParseEXRVersionFromMemory(&exr_version, memory, size);
6614 if (ret != TINYEXR_SUCCESS) {
6615 std::stringstream ss;
6616 ss << "Failed to parse EXR version. code(" << ret << ")";
6617 tinyexr::SetErrorMessage(ss.str(), err);
6618 return ret;
6619 }
6620
6621 ret = ParseEXRHeaderFromMemory(&exr_header, &exr_version, memory, size, err);
6622 if (ret != TINYEXR_SUCCESS) {
6623 FreeEXRHeader(&exr_header);
6624 return ret;
6625 }
6626
6627 // Read HALF channel as FLOAT.
6628 for (int i = 0; i < exr_header.num_channels; i++) {
6629 if (exr_header.pixel_types[i] == TINYEXR_PIXELTYPE_HALF) {
6630 exr_header.requested_pixel_types[i] = TINYEXR_PIXELTYPE_FLOAT;
6631 }
6632 }
6633
6634 InitEXRImage(&exr_image);
6635 ret = LoadEXRImageFromMemory(&exr_image, &exr_header, memory, size, err);
6636 if (ret != TINYEXR_SUCCESS) {
6637 FreeEXRHeader(&exr_header);
6638 FreeEXRImage(&exr_image);
6639 return ret;
6640 }
6641
6642 // RGBA
6643 int idxR = -1;
6644 int idxG = -1;
6645 int idxB = -1;
6646 int idxA = -1;
6647 for (int c = 0; c < exr_header.num_channels; c++) {
6648 if (strcmp(exr_header.channels[c].name, "R") == 0) {
6649 idxR = c;
6650 } else if (strcmp(exr_header.channels[c].name, "G") == 0) {
6651 idxG = c;
6652 } else if (strcmp(exr_header.channels[c].name, "B") == 0) {
6653 idxB = c;
6654 } else if (strcmp(exr_header.channels[c].name, "A") == 0) {
6655 idxA = c;
6656 }

Callers

nothing calls this directly

Calls 10

SetErrorMessageFunction · 0.85
InitEXRHeaderFunction · 0.85
ParseEXRHeaderFromMemoryFunction · 0.85
FreeEXRHeaderFunction · 0.85
InitEXRImageFunction · 0.85
LoadEXRImageFromMemoryFunction · 0.85
FreeEXRImageFunction · 0.85
mallocFunction · 0.85
strMethod · 0.45

Tested by

no test coverage detected