Blender  V3.3
mathutils_Color.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include <Python.h>
8 
9 #include "mathutils.h"
10 
11 #include "BLI_math.h"
12 #include "BLI_utildefines.h"
13 
14 #include "../generic/py_capi_utils.h"
15 #include "../generic/python_utildefines.h"
16 
17 #include "IMB_colormanagement.h"
18 
19 #ifndef MATH_STANDALONE
20 # include "BLI_dynstr.h"
21 #endif
22 
23 #define COLOR_SIZE 3
24 
25 /* -------------------------------------------------------------------- */
32 static PyObject *Color_to_tuple_ex(ColorObject *self, int ndigits)
33 {
34  PyObject *ret;
35  int i;
36 
37  ret = PyTuple_New(COLOR_SIZE);
38 
39  if (ndigits >= 0) {
40  for (i = 0; i < COLOR_SIZE; i++) {
41  PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(double_round((double)self->col[i], ndigits)));
42  }
43  }
44  else {
45  for (i = 0; i < COLOR_SIZE; i++) {
46  PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(self->col[i]));
47  }
48  }
49 
50  return ret;
51 }
52 
55 /* -------------------------------------------------------------------- */
59 static PyObject *Color_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
60 {
61  float col[3] = {0.0f, 0.0f, 0.0f};
62 
63  if (kwds && PyDict_Size(kwds)) {
64  PyErr_SetString(PyExc_TypeError,
65  "mathutils.Color(): "
66  "takes no keyword args");
67  return NULL;
68  }
69 
70  switch (PyTuple_GET_SIZE(args)) {
71  case 0:
72  break;
73  case 1:
75  col, COLOR_SIZE, COLOR_SIZE, PyTuple_GET_ITEM(args, 0), "mathutils.Color()")) ==
76  -1) {
77  return NULL;
78  }
79  break;
80  default:
81  PyErr_SetString(PyExc_TypeError,
82  "mathutils.Color(): "
83  "more than a single arg given");
84  return NULL;
85  }
86  return Color_CreatePyObject(col, type);
87 }
88 
91 /* -------------------------------------------------------------------- */
95 PyDoc_STRVAR(Color_from_scene_linear_to_srgb_doc,
96  ".. function:: from_scene_linear_to_srgb()\n"
97  "\n"
98  " Convert from scene linear to sRGB color space.\n"
99  "\n"
100  " :return: A color in sRGB color space.\n"
101  " :rtype: :class:`Color`\n");
103 {
104  float col[3];
106  return Color_CreatePyObject(col, Py_TYPE(self));
107 }
108 
109 PyDoc_STRVAR(Color_from_srgb_to_scene_linear_doc,
110  ".. function:: from_srgb_to_scene_linear()\n"
111  "\n"
112  " Convert from sRGB to scene linear color space.\n"
113  "\n"
114  " :return: A color in scene linear color space.\n"
115  " :rtype: :class:`Color`\n");
117 {
118  float col[3];
120  return Color_CreatePyObject(col, Py_TYPE(self));
121 }
122 
123 PyDoc_STRVAR(Color_from_scene_linear_to_xyz_d65_doc,
124  ".. function:: from_scene_linear_to_xyz_d65()\n"
125  "\n"
126  " Convert from scene linear to CIE XYZ (Illuminant D65) color space.\n"
127  "\n"
128  " :return: A color in XYZ color space.\n"
129  " :rtype: :class:`Color`\n");
131 {
132  float col[3];
134  return Color_CreatePyObject(col, Py_TYPE(self));
135 }
136 
137 PyDoc_STRVAR(Color_from_xyz_d65_to_scene_linear_doc,
138  ".. function:: from_xyz_d65_to_scene_linear()\n"
139  "\n"
140  " Convert from CIE XYZ (Illuminant D65) to scene linear color space.\n"
141  "\n"
142  " :return: A color in scene linear color space.\n"
143  " :rtype: :class:`Color`\n");
145 {
146  float col[3];
148  return Color_CreatePyObject(col, Py_TYPE(self));
149 }
150 
151 PyDoc_STRVAR(Color_from_scene_linear_to_aces_doc,
152  ".. function:: from_scene_linear_to_aces()\n"
153  "\n"
154  " Convert from scene linear to ACES2065-1 linear color space.\n"
155  "\n"
156  " :return: A color in ACES2065-1 linear color space.\n"
157  " :rtype: :class:`Color`\n");
159 {
160  float col[3];
162  return Color_CreatePyObject(col, Py_TYPE(self));
163 }
164 
165 PyDoc_STRVAR(Color_from_aces_to_scene_linear_doc,
166  ".. function:: from_aces_to_scene_linear()\n"
167  "\n"
168  " Convert from ACES2065-1 linear to scene linear color space.\n"
169  "\n"
170  " :return: A color in scene linear color space.\n"
171  " :rtype: :class:`Color`\n");
173 {
174  float col[3];
176  return Color_CreatePyObject(col, Py_TYPE(self));
177 }
178 
179 PyDoc_STRVAR(Color_from_scene_linear_to_rec709_linear_doc,
180  ".. function:: from_scene_linear_to_rec709_linear()\n"
181  "\n"
182  " Convert from scene linear to Rec.709 linear color space.\n"
183  "\n"
184  " :return: A color in Rec.709 linear color space.\n"
185  " :rtype: :class:`Color`\n");
187 {
188  float col[3];
190  return Color_CreatePyObject(col, Py_TYPE(self));
191 }
192 
193 PyDoc_STRVAR(Color_from_rec709_linear_to_scene_linear_doc,
194  ".. function:: from_rec709_linear_to_scene_linear()\n"
195  "\n"
196  " Convert from Rec.709 linear color space to scene linear color space.\n"
197  "\n"
198  " :return: A color in scene linear color space.\n"
199  " :rtype: :class:`Color`\n");
201 {
202  float col[3];
204  return Color_CreatePyObject(col, Py_TYPE(self));
205 }
206 
209 /* -------------------------------------------------------------------- */
213 PyDoc_STRVAR(Color_copy_doc,
214  ".. function:: copy()\n"
215  "\n"
216  " Returns a copy of this color.\n"
217  "\n"
218  " :return: A copy of the color.\n"
219  " :rtype: :class:`Color`\n"
220  "\n"
221  " .. note:: use this to get a copy of a wrapped color with\n"
222  " no reference to the original data.\n");
223 static PyObject *Color_copy(ColorObject *self)
224 {
225  if (BaseMath_ReadCallback(self) == -1) {
226  return NULL;
227  }
228 
229  return Color_CreatePyObject(self->col, Py_TYPE(self));
230 }
231 static PyObject *Color_deepcopy(ColorObject *self, PyObject *args)
232 {
233  if (!PyC_CheckArgs_DeepCopy(args)) {
234  return NULL;
235  }
236  return Color_copy(self);
237 }
238 
241 /* -------------------------------------------------------------------- */
245 static PyObject *Color_repr(ColorObject *self)
246 {
247  PyObject *ret, *tuple;
248 
249  if (BaseMath_ReadCallback(self) == -1) {
250  return NULL;
251  }
252 
253  tuple = Color_to_tuple_ex(self, -1);
254 
255  ret = PyUnicode_FromFormat("Color(%R)", tuple);
256 
257  Py_DECREF(tuple);
258  return ret;
259 }
260 
261 #ifndef MATH_STANDALONE
262 static PyObject *Color_str(ColorObject *self)
263 {
264  DynStr *ds;
265 
266  if (BaseMath_ReadCallback(self) == -1) {
267  return NULL;
268  }
269 
270  ds = BLI_dynstr_new();
271 
273  ds, "<Color (r=%.4f, g=%.4f, b=%.4f)>", self->col[0], self->col[1], self->col[2]);
274 
275  return mathutils_dynstr_to_py(ds); /* frees ds */
276 }
277 #endif
278 
281 /* -------------------------------------------------------------------- */
285 static PyObject *Color_richcmpr(PyObject *a, PyObject *b, int op)
286 {
287  PyObject *res;
288  int ok = -1; /* zero is true */
289 
291  ColorObject *colA = (ColorObject *)a;
292  ColorObject *colB = (ColorObject *)b;
293 
294  if (BaseMath_ReadCallback(colA) == -1 || BaseMath_ReadCallback(colB) == -1) {
295  return NULL;
296  }
297 
298  ok = EXPP_VectorsAreEqual(colA->col, colB->col, COLOR_SIZE, 1) ? 0 : -1;
299  }
300 
301  switch (op) {
302  case Py_NE:
303  ok = !ok;
305  case Py_EQ:
306  res = ok ? Py_False : Py_True;
307  break;
308 
309  case Py_LT:
310  case Py_LE:
311  case Py_GT:
312  case Py_GE:
313  res = Py_NotImplemented;
314  break;
315  default:
316  PyErr_BadArgument();
317  return NULL;
318  }
319 
320  return Py_INCREF_RET(res);
321 }
322 
325 /* -------------------------------------------------------------------- */
329 static Py_hash_t Color_hash(ColorObject *self)
330 {
331  if (BaseMath_ReadCallback(self) == -1) {
332  return -1;
333  }
334 
335  if (BaseMathObject_Prepare_ForHash(self) == -1) {
336  return -1;
337  }
338 
339  return mathutils_array_hash(self->col, COLOR_SIZE);
340 }
341 
344 /* -------------------------------------------------------------------- */
349 static int Color_len(ColorObject *UNUSED(self))
350 {
351  return COLOR_SIZE;
352 }
353 
355 static PyObject *Color_item(ColorObject *self, int i)
356 {
357  if (i < 0) {
358  i = COLOR_SIZE - i;
359  }
360 
361  if (i < 0 || i >= COLOR_SIZE) {
362  PyErr_SetString(PyExc_IndexError,
363  "color[item]: "
364  "array index out of range");
365  return NULL;
366  }
367 
368  if (BaseMath_ReadIndexCallback(self, i) == -1) {
369  return NULL;
370  }
371 
372  return PyFloat_FromDouble(self->col[i]);
373 }
374 
376 static int Color_ass_item(ColorObject *self, int i, PyObject *value)
377 {
378  float f;
379 
380  if (BaseMath_Prepare_ForWrite(self) == -1) {
381  return -1;
382  }
383 
384  f = PyFloat_AsDouble(value);
385  if (f == -1 && PyErr_Occurred()) { /* parsed item not a number */
386  PyErr_SetString(PyExc_TypeError,
387  "color[item] = x: "
388  "assigned value not a number");
389  return -1;
390  }
391 
392  if (i < 0) {
393  i = COLOR_SIZE - i;
394  }
395 
396  if (i < 0 || i >= COLOR_SIZE) {
397  PyErr_SetString(PyExc_IndexError,
398  "color[item] = x: "
399  "array assignment index out of range");
400  return -1;
401  }
402 
403  self->col[i] = f;
404 
405  if (BaseMath_WriteIndexCallback(self, i) == -1) {
406  return -1;
407  }
408 
409  return 0;
410 }
411 
413 static PyObject *Color_slice(ColorObject *self, int begin, int end)
414 {
415  PyObject *tuple;
416  int count;
417 
418  if (BaseMath_ReadCallback(self) == -1) {
419  return NULL;
420  }
421 
422  CLAMP(begin, 0, COLOR_SIZE);
423  if (end < 0) {
424  end = (COLOR_SIZE + 1) + end;
425  }
426  CLAMP(end, 0, COLOR_SIZE);
427  begin = MIN2(begin, end);
428 
429  tuple = PyTuple_New(end - begin);
430  for (count = begin; count < end; count++) {
431  PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(self->col[count]));
432  }
433 
434  return tuple;
435 }
436 
438 static int Color_ass_slice(ColorObject *self, int begin, int end, PyObject *seq)
439 {
440  int i, size;
441  float col[COLOR_SIZE];
442 
443  if (BaseMath_ReadCallback_ForWrite(self) == -1) {
444  return -1;
445  }
446 
447  CLAMP(begin, 0, COLOR_SIZE);
448  if (end < 0) {
449  end = (COLOR_SIZE + 1) + end;
450  }
451  CLAMP(end, 0, COLOR_SIZE);
452  begin = MIN2(begin, end);
453 
454  if ((size = mathutils_array_parse(col, 0, COLOR_SIZE, seq, "mathutils.Color[begin:end] = []")) ==
455  -1) {
456  return -1;
457  }
458 
459  if (size != (end - begin)) {
460  PyErr_SetString(PyExc_ValueError,
461  "color[begin:end] = []: "
462  "size mismatch in slice assignment");
463  return -1;
464  }
465 
466  for (i = 0; i < COLOR_SIZE; i++) {
467  self->col[begin + i] = col[i];
468  }
469 
471  return 0;
472 }
473 
475 static PyObject *Color_subscript(ColorObject *self, PyObject *item)
476 {
477  if (PyIndex_Check(item)) {
478  Py_ssize_t i;
479  i = PyNumber_AsSsize_t(item, PyExc_IndexError);
480  if (i == -1 && PyErr_Occurred()) {
481  return NULL;
482  }
483  if (i < 0) {
484  i += COLOR_SIZE;
485  }
486  return Color_item(self, i);
487  }
488  if (PySlice_Check(item)) {
489  Py_ssize_t start, stop, step, slicelength;
490 
491  if (PySlice_GetIndicesEx(item, COLOR_SIZE, &start, &stop, &step, &slicelength) < 0) {
492  return NULL;
493  }
494 
495  if (slicelength <= 0) {
496  return PyTuple_New(0);
497  }
498  if (step == 1) {
499  return Color_slice(self, start, stop);
500  }
501 
502  PyErr_SetString(PyExc_IndexError, "slice steps not supported with color");
503  return NULL;
504  }
505 
506  PyErr_Format(
507  PyExc_TypeError, "color indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
508  return NULL;
509 }
510 
512 static int Color_ass_subscript(ColorObject *self, PyObject *item, PyObject *value)
513 {
514  if (PyIndex_Check(item)) {
515  Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
516  if (i == -1 && PyErr_Occurred()) {
517  return -1;
518  }
519  if (i < 0) {
520  i += COLOR_SIZE;
521  }
522  return Color_ass_item(self, i, value);
523  }
524  if (PySlice_Check(item)) {
525  Py_ssize_t start, stop, step, slicelength;
526 
527  if (PySlice_GetIndicesEx(item, COLOR_SIZE, &start, &stop, &step, &slicelength) < 0) {
528  return -1;
529  }
530 
531  if (step == 1) {
532  return Color_ass_slice(self, start, stop, value);
533  }
534 
535  PyErr_SetString(PyExc_IndexError, "slice steps not supported with color");
536  return -1;
537  }
538 
539  PyErr_Format(
540  PyExc_TypeError, "color indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
541  return -1;
542 }
543 
546 /* -------------------------------------------------------------------- */
551 static PyObject *Color_add(PyObject *v1, PyObject *v2)
552 {
553  ColorObject *color1 = NULL, *color2 = NULL;
554  float col[COLOR_SIZE];
555 
557  PyErr_Format(PyExc_TypeError,
558  "Color addition: (%s + %s) "
559  "invalid type for this operation",
560  Py_TYPE(v1)->tp_name,
561  Py_TYPE(v2)->tp_name);
562  return NULL;
563  }
564  color1 = (ColorObject *)v1;
565  color2 = (ColorObject *)v2;
566 
567  if (BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1) {
568  return NULL;
569  }
570 
571  add_vn_vnvn(col, color1->col, color2->col, COLOR_SIZE);
572 
573  return Color_CreatePyObject(col, Py_TYPE(v1));
574 }
575 
577 static PyObject *Color_iadd(PyObject *v1, PyObject *v2)
578 {
579  ColorObject *color1 = NULL, *color2 = NULL;
580 
582  PyErr_Format(PyExc_TypeError,
583  "Color addition: (%s += %s) "
584  "invalid type for this operation",
585  Py_TYPE(v1)->tp_name,
586  Py_TYPE(v2)->tp_name);
587  return NULL;
588  }
589  color1 = (ColorObject *)v1;
590  color2 = (ColorObject *)v2;
591 
592  if (BaseMath_ReadCallback_ForWrite(color1) == -1 || BaseMath_ReadCallback(color2) == -1) {
593  return NULL;
594  }
595 
596  add_vn_vn(color1->col, color2->col, COLOR_SIZE);
597 
598  (void)BaseMath_WriteCallback(color1);
599  Py_INCREF(v1);
600  return v1;
601 }
602 
604 static PyObject *Color_sub(PyObject *v1, PyObject *v2)
605 {
606  ColorObject *color1 = NULL, *color2 = NULL;
607  float col[COLOR_SIZE];
608 
610  PyErr_Format(PyExc_TypeError,
611  "Color subtraction: (%s - %s) "
612  "invalid type for this operation",
613  Py_TYPE(v1)->tp_name,
614  Py_TYPE(v2)->tp_name);
615  return NULL;
616  }
617  color1 = (ColorObject *)v1;
618  color2 = (ColorObject *)v2;
619 
620  if (BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1) {
621  return NULL;
622  }
623 
624  sub_vn_vnvn(col, color1->col, color2->col, COLOR_SIZE);
625 
626  return Color_CreatePyObject(col, Py_TYPE(v1));
627 }
628 
630 static PyObject *Color_isub(PyObject *v1, PyObject *v2)
631 {
632  ColorObject *color1 = NULL, *color2 = NULL;
633 
635  PyErr_Format(PyExc_TypeError,
636  "Color subtraction: (%s -= %s) "
637  "invalid type for this operation",
638  Py_TYPE(v1)->tp_name,
639  Py_TYPE(v2)->tp_name);
640  return NULL;
641  }
642  color1 = (ColorObject *)v1;
643  color2 = (ColorObject *)v2;
644 
645  if (BaseMath_ReadCallback_ForWrite(color1) == -1 || BaseMath_ReadCallback(color2) == -1) {
646  return NULL;
647  }
648 
649  sub_vn_vn(color1->col, color2->col, COLOR_SIZE);
650 
651  (void)BaseMath_WriteCallback(color1);
652  Py_INCREF(v1);
653  return v1;
654 }
655 
656 static PyObject *color_mul_float(ColorObject *color, const float scalar)
657 {
658  float tcol[COLOR_SIZE];
659  mul_vn_vn_fl(tcol, color->col, COLOR_SIZE, scalar);
660  return Color_CreatePyObject(tcol, Py_TYPE(color));
661 }
662 
664 static PyObject *Color_mul(PyObject *v1, PyObject *v2)
665 {
666  ColorObject *color1 = NULL, *color2 = NULL;
667  float scalar;
668 
669  if (ColorObject_Check(v1)) {
670  color1 = (ColorObject *)v1;
671  if (BaseMath_ReadCallback(color1) == -1) {
672  return NULL;
673  }
674  }
675  if (ColorObject_Check(v2)) {
676  color2 = (ColorObject *)v2;
677  if (BaseMath_ReadCallback(color2) == -1) {
678  return NULL;
679  }
680  }
681 
682  /* make sure v1 is always the vector */
683  if (color1 && color2) {
684  /* col * col, don't support yet! */
685  }
686  else if (color1) {
687  if (((scalar = PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred()) == 0) { /* COLOR * FLOAT */
688  return color_mul_float(color1, scalar);
689  }
690  }
691  else if (color2) {
692  if (((scalar = PyFloat_AsDouble(v1)) == -1.0f && PyErr_Occurred()) == 0) { /* FLOAT * COLOR */
693  return color_mul_float(color2, scalar);
694  }
695  }
696  else {
697  BLI_assert_msg(0, "internal error");
698  }
699 
700  PyErr_Format(PyExc_TypeError,
701  "Color multiplication: not supported between "
702  "'%.200s' and '%.200s' types",
703  Py_TYPE(v1)->tp_name,
704  Py_TYPE(v2)->tp_name);
705  return NULL;
706 }
707 
709 static PyObject *Color_div(PyObject *v1, PyObject *v2)
710 {
711  ColorObject *color1 = NULL;
712  float scalar;
713 
714  if (ColorObject_Check(v1)) {
715  color1 = (ColorObject *)v1;
716  if (BaseMath_ReadCallback(color1) == -1) {
717  return NULL;
718  }
719  }
720  else {
721  PyErr_SetString(PyExc_TypeError, "Color division not supported in this order");
722  return NULL;
723  }
724 
725  /* make sure v1 is always the vector */
726  if (((scalar = PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred()) == 0) { /* COLOR * FLOAT */
727  if (scalar == 0.0f) {
728  PyErr_SetString(PyExc_ZeroDivisionError, "Color division: divide by zero error");
729  return NULL;
730  }
731  return color_mul_float(color1, 1.0f / scalar);
732  }
733 
734  PyErr_Format(PyExc_TypeError,
735  "Color multiplication: not supported between "
736  "'%.200s' and '%.200s' types",
737  Py_TYPE(v1)->tp_name,
738  Py_TYPE(v2)->tp_name);
739  return NULL;
740 }
741 
743 static PyObject *Color_imul(PyObject *v1, PyObject *v2)
744 {
746  float scalar;
747 
749  return NULL;
750  }
751 
752  /* only support color *= float */
753  if (((scalar = PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred()) == 0) { /* COLOR *= FLOAT */
754  mul_vn_fl(color->col, COLOR_SIZE, scalar);
755  }
756  else {
757  PyErr_Format(PyExc_TypeError,
758  "Color multiplication: (%s *= %s) "
759  "invalid type for this operation",
760  Py_TYPE(v1)->tp_name,
761  Py_TYPE(v2)->tp_name);
762  return NULL;
763  }
764 
766  Py_INCREF(v1);
767  return v1;
768 }
769 
771 static PyObject *Color_idiv(PyObject *v1, PyObject *v2)
772 {
774  float scalar;
775 
777  return NULL;
778  }
779 
780  /* only support color /= float */
781  if (((scalar = PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred()) == 0) { /* COLOR /= FLOAT */
782  if (scalar == 0.0f) {
783  PyErr_SetString(PyExc_ZeroDivisionError, "Color division: divide by zero error");
784  return NULL;
785  }
786 
787  mul_vn_fl(color->col, COLOR_SIZE, 1.0f / scalar);
788  }
789  else {
790  PyErr_Format(PyExc_TypeError,
791  "Color division: (%s /= %s) "
792  "invalid type for this operation",
793  Py_TYPE(v1)->tp_name,
794  Py_TYPE(v2)->tp_name);
795  return NULL;
796  }
797 
799  Py_INCREF(v1);
800  return v1;
801 }
802 
804 static PyObject *Color_neg(ColorObject *self)
805 {
806  float tcol[COLOR_SIZE];
807 
808  if (BaseMath_ReadCallback(self) == -1) {
809  return NULL;
810  }
811 
812  negate_vn_vn(tcol, self->col, COLOR_SIZE);
813  return Color_CreatePyObject(tcol, Py_TYPE(self));
814 }
815 
818 /* -------------------------------------------------------------------- */
822 static PySequenceMethods Color_SeqMethods = {
823  (lenfunc)Color_len, /*sq_length*/
824  (binaryfunc)NULL, /*sq_concat*/
825  (ssizeargfunc)NULL, /*sq_repeat*/
826  (ssizeargfunc)Color_item, /*sq_item*/
827  NULL, /*sq_slice(DEPRECATED)*/
828  (ssizeobjargproc)Color_ass_item, /*sq_ass_item*/
829  NULL, /*sq_ass_slice(DEPRECATED)*/
830  (objobjproc)NULL, /*sq_contains*/
831  (binaryfunc)NULL, /*sq_inplace_concat*/
832  (ssizeargfunc)NULL, /*sq_inplace_repeat*/
833 };
834 
835 static PyMappingMethods Color_AsMapping = {
836  (lenfunc)Color_len,
837  (binaryfunc)Color_subscript,
838  (objobjargproc)Color_ass_subscript,
839 };
840 
841 static PyNumberMethods Color_NumMethods = {
842  (binaryfunc)Color_add, /*nb_add*/
843  (binaryfunc)Color_sub, /*nb_subtract*/
844  (binaryfunc)Color_mul, /*nb_multiply*/
845  NULL, /*nb_remainder*/
846  NULL, /*nb_divmod*/
847  NULL, /*nb_power*/
848  (unaryfunc)Color_neg, /*nb_negative*/
849  (unaryfunc)Color_copy, /*tp_positive*/
850  (unaryfunc)NULL, /*tp_absolute*/
851  (inquiry)NULL, /*tp_bool*/
852  (unaryfunc)NULL, /*nb_invert*/
853  NULL, /*nb_lshift*/
854  (binaryfunc)NULL, /*nb_rshift*/
855  NULL, /*nb_and*/
856  NULL, /*nb_xor*/
857  NULL, /*nb_or*/
858  NULL, /*nb_int*/
859  NULL, /*nb_reserved*/
860  NULL, /*nb_float*/
861  Color_iadd, /*nb_inplace_add*/
862  Color_isub, /*nb_inplace_subtract*/
863  Color_imul, /*nb_inplace_multiply*/
864  NULL, /*nb_inplace_remainder*/
865  NULL, /*nb_inplace_power*/
866  NULL, /*nb_inplace_lshift*/
867  NULL, /*nb_inplace_rshift*/
868  NULL, /*nb_inplace_and*/
869  NULL, /*nb_inplace_xor*/
870  NULL, /*nb_inplace_or*/
871  NULL, /*nb_floor_divide*/
872  Color_div, /*nb_true_divide*/
873  NULL, /*nb_inplace_floor_divide*/
874  Color_idiv, /*nb_inplace_true_divide*/
875  NULL, /*nb_index*/
876 };
877 
880 /* -------------------------------------------------------------------- */
884 /* Color channel (RGB): `color.r/g/b`. */
885 
886 PyDoc_STRVAR(Color_channel_r_doc, "Red color channel.\n\n:type: float");
887 PyDoc_STRVAR(Color_channel_g_doc, "Green color channel.\n\n:type: float");
888 PyDoc_STRVAR(Color_channel_b_doc, "Blue color channel.\n\n:type: float");
889 
890 static PyObject *Color_channel_get(ColorObject *self, void *type)
891 {
892  return Color_item(self, POINTER_AS_INT(type));
893 }
894 
895 static int Color_channel_set(ColorObject *self, PyObject *value, void *type)
896 {
897  return Color_ass_item(self, POINTER_AS_INT(type), value);
898 }
899 
900 /* Color channel (HSV): `color.h/s/v`. */
901 
902 PyDoc_STRVAR(Color_channel_hsv_h_doc, "HSV Hue component in [0, 1].\n\n:type: float");
903 PyDoc_STRVAR(Color_channel_hsv_s_doc, "HSV Saturation component in [0, 1].\n\n:type: float");
904 PyDoc_STRVAR(Color_channel_hsv_v_doc, "HSV Value component in [0, 1].\n\n:type: float");
905 
906 static PyObject *Color_channel_hsv_get(ColorObject *self, void *type)
907 {
908  float hsv[3];
909  const int i = POINTER_AS_INT(type);
910 
911  if (BaseMath_ReadCallback(self) == -1) {
912  return NULL;
913  }
914 
915  rgb_to_hsv(self->col[0], self->col[1], self->col[2], &(hsv[0]), &(hsv[1]), &(hsv[2]));
916 
917  return PyFloat_FromDouble(hsv[i]);
918 }
919 
920 static int Color_channel_hsv_set(ColorObject *self, PyObject *value, void *type)
921 {
922  float hsv[3];
923  const int i = POINTER_AS_INT(type);
924  float f = PyFloat_AsDouble(value);
925 
926  if (f == -1 && PyErr_Occurred()) {
927  PyErr_SetString(PyExc_TypeError,
928  "color.h/s/v = value: "
929  "assigned value not a number");
930  return -1;
931  }
932 
933  if (BaseMath_ReadCallback_ForWrite(self) == -1) {
934  return -1;
935  }
936 
937  rgb_to_hsv_v(self->col, hsv);
938  CLAMP(f, 0.0f, 1.0f);
939  hsv[i] = f;
940  hsv_to_rgb_v(hsv, self->col);
941 
942  if (BaseMath_WriteCallback(self) == -1) {
943  return -1;
944  }
945 
946  return 0;
947 }
948 
949 PyDoc_STRVAR(Color_hsv_doc, "HSV Values in [0, 1].\n\n:type: float triplet");
951 static PyObject *Color_hsv_get(ColorObject *self, void *UNUSED(closure))
952 {
953  float hsv[3];
954  PyObject *ret;
955 
956  if (BaseMath_ReadCallback(self) == -1) {
957  return NULL;
958  }
959 
960  rgb_to_hsv(self->col[0], self->col[1], self->col[2], &(hsv[0]), &(hsv[1]), &(hsv[2]));
961 
962  ret = PyTuple_New(3);
964  ret, PyFloat_FromDouble(hsv[0]), PyFloat_FromDouble(hsv[1]), PyFloat_FromDouble(hsv[2]));
965  return ret;
966 }
967 
969 static int Color_hsv_set(ColorObject *self, PyObject *value, void *UNUSED(closure))
970 {
971  float hsv[3];
972 
973  if (mathutils_array_parse(hsv, 3, 3, value, "mathutils.Color.hsv = value") == -1) {
974  return -1;
975  }
976 
977  if (BaseMath_Prepare_ForWrite(self) == -1) {
978  return -1;
979  }
980 
981  clamp_v3(hsv, 0.0f, 1.0f);
982  hsv_to_rgb_v(hsv, self->col);
983 
984  if (BaseMath_WriteCallback(self) == -1) {
985  return -1;
986  }
987 
988  return 0;
989 }
990 
993 /* -------------------------------------------------------------------- */
997 static PyGetSetDef Color_getseters[] = {
998  {"r", (getter)Color_channel_get, (setter)Color_channel_set, Color_channel_r_doc, (void *)0},
999  {"g", (getter)Color_channel_get, (setter)Color_channel_set, Color_channel_g_doc, (void *)1},
1000  {"b", (getter)Color_channel_get, (setter)Color_channel_set, Color_channel_b_doc, (void *)2},
1001 
1002  {"h",
1003  (getter)Color_channel_hsv_get,
1004  (setter)Color_channel_hsv_set,
1005  Color_channel_hsv_h_doc,
1006  (void *)0},
1007  {"s",
1008  (getter)Color_channel_hsv_get,
1009  (setter)Color_channel_hsv_set,
1010  Color_channel_hsv_s_doc,
1011  (void *)1},
1012  {"v",
1013  (getter)Color_channel_hsv_get,
1014  (setter)Color_channel_hsv_set,
1015  Color_channel_hsv_v_doc,
1016  (void *)2},
1017 
1018  {"hsv", (getter)Color_hsv_get, (setter)Color_hsv_set, Color_hsv_doc, (void *)0},
1019 
1020  {"is_wrapped",
1022  (setter)NULL,
1024  NULL},
1025  {"is_frozen",
1027  (setter)NULL,
1029  NULL},
1030  {"is_valid",
1032  (setter)NULL,
1034  NULL},
1035  {"owner", (getter)BaseMathObject_owner_get, (setter)NULL, BaseMathObject_owner_doc, NULL},
1036  {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
1037 };
1038 
1041 /* -------------------------------------------------------------------- */
1045 static struct PyMethodDef Color_methods[] = {
1046  {"copy", (PyCFunction)Color_copy, METH_NOARGS, Color_copy_doc},
1047  {"__copy__", (PyCFunction)Color_copy, METH_NOARGS, Color_copy_doc},
1048  {"__deepcopy__", (PyCFunction)Color_deepcopy, METH_VARARGS, Color_copy_doc},
1049 
1050  /* base-math methods */
1051  {"freeze", (PyCFunction)BaseMathObject_freeze, METH_NOARGS, BaseMathObject_freeze_doc},
1052 
1053  /* Color-space methods. */
1054  {"from_scene_linear_to_srgb",
1055  (PyCFunction)Color_from_scene_linear_to_srgb,
1056  METH_NOARGS,
1057  Color_from_scene_linear_to_srgb_doc},
1058  {"from_srgb_to_scene_linear",
1059  (PyCFunction)Color_from_srgb_to_scene_linear,
1060  METH_NOARGS,
1061  Color_from_srgb_to_scene_linear_doc},
1062  {"from_scene_linear_to_xyz_d65",
1064  METH_NOARGS,
1065  Color_from_scene_linear_to_xyz_d65_doc},
1066  {"from_xyz_d65_to_scene_linear",
1068  METH_NOARGS,
1069  Color_from_xyz_d65_to_scene_linear_doc},
1070  {"from_scene_linear_to_aces",
1071  (PyCFunction)Color_from_scene_linear_to_aces,
1072  METH_NOARGS,
1073  Color_from_scene_linear_to_aces_doc},
1074  {"from_aces_to_scene_linear",
1075  (PyCFunction)Color_from_aces_to_scene_linear,
1076  METH_NOARGS,
1077  Color_from_aces_to_scene_linear_doc},
1078  {"from_scene_linear_to_rec709_linear",
1080  METH_NOARGS,
1081  Color_from_scene_linear_to_rec709_linear_doc},
1082  {"from_rec709_linear_to_scene_linear",
1084  METH_NOARGS,
1085  Color_from_rec709_linear_to_scene_linear_doc},
1086  {NULL, NULL, 0, NULL},
1087 };
1088 
1091 /* -------------------------------------------------------------------- */
1096  color_doc,
1097  ".. class:: Color(rgb)\n"
1098  "\n"
1099  " This object gives access to Colors in Blender.\n"
1100  "\n"
1101  " Most colors returned by Blender APIs are in scene linear color space, as defined by "
1102  " the OpenColorIO configuration. The notable exception is user interface theming colors, "
1103  " which are in sRGB color space.\n"
1104  "\n"
1105  " :param rgb: (r, g, b) color values\n"
1106  " :type rgb: 3d vector\n");
1107 PyTypeObject color_Type = {
1108  PyVarObject_HEAD_INIT(NULL, 0) "Color", /* tp_name */
1109  sizeof(ColorObject), /* tp_basicsize */
1110  0, /* tp_itemsize */
1111  (destructor)BaseMathObject_dealloc, /* tp_dealloc */
1112  (printfunc)NULL, /* tp_print */
1113  NULL, /* tp_getattr */
1114  NULL, /* tp_setattr */
1115  NULL, /* tp_compare */
1116  (reprfunc)Color_repr, /* tp_repr */
1117  &Color_NumMethods, /* tp_as_number */
1118  &Color_SeqMethods, /* tp_as_sequence */
1119  &Color_AsMapping, /* tp_as_mapping */
1120  (hashfunc)Color_hash, /* tp_hash */
1121  NULL, /* tp_call */
1122 #ifndef MATH_STANDALONE
1123  (reprfunc)Color_str, /* tp_str */
1124 #else
1125  NULL, /* tp_str */
1126 #endif
1127  NULL, /* tp_getattro */
1128  NULL, /* tp_setattro */
1129  NULL, /* tp_as_buffer */
1130  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */
1131  color_doc, /* tp_doc */
1132  (traverseproc)BaseMathObject_traverse, /* tp_traverse */
1133  (inquiry)BaseMathObject_clear, /* tp_clear */
1134  (richcmpfunc)Color_richcmpr, /* tp_richcompare */
1135  0, /* tp_weaklistoffset */
1136  NULL, /* tp_iter */
1137  NULL, /* tp_iternext */
1138  Color_methods, /* tp_methods */
1139  NULL, /* tp_members */
1140  Color_getseters, /* tp_getset */
1141  NULL, /* tp_base */
1142  NULL, /* tp_dict */
1143  NULL, /* tp_descr_get */
1144  NULL, /* tp_descr_set */
1145  0, /* tp_dictoffset */
1146  NULL, /* tp_init */
1147  NULL, /* tp_alloc */
1148  Color_new, /* tp_new */
1149  NULL, /* tp_free */
1150  NULL, /* tp_is_gc */
1151  NULL, /* tp_bases */
1152  NULL, /* tp_mro */
1153  NULL, /* tp_cache */
1154  NULL, /* tp_subclasses */
1155  NULL, /* tp_weaklist */
1156  NULL, /* tp_del */
1157 };
1158 
1161 /* -------------------------------------------------------------------- */
1165 PyObject *Color_CreatePyObject(const float col[3], PyTypeObject *base_type)
1166 {
1167  ColorObject *self;
1168  float *col_alloc;
1169 
1170  col_alloc = PyMem_Malloc(COLOR_SIZE * sizeof(float));
1171  if (UNLIKELY(col_alloc == NULL)) {
1172  PyErr_SetString(PyExc_MemoryError,
1173  "Color(): "
1174  "problem allocating data");
1175  return NULL;
1176  }
1177 
1178  self = BASE_MATH_NEW(ColorObject, color_Type, base_type);
1179  if (self) {
1180  self->col = col_alloc;
1181 
1182  /* init callbacks as NULL */
1183  self->cb_user = NULL;
1184  self->cb_type = self->cb_subtype = 0;
1185 
1186  /* NEW */
1187  if (col) {
1188  copy_v3_v3(self->col, col);
1189  }
1190  else {
1191  zero_v3(self->col);
1192  }
1193 
1194  self->flag = BASE_MATH_FLAG_DEFAULT;
1195  }
1196  else {
1197  PyMem_Free(col_alloc);
1198  }
1199 
1200  return (PyObject *)self;
1201 }
1202 
1203 PyObject *Color_CreatePyObject_wrap(float col[3], PyTypeObject *base_type)
1204 {
1205  ColorObject *self;
1206 
1207  self = BASE_MATH_NEW(ColorObject, color_Type, base_type);
1208  if (self) {
1209  /* init callbacks as NULL */
1210  self->cb_user = NULL;
1211  self->cb_type = self->cb_subtype = 0;
1212 
1213  /* WRAP */
1214  self->col = col;
1216  }
1217 
1218  return (PyObject *)self;
1219 }
1220 
1221 PyObject *Color_CreatePyObject_cb(PyObject *cb_user, uchar cb_type, uchar cb_subtype)
1222 {
1224  if (self) {
1225  Py_INCREF(cb_user);
1226  self->cb_user = cb_user;
1227  self->cb_type = cb_type;
1228  self->cb_subtype = cb_subtype;
1229  PyObject_GC_Track(self);
1230  }
1231 
1232  return (PyObject *)self;
1233 }
1234 
#define BLI_assert_msg(a, msg)
Definition: BLI_assert.h:53
#define ATTR_FALLTHROUGH
A dynamically sized string ADT.
DynStr * BLI_dynstr_new(void) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition: BLI_dynstr.c:50
void BLI_dynstr_appendf(DynStr *__restrict ds, const char *__restrict format,...) ATTR_PRINTF_FORMAT(2
double double_round(double x, int ndigits)
Definition: math_base.c:27
void hsv_to_rgb_v(const float hsv[3], float r_rgb[3])
Definition: math_color.c:49
void rgb_to_hsv_v(const float rgb[3], float r_hsv[3])
Definition: math_color.c:232
void rgb_to_hsv(float r, float g, float b, float *r_h, float *r_s, float *r_v)
Definition: math_color.c:208
void add_vn_vn(float *array_tar, const float *array_src, int size)
Definition: math_vector.c:1112
void mul_vn_fl(float *array_tar, int size, float f)
Definition: math_vector.c:1093
MINLINE void clamp_v3(float vec[3], float min, float max)
void sub_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, int size)
Definition: math_vector.c:1171
MINLINE void copy_v3_v3(float r[3], const float a[3])
void add_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, int size)
Definition: math_vector.c:1122
void negate_vn_vn(float *array_tar, const float *array_src, int size)
Definition: math_vector.c:1059
MINLINE void zero_v3(float r[3])
void mul_vn_vn_fl(float *array_tar, const float *array_src, int size, float f)
Definition: math_vector.c:1102
void sub_vn_vn(float *array_tar, const float *array_src, int size)
Definition: math_vector.c:1161
unsigned char uchar
Definition: BLI_sys_types.h:70
#define UNUSED(x)
#define POINTER_AS_INT(i)
#define UNLIKELY(x)
#define MIN2(a, b)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
BLI_INLINE void IMB_colormanagement_srgb_to_scene_linear_v3(float scene_linear[3], const float srgb[3])
BLI_INLINE void IMB_colormanagement_scene_linear_to_rec709(float rec709[3], const float scene_linear[3])
BLI_INLINE void IMB_colormanagement_aces_to_scene_linear(float scene_linear[3], const float aces[3])
BLI_INLINE void IMB_colormanagement_xyz_to_scene_linear(float scene_linear[3], const float xyz[3])
BLI_INLINE void IMB_colormanagement_rec709_to_scene_linear(float scene_linear[3], const float rec709[3])
BLI_INLINE void IMB_colormanagement_scene_linear_to_xyz(float xyz[3], const float scene_linear[3])
BLI_INLINE void IMB_colormanagement_scene_linear_to_aces(float aces[3], const float scene_linear[3])
BLI_INLINE void IMB_colormanagement_scene_linear_to_srgb_v3(float srgb[3], const float scene_linear[3])
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position CLAMP
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a color
ATTR_WARN_UNUSED_RESULT const BMVert * v2
PyObject * self
Definition: bpy_driver.c:165
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
SyclQueue void void size_t num_bytes void
uint col
int count
PyObject * BaseMathObject_freeze(BaseMathObject *self)
Definition: mathutils.c:681
PyObject * BaseMathObject_is_frozen_get(BaseMathObject *self, void *UNUSED(closure))
Definition: mathutils.c:661
PyObject * BaseMathObject_is_wrapped_get(BaseMathObject *self, void *UNUSED(closure))
Definition: mathutils.c:654
PyObject * mathutils_dynstr_to_py(struct DynStr *ds)
Definition: mathutils.c:531
Py_hash_t mathutils_array_hash(const float *array, size_t array_len)
Definition: mathutils.c:66
void BaseMathObject_dealloc(BaseMathObject *self)
Definition: mathutils.c:705
int EXPP_VectorsAreEqual(const float *vecA, const float *vecB, int size, int floatSteps)
Definition: mathutils.c:519
int mathutils_array_parse(float *array, int array_num_min, int array_num_max, PyObject *value, const char *error_prefix)
Definition: mathutils.c:98
char BaseMathObject_is_valid_doc[]
Definition: mathutils.c:666
PyObject * BaseMathObject_owner_get(BaseMathObject *self, void *UNUSED(closure))
Definition: mathutils.c:646
char BaseMathObject_is_wrapped_doc[]
Definition: mathutils.c:652
char BaseMathObject_is_frozen_doc[]
Definition: mathutils.c:659
PyObject * BaseMathObject_is_valid_get(BaseMathObject *self, void *UNUSED(closure))
Definition: mathutils.c:668
char BaseMathObject_owner_doc[]
Definition: mathutils.c:645
char BaseMathObject_freeze_doc[]
Definition: mathutils.c:673
int BaseMathObject_clear(BaseMathObject *self)
Definition: mathutils.c:699
int BaseMathObject_traverse(BaseMathObject *self, visitproc visit, void *arg)
Definition: mathutils.c:693
@ BASE_MATH_FLAG_IS_WRAP
Definition: mathutils.h:31
#define BaseMath_ReadCallback_ForWrite(_self)
Definition: mathutils.h:129
#define BaseMath_ReadIndexCallback(_self, _index)
Definition: mathutils.h:123
#define BaseMath_WriteCallback(_self)
Definition: mathutils.h:121
#define BASE_MATH_NEW(struct_name, root_type, base_type)
Definition: mathutils.h:20
#define BaseMathObject_Prepare_ForHash(_self)
Definition: mathutils.h:144
#define BASE_MATH_FLAG_DEFAULT
Definition: mathutils.h:38
#define BaseMath_Prepare_ForWrite(_self)
Definition: mathutils.h:139
#define BaseMath_ReadCallback(_self)
Definition: mathutils.h:119
#define BaseMath_WriteIndexCallback(_self, _index)
Definition: mathutils.h:125
PyTypeObject color_Type
static PyObject * Color_subscript(ColorObject *self, PyObject *item)
static Py_hash_t Color_hash(ColorObject *self)
static int Color_ass_subscript(ColorObject *self, PyObject *item, PyObject *value)
static PyObject * Color_copy(ColorObject *self)
static PyObject * Color_from_xyz_d65_to_scene_linear(ColorObject *self)
static PyObject * Color_channel_hsv_get(ColorObject *self, void *type)
static PyObject * Color_channel_get(ColorObject *self, void *type)
static PySequenceMethods Color_SeqMethods
static PyObject * Color_div(PyObject *v1, PyObject *v2)
static PyObject * Color_slice(ColorObject *self, int begin, int end)
PyDoc_STRVAR(Color_from_scene_linear_to_srgb_doc, ".. function:: from_scene_linear_to_srgb()\n" "\n" " Convert from scene linear to sRGB color space.\n" "\n" " :return: A color in sRGB color space.\n" " :rtype: :class:`Color`\n")
static PyGetSetDef Color_getseters[]
static PyObject * Color_mul(PyObject *v1, PyObject *v2)
static PyObject * Color_imul(PyObject *v1, PyObject *v2)
static PyObject * Color_from_rec709_linear_to_scene_linear(ColorObject *self)
PyObject * Color_CreatePyObject_cb(PyObject *cb_user, uchar cb_type, uchar cb_subtype)
static PyObject * Color_sub(PyObject *v1, PyObject *v2)
#define COLOR_SIZE
static PyObject * Color_to_tuple_ex(ColorObject *self, int ndigits)
static PyObject * Color_neg(ColorObject *self)
static PyObject * Color_from_scene_linear_to_srgb(ColorObject *self)
static PyNumberMethods Color_NumMethods
static PyObject * Color_richcmpr(PyObject *a, PyObject *b, int op)
PyObject * Color_CreatePyObject(const float col[3], PyTypeObject *base_type)
static int Color_ass_slice(ColorObject *self, int begin, int end, PyObject *seq)
PyObject * Color_CreatePyObject_wrap(float col[3], PyTypeObject *base_type)
static PyObject * Color_str(ColorObject *self)
static PyObject * Color_repr(ColorObject *self)
static PyObject * Color_from_scene_linear_to_rec709_linear(ColorObject *self)
static PyObject * Color_from_scene_linear_to_aces(ColorObject *self)
static int Color_hsv_set(ColorObject *self, PyObject *value, void *UNUSED(closure))
static PyObject * Color_from_aces_to_scene_linear(ColorObject *self)
static struct PyMethodDef Color_methods[]
static PyObject * Color_iadd(PyObject *v1, PyObject *v2)
static PyObject * Color_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static PyMappingMethods Color_AsMapping
static PyObject * Color_add(PyObject *v1, PyObject *v2)
static PyObject * Color_item(ColorObject *self, int i)
static int Color_ass_item(ColorObject *self, int i, PyObject *value)
static PyObject * Color_idiv(PyObject *v1, PyObject *v2)
static PyObject * Color_deepcopy(ColorObject *self, PyObject *args)
static int Color_channel_set(ColorObject *self, PyObject *value, void *type)
static int Color_channel_hsv_set(ColorObject *self, PyObject *value, void *type)
static PyObject * Color_isub(PyObject *v1, PyObject *v2)
static PyObject * Color_from_srgb_to_scene_linear(ColorObject *self)
static int Color_len(ColorObject *UNUSED(self))
static PyObject * color_mul_float(ColorObject *color, const float scalar)
static PyObject * Color_from_scene_linear_to_xyz_d65(ColorObject *self)
static PyObject * Color_hsv_get(ColorObject *self, void *UNUSED(closure))
#define ColorObject_Check(v)
static unsigned a[3]
Definition: RandGen.cpp:78
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
int PyC_CheckArgs_DeepCopy(PyObject *args)
#define PyTuple_SET_ITEMS(op_arg,...)
return ret