Debian Codegraph @

src/python/PyImath/PyImathColor3ArrayImpl.h

raw
1 //
2 // SPDX-License-Identifier: BSD-3-Clause
3 // Copyright Contributors to the OpenEXR Project.
4 //
5
6 // clang-format off
7
8 #ifndef _PyImathColor3ArrayImpl_h_
9 #define _PyImathColor3ArrayImpl_h_
10
11 //
12 // This .C file was turned into a header file so that instantiations
13 // of the various V3* types can be spread across multiple files in
14 // order to work around MSVC limitations.
15 //
16
17 #include <Python.h>
18 #define BOOST_BIND_GLOBAL_PLACEHOLDERS
19 #include <boost/python.hpp>
20 #include <boost/python/make_constructor.hpp>
21 #include <boost/format.hpp>
22 #include "PyImath.h"
23 #include "PyImathMathExc.h"
24 #include "PyImathDecorators.h"
25
26 namespace PyImath {
27 using namespace boost::python;
28 using namespace IMATH_NAMESPACE;
29
30 // XXX fixme - template this
31 // really this should get generated automatically...
32
33 template <class T,int index>
34 static FixedArray<T>
35 Color3Array_get(FixedArray<IMATH_NAMESPACE::Color3<T> > &ca)
36 {
37 return FixedArray<T>(&(ca.unchecked_index(0)[index]),
38 ca.len(),3*ca.stride(),ca.handle(),ca.writable());
39 }
40
41 // Currently we are only exposing the RGBA components.
42 template <class T>
43 class_<FixedArray<IMATH_NAMESPACE::Color3<T> > >
44 register_Color3Array()
45 {
46 class_<FixedArray<IMATH_NAMESPACE::Color3<T> > > color3Array_class = FixedArray<IMATH_NAMESPACE::Color3<T> >::register_("Fixed length array of Imath::Color3");
47 color3Array_class
48 .add_property("r",&Color3Array_get<T,0>)
49 .add_property("g",&Color3Array_get<T,1>)
50 .add_property("b",&Color3Array_get<T,2>)
51 ;
52
53 return color3Array_class;
54 }
55
56 } // namespace PyImath
57
58 #endif // _PyImathColor3ArrayImpl_h_