text: /*! dicom-parser - v1.7.4 - 2016-08-18 | (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;e<b.fragments.length;e++)if(c(a,b,e))return e}return void 0===a&&(a={}),a.createJPEGBasicOffsetTable=function(a,b,c){if(void 0===a)throw"dicomParser.createJPEGBasicOffsetTable: missing required parameter dataSet";if(void 0===b)throw"dicomParser.createJPEGBasicOffsetTable: missing required parameter pixelDataElement";if("x7fe00010"!==b.tag)throw"dicomParser.createJPEGBasicOffsetTable: parameter 'pixelDataElement' refers to non pixel data tag (expected tag = x7fe00010'";if(b.encapsulatedPixelData!==!0)throw"dicomParser.createJPEGBasicOffsetTable: parameter 'pixelDataElement' refers to pixel data element that does not have encapsulated pixel data";if(b.hadUndefinedLength!==!0)throw"dicomParser.createJPEGBasicOffsetTable: parameter 'pixelDataElement' refers to pixel data element that does not have encapsulated pixel data";if(void 0===b.basicOffsetTable)throw"dicomParser.createJPEGBasicOffsetTable: parameter 'pixelDataElement' refers to pixel data element that does not have encapsulated pixel data";if(void 0===b.fragments)throw"dicomParser.createJPEGBasicOffsetTable: parameter 'pixelDataElement' refers to pixel data element that does not have encapsulated pixel data";if(b.fragments.length<=0)throw"dicomParser.createJPEGBasicOffsetTable: parameter 'pixelDataElement' refers to pixel data element that does not have encapsulated pixel data";if(c&&c.length<=0)throw"dicomParser.createJPEGBasicOffsetTable: parameter 'fragments' must not be zero length";c=c||b.fragments;for(var e=[],f=0;;){e.push(b.fragments[f].offset);var g=d(a,b,f);if(void 0===g||g===b.fragments.length-1)return e;f=g+1}},a}(a),a=function(a){"use strict";return void 0===a&&(a={}),a.explicitDataSetToJS=function(b,c){if(void 0===b)throw"dicomParser.explicitDataSetToJS: missing required parameter dataSet";c=c||{omitPrivateAttibutes:!0,maxElementLength:128};var d={};for(var e in b.elements){var f=b.elements[e];if(c.omitPrivateAttibutes!==!0||!a.isPrivateTag(e))if(f.items){for(var g=[],h=0;h<f.items.length;h++)g.push(a.explicitDataSetToJS(f.items[h].dataSet,c));d[e]=g}else{var i;i=void 0,f.length<c.maxElementLength&&(i=a.explicitElementToString(b,f)),void 0!==i?d[e]=i:d[e]={dataOffset:f.dataOffset,length:f.length}}}return d},a}(a),a=function(a){"use strict";return void 0===a&&(a={}),a.explicitElementToString=function(b,c){function d(a,c){for(var d="",e=0;e<a;e++)0!==e&&(d+="/"),d+=c.call(b,g,e).toString();return d}if(void 0===b||void 0===c)throw"dicomParser.explicitElementToString: missing required parameters";if(void 0===c.vr)throw"dicomParser.explicitElementToString: cannot convert implicit element to string";var e,f=c.vr,g=c.tag;if(a.isStringVr(f)===!0)e=b.string(g);else{if("AT"==f){var h=b.uint32(g);if(void 0===h)return;return h<0&&(h=4294967295+h+1),"x"+h.toString(16).toUpperCase()}"US"==f?e=d(c.length/2,b.uint16):"SS"===f?e=d(c.length/2,b.int16):"UL"==f?e=d(c.length/4,b.uint32):"SL"===f?e=d(c.length/4,b.int32):"FD"==f?e=d(c.length/8,b["double"]):"FL"==f&&(e=d(c.length/4,b["float"]))}return e},a}(a),a=function(a){"use strict";function b(a,b){switch(a){case 2:return b%4==0&&b%100||b%400==0?29:28;case 9:case 4:case 6:case 11:return 30;default:return 31}}function c(a,c,d){return!isNaN(d)&&(c>0&&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<c;f++){if(d=a[b+f],0===d)return b+=c,e;e+=String.fromCharCode(d)}return e},a}(a),a=function(a){"use strict";return void 0===a&&(a={}),a.ByteStream=function(a,b,c){if(void 0===a)throw"dicomParser.ByteStream: missing required parameter 'byteArrayParser'";if(void 0===b)throw"dicomParser.ByteStream: missing required parameter 'byteArray'";if(b instanceof Uint8Array==!1&&b instanceof Buffer==!1)throw"dicomParser.ByteStream: parameter byteArray is not of type Uint8Array or Buffer";if(c<0)throw"dicomParser.ByteStream: parameter 'position' cannot be less than 0";if(c>=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.findAndSetUNElementLength=function(a,b){if(void 0===a)throw"dicomParser.findAndSetUNElementLength: missing required parameter 'byteStream'";for(var c=8,d=a.byteArray.length-c;a.position<=d;){var e;if(e=a.readUint16(),65534===e){var f;if(f=a.readUint16(),57565===f){var g;return g=a.readUint32(),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.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;h<g;h++){var i=b.readUint32();c.basicOffsetTable.push(i)}for(var j=b.position;b.position<b.byteArray.length;){var k=a.readTag(b),l=b.readUint32();if("xfffee0dd"===k)return b.seek(l),void(c.length=b.position-c.dataOffset);if("xfffee000"!==k)return d&&d.push("unexpected tag "+k+" while searching for end of pixel data element with undefined length"),l>b.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(d<c.position||d>c.byteArray.length)throw"dicomParser.parseDicomDataSetExplicit: invalid value for parameter 'maxPosition'";for(var f=b.elements;c.position<d;){var g=a.readDicomElementExplicit(c,b.warnings,e.untilTag);if(f[g.tag]=g,g.tag===e.untilTag)return}if(c.position>d)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(d<c.position||d>c.byteArray.length)throw"dicomParser.parseDicomDataSetImplicit: invalid value for parameter 'maxPosition'";for(var f=b.elements;c.position<d;){var g=a.readDicomElementImplicit(c,e.untilTag,e.vrCallback);if(f[g.tag]=g,g.tag===e.untilTag)return}},a}(a),a=function(a){"use strict";function b(a){return"OB"===a||"OW"===a||"SQ"===a||"OF"===a||"UT"===a||"UN"===a?4:2}return void 0===a&&(a={}),a.readDicomElementExplicit=function(c,d,e){if(void 0===c)throw"dicomParser.readDicomElementExplicit: missing required parameter 'byteStream'";var f={tag:a.readTag(c),vr:c.readFixedString(2)},g=b(f.vr);return 2===g?(f.length=c.readUint16(),f.dataOffset=c.position):(c.seek(2),f.length=c.readUint32(),f.dataOffset=c.position),4294967295===f.length&&(f.hadUndefinedLength=!0),f.tag===e?f:"SQ"===f.vr?(a.readSequenceItemsExplicit(c,f,d),f):4294967295===f.length?"x7fe00010"===f.tag?(a.findEndOfEncapsulatedElement(c,f,d),f):"UN"===f.vr?(a.findAndSetUNElementLength(c,f),f):(a.findItemDelimitationItemAndSetElementLength(c,f),f):(c.seek(f.length),f)},a}(a),a=function(a){"use strict";function b(b,c,d){if("undefined"!=typeof d)return"SQ"===d(b.tag);if(c.position+4<=c.byteArray.length){var e=a.readTag(c);return c.seek(-4),"xfffee000"===e||"xfffee0dd"===e}return c.warnings.push("eof encountered before finding sequence item tag or sequence delimiter tag in peeking to determine VR"),!1}return void 0===a&&(a={}),a.readDicomElementImplicit=function(c,d,e){if(void 0===c)throw"dicomParser.readDicomElementImplicit: missing required parameter 'byteStream'";var f={tag:a.readTag(c),length:c.readUint32(),dataOffset:c.position};return 4294967295===f.length&&(f.hadUndefinedLength=!0),f.tag===d?f:b(f,c,e)?(a.readSequenceItemsImplicit(c,f),f):f.hadUndefinedLength?(a.findItemDelimitationItemAndSetElementLength(c,f),f):(c.seek(f.length),f)},a}(a),a=function(a){"use strict";function b(a,b){for(var c=0;c<a.length;c++)if(a[c].offset===b)return c}function c(a,b,c,d){if(a===b.length-1)return c.length-d;for(var e=b[a+1],f=d+1;f<c.length;f++)if(c[f].offset===e)return f-d;throw"dicomParser.calculateNumberOfFragmentsForFrame: could not find fragment with offset matching basic offset table"}return void 0===a&&(a={}),a.readEncapsulatedImageFrame=function(d,e,f,g,h){if(g=g||e.basicOffsetTable,h=h||e.fragments,void 0===d)throw"dicomParser.readEncapsulatedImageFrame: missing required parameter 'dataSet'";if(void 0===e)throw"dicomParser.readEncapsulatedImageFrame: missing required parameter 'pixelDataElement'";if(void 0===f)throw"dicomParser.readEncapsulatedImageFrame: missing required parameter 'frameIndex'";if(void 0===g)throw"dicomParser.readEncapsulatedImageFrame: parameter 'pixelDataElement' does not have basicOffsetTable";if("x7fe00010"!==e.tag)throw"dicomParser.readEncapsulatedImageFrame: parameter 'pixelDataElement' refers to non pixel data tag (expected tag = x7fe00010'";if(e.encapsulatedPixelData!==!0)throw"dicomParser.readEncapsulatedImageFrame: parameter 'pixelDataElement' refers to pixel data element that does not have encapsulated pixel data";if(e.hadUndefinedLength!==!0)throw"dicomParser.readEncapsulatedImageFrame: parameter 'pixelDataElement' refers to pixel data element that does not have undefined length";if(void 0===e.fragments)throw"dicomParser.readEncapsulatedImageFrame: parameter 'pixelDataElement' refers to pixel data element that does not have fragments";if(0===g.length)throw"dicomParser.readEncapsulatedImageFrame: basicOffsetTable has zero entries";if(f<0)throw"dicomParser.readEncapsulatedImageFrame: parameter 'frameIndex' must be >= 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<b+c;e++)d+=a[e].length;return d}return void 0===a&&(a={}),a.readEncapsulatedPixelDataFromFragments=function(c,d,e,f,g){if(f=f||1,g=g||d.fragments,void 0===c)throw"dicomParser.readEncapsulatedPixelDataFromFragments: missing required parameter 'dataSet'";if(void 0===d)throw"dicomParser.readEncapsulatedPixelDataFromFragments: missing required parameter 'pixelDataElement'";if(void 0===e)throw"dicomParser.readEncapsulatedPixelDataFromFragments: missing required parameter 'startFragmentIndex'";if(void 0===f)throw"dicomParser.readEncapsulatedPixelDataFromFragments: missing required parameter 'numFragments'";if("x7fe00010"!==d.tag)throw"dicomParser.readEncapsulatedPixelDataFromFragments: parameter 'pixelDataElement' refers to non pixel data tag (expected tag = x7fe00010'";if(d.encapsulatedPixelData!==!0)throw"dicomParser.readEncapsulatedPixelDataFromFragments: parameter 'pixelDataElement' refers to pixel data element that does not have encapsulated pixel data";if(d.hadUndefinedLength!==!0)throw"dicomParser.readEncapsulatedPixelDataFromFragments: parameter 'pixelDataElement' refers to pixel data element that does not have encapsulated pixel data";if(void 0===d.basicOffsetTable)throw"dicomParser.readEncapsulatedPixelDataFromFragments: parameter 'pixelDataElement' refers to pixel data element that does not have encapsulated pixel data";if(void 0===d.fragments)throw"dicomParser.readEncapsulatedPixelDataFromFragments: parameter 'pixelDataElement' refers to pixel data element that does not have encapsulated pixel data";if(d.fragments.length<=0)throw"dicomParser.readEncapsulatedPixelDataFromFragments: parameter 'pixelDataElement' refers to pixel data element that does not have encapsulated pixel data";if(e<0)throw"dicomParser.readEncapsulatedPixelDataFromFragments: parameter 'startFragmentIndex' must be >= 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<e+f;o++)for(var p=j+g[o].offset+k,q=0;q<g[o].length;q++)m[n++]=h.byteArray[p++];return m},a}(a),a=function(a){return void 0===a&&(a={}),a.readPart10Header=function(b,c){function d(){f.seek(128);var a=f.readFixedString(4);if("DICM"!==a)throw"dicomParser.readPart10Header: DICM prefix not found at location 132 - this is not a valid DICOM P10 file."}function e(){d();for(var b=[],c={};f.position<f.byteArray.length;){var e=f.position,g=a.readDicomElementExplicit(f,b);if(g.tag>"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<b.byteArray.length;){var e=a.readDicomElementExplicit(b,c);if(d[e.tag]=e,"xfffee00d"===e.tag)return new a.DataSet(b.byteArrayParser,b.byteArray,d)}return c.push("eof encountered before finding item delimiter tag while reading sequence item of undefined length"),new a.DataSet(b.byteArrayParser,b.byteArray,d)}function c(c,d){var e=a.readSequenceItem(c);return 4294967295===e.length?(e.hadUndefinedLength=!0,e.dataSet=b(c,d),e.length=c.position-e.dataOffset):(e.dataSet=new a.DataSet(c.byteArrayParser,c.byteArray,{}),a.parseDicomDataSetExplicit(e.dataSet,c,c.position+e.length)),e}function d(b,d,e){for(;b.position+4<=b.byteArray.length;){var f=a.readTag(b);if(b.seek(-4),"xfffee0dd"===f)return d.length=b.position-d.dataOffset,b.seek(8),d;var g=c(b,e);d.items.push(g)}e.push("eof encountered before finding sequence delimitation tag while reading sequence of undefined length"),d.length=b.position-d.dataOffset}function e(a,b,d){for(var e=b.dataOffset+b.length;a.position<e;){var f=c(a,d);b.items.push(f)}}return void 0===a&&(a={}),a.readSequenceItemsExplicit=function(a,b,c){if(void 0===a)throw"dicomParser.readSequenceItemsExplicit: missing required parameter 'byteStream'";if(void 0===b)throw"dicomParser.readSequenceItemsExplicit: missing required parameter 'element'";b.items=[],4294967295===b.length?d(a,b,c):e(a,b,c)},a}(a),a=function(a){"use strict";function b(b,c){for(var d={};b.position<b.byteArray.length;){var e=a.readDicomElementImplicit(b,void 0,c);if(d[e.tag]=e,"xfffee00d"===e.tag)return new a.DataSet(b.byteArrayParser,b.byteArray,d)}return b.warnings.push("eof encountered before finding sequence item delimiter in sequence item of undefined length"),new a.DataSet(b.byteArrayParser,b.byteArray,d)}function c(c,d){var e=a.readSequenceItem(c);return 4294967295===e.length?(e.hadUndefinedLength=!0,e.dataSet=b(c,d),e.length=c.position-e.dataOffset):(e.dataSet=new a.DataSet(c.byteArrayParser,c.byteArray,{}),a.parseDicomDataSetImplicit(e.dataSet,c,c.position+e.length,{vrCallback:d})),e}function d(b,d,e){for(;b.position+4<=b.byteArray.length;){var f=a.readTag(b);if(b.seek(-4),"xfffee0dd"===f)return d.length=b.position-d.dataOffset,b.seek(8),d;var g=c(b,e);d.items.push(g)}b.warnings.push("eof encountered before finding sequence delimiter in sequence of undefined length"),d.length=b.byteArray.length-d.dataOffset}function e(a,b,d){for(var e=b.dataOffset+b.length;a.position<e;){var f=c(a,d);b.items.push(f)}}return void 0===a&&(a={}),a.readSequenceItemsImplicit=function(a,b,c){if(void 0===a)throw"dicomParser.readSequenceItemsImplicit: missing required parameter 'byteStream'";if(void 0===b)throw"dicomParser.readSequenceItemsImplicit: missing required parameter 'element'";b.items=[],4294967295===b.length?d(a,b,c):e(a,b,c)},a}(a),a=function(a){"use strict";return void 0===a&&(a={}),a.readSequenceItem=function(b){if(void 0===b)throw"dicomParser.readSequenceItem: missing required parameter 'byteStream'";var c={tag:a.readTag(b),length:b.readUint32(),dataOffset:b.position};if("xfffee000"!==c.tag){var d=b.position;throw"dicomParser.readSequenceItem: item tag (FFFE,E000) not found at offset "+d}return c},a}(a),a=function(a){"use strict";return void 0===a&&(a={}),a.readTag=function(a){if(void 0===a)throw"dicomParser.readTag: missing required parameter 'byteStream'";var b=256*a.readUint16()*256,c=a.readUint16(),d="x"+("00000000"+(b+c).toString(16)).substr(-8);return d},a}(a),a=function(a){"use strict";return void 0===a&&(a={}),a.sharedCopy=function(a,b,c){if("undefined"!=typeof Buffer&&a instanceof Buffer)return a.slice(b,b+c);if(a instanceof Uint8Array)return new Uint8Array(a.buffer,a.byteOffset+b,c);throw"dicomParser.from: unknown type for byteArray"},a}(a),a=function(a){"use strict";return void 0===a&&(a={}),a.version="1.7.3",a}(a);return a});