can save a single or multi-part image (no deep* formats)
| 7685 | |
| 7686 | // can save a single or multi-part image (no deep* formats) |
| 7687 | static size_t SaveEXRNPartImageToMemory(const EXRImage* exr_images, |
| 7688 | const EXRHeader** exr_headers, |
| 7689 | unsigned int num_parts, |
| 7690 | unsigned char** memory_out, const char** err) { |
| 7691 | if (exr_images == NULL || exr_headers == NULL || num_parts == 0 || |
| 7692 | memory_out == NULL) { |
| 7693 | SetErrorMessage("Invalid argument for SaveEXRNPartImageToMemory", |
| 7694 | err); |
| 7695 | return 0; |
| 7696 | } |
| 7697 | { |
| 7698 | for (unsigned int i = 0; i < num_parts; ++i) { |
| 7699 | if (exr_headers[i]->compression_type < 0) { |
| 7700 | SetErrorMessage("Invalid argument for SaveEXRNPartImageToMemory", |
| 7701 | err); |
| 7702 | return 0; |
| 7703 | } |
| 7704 | #if !TINYEXR_USE_PIZ |
| 7705 | if (exr_headers[i]->compression_type == TINYEXR_COMPRESSIONTYPE_PIZ) { |
| 7706 | SetErrorMessage("PIZ compression is not supported in this build", |
| 7707 | err); |
| 7708 | return 0; |
| 7709 | } |
| 7710 | #endif |
| 7711 | if (exr_headers[i]->compression_type == TINYEXR_COMPRESSIONTYPE_ZFP) { |
| 7712 | #if !TINYEXR_USE_ZFP |
| 7713 | SetErrorMessage("ZFP compression is not supported in this build", |
| 7714 | err); |
| 7715 | return 0; |
| 7716 | #else |
| 7717 | // All channels must be fp32. |
| 7718 | // No fp16 support in ZFP atm(as of 2023 June) |
| 7719 | // https://github.com/LLNL/fpzip/issues/2 |
| 7720 | for (int c = 0; c < exr_headers[i]->num_channels; ++c) { |
| 7721 | if (exr_headers[i]->requested_pixel_types[c] != TINYEXR_PIXELTYPE_FLOAT) { |
| 7722 | SetErrorMessage("Pixel type must be FLOAT for ZFP compression", |
| 7723 | err); |
| 7724 | return 0; |
| 7725 | } |
| 7726 | } |
| 7727 | #endif |
| 7728 | } |
| 7729 | } |
| 7730 | } |
| 7731 | |
| 7732 | std::vector<unsigned char> memory; |
| 7733 | |
| 7734 | // Header |
| 7735 | { |
| 7736 | const char header[] = { 0x76, 0x2f, 0x31, 0x01 }; |
| 7737 | memory.insert(memory.end(), header, header + 4); |
| 7738 | } |
| 7739 | |
| 7740 | // Version |
| 7741 | // using value from the first header |
| 7742 | int long_name = exr_headers[0]->long_name; |
| 7743 | { |
| 7744 | char marker[] = { 2, 0, 0, 0 }; |
no test coverage detected