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

Handle 16-bit containers with 8-bit samples when encoding bytes #21

Merged
merged 2 commits into from
Feb 18, 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
18 changes: 12 additions & 6 deletions jpeg_ls/CharLS.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ def encode_buffer(
Parameters
----------
src : bytes
The image data to be JPEG-LS encoded.
The little-endian ordered image data to be JPEG-LS encoded. May use
either 8- or 16-bits per pixel, as long as the bit-depth is sufficient
for `bits_stored`.
rows : int
The number of rows of pixels in the image.
columns : int
Expand Down Expand Up @@ -275,11 +277,15 @@ def encode_buffer(
length_src = len(src)
length_expected = rows * columns * samples_per_pixel * bytes_per_pixel
if length_expected != length_src:
raise ValueError(
f"The 'src' length of {length_src} bytes does not match the expected "
"length determined from 'rows', 'columns', 'samples_per_pixel' and "
"'bits_stored'"
)
if length_expected * 2 != length_src:
raise ValueError(
f"The 'src' length of {length_src} bytes does not match the expected "
"length determined from 'rows', 'columns', 'samples_per_pixel' and "
"'bits_stored'"
)

# 16-bits per pixel for bits_stored <= 8
src = src[::2]

return _CharLS._encode(
src,
Expand Down
Loading
Loading