MCPcopy Create free account
hub / github.com/corbanbrook/dsp.js / getCanvasData

Function getCanvasData

examples/js/processing.js:8458–8479  ·  view source on GitHub ↗
(obj, w, h)

Source from the content-addressed store, hash-verified

8456
8457 var canvasDataCache = [undef, undef, undef]; // we need three for now
8458 function getCanvasData(obj, w, h) {
8459 var canvasData = canvasDataCache.shift();
8460
8461 if(canvasData === undef) {
8462 canvasData = {};
8463 canvasData.canvas = document.createElement("canvas");
8464 canvasData.context = canvasData.canvas.getContext('2d');
8465 }
8466 canvasDataCache.push(canvasData);
8467 var canvas = canvasData.canvas, context = canvasData.context,
8468 width = w || obj.width, height = h || obj.height;
8469 canvas.width = width; canvas.height = height;
8470 if(!obj) {
8471 context.clearRect(0, 0, width, height);
8472 } else if("data" in obj) { // ImageData
8473 context.putImageData(obj, 0, 0);
8474 } else {
8475 context.clearRect(0, 0, width, height);
8476 context.drawImage(obj, 0, 0, width, height);
8477 }
8478 return canvasData;
8479 }
8480
8481 var PImage = function PImage(aWidth, aHeight, aFormat) {
8482 this.get = function(x, y, w, h) {

Callers 2

PImageFunction · 0.85
processing.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected