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

Function SaveEXRToMemory

tutorials/common/image/tinyexr.h:9099–9253  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9097}
9098
9099int SaveEXRToMemory(const float *data, int width, int height, int components,
9100 const int save_as_fp16, unsigned char **outbuf, const char **err) {
9101
9102 if ((components == 1) || components == 3 || components == 4) {
9103 // OK
9104 } else {
9105 std::stringstream ss;
9106 ss << "Unsupported component value : " << components << std::endl;
9107
9108 tinyexr::SetErrorMessage(ss.str(), err);
9109 return TINYEXR_ERROR_INVALID_ARGUMENT;
9110 }
9111
9112 EXRHeader header;
9113 InitEXRHeader(&header);
9114
9115 if ((width < 16) && (height < 16)) {
9116 // No compression for small image.
9117 header.compression_type = TINYEXR_COMPRESSIONTYPE_NONE;
9118 } else {
9119 header.compression_type = TINYEXR_COMPRESSIONTYPE_ZIP;
9120 }
9121
9122 EXRImage image;
9123 InitEXRImage(&image);
9124
9125 image.num_channels = components;
9126
9127 std::vector<float> images[4];
9128
9129 if (components == 1) {
9130 images[0].resize(static_cast<size_t>(width * height));
9131 memcpy(images[0].data(), data, sizeof(float) * size_t(width * height));
9132 } else {
9133 images[0].resize(static_cast<size_t>(width * height));
9134 images[1].resize(static_cast<size_t>(width * height));
9135 images[2].resize(static_cast<size_t>(width * height));
9136 images[3].resize(static_cast<size_t>(width * height));
9137
9138 // Split RGB(A)RGB(A)RGB(A)... into R, G and B(and A) layers
9139 if (components == 4) {
9140 for (size_t i = 0; i < static_cast<size_t>(width * height); i++) {
9141 images[0][i] = data[static_cast<size_t>(components) * i + 0];
9142 images[1][i] = data[static_cast<size_t>(components) * i + 1];
9143 images[2][i] = data[static_cast<size_t>(components) * i + 2];
9144 images[3][i] = data[static_cast<size_t>(components) * i + 3];
9145 }
9146 } else {
9147 for (size_t i = 0; i < static_cast<size_t>(width * height); i++) {
9148 images[0][i] = data[static_cast<size_t>(components) * i + 0];
9149 images[1][i] = data[static_cast<size_t>(components) * i + 1];
9150 images[2][i] = data[static_cast<size_t>(components) * i + 2];
9151 }
9152 }
9153 }
9154
9155 float *image_ptr[4] = {0, 0, 0, 0};
9156 if (components == 4) {

Callers

nothing calls this directly

Calls 10

SetErrorMessageFunction · 0.85
InitEXRHeaderFunction · 0.85
InitEXRImageFunction · 0.85
mallocFunction · 0.85
SaveEXRImageToMemoryFunction · 0.85
maxFunction · 0.50
strMethod · 0.45
resizeMethod · 0.45
dataMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected