Blender  V3.3
imbuf_py_api.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
9 #include <Python.h>
10 
11 #include "BLI_rect.h"
12 #include "BLI_string.h"
13 #include "BLI_utildefines.h"
14 
15 #include "py_capi_utils.h"
16 
17 #include "python_utildefines.h"
18 
19 #include "imbuf_py_api.h" /* own include */
20 
21 #include "../../imbuf/IMB_imbuf.h"
22 #include "../../imbuf/IMB_imbuf_types.h"
23 
24 /* File IO */
25 #include "BLI_fileops.h"
26 #include <errno.h>
27 #include <fcntl.h>
28 
29 static PyObject *BPyInit_imbuf_types(void);
30 
31 static PyObject *Py_ImBuf_CreatePyObject(ImBuf *ibuf);
32 
33 /* -------------------------------------------------------------------- */
37 typedef struct Py_ImBuf {
38  PyObject_VAR_HEAD
39  /* can be NULL */
42 
43 static int py_imbuf_valid_check(Py_ImBuf *self)
44 {
45  if (LIKELY(self->ibuf)) {
46  return 0;
47  }
48 
49  PyErr_Format(
50  PyExc_ReferenceError, "ImBuf data of type %.200s has been freed", Py_TYPE(self)->tp_name);
51  return -1;
52 }
53 
54 #define PY_IMBUF_CHECK_OBJ(obj) \
55  if (UNLIKELY(py_imbuf_valid_check(obj) == -1)) { \
56  return NULL; \
57  } \
58  ((void)0)
59 #define PY_IMBUF_CHECK_INT(obj) \
60  if (UNLIKELY(py_imbuf_valid_check(obj) == -1)) { \
61  return -1; \
62  } \
63  ((void)0)
64 
67 /* -------------------------------------------------------------------- */
71 PyDoc_STRVAR(py_imbuf_resize_doc,
72  ".. method:: resize(size, method='FAST')\n"
73  "\n"
74  " Resize the image.\n"
75  "\n"
76  " :arg size: New size.\n"
77  " :type size: pair of ints\n"
78  " :arg method: Method of resizing ('FAST', 'BILINEAR')\n"
79  " :type method: str\n");
80 static PyObject *py_imbuf_resize(Py_ImBuf *self, PyObject *args, PyObject *kw)
81 {
82  PY_IMBUF_CHECK_OBJ(self);
83 
84  int size[2];
85 
86  enum { FAST, BILINEAR };
87  const struct PyC_StringEnumItems method_items[] = {
88  {FAST, "FAST"},
89  {BILINEAR, "BILINEAR"},
90  {0, NULL},
91  };
92  struct PyC_StringEnum method = {method_items, FAST};
93 
94  static const char *_keywords[] = {"size", "method", NULL};
95  static _PyArg_Parser _parser = {
96  "(ii)" /* `size` */
97  "|$" /* Optional keyword only arguments. */
98  "O&" /* `method` */
99  ":resize",
100  _keywords,
101  0,
102  };
103  if (!_PyArg_ParseTupleAndKeywordsFast(
104  args, kw, &_parser, &size[0], &size[1], PyC_ParseStringEnum, &method)) {
105  return NULL;
106  }
107  if (size[0] <= 0 || size[1] <= 0) {
108  PyErr_Format(PyExc_ValueError, "resize: Image size cannot be below 1 (%d, %d)", UNPACK2(size));
109  return NULL;
110  }
111 
112  if (method.value_found == FAST) {
114  }
115  else if (method.value_found == BILINEAR) {
116  IMB_scaleImBuf(self->ibuf, UNPACK2(size));
117  }
118  else {
120  }
121  Py_RETURN_NONE;
122 }
123 
124 PyDoc_STRVAR(py_imbuf_crop_doc,
125  ".. method:: crop(min, max)\n"
126  "\n"
127  " Crop the image.\n"
128  "\n"
129  " :arg min: X, Y minimum.\n"
130  " :type min: pair of ints\n"
131  " :arg max: X, Y maximum.\n"
132  " :type max: pair of ints\n");
133 static PyObject *py_imbuf_crop(Py_ImBuf *self, PyObject *args, PyObject *kw)
134 {
135  PY_IMBUF_CHECK_OBJ(self);
136 
137  rcti crop;
138 
139  static const char *_keywords[] = {"min", "max", NULL};
140  static _PyArg_Parser _parser = {
141  "(II)" /* `min` */
142  "(II)" /* `max` */
143  ":crop",
144  _keywords,
145  0,
146  };
147  if (!_PyArg_ParseTupleAndKeywordsFast(
148  args, kw, &_parser, &crop.xmin, &crop.ymin, &crop.xmax, &crop.ymax)) {
149  return NULL;
150  }
151 
152  if (/* X range. */
153  (!(crop.xmin >= 0 && crop.xmax < self->ibuf->x)) ||
154  /* Y range. */
155  (!(crop.ymin >= 0 && crop.ymax < self->ibuf->y)) ||
156  /* X order. */
157  (!(crop.xmin <= crop.xmax)) ||
158  /* Y order. */
159  (!(crop.ymin <= crop.ymax))) {
160  PyErr_SetString(PyExc_ValueError, "ImBuf crop min/max not in range");
161  return NULL;
162  }
163  IMB_rect_crop(self->ibuf, &crop);
164  Py_RETURN_NONE;
165 }
166 
167 PyDoc_STRVAR(py_imbuf_copy_doc,
168  ".. method:: copy()\n"
169  "\n"
170  " :return: A copy of the image.\n"
171  " :rtype: :class:`ImBuf`\n");
172 static PyObject *py_imbuf_copy(Py_ImBuf *self)
173 {
174  PY_IMBUF_CHECK_OBJ(self);
175  ImBuf *ibuf_copy = IMB_dupImBuf(self->ibuf);
176 
177  if (UNLIKELY(ibuf_copy == NULL)) {
178  PyErr_SetString(PyExc_MemoryError,
179  "ImBuf.copy(): "
180  "failed to allocate memory");
181  return NULL;
182  }
183  return Py_ImBuf_CreatePyObject(ibuf_copy);
184 }
185 
186 static PyObject *py_imbuf_deepcopy(Py_ImBuf *self, PyObject *args)
187 {
188  if (!PyC_CheckArgs_DeepCopy(args)) {
189  return NULL;
190  }
191  return py_imbuf_copy(self);
192 }
193 
194 PyDoc_STRVAR(py_imbuf_free_doc,
195  ".. method:: free()\n"
196  "\n"
197  " Clear image data immediately (causing an error on re-use).\n");
198 static PyObject *py_imbuf_free(Py_ImBuf *self)
199 {
200  if (self->ibuf) {
201  IMB_freeImBuf(self->ibuf);
202  self->ibuf = NULL;
203  }
204  Py_RETURN_NONE;
205 }
206 
207 static struct PyMethodDef Py_ImBuf_methods[] = {
208  {"resize", (PyCFunction)py_imbuf_resize, METH_VARARGS | METH_KEYWORDS, py_imbuf_resize_doc},
209  {"crop", (PyCFunction)py_imbuf_crop, METH_VARARGS | METH_KEYWORDS, (char *)py_imbuf_crop_doc},
210  {"free", (PyCFunction)py_imbuf_free, METH_NOARGS, py_imbuf_free_doc},
211  {"copy", (PyCFunction)py_imbuf_copy, METH_NOARGS, py_imbuf_copy_doc},
212  {"__copy__", (PyCFunction)py_imbuf_copy, METH_NOARGS, py_imbuf_copy_doc},
213  {"__deepcopy__", (PyCFunction)py_imbuf_deepcopy, METH_VARARGS, py_imbuf_copy_doc},
214  {NULL, NULL, 0, NULL},
215 };
216 
219 /* -------------------------------------------------------------------- */
223 PyDoc_STRVAR(py_imbuf_size_doc, "size of the image in pixels.\n\n:type: pair of ints");
224 static PyObject *py_imbuf_size_get(Py_ImBuf *self, void *UNUSED(closure))
225 {
226  PY_IMBUF_CHECK_OBJ(self);
227  ImBuf *ibuf = self->ibuf;
228  return PyC_Tuple_Pack_I32(ibuf->x, ibuf->y);
229 }
230 
231 PyDoc_STRVAR(py_imbuf_ppm_doc, "pixels per meter.\n\n:type: pair of floats");
232 static PyObject *py_imbuf_ppm_get(Py_ImBuf *self, void *UNUSED(closure))
233 {
234  PY_IMBUF_CHECK_OBJ(self);
235  ImBuf *ibuf = self->ibuf;
236  return PyC_Tuple_Pack_F64(ibuf->ppm[0], ibuf->ppm[1]);
237 }
238 
239 static int py_imbuf_ppm_set(Py_ImBuf *self, PyObject *value, void *UNUSED(closure))
240 {
241  PY_IMBUF_CHECK_INT(self);
242  double ppm[2];
243 
244  if (PyC_AsArray(ppm, sizeof(*ppm), value, 2, &PyFloat_Type, "ppm") == -1) {
245  return -1;
246  }
247 
248  if (ppm[0] <= 0.0 || ppm[1] <= 0.0) {
249  PyErr_SetString(PyExc_ValueError, "invalid ppm value");
250  return -1;
251  }
252 
253  ImBuf *ibuf = self->ibuf;
254  ibuf->ppm[0] = ppm[0];
255  ibuf->ppm[1] = ppm[1];
256  return 0;
257 }
258 
259 PyDoc_STRVAR(py_imbuf_filepath_doc, "filepath associated with this image.\n\n:type: string");
260 static PyObject *py_imbuf_filepath_get(Py_ImBuf *self, void *UNUSED(closure))
261 {
262  PY_IMBUF_CHECK_OBJ(self);
263  ImBuf *ibuf = self->ibuf;
264  return PyC_UnicodeFromByte(ibuf->name);
265 }
266 
267 static int py_imbuf_filepath_set(Py_ImBuf *self, PyObject *value, void *UNUSED(closure))
268 {
269  PY_IMBUF_CHECK_INT(self);
270 
271  if (!PyUnicode_Check(value)) {
272  PyErr_SetString(PyExc_TypeError, "expected a string!");
273  return -1;
274  }
275 
276  ImBuf *ibuf = self->ibuf;
277  const Py_ssize_t value_str_len_max = sizeof(ibuf->name);
278  Py_ssize_t value_str_len;
279  const char *value_str = PyUnicode_AsUTF8AndSize(value, &value_str_len);
280  if (value_str_len >= value_str_len_max) {
281  PyErr_Format(PyExc_TypeError, "filepath length over %zd", value_str_len_max - 1);
282  return -1;
283  }
284  memcpy(ibuf->name, value_str, value_str_len + 1);
285  return 0;
286 }
287 
288 PyDoc_STRVAR(py_imbuf_planes_doc, "Number of bits associated with this image.\n\n:type: int");
289 static PyObject *py_imbuf_planes_get(Py_ImBuf *self, void *UNUSED(closure))
290 {
291  PY_IMBUF_CHECK_OBJ(self);
292  ImBuf *imbuf = self->ibuf;
293  return PyLong_FromLong(imbuf->planes);
294 }
295 
296 PyDoc_STRVAR(py_imbuf_channels_doc, "Number of bit-planes.\n\n:type: int");
297 static PyObject *py_imbuf_channels_get(Py_ImBuf *self, void *UNUSED(closure))
298 {
299  PY_IMBUF_CHECK_OBJ(self);
300  ImBuf *imbuf = self->ibuf;
301  return PyLong_FromLong(imbuf->channels);
302 }
303 
304 static PyGetSetDef Py_ImBuf_getseters[] = {
305  {"size", (getter)py_imbuf_size_get, (setter)NULL, py_imbuf_size_doc, NULL},
306  {"ppm", (getter)py_imbuf_ppm_get, (setter)py_imbuf_ppm_set, py_imbuf_ppm_doc, NULL},
307  {"filepath",
308  (getter)py_imbuf_filepath_get,
309  (setter)py_imbuf_filepath_set,
310  py_imbuf_filepath_doc,
311  NULL},
312  {"planes", (getter)py_imbuf_planes_get, NULL, py_imbuf_planes_doc, NULL},
313  {"channels", (getter)py_imbuf_channels_get, NULL, py_imbuf_channels_doc, NULL},
314  {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
315 };
316 
319 /* -------------------------------------------------------------------- */
323 static void py_imbuf_dealloc(Py_ImBuf *self)
324 {
325  ImBuf *ibuf = self->ibuf;
326  if (ibuf != NULL) {
327  IMB_freeImBuf(self->ibuf);
328  self->ibuf = NULL;
329  }
330  PyObject_DEL(self);
331 }
332 
333 static PyObject *py_imbuf_repr(Py_ImBuf *self)
334 {
335  const ImBuf *ibuf = self->ibuf;
336  if (ibuf != NULL) {
337  return PyUnicode_FromFormat(
338  "<imbuf: address=%p, filepath='%s', size=(%d, %d)>", ibuf, ibuf->name, ibuf->x, ibuf->y);
339  }
340 
341  return PyUnicode_FromString("<imbuf: address=0x0>");
342 }
343 
344 static Py_hash_t py_imbuf_hash(Py_ImBuf *self)
345 {
346  return _Py_HashPointer(self->ibuf);
347 }
348 
349 PyTypeObject Py_ImBuf_Type = {
350  PyVarObject_HEAD_INIT(NULL, 0)
351  /* For printing, in format "<module>.<name>" */
352  "ImBuf", /* tp_name */
353  sizeof(Py_ImBuf), /* int tp_basicsize; */
354  0, /* tp_itemsize; For allocation */
355 
356  /* Methods to implement standard operations */
357 
358  (destructor)py_imbuf_dealloc, /* destructor tp_dealloc; */
359  0, /* tp_vectorcall_offset */
360  NULL, /* getattrfunc tp_getattr; */
361  NULL, /* setattrfunc tp_setattr; */
362  NULL, /* cmpfunc tp_compare; */
363  (reprfunc)py_imbuf_repr, /* reprfunc tp_repr; */
364 
365  /* Method suites for standard classes */
366 
367  NULL, /* PyNumberMethods *tp_as_number; */
368  NULL, /* PySequenceMethods *tp_as_sequence; */
369  NULL, /* PyMappingMethods *tp_as_mapping; */
370 
371  /* More standard operations (here for binary compatibility) */
372 
373  (hashfunc)py_imbuf_hash, /* hashfunc tp_hash; */
374  NULL, /* ternaryfunc tp_call; */
375  NULL, /* reprfunc tp_str; */
376  NULL, /* getattrofunc tp_getattro; */
377  NULL, /* setattrofunc tp_setattro; */
378 
379  /* Functions to access object as input/output buffer */
380  NULL, /* PyBufferProcs *tp_as_buffer; */
381 
382  /*** Flags to define presence of optional/expanded features ***/
383  Py_TPFLAGS_DEFAULT, /* long tp_flags; */
384 
385  NULL, /* char *tp_doc; Documentation string */
386  /*** Assigned meaning in release 2.0 ***/
387  /* call function for all accessible objects */
388  NULL, /* traverseproc tp_traverse; */
389 
390  /* delete references to contained objects */
391  NULL, /* inquiry tp_clear; */
392 
393  /*** Assigned meaning in release 2.1 ***/
394  /*** rich comparisons ***/
395  NULL, /* richcmpfunc tp_richcompare; */
396 
397  /*** weak reference enabler ***/
398  0, /* long tp_weaklistoffset; */
399 
400  /*** Added in release 2.2 ***/
401  /* Iterators */
402  NULL, /* getiterfunc tp_iter; */
403  NULL, /* iternextfunc tp_iternext; */
404  /*** Attribute descriptor and subclassing stuff ***/
405  Py_ImBuf_methods, /* struct PyMethodDef *tp_methods; */
406  NULL, /* struct PyMemberDef *tp_members; */
407  Py_ImBuf_getseters, /* struct PyGetSetDef *tp_getset; */
408 };
409 
410 static PyObject *Py_ImBuf_CreatePyObject(ImBuf *ibuf)
411 {
412  Py_ImBuf *self = PyObject_New(Py_ImBuf, &Py_ImBuf_Type);
413  self->ibuf = ibuf;
414  return (PyObject *)self;
415 }
416 
419 /* -------------------------------------------------------------------- */
423 PyDoc_STRVAR(M_imbuf_new_doc,
424  ".. function:: new(size)\n"
425  "\n"
426  " Load a new image.\n"
427  "\n"
428  " :arg size: The size of the image in pixels.\n"
429  " :type size: pair of ints\n"
430  " :return: the newly loaded image.\n"
431  " :rtype: :class:`ImBuf`\n");
432 static PyObject *M_imbuf_new(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
433 {
434  int size[2];
435  static const char *_keywords[] = {"size", NULL};
436  static _PyArg_Parser _parser = {
437  "(ii)" /* `size` */
438  ":new",
439  _keywords,
440  0,
441  };
442  if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &size[0], &size[1])) {
443  return NULL;
444  }
445  if (size[0] <= 0 || size[1] <= 0) {
446  PyErr_Format(PyExc_ValueError, "new: Image size cannot be below 1 (%d, %d)", UNPACK2(size));
447  return NULL;
448  }
449 
450  /* TODO: make options. */
451  const uchar planes = 4;
452  const uint flags = IB_rect;
453 
454  ImBuf *ibuf = IMB_allocImBuf(UNPACK2(size), planes, flags);
455  if (ibuf == NULL) {
456  PyErr_Format(PyExc_ValueError, "new: Unable to create image (%d, %d)", UNPACK2(size));
457  return NULL;
458  }
459  return Py_ImBuf_CreatePyObject(ibuf);
460 }
461 
462 PyDoc_STRVAR(M_imbuf_load_doc,
463  ".. function:: load(filepath)\n"
464  "\n"
465  " Load an image from a file.\n"
466  "\n"
467  " :arg filepath: the filepath of the image.\n"
468  " :type filepath: string\n"
469  " :return: the newly loaded image.\n"
470  " :rtype: :class:`ImBuf`\n");
471 static PyObject *M_imbuf_load(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
472 {
473  const char *filepath;
474 
475  static const char *_keywords[] = {"filepath", NULL};
476  static _PyArg_Parser _parser = {
477  "s" /* `filepath` */
478  ":load",
479  _keywords,
480  0,
481  };
482  if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &filepath)) {
483  return NULL;
484  }
485 
486  const int file = BLI_open(filepath, O_BINARY | O_RDONLY, 0);
487  if (file == -1) {
488  PyErr_Format(PyExc_IOError, "load: %s, failed to open file '%s'", strerror(errno), filepath);
489  return NULL;
490  }
491 
492  ImBuf *ibuf = IMB_loadifffile(file, filepath, IB_rect, NULL, filepath);
493 
494  close(file);
495 
496  if (ibuf == NULL) {
497  PyErr_Format(
498  PyExc_ValueError, "load: Unable to recognize image format for file '%s'", filepath);
499  return NULL;
500  }
501 
502  BLI_strncpy(ibuf->name, filepath, sizeof(ibuf->name));
503 
504  return Py_ImBuf_CreatePyObject(ibuf);
505 }
506 
508  M_imbuf_write_doc,
509  ".. function:: write(image, filepath=image.filepath)\n"
510  "\n"
511  " Write an image.\n"
512  "\n"
513  " :arg image: the image to write.\n"
514  " :type image: :class:`ImBuf`\n"
515  " :arg filepath: Optional filepath of the image (fallback to the images file path).\n"
516  " :type filepath: string\n");
517 static PyObject *M_imbuf_write(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
518 {
519  Py_ImBuf *py_imb;
520  const char *filepath = NULL;
521 
522  static const char *_keywords[] = {"image", "filepath", NULL};
523  static _PyArg_Parser _parser = {
524  "O!" /* `image` */
525  "|$" /* Optional keyword only arguments. */
526  "s" /* `filepath` */
527  ":write",
528  _keywords,
529  0,
530  };
531  if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &Py_ImBuf_Type, &py_imb, &filepath)) {
532  return NULL;
533  }
534 
535  if (filepath == NULL) {
536  filepath = py_imb->ibuf->name;
537  }
538 
539  const bool ok = IMB_saveiff(py_imb->ibuf, filepath, IB_rect);
540  if (ok == false) {
541  PyErr_Format(
542  PyExc_IOError, "write: Unable to write image file (%s) '%s'", strerror(errno), filepath);
543  return NULL;
544  }
545 
546  Py_RETURN_NONE;
547 }
548 
551 /* -------------------------------------------------------------------- */
555 static PyMethodDef IMB_methods[] = {
556  {"new", (PyCFunction)M_imbuf_new, METH_VARARGS | METH_KEYWORDS, M_imbuf_new_doc},
557  {"load", (PyCFunction)M_imbuf_load, METH_VARARGS | METH_KEYWORDS, M_imbuf_load_doc},
558  {"write", (PyCFunction)M_imbuf_write, METH_VARARGS | METH_KEYWORDS, M_imbuf_write_doc},
559  {NULL, NULL, 0, NULL},
560 };
561 
562 PyDoc_STRVAR(IMB_doc,
563  "This module provides access to Blender's image manipulation API.\n"
564  "\n"
565  "It provides access to image buffers outside of Blender's\n"
566  ":class:`bpy.types.Image` data-block context.\n");
567 static struct PyModuleDef IMB_module_def = {
568  PyModuleDef_HEAD_INIT,
569  "imbuf", /* m_name */
570  IMB_doc, /* m_doc */
571  0, /* m_size */
572  IMB_methods, /* m_methods */
573  NULL, /* m_reload */
574  NULL, /* m_traverse */
575  NULL, /* m_clear */
576  NULL, /* m_free */
577 };
578 
579 PyObject *BPyInit_imbuf(void)
580 {
581  PyObject *mod;
582  PyObject *submodule;
583  PyObject *sys_modules = PyImport_GetModuleDict();
584 
585  mod = PyModule_Create(&IMB_module_def);
586 
587  /* `imbuf.types` */
588  PyModule_AddObject(mod, "types", (submodule = BPyInit_imbuf_types()));
589  PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
590 
591  return mod;
592 }
593 
596 /* -------------------------------------------------------------------- */
603 PyDoc_STRVAR(IMB_types_doc,
604  "This module provides access to image buffer types.\n"
605  "\n"
606  ".. note::\n"
607  "\n"
608  " Image buffer is also the structure used by :class:`bpy.types.Image`\n"
609  " ID type to store and manipulate image data at runtime.\n");
610 
611 static struct PyModuleDef IMB_types_module_def = {
612  PyModuleDef_HEAD_INIT,
613  "imbuf.types", /* m_name */
614  IMB_types_doc, /* m_doc */
615  0, /* m_size */
616  NULL, /* m_methods */
617  NULL, /* m_reload */
618  NULL, /* m_traverse */
619  NULL, /* m_clear */
620  NULL, /* m_free */
621 };
622 
623 PyObject *BPyInit_imbuf_types(void)
624 {
625  PyObject *submodule = PyModule_Create(&IMB_types_module_def);
626 
627  if (PyType_Ready(&Py_ImBuf_Type) < 0) {
628  return NULL;
629  }
630 
631  PyModule_AddType(submodule, &Py_ImBuf_Type);
632 
633  return submodule;
634 }
635 
#define BLI_assert_unreachable()
Definition: BLI_assert.h:93
File and directory operations.
#define O_BINARY
Definition: BLI_fileops.h:319
int BLI_open(const char *filepath, int oflag, int pmode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: fileops.c:920
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
Definition: string.c:64
unsigned char uchar
Definition: BLI_sys_types.h:70
unsigned int uint
Definition: BLI_sys_types.h:67
#define UNPACK2(a)
#define UNUSED(x)
#define UNLIKELY(x)
#define LIKELY(x)
bool IMB_scaleImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned int newy)
Definition: scaling.c:1644
struct ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, unsigned char planes, unsigned int flags)
Definition: allocimbuf.c:500
struct ImBuf * IMB_dupImBuf(const struct ImBuf *ibuf1)
void IMB_rect_crop(struct ImBuf *ibuf, const struct rcti *crop)
struct ImBuf * IMB_loadifffile(int file, const char *filepath, int flags, char colorspace[IM_MAX_SPACE], const char *descr)
Definition: readimage.c:156
bool IMB_scalefastImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned int newy)
Definition: scaling.c:1689
bool IMB_saveiff(struct ImBuf *ibuf, const char *filepath, int flags)
Definition: writeimage.c:22
@ IB_rect
PyObject * self
Definition: bpy_driver.c:165
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
FILE * file
void IMB_freeImBuf(ImBuf *UNUSED(ibuf))
static PyObject * py_imbuf_channels_get(Py_ImBuf *self, void *UNUSED(closure))
Definition: imbuf_py_api.c:297
static PyObject * Py_ImBuf_CreatePyObject(ImBuf *ibuf)
Definition: imbuf_py_api.c:410
struct Py_ImBuf Py_ImBuf
static int py_imbuf_filepath_set(Py_ImBuf *self, PyObject *value, void *UNUSED(closure))
Definition: imbuf_py_api.c:267
PyDoc_STRVAR(py_imbuf_resize_doc, ".. method:: resize(size, method='FAST')\n" "\n" " Resize the image.\n" "\n" " :arg size: New size.\n" " :type size: pair of ints\n" " :arg method: Method of resizing ('FAST', 'BILINEAR')\n" " :type method: str\n")
static PyObject * py_imbuf_crop(Py_ImBuf *self, PyObject *args, PyObject *kw)
Definition: imbuf_py_api.c:133
static PyObject * M_imbuf_write(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
Definition: imbuf_py_api.c:517
static Py_hash_t py_imbuf_hash(Py_ImBuf *self)
Definition: imbuf_py_api.c:344
#define PY_IMBUF_CHECK_OBJ(obj)
Definition: imbuf_py_api.c:54
static PyMethodDef IMB_methods[]
Definition: imbuf_py_api.c:555
static PyObject * py_imbuf_planes_get(Py_ImBuf *self, void *UNUSED(closure))
Definition: imbuf_py_api.c:289
#define PY_IMBUF_CHECK_INT(obj)
Definition: imbuf_py_api.c:59
static PyObject * M_imbuf_load(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
Definition: imbuf_py_api.c:471
static PyObject * py_imbuf_free(Py_ImBuf *self)
Definition: imbuf_py_api.c:198
static PyObject * py_imbuf_resize(Py_ImBuf *self, PyObject *args, PyObject *kw)
Definition: imbuf_py_api.c:80
static PyObject * M_imbuf_new(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
Definition: imbuf_py_api.c:432
static PyGetSetDef Py_ImBuf_getseters[]
Definition: imbuf_py_api.c:304
PyTypeObject Py_ImBuf_Type
Definition: imbuf_py_api.c:349
static PyObject * py_imbuf_copy(Py_ImBuf *self)
Definition: imbuf_py_api.c:172
static struct PyMethodDef Py_ImBuf_methods[]
Definition: imbuf_py_api.c:207
static struct PyModuleDef IMB_module_def
Definition: imbuf_py_api.c:567
static PyObject * py_imbuf_repr(Py_ImBuf *self)
Definition: imbuf_py_api.c:333
static struct PyModuleDef IMB_types_module_def
Definition: imbuf_py_api.c:611
static PyObject * BPyInit_imbuf_types(void)
Definition: imbuf_py_api.c:623
static int py_imbuf_ppm_set(Py_ImBuf *self, PyObject *value, void *UNUSED(closure))
Definition: imbuf_py_api.c:239
static int py_imbuf_valid_check(Py_ImBuf *self)
Definition: imbuf_py_api.c:43
static void py_imbuf_dealloc(Py_ImBuf *self)
Definition: imbuf_py_api.c:323
static PyObject * py_imbuf_ppm_get(Py_ImBuf *self, void *UNUSED(closure))
Definition: imbuf_py_api.c:232
static PyObject * py_imbuf_deepcopy(Py_ImBuf *self, PyObject *args)
Definition: imbuf_py_api.c:186
static PyObject * py_imbuf_filepath_get(Py_ImBuf *self, void *UNUSED(closure))
Definition: imbuf_py_api.c:260
PyObject * BPyInit_imbuf(void)
Definition: imbuf_py_api.c:579
static PyObject * py_imbuf_size_get(Py_ImBuf *self, void *UNUSED(closure))
Definition: imbuf_py_api.c:224
int PyC_CheckArgs_DeepCopy(PyObject *args)
int PyC_ParseStringEnum(PyObject *o, void *p)
int PyC_AsArray(void *array, const size_t array_item_size, PyObject *value, const Py_ssize_t length, const PyTypeObject *type, const char *error_prefix)
PyObject * PyC_UnicodeFromByte(const char *str)
#define PyC_Tuple_Pack_F64(...)
Definition: py_capi_utils.h:86
#define PyC_Tuple_Pack_I32(...)
Definition: py_capi_utils.h:88
header-only utilities
int channels
unsigned char planes
char name[IMB_FILENAME_SIZE]
double ppm[2]
PyObject_VAR_HEAD ImBuf * ibuf
Definition: imbuf_py_api.c:40
int ymin
Definition: DNA_vec_types.h:64
int ymax
Definition: DNA_vec_types.h:64
int xmin
Definition: DNA_vec_types.h:63
int xmax
Definition: DNA_vec_types.h:63
ccl_device_inline int mod(int x, int m)
Definition: util/math.h:490