-
Notifications
You must be signed in to change notification settings - Fork 3
feat(transcode): support transcoding #44
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
Changes from 3 commits
c8e86bd
549b61b
e61db5d
c7759c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,10 @@ | |
| use async_trait::async_trait; | ||
| use dicom::core::VR; | ||
| use dicom::dictionary_std::tags; | ||
| use dicom::encoding::TransferSyntaxIndex; | ||
| use dicom::object::{FileDicomObject, InMemDicomObject}; | ||
| use dicom::transfer_syntax::TransferSyntaxRegistry; | ||
| use dicom_pixeldata::Transcode; | ||
| use futures::stream::BoxStream; | ||
| use futures::{Stream, StreamExt}; | ||
| use pin_project::pin_project; | ||
|
|
@@ -104,6 +107,7 @@ | |
| async fn metadata(&self, request: MetadataRequest) -> Result<InstanceResponse, RetrieveError> { | ||
| self.retrieve(RetrieveInstanceRequest { | ||
| query: request.query, | ||
| transfer_syntax: None, | ||
| }) | ||
| .await | ||
| } | ||
|
|
@@ -263,11 +267,26 @@ | |
| stream: impl Stream<Item = Result<Arc<FileDicomObject<InMemDicomObject>>, MoveError>> | ||
| + Send | ||
| + 'a, | ||
| transfer_syntax_uid: Option<&str>, | ||
| ) -> Self { | ||
| let transfer_syntax_uid = transfer_syntax_uid | ||
| .map(|ts_uid| TransferSyntaxRegistry.get(&ts_uid)) | ||
|
|
||
| .flatten(); | ||
|
|
||
|
|
||
| let multipart_stream = stream | ||
| .map(|item| { | ||
| .map(move |item| { | ||
| let transfer_syntax_uid = transfer_syntax_uid.clone(); | ||
|
|
||
| item.and_then(|object| { | ||
| Self::write(&object).map_err(|err| MoveError::Write(WriteError::Io(err))) | ||
| if let Some(ts) = transfer_syntax_uid { | ||
| let mut transcoded = (*object).clone(); | ||
| transcoded | ||
| .transcode(&ts) | ||
|
|
||
| .map_err(|err| MoveError::Transcode(err))?; | ||
|
|
||
| Self::write(&transcoded) | ||
| .map_err(|err| MoveError::Write(WriteError::Io(err))) | ||
| } else { | ||
| Self::write(&object).map_err(|err| MoveError::Write(WriteError::Io(err))) | ||
| } | ||
| }) | ||
| }) | ||
| .chain(futures::stream::once(async { | ||
|
|
@@ -276,7 +295,7 @@ | |
| .boxed(); | ||
|
|
||
| Self { | ||
| inner: multipart_stream, | ||
Check warningCode scanning / clippy variables can be used directly in the format! string Warning
variables can be used directly in the format! string
Check warningCode scanning / clippy variables can be used directly in the format! string Warning
variables can be used directly in the format! string
|
||
| } | ||
| } | ||
|
|
||
|
|
@@ -289,8 +308,13 @@ | |
| let mut buffer = Vec::new(); | ||
|
|
||
| writeln!(buffer, "--boundary\r")?; | ||
| writeln!(buffer, "Content-Type: application/dicom\r")?; | ||
| writeln!(buffer, "Content-Length: {file_length}\r")?; | ||
| writeln!( | ||
| buffer, | ||
| "Content-Type: {}; transfer-syntax=\"{}\"\r", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Transfer syntax UIDs might have a trailing null character (\0), which trim does not remove. So it might be worth looking for places where these null characters can emerge by mistake in the output (there was something in the first screenshot).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a commit trimming these trailings null in this place. I think in this PR this is the only relevant place |
||
| "application/dicom", | ||
|
|
||
| file.meta().transfer_syntax.trim_end_matches('\0') | ||
| )?; | ||
| writeln!(buffer, "Content-Length: {}\r", file_length)?; | ||
| writeln!(buffer, "\r")?; | ||
| buffer.append(&mut dcm); | ||
| writeln!(buffer, "\r")?; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.