dcmjs 0.43.1 → 0.44.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/dcmjs.es.js CHANGED
@@ -9028,7 +9028,7 @@ function toWindows(inputArray, size) {
9028
9028
  }
9029
9029
  var DicomMessage$3, Tag$1;
9030
9030
  var binaryVRs = ["FL", "FD", "SL", "SS", "UL", "US", "AT"],
9031
- explicitVRs = ["OB", "OW", "OF", "SQ", "UC", "UR", "UT", "UN", "OD"],
9031
+ length32VRs = ["OB", "OW", "OF", "SQ", "UC", "UR", "UT", "UN", "OD"],
9032
9032
  singleVRs$1 = ["SQ", "OF", "OW", "OB", "UN"];
9033
9033
  var ValueRepresentation = /*#__PURE__*/function () {
9034
9034
  function ValueRepresentation(type) {
@@ -9037,7 +9037,7 @@ var ValueRepresentation = /*#__PURE__*/function () {
9037
9037
  this.multi = false;
9038
9038
  this._isBinary = binaryVRs.indexOf(this.type) != -1;
9039
9039
  this._allowMultiple = !this._isBinary && singleVRs$1.indexOf(this.type) == -1;
9040
- this._isExplicit = explicitVRs.indexOf(this.type) != -1;
9040
+ this._isLength32 = length32VRs.indexOf(this.type) != -1;
9041
9041
  this._storeRaw = true;
9042
9042
  }
9043
9043
  _createClass(ValueRepresentation, [{
@@ -9050,10 +9050,30 @@ var ValueRepresentation = /*#__PURE__*/function () {
9050
9050
  value: function allowMultiple() {
9051
9051
  return this._allowMultiple;
9052
9052
  }
9053
+
9054
+ /**
9055
+ * Returns if the length is 32 bits. This has nothing to do with being
9056
+ * explicit or not, it only has to do with encoding.
9057
+ * @deprecated Replaced by isLength32
9058
+ */
9053
9059
  }, {
9054
9060
  key: "isExplicit",
9055
9061
  value: function isExplicit() {
9056
- return this._isExplicit;
9062
+ return this._isLength32;
9063
+ }
9064
+
9065
+ /**
9066
+ * Returns if the length is 32 bits. This has nothing to do with being
9067
+ * explicit or not, it only has to do with encoding.
9068
+ *
9069
+ * This used to be isExplicit, which was wrong as both encodings are explicit,
9070
+ * just one uses a single 4 byte word to encode both VR and length, and
9071
+ * the isLength32 always use a separate 32 bit length.
9072
+ */
9073
+ }, {
9074
+ key: "isLength32",
9075
+ value: function isLength32() {
9076
+ return this._isLength32;
9057
9077
  }
9058
9078
 
9059
9079
  /**
@@ -10481,7 +10501,7 @@ var ParsedUnknownValue = /*#__PURE__*/function (_BinaryRepresentation2) {
10481
10501
  _this28.noMultiple = true;
10482
10502
  _this28._isBinary = true;
10483
10503
  _this28._allowMultiple = false;
10484
- _this28._isExplicit = true;
10504
+ _this28._isLength32 = true;
10485
10505
  _this28._storeRaw = true;
10486
10506
  return _this28;
10487
10507
  }
@@ -10706,11 +10726,11 @@ var Tag = /*#__PURE__*/function () {
10706
10726
  }, {
10707
10727
  key: "write",
10708
10728
  value: function write(stream, vrType, values, syntax, writeOptions) {
10709
- var vr = ValueRepresentation.createByTypeString(vrType),
10710
- useSyntax = DicomMessage$1._normalizeSyntax(syntax);
10711
- var implicit = useSyntax == IMPLICIT_LITTLE_ENDIAN ? true : false,
10712
- isLittleEndian = useSyntax == IMPLICIT_LITTLE_ENDIAN || useSyntax == EXPLICIT_LITTLE_ENDIAN$1 ? true : false,
10713
- isEncapsulated = this.isPixelDataTag() && DicomMessage$1.isEncapsulated(syntax);
10729
+ var vr = ValueRepresentation.createByTypeString(vrType);
10730
+ var useSyntax = DicomMessage$1._normalizeSyntax(syntax);
10731
+ var implicit = useSyntax == IMPLICIT_LITTLE_ENDIAN ? true : false;
10732
+ var isLittleEndian = useSyntax == IMPLICIT_LITTLE_ENDIAN || useSyntax == EXPLICIT_LITTLE_ENDIAN$1 ? true : false;
10733
+ var isEncapsulated = this.isPixelDataTag() && DicomMessage$1.isEncapsulated(syntax);
10714
10734
  var oldEndian = stream.isLittleEndian;
10715
10735
  stream.setEndian(isLittleEndian);
10716
10736
  stream.writeUint16(this.group());
@@ -10733,8 +10753,13 @@ var Tag = /*#__PURE__*/function () {
10733
10753
  stream.writeUint32(valueLength);
10734
10754
  written += 4;
10735
10755
  } else {
10736
- if (vr.isExplicit()) {
10737
- stream.writeAsciiString(vr.type);
10756
+ // Big 16 length objects are encodings for values larger than
10757
+ // 16 bit lengths which would normally use a 16 bit length field.
10758
+ // This uses a VR=UN instead of the original VR, and a 32 bit length
10759
+ var isBig16Length = !vr.isLength32() && valueLength >= 0x10000 && valueLength !== 0xffffffff;
10760
+ if (vr.isLength32() || isBig16Length) {
10761
+ // Write as vr UN for big values
10762
+ stream.writeAsciiString(isBig16Length ? "UN" : vr.type);
10738
10763
  stream.writeUint16(0);
10739
10764
  stream.writeUint32(valueLength);
10740
10765
  written += 8;
@@ -10888,15 +10913,23 @@ var DicomMessage = /*#__PURE__*/function () {
10888
10913
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
10889
10914
  ignoreErrors: false,
10890
10915
  untilTag: null,
10891
- includeUntilTagValue: false
10916
+ includeUntilTagValue: false,
10917
+ stopOnGreaterTag: false
10892
10918
  };
10893
10919
  var ignoreErrors = options.ignoreErrors,
10894
- untilTag = options.untilTag;
10920
+ untilTag = options.untilTag,
10921
+ stopOnGreaterTag = options.stopOnGreaterTag;
10895
10922
  var dict = {};
10896
10923
  try {
10924
+ var previousTagOffset;
10897
10925
  while (!bufferStream.end()) {
10926
+ previousTagOffset = bufferStream.offset;
10898
10927
  var readInfo = DicomMessage._readTag(bufferStream, syntax, options);
10899
10928
  var cleanTagString = readInfo.tag.toCleanString();
10929
+ if (untilTag && stopOnGreaterTag && cleanTagString > untilTag) {
10930
+ bufferStream.offset = previousTagOffset;
10931
+ break;
10932
+ }
10900
10933
  if (cleanTagString === "00080005") {
10901
10934
  if (readInfo.values.length > 0) {
10902
10935
  var coding = readInfo.values[0];
@@ -10970,15 +11003,36 @@ var DicomMessage = /*#__PURE__*/function () {
10970
11003
  if (stream.readAsciiString(4) !== "DICM") {
10971
11004
  throw new Error("Invalid DICOM file, expected header is missing");
10972
11005
  }
11006
+
11007
+ // save position before reading first tag
11008
+ var metaStartPos = stream.offset;
11009
+
11010
+ // read the first tag to check if it's the meta length tag
10973
11011
  var el = DicomMessage._readTag(stream, useSyntax);
11012
+ var metaHeader = {};
10974
11013
  if (el.tag.toCleanString() !== "00020000") {
10975
- throw new Error("Invalid DICOM file, meta length tag is malformed or not present.");
10976
- }
10977
- var metaLength = el.values[0];
11014
+ // meta length tag is missing
11015
+ if (!options.ignoreErrors) {
11016
+ throw new Error("Invalid DICOM file, meta length tag is malformed or not present.");
11017
+ }
11018
+
11019
+ // reset stream to the position where we started reading tags
11020
+ stream.offset = metaStartPos;
11021
+
11022
+ // read meta header elements sequentially
11023
+ metaHeader = DicomMessage._read(stream, useSyntax, {
11024
+ untilTag: "00030000",
11025
+ stopOnGreaterTag: true,
11026
+ ignoreErrors: true
11027
+ });
11028
+ } else {
11029
+ // meta length tag is present
11030
+ var metaLength = el.values[0];
10978
11031
 
10979
- //read header buffer
10980
- var metaStream = stream.more(metaLength);
10981
- var metaHeader = DicomMessage._read(metaStream, useSyntax, options);
11032
+ // read header buffer using the specified meta length
11033
+ var metaStream = stream.more(metaLength);
11034
+ metaHeader = DicomMessage._read(metaStream, useSyntax, options);
11035
+ }
10982
11036
 
10983
11037
  //get the syntax
10984
11038
  var mainSyntax = metaHeader["00020010"].Value[0];
@@ -11094,7 +11148,7 @@ var DicomMessage = /*#__PURE__*/function () {
11094
11148
  } else {
11095
11149
  vr = ValueRepresentation.createByTypeString(vrType);
11096
11150
  }
11097
- if (vr.isExplicit()) {
11151
+ if (vr.isLength32()) {
11098
11152
  stream.increment(2);
11099
11153
  length = stream.readUint32();
11100
11154
  } else {