function decodeJPEGBaseline(dataSet, frame) { ... var jpeg = new JpegImage();
var w = new Worker("jpeg_parse.js");
w.onmessage = function(event) {
jpeg = event.data; if(bitsAllocated === 8) {
return jpeg.getData(width, height); } else if(bitsAllocated === 16) { return jpeg.getData16(width, height); } }; w.postMessage( frameData );
}
importScripts('../jpx.min.js');
var ColorSpace = ...
var JPEGImage = ...
self.addEventListener('message', function(e) { var jpeg = new JpegImage(); jpeg.parse(e.data); postMessage(jpeg);}, false);
And the code : (obviously worker.onmessage
must be set before worker.postMessage
, I’m just keeping the process order here).
var metaData = ...
var image;
worker.postMessage( {
id: metaData.x$SOPInstanceUID$,
url: metaData.$retireveURL$,
transferSyntax: metaData.x$RransferSyntaxUID$,
imgData: {
width: metaData.x$Columns$,
height: metaData.x$Rows$,
photometricInterpretation: metaData.x$PhotometricInterpretation$,
planarConfiguration: metaData.x$PlanarConfiguration$,
pixelRepresentation: metaData.x$PixelRepresentation$,
bitsAllocated: metaData.x$BitsAllocated$,
samplesPerPixel: metaData.x$SamplesPerPixel$
}
);
Worker :
onmessage = function(e){
cornerstoneWADOImageLoader.wadors.loadImage(e.data.url, e.data.imgData, function(img){
/* img = {
imageId : ....
minPixelValue : ....
maxPixelValue : ....
pixelData: ...
color: ....
}
*/
var transferable;
if(img.pixelData instanceof ImageData)
transferable = [img.pixelData.data.buffer];
else if(img.pixelData instanceof ArrayBuffer)
transferable = [img.pixelData];
else
//typedarray
transferable = [img.pixelData.buffer];
postMessage(img, transferable);
}, e.data.transferSyntax);
};
worker.onmessage = function(e){
image = addImageData(e.data, metaData); //add rows, height, rescale slope and intercept, window width and center etc from metaData
};
--
You received this message because you are subscribed to a topic in the Google Groups "cornerstone platform" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cornerstone-platform/v5boDxIMsig/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cornerstone-plat...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cornerstone-platform/445793df-35a1-44a7-b7a3-de3f2e1bab18%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Ho just realized imgData
is undefined in my first snippet inside decodeJPEGBaseline()
. So I guess you have to pass it to the web worker along with the frameData.
Also I forgot to tell you but there is a lot of broken code on the cornerstoneWADOImageLoader file I attached. For example I changed the signature of ```createImageObject()```` function and I found at least 4 calls to it using the old signature.
And even if it still has “ImageLoader” on the name, I don’t use the ImageLoader feature of cornerstone so this is probably broken too.
Really you should just get inspiration from this code it’s far from being stable and usable.
function decodeJPEGBaseline(dataSet, frame)
{
//frameData gets its value here
var jpeg = new JpegImage();
jpeg.parse(frameData); //This function takes alot of time
if(bitsAllocated === 8) {
return jpeg.getData(width, height); // I could place deferred/promise here but wouldn't that still make the browser freeze?
}
else if(bitsAllocated === 16) {
return jpeg.getData16(width, height);
}
}
var config = { | |
maxWebWorkers: 1, | |
webWorkerPath : '../../dist/cornerstoneWADOImageLoaderWebWorker.js', | |
codecsPath: '../dist/cornerstoneWADOImageLoaderCodecs.js' | |
}; |
--
You received this message because you are subscribed to the Google Groups "cornerstone platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cornerstone-plat...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cornerstone-platform/53776991-9a9a-40e2-8d01-9627f30bc7a5%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to cornerstone-platform+unsub...@googlegroups.com.
Firstly, I tried to put the cornerstone.loadImage("wadourl:" + url) .then(function(image) {...}) in the webworker directly. That didn't work as it depends on jquery, and jquery and webworkers don't go together. So, I created a "fake DOM" that allows jquery code to be used in webworkers. That allowed the image to download but then got into other problems.
However, it's not clear what cornerstone method is for only downloading the image, and then use a different method to do the decoding.