This commit is contained in:
Ross
2021-02-24 10:05:10 +00:00
commit 683f77fcf4
49 changed files with 62632 additions and 0 deletions
@@ -0,0 +1,242 @@
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var _defaultOptions = {
channel: 4,
width: null,
height: null,
schema: 'base64://'
};
var CornerstoneBase64ImageLoader = /** @class */ (function () {
function CornerstoneBase64ImageLoader(cornerstone, options) {
if (options === void 0) { options = _defaultOptions; }
this._cornerstone = cornerstone;
this._options = options;
this._lastImageIdDrawn = null;
this._UPNG = null;
this._canvas = document.createElement('canvas');
this.arrayBufferToImage = this.arrayBufferToImage.bind(this);
this.getArrayBuffer = this.getArrayBuffer.bind(this);
this.decodeBase64 = this.decodeBase64.bind(this);
this.createImage = this.createImage.bind(this);
this.imageLoader = this.imageLoader.bind(this);
this.replaceImage = this.replaceImage.bind(this);
}
CornerstoneBase64ImageLoader.prototype.arrayBufferToImage = function (arrayBuffer) {
return new Promise(function (resolve, reject) {
var image = new Image();
var arrayBufferView = new Uint8Array(arrayBuffer);
var blob = new Blob([arrayBufferView]);
var urlCreator = window.URL || window.webkitURL;
var imageUrl = urlCreator.createObjectURL(blob);
image.src = imageUrl;
image.onload = function () {
urlCreator.revokeObjectURL(imageUrl);
resolve(image);
};
image.onerror = function (error) {
urlCreator.revokeObjectURL(imageUrl);
reject(error);
};
});
};
CornerstoneBase64ImageLoader.prototype.getArrayBuffer = function (str) {
var buf = new ArrayBuffer(str.length);
var bufView = new Uint8Array(buf);
Array.from(str).map(function (ch, idx) {
bufView[idx] = ch.charCodeAt(0);
return ch;
});
return bufView;
};
CornerstoneBase64ImageLoader.prototype.decodeBase64 = function (base64PixelData) {
var pixelDataAsString = window.atob(base64PixelData);
var arrayBuffer = this.getArrayBuffer(pixelDataAsString);
return arrayBuffer;
};
CornerstoneBase64ImageLoader.prototype.createImage = function (image, imageId) {
var _this = this;
var rows = image.naturalHeight;
var columns = image.naturalWidth;
var getImageData = function () {
var context;
if (_this._lastImageIdDrawn === imageId) {
context = _this._canvas.getContext('2d');
}
else {
_this._canvas.height = image.naturalHeight;
_this._canvas.width = image.naturalWidth;
context = _this._canvas.getContext('2d');
context.drawImage(image, 0, 0);
_this._lastImageIdDrawn = imageId;
}
return context.getImageData(0, 0, image.naturalWidth, image.naturalHeight);
};
var getPixelData = function () {
var imageData = getImageData();
return imageData.data;
};
var getCanvas = function () {
if (_this._lastImageIdDrawn === imageId) {
return _this._canvas;
}
_this._canvas.height = image.naturalHeight;
_this._canvas.width = image.naturalWidth;
var context = _this._canvas.getContext('2d');
context.drawImage(image, 0, 0);
_this._lastImageIdDrawn = imageId;
return _this._canvas;
};
var setLastImageIdDrawn = function (nextLastImageIdDrawn) {
if (nextLastImageIdDrawn === void 0) { nextLastImageIdDrawn = null; }
_this._lastImageIdDrawn = nextLastImageIdDrawn;
};
return {
imageId: imageId,
minPixelValue: 0,
maxPixelValue: 255,
slope: 1,
intercept: 0,
windowCenter: 128,
windowWidth: 255,
render: this.cornerstone.renderWebImage,
getPixelData: getPixelData,
getCanvas: getCanvas,
getImage: function () { return image; },
setLastImageIdDrawn: setLastImageIdDrawn,
rows: rows,
columns: columns,
height: rows,
width: columns,
color: true,
rgba: false,
columnPixelSpacing: null,
rowPixelSpacing: null,
invert: false,
sizeInBytes: rows * columns * this._options.channel
};
};
CornerstoneBase64ImageLoader.prototype.imageLoader = function (imageId) {
var _this = this;
// const schema = imageId.split('://')[0]
var base64PixelData = imageId.replace(this._options.schema, '');
var arrayBuffer;
if (this._options.width && this._options.height && this._UPNG) {
var columns = this._options.width;
var rows = this._options.height;
arrayBuffer = new Uint8Array(columns * rows * this._options.channel);
arrayBuffer = this._UPNG.encode([arrayBuffer.buffer], columns, rows, 0);
}
else {
arrayBuffer = this.decodeBase64(base64PixelData);
}
var imagePromise = this.arrayBufferToImage(arrayBuffer);
var promise = new Promise(function (resolve, reject) {
imagePromise.then(function (image) {
var imageObject = _this.createImage(image, imageId);
resolve(imageObject);
}, reject);
});
return {
promise: promise
};
};
CornerstoneBase64ImageLoader.prototype.replaceImage = function (layer, arrayBuffer) {
var _this = this;
if (!this._UPNG) {
return null;
}
var png = this._UPNG.encode([arrayBuffer.buffer], layer.image.columns, layer.image.rows, 0);
var imagePromise = this.arrayBufferToImage(png);
return imagePromise.then(function (image) {
layer.image = _this.createImage(image, layer.image.imageId);
});
};
Object.defineProperty(CornerstoneBase64ImageLoader.prototype, "options", {
get: function () {
return __assign({}, this._options);
},
enumerable: true,
configurable: true
});
Object.defineProperty(CornerstoneBase64ImageLoader.prototype, "cornerstone", {
get: function () {
return this._cornerstone;
},
enumerable: true,
configurable: true
});
Object.defineProperty(CornerstoneBase64ImageLoader.prototype, "UPNG", {
get: function () {
return this._UPNG;
},
enumerable: true,
configurable: true
});
CornerstoneBase64ImageLoader.prototype.setUPNG = function (UPNG) {
this._UPNG = UPNG;
};
CornerstoneBase64ImageLoader.prototype.registerLoaders = function () {
this.cornerstone.registerImageLoader('base64', this.imageLoader);
};
return CornerstoneBase64ImageLoader;
}());
var _imageLoader;
var _options = __assign({}, _defaultOptions);
var cornerstoneBase64ImageLoader = {
external: {
set cornerstone(cs) {
_imageLoader = new CornerstoneBase64ImageLoader(cs, _options);
_imageLoader.registerLoaders();
},
get cornerstone() {
return _imageLoader.cornerstone;
},
get UPNG() {
return _imageLoader.UPNG;
},
set UPNG(_UPNG) {
_imageLoader.setUPNG(_UPNG);
}
},
initOptions: function () {
_options = __assign({}, _defaultOptions);
},
set options(newOptions) {
_options = __assign({}, _options, newOptions);
},
get options() {
return __assign({}, _options);
},
get imageLoader() {
return _imageLoader;
}
};
export default cornerstoneBase64ImageLoader;
//# sourceMappingURL=cornerstone-base64-image-loader.es5.js.map
@@ -0,0 +1,250 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.cornerstoneBase64ImageLoader = factory());
}(this, (function () { 'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var _defaultOptions = {
channel: 4,
width: null,
height: null,
schema: 'base64://'
};
var CornerstoneBase64ImageLoader = /** @class */ (function () {
function CornerstoneBase64ImageLoader(cornerstone, options) {
if (options === void 0) { options = _defaultOptions; }
this._cornerstone = cornerstone;
this._options = options;
this._lastImageIdDrawn = null;
this._UPNG = null;
this._canvas = document.createElement('canvas');
this.arrayBufferToImage = this.arrayBufferToImage.bind(this);
this.getArrayBuffer = this.getArrayBuffer.bind(this);
this.decodeBase64 = this.decodeBase64.bind(this);
this.createImage = this.createImage.bind(this);
this.imageLoader = this.imageLoader.bind(this);
this.replaceImage = this.replaceImage.bind(this);
}
CornerstoneBase64ImageLoader.prototype.arrayBufferToImage = function (arrayBuffer) {
return new Promise(function (resolve, reject) {
var image = new Image();
var arrayBufferView = new Uint8Array(arrayBuffer);
var blob = new Blob([arrayBufferView]);
var urlCreator = window.URL || window.webkitURL;
var imageUrl = urlCreator.createObjectURL(blob);
image.src = imageUrl;
image.onload = function () {
urlCreator.revokeObjectURL(imageUrl);
resolve(image);
};
image.onerror = function (error) {
urlCreator.revokeObjectURL(imageUrl);
reject(error);
};
});
};
CornerstoneBase64ImageLoader.prototype.getArrayBuffer = function (str) {
var buf = new ArrayBuffer(str.length);
var bufView = new Uint8Array(buf);
Array.from(str).map(function (ch, idx) {
bufView[idx] = ch.charCodeAt(0);
return ch;
});
return bufView;
};
CornerstoneBase64ImageLoader.prototype.decodeBase64 = function (base64PixelData) {
var pixelDataAsString = window.atob(base64PixelData);
var arrayBuffer = this.getArrayBuffer(pixelDataAsString);
return arrayBuffer;
};
CornerstoneBase64ImageLoader.prototype.createImage = function (image, imageId) {
var _this = this;
var rows = image.naturalHeight;
var columns = image.naturalWidth;
var getImageData = function () {
var context;
if (_this._lastImageIdDrawn === imageId) {
context = _this._canvas.getContext('2d');
}
else {
_this._canvas.height = image.naturalHeight;
_this._canvas.width = image.naturalWidth;
context = _this._canvas.getContext('2d');
context.drawImage(image, 0, 0);
_this._lastImageIdDrawn = imageId;
}
return context.getImageData(0, 0, image.naturalWidth, image.naturalHeight);
};
var getPixelData = function () {
var imageData = getImageData();
return imageData.data;
};
var getCanvas = function () {
if (_this._lastImageIdDrawn === imageId) {
return _this._canvas;
}
_this._canvas.height = image.naturalHeight;
_this._canvas.width = image.naturalWidth;
var context = _this._canvas.getContext('2d');
context.drawImage(image, 0, 0);
_this._lastImageIdDrawn = imageId;
return _this._canvas;
};
var setLastImageIdDrawn = function (nextLastImageIdDrawn) {
if (nextLastImageIdDrawn === void 0) { nextLastImageIdDrawn = null; }
_this._lastImageIdDrawn = nextLastImageIdDrawn;
};
return {
imageId: imageId,
minPixelValue: 0,
maxPixelValue: 255,
slope: 1,
intercept: 0,
windowCenter: 128,
windowWidth: 255,
render: this.cornerstone.renderWebImage,
getPixelData: getPixelData,
getCanvas: getCanvas,
getImage: function () { return image; },
setLastImageIdDrawn: setLastImageIdDrawn,
rows: rows,
columns: columns,
height: rows,
width: columns,
color: true,
rgba: false,
columnPixelSpacing: null,
rowPixelSpacing: null,
invert: false,
sizeInBytes: rows * columns * this._options.channel
};
};
CornerstoneBase64ImageLoader.prototype.imageLoader = function (imageId) {
var _this = this;
// const schema = imageId.split('://')[0]
var base64PixelData = imageId.replace(this._options.schema, '');
var arrayBuffer;
if (this._options.width && this._options.height && this._UPNG) {
var columns = this._options.width;
var rows = this._options.height;
arrayBuffer = new Uint8Array(columns * rows * this._options.channel);
arrayBuffer = this._UPNG.encode([arrayBuffer.buffer], columns, rows, 0);
}
else {
arrayBuffer = this.decodeBase64(base64PixelData);
}
var imagePromise = this.arrayBufferToImage(arrayBuffer);
var promise = new Promise(function (resolve, reject) {
imagePromise.then(function (image) {
var imageObject = _this.createImage(image, imageId);
resolve(imageObject);
}, reject);
});
return {
promise: promise
};
};
CornerstoneBase64ImageLoader.prototype.replaceImage = function (layer, arrayBuffer) {
var _this = this;
if (!this._UPNG) {
return null;
}
var png = this._UPNG.encode([arrayBuffer.buffer], layer.image.columns, layer.image.rows, 0);
var imagePromise = this.arrayBufferToImage(png);
return imagePromise.then(function (image) {
layer.image = _this.createImage(image, layer.image.imageId);
});
};
Object.defineProperty(CornerstoneBase64ImageLoader.prototype, "options", {
get: function () {
return __assign({}, this._options);
},
enumerable: true,
configurable: true
});
Object.defineProperty(CornerstoneBase64ImageLoader.prototype, "cornerstone", {
get: function () {
return this._cornerstone;
},
enumerable: true,
configurable: true
});
Object.defineProperty(CornerstoneBase64ImageLoader.prototype, "UPNG", {
get: function () {
return this._UPNG;
},
enumerable: true,
configurable: true
});
CornerstoneBase64ImageLoader.prototype.setUPNG = function (UPNG) {
this._UPNG = UPNG;
};
CornerstoneBase64ImageLoader.prototype.registerLoaders = function () {
this.cornerstone.registerImageLoader('base64', this.imageLoader);
};
return CornerstoneBase64ImageLoader;
}());
var _imageLoader;
var _options = __assign({}, _defaultOptions);
var cornerstoneBase64ImageLoader = {
external: {
set cornerstone(cs) {
_imageLoader = new CornerstoneBase64ImageLoader(cs, _options);
_imageLoader.registerLoaders();
},
get cornerstone() {
return _imageLoader.cornerstone;
},
get UPNG() {
return _imageLoader.UPNG;
},
set UPNG(_UPNG) {
_imageLoader.setUPNG(_UPNG);
}
},
initOptions: function () {
_options = __assign({}, _defaultOptions);
},
set options(newOptions) {
_options = __assign({}, _options, newOptions);
},
get options() {
return __assign({}, _options);
},
get imageLoader() {
return _imageLoader;
}
};
return cornerstoneBase64ImageLoader;
})));
//# sourceMappingURL=cornerstone-base64-image-loader.umd.js.map
File diff suppressed because one or more lines are too long
+1
View File
@@ -0,0 +1 @@
/*! cornerstone - v0.9.0 - 2016-02-03 | (c) 2014 Chris Hafey | https://github.com/chafey/cornerstone */.cornerstone-enabled-image{-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:default}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+3
View File
@@ -0,0 +1,3 @@
/*! cornerstone-web-image-loader - 2.1.1 - 2018-12-05 | (c) 2016 Chris Hafey | https://github.com/cornerstonejs/cornerstoneWebImageLoader */
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("cornerstoneWebImageLoader",[],t):"object"==typeof exports?exports.cornerstoneWebImageLoader=t():e.cornerstoneWebImageLoader=t()}(window,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=5)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.external=void 0;var r,o=n(4),a=(r=o)&&r.__esModule?r:{default:r};var u=void 0,i={set cornerstone(e){u=e,(0,a.default)(u)},get cornerstone(){return u}};t.external=i},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.loadImage=function(e){var t=r.external.cornerstone,n=new XMLHttpRequest;return n.open("GET",e,!0),n.responseType="arraybuffer",i.beforeSend(n),n.onprogress=function(n){if(n.lengthComputable){var r=n.loaded,o=n.total,a=Math.round(r/o*100),u={imageId:e,loaded:r,total:o,percentComplete:a};t.triggerEvent(t.events,"cornerstoneimageloadprogress",u)}},{promise:new Promise(function(t,r){n.onload=function(){(0,o.default)(this.response).then(function(n){var r=(0,a.default)(n,e);t(r)},r)},n.send()}),cancelFn:function(){n.abort()}}},t.configure=function(e){i=e};var r=n(0),o=u(n(3)),a=u(n(2));function u(e){return e&&e.__esModule?e:{default:e}}var i={beforeSend:function(){}}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){var n=e.naturalHeight,u=e.naturalWidth;return{imageId:t,minPixelValue:0,maxPixelValue:255,slope:1,intercept:0,windowCenter:128,windowWidth:255,render:r.external.cornerstone.renderWebImage,getPixelData:function(){return(n=void 0,a===t?n=o.getContext("2d"):(o.height=e.naturalHeight,o.width=e.naturalWidth,(n=o.getContext("2d")).drawImage(e,0,0),a=t),n.getImageData(0,0,e.naturalWidth,e.naturalHeight)).data;var n},getCanvas:function(){return a===t?o:(o.height=e.naturalHeight,o.width=e.naturalWidth,o.getContext("2d").drawImage(e,0,0),a=t,o)},getImage:function(){return e},rows:n,columns:u,height:n,width:u,color:!0,rgba:!1,columnPixelSpacing:void 0,rowPixelSpacing:void 0,invert:!1,sizeInBytes:n*u*4}};var r=n(0),o=document.createElement("canvas"),a=void 0},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){return new Promise(function(t,n){var r=new Image,o=new Uint8Array(e),a=new Blob([o]),u=window.URL||window.webkitURL,i=u.createObjectURL(a);r.src=i,r.onload=function(){t(r),u.revokeObjectURL(i)},r.onerror=function(e){u.revokeObjectURL(i),n(e)}})}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){e.registerImageLoader("http",r.loadImage),e.registerImageLoader("https",r.loadImage)};var r=n(1)},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.external=t.configure=t.loadImage=t.createImage=t.arrayBufferToImage=void 0;var r=i(n(3)),o=i(n(2)),a=n(1),u=n(0);function i(e){return e&&e.__esModule?e:{default:e}}var d={arrayBufferToImage:r.default,createImage:o.default,loadImage:a.loadImage,configure:a.configure,external:u.external};t.arrayBufferToImage=r.default,t.createImage=o.default,t.loadImage=a.loadImage,t.configure=a.configure,t.external=u.external,t.default=d}])});
//# sourceMappingURL=cornerstoneWebImageLoader.min.js.map
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
+4474
View File
File diff suppressed because it is too large Load Diff