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

Function SaveEXR

tutorials/common/image/tinyexr.h:9255–9397  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9253}
9254
9255int SaveEXR(const float *data, int width, int height, int components,
9256 const int save_as_fp16, const char *outfilename, const char **err) {
9257 if ((components == 1) || components == 3 || components == 4) {
9258 // OK
9259 } else {
9260 std::stringstream ss;
9261 ss << "Unsupported component value : " << components << std::endl;
9262
9263 tinyexr::SetErrorMessage(ss.str(), err);
9264 return TINYEXR_ERROR_INVALID_ARGUMENT;
9265 }
9266
9267 EXRHeader header;
9268 InitEXRHeader(&header);
9269
9270 if ((width < 16) && (height < 16)) {
9271 // No compression for small image.
9272 header.compression_type = TINYEXR_COMPRESSIONTYPE_NONE;
9273 } else {
9274 header.compression_type = TINYEXR_COMPRESSIONTYPE_ZIP;
9275 }
9276
9277 EXRImage image;
9278 InitEXRImage(&image);
9279
9280 image.num_channels = components;
9281
9282 std::vector<float> images[4];
9283 const size_t pixel_count =
9284 static_cast<size_t>(width) * static_cast<size_t>(height);
9285
9286 if (components == 1) {
9287 images[0].resize(pixel_count);
9288 memcpy(images[0].data(), data, sizeof(float) * pixel_count);
9289 } else {
9290 images[0].resize(pixel_count);
9291 images[1].resize(pixel_count);
9292 images[2].resize(pixel_count);
9293 images[3].resize(pixel_count);
9294
9295 // Split RGB(A)RGB(A)RGB(A)... into R, G and B(and A) layers
9296 if (components == 4) {
9297 for (size_t i = 0; i < pixel_count; i++) {
9298 images[0][i] = data[static_cast<size_t>(components) * i + 0];
9299 images[1][i] = data[static_cast<size_t>(components) * i + 1];
9300 images[2][i] = data[static_cast<size_t>(components) * i + 2];
9301 images[3][i] = data[static_cast<size_t>(components) * i + 3];
9302 }
9303 } else {
9304 for (size_t i = 0; i < pixel_count; i++) {
9305 images[0][i] = data[static_cast<size_t>(components) * i + 0];
9306 images[1][i] = data[static_cast<size_t>(components) * i + 1];
9307 images[2][i] = data[static_cast<size_t>(components) * i + 2];
9308 }
9309 }
9310 }
9311
9312 float *image_ptr[4] = {0, 0, 0, 0};

Callers 1

storeEXRFunction · 0.85

Calls 9

SetErrorMessageFunction · 0.85
InitEXRHeaderFunction · 0.85
InitEXRImageFunction · 0.85
mallocFunction · 0.85
SaveEXRImageToFileFunction · 0.85
strMethod · 0.45
resizeMethod · 0.45
dataMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected