Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pixelworks

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pixelworks - npm Package Compare versions

Comparing version 0.5.0 to 0.6.0

.eslintrc

17

examples/operations.js

@@ -0,1 +1,3 @@

/* global pixelworks */
var luminance = function(pixels, data) {

@@ -7,3 +9,4 @@ var pixel = pixels[0];

pixel[2] = l;
}
return pixels;
};

@@ -21,3 +24,4 @@ var color = function(pixels, data) {

}
}
return pixels;
};

@@ -34,3 +38,3 @@ var inputContext = document.getElementById('input').getContext('2d');

var data = {
threshold: threshold.value,
threshold: threshold.value
};

@@ -41,6 +45,7 @@

var input = inputContext.getImageData(0, 0, canvas.width, canvas.height);
worker.process([input], data).then(function(output) {
worker.process([input], data, function(err, output) {
if (err) {
throw err;
}
outputContext.putImageData(output, 0, 0);
}, function(err) {
throw err;
});

@@ -47,0 +52,0 @@ }

@@ -5,11 +5,17 @@ function createMinion(operations) {

return function(data) {
/* eslint-disable dot-notation */
// bracket notation for minification support
var buffers = data['buffers'];
var meta = data['meta'];
var imageOps = data['imageOps'];
var width = data['width'];
var height = data['height'];
/* eslint-enable dot-notation */
var numBuffers = buffers.length;
var numBytes = buffers[0].byteLength;
var output, b, i, j, k;
if (!pixels) {
arrays = new Array(numBuffers);
pixels = new Array(numBuffers);
for (var b = 0; b < numBuffers; ++b) {
for (b = 0; b < numBuffers; ++b) {
arrays[b] = new Uint8ClampedArray(buffers[b]);

@@ -19,22 +25,33 @@ pixels[b] = [0, 0, 0, 0];

}
var data = new Uint8ClampedArray(numBytes);
for (var i = 0; i < numBytes; i += 4) {
for (var j = 0; j < numBuffers; ++j) {
var array = arrays[j];
pixels[j][0] = array[i];
pixels[j][1] = array[i + 1];
pixels[j][2] = array[i + 2];
pixels[j][3] = array[i + 3];
if (imageOps) {
var images = new Array(numBuffers);
for (b = 0; b < numBuffers; ++b) {
images[b] = new ImageData(arrays[b], width, height);
}
for (var k = 0; k < numOps; ++k) {
operations[k](pixels, meta);
for (k = 0; k < numOps; ++k) {
images = operations[k](images, meta);
}
var pixel = pixels[0];
data[i] = pixel[0];
data[i + 1] = pixel[1];
data[i + 2] = pixel[2];
data[i + 3] = pixel[3];
output = images[0].data;
} else {
output = new Uint8ClampedArray(numBytes);
for (i = 0; i < numBytes; i += 4) {
for (j = 0; j < numBuffers; ++j) {
var array = arrays[j];
pixels[j][0] = array[i];
pixels[j][1] = array[i + 1];
pixels[j][2] = array[i + 2];
pixels[j][3] = array[i + 3];
}
for (k = 0; k < numOps; ++k) {
pixels = operations[k](pixels, meta);
}
var pixel = pixels[0];
output[i] = pixel[0];
output[i + 1] = pixel[1];
output[i + 2] = pixel[2];
output[i + 3] = pixel[3];
}
}
return data.buffer;
}
return output.buffer;
};
}

@@ -57,3 +74,4 @@

function Processor(config) {
var threads = config.threads || 1;
this._imageOps = !!config.imageOps;
var threads = this._imageOps ? 1 : config.threads || 1;
var workers = [];

@@ -73,13 +91,9 @@ for (var i = 0; i < threads; ++i) {

Processor.prototype.process = function(inputs, meta) {
var promise = new Promise(function(resolve, reject) {
this._enqueue({
resolve: resolve,
reject: reject,
inputs: inputs,
meta: meta
});
}.bind(this));
Processor.prototype.process = function(inputs, meta, callback) {
this._enqueue({
inputs: inputs,
meta: meta,
callback: callback
});
this._dispatch();
return promise;
};

@@ -90,3 +104,3 @@

while (this._queue.length > this._maxQueueLength) {
this._queue.shift().resolve(null);
this._queue.shift().callback(null, null);
}

@@ -98,2 +112,4 @@ };

var job = this._job = this._queue.shift();
var width = job.inputs[0].width;
var height = job.inputs[0].height;
var buffers = job.inputs.map(function(input) {

@@ -107,3 +123,6 @@ return input.data.buffer;

'buffers': buffers,
'meta': job.meta
'meta': job.meta,
'imageOps': this._imageOps,
'width': width,
'height': height
}, buffers);

@@ -115,8 +134,12 @@ } else {

var offset = i * segmentLength;
var slices = buffers.map(function(buffer) {
return buffer.slice(offset, offset + segmentLength);
});
var slices = [];
for (var j = 0, jj = buffers.length; j < jj; ++j) {
slices.push(buffers[i].slice(offset, offset + segmentLength));
}
this._workers[i].postMessage({
'buffers': slices,
'meta': job.meta
'meta': job.meta,
'imageOps': this._imageOps,
'width': width,
'height': height
}, slices);

@@ -154,3 +177,4 @@ }

this._bufferLookup = {};
job.resolve(new ImageData(data, job.inputs[0].width, job.inputs[0].height));
job.callback(null,
new ImageData(data, job.inputs[0].width, job.inputs[0].height));
this._dispatch();

@@ -157,0 +181,0 @@ };

{
"name": "pixelworks",
"version": "0.5.0",
"version": "0.6.0",
"description": "Utilities for working with ImageData in Workers",
"main": "lib/index.js",
"scripts": {
"test": "eslint lib examples",
"start": "webpack"

@@ -18,4 +19,6 @@ },

"devDependencies": {
"eslint": "^0.24.0",
"eslint-config-tschaub": "^1.0.0",
"webpack": "^1.9.12"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc