Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RGB24 support #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
node_modules/
coverage/
package-lock.json
examples/data/603_1__ALPHA_Serie_a.nii.gz
examples/data/603_1__ALPHA_Serie_a.nii
package-lock.json
package-lock.json
52 changes: 47 additions & 5 deletions dist/cornerstoneNIFTIImageLoader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! cornerstone-nifti-image-loader - 1.0.0 - 2019-06-19 | (c) 2018 Flywheel Exchange, LLC | https://github.com/flywheel-io/cornerstone-nifti-image-loader */
/*! cornerstone-nifti-image-loader - 1.0.0 - 2020-04-08 | (c) 2018 Flywheel Exchange, LLC | https://github.com/flywheel-io/cornerstone-nifti-image-loader */
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
Expand Down Expand Up @@ -70,6 +70,17 @@ return /******/ (function(modules) { // webpackBootstrap
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // webpack-livereload-plugin
/******/ (function() {
/******/ if (typeof window === "undefined") { return };
/******/ var id = "webpack-livereload-plugin-script";
/******/ if (document.getElementById(id)) { return; }
/******/ var el = document.createElement("script");
/******/ el.id = id;
/******/ el.async = true;
/******/ el.src = "//" + location.hostname + ":45001/livereload.js";
/******/ document.getElementsByTagName("head")[0].appendChild(el);
/******/ }());
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 41);
/******/ })
Expand Down Expand Up @@ -3407,6 +3418,22 @@ function parseNiftiHeader(fileData) {
};
}

function convert24bito32bit(typedArray8) {
var dview = new DataView(typedArray8.buffer);
var num_pixels = typedArray8.length / 3 * 4;
var image32bit = new Uint32Array(num_pixels);

for (var i = 0; i < num_pixels; i++) {
var b = dview.getUint8(i * 3);
var g = dview.getUint8(i * 3 + 1);
var r = dview.getUint8(i * 3 + 2);

image32bit[i] = (r << 16) + (g << 8) + b + 0xff000000;
}

return image32bit;
}

