ImBuf Py API: rename filename to filepath

Match RNA image naming.
This commit is contained in:
2019-09-16 09:06:40 +10:00
parent b043bef000
commit 367ce71b47

View File

@@ -258,7 +258,7 @@ static PyObject *py_imbuf_repr(Py_ImBuf *self)
const ImBuf *ibuf = self->ibuf; const ImBuf *ibuf = self->ibuf;
if (ibuf != NULL) { if (ibuf != NULL) {
return PyUnicode_FromFormat( return PyUnicode_FromFormat(
"<imbuf: address=%p, filename='%s', size=(%d, %d)>", ibuf, ibuf->name, ibuf->x, ibuf->y); "<imbuf: address=%p, filepath='%s', size=(%d, %d)>", ibuf, ibuf->name, ibuf->x, ibuf->y);
} }
else { else {
return PyUnicode_FromString("<imbuf: address=0x0>"); return PyUnicode_FromString("<imbuf: address=0x0>");
@@ -375,73 +375,73 @@ static PyObject *M_imbuf_new(PyObject *UNUSED(self), PyObject *args, PyObject *k
} }
PyDoc_STRVAR(M_imbuf_load_doc, PyDoc_STRVAR(M_imbuf_load_doc,
".. function:: load(filename)\n" ".. function:: load(filepath)\n"
"\n" "\n"
" Load an image from a file.\n" " Load an image from a file.\n"
"\n" "\n"
" :arg filename: the filename of the image.\n" " :arg filepath: the filepath of the image.\n"
" :type filename: string\n" " :type filepath: string\n"
" :return: the newly loaded image.\n" " :return: the newly loaded image.\n"
" :rtype: :class:`ImBuf`\n"); " :rtype: :class:`ImBuf`\n");
static PyObject *M_imbuf_load(PyObject *UNUSED(self), PyObject *args, PyObject *kw) static PyObject *M_imbuf_load(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
{ {
const char *filename; const char *filepath;
static const char *_keywords[] = {"filename", NULL}; static const char *_keywords[] = {"filepath", NULL};
static _PyArg_Parser _parser = {"s:load", _keywords, 0}; static _PyArg_Parser _parser = {"s:load", _keywords, 0};
if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &filename)) { if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &filepath)) {
return NULL; return NULL;
} }
const int file = BLI_open(filename, O_BINARY | O_RDONLY, 0); const int file = BLI_open(filepath, O_BINARY | O_RDONLY, 0);
if (file == -1) { if (file == -1) {
PyErr_Format(PyExc_IOError, "load: %s, failed to open file '%s'", strerror(errno)); PyErr_Format(PyExc_IOError, "load: %s, failed to open file '%s'", strerror(errno));
return NULL; return NULL;
} }
ImBuf *ibuf = IMB_loadifffile(file, filename, IB_rect, NULL, filename); ImBuf *ibuf = IMB_loadifffile(file, filepath, IB_rect, NULL, filepath);
close(file); close(file);
if (ibuf == NULL) { if (ibuf == NULL) {
PyErr_Format( PyErr_Format(
PyExc_ValueError, "load: Unable to recognize image format for file '%s'", filename); PyExc_ValueError, "load: Unable to recognize image format for file '%s'", filepath);
return NULL; return NULL;
} }
BLI_strncpy(ibuf->name, filename, sizeof(ibuf->name)); BLI_strncpy(ibuf->name, filepath, sizeof(ibuf->name));
return Py_ImBuf_CreatePyObject(ibuf); return Py_ImBuf_CreatePyObject(ibuf);
} }
PyDoc_STRVAR(M_imbuf_write_doc, PyDoc_STRVAR(M_imbuf_write_doc,
".. function:: write(image, filename)\n" ".. function:: write(image, filepath)\n"
"\n" "\n"
" Write an image.\n" " Write an image.\n"
"\n" "\n"
" :arg image: the image to write.\n" " :arg image: the image to write.\n"
" :type image: :class:`ImBuf`\n" " :type image: :class:`ImBuf`\n"
" :arg filename: the filename of the image.\n" " :arg filepath: the filepath of the image.\n"
" :type filename: string\n"); " :type filepath: string\n");
static PyObject *M_imbuf_write(PyObject *UNUSED(self), PyObject *args, PyObject *kw) static PyObject *M_imbuf_write(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
{ {
Py_ImBuf *py_imb; Py_ImBuf *py_imb;
const char *filename = NULL; const char *filepath = NULL;
static const char *_keywords[] = {"image", "filename", NULL}; static const char *_keywords[] = {"image", "filepath", NULL};
static _PyArg_Parser _parser = {"O!|s:write", _keywords, 0}; static _PyArg_Parser _parser = {"O!|s:write", _keywords, 0};
if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &Py_ImBuf_Type, &py_imb, &filename)) { if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &Py_ImBuf_Type, &py_imb, &filepath)) {
return NULL; return NULL;
} }
if (filename == NULL) { if (filepath == NULL) {
filename = py_imb->ibuf->name; filepath = py_imb->ibuf->name;
} }
bool ok = IMB_saveiff(py_imb->ibuf, filename, IB_rect); bool ok = IMB_saveiff(py_imb->ibuf, filepath, IB_rect);
if (ok == false) { if (ok == false) {
PyErr_Format( PyErr_Format(
PyExc_IOError, "write: Unable to write image file (%s) '%s'", strerror(errno), filename); PyExc_IOError, "write: Unable to write image file (%s) '%s'", strerror(errno), filepath);
return NULL; return NULL;
} }