forked from chafey/cornerstoneDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cornerstoneWADOImageLoader.min.js
2 lines (2 loc) · 6.12 KB
/
cornerstoneWADOImageLoader.min.js
1
2
/*! cornerstoneWADOImageLoader - v0.2.2 - 2014-05-07 | (c) 2014 Chris Hafey | https://github.com/chafey/cornerstoneWADOImageLoader */
var cornerstoneWADOImageLoader=function(a,b,c){"use strict";function d(a){return"RGB"===a||"PALETTE COLOR"===a||"YBR_FULL"===a||"YBR_FULL_422"===a||"YBR_PARTIAL_422"===a||"YBR_PARTIAL_420"===a||"YBR_RCT"===a?!0:!1}function e(a,b,e){void 0===e&&(e=0);var f=a.string("x00280004"),g=d(f);return g===!1?c.makeGrayscaleImage(b,a,a.byteArray,f,e):c.makeColorImage(b,a,a.byteArray,f,e)}function f(b){var c=a.Deferred(),d=b;d=d.replace("dicomweb","http"),d=d.replace("dicomwebs","https");var f,h=d.indexOf("frame=");if(-1!==h){var i=d.substr(h+6);f=parseInt(i),d=d.substr(0,h-1)}if(void 0!==f&&g.hasOwnProperty(d)){var j=g[d],k=e(j,b,f);return k.then(function(a){c.resolve(a)},function(){c.reject()}),c}var l=new XMLHttpRequest;return l.open("get",d,!0),l.responseType="arraybuffer",l.onreadystatechange=function(){if(4===l.readyState)if(200===l.status){var a=l.response,h=new Uint8Array(a),i=dicomParser.parseDicom(h);void 0!==f&&(g[d]=i);var j=e(i,b,f);j.then(function(a){c.resolve(a)},function(){c.reject()})}else c.reject()},l.send(),c}void 0===c&&(c={});var g={};return b.registerImageLoader("dicomweb",f),b.registerImageLoader("dicomwebs",f),c}($,cornerstone,cornerstoneWADOImageLoader),cornerstoneWADOImageLoader=function(a){"use strict";function b(a,b){if(void 0===a)throw"decodeRGB: rgbBuffer must not be undefined";if(a.length%3!==0)throw"decodeRGB: rgbBuffer length must be divisble by 3";for(var c=a.length/3,d=0,e=0,f=0;c>f;f++)b[e++]=a[d++],b[e++]=a[d++],b[e++]=a[d++],b[e++]=255}return void 0===a&&(a={}),a.decodeRGB=b,a}(cornerstoneWADOImageLoader),cornerstoneWADOImageLoader=function(a){"use strict";function b(a,b){if(void 0===a)throw"decodeRGB: ybrBuffer must not be undefined";if(a.length%3!==0)throw"decodeRGB: ybrBuffer length must be divisble by 3";for(var c=a.length/3,d=0,e=0,f=0;c>f;f++){var g=a[d++],h=a[d++],i=a[d++];b[e++]=g+1.402*(i-128),b[e++]=g-.34414*(h-128)-.71414*(i-128),b[e++]=g+1.772*(h-128),b[e++]=255}}return void 0===a&&(a={}),a.decodeYBRFull=b,a}(cornerstoneWADOImageLoader),cornerstoneWADOImageLoader=function(a){"use strict";function b(a){var b=a.string("x00280030");if(b&&b.length>0){var c=b.split("\\");return{row:parseFloat(c[0]),column:parseFloat(c[1])}}return{row:void 0,column:void 0}}return void 0===a&&(a={}),a.getPixelSpacing=b,a}(cornerstoneWADOImageLoader),cornerstoneWADOImageLoader=function(a){"use strict";function b(a){var b={intercept:0,slope:1},c=a.floatString("x00281052"),d=a.floatString("x00281053");return c&&(b.intercept=c),d&&(b.slope=d),b}return void 0===a&&(a={}),a.getRescaleSlopeAndIntercept=b,a}(cornerstoneWADOImageLoader),cornerstoneWADOImageLoader=function(a){"use strict";function b(a){var b={windowCenter:void 0,windowWidth:void 0},c=a.floatString("x00281050"),d=a.floatString("x00281051");return c&&(b.windowCenter=c),d&&(b.windowWidth=d),b}return void 0===a&&(a={}),a.getWindowWidthAndCenter=b,a}(cornerstoneWADOImageLoader),cornerstoneWADOImageLoader=function(a,b){"use strict";function c(c,d,f,g,h,i){e.height=h,e.width=g;var j,k=c.elements.x7fe00010,l=k.dataOffset,m=c.string("x00020010"),n=g*h*3,o=l+i*n,p=e.getContext("2d"),q=p.createImageData(g,h),r=a.Deferred();if("RGB"===f)return j=new Uint8Array(d.buffer,o),b.decodeRGB(j,q.data),r.resolve(q),r;if("YBR_FULL"===f)return j=new Uint8Array(d.buffer,o),b.decodeYBRFull(j,q.data),r.resolve(q),r;if("YBR_FULL_422"===f&&"1.2.840.10008.1.2.4.50"===m){j=dicomParser.readEncapsulatedPixelData(c,i);var s=new Blob([j],{type:"image/jpeg"}),t=new FileReader;return t.readAsBinaryString(s),t.onload=function(){var a=new Image;a.onload=function(){p.drawImage(this,0,0),q=p.getImageData(0,0,g,h),r.resolve(q)},a.onerror=function(){r.reject()},a.src="data:image/jpeg;base64,"+window.btoa(t.result)},r}throw"no codec for "+f}function d(d,g,h,i,j){var k=b.getPixelSpacing(g),l=g.uint16("x00280010"),m=g.uint16("x00280011"),n=b.getRescaleSlopeAndIntercept(g),o=4,p=l*m,q=p*o,r=b.getWindowWidthAndCenter(g),s=a.Deferred(),t=c(g,h,i,m,l,j);return t.then(function(a){function b(){return a.data}function c(){return a}function h(){if(f===d)return e;e.height=l,e.width=m;var b=e.getContext("2d");return b.putImageData(a,0,0),f=d,e}var i={imageId:d,minPixelValue:0,maxPixelValue:255,slope:n.slope,intercept:n.intercept,windowCenter:r.windowCenter,windowWidth:r.windowWidth,getPixelData:b,getImageData:c,getCanvas:h,rows:l,columns:m,height:l,width:m,color:!0,columnPixelSpacing:k.column,rowPixelSpacing:k.row,data:g,invert:!1,sizeInBytes:q};void 0===i.windowCenter&&(i.windowWidth=255,i.windowCenter=128),s.resolve(i)},function(){s.reject()}),s}void 0===b&&(b={});var e=document.createElement("canvas"),f="";return b.makeColorImage=d,b}($,cornerstoneWADOImageLoader),cornerstoneWADOImageLoader=function(a,b){"use strict";function c(a){{var b=a.uint16("x00280103"),c=a.uint16("x00280100");a.string("x00280004")}return 0===b&&8===c?1:0===b&&16===c?2:1===b&&16===c?3:void 0}function d(a,b,d,e,f){var g=c(a),h=a.elements.x7fe00010,i=h.dataOffset,j=d*e,k=0;return 1===g?(k=i+f*j,new Uint8Array(b.buffer,k)):2===g?(k=i+f*j*2,new Uint16Array(b.buffer,k)):3===g?(k=i+f*j*2,new Int16Array(b.buffer,k)):void 0}function e(a){var b=c(a);if(1===b)return 1;if(2===b||3===b)return 2;throw"unknown pixel format"}function f(a){for(var b=65535,c=-32768,d=a.length,e=a,f=0;d>f;f++){var g=e[f];b=Math.min(b,g),c=Math.max(c,g)}return{min:b,max:c}}function g(c,g,h,i,j){function k(){return u}var l=b.getPixelSpacing(g),m=g.uint16("x00280010"),n=g.uint16("x00280011"),o=b.getRescaleSlopeAndIntercept(g),p=e(g),q=m*n,r=q*p,s="MONOCHROME1"===i,t=b.getWindowWidthAndCenter(g),u=d(g,h,n,m,j),v=f(u),w={imageId:c,minPixelValue:v.min,maxPixelValue:v.max,slope:o.slope,intercept:o.intercept,windowCenter:t.windowCenter,windowWidth:t.windowWidth,getPixelData:k,rows:m,columns:n,height:m,width:n,color:!1,columnPixelSpacing:l.column,rowPixelSpacing:l.row,data:g,invert:s,sizeInBytes:r};if(void 0===w.windowCenter){var x=w.maxPixelValue*w.slope+w.intercept,y=w.minPixelValue*w.slope+w.intercept;w.windowWidth=x-y,w.windowCenter=(x+y)/2}var z=a.Deferred();return z.resolve(w),z}return void 0===b&&(b={}),b.makeGrayscaleImage=g,b}($,cornerstoneWADOImageLoader);