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

Function SaveEXRToMemory

include/tinyexr/tinyexr.h:9094–9248  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected