Skip to content

Commit

Permalink
Merge fab32c7 into 3ee8c9e
Browse files Browse the repository at this point in the history
  • Loading branch information
andrebot committed Dec 8, 2017
2 parents 3ee8c9e + fab32c7 commit e00048b
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 77 deletions.
16 changes: 16 additions & 0 deletions test/internal/getDefaultViewport_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { should } from 'chai';
import getDefaultViewport from '../../src/internal/getDefaultViewport';

should();

describe('getDefaultViewport', function () {
it('should throw an error if we don\'t have a canvas', function () {
getDefaultViewport.should.throw('getDefaultViewport: parameter canvas must not be undefined');
});

it('should return an empty viewport if no image is provided', function () {
const emptyViewport = getDefaultViewport({});

emptyViewport.should.have.all.keys(['scale', 'translation', 'voi', 'invert', 'pixelReplication', 'rotation', 'hflip', 'vflip', 'modalityLUT', 'voiLUT', 'colormap', 'labelmap']);
});
});
44 changes: 44 additions & 0 deletions test/internal/storedColorPixelDataToCanvasImageData_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { should } from 'chai';
import storedColorPixelDataToCanvasImageData from '../../src/internal/storedColorPixelDataToCanvasImageData';

should();

describe('storedColorPixelDataToCanvasImageData', function () {
before(function () {
this.image = {
getPixelData() {
return [1, 2, 3, 4, 2, 0, 1, 0]
},
stats: {}
};
this.lut = [1, 2, 3, 4, 5, 6, 7, 8];
});

describe('pixel value less than 0', function () {
before(function () {
this.image.minPixelValue = -3;
});

it('should generate the image subtracting the minimum pixel value', function () {
let canvasImageDataData = [0, 0, 0, 0, 0, 0, 0, 0];

storedColorPixelDataToCanvasImageData(this.image, this.lut, canvasImageDataData);

canvasImageDataData.should.be.deep.equal([5, 6, 7, 0, 6, 4, 5, 0]);
});
});

describe('pixel value is equal to or greater than 0', function () {
before(function () {
this.image.minPixelValue = 0;
});

it('should generate the image just using the lookup table', function () {
let canvasImageDataData = [0, 0, 0, 0, 0, 0, 0, 0];

storedColorPixelDataToCanvasImageData(this.image, this.lut, canvasImageDataData);

canvasImageDataData.should.be.deep.equal([2, 3, 4, 0, 3, 1, 2, 0]);
});
});
});
39 changes: 39 additions & 0 deletions test/internal/storedPixelDataToCanvasImageDataColorLUT_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { should } from 'chai';
import storedPixelDataToCanvasImageDataColorLUT from '../../src/internal/storedPixelDataToCanvasImageDataColorLUT';

should();

