-
Notifications
You must be signed in to change notification settings - Fork 124
454 refactored Encoding/Decoding logic to expose DICOM encoding mappings for consumption #455
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
Open
luissantosHCIT
wants to merge
6
commits into
dcmjs-org:master
Choose a base branch
from
luissantosHCIT:454_incorrect_decoding_of_iso_ir_100
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3d8f679
chore refactored proper location of dictionaries and removed redundan…
b2fa72d
chore refactored the logic for switching to target decoder such that …
4d55daf
chore Forgot to pass the ignoreErrors flag.
6b70b60
chore Moved the decoder logic to the base BufferStream class since it…
5596de1
chore Refactored core encoding decoding logic to be in its own class …
50327d2
chore Added docstrings to new class to clarify usage and expectations.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,68 +13,6 @@ import { log } from "./log.js"; | |
| import { deepEqual } from "./utilities/deepEqual"; | ||
| import { ValueRepresentation } from "./ValueRepresentation.js"; | ||
|
|
||
| const singleVRs = ["SQ", "OF", "OW", "OB", "UN", "LT"]; | ||
|
|
||
| const encodingMapping = { | ||
| "": "iso-8859-1", | ||
| "iso-ir-6": "iso-8859-1", | ||
| "iso-ir-13": "shift-jis", | ||
| "iso-ir-100": "latin1", | ||
| "iso-ir-101": "iso-8859-2", | ||
| "iso-ir-109": "iso-8859-3", | ||
| "iso-ir-110": "iso-8859-4", | ||
| "iso-ir-126": "iso-ir-126", | ||
| "iso-ir-127": "iso-ir-127", | ||
| "iso-ir-138": "iso-ir-138", | ||
| "iso-ir-144": "iso-ir-144", | ||
| "iso-ir-148": "iso-ir-148", | ||
| "iso-ir-166": "tis-620", | ||
| "iso-2022-ir-6": "iso-8859-1", | ||
| "iso-2022-ir-13": "shift-jis", | ||
| "iso-2022-ir-87": "iso-2022-jp", | ||
| "iso-2022-ir-100": "latin1", | ||
| "iso-2022-ir-101": "iso-8859-2", | ||
| "iso-2022-ir-109": "iso-8859-3", | ||
| "iso-2022-ir-110": "iso-8859-4", | ||
| "iso-2022-ir-126": "iso-ir-126", | ||
| "iso-2022-ir-127": "iso-ir-127", | ||
| "iso-2022-ir-138": "iso-ir-138", | ||
| "iso-2022-ir-144": "iso-ir-144", | ||
| "iso-2022-ir-148": "iso-ir-148", | ||
| "iso-2022-ir-149": "euc-kr", | ||
| "iso-2022-ir-159": "iso-2022-jp", | ||
| "iso-2022-ir-166": "tis-620", | ||
| "iso-2022-ir-58": "iso-ir-58", | ||
| "iso-ir-192": "utf-8", | ||
| gb18030: "gb18030", | ||
| "iso-2022-gbk": "gbk", | ||
| "iso-2022-58": "gb2312", | ||
| gbk: "gbk" | ||
| }; | ||
|
|
||
| const encapsulatedSyntaxes = [ | ||
| "1.2.840.10008.1.2.4.50", | ||
| "1.2.840.10008.1.2.4.51", | ||
| "1.2.840.10008.1.2.4.57", | ||
| "1.2.840.10008.1.2.4.70", | ||
| "1.2.840.10008.1.2.4.80", | ||
| "1.2.840.10008.1.2.4.81", | ||
| "1.2.840.10008.1.2.4.90", | ||
| "1.2.840.10008.1.2.4.91", | ||
| "1.2.840.10008.1.2.4.92", | ||
| "1.2.840.10008.1.2.4.93", | ||
| "1.2.840.10008.1.2.4.94", | ||
| "1.2.840.10008.1.2.4.95", | ||
| "1.2.840.10008.1.2.5", | ||
| "1.2.840.10008.1.2.6.1", | ||
| "1.2.840.10008.1.2.4.100", | ||
| "1.2.840.10008.1.2.4.102", | ||
| "1.2.840.10008.1.2.4.103", | ||
| "1.2.840.10008.1.2.4.201", | ||
| "1.2.840.10008.1.2.4.202", | ||
| "1.2.840.10008.1.2.4.203" | ||
| ]; | ||
|
|
||
| class DicomMessage { | ||
| static read( | ||
| bufferStream, | ||
|
|
@@ -132,18 +70,10 @@ class DicomMessage { | |
| } | ||
| if (cleanTagString === "00080005") { | ||
| if (readInfo.values.length > 0) { | ||
| let coding = readInfo.values[0]; | ||
| coding = coding.replace(/[_ ]/g, "-").toLowerCase(); | ||
| if (coding in encodingMapping) { | ||
| coding = encodingMapping[coding]; | ||
| bufferStream.setDecoder(new TextDecoder(coding)); | ||
| } else if (ignoreErrors) { | ||
| log.warn( | ||
| `Unsupported character set: ${coding}, using default character set` | ||
| ); | ||
| } else { | ||
| throw Error(`Unsupported character set: ${coding}`); | ||
| } | ||
| bufferStream.setDecoder( | ||
| readInfo.values[0], | ||
| ignoreErrors | ||
| ); | ||
| } | ||
| if (readInfo.values.length > 1) { | ||
| if (ignoreErrors) { | ||
|
|
@@ -182,9 +112,9 @@ class DicomMessage { | |
|
|
||
| static _normalizeSyntax(syntax) { | ||
| if ( | ||
| syntax == IMPLICIT_LITTLE_ENDIAN || | ||
| syntax == EXPLICIT_LITTLE_ENDIAN || | ||
| syntax == EXPLICIT_BIG_ENDIAN | ||
| syntax === IMPLICIT_LITTLE_ENDIAN || | ||
| syntax === EXPLICIT_LITTLE_ENDIAN || | ||
| syntax === EXPLICIT_BIG_ENDIAN | ||
| ) { | ||
| return syntax; | ||
| } else { | ||
|
|
@@ -193,7 +123,7 @@ class DicomMessage { | |
| } | ||
|
|
||
| static isEncapsulated(syntax) { | ||
| return encapsulatedSyntaxes.indexOf(syntax) != -1; | ||
| return DicomMetaDictionary.encapsulatedSyntaxes.indexOf(syntax) !== -1; | ||
| } | ||
|
|
||
| static readFile( | ||
|
|
@@ -331,12 +261,10 @@ class DicomMessage { | |
| } | ||
| ) { | ||
| const { untilTag, includeUntilTagValue } = options; | ||
| var implicit = syntax == IMPLICIT_LITTLE_ENDIAN ? true : false, | ||
| var implicit = syntax === IMPLICIT_LITTLE_ENDIAN, | ||
| isLittleEndian = | ||
| syntax == IMPLICIT_LITTLE_ENDIAN || | ||
| syntax == EXPLICIT_LITTLE_ENDIAN | ||
| ? true | ||
| : false; | ||
| syntax === IMPLICIT_LITTLE_ENDIAN || | ||
| syntax === EXPLICIT_LITTLE_ENDIAN; | ||
|
|
||
| var oldEndian = stream.isLittleEndian; | ||
| stream.setEndian(isLittleEndian); | ||
|
|
@@ -359,11 +287,11 @@ class DicomMessage { | |
| vrType = elementData.vr; | ||
| } else { | ||
| //unknown tag | ||
| if (length == 0xffffffff) { | ||
| if (length === 0xffffffff) { | ||
| vrType = "SQ"; | ||
| } else if (tag.isPixelDataTag()) { | ||
| vrType = "OW"; | ||
| } else if (vrType == "xs") { | ||
| } else if (vrType === "xs") { | ||
| vrType = "US"; | ||
| } else if (tag.isPrivateCreator()) { | ||
| vrType = "LO"; | ||
|
|
@@ -413,18 +341,21 @@ class DicomMessage { | |
| } else { | ||
| const { rawValue, value } = | ||
| vr.read(stream, length, syntax, options) || {}; | ||
| if (!vr.isBinary() && singleVRs.indexOf(vr.type) == -1) { | ||
| if ( | ||
| !vr.isBinary() && | ||
| ValueRepresentation.singleVRs.indexOf(vr.type) === -1 | ||
|
Contributor
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. Use ValueRepresentation.singleVRs.has(vr.type) |
||
| ) { | ||
| rawValues = rawValue; | ||
| values = value; | ||
| if (typeof value === "string") { | ||
| const delimiterChar = String.fromCharCode(VM_DELIMITER); | ||
| rawValues = vr.dropPadByte(rawValue.split(delimiterChar)); | ||
| values = vr.dropPadByte(value.split(delimiterChar)); | ||
| } | ||
| } else if (vr.type == "SQ") { | ||
| } else if (vr.type === "SQ") { | ||
| rawValues = rawValue; | ||
| values = value; | ||
| } else if (vr.type == "OW" || vr.type == "OB") { | ||
| } else if (vr.type === "OW" || vr.type === "OB") { | ||
| rawValues = rawValue; | ||
| values = value; | ||
| } else { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This should be it's own file.
Also, the encoder/decoder should be identical because there are cases that both reading and writing occur on a single dicom buffer.
Would like to see a small unit test on this.
The default for both should actually be latin1 until the specific character set gets written.