Debian Codegraph @

src/python/PyImath/PyImathColor4ArrayImpl.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 _PyImathColor4ArrayImpl_h_
9 #define _PyImathColor4ArrayImpl_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 Color4Array_get(FixedArray<IMATH_NAMESPACE::Color4<T> > &ca)
36 {
37 return FixedArray<T>(&(ca.unchecked_index(0)[index]),
38 ca.len(),4*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::Color4<T> > >
44 register_Color4Array()
45 {
46 class_<FixedArray<IMATH_NAMESPACE::Color4<T> > > color4Array_class = FixedArray<IMATH_NAMESPACE::Color4<T> >::register_("Fixed length array of IMATH_NAMESPACE::Color4");
47 color4Array_class
48 .add_property("r",&Color4Array_get<T,0>)
49 .add_property("g",&Color4Array_get<T,1>)
50 .add_property("b",&Color4Array_get<T,2>)
51 .add_property("a",&Color4Array_get<T,3>)
52 ;
53
54 return color4Array_class;
55 }
56
57 } // namespace PyImath
58
59 #endif // _PyImathColor4ArrayImpl_h_