Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Apr 25, 2024
1 parent b4e59b0 commit b2e3859
Show file tree
Hide file tree
Showing 33 changed files with 605 additions and 485 deletions.
19 changes: 6 additions & 13 deletions src/Tk/tkImaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,7 @@ PyImagingPhotoPut(
block.pixelPtr = (unsigned char *)im->block;

TK_PHOTO_PUT_BLOCK(
interp,
photo,
&block,
0,
0,
block.width,
block.height,
TK_PHOTO_COMPOSITE_SET);
interp, photo, &block, 0, 0, block.width, block.height, TK_PHOTO_COMPOSITE_SET);

return TCL_OK;
}
Expand Down Expand Up @@ -287,7 +280,7 @@ load_tkinter_funcs(void) {
* Return 0 for success, non-zero for failure.
*/

HMODULE* hMods = NULL;
HMODULE *hMods = NULL;
HANDLE hProcess;
DWORD cbNeeded;
unsigned int i;
Expand All @@ -313,7 +306,7 @@ load_tkinter_funcs(void) {
#endif
return 1;
}
if (!(hMods = (HMODULE*) malloc(cbNeeded))) {
if (!(hMods = (HMODULE *)malloc(cbNeeded))) {
PyErr_NoMemory();
return 1;
}
Expand Down Expand Up @@ -345,7 +338,7 @@ load_tkinter_funcs(void) {
} else if (found_tk == 0) {
PyErr_SetString(PyExc_RuntimeError, "Could not find Tk routines");
}
return (int) ((found_tcl != 1) || (found_tk != 1));
return (int)((found_tcl != 1) || (found_tk != 1));
}

#else /* not Windows */
Expand Down Expand Up @@ -400,8 +393,8 @@ _func_loader(void *lib) {
return 1;
}
return (
(TK_PHOTO_PUT_BLOCK =
(Tk_PhotoPutBlock_t)_dfunc(lib, "Tk_PhotoPutBlock")) == NULL);
(TK_PHOTO_PUT_BLOCK = (Tk_PhotoPutBlock_t)_dfunc(lib, "Tk_PhotoPutBlock")) ==
NULL);
}

int
Expand Down
54 changes: 33 additions & 21 deletions src/_imaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@

#define B16(p, i) ((((int)p[(i)]) << 8) + p[(i) + 1])
#define L16(p, i) ((((int)p[(i) + 1]) << 8) + p[(i)])
#define S16(v) ((v) < 32768 ? (v) : ((v)-65536))
#define S16(v) ((v) < 32768 ? (v) : ((v) - 65536))

