-
Notifications
You must be signed in to change notification settings - Fork 82
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
Add support for JPEG-LS decoding #534
Conversation
Ah, I had entertained the idea of linking to charls for JPEG-LS support, but I wouldn't be able to know if people were interested in it. Good that we have a proof of concept now! I may take my time to look into the other crate. From what I can already tell, it is odd to find both the low-level API and the high-level memory safe API in the same crate. Usually We can (and should!) also add tests that decode the test files available from WG04. |
JPEG-LS is still useful, a lot of modalities use it (and for some modalities it is the only compressed format available) so I think it is better to have it supported than relying on gdcm (specially when building for windows). The other crate is using bindgen generated bindings, so I did not think it would be worth it to create a separate crate. But I am open to split it if it helps. |
Updated pixeldata tests to include jpegls samples. |
Great to know! 👍
I would really prefer to follow the convention, if you don't mind. I can also assist in the split if it helps. See also the relevant section from the Cargo book: https://doc.rust-lang.org/cargo/reference/build-scripts.html#-sys-packages |
As suggested, the charls codec has been spit into charls-sys and charls-rs. |
Hey, great to know! Don't you want to take over the crate named |
Done, I have renamed the crate from charls-rs to charls |
Hello. I've been going through the charls bindings so we can polish it a bit before it's used by DICOM-rs. I will send in a few maintenance PR to the other repos, but in the meantime, there are some other concerns about the API provided by the crate that we should also work on.
|
I think there is a call on charls to get data, but this kind of validations are not required per DICOM standard (I could be wrong on this).
I think it is worth exploring how to lower the amount of allocations.
I left it there to pass it to the lower API. So if you know the stride, you can pass it, or if you don't, per charls documentation a value of |
Validation tools may want to cross-check the information from it, but even if we don't use it over here, it may be useful for the the crate itself for testing, and it may help other people interested in working with JPEG-LS for other reasons, so I believe it's worth it. I can help with this if necessary.
I had a better look at the decoder implementation, |
I am applying the suggestion. I have added |
Updated the library and the code on this PR. I did plan to validate the dicom metadata and the data on the spiff header, but according to what I saw, the charls codec doesn't use that header, since it's values are not reliable. |
After doing additional tests, there is a part that can be improved, as it is now, when you decode an image you need to append the results on Now, if we want to reduce the amount of allocations, on fn decode(&self, src: &dyn PixelDataObject, dst: &mut Vec<u8>) -> DecodeResult<()> {
let frames = src.number_of_frames().unwrap_or(1);
let cols = src
.cols()
.context(decode_error::MissingAttributeSnafu { name: "Cols" })?;
let rows = src
.rows()
.context(decode_error::MissingAttributeSnafu { name: "Rows" })?;
let bits_allocated = src
.bits_allocated()
.context(decode_error::MissingAttributeSnafu {
name: "BitsAllocated",
})?;
let samples_per_pixel =
src.samples_per_pixel()
.context(decode_error::MissingAttributeSnafu {
name: "SamplePerPixel",
})?;
let buffer_size = cols * rows * bits_allocated.div(8) * samples_per_pixel * frames;
dst.reserve(buffer_size);
for frame in 0..frames {
self.decode_frame(src, frame, dst)?;
}
Ok(())
} The idea would be to allocate the necessary memory to store the image, that way the |
That makes sense! But I would strongly recommend that |
Other than the comment above, I don't see any major issues so far. I'd say we take care of the PRs over at
And after any eventual optimizations that you might want to make, we would be ready to merge this one. |
I think further optimization, like the one I proposed would be better on another PR if needed. I do not think it is required, as it will not add much performance and changes on the adapters would be required to use it. A good optimization would be to use a mutable slice, and send the adapter a mutable window of the slice, that way the codecs could write it inplace. But this can be done at a later time. And regarding this PR, I don't think further changes will be required. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few copy&paste mistakes in the doc-comments, I will push them right away.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonderful! Thank you for working on JPEG-LS support. 👍
Add jpeg ls decoding support using charls bindings via charls-sys crate