Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (webWorkerUrl.startsWith('http')) {
return axios.get(webWorkerUrl, {
responseType: 'blob'
}).then(function (response) {
var worker = new window.Worker(URL.createObjectURL(response.data) // eslint-disable-line
);
var webworkerPromise = new WebworkerPromise(worker);
return {
webworkerPromise: webworkerPromise,
worker: worker
};
});
}
var worker = new window.Worker(webWorkerUrl);
var webworkerPromise = new WebworkerPromise(worker);
return Promise.resolve({
webworkerPromise: webworkerPromise,
worker: worker
});
};
}).then(function (response) {
var worker = new window.Worker(URL.createObjectURL(response.data) // eslint-disable-line
);
var webworkerPromise = new WebworkerPromise(worker);
return {
webworkerPromise: webworkerPromise,
worker: worker
};
});
}
var createWebworkerPromise = function createWebworkerPromise(name, existingWorker) {
if (existingWorker) {
var _webworkerPromise = new WebworkerPromise(existingWorker);
return Promise.resolve({
webworkerPromise: _webworkerPromise,
worker: existingWorker
});
}
var webWorkerUrl = "".concat(config.itkModulesPath, "/WebWorkers/").concat(name, ".worker.js");
if (webWorkerUrl.startsWith('http')) {
return axios.get(webWorkerUrl, {
responseType: 'blob'
}).then(function (response) {
var worker = new window.Worker(URL.createObjectURL(response.data) // eslint-disable-line
);
var webworkerPromise = new WebworkerPromise(worker);
reformattedGradients
);
publicAPI.deactivate();
return true;
};
}
const maxNumberOfWorkers = 4;
const depthStride = Math.ceil(depth / maxNumberOfWorkers);
const workerPromises = [];
const workers = [];
let depthIndex = 0;
while (depthIndex < depth - 1) {
const worker = new ComputeGradientsWorker();
const workerPromise = new WebworkerPromise(worker);
const depthStart = depthIndex;
let depthEnd = depthIndex + depthStride; // no -1 to include one more slice to compute gradient
depthEnd = Math.min(depthEnd, depth - 1);
const subData = new data.constructor(
data.slice(depthStart * width * height, (depthEnd + 1) * width * height) // +1 to include data from slice at depthEnd
);
workers.push(worker);
workerPromises.push(
workerPromise.postMessage(
{
width,
height,
depth,
spacing,
data: subData,
haveWebgl2,
thresh[ii] -= delta[ii];
if (thresh[ii] < 0) {
thresh[ii] = step;
pt[ii] += inc[ii];
}
}
}
}
}
}
}
globals.prevPoint = point;
}
registerWebworker()
.operation('start', ({ bufferType, dimensions }) => {
const bufferSize = dimensions[0] * dimensions[1] * dimensions[2];
/* eslint-disable-next-line */
globals.buffer = new self[bufferType](bufferSize);
globals.dimensions = dimensions;
globals.prevPoint = null;
})
.operation('paint', handlePaint)
.operation(
'end',
() =>
new registerWebworker.TransferableResponse(globals.buffer.buffer, [
globals.buffer.buffer,
])
);
}
let ioModule = null
if (io in ioToModule) {
ioModule = ioToModule[io]
} else {
ioToModule[io] = loadEmscriptenModule(input.config.itkModulesPath, 'ImageIOs', io)
ioModule = ioToModule[io]
}
const filePath = mountpoint + '/' + input.name
ioModule.mkdirs(mountpoint)
writeImageEmscriptenFSFile(ioModule, input.useCompression, input.image, filePath)
const writtenFile = ioModule.readFile(filePath, { encoding: 'binary' })
return new registerWebworker.TransferableResponse(writtenFile.buffer, [writtenFile.buffer])
}
if (!seriesReaderModule) {
seriesReaderModule = loadEmscriptenModule(input.config.itkModulesPath, 'ImageIOs', seriesReader)
}
const blobs = input.fileDescriptions.map((fileDescription) => {
const blob = new Blob([fileDescription.data])
return { name: fileDescription.name, data: blob }
})
const mountpoint = '/work'
seriesReaderModule.mountBlobs(mountpoint, blobs)
const filePath = mountpoint + '/' + input.fileDescriptions[0].name
const image = readImageEmscriptenFSDICOMFileSeries(seriesReaderModule,
mountpoint, filePath)
seriesReaderModule.unmountBlobs(mountpoint)
return new registerWebworker.TransferableResponse(image, [image.data.buffer])
}
let ioModule = null
if (io in ioToModule) {
ioModule = ioToModule[io]
} else {
ioToModule[io] = loadEmscriptenModule(input.config.itkModulesPath, 'ImageIOs', io)
ioModule = ioToModule[io]
}
const blob = new Blob([input.data])
const blobs = [{ name: input.name, data: blob }]
ioModule.mountBlobs(mountpoint, blobs)
const filePath = mountpoint + '/' + input.name
const image = readImageEmscriptenFSFile(ioModule, filePath)
ioModule.unmountBlobs(mountpoint)
return new registerWebworker.TransferableResponse(image, [image.data.buffer])
}
let ioModule = null
if (io in ioToModule) {
ioModule = ioToModule[io]
} else {
ioToModule[io] = loadEmscriptenModule(input.config.itkModulesPath, 'MeshIOs', io)
ioModule = ioToModule[io]
}
const filePath = mountpoint + '/' + input.name
ioModule.mkdirs(mountpoint)
writeMeshEmscriptenFSFile(ioModule,
{ useCompression: input.useCompression, binaryFileType: input.binaryFileType },
input.mesh, filePath)
const writtenFile = ioModule.readFile(filePath, { encoding: 'binary' })
return new registerWebworker.TransferableResponse(writtenFile.buffer, [writtenFile.buffer])
}
ioModule.unmountBlobs(mountpoint)
const transferables = []
if (mesh.points) {
transferables.push(mesh.points.buffer)
}
if (mesh.pointData) {
transferables.push(mesh.pointData.buffer)
}
if (mesh.cells) {
transferables.push(mesh.cells.buffer)
}
if (mesh.cellData) {
transferables.push(mesh.cellData.buffer)
}
return new registerWebworker.TransferableResponse(mesh, transferables)
}