|
| 1 | +// SPDX-License-Identifier: BSD-3-Clause |
| 2 | +// Copyright Contributors to the OpenColorIO Project. |
| 3 | + |
| 4 | +#ifndef INCLUDED_OCIO_PYBUFFERUTILS_H |
| 5 | +#define INCLUDED_OCIO_PYBUFFERUTILS_H |
| 6 | + |
| 7 | +#include <string> |
| 8 | + |
| 9 | +#include <OpenColorABI.h> |
| 10 | +#include <OpenColorIO/OpenColorTypes.h> |
| 11 | + |
| 12 | +#include <pybind11/pybind11.h> |
| 13 | +#include <pybind11/numpy.h> |
| 14 | + |
| 15 | +namespace OCIO_NAMESPACE |
| 16 | +{ |
| 17 | + |
| 18 | +// Convert Python buffer protocol format code to NumPy dtype name |
| 19 | +std::string formatCodeToDtypeName(const std::string & format, pybind11::ssize_t numBits); |
| 20 | +// Convert OCIO BitDepth to NumPy dtype |
| 21 | +pybind11::dtype bitDepthToDtype(BitDepth bitDepth); |
| 22 | +// Convert OCIO BitDepth to data type byte count |
| 23 | +pybind11::ssize_t bitDepthToBytes(BitDepth bitDepth); |
| 24 | +// Convert OCIO ChannelOrdering to channel count |
| 25 | +long chanOrderToNumChannels(ChannelOrdering chanOrder); |
| 26 | + |
| 27 | +// Return string that describes Python buffer's N-dimensional array shape |
| 28 | +std::string getBufferShapeStr(const pybind11::buffer_info & info); |
| 29 | +// Return BitDepth for a supported Python buffer data type |
| 30 | +BitDepth getBufferBitDepth(const pybind11::buffer_info & info); |
| 31 | + |
| 32 | +// Throw if Python buffer format is incompatible with a NumPy dtype |
| 33 | +void checkBufferType(const pybind11::buffer_info & info, const pybind11::dtype & dt); |
| 34 | +// Throw if Python buffer format is incompatible with an OCIO BitDepth |
| 35 | +void checkBufferType(const pybind11::buffer_info & info, BitDepth bitDepth); |
| 36 | +// Throw if Python buffer size is not divisible by channel count |
| 37 | +void checkBufferDivisible(const pybind11::buffer_info & info, pybind11::ssize_t numChannels); |
| 38 | +// Throw if Python buffer does not have an exact count of entries |
| 39 | +void checkBufferSize(const pybind11::buffer_info & info, pybind11::ssize_t numEntries); |
| 40 | + |
| 41 | +// Calculate 3D grid size from a packed 3D LUT buffer |
| 42 | +unsigned long getBufferLut3DGridSize(const pybind11::buffer_info & info); |
| 43 | + |
| 44 | +// Throw if vector size is not divisible by channel count |
| 45 | +void checkVectorDivisible(const std::vector<float> & pixel, size_t numChannels); |
| 46 | + |
| 47 | +// Throw if array is not C-contiguous |
| 48 | +void checkCContiguousArray(const pybind11::buffer_info & info); |
| 49 | + |
| 50 | +} // namespace OCIO_NAMESPACE |
| 51 | + |
| 52 | +#endif // INCLUDED_OCIO_PYBUFFERUTILS_H |
0 commit comments