35 #include "../../imbuf/IMB_imbuf.h"
36 #include "../../imbuf/IMB_imbuf_types.h"
64 PyExc_ReferenceError,
"ImBuf data of type %.200s has been freed", Py_TYPE(
self)->tp_name);
68 #define PY_IMBUF_CHECK_OBJ(obj) \
69 if (UNLIKELY(py_imbuf_valid_check(obj) == -1)) { \
73 #define PY_IMBUF_CHECK_INT(obj) \
74 if (UNLIKELY(py_imbuf_valid_check(obj) == -1)) { \
86 ".. method:: resize(size, method='FAST')\n"
88 " Resize the image.\n"
90 " :arg size: New size.\n"
91 " :type size: pair of ints\n"
92 " :arg method: Method of resizing ('FAST', 'BILINEAR')\n"
93 " :type method: str\n");
100 enum { FAST, BILINEAR };
103 {BILINEAR,
"BILINEAR"},
108 static const char *_keywords[] = {
"size",
"method",
NULL};
109 static _PyArg_Parser _parser = {
"(ii)|O&:resize", _keywords, 0};
110 if (!_PyArg_ParseTupleAndKeywordsFast(
115 PyErr_Format(PyExc_ValueError,
"resize: Image size cannot be below 1 (%d, %d)",
UNPACK2(
size));
132 ".. method:: crop(min, max)\n"
136 " :arg min: X, Y minimum.\n"
137 " :type min: pair of ints\n"
138 " :arg max: X, Y maximum.\n"
139 " :type max: pair of ints\n");
146 static const char *_keywords[] = {
"min",
"max",
NULL};
147 static _PyArg_Parser _parser = {
"(II)(II):crop", _keywords, 0};
148 if (!_PyArg_ParseTupleAndKeywordsFast(
161 PyErr_SetString(PyExc_ValueError,
"ImBuf crop min/max not in range");
169 ".. method:: copy()\n"
171 " :return: A copy of the image.\n"
172 " :rtype: :class:`ImBuf`\n");
179 PyErr_SetString(PyExc_MemoryError,
181 "failed to allocate memory memory");
196 ".. method:: free()\n"
198 " Clear image data immediately (causing an error on re-use).\n");
209 {
"resize", (PyCFunction)
py_imbuf_resize, METH_VARARGS | METH_KEYWORDS, py_imbuf_resize_doc},
210 {
"crop", (PyCFunction)
py_imbuf_crop, METH_VARARGS | METH_KEYWORDS, (
char *)py_imbuf_crop_doc},
211 {
"free", (PyCFunction)
py_imbuf_free, METH_NOARGS, py_imbuf_free_doc},
212 {
"copy", (PyCFunction)
py_imbuf_copy, METH_NOARGS, py_imbuf_copy_doc},
213 {
"__copy__", (PyCFunction)
py_imbuf_copy, METH_NOARGS, py_imbuf_copy_doc},
214 {
"__deepcopy__", (PyCFunction)
py_imbuf_deepcopy, METH_VARARGS, py_imbuf_copy_doc},
224 PyDoc_STRVAR(py_imbuf_size_doc,
"size of the image in pixels.\n\n:type: pair of ints");
228 ImBuf *ibuf =
self->ibuf;
232 PyDoc_STRVAR(py_imbuf_ppm_doc,
"pixels per meter.\n\n:type: pair of floats");
236 ImBuf *ibuf =
self->ibuf;
245 if (
PyC_AsArray(ppm, value, 2, &PyFloat_Type,
true,
"ppm") == -1) {
249 if (ppm[0] <= 0.0 || ppm[1] <= 0.0) {
250 PyErr_SetString(PyExc_ValueError,
"invalid ppm value");
254 ImBuf *ibuf =
self->ibuf;
255 ibuf->
ppm[0] = ppm[0];
256 ibuf->
ppm[1] = ppm[1];
260 PyDoc_STRVAR(py_imbuf_filepath_doc,
"filepath associated with this image.\n\n:type: string");
264 ImBuf *ibuf =
self->ibuf;
272 if (!PyUnicode_Check(value)) {
273 PyErr_SetString(PyExc_TypeError,
"expected a string!");
277 ImBuf *ibuf =
self->ibuf;
278 const Py_ssize_t value_str_len_max =
sizeof(ibuf->
name);
279 Py_ssize_t value_str_len;
280 const char *value_str = PyUnicode_AsUTF8AndSize(value, &value_str_len);
281 if (value_str_len >= value_str_len_max) {
282 PyErr_Format(PyExc_TypeError,
"filepath length over %zd", value_str_len_max - 1);
285 memcpy(ibuf->
name, value_str, value_str_len + 1);
289 PyDoc_STRVAR(py_imbuf_planes_doc,
"Number of bits associated with this image.\n\n:type: int");
293 ImBuf *imbuf =
self->ibuf;
294 return PyLong_FromLong(imbuf->
planes);
297 PyDoc_STRVAR(py_imbuf_channels_doc,
"Number of bit-planes.\n\n:type: int");
301 ImBuf *imbuf =
self->ibuf;
302 return PyLong_FromLong(imbuf->
channels);
311 py_imbuf_filepath_doc,
326 ImBuf *ibuf =
self->ibuf;
336 const ImBuf *ibuf =
self->ibuf;
338 return PyUnicode_FromFormat(
339 "<imbuf: address=%p, filepath='%s', size=(%d, %d)>", ibuf, ibuf->
name, ibuf->
x, ibuf->
y);
342 return PyUnicode_FromString(
"<imbuf: address=0x0>");
347 return _Py_HashPointer(
self->ibuf);
351 PyVarObject_HEAD_INIT(
NULL, 0)
415 return (PyObject *)
self;
425 ".. function:: new(size)\n"
427 " Load a new image.\n"
429 " :arg size: The size of the image in pixels.\n"
430 " :type size: pair of ints\n"
431 " :return: the newly loaded image.\n"
432 " :rtype: :class:`ImBuf`\n");
436 static const char *_keywords[] = {
"size",
NULL};
437 static _PyArg_Parser _parser = {
"(ii):new", _keywords, 0};
438 if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &
size[0], &
size[1])) {
442 PyErr_Format(PyExc_ValueError,
"new: Image size cannot be below 1 (%d, %d)",
UNPACK2(
size));
447 const uchar planes = 4;
452 PyErr_Format(PyExc_ValueError,
"new: Unable to create image (%d, %d)",
UNPACK2(
size));
459 ".. function:: load(filepath)\n"
461 " Load an image from a file.\n"
463 " :arg filepath: the filepath of the image.\n"
464 " :type filepath: string\n"
465 " :return: the newly loaded image.\n"
466 " :rtype: :class:`ImBuf`\n");
469 const char *filepath;
471 static const char *_keywords[] = {
"filepath",
NULL};
472 static _PyArg_Parser _parser = {
"s:load", _keywords, 0};
473 if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &filepath)) {
479 PyErr_Format(PyExc_IOError,
"load: %s, failed to open file '%s'", strerror(errno), filepath);
489 PyExc_ValueError,
"load: Unable to recognize image format for file '%s'", filepath);
499 ".. function:: write(image, filepath)\n"
503 " :arg image: the image to write.\n"
504 " :type image: :class:`ImBuf`\n"
505 " :arg filepath: the filepath of the image.\n"
506 " :type filepath: string\n");
510 const char *filepath =
NULL;
512 static const char *_keywords[] = {
"image",
"filepath",
NULL};
513 static _PyArg_Parser _parser = {
"O!|s:write", _keywords, 0};
514 if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &
Py_ImBuf_Type, &py_imb, &filepath)) {
518 if (filepath ==
NULL) {
525 PyExc_IOError,
"write: Unable to write image file (%s) '%s'", strerror(errno), filepath);
539 {
"new", (PyCFunction)
M_imbuf_new, METH_VARARGS | METH_KEYWORDS, M_imbuf_new_doc},
540 {
"load", (PyCFunction)
M_imbuf_load, METH_VARARGS | METH_KEYWORDS, M_imbuf_load_doc},
541 {
"write", (PyCFunction)
M_imbuf_write, METH_VARARGS | METH_KEYWORDS, M_imbuf_write_doc},
545 PyDoc_STRVAR(IMB_doc,
"This module provides access to Blender's image manipulation API.");
547 PyModuleDef_HEAD_INIT,
562 PyObject *sys_modules = PyImport_GetModuleDict();
568 PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
582 PyDoc_STRVAR(IMB_types_doc,
"This module provides access to image buffer types.");
585 PyModuleDef_HEAD_INIT,
#define BLI_assert_unreachable()
File and directory operations.
int BLI_open(const char *filename, int oflag, int pmode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
bool IMB_scaleImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned int newy)
struct ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, unsigned char planes, unsigned int flags)
struct ImBuf * IMB_dupImBuf(const struct ImBuf *ibuf1)
void IMB_rect_crop(struct ImBuf *ibuf, const struct rcti *crop)
void IMB_freeImBuf(struct ImBuf *ibuf)
struct ImBuf * IMB_loadifffile(int file, const char *filepath, int flags, char colorspace[IM_MAX_SPACE], const char *descr)
bool IMB_scalefastImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned int newy)
bool IMB_saveiff(struct ImBuf *ibuf, const char *filepath, int flags)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
static PyObject * py_imbuf_channels_get(Py_ImBuf *self, void *UNUSED(closure))
static PyObject * Py_ImBuf_CreatePyObject(ImBuf *ibuf)
static int py_imbuf_filepath_set(Py_ImBuf *self, PyObject *value, void *UNUSED(closure))
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)
static PyObject * M_imbuf_write(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
static Py_hash_t py_imbuf_hash(Py_ImBuf *self)
#define PY_IMBUF_CHECK_OBJ(obj)
static PyMethodDef IMB_methods[]
static PyObject * py_imbuf_planes_get(Py_ImBuf *self, void *UNUSED(closure))
#define PY_IMBUF_CHECK_INT(obj)
static PyObject * M_imbuf_load(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
static PyObject * py_imbuf_free(Py_ImBuf *self)
static PyObject * py_imbuf_resize(Py_ImBuf *self, PyObject *args, PyObject *kw)
static PyObject * M_imbuf_new(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
static PyGetSetDef Py_ImBuf_getseters[]
PyTypeObject Py_ImBuf_Type
static PyObject * py_imbuf_copy(Py_ImBuf *self)
static struct PyMethodDef Py_ImBuf_methods[]
static struct PyModuleDef IMB_module_def
static PyObject * py_imbuf_repr(Py_ImBuf *self)
static struct PyModuleDef IMB_types_module_def
static PyObject * BPyInit_imbuf_types(void)
static int py_imbuf_ppm_set(Py_ImBuf *self, PyObject *value, void *UNUSED(closure))
static int py_imbuf_valid_check(Py_ImBuf *self)
static void py_imbuf_dealloc(Py_ImBuf *self)
static PyObject * py_imbuf_ppm_get(Py_ImBuf *self, void *UNUSED(closure))
static PyObject * py_imbuf_deepcopy(Py_ImBuf *self, PyObject *args)
static PyObject * py_imbuf_filepath_get(Py_ImBuf *self, void *UNUSED(closure))
PyObject * BPyInit_imbuf(void)
static PyObject * py_imbuf_size_get(Py_ImBuf *self, void *UNUSED(closure))
int PyC_CheckArgs_DeepCopy(PyObject *args)
int PyC_ParseStringEnum(PyObject *o, void *p)
PyObject * PyC_UnicodeFromByte(const char *str)
int PyC_AsArray(void *array, PyObject *value, const Py_ssize_t length, const PyTypeObject *type, const bool is_double, const char *error_prefix)
#define PyC_Tuple_Pack_F64(...)
#define PyC_Tuple_Pack_I32(...)
char name[IMB_FILENAME_SIZE]
PyObject_VAR_HEAD ImBuf * ibuf
ccl_device_inline int mod(int x, int m)