Fix imbuf.new & resize allowing zero & negative dimensions
This commit is contained in:
parent
a6285339ba
commit
b8e536f381
|
@ -93,7 +93,7 @@ static PyObject *py_imbuf_resize(Py_ImBuf *self, PyObject *args, PyObject *kw)
|
|||
{
|
||||
PY_IMBUF_CHECK_OBJ(self);
|
||||
|
||||
uint size[2];
|
||||
int size[2];
|
||||
|
||||
enum { FAST, BILINEAR };
|
||||
const struct PyC_StringEnumItems method_items[] = {
|
||||
|
@ -104,11 +104,16 @@ static PyObject *py_imbuf_resize(Py_ImBuf *self, PyObject *args, PyObject *kw)
|
|||
struct PyC_StringEnum method = {method_items, FAST};
|
||||
|
||||
static const char *_keywords[] = {"size", "method", NULL};
|
||||
static _PyArg_Parser _parser = {"(II)|O&:resize", _keywords, 0};
|
||||
static _PyArg_Parser _parser = {"(ii)|O&:resize", _keywords, 0};
|
||||
if (!_PyArg_ParseTupleAndKeywordsFast(
|
||||
args, kw, &_parser, &size[0], &size[1], PyC_ParseStringEnum, &method)) {
|
||||
return NULL;
|
||||
}
|
||||
if (size[0] <= 0 || size[1] <= 0) {
|
||||
PyErr_Format(PyExc_ValueError, "resize: Image size cannot be below 1 (%d, %d)", UNPACK2(size));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (method.value_found == FAST) {
|
||||
IMB_scalefastImBuf(self->ibuf, UNPACK2(size));
|
||||
}
|
||||
|
@ -427,6 +432,10 @@ static PyObject *M_imbuf_new(PyObject *UNUSED(self), PyObject *args, PyObject *k
|
|||
if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &size[0], &size[1])) {
|
||||
return NULL;
|
||||
}
|
||||
if (size[0] <= 0 || size[1] <= 0) {
|
||||
PyErr_Format(PyExc_ValueError, "new: Image size cannot be below 1 (%d, %d)", UNPACK2(size));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* TODO, make options */
|
||||
const uchar planes = 4;
|
||||
|
|
Loading…
Reference in New Issue