forked from AcademySoftwareFoundation/openexr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite OpenEXR python bindings using pybind11 and numpy (AcademySoft…
…wareFoundation#1756) * Rewrite python bindings with pybind11 and numpy This introduces an entirely new python API for reading and writing OpenEXR files that supports all file features (or will soon): scanline, tiled, deep, multi-part, etc. It uses numpy arrays for pixel data, and it supports both separate arrays for each channel and interleaving of RGB data into a single composite channel. It leaves the existing binding API in place for backwards-compatibility; there's no overlap between the two APIs. See src/wrappers/python/README.md for examples of the new API. The API is simple: the ``File`` object holds a py::list of ``Part`` objects, each of which has a py::dict for the header and a py::dict for the channels, and each channels hold a numpy array for the pixel data. There's intentionally no support for selective scanline/time reading; reading a file reads the entire channel data for all parts. There *is*, however, an option to read just the headers and skip the pixel data entirely. A few things don't work yet: - Reading and writing of deep data isn't finished. - ID manfest attributes aren't supported yet. - For mipmaped images, it current only reads the top level. This also does not (yet) properly integrate the real Imath types. It leaves in place for now the internal "Imath.py" module, but defines its own internal set of set of Imath classes. This needs to be resolve once the Imath bindings are distributed via pypi.org The test suite downloads images from openexr-images and runs them through a battery of reading/writing tests. Currently, the download is enabled via the ``OPENEXR_TEST_IMAGE_REPO`` environment variable that is off by default but is on in the python wheel CI workflow. This also adds operator== methods to ``KeyCode`` and ``PreviewImage``, required in order to implement operator== for the ``Part`` and ``File`` objects. Signed-off-by: Cary Phillips <[email protected]> * Fix subsampling Signed-off-by: Cary Phillips <[email protected]> * - Make README.md examples more pythonic - Add __enter__/__exit__ so "with File(name) as f" works - Allow channel dict to reference pixel array directly - Fix subsampling Signed-off-by: Cary Phillips <[email protected]> * Use numpy/tuples in place of Imath types Also: - Use single-element array for DoubleAttribute - Use fractions.Fraction for Rational - Use 8-element tuple for chromaticities - Add __enter__/__exit__ so "with" works with File object - remove operator== entirely, it's way too hard to implement something that's actually useful for testing purposes. The tests do their own validations. Signed-off-by: Cary Phillips <[email protected]> pixel comparison Signed-off-by: Cary Phillips <[email protected]> * Deep reading/writing works for both scanline and tiles Also works properly for separate channels and when coalescing into RGB/RGBA arrays. Signed-off-by: Cary Phillips <[email protected]> * doc strings Signed-off-by: Cary Phillips <[email protected]> * Rename rgba param to separate_channels, off by default. Signed-off-by: Cary Phillips <[email protected]> * remove numpy as build requirement Signed-off-by: Cary Phillips <[email protected]> * Rename rgbaChannel() to channelNameToRGBA; rename is_* to objectTo* Signed-off-by: Cary Phillips <[email protected]> * Add "deprecated" to InputFile/OutputFile/Imath doc strings Signed-off-by: Cary Phillips <[email protected]> * Explicitly set python versions for wheel workflows, and exclude 3.13 Signed-off-by: Cary Phillips <[email protected]> * resolve conflicts Signed-off-by: Cary Phillips <[email protected]> * resolve conflict Signed-off-by: Cary Phillips <[email protected]> --------- Signed-off-by: Cary Phillips <[email protected]>
- Loading branch information
Showing
23 changed files
with
5,327 additions
and
410 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env bash | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# Copyright Contributors to the OpenColorIO Project. | ||
|
||
set -ex | ||
|
||
PYBIND11_VERSION="$1" | ||
|
||
if [[ $OSTYPE == "msys" ]]; then | ||
SUDO="" | ||
else | ||
SUDO="sudo" | ||
fi | ||
|
||
git clone https://github.com/pybind/pybind11.git | ||
cd pybind11 | ||
|
||
if [ "$PYBIND11_VERSION" == "latest" ]; then | ||
LATEST_TAG=$(git describe --abbrev=0 --tags) | ||
git checkout tags/${LATEST_TAG} -b ${LATEST_TAG} | ||
else | ||
git checkout tags/v${PYBIND11_VERSION} -b v${PYBIND11_VERSION} | ||
fi | ||
|
||
mkdir build | ||
cd build | ||
cmake -DCMAKE_BUILD_TYPE=Release \ | ||
-DPYBIND11_INSTALL=ON \ | ||
-DPYBIND11_TEST=OFF \ | ||
../. | ||
$SUDO cmake --build . \ | ||
--target install \ | ||
--config Release \ | ||
--parallel 2 | ||
|
||
cd ../.. | ||
rm -rf pybind11 |
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
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
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.