MCPcopy
hub / github.com/processing/p5.js / applyFilter

Method applyFilter

src/image/filterRenderer2D.js:447–494  ·  view source on GitHub ↗

* Applies the current filter operation. If the filter requires multiple passes (e.g. blur), * it handles those internally. Make sure setOperation() has been called before applyFilter().

()

Source from the content-addressed store, hash-verified

445 * it handles those internally. Make sure setOperation() has been called before applyFilter().
446 */
447 applyFilter() {
448 if (!this._shader) {
449 console.error('Cannot apply filter: shader not initialized.');
450 return;
451 }
452 this.parentRenderer.push();
453 this.parentRenderer.resetMatrix();
454 // For blur, we typically do two passes: one horizontal, one vertical.
455 if (this.operation === constants.BLUR && !this.customShader) {
456 // Horizontal pass
457 this._shader.setUniform('direction', [1, 0]);
458 this._renderPass();
459
460 // Draw the result onto itself
461 this.parentRenderer.clear();
462 this.parentRenderer.drawingContext.drawImage(
463 this.canvas,
464 0, 0,
465 this.parentRenderer.width, this.parentRenderer.height
466 );
467
468 // Vertical pass
469 this._shader.setUniform('direction', [0, 1]);
470 this._renderPass();
471
472 this.parentRenderer.clear();
473 this.parentRenderer.drawingContext.drawImage(
474 this.canvas,
475 0, 0,
476 this.parentRenderer.width, this.parentRenderer.height
477 );
478 } else {
479 // Single-pass filters
480
481 this._renderPass();
482 this.parentRenderer.clear();
483 // con
484 this.parentRenderer.blendMode(constants.BLEND);
485
486
487 this.parentRenderer.drawingContext.drawImage(
488 this.canvas,
489 0, 0,
490 this.parentRenderer.width, this.parentRenderer.height
491 );
492 }
493 this.parentRenderer.pop();
494 }
495}
496
497export default FilterRenderer2D;

Callers 1

pixelsFunction · 0.80

Calls 7

_renderPassMethod · 0.95
setUniformMethod · 0.80
pushMethod · 0.45
resetMatrixMethod · 0.45
clearMethod · 0.45
blendModeMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected