MCPcopy Create free account
hub / github.com/TheRealMJP/BakingLab / SaveMultiChannelEXR

Function SaveMultiChannelEXR

SampleFramework11/v1.02/TinyEXR.cpp:7540–7751  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7538#endif
7539
7540int SaveMultiChannelEXR(const EXRImage *exrImage, const char *filename,
7541 const char **err) {
7542 if (exrImage == NULL || filename == NULL) {
7543 if (err) {
7544 (*err) = "Invalid argument.";
7545 }
7546 return -1;
7547 }
7548
7549 FILE *fp = fopen(filename, "wb");
7550 if (!fp) {
7551 if (err) {
7552 (*err) = "Cannot write a file.";
7553 }
7554 return -1;
7555 }
7556
7557 // Header
7558 {
7559 const char header[] = {0x76, 0x2f, 0x31, 0x01};
7560 size_t n = fwrite(header, 1, 4, fp);
7561 assert(n == 4);
7562 }
7563
7564 // Version, scanline.
7565 {
7566 const char marker[] = {2, 0, 0, 0};
7567 size_t n = fwrite(marker, 1, 4, fp);
7568 assert(n == 4);
7569 }
7570
7571 int numScanlineBlocks = 16; // 16 for ZIP compression.
7572
7573 // Write attributes.
7574 {
7575 std::vector<unsigned char> data;
7576
7577 std::vector<ChannelInfo> channels;
7578 for (int c = 0; c < exrImage->num_channels; c++) {
7579 ChannelInfo info;
7580 info.pLinear = 0;
7581 info.pixelType = 1; // Assume HALF
7582 info.xSampling = 1;
7583 info.ySampling = 1;
7584 info.name = std::string(exrImage->channel_names[c]);
7585 channels.push_back(info);
7586 }
7587
7588 WriteChannelInfo(data, channels);
7589
7590 WriteAttribute(fp, "channels", "chlist", &data.at(0),
7591 data.size()); // +1 = null
7592 }
7593
7594 {
7595 int compressionType = 3; // ZIP compression
7596 if (IsBigEndian()) {
7597 swap4(reinterpret_cast<unsigned int*>(&compressionType));

Callers 1

SaveTextureAsEXRFunction · 0.85

Calls 14

WriteChannelInfoFunction · 0.85
WriteAttributeFunction · 0.85
IsBigEndianFunction · 0.85
swap4Function · 0.85
float_to_half_fullFunction · 0.85
swap2Function · 0.85
mz_compressBoundFunction · 0.85
CompressZipFunction · 0.85
swap8Function · 0.85
atMethod · 0.80
endMethod · 0.80
push_backMethod · 0.45

Tested by

no test coverage detected