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

Fix using MCT with RGB, update type hints #92

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 10 additions & 9 deletions openjpeg/tests/test_encode.py
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,7 @@ def test_photometric_interpretation(self):
"pixel_representation": 0,
"bits_stored": 8,
}
for pi in ("RGB", "YBR_ICT", "YBR_RCT"):
for pi in ("YBR_ICT", "YBR_RCT"):
buffer = encode_pixel_data(
arr.tobytes(),
photometric_interpretation=pi,
Expand All @@ -1722,14 +1722,15 @@ def test_photometric_interpretation(self):
param = parse_j2k(buffer)
assert param["mct"] is True

buffer = encode_pixel_data(
arr.tobytes(),
photometric_interpretation="YBR_FULL",
use_mct=True,
**kwargs,
)
param = parse_j2k(buffer)
assert param["mct"] is False
for pi in ("RGB", "YBR_FULL", "MONOCHROME1"):
buffer = encode_pixel_data(
arr.tobytes(),
photometric_interpretation=pi,
use_mct=True,
**kwargs,
)
param = parse_j2k(buffer)
assert param["mct"] is False

def test_codec_format_ignored(self):
"""Test that codec_format gets ignored."""
Expand Down
14 changes: 6 additions & 8 deletions openjpeg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ def encode_array(


def encode_buffer(
src: Union[bytes, bytearray],
src: bytes,
columns: int,
rows: int,
samples_per_pixel: int,
Expand Down Expand Up @@ -609,7 +609,7 @@ def encode_buffer(

Parameters
----------
src : bytes | bytearray
src : bytes
A single frame of little endian, colour-by-pixel ordered image data to
be JPEG 2000 encoded. Each pixel should be encoded using the following
(each pixel has 1 or more samples):
Expand Down Expand Up @@ -712,16 +712,14 @@ def encode_buffer(
return cast(bytes, buffer)


def encode_pixel_data(
src: Union[bytes, bytearray], **kwargs: Any
) -> bytes:
def encode_pixel_data(src: bytes, **kwargs: Any) -> bytes:
"""Return the JPEG 2000 compressed `src`.

.. versionadded:: 2.2

Parameters
----------
src : bytes | bytearray
src : bytes
A single frame of little endian, colour-by-pixel ordered image data to
be JPEG2000 encoded. Each pixel should be encoded using the following:

Expand All @@ -743,7 +741,7 @@ def encode_pixel_data(

* ``'use_mct'``: bool: ``True`` to use MCT with RGB images (default)
``False`` otherwise. Will be ignored if `photometric_interpretation`
is not RGB, YBR_RCT or YBR_ICT.
is not YBR_RCT or YBR_ICT.
* ''`compression_ratios'``: list[float] - required for lossy encoding if
`signal_noise_ratios` is not used. The desired compression ratio to
use for each quality layer.
Expand All @@ -759,7 +757,7 @@ def encode_pixel_data(
# A J2K codestream doesn't track the colour space, so the photometric
# interpretation is only used to help with setting MCT
pi = kwargs["photometric_interpretation"]
if pi in ("RGB", "YBR_ICT", "YBR_RCT"):
if pi in ("YBR_ICT", "YBR_RCT"):
kwargs["photometric_interpretation"] = 1
else:
kwargs["photometric_interpretation"] = 0
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ packages = [
{include = "openjpeg" },
]
readme = "README.md"
version = "2.2.0"
version = "2.2.1"


[tool.poetry.dependencies]
Expand Down