diff --git a/dist/dicomParser.js b/dist/dicomParser.js index 5960f1d..df09050 100644 --- a/dist/dicomParser.js +++ b/dist/dicomParser.js @@ -1752,7 +1752,7 @@ var dicomParser = (function (dicomParser) while(byteStream.position < maxPosition) { var element = dicomParser.readDicomElementExplicit(byteStream, dataSet.warnings, options.untilTag); - if (element) { + if (('vr' in element) || ('length') in element) { elements[element.tag] = element; } switch (typeof options.untilTag) { @@ -1860,7 +1860,7 @@ var dicomParser = (function (dicomParser) var isUntilTag = false; if (typeof untilTag === 'object' && tag === untilTag.tag) { if (untilTag.include === false) { - return false; + return {tag: tag}; } else { isUntilTag = true; } @@ -1963,7 +1963,7 @@ var dicomParser = (function (dicomParser) var isUntilTag = false; if (typeof untilTag === 'object' && tag === untilTag.tag) { if (untilTag.include === false) { - return false; + return {tag: tag}; } else { isUntilTag = true; } diff --git a/dist/dicomParser.min.js b/dist/dicomParser.min.js index e6d9025..78f7a38 100644 --- a/dist/dicomParser.min.js +++ b/dist/dicomParser.min.js @@ -1,2 +1,2 @@ /*! dicom-parser - v1.7.2 - 2016-07-16 | (c) 2014 Chris Hafey | https://github.com/chafey/dicomParser */ -!function(a,b){"undefined"!=typeof module&&module.exports?module.exports=b():"function"==typeof define&&define.amd?define([],b):("undefined"==typeof cornerstone&&(dicomParser={},"undefined"!=typeof Package&&(a.dicomParser=dicomParser)),dicomParser=b())}(this,function(){var a=function(a){return void 0===a&&(a={}),a.parseDicom=function(b,c){function d(c){if(void 0===c.elements.x00020010)throw"dicomParser.parseDicom: missing required meta header attribute 0002,0010";var d=c.elements.x00020010;return a.readFixedString(b,d.dataOffset,d.length)}function e(a){return"1.2.840.10008.1.2"!==a}function f(d,e){if("1.2.840.10008.1.2.1.99"===d){if(c&&c.inflater){var f=c.inflater(b,e);return new a.ByteStream(a.littleEndianByteArrayParser,f,0)}if("undefined"!=typeof module&&this.module!==module){var g=require("zlib"),h=a.sharedCopy(b,e,b.length-e),i=g.inflateRawSync(h),j=a.alloc(b,i.length+e);return b.copy(j,0,0,e),i.copy(j,e),new a.ByteStream(a.littleEndianByteArrayParser,j,0)}if("undefined"!=typeof pako){var k=b.slice(e),l=pako.inflateRaw(k),m=a.alloc(b,l.length+e);return m.set(b.slice(0,e),0),m.set(l,e),new a.ByteStream(a.littleEndianByteArrayParser,m,0)}throw"dicomParser.parseDicom: no inflater available to handle deflate transfer syntax"}return"1.2.840.10008.1.2.2"===d?new a.ByteStream(a.bigEndianByteArrayParser,b,e):new a.ByteStream(a.littleEndianByteArrayParser,b,e)}function g(a,b){for(var c in a.elements)a.elements.hasOwnProperty(c)&&(b.elements[c]=a.elements[c]);return void 0!==a.warnings&&(b.warnings=a.warnings.concat(b.warnings)),b}function h(b){var g=d(b),h=e(g),i=f(g,b.position),j={},k=new a.DataSet(i.byteArrayParser,i.byteArray,j);k.warnings=i.warnings;try{h?a.parseDicomDataSetExplicit(k,i,i.byteArray.length,c):a.parseDicomDataSetImplicit(k,i,i.byteArray.length,c)}catch(l){var m={exception:l,dataSet:k};throw m}return k}function i(){var d=a.readPart10Header(b,c),e=h(d);return g(d,e)}if(void 0===b)throw"dicomParser.parseDicom: missing required parameter 'byteArray'";return i()},a}(a),a=function(a){"use strict";function b(a,b){return 255===a.byteArray[b]&&217===a.byteArray[b+1]}function c(a,c,d){var e=c.fragments[d];return!(!b(a,e.position+e.length-2)&&!b(a,e.position+e.length-3))}function d(a,b,d){for(var e=d;e0&&c<=12&&a>0&&a<=b(c,d))}return void 0===a&&(a={}),a.parseDA=function(a,b){if(a&&8===a.length){var d=parseInt(a.substring(0,4),10),e=parseInt(a.substring(4,6),10),f=parseInt(a.substring(6,8),10);if(b&&c(f,e,d)!==!0)throw"invalid DA '"+a+"'";return{year:d,month:e,day:f}}if(b)throw"invalid DA '"+a+"'"},a}(a),a=function(a){"use strict";return void 0===a&&(a={}),a.parseTM=function(a,b){if(a.length>=2){var c=parseInt(a.substring(0,2),10),d=a.length>=4?parseInt(a.substring(2,4),10):void 0,e=a.length>=6?parseInt(a.substring(4,6),10):void 0,f=a.length>=8?parseInt(a.substring(7,13),10):void 0;if(b&&(isNaN(c)||void 0!==d&&isNaN(d)||void 0!==e&&isNaN(e)||void 0!==f&&isNaN(f)||c<0||c>23||d&&(d<0||d>59)||e&&(e<0||e>59)||f&&(f<0||f>999999)))throw"invalid TM '"+a+"'";return{hours:c,minutes:d,seconds:e,fractionalSeconds:f}}if(b)throw"invalid TM '"+a+"'"},a}(a),a=function(a){"use strict";void 0===a&&(a={});var b={AE:!0,AS:!0,AT:!1,CS:!0,DA:!0,DS:!0,DT:!0,FL:!1,FD:!1,IS:!0,LO:!0,LT:!0,OB:!1,OD:!1,OF:!1,OW:!1,PN:!0,SH:!0,SL:!1,SQ:!1,SS:!1,ST:!0,TM:!0,UI:!0,UL:!1,UN:void 0,UR:!0,US:!1,UT:!0};return a.isStringVr=function(a){return b[a]},a.isPrivateTag=function(a){var b=parseInt(a[4]),c=b%2===1;return c},a.parsePN=function(a){if(void 0!==a){var b=a.split("^");return{familyName:b[0],givenName:b[1],middleName:b[2],prefix:b[3],suffix:b[4]}}},a}(a),a=function(a){"use strict";void 0===a&&(a={});var b=!1;return a.readEncapsulatedPixelData=function(c,d,e){if(b||(b=!0,console&&console.log&&console.log("WARNING: dicomParser.readEncapsulatedPixelData() has been deprecated")),void 0===c)throw"dicomParser.readEncapsulatedPixelData: missing required parameter 'dataSet'";if(void 0===d)throw"dicomParser.readEncapsulatedPixelData: missing required parameter 'element'";if(void 0===e)throw"dicomParser.readEncapsulatedPixelData: missing required parameter 'frame'";if("x7fe00010"!==d.tag)throw"dicomParser.readEncapsulatedPixelData: parameter 'element' refers to non pixel data tag (expected tag = x7fe00010'";if(d.encapsulatedPixelData!==!0)throw"dicomParser.readEncapsulatedPixelData: parameter 'element' refers to pixel data element that does not have encapsulated pixel data";if(d.hadUndefinedLength!==!0)throw"dicomParser.readEncapsulatedPixelData: parameter 'element' refers to pixel data element that does not have encapsulated pixel data";if(void 0===d.basicOffsetTable)throw"dicomParser.readEncapsulatedPixelData: parameter 'element' refers to pixel data element that does not have encapsulated pixel data";if(void 0===d.fragments)throw"dicomParser.readEncapsulatedPixelData: parameter 'element' refers to pixel data element that does not have encapsulated pixel data";if(e<0)throw"dicomParser.readEncapsulatedPixelData: parameter 'frame' must be >= 0";return 0!==d.basicOffsetTable.length?a.readEncapsulatedImageFrame(c,d,e):a.readEncapsulatedPixelDataFromFragments(c,d,0,d.fragments.length)},a}(a),a=function(a){"use strict";return void 0===a&&(a={}),a.alloc=function(a,b){if("undefined"!=typeof Buffer&&a instanceof Buffer)return Buffer.alloc(b);if(a instanceof Uint8Array)return new Uint8Array(b);throw"dicomParser.alloc: unknown type for byteArray"},a}(a),a=function(a){"use strict";return void 0===a&&(a={}),a.bigEndianByteArrayParser={readUint16:function(a,b){if(b<0)throw"bigEndianByteArrayParser.readUint16: position cannot be less than 0";if(b+2>a.length)throw"bigEndianByteArrayParser.readUint16: attempt to read past end of buffer";return(a[b]<<8)+a[b+1]},readInt16:function(a,b){if(b<0)throw"bigEndianByteArrayParser.readInt16: position cannot be less than 0";if(b+2>a.length)throw"bigEndianByteArrayParser.readInt16: attempt to read past end of buffer";var c=(a[b]<<8)+a[b+1];return 32768&c&&(c=c-65535-1),c},readUint32:function(a,b){if(b<0)throw"bigEndianByteArrayParser.readUint32: position cannot be less than 0";if(b+4>a.length)throw"bigEndianByteArrayParser.readUint32: attempt to read past end of buffer";var c=256*(256*(256*a[b]+a[b+1])+a[b+2])+a[b+3];return c},readInt32:function(a,b){if(b<0)throw"bigEndianByteArrayParser.readInt32: position cannot be less than 0";if(b+4>a.length)throw"bigEndianByteArrayParser.readInt32: attempt to read past end of buffer";var c=(a[b]<<24)+(a[b+1]<<16)+(a[b+2]<<8)+a[b+3];return c},readFloat:function(a,b){if(b<0)throw"bigEndianByteArrayParser.readFloat: position cannot be less than 0";if(b+4>a.length)throw"bigEndianByteArrayParser.readFloat: attempt to read past end of buffer";var c=new Uint8Array(4);c[3]=a[b],c[2]=a[b+1],c[1]=a[b+2],c[0]=a[b+3];var d=new Float32Array(c.buffer);return d[0]},readDouble:function(a,b){if(b<0)throw"bigEndianByteArrayParser.readDouble: position cannot be less than 0";if(b+8>a.length)throw"bigEndianByteArrayParser.readDouble: attempt to read past end of buffer";var c=new Uint8Array(8);c[7]=a[b],c[6]=a[b+1],c[5]=a[b+2],c[4]=a[b+3],c[3]=a[b+4],c[2]=a[b+5],c[1]=a[b+6],c[0]=a[b+7];var d=new Float64Array(c.buffer);return d[0]}},a}(a),a=function(a){"use strict";return void 0===a&&(a={}),a.readFixedString=function(a,b,c){if(c<0)throw"dicomParser.readFixedString - length cannot be less than 0";if(b+c>a.length)throw"dicomParser.readFixedString: attempt to read past end of buffer";for(var d,e="",f=0;f=b.length)throw"dicomParser.ByteStream: parameter 'position' cannot be greater than or equal to 'byteArray' length";this.byteArrayParser=a,this.byteArray=b,this.position=c?c:0,this.warnings=[]},a.ByteStream.prototype.seek=function(a){if(this.position+a<0)throw"dicomParser.ByteStream.prototype.seek: cannot seek to position < 0";this.position+=a},a.ByteStream.prototype.readByteStream=function(b){if(this.position+b>this.byteArray.length)throw"dicomParser.ByteStream.prototype.readByteStream: readByteStream - buffer overread";var c=a.sharedCopy(this.byteArray,this.position,b);return this.position+=b,new a.ByteStream(this.byteArrayParser,c)},a.ByteStream.prototype.readUint16=function(){var a=this.byteArrayParser.readUint16(this.byteArray,this.position);return this.position+=2,a},a.ByteStream.prototype.readUint32=function(){var a=this.byteArrayParser.readUint32(this.byteArray,this.position);return this.position+=4,a},a.ByteStream.prototype.readFixedString=function(b){var c=a.readFixedString(this.byteArray,this.position,b);return this.position+=b,c},a}(a),a=function(a){"use strict";function b(a,b){return void 0!==a.parser?a.parser:b}return void 0===a&&(a={}),a.DataSet=function(a,b,c){this.byteArrayParser=a,this.byteArray=b,this.elements=c},a.DataSet.prototype.uint16=function(a,c){var d=this.elements[a];if(c=void 0!==c?c:0,d&&0!==d.length)return b(d,this.byteArrayParser).readUint16(this.byteArray,d.dataOffset+2*c)},a.DataSet.prototype.int16=function(a,c){var d=this.elements[a];if(c=void 0!==c?c:0,d&&0!==d.length)return b(d,this.byteArrayParser).readInt16(this.byteArray,d.dataOffset+2*c)},a.DataSet.prototype.uint32=function(a,c){var d=this.elements[a];if(c=void 0!==c?c:0,d&&0!==d.length)return b(d,this.byteArrayParser).readUint32(this.byteArray,d.dataOffset+4*c)},a.DataSet.prototype.int32=function(a,c){var d=this.elements[a];if(c=void 0!==c?c:0,d&&0!==d.length)return b(d,this.byteArrayParser).readInt32(this.byteArray,d.dataOffset+4*c)},a.DataSet.prototype.float=function(a,c){var d=this.elements[a];if(c=void 0!==c?c:0,d&&0!==d.length)return b(d,this.byteArrayParser).readFloat(this.byteArray,d.dataOffset+4*c)},a.DataSet.prototype.double=function(a,c){var d=this.elements[a];if(c=void 0!==c?c:0,d&&0!==d.length)return b(d,this.byteArrayParser).readDouble(this.byteArray,d.dataOffset+8*c)},a.DataSet.prototype.numStringValues=function(b){var c=this.elements[b];if(c&&c.length>0){var d=a.readFixedString(this.byteArray,c.dataOffset,c.length),e=d.match(/\\/g);return null===e?1:e.length+1}},a.DataSet.prototype.string=function(b,c){var d=this.elements[b];if(d&&d.length>0){var e=a.readFixedString(this.byteArray,d.dataOffset,d.length);if(c>=0){var f=e.split("\\");return f[c].trim()}return e.trim()}},a.DataSet.prototype.text=function(b,c){var d=this.elements[b];if(d&&d.length>0){var e=a.readFixedString(this.byteArray,d.dataOffset,d.length);if(c>=0){var f=e.split("\\");return f[c].replace(/ +$/,"")}return e.replace(/ +$/,"")}},a.DataSet.prototype.floatString=function(a,b){var c=this.elements[a];if(c&&c.length>0){b=void 0!==b?b:0;var d=this.string(a,b);if(void 0!==d)return parseFloat(d)}},a.DataSet.prototype.intString=function(a,b){var c=this.elements[a];if(c&&c.length>0){b=void 0!==b?b:0;var d=this.string(a,b);if(void 0!==d)return parseInt(d)}},a}(a),a=function(a){"use strict";return void 0===a&&(a={}),a.findEndOfEncapsulatedElement=function(b,c,d){if(void 0===b)throw"dicomParser.findEndOfEncapsulatedElement: missing required parameter 'byteStream'";if(void 0===c)throw"dicomParser.findEndOfEncapsulatedElement: missing required parameter 'element'";c.encapsulatedPixelData=!0,c.basicOffsetTable=[],c.fragments=[];var e=a.readTag(b);if("xfffee000"!==e)throw"dicomParser.findEndOfEncapsulatedElement: basic offset table not found";for(var f=b.readUint32(),g=f/4,h=0;hb.byteArray.length-b.position&&(l=b.byteArray.length-b.position),c.fragments.push({offset:b.position-j-8,position:b.position,length:l}),b.seek(l),void(c.length=b.position-c.dataOffset);c.fragments.push({offset:b.position-j-8,position:b.position,length:l}),b.seek(l)}d&&d.push("pixel data element "+c.tag+" missing sequence delimiter tag xfffee0dd")},a}(a),a=function(a){"use strict";return void 0===a&&(a={}),a.findItemDelimitationItemAndSetElementLength=function(a,b){if(void 0===a)throw"dicomParser.readDicomElementImplicit: missing required parameter 'byteStream'";for(var c=8,d=a.byteArray.length-c;a.position<=d;){var e=a.readUint16();if(65534===e){var f=a.readUint16();if(57357===f){var g=a.readUint32();return 0!==g&&a.warnings("encountered non zero length following item delimiter at position"+a.position-4+" while reading element of undefined length with tag ' + element.tag"),void(b.length=a.position-b.dataOffset)}}}b.length=a.byteArray.length-b.dataOffset,a.seek(a.byteArray.length-a.position)},a}(a),a=function(a){"use strict";return void 0===a&&(a={}),a.littleEndianByteArrayParser={readUint16:function(a,b){if(b<0)throw"littleEndianByteArrayParser.readUint16: position cannot be less than 0";if(b+2>a.length)throw"littleEndianByteArrayParser.readUint16: attempt to read past end of buffer";return a[b]+256*a[b+1]},readInt16:function(a,b){if(b<0)throw"littleEndianByteArrayParser.readInt16: position cannot be less than 0";if(b+2>a.length)throw"littleEndianByteArrayParser.readInt16: attempt to read past end of buffer";var c=a[b]+(a[b+1]<<8);return 32768&c&&(c=c-65535-1),c},readUint32:function(a,b){if(b<0)throw"littleEndianByteArrayParser.readUint32: position cannot be less than 0";if(b+4>a.length)throw"littleEndianByteArrayParser.readUint32: attempt to read past end of buffer";var c=a[b]+256*a[b+1]+256*a[b+2]*256+256*a[b+3]*256*256;return c},readInt32:function(a,b){if(b<0)throw"littleEndianByteArrayParser.readInt32: position cannot be less than 0";if(b+4>a.length)throw"littleEndianByteArrayParser.readInt32: attempt to read past end of buffer";var c=a[b]+(a[b+1]<<8)+(a[b+2]<<16)+(a[b+3]<<24);return c},readFloat:function(a,b){if(b<0)throw"littleEndianByteArrayParser.readFloat: position cannot be less than 0";if(b+4>a.length)throw"littleEndianByteArrayParser.readFloat: attempt to read past end of buffer";var c=new Uint8Array(4);c[0]=a[b],c[1]=a[b+1],c[2]=a[b+2],c[3]=a[b+3];var d=new Float32Array(c.buffer);return d[0]},readDouble:function(a,b){if(b<0)throw"littleEndianByteArrayParser.readDouble: position cannot be less than 0";if(b+8>a.length)throw"littleEndianByteArrayParser.readDouble: attempt to read past end of buffer";var c=new Uint8Array(8);c[0]=a[b],c[1]=a[b+1],c[2]=a[b+2],c[3]=a[b+3],c[4]=a[b+4],c[5]=a[b+5],c[6]=a[b+6],c[7]=a[b+7];var d=new Float64Array(c.buffer);return d[0]}},a}(a),a=function(a){"use strict";return void 0===a&&(a={}),a.parseDicomDataSetExplicit=function(b,c,d,e){if(d=void 0===d?c.byteArray.length:d,e=e||{},void 0===c)throw"dicomParser.parseDicomDataSetExplicit: missing required parameter 'byteStream'";if(dc.byteArray.length)throw"dicomParser.parseDicomDataSetExplicit: invalid value for parameter 'maxPosition'";for(var f=b.elements;c.positiond)throw"dicomParser:parseDicomDataSetExplicit: buffer overrun"},a.parseDicomDataSetImplicit=function(b,c,d,e){if(d=void 0===d?b.byteArray.length:d,e=e||{},void 0===c)throw"dicomParser.parseDicomDataSetImplicit: missing required parameter 'byteStream'";if(dc.byteArray.length)throw"dicomParser.parseDicomDataSetImplicit: invalid value for parameter 'maxPosition'";for(var f=b.elements;c.position= 0";if(f>=g.length)throw"dicomParser.readEncapsulatedImageFrame: parameter 'frameIndex' must be < basicOffsetTable.length";var i=g[f],j=b(h,i);if(void 0===j)throw"dicomParser.readEncapsulatedImageFrame: unable to find fragment that matches basic offset table entry";var k=c(f,g,h,j);return a.readEncapsulatedPixelDataFromFragments(d,e,j,k,h)},a}(a),a=function(a){"use strict";function b(a,b,c){for(var d=0,e=b;e= 0";if(e>=d.fragments.length)throw"dicomParser.readEncapsulatedPixelDataFromFragments: parameter 'startFragmentIndex' must be < number of fragments";if(f<1)throw"dicomParser.readEncapsulatedPixelDataFromFragments: parameter 'numFragments' must be > 0";if(e+f>d.fragments.length)throw"dicomParser.readEncapsulatedPixelDataFromFragments: parameter 'startFragment' + 'numFragments' < number of fragments";var h=new a.ByteStream(c.byteArrayParser,c.byteArray,d.dataOffset),i=a.readSequenceItem(h);if("xfffee000"!==i.tag)throw"dicomParser.readEncapsulatedPixelData: missing basic offset table xfffee000";h.seek(i.length);var j=h.position,k=8;if(1===f)return a.sharedCopy(h.byteArray,j+g[e].offset+k,g[e].length);for(var l=b(g,e,f),m=a.alloc(h.byteArray,l),n=0,o=e;o"x0002ffff"){f.position=e;break}g.parser=a.littleEndianByteArrayParser,c[g.tag]=g}var h=new a.DataSet(f.byteArrayParser,f.byteArray,c);return h.warnings=f.warnings,h.position=f.position,h}if(void 0===b)throw"dicomParser.readPart10Header: missing required parameter 'byteArray'";var f=new a.ByteStream(a.littleEndianByteArrayParser,b);return e()},a}(a),a=function(a){"use strict";function b(b,c){for(var d={};b.position0&&c<=12&&a>0&&a<=b(c,d))}return void 0===a&&(a={}),a.parseDA=function(a,b){if(a&&8===a.length){var d=parseInt(a.substring(0,4),10),e=parseInt(a.substring(4,6),10),f=parseInt(a.substring(6,8),10);if(b&&c(f,e,d)!==!0)throw"invalid DA '"+a+"'";return{year:d,month:e,day:f}}if(b)throw"invalid DA '"+a+"'"},a}(a),a=function(a){"use strict";return void 0===a&&(a={}),a.parseTM=function(a,b){if(a.length>=2){var c=parseInt(a.substring(0,2),10),d=a.length>=4?parseInt(a.substring(2,4),10):void 0,e=a.length>=6?parseInt(a.substring(4,6),10):void 0,f=a.length>=8?parseInt(a.substring(7,13),10):void 0;if(b&&(isNaN(c)||void 0!==d&&isNaN(d)||void 0!==e&&isNaN(e)||void 0!==f&&isNaN(f)||c<0||c>23||d&&(d<0||d>59)||e&&(e<0||e>59)||f&&(f<0||f>999999)))throw"invalid TM '"+a+"'";return{hours:c,minutes:d,seconds:e,fractionalSeconds:f}}if(b)throw"invalid TM '"+a+"'"},a}(a),a=function(a){"use strict";void 0===a&&(a={});var b={AE:!0,AS:!0,AT:!1,CS:!0,DA:!0,DS:!0,DT:!0,FL:!1,FD:!1,IS:!0,LO:!0,LT:!0,OB:!1,OD:!1,OF:!1,OW:!1,PN:!0,SH:!0,SL:!1,SQ:!1,SS:!1,ST:!0,TM:!0,UI:!0,UL:!1,UN:void 0,UR:!0,US:!1,UT:!0};return a.isStringVr=function(a){return b[a]},a.isPrivateTag=function(a){var b=parseInt(a[4]),c=b%2===1;return c},a.parsePN=function(a){if(void 0!==a){var b=a.split("^");return{familyName:b[0],givenName:b[1],middleName:b[2],prefix:b[3],suffix:b[4]}}},a}(a),a=function(a){"use strict";void 0===a&&(a={});var b=!1;return a.readEncapsulatedPixelData=function(c,d,e){if(b||(b=!0,console&&console.log&&console.log("WARNING: dicomParser.readEncapsulatedPixelData() has been deprecated")),void 0===c)throw"dicomParser.readEncapsulatedPixelData: missing required parameter 'dataSet'";if(void 0===d)throw"dicomParser.readEncapsulatedPixelData: missing required parameter 'element'";if(void 0===e)throw"dicomParser.readEncapsulatedPixelData: missing required parameter 'frame'";if("x7fe00010"!==d.tag)throw"dicomParser.readEncapsulatedPixelData: parameter 'element' refers to non pixel data tag (expected tag = x7fe00010'";if(d.encapsulatedPixelData!==!0)throw"dicomParser.readEncapsulatedPixelData: parameter 'element' refers to pixel data element that does not have encapsulated pixel data";if(d.hadUndefinedLength!==!0)throw"dicomParser.readEncapsulatedPixelData: parameter 'element' refers to pixel data element that does not have encapsulated pixel data";if(void 0===d.basicOffsetTable)throw"dicomParser.readEncapsulatedPixelData: parameter 'element' refers to pixel data element that does not have encapsulated pixel data";if(void 0===d.fragments)throw"dicomParser.readEncapsulatedPixelData: parameter 'element' refers to pixel data element that does not have encapsulated pixel data";if(e<0)throw"dicomParser.readEncapsulatedPixelData: parameter 'frame' must be >= 0";return 0!==d.basicOffsetTable.length?a.readEncapsulatedImageFrame(c,d,e):a.readEncapsulatedPixelDataFromFragments(c,d,0,d.fragments.length)},a}(a),a=function(a){"use strict";return void 0===a&&(a={}),a.alloc=function(a,b){if("undefined"!=typeof Buffer&&a instanceof Buffer)return Buffer.alloc(b);if(a instanceof Uint8Array)return new Uint8Array(b);throw"dicomParser.alloc: unknown type for byteArray"},a}(a),a=function(a){"use strict";return void 0===a&&(a={}),a.bigEndianByteArrayParser={readUint16:function(a,b){if(b<0)throw"bigEndianByteArrayParser.readUint16: position cannot be less than 0";if(b+2>a.length)throw"bigEndianByteArrayParser.readUint16: attempt to read past end of buffer";return(a[b]<<8)+a[b+1]},readInt16:function(a,b){if(b<0)throw"bigEndianByteArrayParser.readInt16: position cannot be less than 0";if(b+2>a.length)throw"bigEndianByteArrayParser.readInt16: attempt to read past end of buffer";var c=(a[b]<<8)+a[b+1];return 32768&c&&(c=c-65535-1),c},readUint32:function(a,b){if(b<0)throw"bigEndianByteArrayParser.readUint32: position cannot be less than 0";if(b+4>a.length)throw"bigEndianByteArrayParser.readUint32: attempt to read past end of buffer";var c=256*(256*(256*a[b]+a[b+1])+a[b+2])+a[b+3];return c},readInt32:function(a,b){if(b<0)throw"bigEndianByteArrayParser.readInt32: position cannot be less than 0";if(b+4>a.length)throw"bigEndianByteArrayParser.readInt32: attempt to read past end of buffer";var c=(a[b]<<24)+(a[b+1]<<16)+(a[b+2]<<8)+a[b+3];return c},readFloat:function(a,b){if(b<0)throw"bigEndianByteArrayParser.readFloat: position cannot be less than 0";if(b+4>a.length)throw"bigEndianByteArrayParser.readFloat: attempt to read past end of buffer";var c=new Uint8Array(4);c[3]=a[b],c[2]=a[b+1],c[1]=a[b+2],c[0]=a[b+3];var d=new Float32Array(c.buffer);return d[0]},readDouble:function(a,b){if(b<0)throw"bigEndianByteArrayParser.readDouble: position cannot be less than 0";if(b+8>a.length)throw"bigEndianByteArrayParser.readDouble: attempt to read past end of buffer";var c=new Uint8Array(8);c[7]=a[b],c[6]=a[b+1],c[5]=a[b+2],c[4]=a[b+3],c[3]=a[b+4],c[2]=a[b+5],c[1]=a[b+6],c[0]=a[b+7];var d=new Float64Array(c.buffer);return d[0]}},a}(a),a=function(a){"use strict";return void 0===a&&(a={}),a.readFixedString=function(a,b,c){if(c<0)throw"dicomParser.readFixedString - length cannot be less than 0";if(b+c>a.length)throw"dicomParser.readFixedString: attempt to read past end of buffer";for(var d,e="",f=0;f=b.length)throw"dicomParser.ByteStream: parameter 'position' cannot be greater than or equal to 'byteArray' length";this.byteArrayParser=a,this.byteArray=b,this.position=c?c:0,this.warnings=[]},a.ByteStream.prototype.seek=function(a){if(this.position+a<0)throw"dicomParser.ByteStream.prototype.seek: cannot seek to position < 0";this.position+=a},a.ByteStream.prototype.readByteStream=function(b){if(this.position+b>this.byteArray.length)throw"dicomParser.ByteStream.prototype.readByteStream: readByteStream - buffer overread";var c=a.sharedCopy(this.byteArray,this.position,b);return this.position+=b,new a.ByteStream(this.byteArrayParser,c)},a.ByteStream.prototype.readUint16=function(){var a=this.byteArrayParser.readUint16(this.byteArray,this.position);return this.position+=2,a},a.ByteStream.prototype.readUint32=function(){var a=this.byteArrayParser.readUint32(this.byteArray,this.position);return this.position+=4,a},a.ByteStream.prototype.readFixedString=function(b){var c=a.readFixedString(this.byteArray,this.position,b);return this.position+=b,c},a}(a),a=function(a){"use strict";function b(a,b){return void 0!==a.parser?a.parser:b}return void 0===a&&(a={}),a.DataSet=function(a,b,c){this.byteArrayParser=a,this.byteArray=b,this.elements=c},a.DataSet.prototype.uint16=function(a,c){var d=this.elements[a];if(c=void 0!==c?c:0,d&&0!==d.length)return b(d,this.byteArrayParser).readUint16(this.byteArray,d.dataOffset+2*c)},a.DataSet.prototype.int16=function(a,c){var d=this.elements[a];if(c=void 0!==c?c:0,d&&0!==d.length)return b(d,this.byteArrayParser).readInt16(this.byteArray,d.dataOffset+2*c)},a.DataSet.prototype.uint32=function(a,c){var d=this.elements[a];if(c=void 0!==c?c:0,d&&0!==d.length)return b(d,this.byteArrayParser).readUint32(this.byteArray,d.dataOffset+4*c)},a.DataSet.prototype.int32=function(a,c){var d=this.elements[a];if(c=void 0!==c?c:0,d&&0!==d.length)return b(d,this.byteArrayParser).readInt32(this.byteArray,d.dataOffset+4*c)},a.DataSet.prototype.float=function(a,c){var d=this.elements[a];if(c=void 0!==c?c:0,d&&0!==d.length)return b(d,this.byteArrayParser).readFloat(this.byteArray,d.dataOffset+4*c)},a.DataSet.prototype.double=function(a,c){var d=this.elements[a];if(c=void 0!==c?c:0,d&&0!==d.length)return b(d,this.byteArrayParser).readDouble(this.byteArray,d.dataOffset+8*c)},a.DataSet.prototype.numStringValues=function(b){var c=this.elements[b];if(c&&c.length>0){var d=a.readFixedString(this.byteArray,c.dataOffset,c.length),e=d.match(/\\/g);return null===e?1:e.length+1}},a.DataSet.prototype.string=function(b,c){var d=this.elements[b];if(d&&d.length>0){var e=a.readFixedString(this.byteArray,d.dataOffset,d.length);if(c>=0){var f=e.split("\\");return f[c].trim()}return e.trim()}},a.DataSet.prototype.text=function(b,c){var d=this.elements[b];if(d&&d.length>0){var e=a.readFixedString(this.byteArray,d.dataOffset,d.length);if(c>=0){var f=e.split("\\");return f[c].replace(/ +$/,"")}return e.replace(/ +$/,"")}},a.DataSet.prototype.floatString=function(a,b){var c=this.elements[a];if(c&&c.length>0){b=void 0!==b?b:0;var d=this.string(a,b);if(void 0!==d)return parseFloat(d)}},a.DataSet.prototype.intString=function(a,b){var c=this.elements[a];if(c&&c.length>0){b=void 0!==b?b:0;var d=this.string(a,b);if(void 0!==d)return parseInt(d)}},a}(a),a=function(a){"use strict";return void 0===a&&(a={}),a.findEndOfEncapsulatedElement=function(b,c,d){if(void 0===b)throw"dicomParser.findEndOfEncapsulatedElement: missing required parameter 'byteStream'";if(void 0===c)throw"dicomParser.findEndOfEncapsulatedElement: missing required parameter 'element'";c.encapsulatedPixelData=!0,c.basicOffsetTable=[],c.fragments=[];var e=a.readTag(b);if("xfffee000"!==e)throw"dicomParser.findEndOfEncapsulatedElement: basic offset table not found";for(var f=b.readUint32(),g=f/4,h=0;hb.byteArray.length-b.position&&(l=b.byteArray.length-b.position),c.fragments.push({offset:b.position-j-8,position:b.position,length:l}),b.seek(l),void(c.length=b.position-c.dataOffset);c.fragments.push({offset:b.position-j-8,position:b.position,length:l}),b.seek(l)}d&&d.push("pixel data element "+c.tag+" missing sequence delimiter tag xfffee0dd")},a}(a),a=function(a){"use strict";return void 0===a&&(a={}),a.findItemDelimitationItemAndSetElementLength=function(a,b){if(void 0===a)throw"dicomParser.readDicomElementImplicit: missing required parameter 'byteStream'";for(var c=8,d=a.byteArray.length-c;a.position<=d;){var e=a.readUint16();if(65534===e){var f=a.readUint16();if(57357===f){var g=a.readUint32();return 0!==g&&a.warnings("encountered non zero length following item delimiter at position"+a.position-4+" while reading element of undefined length with tag ' + element.tag"),void(b.length=a.position-b.dataOffset)}}}b.length=a.byteArray.length-b.dataOffset,a.seek(a.byteArray.length-a.position)},a}(a),a=function(a){"use strict";return void 0===a&&(a={}),a.littleEndianByteArrayParser={readUint16:function(a,b){if(b<0)throw"littleEndianByteArrayParser.readUint16: position cannot be less than 0";if(b+2>a.length)throw"littleEndianByteArrayParser.readUint16: attempt to read past end of buffer";return a[b]+256*a[b+1]},readInt16:function(a,b){if(b<0)throw"littleEndianByteArrayParser.readInt16: position cannot be less than 0";if(b+2>a.length)throw"littleEndianByteArrayParser.readInt16: attempt to read past end of buffer";var c=a[b]+(a[b+1]<<8);return 32768&c&&(c=c-65535-1),c},readUint32:function(a,b){if(b<0)throw"littleEndianByteArrayParser.readUint32: position cannot be less than 0";if(b+4>a.length)throw"littleEndianByteArrayParser.readUint32: attempt to read past end of buffer";var c=a[b]+256*a[b+1]+256*a[b+2]*256+256*a[b+3]*256*256;return c},readInt32:function(a,b){if(b<0)throw"littleEndianByteArrayParser.readInt32: position cannot be less than 0";if(b+4>a.length)throw"littleEndianByteArrayParser.readInt32: attempt to read past end of buffer";var c=a[b]+(a[b+1]<<8)+(a[b+2]<<16)+(a[b+3]<<24);return c},readFloat:function(a,b){if(b<0)throw"littleEndianByteArrayParser.readFloat: position cannot be less than 0";if(b+4>a.length)throw"littleEndianByteArrayParser.readFloat: attempt to read past end of buffer";var c=new Uint8Array(4);c[0]=a[b],c[1]=a[b+1],c[2]=a[b+2],c[3]=a[b+3];var d=new Float32Array(c.buffer);return d[0]},readDouble:function(a,b){if(b<0)throw"littleEndianByteArrayParser.readDouble: position cannot be less than 0";if(b+8>a.length)throw"littleEndianByteArrayParser.readDouble: attempt to read past end of buffer";var c=new Uint8Array(8);c[0]=a[b],c[1]=a[b+1],c[2]=a[b+2],c[3]=a[b+3],c[4]=a[b+4],c[5]=a[b+5],c[6]=a[b+6],c[7]=a[b+7];var d=new Float64Array(c.buffer);return d[0]}},a}(a),a=function(a){"use strict";return void 0===a&&(a={}),a.parseDicomDataSetExplicit=function(b,c,d,e){if(d=void 0===d?c.byteArray.length:d,e=e||{},void 0===c)throw"dicomParser.parseDicomDataSetExplicit: missing required parameter 'byteStream'";if(dc.byteArray.length)throw"dicomParser.parseDicomDataSetExplicit: invalid value for parameter 'maxPosition'";for(var f=b.elements;c.positiond)throw"dicomParser:parseDicomDataSetExplicit: buffer overrun"},a.parseDicomDataSetImplicit=function(b,c,d,e){if(d=void 0===d?b.byteArray.length:d,e=e||{},void 0===c)throw"dicomParser.parseDicomDataSetImplicit: missing required parameter 'byteStream'";if(dc.byteArray.length)throw"dicomParser.parseDicomDataSetImplicit: invalid value for parameter 'maxPosition'";for(var f=b.elements;c.position= 0";if(f>=g.length)throw"dicomParser.readEncapsulatedImageFrame: parameter 'frameIndex' must be < basicOffsetTable.length";var i=g[f],j=b(h,i);if(void 0===j)throw"dicomParser.readEncapsulatedImageFrame: unable to find fragment that matches basic offset table entry";var k=c(f,g,h,j);return a.readEncapsulatedPixelDataFromFragments(d,e,j,k,h)},a}(a),a=function(a){"use strict";function b(a,b,c){for(var d=0,e=b;e= 0";if(e>=d.fragments.length)throw"dicomParser.readEncapsulatedPixelDataFromFragments: parameter 'startFragmentIndex' must be < number of fragments";if(f<1)throw"dicomParser.readEncapsulatedPixelDataFromFragments: parameter 'numFragments' must be > 0";if(e+f>d.fragments.length)throw"dicomParser.readEncapsulatedPixelDataFromFragments: parameter 'startFragment' + 'numFragments' < number of fragments";var h=new a.ByteStream(c.byteArrayParser,c.byteArray,d.dataOffset),i=a.readSequenceItem(h);if("xfffee000"!==i.tag)throw"dicomParser.readEncapsulatedPixelData: missing basic offset table xfffee000";h.seek(i.length);var j=h.position,k=8;if(1===f)return a.sharedCopy(h.byteArray,j+g[e].offset+k,g[e].length);for(var l=b(g,e,f),m=a.alloc(h.byteArray,l),n=0,o=e;o"x0002ffff"){f.position=e;break}g.parser=a.littleEndianByteArrayParser,c[g.tag]=g}var h=new a.DataSet(f.byteArrayParser,f.byteArray,c);return h.warnings=f.warnings,h.position=f.position,h}if(void 0===b)throw"dicomParser.readPart10Header: missing required parameter 'byteArray'";var f=new a.ByteStream(a.littleEndianByteArrayParser,b);return e()},a}(a),a=function(a){"use strict";function b(b,c){for(var d={};b.position