[Bf-blender-cvs] [f006fc7371f] temp-lanpr-cleanup: ImBuf Py API: add filepath access
Campbell Barton
noreply at git.blender.org
Mon Sep 16 14:56:38 CEST 2019
Commit: f006fc7371fe0c4e0940bc3afd7dbcf666dcfaa4
Author: Campbell Barton
Date: Mon Sep 16 10:31:17 2019 +1000
Branches: temp-lanpr-cleanup
https://developer.blender.org/rBf006fc7371fe0c4e0940bc3afd7dbcf666dcfaa4
ImBuf Py API: add filepath access
D5804 by @cmbasnett with setter support added.
===================================================================
M source/blender/python/generic/imbuf_py_api.c
===================================================================
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 */
};
More information about the Bf-blender-cvs
mailing list