Skip to content

Commit 07a561d

Browse files
author
hackermd
committed
Fix bug related to pixel decoding
1 parent a4792ce commit 07a561d

File tree

3 files changed

+46
-12
lines changed

3 files changed

+46
-12
lines changed

build/dicom-microscopy-viewer.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49630,6 +49630,20 @@
4963049630
'1.2.840.10008.1.2.4.80': 'x-jls',
4963149631
'1.2.840.10008.1.2.4.90': 'jp2'
4963249632
};
49633+
49634+
function base64Encode(data){
49635+
const uint8Array = new Uint8Array(data);
49636+
const chunkSize = 0x8000;
49637+
const strArray = [];
49638+
for (let i=0; i < uint8Array.length; i+=chunkSize) {
49639+
let str = String.fromCharCode.apply(
49640+
null, uint8Array.subarray(i, i + chunkSize)
49641+
);
49642+
strArray.push(str);
49643+
}
49644+
return btoa(strArray.join(''));
49645+
}
49646+
4963349647
function tileLoadFunction(tile, src) {
4963449648
if (src !== null) {
4963549649
let studyInstanceUID = DICOMwebClient.utils.getStudyInstanceUIDFromUri(src);
@@ -49648,9 +49662,8 @@
4964849662
imageSubtype
4964949663
};
4965049664
client.retrieveInstanceFrames(retrieveOptions).then((frames) => {
49651-
let pixels = frames[0];
4965249665
// Encode pixel data as base64 string
49653-
const encodedPixels = btoa(String.fromCharCode(...new Uint8Array(pixels)));
49666+
const encodedPixels = base64Encode(frames[0]);
4965449667
// Add pixel data to image
4965549668
tile.getImage().src = "data:image/" + imageSubtype + ";base64," + encodedPixels;
4965649669

@@ -49814,7 +49827,7 @@
4981449827
loadTilesWhileInteracting: true,
4981549828
logo: false
4981649829
});
49817-
this.map.getView().fit(extent);
49830+
this.map.getView().fit(extent, this.map.getSize());
4981849831
return(this.map);
4981949832
});
4982049833
return(mapPromise);

src/api.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import WebGLMap from 'ol/WebGLMap';
2+
import Map from 'ol/Map';
23
import View from 'ol/View';
34
import TileLayer from 'ol/layer/Tile';
45
import XYZ from 'ol/source/XYZ';
@@ -214,6 +215,20 @@ class DICOMMicroscopyViewer {
214215
'1.2.840.10008.1.2.4.80': 'x-jls',
215216
'1.2.840.10008.1.2.4.90': 'jp2'
216217
}
218+
219+
function base64Encode(data){
220+
const uint8Array = new Uint8Array(data);
221+
const chunkSize = 0x8000;
222+
const strArray = [];
223+
for (let i=0; i < uint8Array.length; i+=chunkSize) {
224+
let str = String.fromCharCode.apply(
225+
null, uint8Array.subarray(i, i + chunkSize)
226+
);
227+
strArray.push(str);
228+
}
229+
return btoa(strArray.join(''));
230+
}
231+
217232
function tileLoadFunction(tile, src) {
218233
if (src !== null) {
219234
let studyInstanceUID = DICOMwebClient.utils.getStudyInstanceUIDFromUri(src);
@@ -232,9 +247,8 @@ class DICOMMicroscopyViewer {
232247
imageSubtype
233248
};
234249
client.retrieveInstanceFrames(retrieveOptions).then((frames) => {
235-
let pixels = frames[0];
236250
// Encode pixel data as base64 string
237-
const encodedPixels = btoa(String.fromCharCode(...new Uint8Array(pixels)));
251+
const encodedPixels = base64Encode(frames[0]);
238252
// Add pixel data to image
239253
tile.getImage().src = "data:image/" + imageSubtype + ";base64," + encodedPixels;
240254

@@ -398,7 +412,7 @@ class DICOMMicroscopyViewer {
398412
loadTilesWhileInteracting: true,
399413
logo: false
400414
});
401-
this.map.getView().fit(extent);
415+
this.map.getView().fit(extent, this.map.getSize());
402416
return(this.map);
403417
});
404418
return(mapPromise);

test/test.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,29 @@ const chai = require('chai');
22
chai.should();
33

44
const dicomMicroscopyViewer = require('../build/dicom-microscopy-viewer.js');
5-
const viewer = new dicomMicroscopyViewer.api.DICOMMicroscopyViewer({
6-
client: 'foo',
7-
studyInstanceUID: '1.2.3.4',
8-
seriesInstanceUID: '1.2.3.5'
9-
});
10-
describe('viewer', function() {
5+
6+
describe('dicomMicroscopyViewer.api.DICOMMicroscopyViewer', function() {
7+
8+
const viewer = new dicomMicroscopyViewer.api.DICOMMicroscopyViewer({
9+
client: 'foo',
10+
studyInstanceUID: '1.2.3.4',
11+
seriesInstanceUID: '1.2.3.5'
12+
});
13+
1114
it('should have property "map"', function() {
1215
viewer.should.have.property('map').equal(null);
1316
});
17+
1418
it('should have property "client"', function() {
1519
viewer.should.have.property('client').equal('foo');
1620
});
21+
1722
it('should have property "studyInstanceUID"', function() {
1823
viewer.should.have.property('studyInstanceUID').equal('1.2.3.4');
1924
});
25+
2026
it('should have property "seriesInstanceUID"', function() {
2127
viewer.should.have.property('seriesInstanceUID').equal('1.2.3.5');
2228
});
29+
2330
});

0 commit comments

Comments
 (0)