Skip to content

Commit 22b64ff

Browse files
authored
Merge pull request #8015 from hugovk/pre-commit-clang
Add ClangFormat to pre-commit
2 parents c6fb36f + 82c87c4 commit 22b64ff

35 files changed

+607
-486
lines changed

.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ BinPackParameters: false
99
BreakBeforeBraces: Attach
1010
ColumnLimit: 88
1111
DerivePointerAlignment: false
12+
IndentGotoLabels: false
1213
IndentWidth: 4
1314
Language: Cpp
1415
PointerAlignment: Right

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ repos:
2323
- id: remove-tabs
2424
exclude: (Makefile$|\.bat$|\.cmake$|\.eps$|\.fits$|\.gd$|\.opt$)
2525

26+
- repo: https://github.com/pre-commit/mirrors-clang-format
27+
rev: v18.1.4
28+
hooks:
29+
- id: clang-format
30+
types: [c]
31+
exclude: ^src/thirdparty/
32+
2633
- repo: https://github.com/pre-commit/pygrep-hooks
2734
rev: v1.10.0
2835
hooks:

src/Tk/tkImaging.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,7 @@ PyImagingPhotoPut(
128128
block.pixelPtr = (unsigned char *)im->block;
129129

130130
TK_PHOTO_PUT_BLOCK(
131-
interp,
132-
photo,
133-
&block,
134-
0,
135-
0,
136-
block.width,
137-
block.height,
138-
TK_PHOTO_COMPOSITE_SET);
131+
interp, photo, &block, 0, 0, block.width, block.height, TK_PHOTO_COMPOSITE_SET);
139132

140133
return TCL_OK;
141134
}
@@ -287,7 +280,7 @@ load_tkinter_funcs(void) {
287280
* Return 0 for success, non-zero for failure.
288281
*/
289282

290-
HMODULE* hMods = NULL;
283+
HMODULE *hMods = NULL;
291284
HANDLE hProcess;
292285
DWORD cbNeeded;
293286
unsigned int i;
@@ -313,7 +306,7 @@ load_tkinter_funcs(void) {
313306
#endif
314307
return 1;
315308
}
316-
if (!(hMods = (HMODULE*) malloc(cbNeeded))) {
309+
if (!(hMods = (HMODULE *)malloc(cbNeeded))) {
317310
PyErr_NoMemory();
318311
return 1;
319312
}
@@ -345,7 +338,7 @@ load_tkinter_funcs(void) {
345338
} else if (found_tk == 0) {
346339
PyErr_SetString(PyExc_RuntimeError, "Could not find Tk routines");
347340
}
348-
return (int) ((found_tcl != 1) || (found_tk != 1));
341+
return (int)((found_tcl != 1) || (found_tk != 1));
349342
}
350343

351344
#else /* not Windows */
@@ -400,8 +393,8 @@ _func_loader(void *lib) {
400393
return 1;
401394
}
402395
return (
403-
(TK_PHOTO_PUT_BLOCK =
404-
(Tk_PhotoPutBlock_t)_dfunc(lib, "Tk_PhotoPutBlock")) == NULL);
396+
(TK_PHOTO_PUT_BLOCK = (Tk_PhotoPutBlock_t)_dfunc(lib, "Tk_PhotoPutBlock")) ==
397+
NULL);
405398
}
406399

407400
int

src/_imaging.c

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110

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

