(p5Image)
| 1000 | */ |
| 1001 | // TODO: - Accept an array of alpha values. |
| 1002 | mask(p5Image) { |
| 1003 | if (p5Image === undefined) { |
| 1004 | p5Image = this; |
| 1005 | } |
| 1006 | const currBlend = this.drawingContext.globalCompositeOperation; |
| 1007 | |
| 1008 | let imgScaleFactor = this._pixelDensity; |
| 1009 | let maskScaleFactor = 1; |
| 1010 | if (p5Image instanceof Renderer) { |
| 1011 | maskScaleFactor = p5Image._pInst._renderer._pixelDensity; |
| 1012 | } |
| 1013 | |
| 1014 | const copyArgs = [ |
| 1015 | p5Image, |
| 1016 | 0, |
| 1017 | 0, |
| 1018 | maskScaleFactor * p5Image.width, |
| 1019 | maskScaleFactor * p5Image.height, |
| 1020 | 0, |
| 1021 | 0, |
| 1022 | imgScaleFactor * this.width, |
| 1023 | imgScaleFactor * this.height |
| 1024 | ]; |
| 1025 | |
| 1026 | this.drawingContext.globalCompositeOperation = 'destination-in'; |
| 1027 | if (this.gifProperties) { |
| 1028 | for (let i = 0; i < this.gifProperties.frames.length; i++) { |
| 1029 | this.drawingContext.putImageData( |
| 1030 | this.gifProperties.frames[i].image, |
| 1031 | 0, |
| 1032 | 0 |
| 1033 | ); |
| 1034 | this.copy(...copyArgs); |
| 1035 | this.gifProperties.frames[i].image = this.drawingContext.getImageData( |
| 1036 | 0, |
| 1037 | 0, |
| 1038 | imgScaleFactor * this.width, |
| 1039 | imgScaleFactor * this.height |
| 1040 | ); |
| 1041 | } |
| 1042 | this.drawingContext.putImageData( |
| 1043 | this.gifProperties.frames[this.gifProperties.displayIndex].image, |
| 1044 | 0, |
| 1045 | 0 |
| 1046 | ); |
| 1047 | } else { |
| 1048 | this.copy(...copyArgs); |
| 1049 | } |
| 1050 | this.drawingContext.globalCompositeOperation = currBlend; |
| 1051 | this.setModified(true); |
| 1052 | } |
| 1053 | |
| 1054 | /** |
| 1055 | * Applies an image filter to the image. |
no test coverage detected