28 #include "../generic/py_capi_utils.h"
29 #include "../generic/python_utildefines.h"
31 #ifndef MATH_STANDALONE
39 static PyObject *
Color_new(PyTypeObject *
type, PyObject *args, PyObject *kwds)
41 float col[3] = {0.0f, 0.0f, 0.0f};
43 if (kwds && PyDict_Size(kwds)) {
44 PyErr_SetString(PyExc_TypeError,
46 "takes no keyword args");
50 switch (PyTuple_GET_SIZE(args)) {
61 PyErr_SetString(PyExc_TypeError,
63 "more than a single arg given");
86 PyTuple_SET_ITEM(
ret, i, PyFloat_FromDouble(
self->col[i]));
94 ".. function:: copy()\n"
96 " Returns a copy of this color.\n"
98 " :return: A copy of the color.\n"
99 " :rtype: :class:`Color`\n"
101 " .. note:: use this to get a copy of a wrapped color with\n"
102 " no reference to the original data.\n");
124 PyObject *
ret, *tuple;
132 ret = PyUnicode_FromFormat(
"Color(%R)", tuple);
138 #ifndef MATH_STANDALONE
150 ds,
"<Color (r=%.4f, g=%.4f, b=%.4f)>",
self->col[0],
self->col[1],
self->col[2]);
179 res = ok ? Py_False : Py_True;
186 res = Py_NotImplemented;
193 return Py_INCREF_RET(res);
225 PyErr_SetString(PyExc_IndexError,
227 "array index out of range");
235 return PyFloat_FromDouble(
self->col[i]);
247 f = PyFloat_AsDouble(value);
248 if (f == -1 && PyErr_Occurred()) {
249 PyErr_SetString(PyExc_TypeError,
251 "assigned value not a number");
260 PyErr_SetString(PyExc_IndexError,
262 "array assignment index out of range");
290 begin =
MIN2(begin, end);
292 tuple = PyTuple_New(end - begin);
294 PyTuple_SET_ITEM(tuple,
count - begin, PyFloat_FromDouble(
self->col[
count]));
315 begin =
MIN2(begin, end);
322 if (
size != (end - begin)) {
323 PyErr_SetString(PyExc_ValueError,
324 "color[begin:end] = []: "
325 "size mismatch in slice assignment");
330 self->col[begin + i] =
col[i];
339 if (PyIndex_Check(item)) {
341 i = PyNumber_AsSsize_t(item, PyExc_IndexError);
342 if (i == -1 && PyErr_Occurred()) {
350 if (PySlice_Check(item)) {
351 Py_ssize_t start, stop, step, slicelength;
353 if (PySlice_GetIndicesEx(item,
COLOR_SIZE, &start, &stop, &step, &slicelength) < 0) {
357 if (slicelength <= 0) {
358 return PyTuple_New(0);
364 PyErr_SetString(PyExc_IndexError,
"slice steps not supported with color");
369 PyExc_TypeError,
"color indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
375 if (PyIndex_Check(item)) {
376 Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
377 if (i == -1 && PyErr_Occurred()) {
385 if (PySlice_Check(item)) {
386 Py_ssize_t start, stop, step, slicelength;
388 if (PySlice_GetIndicesEx(item,
COLOR_SIZE, &start, &stop, &step, &slicelength) < 0) {
396 PyErr_SetString(PyExc_IndexError,
"slice steps not supported with color");
401 PyExc_TypeError,
"color indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
434 PyErr_Format(PyExc_TypeError,
435 "Color addition: (%s + %s) "
436 "invalid type for this operation",
437 Py_TYPE(
v1)->tp_name,
438 Py_TYPE(
v2)->tp_name);
459 PyErr_Format(PyExc_TypeError,
460 "Color addition: (%s += %s) "
461 "invalid type for this operation",
462 Py_TYPE(
v1)->tp_name,
463 Py_TYPE(
v2)->tp_name);
487 PyErr_Format(PyExc_TypeError,
488 "Color subtraction: (%s - %s) "
489 "invalid type for this operation",
490 Py_TYPE(
v1)->tp_name,
491 Py_TYPE(
v2)->tp_name);
512 PyErr_Format(PyExc_TypeError,
513 "Color subtraction: (%s -= %s) "
514 "invalid type for this operation",
515 Py_TYPE(
v1)->tp_name,
516 Py_TYPE(
v2)->tp_name);
559 if (color1 && color2) {
563 if (((scalar = PyFloat_AsDouble(
v2)) == -1.0f && PyErr_Occurred()) == 0) {
568 if (((scalar = PyFloat_AsDouble(
v1)) == -1.0f && PyErr_Occurred()) == 0) {
576 PyErr_Format(PyExc_TypeError,
577 "Color multiplication: not supported between "
578 "'%.200s' and '%.200s' types",
579 Py_TYPE(
v1)->tp_name,
580 Py_TYPE(
v2)->tp_name);
596 PyErr_SetString(PyExc_TypeError,
"Color division not supported in this order");
601 if (((scalar = PyFloat_AsDouble(
v2)) == -1.0f && PyErr_Occurred()) == 0) {
602 if (scalar == 0.0f) {
603 PyErr_SetString(PyExc_ZeroDivisionError,
"Color division: divide by zero error");
609 PyErr_Format(PyExc_TypeError,
610 "Color multiplication: not supported between "
611 "'%.200s' and '%.200s' types",
612 Py_TYPE(
v1)->tp_name,
613 Py_TYPE(
v2)->tp_name);
628 if (((scalar = PyFloat_AsDouble(
v2)) == -1.0f && PyErr_Occurred()) == 0) {
632 PyErr_Format(PyExc_TypeError,
633 "Color multiplication: (%s *= %s) "
634 "invalid type for this operation",
635 Py_TYPE(
v1)->tp_name,
636 Py_TYPE(
v2)->tp_name);
656 if (((scalar = PyFloat_AsDouble(
v2)) == -1.0f && PyErr_Occurred()) == 0) {
657 if (scalar == 0.0f) {
658 PyErr_SetString(PyExc_ZeroDivisionError,
"Color division: divide by zero error");
665 PyErr_Format(PyExc_TypeError,
666 "Color division: (%s /= %s) "
667 "invalid type for this operation",
668 Py_TYPE(
v1)->tp_name,
669 Py_TYPE(
v2)->tp_name);
730 PyDoc_STRVAR(Color_channel_r_doc,
"Red color channel.\n\n:type: float");
731 PyDoc_STRVAR(Color_channel_g_doc,
"Green color channel.\n\n:type: float");
732 PyDoc_STRVAR(Color_channel_b_doc,
"Blue color channel.\n\n:type: float");
745 PyDoc_STRVAR(Color_channel_hsv_h_doc,
"HSV Hue component in [0, 1].\n\n:type: float");
746 PyDoc_STRVAR(Color_channel_hsv_s_doc,
"HSV Saturation component in [0, 1].\n\n:type: float");
747 PyDoc_STRVAR(Color_channel_hsv_v_doc,
"HSV Value component in [0, 1].\n\n:type: float");
760 return PyFloat_FromDouble(hsv[i]);
767 float f = PyFloat_AsDouble(value);
769 if (f == -1 && PyErr_Occurred()) {
770 PyErr_SetString(PyExc_TypeError,
771 "color.h/s/v = value: "
772 "assigned value not a number");
781 CLAMP(f, 0.0f, 1.0f);
793 PyDoc_STRVAR(Color_hsv_doc,
"HSV Values in [0, 1].\n\n:type: float triplet");
805 ret = PyTuple_New(3);
807 ret, PyFloat_FromDouble(hsv[0]), PyFloat_FromDouble(hsv[1]), PyFloat_FromDouble(hsv[2]));
844 Color_channel_hsv_h_doc,
849 Color_channel_hsv_s_doc,
854 Color_channel_hsv_v_doc,
875 {
"copy", (PyCFunction)
Color_copy, METH_NOARGS, Color_copy_doc},
876 {
"__copy__", (PyCFunction)
Color_copy, METH_NOARGS, Color_copy_doc},
877 {
"__deepcopy__", (PyCFunction)
Color_deepcopy, METH_VARARGS, Color_copy_doc},
886 ".. class:: Color(rgb)\n"
888 " This object gives access to Colors in Blender.\n"
890 " :param rgb: (r, g, b) color values\n"
891 " :type rgb: 3d vector\n");
893 PyVarObject_HEAD_INIT(
NULL, 0)
"Color",
907 #ifndef MATH_STANDALONE
915 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
949 col_alloc = PyMem_Malloc(
COLOR_SIZE *
sizeof(
float));
951 PyErr_SetString(PyExc_MemoryError,
953 "problem allocating data");
959 self->col = col_alloc;
962 self->cb_user =
NULL;
963 self->cb_type =
self->cb_subtype = 0;
976 PyMem_Free(col_alloc);
979 return (PyObject *)
self;
989 self->cb_user =
NULL;
990 self->cb_type =
self->cb_subtype = 0;
997 return (PyObject *)
self;
1005 self->cb_user = cb_user;
1006 self->cb_type = cb_type;
1007 self->cb_subtype = cb_subtype;
1008 PyObject_GC_Track(
self);
1011 return (PyObject *)
self;
A dynamically sized string ADT.
DynStr * BLI_dynstr_new(void) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void BLI_dynstr_appendf(DynStr *__restrict ds, const char *__restrict format,...) ATTR_PRINTF_FORMAT(2
double double_round(double x, int ndigits)
void hsv_to_rgb_v(const float hsv[3], float r_rgb[3])
void rgb_to_hsv_v(const float rgb[3], float r_hsv[3])
void rgb_to_hsv(float r, float g, float b, float *r_h, float *r_s, float *r_v)
void sub_vn_vn(float *array_tar, const float *array_src, const int size)
void mul_vn_vn_fl(float *array_tar, const float *array_src, const int size, const float f)
void sub_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, const int size)
MINLINE void clamp_v3(float vec[3], const float min, const float max)
void add_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, const int size)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void add_vn_vn(float *array_tar, const float *array_src, const int size)
void negate_vn_vn(float *array_tar, const float *array_src, const int size)
MINLINE void zero_v3(float r[3])
void mul_vn_fl(float *array_tar, const int size, const float f)
#define POINTER_AS_INT(i)
_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
Group RGB to Bright Vector Camera CLAMP
ATTR_WARN_UNUSED_RESULT const BMVert * v2
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
PyObject * BaseMathObject_freeze(BaseMathObject *self)
PyObject * BaseMathObject_is_frozen_get(BaseMathObject *self, void *UNUSED(closure))
PyObject * BaseMathObject_is_wrapped_get(BaseMathObject *self, void *UNUSED(closure))
PyObject * mathutils_dynstr_to_py(struct DynStr *ds)
Py_hash_t mathutils_array_hash(const float *array, size_t array_len)
void BaseMathObject_dealloc(BaseMathObject *self)
int EXPP_VectorsAreEqual(const float *vecA, const float *vecB, int size, int floatSteps)
PyObject * BaseMathObject_owner_get(BaseMathObject *self, void *UNUSED(closure))
char BaseMathObject_is_wrapped_doc[]
char BaseMathObject_is_frozen_doc[]
int mathutils_array_parse(float *array, int array_min, int array_max, PyObject *value, const char *error_prefix)
char BaseMathObject_owner_doc[]
char BaseMathObject_freeze_doc[]
int BaseMathObject_clear(BaseMathObject *self)
int BaseMathObject_traverse(BaseMathObject *self, visitproc visit, void *arg)
#define BaseMath_ReadCallback_ForWrite(_self)
#define BaseMath_ReadIndexCallback(_self, _index)
#define BaseMath_WriteCallback(_self)
#define BASE_MATH_NEW(struct_name, root_type, base_type)
#define BaseMathObject_Prepare_ForHash(_self)
#define BASE_MATH_FLAG_DEFAULT
#define BaseMath_Prepare_ForWrite(_self)
#define BaseMath_ReadCallback(_self)
#define BaseMath_WriteIndexCallback(_self, _index)
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_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)
static PyGetSetDef Color_getseters[]
static PyObject * Color_ToTupleExt(ColorObject *self, int ndigits)
static PyObject * Color_mul(PyObject *v1, PyObject *v2)
static PyObject * Color_imul(PyObject *v1, PyObject *v2)
PyDoc_STRVAR(Color_copy_doc, ".. function:: copy()\n" "\n" " Returns a copy of this color.\n" "\n" " :return: A copy of the color.\n" " :rtype: :class:`Color`\n" "\n" " .. note:: use this to get a copy of a wrapped color with\n" " no reference to the original data.\n")
PyObject * Color_CreatePyObject_cb(PyObject *cb_user, uchar cb_type, uchar cb_subtype)
static PyObject * Color_sub(PyObject *v1, PyObject *v2)
static PyObject * Color_neg(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 int Color_hsv_set(ColorObject *self, PyObject *value, void *UNUSED(closure))
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 int Color_len(ColorObject *UNUSED(self))
static PyObject * color_mul_float(ColorObject *color, const float scalar)
static PyObject * Color_hsv_get(ColorObject *self, void *UNUSED(closure))
#define ColorObject_Check(v)
int PyC_CheckArgs_DeepCopy(PyObject *args)
#define PyTuple_SET_ITEMS(op_arg,...)