115115
/* -------------------------------------------------------------------- */
116116
/* OBJECT ADMINISTRATION */
@@ -533,7 +533,9 @@ getink(PyObject *color, Imaging im, char *ink) {
533533
/* unsigned integer, single layer */
534534
if (rIsInt != 1) {
535535
if (tupleSize != 1) {
536-
PyErr_SetString(PyExc_TypeError, "color must be int or single-element tuple");
536+
PyErr_SetString(
537+
PyExc_TypeError,
538+
"color must be int or single-element tuple");
537539
return NULL;
538540
} else if (!PyArg_ParseTuple(color, "L", &r)) {
539541
return NULL;
@@ -552,15 +554,20 @@ getink(PyObject *color, Imaging im, char *ink) {
552554
a = 255;
553555
if (im->bands == 2) {
554556
if (tupleSize != 1 && tupleSize != 2) {
555-
PyErr_SetString(PyExc_TypeError, "color must be int, or tuple of one or two elements");
557+
PyErr_SetString(
558+
PyExc_TypeError,
559+
"color must be int, or tuple of one or two elements");
556560
return NULL;
557561
} else if (!PyArg_ParseTuple(color, "L|i", &r, &a)) {
558562
return NULL;
559563
}
560564
g = b = r;
561565
} else {
562566
if (tupleSize != 3 && tupleSize != 4) {
563-
PyErr_SetString(PyExc_TypeError, "color must be int, or tuple of one, three or four elements");
567+
PyErr_SetString(
568+
PyExc_TypeError,
569+
"color must be int, or tuple of one, three or four "
570+
"elements");
564571
return NULL;
565572
} else if (!PyArg_ParseTuple(color, "Lii|i", &r, &g, &b, &a)) {
566573
return NULL;
@@ -599,7 +606,9 @@ getink(PyObject *color, Imaging im, char *ink) {
599606
g = (UINT8)(r >> 8);
600607
r = (UINT8)r;
601608
} else if (tupleSize != 3) {
602-
PyErr_SetString(PyExc_TypeError, "color must be int, or tuple of one or three elements");
609+
PyErr_SetString(
610+
PyExc_TypeError,
611+
"color must be int, or tuple of one or three elements");
603612
return NULL;
604613
} else if (!PyArg_ParseTuple(color, "iiL", &b, &g, &r)) {
605614
return NULL;
@@ -1537,14 +1546,14 @@ _putdata(ImagingObject *self, PyObject *args) {
15371546
return NULL;
15381547
}
15391548

1540-
#define set_value_to_item(seq, i) \
1541-
op = PySequence_Fast_GET_ITEM(seq, i); \
1542-
if (PySequence_Check(op)) { \
1543-
PyErr_SetString(PyExc_TypeError, "sequence must be flattened"); \
1544-
return NULL; \
1545-
} else { \
1546-
value = PyFloat_AsDouble(op); \
1547-
}
1549+
#define set_value_to_item(seq, i) \
1550+
op = PySequence_Fast_GET_ITEM(seq, i); \
1551+
if (PySequence_Check(op)) { \
1552+
PyErr_SetString(PyExc_TypeError, "sequence must be flattened"); \
1553+
return NULL; \
1554+
} else { \
1555+
value = PyFloat_AsDouble(op); \
1556+
}
15481557
if (image->image8) {
15491558
if (PyBytes_Check(data)) {
15501559
unsigned char *p;
@@ -1596,8 +1605,10 @@ if (PySequence_Check(op)) { \
15961605
value = value * scale + offset;
15971606
}
15981607
if (image->type == IMAGING_TYPE_SPECIAL) {
1599-
image->image8[y][x * 2 + (bigendian ? 1 : 0)] = CLIP8((int)value % 256);
1600-
image->image8[y][x * 2 + (bigendian ? 0 : 1)] = CLIP8((int)value >> 8);
1608+
image->image8[y][x * 2 + (bigendian ? 1 : 0)] =
1609+
CLIP8((int)value % 256);
1610+
image->image8[y][x * 2 + (bigendian ? 0 : 1)] =
1611+
CLIP8((int)value >> 8);
16011612
} else {
16021613
image->image8[y][x] = (UINT8)CLIP8(value);
16031614
}
@@ -1639,8 +1650,7 @@ if (PySequence_Check(op)) { \
16391650
for (i = x = y = 0; i < n; i++) {
16401651
double value;
16411652
set_value_to_item(seq, i);
1642-
IMAGING_PIXEL_INT32(image, x, y) =
1643-
(INT32)(value * scale + offset);
1653+
IMAGING_PIXEL_INT32(image, x, y) = (INT32)(value * scale + offset);
16441654
if (++x >= (int)image->xsize) {
16451655
x = 0, y++;
16461656
}
@@ -2785,8 +2795,8 @@ _font_getmask(ImagingFontObject *self, PyObject *args) {
27852795
glyph = &self->glyphs[text[i]];
27862796
if (i == 0 || text[i] != text[i - 1]) {
27872797
ImagingDelete(bitmap);
2788-
bitmap =
2789-
ImagingCrop(self->bitmap, glyph->sx0, glyph->sy0, glyph->sx1, glyph->sy1);
2798+
bitmap = ImagingCrop(
2799+
self->bitmap, glyph->sx0, glyph->sy0, glyph->sx1, glyph->sy1);
27902800
if (!bitmap) {
27912801
goto failed;
27922802
}
@@ -3315,7 +3325,8 @@ _draw_polygon(ImagingDrawObject *self, PyObject *args) {
33153325

33163326
free(xy);
33173327

3318-
if (ImagingDrawPolygon(self->image->image, n, ixy, &ink, fill, width, self->blend) < 0) {
3328+
if (ImagingDrawPolygon(self->image->image, n, ixy, &ink, fill, width, self->blend) <
3329+
0) {
33193330
free(ixy);
33203331
return NULL;
33213332
}
@@ -4411,7 +4422,8 @@ setup_module(PyObject *m) {
44114422
PyModule_AddObject(m, "HAVE_XCB", have_xcb);
44124423

44134424
PyObject *pillow_version = PyUnicode_FromString(version);
4414-
PyDict_SetItemString(d, "PILLOW_VERSION", pillow_version ? pillow_version : Py_None);
4425+
PyDict_SetItemString(
4426+
d, "PILLOW_VERSION", pillow_version ? pillow_version : Py_None);
44154427
Py_XDECREF(pillow_version);
44164428

44174429
return 0;

src/_imagingcms.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,8 @@ cms_transform_dealloc(CmsTransformObject *self) {
213213

214214
static cmsUInt32Number
215215
findLCMStype(char *PILmode) {
216-
if (
217-
strcmp(PILmode, "RGB") == 0 ||
218-
strcmp(PILmode, "RGBA") == 0 ||
219-
strcmp(PILmode, "RGBX") == 0
220-
) {
216+
if (strcmp(PILmode, "RGB") == 0 || strcmp(PILmode, "RGBA") == 0 ||
217+
strcmp(PILmode, "RGBX") == 0) {
221218
return TYPE_RGBA_8;
222219
}
223220
if (strcmp(PILmode, "RGBA;16B") == 0) {
@@ -232,10 +229,7 @@ findLCMStype(char *PILmode) {
232229
if (strcmp(PILmode, "L;16B") == 0) {
233230
return TYPE_GRAY_16_SE;
234231
}
235-
if (
236-
strcmp(PILmode, "YCCA") == 0 ||
237-
strcmp(PILmode, "YCC") == 0
238-
) {
232+
if (strcmp(PILmode, "YCCA") == 0 || strcmp(PILmode, "YCC") == 0) {
239233
return TYPE_YCbCr_8;
240234
}
241235
if (strcmp(PILmode, "LAB") == 0) {
@@ -391,7 +385,7 @@ _buildTransform(
391385
iRenderingIntent,
392386
cmsFLAGS);
393387

394-
Py_END_ALLOW_THREADS
388+
Py_END_ALLOW_THREADS;
395389

396390
if (!hTransform) {
397391
PyErr_SetString(PyExc_ValueError, "cannot build transform");
@@ -425,7 +419,7 @@ _buildProofTransform(
425419
iProofIntent,
426420
cmsFLAGS);
427421

428-
Py_END_ALLOW_THREADS
422+
Py_END_ALLOW_THREADS;
429423

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

0 commit comments

Comments
 (0)