Skip to content

Commit

Permalink
Fix using MCT with RGB, update type hints to remove bytearray for enc…
Browse files Browse the repository at this point in the history
…oding (#92)
  • Loading branch information
scaramallion authored Mar 25, 2024
1 parent f45f309 commit d27f807
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
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

0 comments on commit d27f807

Please sign in to comment.