function parseNiftiFile(fileData, metaData) {
var nifti = _externalModules.external.niftiReader;

Expand All @@ -3424,6 +3451,10 @@ function parseNiftiFile(fileData, metaData) {
imageData = (0, _niftiBigEndianDecoder2.default)(metaData.header.datatypeCode, imageData);
}

if (metaData.header.datatypeCode === nifti.NIFTI1.TYPE_RGB24) {
imageData = convert24bito32bit(imageData);
}

// determines the meta data that depends on the image data
return {
metaData: metaData,
Expand Down Expand Up @@ -3511,15 +3542,15 @@ function getOrientationMatrix(header) {
function niftiDatatypeCodeToTypedArray(nifti, datatypeCode) {
var _typedArrayConstructo;

var typedArrayConstructorMap = (_typedArrayConstructo = {}, _defineProperty(_typedArrayConstructo, nifti.NIFTI1.TYPE_UINT8, Uint8Array), _defineProperty(_typedArrayConstructo, nifti.NIFTI1.TYPE_UINT16, Uint16Array), _defineProperty(_typedArrayConstructo, nifti.NIFTI1.TYPE_UINT32, Uint32Array), _defineProperty(_typedArrayConstructo, nifti.NIFTI1.TYPE_INT8, Int8Array), _defineProperty(_typedArrayConstructo, nifti.NIFTI1.TYPE_INT16, Int16Array), _defineProperty(_typedArrayConstructo, nifti.NIFTI1.TYPE_INT32, Int32Array), _defineProperty(_typedArrayConstructo, nifti.NIFTI1.TYPE_FLOAT32, Float32Array), _defineProperty(_typedArrayConstructo, nifti.NIFTI1.TYPE_FLOAT64, Float64Array), _defineProperty(_typedArrayConstructo, nifti.NIFTI1.TYPE_RGB, Uint8Array), _defineProperty(_typedArrayConstructo, nifti.NIFTI1.TYPE_RGBA, Uint8Array), _typedArrayConstructo);
var typedArrayConstructorMap = (_typedArrayConstructo = {}, _defineProperty(_typedArrayConstructo, nifti.NIFTI1.TYPE_UINT8, Uint8Array), _defineProperty(_typedArrayConstructo, nifti.NIFTI1.TYPE_UINT16, Uint16Array), _defineProperty(_typedArrayConstructo, nifti.NIFTI1.TYPE_UINT32, Uint32Array), _defineProperty(_typedArrayConstructo, nifti.NIFTI1.TYPE_INT8, Int8Array), _defineProperty(_typedArrayConstructo, nifti.NIFTI1.TYPE_INT16, Int16Array), _defineProperty(_typedArrayConstructo, nifti.NIFTI1.TYPE_INT32, Int32Array), _defineProperty(_typedArrayConstructo, nifti.NIFTI1.TYPE_FLOAT32, Float32Array), _defineProperty(_typedArrayConstructo, nifti.NIFTI1.TYPE_FLOAT64, Float64Array), _defineProperty(_typedArrayConstructo, nifti.NIFTI1.TYPE_RGB, Uint8Array), _defineProperty(_typedArrayConstructo, nifti.NIFTI1.TYPE_RGBA, Uint8Array), _defineProperty(_typedArrayConstructo, nifti.NIFTI1.TYPE_RGB24, Uint32Array), _typedArrayConstructo);

return typedArrayConstructorMap[datatypeCode];
}

function isDataInFloat(nifti, datatypeCode) {
var _isFloatTypeMap;

var isFloatTypeMap = (_isFloatTypeMap = {}, _defineProperty(_isFloatTypeMap, nifti.NIFTI1.TYPE_UINT8, false), _defineProperty(_isFloatTypeMap, nifti.NIFTI1.TYPE_UINT16, false), _defineProperty(_isFloatTypeMap, nifti.NIFTI1.TYPE_UINT32, false), _defineProperty(_isFloatTypeMap, nifti.NIFTI1.TYPE_INT8, false), _defineProperty(_isFloatTypeMap, nifti.NIFTI1.TYPE_INT16, false), _defineProperty(_isFloatTypeMap, nifti.NIFTI1.TYPE_INT32, false), _defineProperty(_isFloatTypeMap, nifti.NIFTI1.TYPE_FLOAT32, true), _defineProperty(_isFloatTypeMap, nifti.NIFTI1.TYPE_FLOAT64, true), _defineProperty(_isFloatTypeMap, nifti.NIFTI1.TYPE_RGB, false), _defineProperty(_isFloatTypeMap, nifti.NIFTI1.TYPE_RGBA, false), _isFloatTypeMap);
var isFloatTypeMap = (_isFloatTypeMap = {}, _defineProperty(_isFloatTypeMap, nifti.NIFTI1.TYPE_UINT8, false), _defineProperty(_isFloatTypeMap, nifti.NIFTI1.TYPE_UINT16, false), _defineProperty(_isFloatTypeMap, nifti.NIFTI1.TYPE_UINT32, false), _defineProperty(_isFloatTypeMap, nifti.NIFTI1.TYPE_INT8, false), _defineProperty(_isFloatTypeMap, nifti.NIFTI1.TYPE_INT16, false), _defineProperty(_isFloatTypeMap, nifti.NIFTI1.TYPE_INT32, false), _defineProperty(_isFloatTypeMap, nifti.NIFTI1.TYPE_FLOAT32, true), _defineProperty(_isFloatTypeMap, nifti.NIFTI1.TYPE_FLOAT64, true), _defineProperty(_isFloatTypeMap, nifti.NIFTI1.TYPE_RGB, false), _defineProperty(_isFloatTypeMap, nifti.NIFTI1.TYPE_RGBA, false), _defineProperty(_isFloatTypeMap, nifti.NIFTI1.TYPE_RGB24, false), _isFloatTypeMap);

return isFloatTypeMap[datatypeCode];
}
Expand All @@ -3528,7 +3559,7 @@ function isDataInColors(nifti, dims, datatypeCode) {
var _hasColorsMap;

var samplesPerPixel = getSamplesPerPixel(dims);
var hasColorsMap = (_hasColorsMap = {}, _defineProperty(_hasColorsMap, nifti.NIFTI1.TYPE_UINT8, false), _defineProperty(_hasColorsMap, nifti.NIFTI1.TYPE_UINT16, false), _defineProperty(_hasColorsMap, nifti.NIFTI1.TYPE_UINT32, false), _defineProperty(_hasColorsMap, nifti.NIFTI1.TYPE_INT8, false), _defineProperty(_hasColorsMap, nifti.NIFTI1.TYPE_INT16, false), _defineProperty(_hasColorsMap, nifti.NIFTI1.TYPE_INT32, false), _defineProperty(_hasColorsMap, nifti.NIFTI1.TYPE_FLOAT32, false), _defineProperty(_hasColorsMap, nifti.NIFTI1.TYPE_FLOAT64, false), _defineProperty(_hasColorsMap, nifti.NIFTI1.TYPE_RGB, samplesPerPixel === 3), _defineProperty(_hasColorsMap, nifti.NIFTI1.TYPE_RGBA, samplesPerPixel === 4), _hasColorsMap);
var hasColorsMap = (_hasColorsMap = {}, _defineProperty(_hasColorsMap, nifti.NIFTI1.TYPE_UINT8, false), _defineProperty(_hasColorsMap, nifti.NIFTI1.TYPE_UINT16, false), _defineProperty(_hasColorsMap, nifti.NIFTI1.TYPE_UINT32, false), _defineProperty(_hasColorsMap, nifti.NIFTI1.TYPE_INT8, false), _defineProperty(_hasColorsMap, nifti.NIFTI1.TYPE_INT16, false), _defineProperty(_hasColorsMap, nifti.NIFTI1.TYPE_INT32, false), _defineProperty(_hasColorsMap, nifti.NIFTI1.TYPE_FLOAT32, false), _defineProperty(_hasColorsMap, nifti.NIFTI1.TYPE_FLOAT64, false), _defineProperty(_hasColorsMap, nifti.NIFTI1.TYPE_RGB, samplesPerPixel === 3), _defineProperty(_hasColorsMap, nifti.NIFTI1.TYPE_RGBA, samplesPerPixel === 4), _defineProperty(_hasColorsMap, nifti.NIFTI1.TYPE_RGB24, true), _hasColorsMap);

return hasColorsMap[datatypeCode];
}
Expand Down Expand Up @@ -8648,9 +8679,10 @@ function getPhotometricInterpretation(metaData, niftiReader) {
var samplesPerPixel = getSamplesPerPixel(metaData);
var isRGB = dataTypeCode === niftiReader.NIFTI1.TYPE_RGB && samplesPerPixel === 3;
var isRGBA = dataTypeCode === niftiReader.NIFTI1.TYPE_RGBA && samplesPerPixel === 4;
var isRGB24 = dataTypeCode === niftiReader.NIFTI1.TYPE_RGB24;

// we assume 'RGB' if nifti file has RGB or RGBA types and samplesPerPixel matches
if (isRGB || isRGBA) {
if (isRGB || isRGBA || isRGB24) {
return 'RGB';
}

Expand Down Expand Up @@ -16327,6 +16359,16 @@ var Slice = function () {
var cornerstone = _externalModules.external.cornerstone;
var render = volumeMetaData.dataType.isDataInColors ? cornerstone.renderColorImage : cornerstone.renderGrayscaleImage;

if (volumeMetaData.header.datatypeCode === 128) {
this.pixelData = new Uint8Array(this.pixelData.buffer);

// this should probably go elsewhere for RGB24 data
volumeMetaData.windowCenter = 128;
volumeMetaData.windowWidth = 256;
volumeMetaData.minPixelValue = 0;
volumeMetaData.maxPixelValue = 255;
}

return {
imageId: this.imageIdObject.url,
color: volumeMetaData.dataType.isDataInColors,
Expand Down
2 changes: 1 addition & 1 deletion dist/cornerstoneNIFTIImageLoader.js.map

Large diffs are not rendered by default.

Loading