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 Oct 28, 2024
1 parent b8ec8aa commit 1719eb2
Show file tree
Hide file tree
Showing 22 changed files with 170 additions and 144 deletions.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
import sys
import warnings
from collections.abc import Iterator
from typing import Any, TYPE_CHECKING
from typing import TYPE_CHECKING, Any

from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext

if TYPE_CHECKING:
from setuptools import _BuildInfo

Expand Down
6 changes: 2 additions & 4 deletions src/Tk/tkImaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,8 @@ PyImagingPhotoPut(
if (im->mode == IMAGING_MODE_1 || im->mode == IMAGING_MODE_L) {
block.pixelSize = 1;
block.offset[0] = block.offset[1] = block.offset[2] = block.offset[3] = 0;
} else if (
im->mode == IMAGING_MODE_RGB || im->mode == IMAGING_MODE_RGBA ||
im->mode == IMAGING_MODE_RGBX || im->mode == IMAGING_MODE_RGBa
) {
} else if (im->mode == IMAGING_MODE_RGB || im->mode == IMAGING_MODE_RGBA ||
im->mode == IMAGING_MODE_RGBX || im->mode == IMAGING_MODE_RGBa) {

Check warning on line 128 in src/Tk/tkImaging.c

View check run for this annotation

Codecov / codecov/patch

src/Tk/tkImaging.c#L128

Added line #L128 was not covered by tests
block.pixelSize = 4;
block.offset[0] = 0;
block.offset[1] = 1;
Expand Down
7 changes: 5 additions & 2 deletions src/_imaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,9 @@ _quantize(ImagingObject *self, PyObject *args) {

if (!self->image->xsize || !self->image->ysize) {
/* no content; return an empty image */
return PyImagingNew(ImagingNew(IMAGING_MODE_P, self->image->xsize, self->image->ysize));
return PyImagingNew(
ImagingNew(IMAGING_MODE_P, self->image->xsize, self->image->ysize)
);
}

return PyImagingNew(ImagingQuantize(self->image, colours, method, kmeans));
Expand Down Expand Up @@ -2004,7 +2006,8 @@ _reduce(ImagingObject *self, PyObject *args) {

static int
isRGB(const ModeID mode) {
return mode == IMAGING_MODE_RGB || mode == IMAGING_MODE_RGBA || mode == IMAGING_MODE_RGBX;
return mode == IMAGING_MODE_RGB || mode == IMAGING_MODE_RGBA ||
mode == IMAGING_MODE_RGBX;
}

static PyObject *
Expand Down
6 changes: 4 additions & 2 deletions src/_imagingcms.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ cms_transform_dealloc(CmsTransformObject *self) {
/* internal functions */

static cmsUInt32Number
findLCMStype(const char * const mode_name) {
findLCMStype(const char *const mode_name) {
const ModeID mode = findModeID(mode_name);
switch (mode) {
case IMAGING_MODE_RGB:
Expand All @@ -230,7 +230,9 @@ findLCMStype(const char * const mode_name) {
return TYPE_YCbCr_8;

Check warning on line 230 in src/_imagingcms.c

View check run for this annotation

Codecov / codecov/patch

src/_imagingcms.c#L226-L230

Added lines #L226 - L230 were not covered by tests
case IMAGING_MODE_LAB:
// 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));
return (
COLORSPACE_SH(PT_LabV2) | CHANNELS_SH(3) | BYTES_SH(1) | EXTRA_SH(1)
);
default:
// This function only accepts a subset of the imaging modes Pillow has.
break;
Expand Down
9 changes: 8 additions & 1 deletion src/_imagingft.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,14 @@ font_getsize(FontObject *self, PyObject *args) {
/* calculate size and bearing for a given string */

if (!PyArg_ParseTuple(
args, "O|zzOzz:getsize", &string, &mode_name, &dir, &features, &lang, &anchor
args,
"O|zzOzz:getsize",
&string,
&mode_name,
&dir,
&features,
&lang,
&anchor
)) {
return NULL;
}
Expand Down
22 changes: 16 additions & 6 deletions src/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,9 @@ static PyTypeObject ImagingDecoderType = {
/* -------------------------------------------------------------------- */

int
get_unpacker(ImagingDecoderObject *decoder, const ModeID mode, const RawModeID rawmode) {
get_unpacker(
ImagingDecoderObject *decoder, const ModeID mode, const RawModeID rawmode
) {
int bits;
ImagingShuffler unpack;

Expand Down Expand Up @@ -324,7 +326,9 @@ PyImaging_BitDecoderNew(PyObject *self, PyObject *args) {
int fill = 0;
int sign = 0;
int ystep = 1;
if (!PyArg_ParseTuple(args, "s|iiiii", &mode_name, &bits, &pad, &fill, &sign, &ystep)) {
if (!PyArg_ParseTuple(
args, "s|iiiii", &mode_name, &bits, &pad, &fill, &sign, &ystep

Check warning on line 330 in src/decode.c

View check run for this annotation

Codecov / codecov/patch

src/decode.c#L330

Added line #L330 was not covered by tests
)) {
return NULL;
}

Expand Down Expand Up @@ -435,7 +439,9 @@ PyImaging_GifDecoderNew(PyObject *self, PyObject *args) {
int bits = 8;
int interlace = 0;
int transparency = -1;
if (!PyArg_ParseTuple(args, "s|iii", &mode_name, &bits, &interlace, &transparency)) {
if (!PyArg_ParseTuple(
args, "s|iii", &mode_name, &bits, &interlace, &transparency
)) {
return NULL;
}

Expand Down Expand Up @@ -508,7 +514,9 @@ PyImaging_LibTiffDecoderNew(PyObject *self, PyObject *args) {
int fp;
uint32_t ifdoffset;

if (!PyArg_ParseTuple(args, "sssiI", &mode_name, &rawmode_name, &compname, &fp, &ifdoffset)) {
if (!PyArg_ParseTuple(
args, "sssiI", &mode_name, &rawmode_name, &compname, &fp, &ifdoffset
)) {
return NULL;
}

Expand Down Expand Up @@ -850,12 +858,14 @@ PyImaging_JpegDecoderNew(PyObject *self, PyObject *args) {
ImagingDecoderObject *decoder;

char *mode_name;
char *rawmode_name; /* what we want from the decoder */
char *rawmode_name; /* what we want from the decoder */
char *jpegmode_name; /* what's in the file */
int scale = 1;
int draft = 0;

if (!PyArg_ParseTuple(args, "ssz|ii", &mode_name, &rawmode_name, &jpegmode_name, &scale, &draft)) {
if (!PyArg_ParseTuple(
args, "ssz|ii", &mode_name, &rawmode_name, &jpegmode_name, &scale, &draft
)) {
return NULL;
}

Expand Down
13 changes: 10 additions & 3 deletions src/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,12 @@ get_packer(ImagingEncoderObject *encoder, const ModeID mode, const RawModeID raw
pack = ImagingFindPacker(mode, rawmode, &bits);
if (!pack) {
Py_DECREF(encoder);
PyErr_Format(PyExc_ValueError, "No packer found from %s to %s", getModeData(mode)->name, getRawModeData(rawmode)->name);
PyErr_Format(
PyExc_ValueError,

Check warning on line 371 in src/encode.c

View check run for this annotation

Codecov / codecov/patch

src/encode.c#L370-L371

Added lines #L370 - L371 were not covered by tests
"No packer found from %s to %s",
getModeData(mode)->name,
getRawModeData(rawmode)->name

Check warning on line 374 in src/encode.c

View check run for this annotation

Codecov / codecov/patch

src/encode.c#L373-L374

Added lines #L373 - L374 were not covered by tests
);
return -1;
}

Expand Down Expand Up @@ -407,7 +412,9 @@ PyImaging_GifEncoderNew(PyObject *self, PyObject *args) {
char *rawmode_name;
Py_ssize_t bits = 8;
Py_ssize_t interlace = 0;
if (!PyArg_ParseTuple(args, "ss|nn", &mode_name, &rawmode_name, &bits, &interlace)) {
if (!PyArg_ParseTuple(
args, "ss|nn", &mode_name, &rawmode_name, &bits, &interlace
)) {
return NULL;
}

Expand Down Expand Up @@ -1152,7 +1159,7 @@ PyImaging_JpegEncoderNew(PyObject *self, PyObject *args) {
}

const ModeID mode = findModeID(mode_name);
RawModeID rawmode = findRawModeID(rawmode_name);
RawModeID rawmode = findRawModeID(rawmode_name);

// libjpeg-turbo supports different output formats.
// We are choosing Pillow's native format (3 color bytes + 1 padding)
Expand Down
3 changes: 0 additions & 3 deletions src/libImaging/Access.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include "Imaging.h"


/* fetch individual pixel */

static void
Expand Down Expand Up @@ -102,7 +101,6 @@ get_pixel_32B(Imaging im, int x, int y, void *color) {
#endif
}


/* store individual pixel */

static void
Expand Down Expand Up @@ -153,7 +151,6 @@ put_pixel_32(Imaging im, int x, int y, const void *color) {
memcpy(&im->image32[y][x], color, sizeof(INT32));
}


static struct ImagingAccessInstance accessors[] = {
{IMAGING_MODE_1, get_pixel_8, put_pixel_8},
{IMAGING_MODE_L, get_pixel_8, put_pixel_8},
Expand Down
30 changes: 15 additions & 15 deletions src/libImaging/Chops.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@
} \
return imOut;

#define CHOP2(operation, mode) \
int x, y; \
Imaging imOut; \
imOut = create(imIn1, imIn2, mode); \
if (!imOut) { \
return NULL; \
} \
for (y = 0; y < imOut->ysize; y++) { \
UINT8 *out = (UINT8 *)imOut->image[y]; \
UINT8 *in1 = (UINT8 *)imIn1->image[y]; \
UINT8 *in2 = (UINT8 *)imIn2->image[y]; \
for (x = 0; x < imOut->linesize; x++) { \
out[x] = operation; \
} \
} \
#define CHOP2(operation, mode) \
int x, y; \
Imaging imOut; \
imOut = create(imIn1, imIn2, mode); \
if (!imOut) { \
return NULL; \
} \
for (y = 0; y < imOut->ysize; y++) { \
UINT8 *out = (UINT8 *)imOut->image[y]; \
UINT8 *in1 = (UINT8 *)imIn1->image[y]; \
UINT8 *in2 = (UINT8 *)imIn2->image[y]; \
for (x = 0; x < imOut->linesize; x++) { \
out[x] = operation; \
} \
} \
return imOut;

static Imaging
Expand Down
27 changes: 13 additions & 14 deletions src/libImaging/Convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -1624,9 +1624,7 @@ static struct {
};

static Imaging
convert(
Imaging imOut, Imaging imIn, ModeID mode, ImagingPalette palette, int dither
) {
convert(Imaging imOut, Imaging imIn, ModeID mode, ImagingPalette palette, int dither) {
ImagingSectionCookie cookie;
ImagingShuffler convert;

Expand Down Expand Up @@ -1677,7 +1675,11 @@ convert(
#else
static char buf[100];
snprintf(
buf, 100, "conversion from %.10s to %.10s not supported", getModeData(imIn->mode)->name, getModeData(mode)->name
buf,
100,
"conversion from %.10s to %.10s not supported",
getModeData(imIn->mode)->name,
getModeData(mode)->name
);
return (Imaging)ImagingError_ValueError(buf);
#endif
Expand Down Expand Up @@ -1722,25 +1724,22 @@ ImagingConvertTransparent(Imaging imIn, const ModeID mode, int r, int g, int b)
return (Imaging)ImagingError_ModeError();
}

if (imIn->mode == IMAGING_MODE_RGB && (mode == IMAGING_MODE_RGBA || mode == IMAGING_MODE_RGBa)) {
if (imIn->mode == IMAGING_MODE_RGB &&
(mode == IMAGING_MODE_RGBA || mode == IMAGING_MODE_RGBa)) {
convert = rgb2rgba;
if (mode == IMAGING_MODE_RGBa) {
premultiplied = 1;
}
} else if (imIn->mode == IMAGING_MODE_RGB && (mode == IMAGING_MODE_LA || mode == IMAGING_MODE_La)) {
} else if (imIn->mode == IMAGING_MODE_RGB &&
(mode == IMAGING_MODE_LA || mode == IMAGING_MODE_La)) {
convert = rgb2la;
source_transparency = 1;
if (mode == IMAGING_MODE_La) {
premultiplied = 1;
}
} else if ((imIn->mode == IMAGING_MODE_1 ||
imIn->mode == IMAGING_MODE_I ||
imIn->mode == IMAGING_MODE_I_16 ||
imIn->mode == IMAGING_MODE_L
) && (
mode == IMAGING_MODE_RGBA ||
mode == IMAGING_MODE_LA
)) {
} else if ((imIn->mode == IMAGING_MODE_1 || imIn->mode == IMAGING_MODE_I ||
imIn->mode == IMAGING_MODE_I_16 || imIn->mode == IMAGING_MODE_L) &&
(mode == IMAGING_MODE_RGBA || mode == IMAGING_MODE_LA)) {
if (imIn->mode == IMAGING_MODE_1) {
convert = bit2rgb;
} else if (imIn->mode == IMAGING_MODE_I) {
Expand Down
12 changes: 4 additions & 8 deletions src/libImaging/Fill.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ ImagingFillLinearGradient(const ModeID mode) {
Imaging im;
int y;

if (mode != IMAGING_MODE_1 && mode != IMAGING_MODE_F &&
mode != IMAGING_MODE_I && mode != IMAGING_MODE_L &&
mode != IMAGING_MODE_P
) {
if (mode != IMAGING_MODE_1 && mode != IMAGING_MODE_F && mode != IMAGING_MODE_I &&
mode != IMAGING_MODE_L && mode != IMAGING_MODE_P) {
return (Imaging)ImagingError_ModeError();
}

Expand Down Expand Up @@ -110,10 +108,8 @@ ImagingFillRadialGradient(const ModeID mode) {
int x, y;
int d;

if (mode != IMAGING_MODE_1 && mode != IMAGING_MODE_F &&
mode != IMAGING_MODE_I && mode != IMAGING_MODE_L &&
mode != IMAGING_MODE_P
) {
if (mode != IMAGING_MODE_1 && mode != IMAGING_MODE_F && mode != IMAGING_MODE_I &&
mode != IMAGING_MODE_L && mode != IMAGING_MODE_P) {
return (Imaging)ImagingError_ModeError();
}

Expand Down
9 changes: 4 additions & 5 deletions src/libImaging/GetBBox.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,10 @@ ImagingGetBBox(Imaging im, int bbox[4], int alpha_only) {
INT32 mask = 0xffffffff;
if (im->bands == 3) {
((UINT8 *)&mask)[3] = 0;
} else if (alpha_only && (
im->mode == IMAGING_MODE_RGBa || im->mode == IMAGING_MODE_RGBA ||
im->mode == IMAGING_MODE_La || im->mode == IMAGING_MODE_LA ||
im->mode == IMAGING_MODE_PA
)) {
} else if (alpha_only &&
(im->mode == IMAGING_MODE_RGBa || im->mode == IMAGING_MODE_RGBA ||
im->mode == IMAGING_MODE_La || im->mode == IMAGING_MODE_LA ||
im->mode == IMAGING_MODE_PA)) {
#ifdef WORDS_BIGENDIAN
mask = 0x000000ff;
#else
Expand Down
13 changes: 7 additions & 6 deletions src/libImaging/Imaging.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ typedef struct {

struct ImagingMemoryInstance {
/* Format */
ModeID mode; /* Band names ("1", "L", "P", "RGB", "RGBA", "CMYK", "YCbCr", "BGR;xy") */
int type; /* Data type (IMAGING_TYPE_*) */
int depth; /* Depth (ignored in this version) */
int bands; /* Number of bands (1, 2, 3, or 4) */
int xsize; /* Image dimension. */
ModeID
mode; /* Band names ("1", "L", "P", "RGB", "RGBA", "CMYK", "YCbCr", "BGR;xy") */
int type; /* Data type (IMAGING_TYPE_*) */
int depth; /* Depth (ignored in this version) */
int bands; /* Number of bands (1, 2, 3, or 4) */
int xsize; /* Image dimension. */
int ysize;

/* Colour palette (for "P" images only) */
Expand Down Expand Up @@ -128,7 +129,7 @@ struct ImagingAccessInstance {
struct ImagingHistogramInstance {
/* Format */
ModeID mode; /* ModeID of corresponding source image */
int bands; /* Number of bands (1, 3, or 4) */
int bands; /* Number of bands (1, 3, or 4) */

/* Data */
long *histogram; /* Histogram (bands*256 longs) */
Expand Down
5 changes: 2 additions & 3 deletions src/libImaging/JpegDecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,8 @@ ImagingJpegDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t by
context->cinfo.out_color_space = JCS_EXT_RGBX;
}
#endif
else if (
context->rawmode == IMAGING_RAWMODE_CMYK ||
context->rawmode == IMAGING_RAWMODE_CMYK_I) {
else if (context->rawmode == IMAGING_RAWMODE_CMYK ||
context->rawmode == IMAGING_RAWMODE_CMYK_I) {
context->cinfo.out_color_space = JCS_CMYK;
} else if (context->rawmode == IMAGING_RAWMODE_YCbCr) {
context->cinfo.out_color_space = JCS_YCbCr;
Expand Down
7 changes: 2 additions & 5 deletions src/libImaging/Matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,8 @@ ImagingConvertMatrix(Imaging im, const ModeID mode, float m[]) {
}
}
ImagingSectionLeave(&cookie);
} else if (
mode == IMAGING_MODE_HSV ||
mode == IMAGING_MODE_LAB ||
mode == IMAGING_MODE_RGB
) {
} else if (mode == IMAGING_MODE_HSV || mode == IMAGING_MODE_LAB ||
mode == IMAGING_MODE_RGB) {
imOut = ImagingNewDirty(mode, im->xsize, im->ysize);
if (!imOut) {
return NULL;
Expand Down
Loading

0 comments on commit 1719eb2

Please sign in to comment.