/* -------------------------------------------------------------------- */
/* OBJECT ADMINISTRATION */
Expand Down Expand Up @@ -533,7 +533,9 @@ getink(PyObject *color, Imaging im, char *ink) {
/* unsigned integer, single layer */
if (rIsInt != 1) {
if (tupleSize != 1) {
PyErr_SetString(PyExc_TypeError, "color must be int or single-element tuple");
PyErr_SetString(
PyExc_TypeError,
"color must be int or single-element tuple");
return NULL;
} else if (!PyArg_ParseTuple(color, "L", &r)) {
return NULL;
Expand All @@ -552,15 +554,20 @@ getink(PyObject *color, Imaging im, char *ink) {
a = 255;
if (im->bands == 2) {
if (tupleSize != 1 && tupleSize != 2) {
PyErr_SetString(PyExc_TypeError, "color must be int, or tuple of one or two elements");
PyErr_SetString(
PyExc_TypeError,
"color must be int, or tuple of one or two elements");
return NULL;
} else if (!PyArg_ParseTuple(color, "L|i", &r, &a)) {
return NULL;
}
g = b = r;
} else {
if (tupleSize != 3 && tupleSize != 4) {
PyErr_SetString(PyExc_TypeError, "color must be int, or tuple of one, three or four elements");
PyErr_SetString(
PyExc_TypeError,
"color must be int, or tuple of one, three or four "
"elements");
return NULL;
} else if (!PyArg_ParseTuple(color, "Lii|i", &r, &g, &b, &a)) {
return NULL;
Expand Down Expand Up @@ -599,7 +606,9 @@ getink(PyObject *color, Imaging im, char *ink) {
g = (UINT8)(r >> 8);
r = (UINT8)r;
} else if (tupleSize != 3) {
PyErr_SetString(PyExc_TypeError, "color must be int, or tuple of one or three elements");
PyErr_SetString(
PyExc_TypeError,
"color must be int, or tuple of one or three elements");
return NULL;
} else if (!PyArg_ParseTuple(color, "iiL", &b, &g, &r)) {
return NULL;
Expand Down Expand Up @@ -1537,14 +1546,14 @@ _putdata(ImagingObject *self, PyObject *args) {
return NULL;
}

#define set_value_to_item(seq, i) \
op = PySequence_Fast_GET_ITEM(seq, i); \
if (PySequence_Check(op)) { \
PyErr_SetString(PyExc_TypeError, "sequence must be flattened"); \
return NULL; \
} else { \
value = PyFloat_AsDouble(op); \
}
#define set_value_to_item(seq, i) \
op = PySequence_Fast_GET_ITEM(seq, i); \
if (PySequence_Check(op)) { \
PyErr_SetString(PyExc_TypeError, "sequence must be flattened"); \
return NULL; \
} else { \
value = PyFloat_AsDouble(op); \
}
if (image->image8) {
if (PyBytes_Check(data)) {
unsigned char *p;
Expand Down Expand Up @@ -1596,8 +1605,10 @@ if (PySequence_Check(op)) { \
value = value * scale + offset;
}
if (image->type == IMAGING_TYPE_SPECIAL) {
image->image8[y][x * 2 + (bigendian ? 1 : 0)] = CLIP8((int)value % 256);
image->image8[y][x * 2 + (bigendian ? 0 : 1)] = CLIP8((int)value >> 8);
image->image8[y][x * 2 + (bigendian ? 1 : 0)] =
CLIP8((int)value % 256);
image->image8[y][x * 2 + (bigendian ? 0 : 1)] =
CLIP8((int)value >> 8);
} else {
image->image8[y][x] = (UINT8)CLIP8(value);
}
Expand Down Expand Up @@ -1639,8 +1650,7 @@ if (PySequence_Check(op)) { \
for (i = x = y = 0; i < n; i++) {
double value;
set_value_to_item(seq, i);
IMAGING_PIXEL_INT32(image, x, y) =
(INT32)(value * scale + offset);
IMAGING_PIXEL_INT32(image, x, y) = (INT32)(value * scale + offset);
if (++x >= (int)image->xsize) {
x = 0, y++;
}
Expand Down Expand Up @@ -2785,8 +2795,8 @@ _font_getmask(ImagingFontObject *self, PyObject *args) {
glyph = &self->glyphs[text[i]];
if (i == 0 || text[i] != text[i - 1]) {
ImagingDelete(bitmap);
bitmap =
ImagingCrop(self->bitmap, glyph->sx0, glyph->sy0, glyph->sx1, glyph->sy1);
bitmap = ImagingCrop(
self->bitmap, glyph->sx0, glyph->sy0, glyph->sx1, glyph->sy1);
if (!bitmap) {
goto failed;
}
Expand Down Expand Up @@ -3315,7 +3325,8 @@ _draw_polygon(ImagingDrawObject *self, PyObject *args) {

free(xy);

if (ImagingDrawPolygon(self->image->image, n, ixy, &ink, fill, width, self->blend) < 0) {
if (ImagingDrawPolygon(self->image->image, n, ixy, &ink, fill, width, self->blend) <
0) {
free(ixy);
return NULL;
}
Expand Down Expand Up @@ -4411,7 +4422,8 @@ setup_module(PyObject *m) {
PyModule_AddObject(m, "HAVE_XCB", have_xcb);

PyObject *pillow_version = PyUnicode_FromString(version);
PyDict_SetItemString(d, "PILLOW_VERSION", pillow_version ? pillow_version : Py_None);
PyDict_SetItemString(
d, "PILLOW_VERSION", pillow_version ? pillow_version : Py_None);
Py_XDECREF(pillow_version);

return 0;
Expand Down
7 changes: 3 additions & 4 deletions src/_imagingcms.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ findLCMStype(char *PILmode) {
} else if (strcmp(PILmode, "LAB") == 0) {
// LabX equivalent like ALab, but not reversed -- no #define in lcms2
return (COLORSPACE_SH(PT_LabV2) | CHANNELS_SH(3) | BYTES_SH(1) | EXTRA_SH(1));
}
else {
} else {
/* take a wild guess... */
return TYPE_GRAY_8;
}
Expand Down Expand Up @@ -390,7 +389,7 @@ _buildTransform(

Py_END_ALLOW_THREADS

if (!hTransform) {
if (!hTransform) {
PyErr_SetString(PyExc_ValueError, "cannot build transform");
}

Expand Down Expand Up @@ -424,7 +423,7 @@ _buildProofTransform(

Py_END_ALLOW_THREADS

if (!hTransform) {
if (!hTransform) {
PyErr_SetString(PyExc_ValueError, "cannot build proof transform");
}

Expand Down

0 comments on commit b2e3859

Please sign in to comment.