Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use enums for Modes and RawModes in C #8510

Open
wants to merge 59 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
abe3dfb
use a struct for mode names instead of just a string
Yay295 Apr 20, 2024
1f2126b
add special modes
Yay295 Apr 21, 2024
cb62dbb
use mode structs in _imaging.c
Yay295 Apr 21, 2024
7a7e838
use mode structs in tkImaging.c
Yay295 Apr 21, 2024
97e29dc
use mode structs in encode.c and decode.c
Yay295 Apr 21, 2024
820f22c
use mode structs in Access.c
Yay295 Apr 21, 2024
b8cead3
use mode structs in AlphaComposite.c
Yay295 Apr 21, 2024
58dedbe
use mode structs in Bands.c
Yay295 Apr 21, 2024
74b112d
use mode structs in Blend.c
Yay295 Apr 21, 2024
08575c6
use mode structs in BoxBlur.c
Yay295 Apr 21, 2024
5197ad7
use mode structs in Chops.c
Yay295 Apr 21, 2024
da808ce
use mode structs in Convert.c
Yay295 Apr 21, 2024
2beb5fa
use mode structs in Draw.c
Yay295 Apr 22, 2024
bc1f506
use mode structs in Effects.c
Yay295 Apr 22, 2024
e6d2f9a
use mode structs in File.c
Yay295 Apr 22, 2024
d2e691c
use mode structs in Fill.c
Yay295 Apr 22, 2024
90ea060
use mode structs in Filter.c
Yay295 Apr 22, 2024
d8f9bfb
use mode structs in Geometry.c
Yay295 Oct 13, 2024
b7c3c3e
use mode structs in GetBBox.c
Yay295 Apr 22, 2024
baa95d6
use mode structs in Histo.c
Yay295 Apr 22, 2024
56e1b3c
use mode structs in Jpeg2KDecode.c
Yay295 Apr 22, 2024
5836c00
use mode structs in Jpeg2KEncode.c
Yay295 Apr 22, 2024
6f127e0
use mode structs in JpegDecode.c
Yay295 Apr 22, 2024
68028fd
use mode structs in JpegEncode.c
Yay295 Apr 22, 2024
e598741
use mode structs in Matrix.c
Yay295 Apr 22, 2024
cf4a42f
add function isModeI16() to check if a mode is an I;16 mode
Yay295 Apr 22, 2024
c906098
use mode structs in Pack.c
Yay295 Apr 22, 2024
c587ad1
use mode structs in Palette.c
Yay295 Apr 22, 2024
26b8178
use mode structs in Paste.c
Yay295 Apr 22, 2024
f2fac0b
use mode structs in Point.c
Yay295 Apr 22, 2024
00f6ecb
use mode structs in Quant.c
Yay295 Apr 22, 2024
adf97ec
use mode structs in Reduce.c
Yay295 Apr 22, 2024
9f28f12
use mode structs in Resample.c
Yay295 Apr 22, 2024
6f0ce3e
use mode structs in Storage.c
Yay295 Apr 22, 2024
91776f2
use mode structs in TiffDecode.c
Yay295 Apr 22, 2024
7cb3efc
use (void) for empty function parameters
Yay295 Apr 22, 2024
4347310
set pointer to NULL after free
Yay295 Apr 22, 2024
ebbe5d8
use mode structs in Unpack.c
Yay295 Apr 22, 2024
1b1f250
use mode structs in map.c
Yay295 Apr 22, 2024
d462843
initialize accessors similar to converters/packers/unpackers
Yay295 Apr 22, 2024
b594a75
define rawmodes
Yay295 Apr 22, 2024
5afeb11
fix findRawMode()
Yay295 Apr 22, 2024
05d7b31
check for null input in findMode() and findRawMode()
Yay295 Apr 22, 2024
7bd8041
replace some string function usage with imaging mode checks
Yay295 Apr 23, 2024
e53aa29
use RawMode struct for jpegmode
Yay295 Apr 23, 2024
20986c8
use Mode struct for windows display code
Yay295 Apr 23, 2024
9c02ccd
change mode structs to enums
Yay295 Apr 23, 2024
5f1858c
use mode enums in _webp.c
Yay295 Apr 23, 2024
268b090
use mode enums in Jpeg2KDecode.c
Yay295 Apr 23, 2024
cb68244
use mode enums in _imagingft.c
Yay295 Apr 23, 2024
4f9b68c
use more mode enums in decode.c
Yay295 Apr 23, 2024
3b33a2c
add Mode.c as a dependency for _imagingft.c and _webp.c
Yay295 Apr 23, 2024
c889643
use a different temp build dir for each module
Yay295 Apr 24, 2024
0d3c59e
build Mode.c as a common library
Yay295 Apr 25, 2024
c3c968e
add debug check that all modes and rawmodes are defined
Yay295 Apr 26, 2024
9642192
use mode enums in _imagingcms.c
Yay295 Apr 26, 2024
f7b5726
require types-setuptools>=75.2.0
Yay295 Oct 28, 2024
3ba2ea7
linter changes
Yay295 Oct 28, 2024
4427767
Merge branch 'main' into mode_enums
radarhere Nov 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ci/requirements-mypy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ sphinx
types-atheris
types-defusedxml
types-olefile
types-setuptools
types-setuptools>=75.2.0
18 changes: 13 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
import sys
import warnings
from collections.abc import Iterator
from typing import Any
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


def get_version() -> str:
version_file = "src/PIL/_version.py"
Expand Down Expand Up @@ -1001,16 +1004,20 @@ def debug_build() -> bool:
return hasattr(sys, "gettotalrefcount") or FUZZING_BUILD


libraries: list[tuple[str, _BuildInfo]] = [
("pil_imaging_mode", {"sources": ["src/libImaging/Mode.c"]}),
]

files: list[str | os.PathLike[str]] = ["src/_imaging.c"]
for src_file in _IMAGING:
files.append("src/" + src_file + ".c")
for src_file in _LIB_IMAGING:
files.append(os.path.join("src/libImaging", src_file + ".c"))
ext_modules = [
Extension("PIL._imaging", files),
Extension("PIL._imagingft", ["src/_imagingft.c"]),
Extension("PIL._imagingcms", ["src/_imagingcms.c"]),
Extension("PIL._webp", ["src/_webp.c"]),
Extension("PIL._imaging", files, libraries=["pil_imaging_mode"]),
Extension("PIL._imagingft", ["src/_imagingft.c"], libraries=["pil_imaging_mode"]),
Extension("PIL._imagingcms", ["src/_imagingcms.c"], libraries=["pil_imaging_mode"]),
Extension("PIL._webp", ["src/_webp.c"], libraries=["pil_imaging_mode"]),
Extension("PIL._imagingtk", ["src/_imagingtk.c", "src/Tk/tkImaging.c"]),
Extension("PIL._imagingmath", ["src/_imagingmath.c"]),
Extension("PIL._imagingmorph", ["src/_imagingmorph.c"]),
Expand All @@ -1026,6 +1033,7 @@ def debug_build() -> bool:
setup(
cmdclass={"build_ext": pil_build_ext},
ext_modules=ext_modules,
libraries=libraries,
zip_safe=not (debug_build() or PLATFORM_MINGW),
)
except RequiredDependencyException as err:
Expand Down
7 changes: 4 additions & 3 deletions src/Tk/tkImaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,16 @@ PyImagingPhotoPut(

/* Mode */

if (strcmp(im->mode, "1") == 0 || strcmp(im->mode, "L") == 0) {
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 (strncmp(im->mode, "RGB", 3) == 0) {
} else if (im->mode == IMAGING_MODE_RGB || im->mode == IMAGING_MODE_RGBA ||
im->mode == IMAGING_MODE_RGBX || im->mode == IMAGING_MODE_RGBa) {
block.pixelSize = 4;
block.offset[0] = 0;
block.offset[1] = 1;
block.offset[2] = 2;
if (strcmp(im->mode, "RGBA") == 0) {
if (im->mode == IMAGING_MODE_RGBA) {
block.offset[3] = 3; /* alpha (or reserved, under Tk 8.2) */
} else {
block.offset[3] = 0; /* no alpha */
Expand Down
Loading
Loading