mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-15 06:07:33 +03:00
Use s# in PyArg_ParseTuple
This commit is contained in:
parent
f916b5dc87
commit
7f48567002
|
@ -11,7 +11,6 @@
|
||||||
* See the README file for information on usage and redistribution.
|
* See the README file for information on usage and redistribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Python.h"
|
|
||||||
#include "libImaging/Imaging.h"
|
#include "libImaging/Imaging.h"
|
||||||
|
|
||||||
#define LUT_SIZE (1 << 9)
|
#define LUT_SIZE (1 << 9)
|
||||||
|
@ -30,7 +29,7 @@
|
||||||
static PyObject *
|
static PyObject *
|
||||||
apply(PyObject *self, PyObject *args) {
|
apply(PyObject *self, PyObject *args) {
|
||||||
const char *lut;
|
const char *lut;
|
||||||
PyObject *py_lut, *i0, *i1;
|
PyObject *i0, *i1;
|
||||||
Py_ssize_t lut_len;
|
Py_ssize_t lut_len;
|
||||||
Imaging imgin, imgout;
|
Imaging imgin, imgout;
|
||||||
int width, height;
|
int width, height;
|
||||||
|
@ -38,25 +37,15 @@ apply(PyObject *self, PyObject *args) {
|
||||||
UINT8 **inrows, **outrows;
|
UINT8 **inrows, **outrows;
|
||||||
int num_changed_pixels = 0;
|
int num_changed_pixels = 0;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "OOO", &py_lut, &i0, &i1)) {
|
if (!PyArg_ParseTuple(args, "s#OO", &lut, &lut_len, &i0, &i1)) {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "Argument parsing problem");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PyBytes_Check(py_lut)) {
|
|
||||||
PyErr_SetString(PyExc_RuntimeError, "The morphology LUT is not a bytes object");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
lut_len = PyBytes_Size(py_lut);
|
|
||||||
|
|
||||||
if (lut_len < LUT_SIZE) {
|
if (lut_len < LUT_SIZE) {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "The morphology LUT has the wrong size");
|
PyErr_SetString(PyExc_RuntimeError, "The morphology LUT has the wrong size");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
lut = PyBytes_AsString(py_lut);
|
|
||||||
|
|
||||||
if (!PyCapsule_IsValid(i0, IMAGING_MAGIC) ||
|
if (!PyCapsule_IsValid(i0, IMAGING_MAGIC) ||
|
||||||
!PyCapsule_IsValid(i1, IMAGING_MAGIC)) {
|
!PyCapsule_IsValid(i1, IMAGING_MAGIC)) {
|
||||||
PyErr_Format(
|
PyErr_Format(
|
||||||
|
@ -137,39 +126,22 @@ apply(PyObject *self, PyObject *args) {
|
||||||
static PyObject *
|
static PyObject *
|
||||||
match(PyObject *self, PyObject *args) {
|
match(PyObject *self, PyObject *args) {
|
||||||
const char *lut;
|
const char *lut;
|
||||||
PyObject *py_lut, *i0;
|
PyObject *i0;
|
||||||
Py_ssize_t lut_len;
|
Py_ssize_t lut_len;
|
||||||
Imaging imgin;
|
Imaging imgin;
|
||||||
int width, height;
|
int width, height;
|
||||||
int row_idx, col_idx;
|
int row_idx, col_idx;
|
||||||
UINT8 **inrows;
|
UINT8 **inrows;
|
||||||
PyObject *ret = PyList_New(0);
|
|
||||||
if (ret == NULL) {
|
if (!PyArg_ParseTuple(args, "s#O", &lut, &lut_len, &i0)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "OO", &py_lut, &i0)) {
|
|
||||||
Py_DECREF(ret);
|
|
||||||
PyErr_SetString(PyExc_RuntimeError, "Argument parsing problem");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!PyBytes_Check(py_lut)) {
|
|
||||||
Py_DECREF(ret);
|
|
||||||
PyErr_SetString(PyExc_RuntimeError, "The morphology LUT is not a bytes object");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
lut_len = PyBytes_Size(py_lut);
|
|
||||||
|
|
||||||
if (lut_len < LUT_SIZE) {
|
if (lut_len < LUT_SIZE) {
|
||||||
Py_DECREF(ret);
|
|
||||||
PyErr_SetString(PyExc_RuntimeError, "The morphology LUT has the wrong size");
|
PyErr_SetString(PyExc_RuntimeError, "The morphology LUT has the wrong size");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
lut = PyBytes_AsString(py_lut);
|
|
||||||
|
|
||||||
if (!PyCapsule_IsValid(i0, IMAGING_MAGIC)) {
|
if (!PyCapsule_IsValid(i0, IMAGING_MAGIC)) {
|
||||||
PyErr_Format(
|
PyErr_Format(
|
||||||
PyExc_TypeError, "Expected PyCapsule with '%s' name.", IMAGING_MAGIC
|
PyExc_TypeError, "Expected PyCapsule with '%s' name.", IMAGING_MAGIC
|
||||||
|
@ -180,11 +152,15 @@ match(PyObject *self, PyObject *args) {
|
||||||
imgin = (Imaging)PyCapsule_GetPointer(i0, IMAGING_MAGIC);
|
imgin = (Imaging)PyCapsule_GetPointer(i0, IMAGING_MAGIC);
|
||||||
|
|
||||||
if (imgin->type != IMAGING_TYPE_UINT8 || imgin->bands != 1) {
|
if (imgin->type != IMAGING_TYPE_UINT8 || imgin->bands != 1) {
|
||||||
Py_DECREF(ret);
|
|
||||||
PyErr_SetString(PyExc_RuntimeError, "Unsupported image type");
|
PyErr_SetString(PyExc_RuntimeError, "Unsupported image type");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyObject *ret = PyList_New(0);
|
||||||
|
if (ret == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
inrows = imgin->image8;
|
inrows = imgin->image8;
|
||||||
width = imgin->xsize;
|
width = imgin->xsize;
|
||||||
height = imgin->ysize;
|
height = imgin->ysize;
|
||||||
|
@ -236,14 +212,8 @@ get_on_pixels(PyObject *self, PyObject *args) {
|
||||||
UINT8 **rows;
|
UINT8 **rows;
|
||||||
int row_idx, col_idx;
|
int row_idx, col_idx;
|
||||||
int width, height;
|
int width, height;
|
||||||
PyObject *ret = PyList_New(0);
|
|
||||||
if (ret == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "O", &i0)) {
|
if (!PyArg_ParseTuple(args, "O", &i0)) {
|
||||||
Py_DECREF(ret);
|
|
||||||
PyErr_SetString(PyExc_RuntimeError, "Argument parsing problem");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,6 +229,11 @@ get_on_pixels(PyObject *self, PyObject *args) {
|
||||||
width = img->xsize;
|
width = img->xsize;
|
||||||
height = img->ysize;
|
height = img->ysize;
|
||||||
|
|
||||||
|
PyObject *ret = PyList_New(0);
|
||||||
|
if (ret == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
for (row_idx = 0; row_idx < height; row_idx++) {
|
for (row_idx = 0; row_idx < height; row_idx++) {
|
||||||
UINT8 *row = rows[row_idx];
|
UINT8 *row = rows[row_idx];
|
||||||
for (col_idx = 0; col_idx < width; col_idx++) {
|
for (col_idx = 0; col_idx < width; col_idx++) {
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
* Copyright (c) Fredrik Lundh 1995-2003.
|
* Copyright (c) Fredrik Lundh 1995-2003.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define PY_SSIZE_T_CLEAN
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
|
|
||||||
/* Check that we have an ANSI compliant compiler */
|
/* Check that we have an ANSI compliant compiler */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user