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

First crack at adding dataset read adapter in DS read for deflate #438

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

naterichman
Copy link
Contributor

No description provided.

@Enet4 Enet4 added A-lib Area: library C-object Crate: dicom-object C-pixeldata Crate: dicom-pixeldata C-transfer-syntax Crate: dicom-transfer-syntax-registry labels Mar 22, 2024
@Enet4 Enet4 added the breaking change Hint that this may require a major version bump on release label Apr 14, 2024
@Enet4 Enet4 mentioned this pull request Dec 7, 2024
* Note, not all paths lead to writing, for example using
  `InMemDicomObject.read_dataset_with_dict` would bypass deflate.
* No support for writing right now
Enet4 added 3 commits December 8, 2024 10:03
- make it fully dynamic and pass a lifetime from input to output
- change the rest of the code to fit DataRWAdapter
- revert 'static lifetime constraints
- remove unused file
- remove use of dicom_pixeldata
- inspect dicom object contents
@Enet4
Copy link
Owner

Enet4 commented Dec 8, 2024

I had another try at this. Last time we talked about deflate TS support, the main problem was that the data RW adapter would not allow us to bind the lifetime of the adapted reader/writer to the lifetime of the input reader/writer. With the current signature, this is simply impossible.

So we had to change the trait DataRWAdapter. One way that we can do in modern Rust thanks to GATs is something the likes of this:

pub trait DataRWAdapter {
    type Reader<'r, R: 'r>: Read
        where Self: 'r;
    type Writer<'w, W: 'w>: Write
        where Self: 'w;

    /// Adapt a byte reader.
    fn adapt_reader<R>(&self, reader: R) -> Self::Reader<R>;

    /// Adapt a byte writer.
    fn adapt_reader<W>(&self, writer: W) -> Self::Writer<W>;
}

As delightful as this trait is, it is not dyn-compatible (the new nomenclature for what was previously known as object-safe), so we could not have a registry for any adapter of this kind.

Ultimately, we have to go for a fully dynamic approach with an added lifetime parameter at each method.

pub trait DataRWAdapter {
    /// Adapt a byte reader.
    fn adapt_reader<'r>(&self, reader: Box<dyn Read + 'r>) -> Box<dyn Read + 'r>;

    /// Adapt a byte writer.
    fn adapt_writer<'w>(&self, writer: Box<dyn Write + 'w>) -> Box<dyn Write + 'w>;
}

After propagating the changes to the rest of the code, we thus bring support for deflated DICOM data sets in dicom-dump, dicom-toimage, and many other tools.


This is not yet ready though.

  • dicom-transcode needs a few more tweaks in order to enable reading and writing deflated DICOM files. I can work on this soon-ish. Done
  • Two of the new tests need to be changed. A round trip from deflated DICOM data and back to deflated DICOM data does not guarantee a file with the same size, since it could be done using a different deflate encoder implementation with different compression parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lib Area: library breaking change Hint that this may require a major version bump on release C-object Crate: dicom-object C-pixeldata Crate: dicom-pixeldata C-transfer-syntax Crate: dicom-transfer-syntax-registry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants