-
Notifications
You must be signed in to change notification settings - Fork 608
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement copy_image for OpenEXR (#4004)
Base on the [OIIO slack channel discussion](https://academysoftwarefdn.slack.com/archives/C05782U3806/p1689031780561469), this PR implements the `copy_image` function for the OpenEXR format. The main motivation of this PR was due to a recompression issue where copying a lossy compressed EXR image (pixels are decoded and then encoded again), which can cause the image quality to downgrade on each iteration. - `OpenEXROutput` is now a friend class of `OpenEXRInput`. Since `OpenEXROutput::copy_image()` needs to access some of the private members in `OpenEXRInput` (This approach is referencing the implementation in `JpegInput` and `JpegOutput`). - The `OpenEXRInputStream` and `OpenEXRInput` class have been moved from `exrinput.cpp` to `exr_pvt.h`. As `OpenEXRInput` depends on `OpenEXRInputStream`, so both have to be moved together. Such relocation is necessary due to the above reason, i.e. `OpenEXROutput::copy_image()` needs to access some of the private members in `OpenEXRInput`. - And the implementation itself, `OpenEXROutput::copy_image()` overrides the base class method just like `JpegOutput` does. The `OpenEXROutput::copy_image()` implementation took the advantages of the existing OpenEXR function `Imf::OutputFile::copyPixels`, quoting the comment from the function: > //-------------------------------------------------------------- // Shortcut to copy all pixels from an InputFile into this file, // without uncompressing and then recompressing the pixel data. // This file's header must be compatible with the InputFile's // header: The two header's "dataWindow", "compression", // "lineOrder" and "channels" attributes must be the same. //-------------------------------------------------------------- IMF_EXPORT void copyPixels (InputFile &in); When the output image is copied from an input image, the pixel data can only be located in one of the input parts. So it checks if both input and output part is initialized (non-null), then invoke the `copyPixels` function in place. All the error handling is done within the OpenEXR `copyPixels` call. There is a try-catch block in OIIO side that emits an error message and fallback to the default image copy routine, e.g. `ImageOutput::copy_image`. Note that currently, this doesn't do anything optimized for the "core library" code path. --------- Signed-off-by: Andy Chan <[email protected]>
- Loading branch information
Showing
7 changed files
with
338 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.