MCPcopy Index your code
hub / github.com/clips/pattern / composite

Function composite

pattern/canvas.js:3170–3196  ·  view source on GitHub ↗
(img1, img2, dx, dy, operator)

Source from the content-addressed store, hash-verified

3168// Based on: R. Dura, 2009, http://mouaif.wordpress.com/2009/01/05/photoshop-math-with-glsl-shaders/
3169
3170function composite(img1, img2, dx, dy, operator) {
3171 /* Returns a new Image by mixing img1 (the destination) with blend image img2 (the source).
3172 * The given operator is a function(pixel1, pixel2) that returns a new pixel (RGBA-array).
3173 * This is used to implement alpha compositing and blend modes.
3174 * - dx: horizontal offset (in pixels) of the blend layer.
3175 * - dy: vertical offset (in pixels) of the blend layer.
3176 */
3177 //var t = new Date().getTime();
3178 dx = dx || 0;
3179 dy = dy || 0;
3180 var pixels1 = new Pixels(img1);
3181 var pixels2 = new Pixels(img2);
3182 for (var j=0; j < pixels1.height; j++) {
3183 for (var i=0; i < pixels1.width; i++) {
3184 if (0 <= i-dx && i-dx < pixels2.width) {
3185 if (0 <= j-dy && j-dy < pixels2.height) {
3186 var p1 = pixels1.get(i + j * pixels1.width);
3187 var p2 = pixels2.get((i-dx) + (j-dy) * pixels2.width);
3188 pixels1.set(i + j * pixels1.width, operator(p1, p2));
3189 }
3190 }
3191 }
3192 }
3193 pixels1.update();
3194 //console.log(new Date().getTime() - t);
3195 return pixels1.image();
3196}
3197
3198function transparent(img, alpha) {
3199 /* Returns a transparent version of the image.

Callers 2

maskFunction · 0.85
blendFunction · 0.85

Calls 2

getMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…