Skip to content

Save all MODES as all SAVE formats#9447

Open
CTimmerman wants to merge 3 commits intopython-pillow:mainfrom
CTimmerman:main
Open

Save all MODES as all SAVE formats#9447
CTimmerman wants to merge 3 commits intopython-pillow:mainfrom
CTimmerman:main

Conversation

@CTimmerman
Copy link
Contributor

@CTimmerman CTimmerman commented Feb 23, 2026

Fixes #2663
Fixes #9428

Changes proposed in this pull request:

  • Save all MODES as all SAVE formats.
  • Accept extensions in format for unnamed file object saving of mode L in BW etc.
  • Document name feature of file pointer if user still prefers to not use the format parameter for nameless file objects.
  • Convert between all MODES.
@CTimmerman CTimmerman force-pushed the main branch 4 times, most recently from e7ef6c7 to f8eb039 Compare February 23, 2026 01:22
@CTimmerman CTimmerman marked this pull request as draft February 23, 2026 01:25
@CTimmerman CTimmerman changed the title Save all MODES except La and LAB as all 53 SAVE formats Save all MODES as all SAVE formats Feb 23, 2026
@CTimmerman CTimmerman force-pushed the main branch 11 times, most recently from 0be9ef1 to bff2850 Compare February 25, 2026 22:15
@CTimmerman CTimmerman marked this pull request as ready for review February 26, 2026 10:38
@CTimmerman
Copy link
Contributor Author

CTimmerman commented Feb 26, 2026

I don't know why only amazon-2-amd64 failed to load the jpeg2k plugin, but that might relate to #9432.

Also, mode CMYK fails to save in Jpeg2k plugin, but only on the Ubuntu test machines, so on sys.platform "linux" i also convert CMYK to RGBA when saving JPEG2000.

@radarhere
Copy link
Member

radarhere commented Feb 26, 2026

I don't know why only amazon-2-amd64 failed to load the jpeg2k plugin

It would be because OpenJPEG is not installed - https://github.com/python-pillow/Pillow/actions/runs/22418319033/job/64909670542?pr=9447#step:6:694

External libraries are not always installed by users in the real world either, and tests should accommodate this by avoiding checking that functionality with something like

if ext == ".jp2" and not features.check_codec("jpg_2000"):

or
@skip_unless_feature("webp")

@CTimmerman CTimmerman force-pushed the main branch 2 times, most recently from c2f1ac9 to 9b5e8d6 Compare February 26, 2026 12:21
@CTimmerman
Copy link
Contributor Author

CTimmerman commented Feb 26, 2026

Thanks for the touch up. I assume since the modebase uses the same color space as the mode, it doesn't need the dither argument? checks implementation Nope, that only returns L or RGB so should get dithered as well.

@CTimmerman CTimmerman force-pushed the main branch 3 times, most recently from 647dd2f to 0e6eb12 Compare February 26, 2026 15:56
@CTimmerman
Copy link
Contributor Author

That one fail is a pipeline glitch.

@CTimmerman
Copy link
Contributor Author

I see the struct error for PCX with a zero size is 'H' format requires 0 <= number <= 65535 which is confusing as the size was zero, so i'll restore the ValueError code.

@CTimmerman
Copy link
Contributor Author

CTimmerman commented Mar 1, 2026

save_all still needs work.

Update: Fixed.

@CTimmerman CTimmerman force-pushed the main branch 5 times, most recently from 2d07f47 to aba34a7 Compare March 2, 2026 11:50
@CTimmerman
Copy link
Contributor Author

The LAB to RGBA code in Image.py appears to be redundant, and the missing handler case should break. Updating code.

@CTimmerman CTimmerman force-pushed the main branch 2 times, most recently from e295db6 to 81256f8 Compare March 2, 2026 14:26
@CTimmerman
Copy link
Contributor Author

CTimmerman commented Mar 2, 2026

Image.MODES is a superset of the ones tested in Tests\test_image_convert.py
Modes to test: 13: ('1', 'L', 'LA', 'P', 'PA', 'I', 'F', 'RGB', 'RGBA', 'RGBX', 'CMYK', 'YCbCr', 'HSV')
Modes there are: 20: ['1', 'CMYK', 'F', 'HSV', 'I', 'I;16', 'I;16B', 'I;16L', 'I;16N', 'L', 'LA', 'La', 'LAB', 'P', 'PA', 'RGB', 'RGBA', 'RGBa', 'RGBX', 'YCbCr']

The 7 differences are:

>>> set(['1', 'CMYK', 'F', 'HSV', 'I', 'I;16', 'I;16B', 'I;16L', 'I;16N', 'L', 'LA', 'La', 'LAB', 'P', 'PA', 'RGB', 'RGBA', 'RGBa', 'RGBX', 'YCbCr']) - set(('1', 'L', 'LA', 'P', 'PA', 'I', 'F', 'RGB', 'RGBA', 'RGBX', 'CMYK', 'YCbCr', 'HSV')) {'I;16', 'I;16N', 'LAB', 'I;16B', 'RGBa', 'I;16L', 'La'}

All work now.

Document name feature of file pointer
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants