MCPcopy Create free account
hub / github.com/cinder/Cinder / LoadEXRFromMemory

Function LoadEXRFromMemory

include/tinyexr/tinyexr.h:6599–6804  ·  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 return ret;
6624 }
6625
6626 // Read HALF channel as FLOAT.
6627 for (int i = 0; i < exr_header.num_channels; i++) {
6628 if (exr_header.pixel_types[i] == TINYEXR_PIXELTYPE_HALF) {
6629 exr_header.requested_pixel_types[i] = TINYEXR_PIXELTYPE_FLOAT;
6630 }
6631 }
6632
6633 InitEXRImage(&exr_image);
6634 ret = LoadEXRImageFromMemory(&exr_image, &exr_header, memory, size, err);
6635 if (ret != TINYEXR_SUCCESS) {
6636 return ret;
6637 }
6638
6639 // RGBA
6640 int idxR = -1;
6641 int idxG = -1;
6642 int idxB = -1;
6643 int idxA = -1;
6644 for (int c = 0; c < exr_header.num_channels; c++) {
6645 if (strcmp(exr_header.channels[c].name, "R") == 0) {
6646 idxR = c;
6647 } else if (strcmp(exr_header.channels[c].name, "G") == 0) {
6648 idxG = c;
6649 } else if (strcmp(exr_header.channels[c].name, "B") == 0) {
6650 idxB = c;
6651 } else if (strcmp(exr_header.channels[c].name, "A") == 0) {
6652 idxA = c;
6653 }
6654 }
6655
6656 // TODO(syoyo): Refactor removing same code as used in LoadEXR().

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected