From 7b3179161f8c74eee1e02e551a00af9a369c878c Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Sun, 15 Sep 2024 13:37:30 +0200 Subject: [PATCH 01/17] MIN and MAX macros in ImagingUtils --- src/_imagingmath.c | 12 ++++++------ src/libImaging/BoxBlur.c | 3 --- src/libImaging/Convert.c | 3 --- src/libImaging/ImagingUtils.h | 3 +++ src/libImaging/QuantOctree.c | 2 -- src/libImaging/TiffDecode.c | 16 ++++++++-------- src/libImaging/TiffDecode.h | 5 ----- 7 files changed, 17 insertions(+), 27 deletions(-) diff --git a/src/_imagingmath.c b/src/_imagingmath.c index dbe636707..d4912d4a1 100644 --- a/src/_imagingmath.c +++ b/src/_imagingmath.c @@ -63,8 +63,8 @@ #define SUB(type, v1, v2) (v1) - (v2) #define MUL(type, v1, v2) (v1) * (v2) -#define MIN(type, v1, v2) ((v1) < (v2)) ? (v1) : (v2) -#define MAX(type, v1, v2) ((v1) > (v2)) ? (v1) : (v2) +#define MINOP(type, v1, v2) ((v1) < (v2)) ? (v1) : (v2) +#define MAXOP(type, v1, v2) ((v1) > (v2)) ? (v1) : (v2) #define AND(type, v1, v2) (v1) & (v2) #define OR(type, v1, v2) (v1) | (v2) @@ -134,8 +134,8 @@ BINOP(xor_I, XOR, INT32) BINOP(lshift_I, LSHIFT, INT32) BINOP(rshift_I, RSHIFT, INT32) -BINOP(min_I, MIN, INT32) -BINOP(max_I, MAX, INT32) +BINOP(min_I, MINOP, INT32) +BINOP(max_I, MAXOP, INT32) BINOP(eq_I, EQ, INT32) BINOP(ne_I, NE, INT32) @@ -155,8 +155,8 @@ BINOP(mod_F, MOD_F, FLOAT32) BINOP(pow_F, POW_F, FLOAT32) BINOP(diff_F, DIFF_F, FLOAT32) -BINOP(min_F, MIN, FLOAT32) -BINOP(max_F, MAX, FLOAT32) +BINOP(min_F, MINOP, FLOAT32) +BINOP(max_F, MAXOP, FLOAT32) BINOP(eq_F, EQ, FLOAT32) BINOP(ne_F, NE, FLOAT32) diff --git a/src/libImaging/BoxBlur.c b/src/libImaging/BoxBlur.c index ed91541fe..41fb5f0d9 100644 --- a/src/libImaging/BoxBlur.c +++ b/src/libImaging/BoxBlur.c @@ -1,8 +1,5 @@ #include "Imaging.h" -#define MAX(x, y) (((x) > (y)) ? (x) : (y)) -#define MIN(x, y) (((x) < (y)) ? (x) : (y)) - typedef UINT8 pixel[4]; void static inline ImagingLineBoxBlur32( diff --git a/src/libImaging/Convert.c b/src/libImaging/Convert.c index c8f234261..1a410891f 100644 --- a/src/libImaging/Convert.c +++ b/src/libImaging/Convert.c @@ -34,9 +34,6 @@ #include "Imaging.h" -#define MAX(a, b) (a) > (b) ? (a) : (b) -#define MIN(a, b) (a) < (b) ? (a) : (b) - #define CLIP16(v) ((v) <= 0 ? 0 : (v) >= 65535 ? 65535 : (v)) /* ITU-R Recommendation 601-2 (assuming nonlinear RGB) */ diff --git a/src/libImaging/ImagingUtils.h b/src/libImaging/ImagingUtils.h index 714458ad0..e80455069 100644 --- a/src/libImaging/ImagingUtils.h +++ b/src/libImaging/ImagingUtils.h @@ -14,6 +14,9 @@ #define MASK_UINT32_CHANNEL_3 0xff000000 #endif +#define MAX(x, y) (((x) > (y)) ? (x) : (y)) +#define MIN(x, y) (((x) < (y)) ? (x) : (y)) + #define SHIFTFORDIV255(a) ((((a) >> 8) + a) >> 8) /* like (a * b + 127) / 255), but much faster on most platforms */ diff --git a/src/libImaging/QuantOctree.c b/src/libImaging/QuantOctree.c index 7e02ebf65..ef1a35970 100644 --- a/src/libImaging/QuantOctree.c +++ b/src/libImaging/QuantOctree.c @@ -49,8 +49,6 @@ typedef struct _ColorCube { ColorBucket buckets; } *ColorCube; -#define MAX(a, b) (a) > (b) ? (a) : (b) - static ColorCube new_color_cube(int r, int g, int b, int a) { ColorCube cube; diff --git a/src/libImaging/TiffDecode.c b/src/libImaging/TiffDecode.c index 18a54f633..846156446 100644 --- a/src/libImaging/TiffDecode.c +++ b/src/libImaging/TiffDecode.c @@ -69,7 +69,7 @@ _tiffReadProc(thandle_t hdata, tdata_t buf, tsize_t size) { ); return 0; } - to_read = min(size, min(state->size, (tsize_t)state->eof) - (tsize_t)state->loc); + to_read = MIN(size, MIN(state->size, (tsize_t)state->eof) - (tsize_t)state->loc); TRACE(("to_read: %d\n", (int)to_read)); _TIFFmemcpy(buf, (UINT8 *)state->data + state->loc, to_read); @@ -87,7 +87,7 @@ _tiffWriteProc(thandle_t hdata, tdata_t buf, tsize_t size) { TRACE(("_tiffWriteProc: %d \n", (int)size)); dump_state(state); - to_write = min(size, state->size - (tsize_t)state->loc); + to_write = MIN(size, state->size - (tsize_t)state->loc); if (state->flrealloc && size > to_write) { tdata_t new_data; tsize_t newsize = state->size; @@ -114,7 +114,7 @@ _tiffWriteProc(thandle_t hdata, tdata_t buf, tsize_t size) { _TIFFmemcpy((UINT8 *)state->data + state->loc, buf, to_write); state->loc += (toff_t)to_write; - state->eof = max(state->loc, state->eof); + state->eof = MAX(state->loc, state->eof); dump_state(state); return to_write; @@ -333,7 +333,7 @@ _decodeAsRGBA(Imaging im, ImagingCodecState state, TIFF *tiff) { for (; state->y < state->ysize; state->y += rows_per_block) { img.row_offset = state->y; - rows_to_read = min(rows_per_block, img.height - state->y); + rows_to_read = MIN(rows_per_block, img.height - state->y); if (!TIFFRGBAImageGet(&img, (UINT32 *)state->buffer, img.width, rows_to_read)) { TRACE(("Decode Error, y: %d\n", state->y)); @@ -349,7 +349,7 @@ _decodeAsRGBA(Imaging im, ImagingCodecState state, TIFF *tiff) { // iterate over each row in the strip and stuff data into image for (current_row = 0; - current_row < min((INT32)rows_per_block, state->ysize - state->y); + current_row < MIN((INT32)rows_per_block, state->ysize - state->y); current_row++) { TRACE(("Writing data into line %d ; \n", state->y + current_row)); @@ -452,8 +452,8 @@ _decodeTile( TRACE(("Read tile at %dx%d; \n\n", x, y)); - current_tile_width = min((INT32)tile_width, state->xsize - x); - current_tile_length = min((INT32)tile_length, state->ysize - y); + current_tile_width = MIN((INT32)tile_width, state->xsize - x); + current_tile_length = MIN((INT32)tile_length, state->ysize - y); // iterate over each line in the tile and stuff data into image for (tile_y = 0; tile_y < current_tile_length; tile_y++) { TRACE( @@ -566,7 +566,7 @@ _decodeStrip( // iterate over each row in the strip and stuff data into image for (strip_row = 0; - strip_row < min((INT32)rows_per_strip, state->ysize - state->y); + strip_row < MIN((INT32)rows_per_strip, state->ysize - state->y); strip_row++) { TRACE(("Writing data into line %d ; \n", state->y + strip_row)); diff --git a/src/libImaging/TiffDecode.h b/src/libImaging/TiffDecode.h index 22361210d..bfddec5ca 100644 --- a/src/libImaging/TiffDecode.h +++ b/src/libImaging/TiffDecode.h @@ -13,11 +13,6 @@ #include #endif -#ifndef min -#define min(x, y) ((x > y) ? y : x) -#define max(x, y) ((x < y) ? y : x) -#endif - #ifndef _PIL_LIBTIFF_ #define _PIL_LIBTIFF_ From f4accfe336043bb7f65f00b72f1187e80dbd5f71 Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Sun, 15 Sep 2024 13:40:42 +0200 Subject: [PATCH 02/17] Rename ImPlarform to ImagingPlatform --- src/libImaging/ImDib.h | 2 +- src/libImaging/Imaging.h | 2 +- src/libImaging/{ImPlatform.h => ImagingPlatform.h} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename src/libImaging/{ImPlatform.h => ImagingPlatform.h} (100%) diff --git a/src/libImaging/ImDib.h b/src/libImaging/ImDib.h index 91ff3f322..e188ffc8e 100644 --- a/src/libImaging/ImDib.h +++ b/src/libImaging/ImDib.h @@ -12,7 +12,7 @@ #ifdef _WIN32 -#include "ImPlatform.h" +#include "ImagingPlatform.h" #if defined(__cplusplus) extern "C" { diff --git a/src/libImaging/Imaging.h b/src/libImaging/Imaging.h index 31052c68a..315ec4440 100644 --- a/src/libImaging/Imaging.h +++ b/src/libImaging/Imaging.h @@ -10,7 +10,7 @@ * See the README file for information on usage and redistribution. */ -#include "ImPlatform.h" +#include "ImagingPlatform.h" #if defined(__cplusplus) extern "C" { diff --git a/src/libImaging/ImPlatform.h b/src/libImaging/ImagingPlatform.h similarity index 100% rename from src/libImaging/ImPlatform.h rename to src/libImaging/ImagingPlatform.h From c46ff6405227ef22bae219f9b7b742a77982c48d Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Sun, 15 Sep 2024 14:00:25 +0200 Subject: [PATCH 03/17] Remove tiff extra guards --- src/_imaging.c | 2 -- src/libImaging/TiffDecode.h | 9 --------- 2 files changed, 11 deletions(-) diff --git a/src/_imaging.c b/src/_imaging.c index 2db4486b2..7d88f7d5c 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -83,10 +83,8 @@ #endif #ifdef HAVE_LIBTIFF -#ifndef _TIFFIO_ #include #endif -#endif #include "libImaging/Imaging.h" diff --git a/src/libImaging/TiffDecode.h b/src/libImaging/TiffDecode.h index bfddec5ca..0768fb674 100644 --- a/src/libImaging/TiffDecode.h +++ b/src/libImaging/TiffDecode.h @@ -6,15 +6,8 @@ * */ -#ifndef _TIFFIO_ #include -#endif -#ifndef _TIFF_ #include -#endif - -#ifndef _PIL_LIBTIFF_ -#define _PIL_LIBTIFF_ typedef struct { tdata_t data; /* tdata_t == void* */ @@ -52,5 +45,3 @@ ImagingLibTiffSetField(ImagingCodecState state, ttag_t tag, ...); */ #define TRACE(args) - -#endif From 2a7c9670c139be2151432df5514d03734a62329e Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Sun, 15 Sep 2024 14:43:47 +0200 Subject: [PATCH 04/17] Cleanup Jpeg.h undefs --- src/decode.c | 126 +++++------ src/encode.c | 412 ++++++++++++++++++------------------ src/libImaging/Jpeg.h | 11 +- src/libImaging/JpegDecode.c | 9 - src/libImaging/JpegEncode.c | 9 - 5 files changed, 269 insertions(+), 298 deletions(-) diff --git a/src/decode.c b/src/decode.c index 51d0aced2..00ecf555d 100644 --- a/src/decode.c +++ b/src/decode.c @@ -800,74 +800,6 @@ PyImaging_ZipDecoderNew(PyObject *self, PyObject *args) { } #endif -/* -------------------------------------------------------------------- */ -/* JPEG */ -/* -------------------------------------------------------------------- */ - -#ifdef HAVE_LIBJPEG - -/* We better define this decoder last in this file, so the following - undef's won't mess things up for the Imaging library proper. */ - -#undef HAVE_PROTOTYPES -#undef HAVE_STDDEF_H -#undef HAVE_STDLIB_H -#undef UINT8 -#undef UINT16 -#undef UINT32 -#undef INT8 -#undef INT16 -#undef INT32 - -#include "libImaging/Jpeg.h" - -PyObject * -PyImaging_JpegDecoderNew(PyObject *self, PyObject *args) { - ImagingDecoderObject *decoder; - - char *mode; - char *rawmode; /* what we want from the decoder */ - char *jpegmode; /* what's in the file */ - int scale = 1; - int draft = 0; - - if (!PyArg_ParseTuple(args, "ssz|ii", &mode, &rawmode, &jpegmode, &scale, &draft)) { - return NULL; - } - - if (!jpegmode) { - jpegmode = ""; - } - - decoder = PyImaging_DecoderNew(sizeof(JPEGSTATE)); - if (decoder == NULL) { - return NULL; - } - - // libjpeg-turbo supports different output formats. - // We are choosing Pillow's native format (3 color bytes + 1 padding) - // to avoid extra conversion in Unpack.c. - if (ImagingJpegUseJCSExtensions() && strcmp(rawmode, "RGB") == 0) { - rawmode = "RGBX"; - } - - if (get_unpacker(decoder, mode, rawmode) < 0) { - return NULL; - } - - decoder->decode = ImagingJpegDecode; - decoder->cleanup = ImagingJpegDecodeCleanup; - - strncpy(((JPEGSTATE *)decoder->state.context)->rawmode, rawmode, 8); - strncpy(((JPEGSTATE *)decoder->state.context)->jpegmode, jpegmode, 8); - - ((JPEGSTATE *)decoder->state.context)->scale = scale; - ((JPEGSTATE *)decoder->state.context)->draft = draft; - - return (PyObject *)decoder; -} -#endif - /* -------------------------------------------------------------------- */ /* JPEG 2000 */ /* -------------------------------------------------------------------- */ @@ -925,3 +857,61 @@ PyImaging_Jpeg2KDecoderNew(PyObject *self, PyObject *args) { return (PyObject *)decoder; } #endif /* HAVE_OPENJPEG */ + +/* -------------------------------------------------------------------- */ +/* JPEG */ +/* -------------------------------------------------------------------- */ + +#ifdef HAVE_LIBJPEG + +/* We better define this decoder last in this file, so the undef's + in Jpeg.h won't mess things up for the Imaging library proper. */ + +#include "libImaging/Jpeg.h" + +PyObject * +PyImaging_JpegDecoderNew(PyObject *self, PyObject *args) { + ImagingDecoderObject *decoder; + + char *mode; + char *rawmode; /* what we want from the decoder */ + char *jpegmode; /* what's in the file */ + int scale = 1; + int draft = 0; + + if (!PyArg_ParseTuple(args, "ssz|ii", &mode, &rawmode, &jpegmode, &scale, &draft)) { + return NULL; + } + + if (!jpegmode) { + jpegmode = ""; + } + + decoder = PyImaging_DecoderNew(sizeof(JPEGSTATE)); + if (decoder == NULL) { + return NULL; + } + + // libjpeg-turbo supports different output formats. + // We are choosing Pillow's native format (3 color bytes + 1 padding) + // to avoid extra conversion in Unpack.c. + if (ImagingJpegUseJCSExtensions() && strcmp(rawmode, "RGB") == 0) { + rawmode = "RGBX"; + } + + if (get_unpacker(decoder, mode, rawmode) < 0) { + return NULL; + } + + decoder->decode = ImagingJpegDecode; + decoder->cleanup = ImagingJpegDecodeCleanup; + + strncpy(((JPEGSTATE *)decoder->state.context)->rawmode, rawmode, 8); + strncpy(((JPEGSTATE *)decoder->state.context)->jpegmode, jpegmode, 8); + + ((JPEGSTATE *)decoder->state.context)->scale = scale; + ((JPEGSTATE *)decoder->state.context)->draft = draft; + + return (PyObject *)decoder; +} +#endif diff --git a/src/encode.c b/src/encode.c index 1a4cd489d..fa6c3a51c 100644 --- a/src/encode.c +++ b/src/encode.c @@ -982,24 +982,213 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) { #endif +/* -------------------------------------------------------------------- */ +/* JPEG 2000 */ +/* -------------------------------------------------------------------- */ + +#ifdef HAVE_OPENJPEG + +#include "libImaging/Jpeg2K.h" + +static void +j2k_decode_coord_tuple(PyObject *tuple, int *x, int *y) { + *x = *y = 0; + + if (tuple && PyTuple_Check(tuple) && PyTuple_GET_SIZE(tuple) == 2) { + *x = (int)PyLong_AsLong(PyTuple_GET_ITEM(tuple, 0)); + *y = (int)PyLong_AsLong(PyTuple_GET_ITEM(tuple, 1)); + + if (*x < 0) { + *x = 0; + } + if (*y < 0) { + *y = 0; + } + } +} + +PyObject * +PyImaging_Jpeg2KEncoderNew(PyObject *self, PyObject *args) { + ImagingEncoderObject *encoder; + JPEG2KENCODESTATE *context; + + char *mode; + char *format; + OPJ_CODEC_FORMAT codec_format; + PyObject *offset = NULL, *tile_offset = NULL, *tile_size = NULL; + char *quality_mode = "rates"; + PyObject *quality_layers = NULL; + Py_ssize_t num_resolutions = 0; + PyObject *cblk_size = NULL, *precinct_size = NULL; + PyObject *irreversible = NULL; + char *progression = "LRCP"; + OPJ_PROG_ORDER prog_order; + char *cinema_mode = "no"; + OPJ_CINEMA_MODE cine_mode; + char mct = 0; + int sgnd = 0; + Py_ssize_t fd = -1; + char *comment; + Py_ssize_t comment_size; + int plt = 0; + + if (!PyArg_ParseTuple( + args, + "ss|OOOsOnOOOssbbnz#p", + &mode, + &format, + &offset, + &tile_offset, + &tile_size, + &quality_mode, + &quality_layers, + &num_resolutions, + &cblk_size, + &precinct_size, + &irreversible, + &progression, + &cinema_mode, + &mct, + &sgnd, + &fd, + &comment, + &comment_size, + &plt + )) { + return NULL; + } + + if (strcmp(format, "j2k") == 0) { + codec_format = OPJ_CODEC_J2K; + } else if (strcmp(format, "jpt") == 0) { + codec_format = OPJ_CODEC_JPT; + } else if (strcmp(format, "jp2") == 0) { + codec_format = OPJ_CODEC_JP2; + } else { + return NULL; + } + + if (strcmp(progression, "LRCP") == 0) { + prog_order = OPJ_LRCP; + } else if (strcmp(progression, "RLCP") == 0) { + prog_order = OPJ_RLCP; + } else if (strcmp(progression, "RPCL") == 0) { + prog_order = OPJ_RPCL; + } else if (strcmp(progression, "PCRL") == 0) { + prog_order = OPJ_PCRL; + } else if (strcmp(progression, "CPRL") == 0) { + prog_order = OPJ_CPRL; + } else { + return NULL; + } + + if (strcmp(cinema_mode, "no") == 0) { + cine_mode = OPJ_OFF; + } else if (strcmp(cinema_mode, "cinema2k-24") == 0) { + cine_mode = OPJ_CINEMA2K_24; + } else if (strcmp(cinema_mode, "cinema2k-48") == 0) { + cine_mode = OPJ_CINEMA2K_48; + } else if (strcmp(cinema_mode, "cinema4k-24") == 0) { + cine_mode = OPJ_CINEMA4K_24; + } else { + return NULL; + } + + encoder = PyImaging_EncoderNew(sizeof(JPEG2KENCODESTATE)); + if (!encoder) { + return NULL; + } + + encoder->encode = ImagingJpeg2KEncode; + encoder->cleanup = ImagingJpeg2KEncodeCleanup; + encoder->pushes_fd = 1; + + context = (JPEG2KENCODESTATE *)encoder->state.context; + + context->fd = fd; + context->format = codec_format; + context->offset_x = context->offset_y = 0; + + j2k_decode_coord_tuple(offset, &context->offset_x, &context->offset_y); + j2k_decode_coord_tuple( + tile_offset, &context->tile_offset_x, &context->tile_offset_y + ); + j2k_decode_coord_tuple(tile_size, &context->tile_size_x, &context->tile_size_y); + + /* Error on illegal tile offsets */ + if (context->tile_size_x && context->tile_size_y) { + if (context->tile_offset_x <= context->offset_x - context->tile_size_x || + context->tile_offset_y <= context->offset_y - context->tile_size_y) { + PyErr_SetString( + PyExc_ValueError, + "JPEG 2000 tile offset too small; top left tile must " + "intersect image area" + ); + Py_DECREF(encoder); + return NULL; + } + + if (context->tile_offset_x > context->offset_x || + context->tile_offset_y > context->offset_y) { + PyErr_SetString( + PyExc_ValueError, "JPEG 2000 tile offset too large to cover image area" + ); + Py_DECREF(encoder); + return NULL; + } + } + + if (comment && comment_size > 0) { + /* Size is stored as as an uint16, subtract 4 bytes for the header */ + if (comment_size >= 65532) { + PyErr_SetString(PyExc_ValueError, "JPEG 2000 comment is too long"); + Py_DECREF(encoder); + return NULL; + } + + char *p = malloc(comment_size + 1); + if (!p) { + Py_DECREF(encoder); + return ImagingError_MemoryError(); + } + memcpy(p, comment, comment_size); + p[comment_size] = '\0'; + context->comment = p; + } + + if (quality_layers && PySequence_Check(quality_layers)) { + context->quality_is_in_db = strcmp(quality_mode, "dB") == 0; + context->quality_layers = quality_layers; + Py_INCREF(quality_layers); + } + + context->num_resolutions = num_resolutions; + + j2k_decode_coord_tuple(cblk_size, &context->cblk_width, &context->cblk_height); + j2k_decode_coord_tuple( + precinct_size, &context->precinct_width, &context->precinct_height + ); + + context->irreversible = PyObject_IsTrue(irreversible); + context->progression = prog_order; + context->cinema_mode = cine_mode; + context->mct = mct; + context->sgnd = sgnd; + context->plt = plt; + + return (PyObject *)encoder; +} + +#endif + /* -------------------------------------------------------------------- */ /* JPEG */ /* -------------------------------------------------------------------- */ #ifdef HAVE_LIBJPEG -/* We better define this encoder last in this file, so the following - undef's won't mess things up for the Imaging library proper. */ - -#undef HAVE_PROTOTYPES -#undef HAVE_STDDEF_H -#undef HAVE_STDLIB_H -#undef UINT8 -#undef UINT16 -#undef UINT32 -#undef INT8 -#undef INT16 -#undef INT32 +/* We better define this decoder last in this file, so the undef's + in Jpeg.h won't mess things up for the Imaging library proper. */ #include "libImaging/Jpeg.h" @@ -1212,202 +1401,3 @@ PyImaging_JpegEncoderNew(PyObject *self, PyObject *args) { } #endif - -/* -------------------------------------------------------------------- */ -/* JPEG 2000 */ -/* -------------------------------------------------------------------- */ - -#ifdef HAVE_OPENJPEG - -#include "libImaging/Jpeg2K.h" - -static void -j2k_decode_coord_tuple(PyObject *tuple, int *x, int *y) { - *x = *y = 0; - - if (tuple && PyTuple_Check(tuple) && PyTuple_GET_SIZE(tuple) == 2) { - *x = (int)PyLong_AsLong(PyTuple_GET_ITEM(tuple, 0)); - *y = (int)PyLong_AsLong(PyTuple_GET_ITEM(tuple, 1)); - - if (*x < 0) { - *x = 0; - } - if (*y < 0) { - *y = 0; - } - } -} - -PyObject * -PyImaging_Jpeg2KEncoderNew(PyObject *self, PyObject *args) { - ImagingEncoderObject *encoder; - JPEG2KENCODESTATE *context; - - char *mode; - char *format; - OPJ_CODEC_FORMAT codec_format; - PyObject *offset = NULL, *tile_offset = NULL, *tile_size = NULL; - char *quality_mode = "rates"; - PyObject *quality_layers = NULL; - Py_ssize_t num_resolutions = 0; - PyObject *cblk_size = NULL, *precinct_size = NULL; - PyObject *irreversible = NULL; - char *progression = "LRCP"; - OPJ_PROG_ORDER prog_order; - char *cinema_mode = "no"; - OPJ_CINEMA_MODE cine_mode; - char mct = 0; - int sgnd = 0; - Py_ssize_t fd = -1; - char *comment; - Py_ssize_t comment_size; - int plt = 0; - - if (!PyArg_ParseTuple( - args, - "ss|OOOsOnOOOssbbnz#p", - &mode, - &format, - &offset, - &tile_offset, - &tile_size, - &quality_mode, - &quality_layers, - &num_resolutions, - &cblk_size, - &precinct_size, - &irreversible, - &progression, - &cinema_mode, - &mct, - &sgnd, - &fd, - &comment, - &comment_size, - &plt - )) { - return NULL; - } - - if (strcmp(format, "j2k") == 0) { - codec_format = OPJ_CODEC_J2K; - } else if (strcmp(format, "jpt") == 0) { - codec_format = OPJ_CODEC_JPT; - } else if (strcmp(format, "jp2") == 0) { - codec_format = OPJ_CODEC_JP2; - } else { - return NULL; - } - - if (strcmp(progression, "LRCP") == 0) { - prog_order = OPJ_LRCP; - } else if (strcmp(progression, "RLCP") == 0) { - prog_order = OPJ_RLCP; - } else if (strcmp(progression, "RPCL") == 0) { - prog_order = OPJ_RPCL; - } else if (strcmp(progression, "PCRL") == 0) { - prog_order = OPJ_PCRL; - } else if (strcmp(progression, "CPRL") == 0) { - prog_order = OPJ_CPRL; - } else { - return NULL; - } - - if (strcmp(cinema_mode, "no") == 0) { - cine_mode = OPJ_OFF; - } else if (strcmp(cinema_mode, "cinema2k-24") == 0) { - cine_mode = OPJ_CINEMA2K_24; - } else if (strcmp(cinema_mode, "cinema2k-48") == 0) { - cine_mode = OPJ_CINEMA2K_48; - } else if (strcmp(cinema_mode, "cinema4k-24") == 0) { - cine_mode = OPJ_CINEMA4K_24; - } else { - return NULL; - } - - encoder = PyImaging_EncoderNew(sizeof(JPEG2KENCODESTATE)); - if (!encoder) { - return NULL; - } - - encoder->encode = ImagingJpeg2KEncode; - encoder->cleanup = ImagingJpeg2KEncodeCleanup; - encoder->pushes_fd = 1; - - context = (JPEG2KENCODESTATE *)encoder->state.context; - - context->fd = fd; - context->format = codec_format; - context->offset_x = context->offset_y = 0; - - j2k_decode_coord_tuple(offset, &context->offset_x, &context->offset_y); - j2k_decode_coord_tuple( - tile_offset, &context->tile_offset_x, &context->tile_offset_y - ); - j2k_decode_coord_tuple(tile_size, &context->tile_size_x, &context->tile_size_y); - - /* Error on illegal tile offsets */ - if (context->tile_size_x && context->tile_size_y) { - if (context->tile_offset_x <= context->offset_x - context->tile_size_x || - context->tile_offset_y <= context->offset_y - context->tile_size_y) { - PyErr_SetString( - PyExc_ValueError, - "JPEG 2000 tile offset too small; top left tile must " - "intersect image area" - ); - Py_DECREF(encoder); - return NULL; - } - - if (context->tile_offset_x > context->offset_x || - context->tile_offset_y > context->offset_y) { - PyErr_SetString( - PyExc_ValueError, "JPEG 2000 tile offset too large to cover image area" - ); - Py_DECREF(encoder); - return NULL; - } - } - - if (comment && comment_size > 0) { - /* Size is stored as as an uint16, subtract 4 bytes for the header */ - if (comment_size >= 65532) { - PyErr_SetString(PyExc_ValueError, "JPEG 2000 comment is too long"); - Py_DECREF(encoder); - return NULL; - } - - char *p = malloc(comment_size + 1); - if (!p) { - Py_DECREF(encoder); - return ImagingError_MemoryError(); - } - memcpy(p, comment, comment_size); - p[comment_size] = '\0'; - context->comment = p; - } - - if (quality_layers && PySequence_Check(quality_layers)) { - context->quality_is_in_db = strcmp(quality_mode, "dB") == 0; - context->quality_layers = quality_layers; - Py_INCREF(quality_layers); - } - - context->num_resolutions = num_resolutions; - - j2k_decode_coord_tuple(cblk_size, &context->cblk_width, &context->cblk_height); - j2k_decode_coord_tuple( - precinct_size, &context->precinct_width, &context->precinct_height - ); - - context->irreversible = PyObject_IsTrue(irreversible); - context->progression = prog_order; - context->cinema_mode = cine_mode; - context->mct = mct; - context->sgnd = sgnd; - context->plt = plt; - - return (PyObject *)encoder; -} - -#endif diff --git a/src/libImaging/Jpeg.h b/src/libImaging/Jpeg.h index 7cdba9022..d4604f84f 100644 --- a/src/libImaging/Jpeg.h +++ b/src/libImaging/Jpeg.h @@ -8,7 +8,16 @@ * Copyright (c) 1995-1996 by Fredrik Lundh */ -#include "jpeglib.h" +/* This undefs ruquired for libjpeg v8 and below */ + +#undef UINT8 +#undef UINT16 +#undef UINT32 +#undef INT8 +#undef INT16 +#undef INT32 + +#include #include diff --git a/src/libImaging/JpegDecode.c b/src/libImaging/JpegDecode.c index 2970f56d1..838a7483c 100644 --- a/src/libImaging/JpegDecode.c +++ b/src/libImaging/JpegDecode.c @@ -25,15 +25,6 @@ #ifdef HAVE_LIBJPEG -#undef HAVE_PROTOTYPES -#undef HAVE_STDLIB_H -#undef HAVE_STDDEF_H -#undef UINT8 -#undef UINT16 -#undef UINT32 -#undef INT16 -#undef INT32 - #include "Jpeg.h" #define STRINGIFY(x) #x diff --git a/src/libImaging/JpegEncode.c b/src/libImaging/JpegEncode.c index 4372d51d5..880a31117 100644 --- a/src/libImaging/JpegEncode.c +++ b/src/libImaging/JpegEncode.c @@ -23,15 +23,6 @@ #ifdef HAVE_LIBJPEG -#undef HAVE_PROTOTYPES -#undef HAVE_STDLIB_H -#undef HAVE_STDDEF_H -#undef UINT8 -#undef UINT16 -#undef UINT32 -#undef INT16 -#undef INT32 - #include "Jpeg.h" /* -------------------------------------------------------------------- */ From 34488d1d4ecbd071ceca3f3440c1ca0d4e6f64af Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Sun, 1 Sep 2024 20:34:55 +0400 Subject: [PATCH 05/17] Drop support of not C99+ compilers (including old MSVC) --- src/_imagingcms.c | 6 ---- src/display.c | 6 ---- src/libImaging/Dib.c | 3 +- src/libImaging/Draw.c | 1 - src/libImaging/ImDib.h | 2 -- src/libImaging/ImagingPlatform.h | 61 +++++--------------------------- src/libImaging/QuantOctree.c | 2 +- src/libImaging/QuantTypes.h | 9 ++--- 8 files changed, 13 insertions(+), 77 deletions(-) diff --git a/src/_imagingcms.c b/src/_imagingcms.c index 1823bcf03..f152fadbf 100644 --- a/src/_imagingcms.c +++ b/src/_imagingcms.c @@ -620,12 +620,6 @@ cms_profile_is_intent_supported(CmsProfileObject *self, PyObject *args) { #ifdef _WIN32 -#ifdef _WIN64 -#define F_HANDLE "K" -#else -#define F_HANDLE "k" -#endif - static PyObject * cms_get_display_profile_win32(PyObject *self, PyObject *args) { char filename[MAX_PATH]; diff --git a/src/display.c b/src/display.c index b4e2e3899..f6380dff3 100644 --- a/src/display.c +++ b/src/display.c @@ -34,12 +34,6 @@ #include "libImaging/ImDib.h" -#if SIZEOF_VOID_P == 8 -#define F_HANDLE "K" -#else -#define F_HANDLE "k" -#endif - typedef struct { PyObject_HEAD ImagingDIB dib; } ImagingDisplayObject; diff --git a/src/libImaging/Dib.c b/src/libImaging/Dib.c index c69e9e552..a34fba85a 100644 --- a/src/libImaging/Dib.c +++ b/src/libImaging/Dib.c @@ -19,10 +19,9 @@ * See the README file for information on usage and redistribution. */ -#include "Imaging.h" - #ifdef _WIN32 +#include "Imaging.h" #include "ImDib.h" char * diff --git a/src/libImaging/Draw.c b/src/libImaging/Draw.c index f1c8ffcff..5c61e0e7e 100644 --- a/src/libImaging/Draw.c +++ b/src/libImaging/Draw.c @@ -35,7 +35,6 @@ #include "Imaging.h" #include -#include #define CEIL(v) (int)ceil(v) #define FLOOR(v) ((v) >= 0.0 ? (int)(v) : (int)floor(v)) diff --git a/src/libImaging/ImDib.h b/src/libImaging/ImDib.h index e188ffc8e..a0c2348fd 100644 --- a/src/libImaging/ImDib.h +++ b/src/libImaging/ImDib.h @@ -12,8 +12,6 @@ #ifdef _WIN32 -#include "ImagingPlatform.h" - #if defined(__cplusplus) extern "C" { #endif diff --git a/src/libImaging/ImagingPlatform.h b/src/libImaging/ImagingPlatform.h index c9b7e43b4..78d27067c 100644 --- a/src/libImaging/ImagingPlatform.h +++ b/src/libImaging/ImagingPlatform.h @@ -8,7 +8,7 @@ */ #define PY_SSIZE_T_CLEAN -#include "Python.h" +#include /* Check that we have an ANSI compliant compiler */ #ifndef HAVE_PROTOTYPES @@ -18,34 +18,25 @@ #error Sorry, this library requires ANSI header files. #endif -#if defined(PIL_NO_INLINE) -#define inline -#else #if defined(_MSC_VER) && !defined(__GNUC__) #define inline __inline #endif -#endif - -#if defined(_WIN32) || defined(__CYGWIN__) /* WIN */ +#ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #include -#ifdef __CYGWIN__ -#undef _WIN64 -#undef _WIN32 -#undef __WIN32__ -#undef WIN32 +#ifdef _WIN64 +#define F_HANDLE "K" +#else +#define F_HANDLE "k" #endif -#else /* not WIN */ -/* For System that are not Windows, we'll need to define these. */ -/* We have to define them instead of using typedef because the JPEG lib also +#endif /* _WIN32 */ + +/* We have to define types instead of using typedef because the JPEG lib also defines their own types with the same names, so we need to be able to undef ours before including the JPEG code. */ - -#if __STDC_VERSION__ >= 199901L /* C99+ */ - #include #define INT8 int8_t @@ -55,45 +46,11 @@ #define INT32 int32_t #define UINT32 uint32_t -#else /* < C99 */ - -#define INT8 signed char - -#if SIZEOF_SHORT == 2 -#define INT16 short -#elif SIZEOF_INT == 2 -#define INT16 int -#else -#error Cannot find required 16-bit integer type -#endif - -#if SIZEOF_SHORT == 4 -#define INT32 short -#elif SIZEOF_INT == 4 -#define INT32 int -#elif SIZEOF_LONG == 4 -#define INT32 long -#else -#error Cannot find required 32-bit integer type -#endif - -#define UINT8 unsigned char -#define UINT16 unsigned INT16 -#define UINT32 unsigned INT32 - -#endif /* < C99 */ - -#endif /* not WIN */ - /* assume IEEE; tweak if necessary (patches are welcome) */ #define FLOAT16 UINT16 #define FLOAT32 float #define FLOAT64 double -#ifdef _MSC_VER -typedef signed __int64 int64_t; -#endif - #ifdef __GNUC__ #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) #endif diff --git a/src/libImaging/QuantOctree.c b/src/libImaging/QuantOctree.c index ef1a35970..b7ade3102 100644 --- a/src/libImaging/QuantOctree.c +++ b/src/libImaging/QuantOctree.c @@ -28,7 +28,7 @@ #include #include -#include "ImagingUtils.h" +#include "Imaging.h" #include "QuantOctree.h" typedef struct _ColorBucket { diff --git a/src/libImaging/QuantTypes.h b/src/libImaging/QuantTypes.h index 986b70806..e01023de7 100644 --- a/src/libImaging/QuantTypes.h +++ b/src/libImaging/QuantTypes.h @@ -9,15 +9,10 @@ * See the README file for information on usage and redistribution. */ -#ifndef __TYPES_H__ -#define __TYPES_H__ +#ifndef __QUANTTYPES_H__ +#define __QUANTTYPES_H__ -#ifdef _MSC_VER -typedef unsigned __int32 uint32_t; -typedef unsigned __int64 uint64_t; -#else #include -#endif typedef union { struct { From ff7c29ced9d6290962a74db495c54edec215de51 Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Sun, 1 Sep 2024 21:09:14 +0400 Subject: [PATCH 06/17] Move include Python.h to ImagingPlatform --- Tests/test_image_access.py | 2 +- src/_imaging.c | 3 --- src/_imagingcms.c | 12 ++++-------- src/_imagingft.c | 4 +--- src/_imagingmath.c | 6 ++---- src/_imagingtk.c | 1 - src/_webp.c | 3 +-- src/decode.c | 4 ---- src/display.c | 3 --- src/encode.c | 5 +---- src/libImaging/codec_fd.c | 1 - src/map.c | 2 -- src/outline.c | 2 -- src/path.c | 3 +-- 14 files changed, 11 insertions(+), 40 deletions(-) diff --git a/Tests/test_image_access.py b/Tests/test_image_access.py index bb30b462d..4e3435cfe 100644 --- a/Tests/test_image_access.py +++ b/Tests/test_image_access.py @@ -282,7 +282,7 @@ class TestEmbeddable: home = sys.prefix.replace("\\", "\\\\") fh.write( f""" -#include "Python.h" +#include int main(int argc, char* argv[]) {{ diff --git a/src/_imaging.c b/src/_imaging.c index 7d88f7d5c..1201e8db7 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -71,9 +71,6 @@ * See the README file for information on usage and redistribution. */ -#define PY_SSIZE_T_CLEAN -#include "Python.h" - #ifdef HAVE_LIBJPEG #include "jconfig.h" #endif diff --git a/src/_imagingcms.c b/src/_imagingcms.c index f152fadbf..63fe0eb2f 100644 --- a/src/_imagingcms.c +++ b/src/_imagingcms.c @@ -26,15 +26,11 @@ kevin@cazabon.com\n\ https://www.cazabon.com\n\ " -#define PY_SSIZE_T_CLEAN -#include "Python.h" // Include before wchar.h so _GNU_SOURCE is set -#include "wchar.h" -#include "datetime.h" +#include "libImaging/Imaging.h" // Include before wchar.h so _GNU_SOURCE is set -#include "lcms2.h" -#include "libImaging/Imaging.h" - -#define PYCMSVERSION "1.0.0 pil" +#include +#include +#include /* version history */ diff --git a/src/_imagingft.c b/src/_imagingft.c index 7f2464124..dea13c47e 100644 --- a/src/_imagingft.c +++ b/src/_imagingft.c @@ -18,10 +18,8 @@ * Copyright (c) 1998-2007 by Secret Labs AB */ -#define PY_SSIZE_T_CLEAN -#include "Python.h" -#include "thirdparty/pythoncapi_compat.h" #include "libImaging/Imaging.h" +#include "thirdparty/pythoncapi_compat.h" #include #include FT_FREETYPE_H diff --git a/src/_imagingmath.c b/src/_imagingmath.c index d4912d4a1..f54ca6cd5 100644 --- a/src/_imagingmath.c +++ b/src/_imagingmath.c @@ -13,12 +13,10 @@ * See the README file for information on usage and redistribution. */ -#include "Python.h" - #include "libImaging/Imaging.h" -#include "math.h" -#include "float.h" +#include +#include #define MAX_INT32 2147483647.0 #define MIN_INT32 -2147483648.0 diff --git a/src/_imagingtk.c b/src/_imagingtk.c index c70d044bb..076995daf 100644 --- a/src/_imagingtk.c +++ b/src/_imagingtk.c @@ -12,7 +12,6 @@ * See the README file for information on usage and redistribution. */ -#include "Python.h" #include "libImaging/Imaging.h" #include "Tk/_tkmini.h" diff --git a/src/_webp.c b/src/_webp.c index dfda7048d..cf6e999b1 100644 --- a/src/_webp.c +++ b/src/_webp.c @@ -1,6 +1,5 @@ -#define PY_SSIZE_T_CLEAN -#include #include "libImaging/Imaging.h" + #include #include #include diff --git a/src/decode.c b/src/decode.c index 00ecf555d..801bab0b3 100644 --- a/src/decode.c +++ b/src/decode.c @@ -29,11 +29,7 @@ /* FIXME: make these pluggable! */ -#define PY_SSIZE_T_CLEAN -#include "Python.h" - #include "libImaging/Imaging.h" - #include "libImaging/Bit.h" #include "libImaging/Bcn.h" #include "libImaging/Gif.h" diff --git a/src/display.c b/src/display.c index f6380dff3..078016797 100644 --- a/src/display.c +++ b/src/display.c @@ -22,9 +22,6 @@ * See the README file for information on usage and redistribution. */ -#define PY_SSIZE_T_CLEAN -#include "Python.h" - #include "libImaging/Imaging.h" /* -------------------------------------------------------------------- */ diff --git a/src/encode.c b/src/encode.c index fa6c3a51c..63f16547f 100644 --- a/src/encode.c +++ b/src/encode.c @@ -22,11 +22,8 @@ /* FIXME: make these pluggable! */ -#define PY_SSIZE_T_CLEAN -#include "Python.h" - -#include "thirdparty/pythoncapi_compat.h" #include "libImaging/Imaging.h" +#include "thirdparty/pythoncapi_compat.h" #include "libImaging/Gif.h" #ifdef HAVE_UNISTD_H diff --git a/src/libImaging/codec_fd.c b/src/libImaging/codec_fd.c index 526168110..f5541c332 100644 --- a/src/libImaging/codec_fd.c +++ b/src/libImaging/codec_fd.c @@ -1,4 +1,3 @@ -#include "Python.h" #include "Imaging.h" Py_ssize_t diff --git a/src/map.c b/src/map.c index c66702981..2fcaa74d2 100644 --- a/src/map.c +++ b/src/map.c @@ -18,8 +18,6 @@ * FIXME: should move the memory mapping primitives into libImaging! */ -#include "Python.h" - #include "libImaging/Imaging.h" /* compatibility wrappers (defined in _imaging.c) */ diff --git a/src/outline.c b/src/outline.c index 27cc255cf..b84bef437 100644 --- a/src/outline.c +++ b/src/outline.c @@ -17,8 +17,6 @@ * See the README file for information on usage and redistribution. */ -#include "Python.h" - #include "libImaging/Imaging.h" /* -------------------------------------------------------------------- */ diff --git a/src/path.c b/src/path.c index 067f42f62..53c1dd8c4 100644 --- a/src/path.c +++ b/src/path.c @@ -25,9 +25,8 @@ * See the README file for information on usage and redistribution. */ -#include "Python.h" -#include "thirdparty/pythoncapi_compat.h" #include "libImaging/Imaging.h" +#include "thirdparty/pythoncapi_compat.h" #include From 039869fe77dcfe40b983f502885ce55c42ccee16 Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Sun, 1 Sep 2024 21:14:51 +0400 Subject: [PATCH 07/17] Move import math.h to ImagingPlatform --- src/_imaging.c | 2 -- src/_imagingmath.c | 1 - src/libImaging/ColorLUT.c | 1 - src/libImaging/Draw.c | 2 -- src/libImaging/Effects.c | 2 -- src/libImaging/Fill.c | 2 -- src/libImaging/Imaging.h | 4 ---- src/libImaging/ImagingPlatform.h | 3 +++ src/libImaging/Palette.c | 2 -- src/libImaging/Quant.c | 1 - src/libImaging/Reduce.c | 2 -- src/libImaging/Resample.c | 2 -- src/path.c | 2 -- 13 files changed, 3 insertions(+), 23 deletions(-) diff --git a/src/_imaging.c b/src/_imaging.c index 1201e8db7..b84784caf 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -85,8 +85,6 @@ #include "libImaging/Imaging.h" -#define _USE_MATH_DEFINES -#include #include #undef VERBOSE diff --git a/src/_imagingmath.c b/src/_imagingmath.c index f54ca6cd5..1c60ad7f4 100644 --- a/src/_imagingmath.c +++ b/src/_imagingmath.c @@ -15,7 +15,6 @@ #include "libImaging/Imaging.h" -#include #include #define MAX_INT32 2147483647.0 diff --git a/src/libImaging/ColorLUT.c b/src/libImaging/ColorLUT.c index 5559de689..33633f555 100644 --- a/src/libImaging/ColorLUT.c +++ b/src/libImaging/ColorLUT.c @@ -1,5 +1,4 @@ #include "Imaging.h" -#include /* 8 bits for result. Table can overflow [0, 1.0] range, so we need extra bits for overflow and negative values. diff --git a/src/libImaging/Draw.c b/src/libImaging/Draw.c index 5c61e0e7e..730bba8ac 100644 --- a/src/libImaging/Draw.c +++ b/src/libImaging/Draw.c @@ -34,8 +34,6 @@ #include "Imaging.h" -#include - #define CEIL(v) (int)ceil(v) #define FLOOR(v) ((v) >= 0.0 ? (int)(v) : (int)floor(v)) diff --git a/src/libImaging/Effects.c b/src/libImaging/Effects.c index 93e7af0bc..64d6188d9 100644 --- a/src/libImaging/Effects.c +++ b/src/libImaging/Effects.c @@ -17,8 +17,6 @@ #include "Imaging.h" -#include - Imaging ImagingEffectMandelbrot(int xsize, int ysize, double extent[4], int quality) { /* Generate a Mandelbrot set covering the given extent */ diff --git a/src/libImaging/Fill.c b/src/libImaging/Fill.c index 8fb481e7e..1e4bb9ba0 100644 --- a/src/libImaging/Fill.c +++ b/src/libImaging/Fill.c @@ -17,8 +17,6 @@ #include "Imaging.h" -#include "math.h" - Imaging ImagingFill(Imaging im, const void *colour) { int x, y; diff --git a/src/libImaging/Imaging.h b/src/libImaging/Imaging.h index 315ec4440..7ba809bf4 100644 --- a/src/libImaging/Imaging.h +++ b/src/libImaging/Imaging.h @@ -16,10 +16,6 @@ extern "C" { #endif -#ifndef M_PI -#define M_PI 3.1415926535897932384626433832795 -#endif - /* -------------------------------------------------------------------- */ /* diff --git a/src/libImaging/ImagingPlatform.h b/src/libImaging/ImagingPlatform.h index 78d27067c..3a3875daf 100644 --- a/src/libImaging/ImagingPlatform.h +++ b/src/libImaging/ImagingPlatform.h @@ -10,6 +10,9 @@ #define PY_SSIZE_T_CLEAN #include +#define _USE_MATH_DEFINES +#include + /* Check that we have an ANSI compliant compiler */ #ifndef HAVE_PROTOTYPES #error Sorry, this library requires support for ANSI prototypes. diff --git a/src/libImaging/Palette.c b/src/libImaging/Palette.c index 78916bca5..032ce8ab2 100644 --- a/src/libImaging/Palette.c +++ b/src/libImaging/Palette.c @@ -18,8 +18,6 @@ #include "Imaging.h" -#include - ImagingPalette ImagingPaletteNew(const char *mode) { /* Create a palette object */ diff --git a/src/libImaging/Quant.c b/src/libImaging/Quant.c index a489a882d..147d8ae52 100644 --- a/src/libImaging/Quant.c +++ b/src/libImaging/Quant.c @@ -1428,7 +1428,6 @@ quantize( } #ifdef TEST_NEAREST_NEIGHBOUR -#include { uint32_t bestmatch, bestdist, dist; HashTable *h2; diff --git a/src/libImaging/Reduce.c b/src/libImaging/Reduce.c index 022daa000..6da18d773 100644 --- a/src/libImaging/Reduce.c +++ b/src/libImaging/Reduce.c @@ -1,7 +1,5 @@ #include "Imaging.h" -#include - #define ROUND_UP(f) ((int)((f) >= 0.0 ? (f) + 0.5F : (f) - 0.5F)) UINT32 diff --git a/src/libImaging/Resample.c b/src/libImaging/Resample.c index f5e386dc2..978bf74c7 100644 --- a/src/libImaging/Resample.c +++ b/src/libImaging/Resample.c @@ -1,7 +1,5 @@ #include "Imaging.h" -#include - #define ROUND_UP(f) ((int)((f) >= 0.0 ? (f) + 0.5F : (f) - 0.5F)) struct filter { diff --git a/src/path.c b/src/path.c index 53c1dd8c4..c9c2d61ef 100644 --- a/src/path.c +++ b/src/path.c @@ -28,8 +28,6 @@ #include "libImaging/Imaging.h" #include "thirdparty/pythoncapi_compat.h" -#include - /* compatibility wrappers (defined in _imaging.c) */ extern int PyImaging_CheckBuffer(PyObject *buffer); From bd03721816413c8efd656a0657b761349ca4a3ae Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Sun, 1 Sep 2024 23:24:29 +0400 Subject: [PATCH 08/17] Remove add-imaging-libs option # Conflicts: # setup.py --- setup.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/setup.py b/setup.py index 60707083f..739c97710 100644 --- a/setup.py +++ b/setup.py @@ -347,7 +347,6 @@ class pil_build_ext(build_ext): ("disable-platform-guessing", None, "Disable platform guessing on Linux"), ("debug", None, "Debug logging"), ] - + [("add-imaging-libs=", None, "Add libs to _imaging build")] ) @staticmethod @@ -358,7 +357,6 @@ class pil_build_ext(build_ext): self.disable_platform_guessing = self.check_configuration( "platform-guessing", "disable" ) - self.add_imaging_libs = "" build_ext.initialize_options(self) for x in self.feature: setattr(self, f"disable_{x}", self.check_configuration(x, "disable")) @@ -849,7 +847,6 @@ class pil_build_ext(build_ext): # core library libs: list[str | bool | None] = [] - libs.extend(self.add_imaging_libs.split()) defs: list[tuple[str, str | None]] = [] if feature.get("tiff"): libs.append(feature.get("tiff")) From 517c3e1c7f58bff42fd3f732bc45473b172e7e45 Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Sun, 15 Sep 2024 15:36:27 +0200 Subject: [PATCH 09/17] import global libs correctly --- src/_imaging.c | 6 ++---- src/libImaging/ImagingPlatform.h | 6 ++---- src/libImaging/Jpeg2KDecode.c | 1 - src/libImaging/QuantPngQuant.c | 6 +++--- src/libImaging/ZipCodecs.h | 2 +- 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/_imaging.c b/src/_imaging.c index b84784caf..c100b103d 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -72,11 +72,11 @@ */ #ifdef HAVE_LIBJPEG -#include "jconfig.h" +#include #endif #ifdef HAVE_LIBZ -#include "zlib.h" +#include #endif #ifdef HAVE_LIBTIFF @@ -85,8 +85,6 @@ #include "libImaging/Imaging.h" -#include - #undef VERBOSE #define B16(p, i) ((((int)p[(i)]) << 8) + p[(i) + 1]) diff --git a/src/libImaging/ImagingPlatform.h b/src/libImaging/ImagingPlatform.h index 3a3875daf..635ade21c 100644 --- a/src/libImaging/ImagingPlatform.h +++ b/src/libImaging/ImagingPlatform.h @@ -28,20 +28,18 @@ #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #include - #ifdef _WIN64 #define F_HANDLE "K" #else #define F_HANDLE "k" #endif - #endif /* _WIN32 */ +#include + /* We have to define types instead of using typedef because the JPEG lib also defines their own types with the same names, so we need to be able to undef ours before including the JPEG code. */ -#include - #define INT8 int8_t #define UINT8 uint8_t #define INT16 int16_t diff --git a/src/libImaging/Jpeg2KDecode.c b/src/libImaging/Jpeg2KDecode.c index fc927d2f0..052ab3e23 100644 --- a/src/libImaging/Jpeg2KDecode.c +++ b/src/libImaging/Jpeg2KDecode.c @@ -17,7 +17,6 @@ #ifdef HAVE_OPENJPEG -#include #include "Jpeg2K.h" typedef struct { diff --git a/src/libImaging/QuantPngQuant.c b/src/libImaging/QuantPngQuant.c index a2258c3a2..52f127515 100644 --- a/src/libImaging/QuantPngQuant.c +++ b/src/libImaging/QuantPngQuant.c @@ -8,15 +8,15 @@ * */ +#ifdef HAVE_LIBIMAGEQUANT + #include #include #include +#include #include "QuantPngQuant.h" -#ifdef HAVE_LIBIMAGEQUANT -#include "libimagequant.h" - int quantize_pngquant( Pixel *pixelData, diff --git a/src/libImaging/ZipCodecs.h b/src/libImaging/ZipCodecs.h index 50218b6c6..42f1a7101 100644 --- a/src/libImaging/ZipCodecs.h +++ b/src/libImaging/ZipCodecs.h @@ -7,7 +7,7 @@ * Copyright (c) Fredrik Lundh 1996. */ -#include "zlib.h" +#include /* modes */ #define ZIP_PNG 0 /* continuous, filtered image data */ From 310f625e60997e69a7f94fa95deb360f0b241897 Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Tue, 17 Sep 2024 15:25:09 +0200 Subject: [PATCH 10/17] Remove obsolete PyImaging_CheckBuffer and PyImaging_GetBuffer --- src/_imaging.c | 22 +++------------------- src/map.c | 10 ++-------- src/path.c | 10 ++-------- 3 files changed, 7 insertions(+), 35 deletions(-) diff --git a/src/_imaging.c b/src/_imaging.c index c100b103d..5775e9ad6 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -198,22 +198,6 @@ ImagingSectionLeave(ImagingSectionCookie *cookie) { PyEval_RestoreThread((PyThreadState *)*cookie); } -/* -------------------------------------------------------------------- */ -/* BUFFER HANDLING */ -/* -------------------------------------------------------------------- */ -/* Python compatibility API */ - -int -PyImaging_CheckBuffer(PyObject *buffer) { - return PyObject_CheckBuffer(buffer); -} - -int -PyImaging_GetBuffer(PyObject *buffer, Py_buffer *view) { - /* must call check_buffer first! */ - return PyObject_GetBuffer(buffer, view, PyBUF_SIMPLE); -} - /* -------------------------------------------------------------------- */ /* EXCEPTION REROUTING */ /* -------------------------------------------------------------------- */ @@ -4188,19 +4172,19 @@ extern PyObject * PyImaging_GrabScreenX11(PyObject *self, PyObject *args); #endif -/* Experimental path stuff (in path.c) */ +/* Path object (in path.c) */ extern PyObject * PyPath_Create(ImagingObject *self, PyObject *args); -/* Experimental outline stuff (in outline.c) */ +/* Outline object (in outline.c) */ extern PyObject * PyOutline_Create(ImagingObject *self, PyObject *args); +/* MapBuffer implementation (in map.c) */ extern PyObject * PyImaging_MapBuffer(PyObject *self, PyObject *args); static PyMethodDef functions[] = { - /* Object factories */ {"alpha_composite", (PyCFunction)_alpha_composite, METH_VARARGS}, {"blend", (PyCFunction)_blend, METH_VARARGS}, diff --git a/src/map.c b/src/map.c index 2fcaa74d2..ee0848cfb 100644 --- a/src/map.c +++ b/src/map.c @@ -20,12 +20,6 @@ #include "libImaging/Imaging.h" -/* compatibility wrappers (defined in _imaging.c) */ -extern int -PyImaging_CheckBuffer(PyObject *buffer); -extern int -PyImaging_GetBuffer(PyObject *buffer, Py_buffer *view); - extern PyObject * PyImagingNew(Imaging im); @@ -75,7 +69,7 @@ PyImaging_MapBuffer(PyObject *self, PyObject *args) { return NULL; } - if (!PyImaging_CheckBuffer(target)) { + if (!PyObject_CheckBuffer(target)) { PyErr_SetString(PyExc_TypeError, "expected string or buffer"); return NULL; } @@ -103,7 +97,7 @@ PyImaging_MapBuffer(PyObject *self, PyObject *args) { } /* check buffer size */ - if (PyImaging_GetBuffer(target, &view) < 0) { + if (PyObject_GetBuffer(target, &view, PyBUF_SIMPLE) < 0) { return NULL; } diff --git a/src/path.c b/src/path.c index c9c2d61ef..50ea57997 100644 --- a/src/path.c +++ b/src/path.c @@ -28,12 +28,6 @@ #include "libImaging/Imaging.h" #include "thirdparty/pythoncapi_compat.h" -/* compatibility wrappers (defined in _imaging.c) */ -extern int -PyImaging_CheckBuffer(PyObject *buffer); -extern int -PyImaging_GetBuffer(PyObject *buffer, Py_buffer *view); - /* -------------------------------------------------------------------- */ /* Class */ /* -------------------------------------------------------------------- */ @@ -123,10 +117,10 @@ PyPath_Flatten(PyObject *data, double **pxy) { return path->count; } - if (PyImaging_CheckBuffer(data)) { + if (PyObject_CheckBuffer(data)) { /* Assume the buffer contains floats */ Py_buffer buffer; - if (PyImaging_GetBuffer(data, &buffer) == 0) { + if (PyObject_GetBuffer(data, &buffer, PyBUF_SIMPLE) == 0) { float *ptr = (float *)buffer.buf; n = buffer.len / (2 * sizeof(float)); xy = alloc_array(n); From 24daafa2ebd2b6a17910f808b1da8a0a93e7b206 Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Wed, 18 Sep 2024 11:42:44 +0200 Subject: [PATCH 11/17] Use Py_RETURN_NONE macro when possible --- src/_imaging.c | 93 ++++++++++++++++------------------------------ src/_imagingcms.c | 90 +++++++++++++++----------------------------- src/_imagingft.c | 6 +-- src/_imagingmath.c | 6 +-- src/_imagingtk.c | 3 +- src/decode.c | 6 +-- src/display.c | 18 +++------ src/encode.c | 6 +-- src/outline.c | 15 +++----- src/path.c | 6 +-- 10 files changed, 83 insertions(+), 166 deletions(-) diff --git a/src/_imaging.c b/src/_imaging.c index 5775e9ad6..b28284fb5 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -441,8 +441,7 @@ getpixel(Imaging im, ImagingAccess access, int x, int y) { } /* unknown type */ - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static char * @@ -933,8 +932,7 @@ _convert2(ImagingObject *self, PyObject *args) { return NULL; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -1182,8 +1180,7 @@ _getpixel(ImagingObject *self, PyObject *args) { } if (self->access == NULL) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } return getpixel(self->image, self->access, x, y); @@ -1385,8 +1382,7 @@ _paste(ImagingObject *self, PyObject *args) { return NULL; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -1659,8 +1655,7 @@ _putdata(ImagingObject *self, PyObject *args) { Py_XDECREF(seq); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -1720,8 +1715,7 @@ _putpalette(ImagingObject *self, PyObject *args) { self->image->palette->size = palettesize * 8 / bits; unpack(self->image->palette->palette, palette, self->image->palette->size); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -1745,8 +1739,7 @@ _putpalettealpha(ImagingObject *self, PyObject *args) { strcpy(self->image->palette->mode, "RGBA"); self->image->palette->palette[index * 4 + 3] = (UINT8)alpha; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -1773,8 +1766,7 @@ _putpalettealphas(ImagingObject *self, PyObject *args) { self->image->palette->palette[i * 4 + 3] = (UINT8)values[i]; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -1810,8 +1802,7 @@ _putpixel(ImagingObject *self, PyObject *args) { self->access->put_pixel(im, x, y, ink); } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -1978,8 +1969,7 @@ im_setmode(ImagingObject *self, PyObject *args) { } self->access = ImagingAccessNew(im); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -2042,8 +2032,7 @@ _transform(ImagingObject *self, PyObject *args) { return NULL; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -2170,8 +2159,7 @@ _getbbox(ImagingObject *self, PyObject *args) { } if (!ImagingGetBBox(self->image, bbox, alpha_only)) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } return Py_BuildValue("iiii", bbox[0], bbox[1], bbox[2], bbox[3]); @@ -2251,8 +2239,7 @@ _getextrema(ImagingObject *self) { } } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -2315,8 +2302,7 @@ _fillband(ImagingObject *self, PyObject *args) { return NULL; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -2331,8 +2317,7 @@ _putband(ImagingObject *self, PyObject *args) { return NULL; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -2918,8 +2903,7 @@ _draw_arc(ImagingDrawObject *self, PyObject *args) { return NULL; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -2956,8 +2940,7 @@ _draw_bitmap(ImagingDrawObject *self, PyObject *args) { return NULL; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -3013,8 +2996,7 @@ _draw_chord(ImagingDrawObject *self, PyObject *args) { return NULL; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -3068,8 +3050,7 @@ _draw_ellipse(ImagingDrawObject *self, PyObject *args) { return NULL; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -3132,8 +3113,7 @@ _draw_lines(ImagingDrawObject *self, PyObject *args) { free(xy); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -3164,8 +3144,7 @@ _draw_points(ImagingDrawObject *self, PyObject *args) { free(xy); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } /* from outline.c */ @@ -3193,8 +3172,7 @@ _draw_outline(ImagingDrawObject *self, PyObject *args) { return NULL; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -3250,8 +3228,7 @@ _draw_pieslice(ImagingDrawObject *self, PyObject *args) { return NULL; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -3302,8 +3279,7 @@ _draw_polygon(ImagingDrawObject *self, PyObject *args) { free(ixy); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -3357,8 +3333,7 @@ _draw_rectangle(ImagingDrawObject *self, PyObject *args) { return NULL; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static struct PyMethodDef _draw_methods[] = { @@ -3563,8 +3538,7 @@ _save_ppm(ImagingObject *self, PyObject *args) { return NULL; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } /* -------------------------------------------------------------------- */ @@ -3952,8 +3926,7 @@ _reset_stats(PyObject *self, PyObject *args) { arena->stats_freed_blocks = 0; MUTEX_UNLOCK(&ImagingDefaultArena.mutex); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -4013,8 +3986,7 @@ _set_alignment(PyObject *self, PyObject *args) { ImagingDefaultArena.alignment = alignment; MUTEX_UNLOCK(&ImagingDefaultArena.mutex); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -4038,8 +4010,7 @@ _set_block_size(PyObject *self, PyObject *args) { ImagingDefaultArena.block_size = block_size; MUTEX_UNLOCK(&ImagingDefaultArena.mutex); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -4067,8 +4038,7 @@ _set_blocks_max(PyObject *self, PyObject *args) { return ImagingError_MemoryError(); } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -4083,8 +4053,7 @@ _clear_cache(PyObject *self, PyObject *args) { ImagingMemoryClearCache(&ImagingDefaultArena, i); MUTEX_UNLOCK(&ImagingDefaultArena.mutex); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } /* -------------------------------------------------------------------- */ diff --git a/src/_imagingcms.c b/src/_imagingcms.c index 63fe0eb2f..6d01770cc 100644 --- a/src/_imagingcms.c +++ b/src/_imagingcms.c @@ -644,8 +644,7 @@ cms_get_display_profile_win32(PyObject *self, PyObject *args) { return PyUnicode_FromStringAndSize(filename, filename_size - 1); } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } #endif @@ -662,20 +661,17 @@ _profile_read_mlu(CmsProfileObject *self, cmsTagSignature info) { wchar_t *buf; if (!cmsIsTag(self->profile, info)) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } mlu = cmsReadTag(self->profile, info); if (!mlu) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } len = cmsMLUgetWide(mlu, lc, cc, NULL, 0); if (len == 0) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } buf = malloc(len); @@ -713,14 +709,12 @@ _profile_read_signature(CmsProfileObject *self, cmsTagSignature info) { unsigned int *sig; if (!cmsIsTag(self->profile, info)) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } sig = (unsigned int *)cmsReadTag(self->profile, info); if (!sig) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } return _profile_read_int_as_string(*sig); @@ -770,14 +764,12 @@ _profile_read_ciexyz(CmsProfileObject *self, cmsTagSignature info, int multi) { cmsCIEXYZ *XYZ; if (!cmsIsTag(self->profile, info)) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } XYZ = (cmsCIEXYZ *)cmsReadTag(self->profile, info); if (!XYZ) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } if (multi) { return _xyz3_py(XYZ); @@ -791,14 +783,12 @@ _profile_read_ciexyy_triple(CmsProfileObject *self, cmsTagSignature info) { cmsCIExyYTRIPLE *triple; if (!cmsIsTag(self->profile, info)) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } triple = (cmsCIExyYTRIPLE *)cmsReadTag(self->profile, info); if (!triple) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } /* Note: lcms does all the heavy lifting and error checking (nr of @@ -825,21 +815,18 @@ _profile_read_named_color_list(CmsProfileObject *self, cmsTagSignature info) { PyObject *result; if (!cmsIsTag(self->profile, info)) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } ncl = (cmsNAMEDCOLORLIST *)cmsReadTag(self->profile, info); if (ncl == NULL) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } n = cmsNamedColorCount(ncl); result = PyList_New(n); if (!result) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } for (i = 0; i < n; i++) { @@ -848,8 +835,7 @@ _profile_read_named_color_list(CmsProfileObject *self, cmsTagSignature info) { str = PyUnicode_FromString(name); if (str == NULL) { Py_DECREF(result); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } PyList_SET_ITEM(result, i, str); } @@ -916,8 +902,7 @@ _is_intent_supported(CmsProfileObject *self, int clut) { result = PyDict_New(); if (result == NULL) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } n = cmsGetSupportedIntents(INTENTS, intent_ids, intent_descs); @@ -947,8 +932,7 @@ _is_intent_supported(CmsProfileObject *self, int clut) { Py_XDECREF(id); Py_XDECREF(entry); Py_XDECREF(result); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } PyDict_SetItem(result, id, entry); Py_DECREF(id); @@ -1032,8 +1016,7 @@ cms_profile_getattr_creation_date(CmsProfileObject *self, void *closure) { result = cmsGetHeaderCreationDateTime(self->profile, &ct); if (!result) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } return PyDateTime_FromDateAndTime( @@ -1131,8 +1114,7 @@ cms_profile_getattr_saturation_rendering_intent_gamut( static PyObject * cms_profile_getattr_red_colorant(CmsProfileObject *self, void *closure) { if (!cmsIsMatrixShaper(self->profile)) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } return _profile_read_ciexyz(self, cmsSigRedColorantTag, 0); } @@ -1140,8 +1122,7 @@ cms_profile_getattr_red_colorant(CmsProfileObject *self, void *closure) { static PyObject * cms_profile_getattr_green_colorant(CmsProfileObject *self, void *closure) { if (!cmsIsMatrixShaper(self->profile)) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } return _profile_read_ciexyz(self, cmsSigGreenColorantTag, 0); } @@ -1149,8 +1130,7 @@ cms_profile_getattr_green_colorant(CmsProfileObject *self, void *closure) { static PyObject * cms_profile_getattr_blue_colorant(CmsProfileObject *self, void *closure) { if (!cmsIsMatrixShaper(self->profile)) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } return _profile_read_ciexyz(self, cmsSigBlueColorantTag, 0); } @@ -1166,21 +1146,18 @@ cms_profile_getattr_media_white_point_temperature( cmsBool result; if (!cmsIsTag(self->profile, info)) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } XYZ = (cmsCIEXYZ *)cmsReadTag(self->profile, info); if (XYZ == NULL || XYZ->X == 0) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } cmsXYZ2xyY(&xyY, XYZ); result = cmsTempFromWhitePoint(&tempK, &xyY); if (!result) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } return PyFloat_FromDouble(tempK); } @@ -1219,8 +1196,7 @@ cms_profile_getattr_red_primary(CmsProfileObject *self, void *closure) { result = _calculate_rgb_primaries(self, &primaries); } if (!result) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } return _xyz_py(&primaries.Red); @@ -1235,8 +1211,7 @@ cms_profile_getattr_green_primary(CmsProfileObject *self, void *closure) { result = _calculate_rgb_primaries(self, &primaries); } if (!result) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } return _xyz_py(&primaries.Green); @@ -1251,8 +1226,7 @@ cms_profile_getattr_blue_primary(CmsProfileObject *self, void *closure) { result = _calculate_rgb_primaries(self, &primaries); } if (!result) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } return _xyz_py(&primaries.Blue); @@ -1311,14 +1285,12 @@ cms_profile_getattr_icc_measurement_condition(CmsProfileObject *self, void *clos const char *geo; if (!cmsIsTag(self->profile, info)) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } mc = (cmsICCMeasurementConditions *)cmsReadTag(self->profile, info); if (!mc) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } if (mc->Geometry == 1) { @@ -1352,14 +1324,12 @@ cms_profile_getattr_icc_viewing_condition(CmsProfileObject *self, void *closure) cmsTagSignature info = cmsSigViewingConditionsTag; if (!cmsIsTag(self->profile, info)) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } vc = (cmsICCViewingConditions *)cmsReadTag(self->profile, info); if (!vc) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } return Py_BuildValue( diff --git a/src/_imagingft.c b/src/_imagingft.c index dea13c47e..66f066398 100644 --- a/src/_imagingft.c +++ b/src/_imagingft.c @@ -1368,8 +1368,7 @@ font_setvarname(FontObject *self, PyObject *args) { return geterror(error); } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -1423,8 +1422,7 @@ font_setvaraxes(FontObject *self, PyObject *args) { return geterror(error); } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } #endif diff --git a/src/_imagingmath.c b/src/_imagingmath.c index 1c60ad7f4..d54c6db56 100644 --- a/src/_imagingmath.c +++ b/src/_imagingmath.c @@ -189,8 +189,7 @@ _unop(PyObject *self, PyObject *args) { unop(out, im1); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -223,8 +222,7 @@ _binop(PyObject *self, PyObject *args) { binop(out, im1, im2); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyMethodDef _functions[] = { diff --git a/src/_imagingtk.c b/src/_imagingtk.c index 076995daf..03bda9163 100644 --- a/src/_imagingtk.c +++ b/src/_imagingtk.c @@ -36,8 +36,7 @@ _tkinit(PyObject *self, PyObject *args) { /* This will bomb if interp is invalid... */ TkImaging_Init(interp); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyMethodDef functions[] = { diff --git a/src/decode.c b/src/decode.c index 801bab0b3..1660741d3 100644 --- a/src/decode.c +++ b/src/decode.c @@ -209,8 +209,7 @@ _setimage(ImagingDecoderObject *decoder, PyObject *args) { Py_XDECREF(decoder->lock); decoder->lock = op; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -227,8 +226,7 @@ _setfd(ImagingDecoderObject *decoder, PyObject *args) { Py_XINCREF(fd); state->fd = fd; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * diff --git a/src/display.c b/src/display.c index 078016797..30fcd41fc 100644 --- a/src/display.c +++ b/src/display.c @@ -76,8 +76,7 @@ _expose(ImagingDisplayObject *display, PyObject *args) { ImagingExposeDIB(display->dib, hdc); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -103,8 +102,7 @@ _draw(ImagingDisplayObject *display, PyObject *args) { ImagingDrawDIB(display->dib, hdc, dst, src); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } extern Imaging @@ -134,8 +132,7 @@ _paste(ImagingDisplayObject *display, PyObject *args) { ImagingPasteDIB(display->dib, im, xy); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -181,8 +178,7 @@ _releasedc(ImagingDisplayObject *display, PyObject *args) { ReleaseDC(window, dc); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -202,8 +198,7 @@ _frombytes(ImagingDisplayObject *display, PyObject *args) { memcpy(display->dib->bits, buffer.buf, buffer.len); PyBuffer_Release(&buffer); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -698,8 +693,7 @@ PyImaging_EventLoopWin32(PyObject *self, PyObject *args) { } Py_END_ALLOW_THREADS - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } /* -------------------------------------------------------------------- */ diff --git a/src/encode.c b/src/encode.c index 63f16547f..3a20ac9d3 100644 --- a/src/encode.c +++ b/src/encode.c @@ -275,8 +275,7 @@ _setimage(ImagingEncoderObject *encoder, PyObject *args) { Py_XDECREF(encoder->lock); encoder->lock = op; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -293,8 +292,7 @@ _setfd(ImagingEncoderObject *encoder, PyObject *args) { Py_XINCREF(fd); state->fd = fd; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * diff --git a/src/outline.c b/src/outline.c index b84bef437..d5e47caf7 100644 --- a/src/outline.c +++ b/src/outline.c @@ -87,8 +87,7 @@ _outline_move(OutlineObject *self, PyObject *args) { ImagingOutlineMove(self->outline, x0, y0); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -100,8 +99,7 @@ _outline_line(OutlineObject *self, PyObject *args) { ImagingOutlineLine(self->outline, x1, y1); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -113,8 +111,7 @@ _outline_curve(OutlineObject *self, PyObject *args) { ImagingOutlineCurve(self->outline, x1, y1, x2, y2, x3, y3); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -125,8 +122,7 @@ _outline_close(OutlineObject *self, PyObject *args) { ImagingOutlineClose(self->outline); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -138,8 +134,7 @@ _outline_transform(OutlineObject *self, PyObject *args) { ImagingOutlineTransform(self->outline, a); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static struct PyMethodDef _outline_methods[] = { diff --git a/src/path.c b/src/path.c index 50ea57997..e83e35d2a 100644 --- a/src/path.c +++ b/src/path.c @@ -406,8 +406,7 @@ path_map(PyPathObject *self, PyObject *args) { } self->mapping = 0; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static int @@ -519,8 +518,7 @@ path_transform(PyPathObject *self, PyObject *args) { } } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static struct PyMethodDef methods[] = { From 8ba076ae8623e149e35bf031138d0e100dcc181e Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Tue, 17 Sep 2024 15:49:20 +0200 Subject: [PATCH 12/17] Remove unused declaration --- src/libImaging/Imaging.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/libImaging/Imaging.h b/src/libImaging/Imaging.h index 7ba809bf4..fbd67af28 100644 --- a/src/libImaging/Imaging.h +++ b/src/libImaging/Imaging.h @@ -605,10 +605,6 @@ ImagingLibTiffDecode( extern int ImagingLibTiffEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int bytes); #endif -#ifdef HAVE_LIBMPEG -extern int -ImagingMpegDecode(Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes); -#endif extern int ImagingMspDecode(Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes); extern int From 50dd94664bb6b75f82ffbfb9090670af9b698091 Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Tue, 17 Sep 2024 23:30:52 +0200 Subject: [PATCH 13/17] Correct types of _imaging methods Move new_block method to _imaging remove _imaging.convert method --- src/PIL/ImageTk.py | 2 +- src/_imaging.c | 26 ++++++++++---------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/PIL/ImageTk.py b/src/PIL/ImageTk.py index bf29fdba5..b095b589c 100644 --- a/src/PIL/ImageTk.py +++ b/src/PIL/ImageTk.py @@ -181,7 +181,7 @@ class PhotoImage: image = im.im if not image.isblock() or im.mode != self.__mode: block = Image.core.new_block(self.__mode, im.size) - image.convert2(block, image) # convert directly between buffers + image.convert2(block) # convert directly between buffers ptr = block.ptr _pyimagingtkcall("PyImagingPhoto", self.__photo, ptr) diff --git a/src/_imaging.c b/src/_imaging.c index b28284fb5..a1bd8b2ad 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -92,7 +92,7 @@ #define S16(v) ((v) < 32768 ? (v) : ((v) - 65536)) /* -------------------------------------------------------------------- */ -/* OBJECT ADMINISTRATION */ +/* OBJECT ADMINISTRATION */ /* -------------------------------------------------------------------- */ typedef struct { @@ -256,7 +256,7 @@ ImagingError_Clear(void) { } /* -------------------------------------------------------------------- */ -/* HELPERS */ +/* HELPERS */ /* -------------------------------------------------------------------- */ static int @@ -605,7 +605,7 @@ getink(PyObject *color, Imaging im, char *ink) { } /* -------------------------------------------------------------------- */ -/* FACTORIES */ +/* FACTORIES */ /* -------------------------------------------------------------------- */ static PyObject * @@ -688,7 +688,7 @@ _radial_gradient(PyObject *self, PyObject *args) { } static PyObject * -_alpha_composite(ImagingObject *self, PyObject *args) { +_alpha_composite(PyObject *self, PyObject *args) { ImagingObject *imagep1; ImagingObject *imagep2; @@ -702,7 +702,7 @@ _alpha_composite(ImagingObject *self, PyObject *args) { } static PyObject * -_blend(ImagingObject *self, PyObject *args) { +_blend(PyObject *self, PyObject *args) { ImagingObject *imagep1; ImagingObject *imagep2; double alpha; @@ -920,15 +920,12 @@ _convert(ImagingObject *self, PyObject *args) { static PyObject * _convert2(ImagingObject *self, PyObject *args) { - ImagingObject *imagep1; - ImagingObject *imagep2; - if (!PyArg_ParseTuple( - args, "O!O!", &Imaging_Type, &imagep1, &Imaging_Type, &imagep2 - )) { + ImagingObject *imagep; + if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep)) { return NULL; } - if (!ImagingConvert2(imagep1->image, imagep2->image)) { + if (!ImagingConvert2(imagep->image, self->image)) { return NULL; } @@ -3487,7 +3484,7 @@ _effect_spread(ImagingObject *self, PyObject *args) { } /* -------------------------------------------------------------------- */ -/* UTILITIES */ +/* UTILITIES */ /* -------------------------------------------------------------------- */ static PyObject * @@ -3523,7 +3520,7 @@ _getcodecstatus(PyObject *self, PyObject *args) { } /* -------------------------------------------------------------------- */ -/* DEBUGGING HELPERS */ +/* DEBUGGING HELPERS */ /* -------------------------------------------------------------------- */ static PyObject * @@ -4162,9 +4159,6 @@ static PyMethodDef functions[] = { {"new_block", (PyCFunction)_new_block, METH_VARARGS}, {"merge", (PyCFunction)_merge, METH_VARARGS}, - /* Functions */ - {"convert", (PyCFunction)_convert2, METH_VARARGS}, - /* Codecs */ {"bcn_decoder", (PyCFunction)PyImaging_BcnDecoderNew, METH_VARARGS}, {"bit_decoder", (PyCFunction)PyImaging_BitDecoderNew, METH_VARARGS}, From 3a16a350cc0239637dafe9814da29094c06ee997 Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Tue, 17 Sep 2024 16:24:23 +0200 Subject: [PATCH 14/17] Fix Imaging_Type check in _convert --- src/_imaging.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/_imaging.c b/src/_imaging.c index a1bd8b2ad..172d46c55 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -896,17 +896,12 @@ _convert(ImagingObject *self, PyObject *args) { int dither = 0; ImagingObject *paletteimage = NULL; - if (!PyArg_ParseTuple(args, "s|iO", &mode, &dither, &paletteimage)) { + if (!PyArg_ParseTuple( + args, "s|iO!", &mode, &dither, &Imaging_Type, &paletteimage + )) { return NULL; } if (paletteimage != NULL) { - if (!PyImaging_Check(paletteimage)) { - PyObject_Print((PyObject *)paletteimage, stderr, 0); - PyErr_SetString( - PyExc_ValueError, "palette argument must be image with mode 'P'" - ); - return NULL; - } if (paletteimage->image->palette == NULL) { PyErr_SetString(PyExc_ValueError, "null palette"); return NULL; From 37b2a1bbaeb0d2729f5cef1efe7786cf98be1da7 Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Tue, 17 Sep 2024 23:57:26 +0200 Subject: [PATCH 15/17] Cleanup exceptions handling Remove unused module Remove ImagingError_Clear alias Do not set PyExc_TypeError after PySequence_Fast Remove ImagingError_OSError alias Use PyErr_Format when possible --- src/Tk/tkImaging.c | 6 +--- src/_imaging.c | 13 -------- src/libImaging/Convert.c | 19 +++-------- src/libImaging/Except.c | 72 ---------------------------------------- src/libImaging/File.c | 2 +- src/libImaging/Imaging.h | 4 --- src/libImaging/Storage.c | 2 +- 7 files changed, 8 insertions(+), 110 deletions(-) delete mode 100644 src/libImaging/Except.c diff --git a/src/Tk/tkImaging.c b/src/Tk/tkImaging.c index a36c3e0bd..0234d2c78 100644 --- a/src/Tk/tkImaging.c +++ b/src/Tk/tkImaging.c @@ -243,13 +243,9 @@ _dfunc(HMODULE lib_handle, const char *func_name) { * Set Python exception if we can't find `func_name` in `lib_handle`. * Returns function pointer or NULL if not present. */ - - char message[100]; - FARPROC func = GetProcAddress(lib_handle, func_name); if (func == NULL) { - sprintf(message, "Cannot load function %s", func_name); - PyErr_SetString(PyExc_RuntimeError, message); + PyErr_Format(PyExc_RuntimeError, "Cannot load function %s", func_name); } return func; } diff --git a/src/_imaging.c b/src/_imaging.c index 172d46c55..7dad9f80a 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -219,12 +219,6 @@ static const char *no_palette = "image has no palette"; static const char *readonly = "image is readonly"; /* static const char* no_content = "image has no content"; */ -void * -ImagingError_OSError(void) { - PyErr_SetString(PyExc_OSError, "error when accessing file"); - return NULL; -} - void * ImagingError_MemoryError(void) { return PyErr_NoMemory(); @@ -250,11 +244,6 @@ ImagingError_ValueError(const char *message) { return NULL; } -void -ImagingError_Clear(void) { - PyErr_Clear(); -} - /* -------------------------------------------------------------------- */ /* HELPERS */ /* -------------------------------------------------------------------- */ @@ -1534,7 +1523,6 @@ _putdata(ImagingObject *self, PyObject *args) { } else { seq = PySequence_Fast(data, must_be_sequence); if (!seq) { - PyErr_SetString(PyExc_TypeError, must_be_sequence); return NULL; } double value; @@ -1593,7 +1581,6 @@ _putdata(ImagingObject *self, PyObject *args) { /* 32-bit images */ seq = PySequence_Fast(data, must_be_sequence); if (!seq) { - PyErr_SetString(PyExc_TypeError, must_be_sequence); return NULL; } switch (image->type) { diff --git a/src/libImaging/Convert.c b/src/libImaging/Convert.c index 1a410891f..a5b2b89a7 100644 --- a/src/libImaging/Convert.c +++ b/src/libImaging/Convert.c @@ -1669,15 +1669,9 @@ convert( } if (!convert) { -#ifdef notdef - return (Imaging)ImagingError_ValueError("conversion not supported"); -#else - static char buf[100]; - snprintf( - buf, 100, "conversion from %.10s to %.10s not supported", imIn->mode, mode + return (Imaging)PyErr_Format( + PyExc_ValueError, "conversion from %s to %s not supported", imIn->mode, mode ); - return (Imaging)ImagingError_ValueError(buf); -#endif } imOut = ImagingNew2Dirty(mode, imOut, imIn); @@ -1746,15 +1740,12 @@ ImagingConvertTransparent(Imaging imIn, const char *mode, int r, int g, int b) { } g = b = r; } else { - static char buf[100]; - snprintf( - buf, - 100, - "conversion from %.10s to %.10s not supported in convert_transparent", + return (Imaging)PyErr_Format( + PyExc_ValueError, + "conversion from %s to %s not supported in convert_transparent", imIn->mode, mode ); - return (Imaging)ImagingError_ValueError(buf); } imOut = ImagingNew2Dirty(mode, imOut, imIn); diff --git a/src/libImaging/Except.c b/src/libImaging/Except.c deleted file mode 100644 index f42ff9aec..000000000 --- a/src/libImaging/Except.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * The Python Imaging Library - * $Id$ - * - * default exception handling - * - * This module is usually overridden by application code (e.g. - * _imaging.c for PIL's standard Python bindings). If you get - * linking errors, remove this file from your project/library. - * - * history: - * 1995-06-15 fl Created - * 1998-12-29 fl Minor tweaks - * 2003-09-13 fl Added ImagingEnter/LeaveSection() - * - * Copyright (c) 1997-2003 by Secret Labs AB. - * Copyright (c) 1995-2003 by Fredrik Lundh. - * - * See the README file for information on usage and redistribution. - */ - -#include "Imaging.h" - -/* exception state */ - -void * -ImagingError_OSError(void) { - fprintf(stderr, "*** exception: file access error\n"); - return NULL; -} - -void * -ImagingError_MemoryError(void) { - fprintf(stderr, "*** exception: out of memory\n"); - return NULL; -} - -void * -ImagingError_ModeError(void) { - return ImagingError_ValueError("bad image mode"); -} - -void * -ImagingError_Mismatch(void) { - return ImagingError_ValueError("images don't match"); -} - -void * -ImagingError_ValueError(const char *message) { - if (!message) { - message = "exception: bad argument to function"; - } - fprintf(stderr, "*** %s\n", message); - return NULL; -} - -void -ImagingError_Clear(void) { - /* nop */; -} - -/* thread state */ - -void -ImagingSectionEnter(ImagingSectionCookie *cookie) { - /* pass */ -} - -void -ImagingSectionLeave(ImagingSectionCookie *cookie) { - /* pass */ -} diff --git a/src/libImaging/File.c b/src/libImaging/File.c index 76d0abccc..901fe83ad 100644 --- a/src/libImaging/File.c +++ b/src/libImaging/File.c @@ -54,7 +54,7 @@ ImagingSavePPM(Imaging im, const char *outfile) { fp = fopen(outfile, "wb"); if (!fp) { - (void)ImagingError_OSError(); + PyErr_SetString(PyExc_OSError, "error when accessing file"); return 0; } diff --git a/src/libImaging/Imaging.h b/src/libImaging/Imaging.h index fbd67af28..945d861a5 100644 --- a/src/libImaging/Imaging.h +++ b/src/libImaging/Imaging.h @@ -237,8 +237,6 @@ ImagingSectionLeave(ImagingSectionCookie *cookie); /* Exceptions */ /* ---------- */ -extern void * -ImagingError_OSError(void); extern void * ImagingError_MemoryError(void); extern void * @@ -247,8 +245,6 @@ extern void * ImagingError_Mismatch(void); /* maps to ValueError by default */ extern void * ImagingError_ValueError(const char *message); -extern void -ImagingError_Clear(void); /* Transform callbacks */ /* ------------------- */ diff --git a/src/libImaging/Storage.c b/src/libImaging/Storage.c index 522e9f375..634ad71bf 100644 --- a/src/libImaging/Storage.c +++ b/src/libImaging/Storage.c @@ -513,7 +513,7 @@ ImagingNewInternal(const char *mode, int xsize, int ysize, int dirty) { return im; } - ImagingError_Clear(); + PyErr_Clear(); // Try to allocate the image once more with smallest possible block size MUTEX_LOCK(&ImagingDefaultArena.mutex); From 5e07d85161529a718c862dbc8b0173bbebadb645 Mon Sep 17 00:00:00 2001 From: Alexander Karpinsky Date: Wed, 18 Sep 2024 13:38:11 +0200 Subject: [PATCH 16/17] Update comment [ci skip] Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com> --- src/libImaging/Jpeg.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libImaging/Jpeg.h b/src/libImaging/Jpeg.h index d4604f84f..f59f7909e 100644 --- a/src/libImaging/Jpeg.h +++ b/src/libImaging/Jpeg.h @@ -8,7 +8,7 @@ * Copyright (c) 1995-1996 by Fredrik Lundh */ -/* This undefs ruquired for libjpeg v8 and below */ +/* These undefs are required for libjpeg v8 and below */ #undef UINT8 #undef UINT16 From 001ee3147d1a002e0a83ceafab4982330c23a53c Mon Sep 17 00:00:00 2001 From: Alexander Karpinsky Date: Mon, 7 Oct 2024 19:11:22 +0400 Subject: [PATCH 17/17] Update comment Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com> --- src/_imagingcms.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_imagingcms.c b/src/_imagingcms.c index 6d01770cc..27d5ad3b0 100644 --- a/src/_imagingcms.c +++ b/src/_imagingcms.c @@ -26,7 +26,7 @@ kevin@cazabon.com\n\ https://www.cazabon.com\n\ " -#include "libImaging/Imaging.h" // Include before wchar.h so _GNU_SOURCE is set +#include "libImaging/Imaging.h" // Set _GNU_SOURCE in Python.h before wchar.h #include #include