Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Infogosoft/jsdicom
Browse files Browse the repository at this point in the history
  • Loading branch information
rickardholmberg committed May 30, 2012
2 parents 039a000 + 1f4633c commit b5bc714
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
4 changes: 2 additions & 2 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
29 changes: 23 additions & 6 deletions js/glpainter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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":
Expand All @@ -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);

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 4 additions & 9 deletions js/shaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);\
Expand All @@ -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 = "\
Expand Down

0 comments on commit b5bc714

Please sign in to comment.