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

Function SaveEXRToMemory

third-party/tinyexr/tinyexr.h:9010–9158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9008}
9009
9010int SaveEXRToMemory(const float *data, int width, int height, int components,
9011 const int save_as_fp16, unsigned char **outbuf, const char **err) {
9012
9013 if ((components == 1) || components == 3 || components == 4) {
9014 // OK
9015 } else {
9016 std::stringstream ss;
9017 ss << "Unsupported component value : " << components << std::endl;
9018
9019 tinyexr::SetErrorMessage(ss.str(), err);
9020 return TINYEXR_ERROR_INVALID_ARGUMENT;
9021 }
9022
9023 EXRHeader header;
9024 InitEXRHeader(&header);
9025
9026 if ((width < 16) && (height < 16)) {
9027 // No compression for small image.
9028 header.compression_type = TINYEXR_COMPRESSIONTYPE_NONE;
9029 } else {
9030 header.compression_type = TINYEXR_COMPRESSIONTYPE_ZIP;
9031 }
9032
9033 EXRImage image;
9034 InitEXRImage(&image);
9035
9036 image.num_channels = components;
9037
9038 std::vector<float> images[4];
9039
9040 if (components == 1) {
9041 images[0].resize(static_cast<size_t>(width * height));
9042 memcpy(images[0].data(), data, sizeof(float) * size_t(width * height));
9043 } else {
9044 images[0].resize(static_cast<size_t>(width * height));
9045 images[1].resize(static_cast<size_t>(width * height));
9046 images[2].resize(static_cast<size_t>(width * height));
9047 images[3].resize(static_cast<size_t>(width * height));
9048
9049 // Split RGB(A)RGB(A)RGB(A)... into R, G and B(and A) layers
9050 for (size_t i = 0; i < static_cast<size_t>(width * height); i++) {
9051 images[0][i] = data[static_cast<size_t>(components) * i + 0];
9052 images[1][i] = data[static_cast<size_t>(components) * i + 1];
9053 images[2][i] = data[static_cast<size_t>(components) * i + 2];
9054 if (components == 4) {
9055 images[3][i] = data[static_cast<size_t>(components) * i + 3];
9056 }
9057 }
9058 }
9059
9060 float *image_ptr[4] = {0, 0, 0, 0};
9061 if (components == 4) {
9062 image_ptr[0] = &(images[3].at(0)); // A
9063 image_ptr[1] = &(images[2].at(0)); // B
9064 image_ptr[2] = &(images[1].at(0)); // G
9065 image_ptr[3] = &(images[0].at(0)); // R
9066 } else if (components == 3) {
9067 image_ptr[0] = &(images[2].at(0)); // B

Callers

nothing calls this directly

Calls 7

SetErrorMessageFunction · 0.85
InitEXRHeaderFunction · 0.85
InitEXRImageFunction · 0.85
SaveEXRImageToMemoryFunction · 0.85
maxFunction · 0.50
resizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected