Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-09-16 03:31:17 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-09-16 03:39:24 +0300
commit6cb1e38c87168b0ab83ca907bcf537d50c263454 (patch)
treed5ec0c7cec83964afe1b8ea0efef4b0e87e21022 /source/blender/python
parent367ce71b4750c55fc91fab27af2c2a50b7b95c24 (diff)
ImBuf Py API: add filepath access
D5804 by @cmbasnett with setter support added.
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/generic/imbuf_py_api.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/source/blender/python/generic/imbuf_py_api.c b/source/blender/python/generic/imbuf_py_api.c
index ba8da46d3f6..0b595987d73 100644
--- a/source/blender/python/generic/imbuf_py_api.c
+++ b/source/blender/python/generic/imbuf_py_api.c
@@ -227,6 +227,35 @@ static int py_imbuf_ppm_set(Py_ImBuf *self, PyObject *value, void *UNUSED(closur
return 0;
}
+PyDoc_STRVAR(py_imbuf_filepath_doc, "filepath associated with this image.\n\n:type: string");
+static PyObject *py_imbuf_filepath_get(Py_ImBuf *self, void *UNUSED(closure))
+{
+ PY_IMBUF_CHECK_OBJ(self);
+ ImBuf *ibuf = self->ibuf;
+ return PyC_UnicodeFromByte(ibuf->name);
+}
+
+static int py_imbuf_filepath_set(Py_ImBuf *self, PyObject *value, void *UNUSED(closure))
+{
+ PY_IMBUF_CHECK_INT(self);
+
+ if (!PyUnicode_Check(value)) {
+ PyErr_SetString(PyExc_TypeError, "expected a string!");
+ return -1;
+ }
+
+ ImBuf *ibuf = self->ibuf;
+ Py_ssize_t value_str_len_max = sizeof(ibuf->name);
+ Py_ssize_t value_str_len;
+ const char *value_str = _PyUnicode_AsStringAndSize(value, &value_str_len);
+ if (value_str_len >= value_str_len_max) {
+ PyErr_Format(PyExc_TypeError, "filepath length over %zd", value_str_len_max - 1);
+ return -1;
+ }
+ memcpy(ibuf->name, value_str, value_str_len + 1);
+ return 0;
+}
+
static PyGetSetDef Py_ImBuf_getseters[] = {
{(char *)"size", (getter)py_imbuf_size_get, (setter)NULL, (char *)py_imbuf_size_doc, NULL},
{(char *)"ppm",
@@ -234,6 +263,11 @@ static PyGetSetDef Py_ImBuf_getseters[] = {
(setter)py_imbuf_ppm_set,
(char *)py_imbuf_ppm_doc,
NULL},
+ {(char *)"filepath",
+ (getter)py_imbuf_filepath_get,
+ (setter)py_imbuf_filepath_set,
+ (char *)py_imbuf_filepath_doc,
+ NULL},
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};