MCPcopy Create free account
hub / github.com/ARM-software/astc-encoder / SaveEXRToMemory

Function SaveEXRToMemory

Source/ThirdParty/tinyexr.h:10652–10806  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10650}
10651
10652int SaveEXRToMemory(const float *data, int width, int height, int components,
10653 const int save_as_fp16, unsigned char **outbuf, const char **err) {
10654
10655 if ((components == 1) || components == 3 || components == 4) {
10656 // OK
10657 } else {
10658 std::stringstream ss;
10659 ss << "Unsupported component value : " << components << std::endl;
10660
10661 tinyexr::SetErrorMessage(ss.str(), err);
10662 return TINYEXR_ERROR_INVALID_ARGUMENT;
10663 }
10664
10665 EXRHeader header;
10666 InitEXRHeader(&header);
10667
10668 if ((width < 16) && (height < 16)) {
10669 // No compression for small image.
10670 header.compression_type = TINYEXR_COMPRESSIONTYPE_NONE;
10671 } else {
10672 header.compression_type = TINYEXR_COMPRESSIONTYPE_ZIP;
10673 }
10674
10675 EXRImage image;
10676 InitEXRImage(&image);
10677
10678 image.num_channels = components;
10679
10680 std::vector<float> images[4];
10681
10682 if (components == 1) {
10683 images[0].resize(static_cast<size_t>(width * height));
10684 memcpy(images[0].data(), data, sizeof(float) * size_t(width * height));
10685 } else {
10686 images[0].resize(static_cast<size_t>(width * height));
10687 images[1].resize(static_cast<size_t>(width * height));
10688 images[2].resize(static_cast<size_t>(width * height));
10689 images[3].resize(static_cast<size_t>(width * height));
10690
10691 // Split RGB(A)RGB(A)RGB(A)... into R, G and B(and A) layers
10692 if (components == 4) {
10693 for (size_t i = 0; i < static_cast<size_t>(width * height); i++) {
10694 images[0][i] = data[static_cast<size_t>(components) * i + 0];
10695 images[1][i] = data[static_cast<size_t>(components) * i + 1];
10696 images[2][i] = data[static_cast<size_t>(components) * i + 2];
10697 images[3][i] = data[static_cast<size_t>(components) * i + 3];
10698 }
10699 } else {
10700 for (size_t i = 0; i < static_cast<size_t>(width * height); i++) {
10701 images[0][i] = data[static_cast<size_t>(components) * i + 0];
10702 images[1][i] = data[static_cast<size_t>(components) * i + 1];
10703 images[2][i] = data[static_cast<size_t>(components) * i + 2];
10704 }
10705 }
10706 }
10707
10708 float *image_ptr[4] = {0, 0, 0, 0};
10709 if (components == 4) {

Callers

nothing calls this directly

Calls 5

SetErrorMessageFunction · 0.85
InitEXRHeaderFunction · 0.85
InitEXRImageFunction · 0.85
SaveEXRImageToMemoryFunction · 0.85
maxFunction · 0.50

Tested by

no test coverage detected