21 #include "../../imbuf/IMB_imbuf.h"
22 #include "../../imbuf/IMB_imbuf_types.h"
50 PyExc_ReferenceError,
"ImBuf data of type %.200s has been freed", Py_TYPE(
self)->tp_name);
54 #define PY_IMBUF_CHECK_OBJ(obj) \
55 if (UNLIKELY(py_imbuf_valid_check(obj) == -1)) { \
59 #define PY_IMBUF_CHECK_INT(obj) \
60 if (UNLIKELY(py_imbuf_valid_check(obj) == -1)) { \
72 ".. method:: resize(size, method='FAST')\n"
74 " Resize the image.\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");
86 enum { FAST, BILINEAR };
89 {BILINEAR,
"BILINEAR"},
94 static const char *_keywords[] = {
"size",
"method",
NULL};
95 static _PyArg_Parser _parser = {
103 if (!_PyArg_ParseTupleAndKeywordsFast(
108 PyErr_Format(PyExc_ValueError,
"resize: Image size cannot be below 1 (%d, %d)",
UNPACK2(
size));
125 ".. method:: crop(min, max)\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");
139 static const char *_keywords[] = {
"min",
"max",
NULL};
140 static _PyArg_Parser _parser = {
147 if (!_PyArg_ParseTupleAndKeywordsFast(
160 PyErr_SetString(PyExc_ValueError,
"ImBuf crop min/max not in range");
168 ".. method:: copy()\n"
170 " :return: A copy of the image.\n"
171 " :rtype: :class:`ImBuf`\n");
178 PyErr_SetString(PyExc_MemoryError,
180 "failed to allocate memory");
195 ".. method:: free()\n"
197 " Clear image data immediately (causing an error on re-use).\n");
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},
223 PyDoc_STRVAR(py_imbuf_size_doc,
"size of the image in pixels.\n\n:type: pair of ints");
227 ImBuf *ibuf =
self->ibuf;
231 PyDoc_STRVAR(py_imbuf_ppm_doc,
"pixels per meter.\n\n:type: pair of floats");
235 ImBuf *ibuf =
self->ibuf;
244 if (
PyC_AsArray(ppm,
sizeof(*ppm), value, 2, &PyFloat_Type,
"ppm") == -1) {
248 if (ppm[0] <= 0.0 || ppm[1] <= 0.0) {
249 PyErr_SetString(PyExc_ValueError,
"invalid ppm value");
253 ImBuf *ibuf =
self->ibuf;
254 ibuf->
ppm[0] = ppm[0];
255 ibuf->
ppm[1] = ppm[1];
259 PyDoc_STRVAR(py_imbuf_filepath_doc,
"filepath associated with this image.\n\n:type: string");
263 ImBuf *ibuf =
self->ibuf;
271 if (!PyUnicode_Check(value)) {
272 PyErr_SetString(PyExc_TypeError,
"expected a string!");
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);
284 memcpy(ibuf->
name, value_str, value_str_len + 1);
288 PyDoc_STRVAR(py_imbuf_planes_doc,
"Number of bits associated with this image.\n\n:type: int");
292 ImBuf *imbuf =
self->ibuf;
293 return PyLong_FromLong(imbuf->
planes);
296 PyDoc_STRVAR(py_imbuf_channels_doc,
"Number of bit-planes.\n\n:type: int");
300 ImBuf *imbuf =
self->ibuf;
301 return PyLong_FromLong(imbuf->
channels);
310 py_imbuf_filepath_doc,
325 ImBuf *ibuf =
self->ibuf;
335 const ImBuf *ibuf =
self->ibuf;
337 return PyUnicode_FromFormat(
338 "<imbuf: address=%p, filepath='%s', size=(%d, %d)>", ibuf, ibuf->
name, ibuf->
x, ibuf->
y);
341 return PyUnicode_FromString(
"<imbuf: address=0x0>");
346 return _Py_HashPointer(
self->ibuf);
350 PyVarObject_HEAD_INIT(
NULL, 0)
414 return (PyObject *)
self;
424 ".. function:: new(size)\n"
426 " Load a new image.\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");
435 static const char *_keywords[] = {
"size",
NULL};
436 static _PyArg_Parser _parser = {
442 if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &
size[0], &
size[1])) {
446 PyErr_Format(PyExc_ValueError,
"new: Image size cannot be below 1 (%d, %d)",
UNPACK2(
size));
451 const uchar planes = 4;
456 PyErr_Format(PyExc_ValueError,
"new: Unable to create image (%d, %d)",
UNPACK2(
size));
463 ".. function:: load(filepath)\n"
465 " Load an image from a file.\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");
473 const char *filepath;
475 static const char *_keywords[] = {
"filepath",
NULL};
476 static _PyArg_Parser _parser = {
482 if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &filepath)) {
488 PyErr_Format(PyExc_IOError,
"load: %s, failed to open file '%s'", strerror(errno), filepath);
498 PyExc_ValueError,
"load: Unable to recognize image format for file '%s'", filepath);
509 ".. function:: write(image, filepath=image.filepath)\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");
520 const char *filepath =
NULL;
522 static const char *_keywords[] = {
"image",
"filepath",
NULL};
523 static _PyArg_Parser _parser = {
531 if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &
Py_ImBuf_Type, &py_imb, &filepath)) {
535 if (filepath ==
NULL) {
542 PyExc_IOError,
"write: Unable to write image file (%s) '%s'", strerror(errno), filepath);
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},
563 "This module provides access to Blender's image manipulation API.\n"
565 "It provides access to image buffers outside of Blender's\n"
566 ":class:`bpy.types.Image` data-block context.\n");
568 PyModuleDef_HEAD_INIT,
583 PyObject *sys_modules = PyImport_GetModuleDict();
589 PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
604 "This module provides access to image buffer types.\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");
612 PyModuleDef_HEAD_INIT,
#define BLI_assert_unreachable()
File and directory operations.
int BLI_open(const char *filepath, int oflag, int pmode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, 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)
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)
void IMB_freeImBuf(ImBuf *UNUSED(ibuf))
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)
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(...)
#define PyC_Tuple_Pack_I32(...)
char name[IMB_FILENAME_SIZE]
PyObject_VAR_HEAD ImBuf * ibuf
ccl_device_inline int mod(int x, int m)