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

fix: use array of mediatypes and transferSyntax when calling a get xhrRequest for image loading #477

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Punzo
Copy link
Contributor

@Punzo Punzo commented Sep 26, 2022

Re IDC OHIF/Viewers#2934

Related to OHIF/Viewers#2934 (comment)

This implements the get image in xhrRequuests using an array of mediaTypes and TransferSyntax (analogous to SLIM viewer https://github.com/herrmannlab/dicom-microscopy-viewer/blob/83739f1ba11840df7f4487cdf8015b7450ee419d/src/pyramid.js#L436-L491 ), instead of always requesting as this default:

 const mediaType =
      'multipart/related; type=application/octet-stream; transfer-syntax=*';

Requesting images with type=application/octet-stream; transfer-syntax=* as default can create several issues. For example as in OHIF/Viewers#2934, the 8 bit colored jpeg will be decoded server side (including color corrections), but then the returned mime and transfer syntax is 1.2.840.10008.1.2 instead of 1.2.840.10008.1.2.4.50 (because the array is already decoded by the server), but at this point cornerstoneWADOLoader willl apply again color corrections (which is based on the photometric Interpretation of the image frame).

With this PR, type=application/octet-stream; transfer-syntax=* will have lower priority and used only as last resource.
For example, in the case of 8 bit colored jpeg, the images will be donwloaded in jpeg format and always decoded (and color transformations applied) client-side.

@netlify
Copy link

netlify bot commented Sep 26, 2022

Deploy Preview for cornerstone-wado-image-loader failed.

Name Link
🔨 Latest commit 213db6a
🔍 Latest deploy log https://app.netlify.com/sites/cornerstone-wado-image-loader/deploys/633559a5ae4c0000081cc49f

@Punzo
Copy link
Contributor Author

Punzo commented Sep 26, 2022

@sedghi can you please review this? thanks!

Copy link
Member

@sedghi sedghi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my comments, refactoring needed

@Punzo
Copy link
Contributor Author

Punzo commented Sep 28, 2022

see my comments, refactoring needed

@sedghi thanks for the review! I have refactored and applied your comments in 55628dd

@Punzo
Copy link
Contributor Author

Punzo commented Sep 29, 2022

@sedghi applied last comment in 213db6a

@Punzo
Copy link
Contributor Author

Punzo commented Sep 29, 2022

@GitanjaliChhetri leaving this to you, but it should be ready, and just merge it


assertMediaTypeIsValid(mediaType);

let fieldValue = `multipart/related; type="${mediaType}"`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should not have type="${mediaType}" it should be type=${mediaType}. Double checking with @wayfarer3130

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @sedghi,
Referring to azure dicom docs, type shoud be in double quotes. Otherwise, 406 response status will be returned.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the DICOM standard it depends on the version, and according to the original RFC for multipart related, the quotes are NOT permitted, although every example in the document shows them. Including them drops the speed by approximately a half because it requires a full extra CORS request, assuming the CORS is used. Not including htem breaks Azure, so the DICOM committee has agreed to a statement that clients need to have an option to fallback from one version to the other. For cornerstone, that is determined by a configuration parameter on the specific back end request, so that you can include them when configured to do so, and omit them otherwise.

@sedghi
Copy link
Member

sedghi commented Oct 5, 2022

so if I understand this, this will create a giant accept header something like

multiplart/related; type="image/x-dicom-rle"; transfer-syntax=1.2.840.10008.1.2.5, multipart/related; type="image/jpeg"; transfer-syntax....., multipart/related; type="application/octstream"; transfer-syntax="*"

is this true?

I need another set of eyes to review this since this can be a bottleneck in the performance

@sedghi
Copy link
Member

sedghi commented Oct 5, 2022

This might be related to this as well cornerstonejs/cornerstone3D#232

@NikGurev
Copy link
Contributor

NikGurev commented Jan 18, 2023

@sedghi
maybe this doc will help you: https://dicom.nema.org/medical/dicom/current/output/chtml/part18/sect_8.7.7.html

If I understand correctly, it's OK to have one or more comma-separated mediatypes. And origin server will ignore all mediatypes that are not valid or not supported.

Any Accept header field values, including media type parameters, that are not valid or not supported shall be ignored by the origin server.

@wayfarer3130
Copy link
Contributor

For the retrieve request, rather than generating a long query URL, you can retrieve just the specific request type you want by using the AvailableTransferSyntaxUID to map to a single accept header. If the back end supports it, you can avoid decoding the multipart/related by requesting single part. The single part request implicitly doesn't use the quotes, so it has no CORS issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants