JPEG 2000 support via the hayro-jpeg2000#787
Open
bowenxuuu wants to merge 5 commits into
Open
Conversation
Contributor
Author
|
@LaurenzV |
bowenxuuu
commented
Jun 14, 2026
|
Is this image available somewhere so I can try it myself? |
Contributor
Author
|
Here's the DICOM image. |
|
Okay, so I get it now. The method I added always scales to 16-bit, but what you want is something that always preserves the native bit depth. I think it's best if I instead expose an API for the raw f32 samples, then this should be the same as you are currently doing. |
|
Could you try this one instead? LaurenzV/hayro#1243 I think the code should then look something like this: #[cfg(feature = "hayro-jpeg2000")]
{
use hayro_jpeg2000::{DecodeSettings, DecoderContext, Image};
let image = Image::new(&frame_data, &DecodeSettings::default())
.whatever_context("hayro-jpeg2000 read image failure")?;
let mut ctx = DecoderContext::default();
let decoded = image
.decode(&mut ctx)
.whatever_context("hayro-jpeg2000 decoder failure")?;
let components = decoded.components();
for (component_i, component) in components.iter().enumerate() {
if component_i >= samples_per_pixel as usize {
warn!(
"JPEG 2000 image has more components than expected ({} >= {})",
component_i, samples_per_pixel
);
break;
}
for (i, sample) in component.samples().iter().enumerate() {
let offset = base_offset
+ i * samples_per_pixel as usize * bytes_per_sample as usize
+ component_i * bytes_per_sample as usize;
let sample = sample.round() as u32;
dst[offset..offset + bytes_per_sample as usize]
.copy_from_slice(&sample.to_le_bytes()[..bytes_per_sample as usize]);
}
}
} |
Contributor
Author
|
@LaurenzV Thanks, it works well now. |
|
Should be included in version 0.4.0 now. :) |
Contributor
Author
|
@Enet4 Hello |
# Conflicts: # Cargo.lock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



follow up #751
fix #730