itom  4.1.0
pythonRgba.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2020, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom.
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  itom is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17  General Public Licence for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with itom. If not, see <http://www.gnu.org/licenses/>.
21 *********************************************************************** */
22 
23 #ifndef PYTHONRGBA
24 #define PYTHONRGBA
25 
26 /* includes */
27 #ifndef Q_MOC_RUN
28  #define PY_ARRAY_UNIQUE_SYMBOL itom_ARRAY_API //see numpy help ::array api :: Miscellaneous :: Importing the api (this line must bebefore include global.h)
29  #define NO_IMPORT_ARRAY
30  //python
31  // see http://vtk.org/gitweb?p=VTK.git;a=commitdiff;h=7f3f750596a105d48ea84ebfe1b1c4ca03e0bab3
32  #if (defined _DEBUG) && (defined WIN32)
33  #undef _DEBUG
34  #include "python/pythonWrapper.h"
35  #define _DEBUG
36  #else
37  #include "python/pythonWrapper.h"
38  #endif
39 #endif
40 
41 #include "../../common/typeDefs.h"
42 #include "../../common/color.h"
43 #include "structmember.h"
44 #include <qobject.h>
45 
46 namespace ito
47 {
49  {
50 
51  public:
52 
53  //-------------------------------------------------------------------------------------------------
54  // typedefs
55  //-------------------------------------------------------------------------------------------------
56  typedef struct
57  {
58  PyObject_HEAD
59  ito::Rgba32 rgba;
60  }
61  PyRgba;
62 
63 
64  #define PyRgba_Check(op) PyObject_TypeCheck(op, &ito::PythonRgba::PyRgbaType)
65 
66 
67  //-------------------------------------------------------------------------------------------------
68  // constructor, deconstructor, alloc, dellaoc
69  //-------------------------------------------------------------------------------------------------
70 
71  static void PyRgba_dealloc(PyRgba *self);
72  static PyObject *PyRgba_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
73  static int PyRgba_init(PyRgba *self, PyObject *args, PyObject *kwds);
74 
75  static PyRgba* createEmptyPyRgba();
76  static bool checkPyRgba(int number, PyObject* rgba1 = NULL, PyObject* rgba2 = NULL, PyObject* rgba3 = NULL);
77 
78 
79  //-------------------------------------------------------------------------------------------------
80  // general members
81  //-------------------------------------------------------------------------------------------------
82  static PyObject *PyRgba_name(PyRgba *self);
83 
84  static PyObject* PyRgba_repr(PyRgba *self);
85 
86  static PyObject *PyRgba_toGray(PyRgba *self);
87 
88  static PyObject *PyRgba_toColor(PyRgba *self);
89 
90  static PyObject* PyRgba_RichCompare(PyRgba *self, PyObject *other, int cmp_op);
91 
92  static PyGetSetDef PyRgba_getseters[];
93 
94  static PyObject* PyRgba_getValue(PyRgba *self, void *closure);
95  static int PyRgba_setValue(PyRgba *self, PyObject *value, void *closure);
96 
97  static PyObject* PyRgba_Reduce(PyRgba *self, PyObject *args);
98  static PyObject* PyRgba_SetState(PyRgba *self, PyObject *args);
99 
100  //-------------------------------------------------------------------------------------------------
101  // number protocol
102  //
103  // python note: Binary and ternary functions must check the type of all their operands, and implement
104  // the necessary conversions (at least one of the operands is an instance of the defined type).
105  // If the operation is not defined for the given operands, binary and ternary functions must return
106  // Py_NotImplemented, if another error occurred they must return NULL and set an exception.
107  //-------------------------------------------------------------------------------------------------
108  static PyObject* PyRgba_nbAdd(PyObject* o1, PyObject* o2);
109  static PyObject* PyRgba_nbSubtract(PyObject* o1, PyObject* o2);
110  static PyObject* PyRgba_nbMultiply(PyObject* o1, PyObject* o2);
111  static PyObject* PyRgba_nbPositive(PyObject* o1);
112  static PyObject* PyRgba_nbAbsolute(PyObject* o1);
113  static PyObject* PyRgba_nbInvert(PyObject* o1);
114  static PyObject* PyRgba_nbLshift(PyObject* o1, PyObject* o2);
115  static PyObject* PyRgba_nbRshift(PyObject* o1, PyObject* o2);
116  static PyObject* PyRgba_nbAnd(PyObject* o1, PyObject* o2);
117  static PyObject* PyRgba_nbXor(PyObject* o1, PyObject* o2);
118  static PyObject* PyRgba_nbOr(PyObject* o1, PyObject* o2);
119 
120  static PyObject* PyRgba_nbInplaceAdd(PyObject* o1, PyObject* o2);
121  static PyObject* PyRgba_nbInplaceSubtract(PyObject* o1, PyObject* o2);
122  static PyObject* PyRgba_nbInplaceMultiply(PyObject* o1, PyObject* o2);
123  static PyObject* PyRgba_nbInplaceLshift(PyObject* o1, PyObject* o2);
124  static PyObject* PyRgba_nbInplaceRshift(PyObject* o1, PyObject* o2);
125  static PyObject* PyRgba_nbInplaceAnd(PyObject* o1, PyObject* o2);
126  static PyObject* PyRgba_nbInplaceXor(PyObject* o1, PyObject* o2);
127  static PyObject* PyRgba_nbInplaceOr(PyObject* o1, PyObject* o2);
128 
129 
130  //-------------------------------------------------------------------------------------------------
131  // type structures
132  //-------------------------------------------------------------------------------------------------
133  static PyMemberDef PyRgba_members[];
134  static PyMethodDef PyRgba_methods[];
135  static PyTypeObject PyRgbaType;
136  static PyModuleDef PyRgbaModule;
137 
138  static PyNumberMethods PyRgba_numberProtocol;
139 
140  //-------------------------------------------------------------------------------------------------
141  // helper methods
142  //-------------------------------------------------------------------------------------------------
143 
144  //-------------------------------------------------------------------------------------------------
145  // static type methods
146  //-------------------------------------------------------------------------------------------------
147 
148 
149 };
150 
151 } //end namespace ito
152 
153 #endif
Definition: apiFunctionsGraph.cpp:39
Definition: pythonRgba.h:56
This class implements basic functionality for color handling in itom. This class implements ARGB32 i...
Definition: color.h:46
Definition: pythonRgba.h:48