describe('storedPixelDataToCanvasImageDataColorLUT', function () {
before(function () {
this.colorLut = [[3, 2, 1, 1], [7, 6, 5, 4], [6, 1, 2, 8]];
this.image = {
stats: {}
};
});

beforeEach(function () {
this.canvasImageData = [255, 255, 255, 128, 255, 255, 255, 128];
});

it('should get LUT values equal to its pixels when minPixelValue == 0', function () {
this.image.minPixelValue = 0;
this.image.getPixelData = function() {
return [0, 1];
};

storedPixelDataToCanvasImageDataColorLUT(this.image, this.colorLut, this.canvasImageData);

this.canvasImageData.should.be.deep.equal([3, 2, 1, 1, 7, 6, 5, 4]);
});

it('should get LUT values equal to its pixels minus its minimun pixel value when minPixelValue < 0', function () {
this.image.minPixelValue = -1;
this.image.getPixelData = function() {
return [-1, 1];
};

storedPixelDataToCanvasImageDataColorLUT(this.image, this.colorLut, this.canvasImageData);

this.canvasImageData.should.be.deep.equal([3, 2, 1, 1, 6, 1, 2, 8]);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { should } from 'chai';
import storedPixelDataToCanvasImageDataPseudocolorLUT from '../../src/internal/storedPixelDataToCanvasImageDataPseudocolorLUT';

should();

describe('storedPixelDataToCanvasImageDataPseudocolorLUT', function () {
before(function () {
this.grayscaleLut = [1, 2];
this.colorLut = [[1, 2, 3, 4], [4, 4, 1, 2], [7, 7, 2, 0]];
this.image = {
minPixelValue: 0,
stats: {},
getPixelData() {
return [0, 1]
}
}
});

beforeEach(function () {
this.canvasImageData = [255, 255, 255, 128, 255, 255, 255, 128];
});

it('should get the values from colorLUT without the minPixel offset when minPixelValue == 0', function () {
storedPixelDataToCanvasImageDataPseudocolorLUT(this.image, this.grayscaleLut, this.colorLut, this.canvasImageData);

this.canvasImageData.should.be.deep.equal([4, 4, 1, 2, 7, 7, 2, 0]);
});

it('should get the values from colorLUT with the minPixel offset when minPixelValue < 0', function () {
this.image.minPixelValue = -1;
this.image.getPixelData = function () {
return [-1, 0];
};

storedPixelDataToCanvasImageDataPseudocolorLUT(this.image, this.grayscaleLut, this.colorLut, this.canvasImageData);

this.canvasImageData.should.be.deep.equal([4, 4, 1, 2, 7, 7, 2, 0]);
});
});
164 changes: 87 additions & 77 deletions test/internal/storedPixelDataToCanvasImageData_test.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,105 @@
import { assert } from 'chai';

// import { assert } from 'chai';
import { should } from 'chai';
import storedPixelDataToCanvasImageData from '../../src/internal/storedPixelDataToCanvasImageData.js';

should();

describe('storedPixelDataToCanvasImageData', function () {
it('storedPixelDataToCanvasImageData minPixel = 0', function () {
before(function () {
this.lut = [0, 255];
// Arrange
const lut = [0, 255];
const canvasImageDataData = [255, 255, 255, 128, 255, 255, 255, 128];
const image = {
minPixelValue: 0,
this.image = {
maxPixelValue: 1,
width: 1,
height: 2,
getPixelData () {
return new Uint16Array([0, 1]);
},
stats: {}
};
});

// Act
storedPixelDataToCanvasImageData(image, lut, canvasImageDataData);

// Assert
assert.equal(canvasImageDataData[0], 255, 'R1');
assert.equal(canvasImageDataData[1], 255, 'G1');
assert.equal(canvasImageDataData[2], 255, 'B1');
assert.equal(canvasImageDataData[3], 0, 'A1');
assert.equal(canvasImageDataData[4], 255, 'R2');
assert.equal(canvasImageDataData[5], 255, 'G2');
assert.equal(canvasImageDataData[6], 255, 'B2');
assert.equal(canvasImageDataData[7], 255, 'A2');
beforeEach(function () {
this.canvasImageDataData = [255, 255, 255, 128, 255, 255, 255, 128];
});

it('storedPixelDataToCanvasImageData minPixel < 0', function () {
// Arrange
const lut = [0, 255];
const canvasImageDataData = [255, 255, 255, 128, 255, 255, 255, 128];
const image = {
minPixelValue: -1,
maxPixelValue: 0,
width: 1,
height: 2,
getPixelData () {
return new Int16Array([-1, 0]);
},
stats: {}
};
describe('Uint16Array', function () {
before(function () {
this.image.getPixelData = function () {
return new Uint16Array([0, 1]);
};
});

it('storedPixelDataToCanvasImageData minPixel = 0', function () {
this.image.minPixelValue = 0;

// Act
storedPixelDataToCanvasImageData(this.image, this.lut, this.canvasImageDataData);

this.canvasImageDataData.should.be.deep.equal([255, 255, 255, 0, 255, 255, 255, 255]);
});

it('storedPixelDataToCanvasImageData minPixel > 0', function () {
this.image.minPixelValue = 1;
this.image.getPixelData = function () {
return new Uint16Array([1, 1]);
};

// Act
storedPixelDataToCanvasImageData(this.image, this.lut, this.canvasImageDataData);

// Act
storedPixelDataToCanvasImageData(image, lut, canvasImageDataData);

// Assert
assert.equal(canvasImageDataData[0], 255, 'R1');
assert.equal(canvasImageDataData[1], 255, 'G1');
assert.equal(canvasImageDataData[2], 255, 'B1');
assert.equal(canvasImageDataData[3], 0, 'A1');
assert.equal(canvasImageDataData[4], 255, 'R2');
assert.equal(canvasImageDataData[5], 255, 'G2');
assert.equal(canvasImageDataData[6], 255, 'B2');
assert.equal(canvasImageDataData[7], 255, 'A2');
this.canvasImageDataData.should.be.deep.equal([255, 255, 255, 255, 255, 255, 255, 255]);
});
});

it('storedPixelDataToCanvasImageData minPixel > 0', function () {
// Arrange
const lut = [];

lut[1] = 0;
lut[2] = 255;
const canvasImageDataData = [255, 255, 255, 128, 255, 255, 255, 128];
const image = {
minPixelValue: 1,
maxPixelValue: 2,
width: 1,
height: 2,
getPixelData () {
return new Uint16Array([1, 2]);
},
stats: {}
};
describe('int16Array', function () {
before(function () {
// Arrange
this.lut = [0, 255];
this.image = {
minPixelValue: -1,
maxPixelValue: 0,
width: 1,
height: 2,
getPixelData () {
return new Int16Array([-1, 0]);
},
stats: {}
};
});

beforeEach(function () {
this.canvasImageDataData = [255, 255, 255, 128, 255, 255, 255, 128];
});

it('storedPixelDataToCanvasImageData minPixel < 0', function () {
// Act
storedPixelDataToCanvasImageData(this.image, this.lut, this.canvasImageDataData);

this.canvasImageDataData.should.be.deep.equal([255, 255, 255, 0, 255, 255, 255, 255]);
});

it('storedPixelDataToCanvasImageData minPixel > 0', function () {
this.image.minPixelValue = 1;
this.image.getPixelData = function () {
return new Int16Array([1, 0]);
};

// Act
storedPixelDataToCanvasImageData(this.image, this.lut, this.canvasImageDataData);

this.canvasImageDataData.should.be.deep.equal([255, 255, 255, 255, 255, 255, 255, 0]);
});
});

describe('regular Array', function () {
it('storedPixelDataToCanvasImageData minPixel < 0', function () {
this.image.minPixelValue = -1;
this.image.maxPixelValue = 0;
this.image.getPixelData = function () {
return [-1, 0];
};

storedPixelDataToCanvasImageData(this.image, this.lut, this.canvasImageDataData);

// Act
storedPixelDataToCanvasImageData(image, lut, canvasImageDataData);

// Assert
assert.equal(canvasImageDataData[0], 255, 'R1');
assert.equal(canvasImageDataData[1], 255, 'G1');
assert.equal(canvasImageDataData[2], 255, 'B1');
assert.equal(canvasImageDataData[3], 0, 'A1');
assert.equal(canvasImageDataData[4], 255, 'R2');
assert.equal(canvasImageDataData[5], 255, 'G2');
assert.equal(canvasImageDataData[6], 255, 'B2');
assert.equal(canvasImageDataData[7], 255, 'A2');
this.canvasImageDataData.should.be.deep.equal([255, 255, 255, 0, 255, 255, 255, 255]);
});
});
});

0 comments on commit e00048b

Please sign in to comment.