mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 09:14:27 +03:00
Merge pull request #8592 from radarhere/jpeg2000_cmyk_save
Support saving CMYK JP2 images
This commit is contained in:
commit
1a79d1025c
|
@ -325,6 +325,18 @@ def test_cmyk() -> None:
|
|||
assert im.getpixel((0, 0)) == (185, 134, 0, 0)
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
not os.path.exists(EXTRA_DIR), reason="Extra image files not installed"
|
||||
)
|
||||
@skip_unless_feature_version("jpg_2000", "2.5.3")
|
||||
def test_cmyk_save() -> None:
|
||||
with Image.open(f"{EXTRA_DIR}/issue205.jp2") as jp2:
|
||||
assert jp2.mode == "CMYK"
|
||||
|
||||
im = roundtrip(jp2)
|
||||
assert_image_equal(im, jp2)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("ext", (".j2k", ".jp2"))
|
||||
def test_16bit_monochrome_has_correct_mode(ext: str) -> None:
|
||||
with Image.open("Tests/images/16bit.cropped" + ext) as im:
|
||||
|
|
|
@ -572,10 +572,19 @@ JPEG 2000
|
|||
Pillow reads and writes JPEG 2000 files containing ``L``, ``LA``, ``RGB``,
|
||||
``RGBA``, or ``YCbCr`` data. When reading, ``YCbCr`` data is converted to
|
||||
``RGB`` or ``RGBA`` depending on whether or not there is an alpha channel.
|
||||
Beginning with version 8.3.0, Pillow can read (but not write) ``RGB``,
|
||||
``RGBA``, and ``YCbCr`` images with subsampled components. Pillow supports
|
||||
JPEG 2000 raw codestreams (``.j2k`` files), as well as boxed JPEG 2000 files
|
||||
(``.jp2`` or ``.jpx`` files).
|
||||
|
||||
.. versionadded:: 8.3.0
|
||||
Pillow can read (but not write) ``RGB``, ``RGBA``, and ``YCbCr`` images with
|
||||
subsampled components.
|
||||
|
||||
.. versionadded:: 10.4.0
|
||||
Pillow can read ``CMYK`` images with OpenJPEG 2.5.1 and later.
|
||||
|
||||
.. versionadded:: 11.1.0
|
||||
Pillow can write ``CMYK`` images with OpenJPEG 2.5.3 and later.
|
||||
|
||||
Pillow supports JPEG 2000 raw codestreams (``.j2k`` files), as well as boxed
|
||||
JPEG 2000 files (``.jp2`` or ``.jpx`` files).
|
||||
|
||||
When loading, if you set the ``mode`` on the image prior to the
|
||||
:py:meth:`~PIL.Image.Image.load` method being invoked, you can ask Pillow to
|
||||
|
|
|
@ -58,6 +58,11 @@ Reading JPEG 2000 comments
|
|||
When opening a JPEG 2000 image, the comment may now be read into
|
||||
:py:attr:`~PIL.Image.Image.info` for J2K images, not just JP2 images.
|
||||
|
||||
Saving JPEG 2000 CMYK images
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
With OpenJPEG 2.5.3 or later, Pillow can now save CMYK images as JPEG 2000 files.
|
||||
|
||||
zlib-ng in wheels
|
||||
^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
|
|
@ -330,6 +330,13 @@ j2k_encode_entry(Imaging im, ImagingCodecState state) {
|
|||
components = 4;
|
||||
color_space = OPJ_CLRSPC_SRGB;
|
||||
pack = j2k_pack_rgba;
|
||||
#if ((OPJ_VERSION_MAJOR == 2 && OPJ_VERSION_MINOR == 5 && OPJ_VERSION_BUILD >= 3) || \
|
||||
(OPJ_VERSION_MAJOR == 2 && OPJ_VERSION_MINOR > 5) || OPJ_VERSION_MAJOR > 2)
|
||||
} else if (strcmp(im->mode, "CMYK") == 0) {
|
||||
components = 4;
|
||||
color_space = OPJ_CLRSPC_CMYK;
|
||||
pack = j2k_pack_rgba;
|
||||
#endif
|
||||
} else {
|
||||
state->errcode = IMAGING_CODEC_BROKEN;
|
||||
state->state = J2K_STATE_FAILED;
|
||||
|
|
Loading…
Reference in New Issue
Block a user