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

Function SaveEXR

include/tinyexr/tinyexr.h:9250–9392  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected