Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:Infogosoft/jsdicom

  • Loading branch information...
commit b5bc714ec5dd0ff875c385a0f7790f6dd28880de 2 parents 039a000 + 1f4633c
@rickardholmberg rickardholmberg authored
View
2  README.md
@@ -2,7 +2,7 @@
Dicom library and viewer written in javascript.
##Dicom parsing
-The dicom parser can handle Implicit VR Little-endian, Explicit VR Little-endian and Explicit VR Big-endian. Sequences are not yet handled correctly.
+The dicom parser can handle Implicit VR Little-endian, Explicit VR Little-endian and Explicit VR Big-endian. ~~Sequences are not yet handled correctly.~~
Parsing files:
View
4 js/app.js
@@ -261,8 +261,8 @@ DcmApp.prototype.draw_image = function() {
$("#sliceidx_info").text(this.curr_file_idx+1 + "/" + this.files.length);
$("#slider").slider("option", "value", this.curr_file_idx);
var windowing = this.painter.get_windowing();
- $("#ww_info").text(windowing[0]);
- $("#wl_info").text(windowing[1]);
+ $("#ww_info").text(windowing[1]);
+ $("#wl_info").text(windowing[0]);
this.painter.set_file(curr_file);
this.painter.set_cluts(this.curr_clut_r, this.curr_clut_g, this.curr_clut_b);
this.painter.draw_image();
View
29 js/glpainter.js
@@ -11,7 +11,8 @@
*/
var FRAG_SHADER_8 = 0;
var FRAG_SHADER_16 = 1;
-var FRAG_SHADER_RGB_8 = 2;
+var FRAG_SHADER_16_TWO_COMPLEMENTS = 2;
+var FRAG_SHADER_RGB_8 = 3;
function ImageSlice(file, texture, rs, ri, alpha) {
this.file = file;
@@ -78,6 +79,7 @@ GLPainter.prototype.set_file = function(dcmfile) {
GLPainter.prototype.file_to_texture = function(dcmfile) {
var internalFormat;
+ raw_data = dcmfile.get_element(dcmdict.PixelData).data;
switch(jQuery.trim(dcmfile.PhotometricInterpretation)) {
case "MONOCHROME1":
// TODO: MONOCHROME1 should use inverse cluts.
@@ -86,6 +88,16 @@ GLPainter.prototype.file_to_texture = function(dcmfile) {
internalFormat = this.gl.LUMINANCE;
} else {
internalFormat = this.gl.LUMINANCE_ALPHA;
+ if(dcmfile.PixelRepresentation == 0x01) {
+ if(!dcmfile.PixelRepresentationPatched) {
+ //var view16bit = new Uint16Array(dcmfile.PixelData.data.buffer, dcmfile.PixelData.data.byteOffset, dcmfile.PixelData.length/2);
+ console.log("Patching");
+ for(var i=0;i<dcmfile.PixelData.length;++i) {
+ dcmfile.PixelData[i] = dcmfile.PixelData[i] ^ 0x8000;
+ }
+ dcmfile.PixelRepresentationPatched = true;
+ }
+ }
}
break;
case "RGB":
@@ -107,10 +119,9 @@ GLPainter.prototype.file_to_texture = function(dcmfile) {
0, // border
internalFormat, // format
this.gl.UNSIGNED_BYTE, // type
- new Uint8Array(dcmfile.PixelData.buffer, dcmfile.PixelData.byteOffset)); // data
- //Uint8Array(dcmfile.PixelData.buffer, dcmfile.PixelData.byteOffset)); // TODO: type conversion instead of new array?
- this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MAG_FILTER, this.gl.LINEAR);
+ dcmfile.get_element(dcmdict.PixelData).data);// Get raw Uint8array
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MIN_FILTER, this.gl.LINEAR);
+ this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MAG_FILTER, this.gl.LINEAR);
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_S, this.gl.CLAMP_TO_EDGE);
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_T, this.gl.CLAMP_TO_EDGE);
@@ -188,8 +199,8 @@ GLPainter.prototype.set_cluts = function(clut_r, clut_g, clut_b) {
}
GLPainter.prototype.set_windowing = function(wl, ww) {
- this.ww = ww;
this.wl = wl;
+ this.ww = ww;
}
GLPainter.prototype.get_windowing = function() {
return [this.wl, this.ww];
@@ -350,12 +361,14 @@ GLPainter.prototype.draw_image = function() {
this.set_matrix_uniforms(shaderProgram);
this.set_window_uniforms(shaderProgram, image);
+
this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, this.vertexIndexBuffer);
this.gl.drawElements(this.gl.TRIANGLES, this.vertexIndexBuffer.numItems, this.gl.UNSIGNED_SHORT, 0);
}
}
+off = (1 << (15 - 1));
GLPainter.prototype.init = function(canvasid) {
try {
@@ -447,7 +460,11 @@ GLPainter.prototype.set_matrix_uniforms = function(shaderProgram) {
}
GLPainter.prototype.set_window_uniforms = function(shaderProgram, image) {
- this.gl.uniform1f(shaderProgram.wlUniform, this.wl);
+ // Hack for files with pixel representation in two complements
+ var wl = this.wl;
+ if(image.file.PixelRepresentation == 0x01)
+ wl += 32768.0;
+ this.gl.uniform1f(shaderProgram.wlUniform, wl);
this.gl.uniform1f(shaderProgram.wwUniform, this.ww);
this.gl.uniform1f(shaderProgram.rsUniform, image.rs);
this.gl.uniform1f(shaderProgram.riUniform, image.ri);
View
13 js/shaders.js
@@ -23,10 +23,8 @@ uniform sampler2D uClutSampler;\
void main(void) { \
highp vec4 texcolor = texture2D(uSampler, vTextureCoord); \
highp float intensity = texcolor.r*65536.0;\
- highp float wl = uWL;\
- highp float ww = uWW;\
- highp float lower_bound = wl - ww/2.0;\
- highp float upper_bound = wl + ww/2.0;\
+ highp float lower_bound = uWL - uWW/2.0;\
+ highp float upper_bound = uWL + uWW/2.0;\
intensity = (intensity - lower_bound)/(upper_bound - lower_bound);\
\
gl_FragColor = vec4(intensity, intensity, intensity, uAlpha);\
@@ -49,14 +47,11 @@ void main(void) { \
highp float rescaleIntercept = uRI;\
highp float rescaleSlope = uRS;\
intensity = intensity * rescaleSlope + rescaleIntercept;\
- highp float wl = uWL;\
- highp float ww = uWW;\
- highp float lower_bound = wl - ww/2.0;\
- highp float upper_bound = wl + ww/2.0;\
+ highp float lower_bound = uWL - uWW/2.0;\
+ highp float upper_bound = uWL + uWW/2.0;\
intensity = (intensity - lower_bound)/(upper_bound - lower_bound);\
highp vec4 clutcolor = texture2D(uClutSampler, vec2(intensity, intensity)); \
gl_FragColor = vec4(clutcolor.r, clutcolor.g, clutcolor.b, uAlpha);\
-\
}";
var fragment_shader_rgb_8 = "\
2  jsdicom-lib
@@ -1 +1 @@
-Subproject commit 3fe933e945f3a45ab382d8a21baf1e577ce6b3ab
+Subproject commit a92451d3e41e9a8cab67b920726d3a5913717408
Please sign in to comment.
Something went wrong with that request. Please try again.