Baseline support for deflate transfer syntaxes with dataset adapter rewrite#438
Baseline support for deflate transfer syntaxes with dataset adapter rewrite#438Enet4 merged 29 commits intoEnet4:masterfrom
Conversation
|
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 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 This is not yet ready though.
|
|
Good news and bad news. The good news is that this pull request is ready. The bad news is that I could not find any issues in the latest revision so far. Maybe you can help cracking down any eventual bugs? 😆 |
naterichman
left a comment
There was a problem hiding this comment.
Looks good to me, just a couple comments. Sorry for the long delay on this, I've been super busy!
There was a problem hiding this comment.
I can't remember what the behavior of this was, but I feel like we should make a Dataset encoding for this that panics with a message about adding the deflate feature.
There was a problem hiding this comment.
A bit torn on that one. Unless I overlooked something, the way to do that is to create and declare a stub data set implementation which raises an error whenever it is called. Semantically, the system would be claiming to support deflated explicit VR little endian at Codec level (on checking that it matches Codec::Dataset(Some(_))), but then still fail at run-time. So any application depending on this check in an automatic discovery of supported transfer syntaxes would be at risk of inadvertently including the stub.
OK, there is one other thing that we can try, which is to adapt the error message in places where support for certain transfer syntaxes were requested, and suggest enabling features there. Need to investigate.
There was a problem hiding this comment.
I extended the error types ReadError and WriteError in dicom_object so that they can provide a suggestion to enable a Cargo feature in order to support that transfer syntax. For example:
❯ cargo run -p dicom-toimage --no-default-features --bin dicom-toimage -- ../dicom-test-files/data/pydicom/image_dfl.dcm
025-06-21T18:45:02.927669Z ERROR dicom_toimage: could not read DICOM file ../dicom-test-files/data/pydicom/image_dfl.dcm
Caused by this error:
1: Unsupported reading for transfer syntax `1.2.840.10008.1.2.1.99` (Deflated Explicit VR Little Endian, try enabling feature `dicom-transfer-syntax-registry/deflate`)
There was a problem hiding this comment.
A bit torn on that one. Unless I overlooked something, the way to do that is to create and declare a stub data set implementation which raises an error whenever it is called. Semantically, the system would be claiming to support deflated explicit VR little endian at Codec level (on checking that it matches Codec::Dataset(Some(_))), but then still fail at run-time. So any application depending on this check in an automatic discovery of supported transfer syntaxes would be at risk of inadvertently including the stub.
OK, there is one other thing that we can try, which is to adapt the error message in places where support for certain transfer syntaxes were requested, and suggest enabling features there. Need to investigate.
|
Thanks for adding this feature. We would like to be able to use it. Are there any blockers to merging the PR Eduardo? |
|
Hello @rforsyth! The short-term plan is to gather the contributions without breaking changes into v0.8.2, then we'll immediately start joining all pending breaking changes for v0.9.0. I hope to get to this soon, as I understand it's been a while since the last release. |
* Note, not all paths lead to writing, for example using `InMemDicomObject.read_dataset_with_dict` would bypass deflate. * No support for writing right now
- 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
- JPIP Referenced Deflate - JPIP HTJ2K Referenced Deflate
- check for differences in encapsulated data from source TS to target TS instead of whether they are codec-free
- only run it if JPIP Referenced Deflate is not fully supported yet
- split unsupported transfer syntax into unrecognized (not found in registry) and unsupported (requires dataset adapter impl) - split unsupported TS error further to show suggested feature name (in case of deflated TSes)
- move common logic into read_parts_with_all_options_impl - add SOP attribute inference to from_reader - move detect_preamble function
- do not try to read it if the transfer syntax requires a dataset adapter that the TS specified does not have
- the features are not needed for baseline dicom-object capabilities
- remove deflate as a default feature - propagate deflate feature to dicom-object and dicom-pixeldata - [pixeldata] add deflate as a capability in "native" - [ts-registry][pixeldata] extend and reorganize root documentation
- add support for other deflated TSes
|
We're ready to merge this. Thanks again @naterichman. 💪 |
No description provided.