Skip to content

Commit 68a00bb

Browse files
authored
Merge branch 'main' into label-update
2 parents 68d3c64 + 919cffa commit 68a00bb

File tree

15 files changed

+306
-76
lines changed

15 files changed

+306
-76
lines changed

.all-contributorsrc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3167,6 +3167,42 @@
31673167
"contributions": [
31683168
"translation"
31693169
]
3170+
},
3171+
{
3172+
"login": "IkeB108",
3173+
"name": "Ike Bischof",
3174+
"avatar_url": "https://avatars.githubusercontent.com/u/56776763?v=4",
3175+
"profile": "https://ikebot108.weebly.com/",
3176+
"contributions": [
3177+
"code"
3178+
]
3179+
},
3180+
{
3181+
"login": "ongzzzzzz",
3182+
"name": "Ong Zhi Zheng",
3183+
"avatar_url": "https://avatars.githubusercontent.com/u/47311100?v=4",
3184+
"profile": "https://ongzz.ml",
3185+
"contributions": [
3186+
"plugin"
3187+
]
3188+
},
3189+
{
3190+
"login": "bsubbaraman",
3191+
"name": "bsubbaraman",
3192+
"avatar_url": "https://avatars.githubusercontent.com/u/11969085?v=4",
3193+
"profile": "https://github.com/bsubbaraman",
3194+
"contributions": [
3195+
"plugin"
3196+
]
3197+
},
3198+
{
3199+
"login": "jdeboi",
3200+
"name": "Jenna deBoisblanc",
3201+
"avatar_url": "https://avatars.githubusercontent.com/u/1548679?v=4",
3202+
"profile": "http://jdeboi.com",
3203+
"contributions": [
3204+
"plugin"
3205+
]
31703206
}
31713207
],
31723208
"repoType": "github",

.github/labeler.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
"Area:Accessibility":
2-
- '\[X\] Accessibility'
2+
- '\[[xX]\]\s*Accessibility'
33
"Area:Color":
4-
- '\[X\] Color'
4+
- '\[[xX]\]\s*Color'
55
"Area:Core":
6-
- '\[X\] Core'
6+
- '\[[xX]\]\s*Core'
77
"Area:Data":
8-
- '\[X\] Data'
8+
- '\[[xX]\]\s*Data'
99
"Area:DOM":
10-
- '\[X\] DOM'
10+
- '\[[xX]\]\s*DOM'
1111
"Area:Events":
12-
- '\[X\] Events'
12+
- '\[[xX]\]\s*Events'
1313
"Area:Image":
14-
- '\[X\] Image'
14+
- '\[[xX]\]\s*Image'
1515
"Area:IO":
16-
- '\[X\] IO'
16+
- '\[[xX]\]\s*IO'
1717
"Area:Math":
18-
- '\[X\] Math'
18+
- '\[[xX]\]\s*Math'
1919
"Area:Typography":
20-
- '\[X\] Typography'
20+
- '\[[xX]\]\s*Typography'
2121
"Area:Utilities":
22-
- '\[X\] Utilities'
22+
- '\[[xX]\]\s*Utilities'
2323
"Area:WebGL":
24-
- '\[X\] WebGL'
24+
- '\[[xX]\]\s*WebGL'
2525
"Build Process":
26-
- '\[X\] Build Process'
26+
- '\[[xX]\]\s*Build Process'
2727
"Unit Testing":
28-
- '\[X\] Unit Testing'
28+
- '\[[xX]\]\s*Unit Testing'
2929
"Localization":
3030
- '\[X\] Internalization'
3131
"Friendly Errors":
32-
- '\[X\] Friendly Errors'
32+
- '\[[xX]\]\s*Friendly Errors'

.github/workflows/labeler.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ name: "Issue Labeler"
22
on:
33
issues:
44
types: [opened, edited]
5-
5+
permissions:
6+
issues: write
67
jobs:
78
triage:
89
runs-on: ubuntu-latest

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Anyone interested can volunteer to be a steward! There are no specific requireme
7979
| [Utilities](https://github.com/processing/p5.js/tree/main/src/utilities) | [@kungfuchicken](https://github.com/kungfuchicken), [@cosmicbhejafry](https://github.com/cosmicbhejafry) |
8080
| [WebGL](https://github.com/processing/p5.js/tree/main/src/webgl) | [@stalgiag](https://github.com/stalgiag); GSoC 2022: [@aceslowman](https://github.com/aceslowman)(Contributor), [@kjhollen](https://github.com/kjhollen)(Mentor); [@ShenpaiSharma](https://github.com/ShenpaiSharma)(Contributor), [@calebfoss](https://github.com/calebfoss)(Mentor); [@davepagurek](https://github.com/davepagurek); [@jeffawang](https://github.com/jeffawang); [@AdilRabbani](https://github.com/AdilRabbani) |
8181
| Build Process/Unit Testing | [@outofambit](https://github.com/outofambit), [@kungfuchicken](https://github.com/kungfuchicken) |
82-
| Localization Tools | [@outofambit](https://github.com/outofambit), [@almchung](https://github.com/almchung) |
82+
| Internalization | [@outofambit](https://github.com/outofambit), [@almchung](https://github.com/almchung) |
8383
| Friendly Errors | [@outofambit](https://github.com/outofambit), [@almchung](https://github.com/almchung) |
8484
| [Contributor Docs](https://github.com/processing/p5.js/tree/main/contributor_docs) | [SoD 2022](https://github.com/processing/p5.js/wiki/Season-of-Docs-2022-Organization-Application---p5.js): [@limzykenneth](https://github.com/limzykenneth) |
8585

@@ -577,6 +577,12 @@ We recognize all types of contributions. This project follows the [all-contribut
577577
<td align="center"><a href="https://github.com/anniezhengg"><img src="https://avatars.githubusercontent.com/u/78184655?v=4?s=100" width="100px;" alt=""/><br /><sub><b>anniezhengg</b></sub></a><br /><a href="https://github.com/processing/p5.js/commits?author=anniezhengg" title="Code">💻</a> <a href="#design-anniezhengg" title="Design">🎨</a></td>
578578
<td align="center"><a href="https://github.com/SNP0301"><img src="https://avatars.githubusercontent.com/u/68281918?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Seung-Gi Kim(David)</b></sub></a><br /><a href="#translation-SNP0301" title="Translation">🌍</a></td>
579579
</tr>
580+
<tr>
581+
<td align="center"><a href="https://ikebot108.weebly.com/"><img src="https://avatars.githubusercontent.com/u/56776763?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ike Bischof</b></sub></a><br /><a href="https://github.com/processing/p5.js/commits?author=IkeB108" title="Code">💻</a></td>
582+
<td align="center"><a href="https://ongzz.ml"><img src="https://avatars.githubusercontent.com/u/47311100?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ong Zhi Zheng</b></sub></a><br /><a href="#plugin-ongzzzzzz" title="Plugin/utility libraries">🔌</a></td>
583+
<td align="center"><a href="https://github.com/bsubbaraman"><img src="https://avatars.githubusercontent.com/u/11969085?v=4?s=100" width="100px;" alt=""/><br /><sub><b>bsubbaraman</b></sub></a><br /><a href="#plugin-bsubbaraman" title="Plugin/utility libraries">🔌</a></td>
584+
<td align="center"><a href="http://jdeboi.com"><img src="https://avatars.githubusercontent.com/u/1548679?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jenna deBoisblanc</b></sub></a><br /><a href="#plugin-jdeboi" title="Plugin/utility libraries">🔌</a></td>
585+
</tr>
580586
</table>
581587

582588
<!-- markdownlint-restore -->

src/core/p5.Renderer2D.js

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import p5 from './main';
22
import * as constants from './constants';
3-
import filters from '../image/filters';
43

54
import './p5.Renderer';
65

@@ -162,13 +161,8 @@ p5.Renderer2D.prototype.image = function(
162161
}
163162

164163
try {
165-
if (this._tint) {
166-
if (p5.MediaElement && img instanceof p5.MediaElement) {
167-
img.loadPixels();
168-
}
169-
if (img.canvas) {
170-
cnv = this._getTintedImageCanvas(img);
171-
}
164+
if (this._tint && img.canvas) {
165+
cnv = this._getTintedImageCanvas(img);
172166
}
173167
if (!cnv) {
174168
cnv = img.canvas || img.elt;
@@ -205,25 +199,66 @@ p5.Renderer2D.prototype._getTintedImageCanvas = function(img) {
205199
if (!img.canvas) {
206200
return img;
207201
}
208-
const pixels = filters._toPixels(img.canvas);
209-
const tmpCanvas = document.createElement('canvas');
210-
tmpCanvas.width = img.canvas.width;
211-
tmpCanvas.height = img.canvas.height;
212-
const tmpCtx = tmpCanvas.getContext('2d');
213-
const id = tmpCtx.createImageData(img.canvas.width, img.canvas.height);
214-
const newPixels = id.data;
215-
for (let i = 0; i < pixels.length; i += 4) {
216-
const r = pixels[i];
217-
const g = pixels[i + 1];
218-
const b = pixels[i + 2];
219-
const a = pixels[i + 3];
220-
newPixels[i] = r * this._tint[0] / 255;
221-
newPixels[i + 1] = g * this._tint[1] / 255;
222-
newPixels[i + 2] = b * this._tint[2] / 255;
223-
newPixels[i + 3] = a * this._tint[3] / 255;
202+
203+
if (!img.tintCanvas) {
204+
// Once an image has been tinted, keep its tint canvas
205+
// around so we don't need to re-incur the cost of
206+
// creating a new one for each tint
207+
img.tintCanvas = document.createElement('canvas');
208+
}
209+
210+
// Keep the size of the tint canvas up-to-date
211+
if (img.tintCanvas.width !== img.canvas.width) {
212+
img.tintCanvas.width = img.canvas.width;
213+
}
214+
if (img.tintCanvas.height !== img.canvas.height) {
215+
img.tintCanvas.height = img.canvas.height;
224216
}
225-
tmpCtx.putImageData(id, 0, 0);
226-
return tmpCanvas;
217+
218+
// Goal: multiply the r,g,b,a values of the source by
219+
// the r,g,b,a values of the tint color
220+
const ctx = img.tintCanvas.getContext('2d');
221+
222+
ctx.save();
223+
ctx.clearRect(0, 0, img.canvas.width, img.canvas.height);
224+
225+
if (this._tint[0] < 255 || this._tint[1] < 255 || this._tint[2] < 255) {
226+
// Color tint: we need to use the multiply blend mode to change the colors.
227+
// However, the canvas implementation of this destroys the alpha channel of
228+
// the image. To accommodate, we first get a version of the image with full
229+
// opacity everywhere, tint using multiply, and then use the destination-in
230+
// blend mode to restore the alpha channel again.
231+
232+
// Start with the original image
233+
ctx.drawImage(img.canvas, 0, 0);
234+
235+
// This blend mode makes everything opaque but forces the luma to match
236+
// the original image again
237+
ctx.globalCompositeOperation = 'luminosity';
238+
ctx.drawImage(img.canvas, 0, 0);
239+
240+
// This blend mode forces the hue and chroma to match the original image.
241+
// After this we should have the original again, but with full opacity.
242+
ctx.globalCompositeOperation = 'color';
243+
ctx.drawImage(img.canvas, 0, 0);
244+
245+
// Apply color tint
246+
ctx.globalCompositeOperation = 'multiply';
247+
ctx.fillStyle = `rgb(${this._tint.slice(0, 3).join(', ')})`;
248+
ctx.fillRect(0, 0, img.canvas.width, img.canvas.height);
249+
250+
// Replace the alpha channel with the original alpha * the alpha tint
251+
ctx.globalCompositeOperation = 'destination-in';
252+
ctx.globalAlpha = this._tint[3] / 255;
253+
ctx.drawImage(img.canvas, 0, 0);
254+
} else {
255+
// If we only need to change the alpha, we can skip all the extra work!
256+
ctx.globalAlpha = this._tint[3] / 255;
257+
ctx.drawImage(img.canvas, 0, 0);
258+
}
259+
260+
ctx.restore();
261+
return img.tintCanvas;
227262
};
228263

229264
//////////////////////////////////////////////

src/dom/dom.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,8 +1993,8 @@ p5.Element.prototype.style = function(prop, val) {
19931993
) {
19941994
let styles = window.getComputedStyle(self.elt);
19951995
let styleVal = styles.getPropertyValue(prop);
1996-
let numVal = styleVal.replace(/\D+/g, '');
1997-
this[prop] = parseInt(numVal, 10);
1996+
let numVal = styleVal.replace(/[^\d.]/g, '');
1997+
this[prop] = Math.round(parseFloat(numVal, 10));
19981998
}
19991999
}
20002000
return this;

src/image/loading_displaying.js

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
import p5 from '../core/main';
9-
import Filters from './filters';
109
import canvas from '../core/helpers';
1110
import * as constants from '../core/constants';
1211
import omggif from 'omggif';
@@ -602,33 +601,8 @@ p5.prototype.noTint = function() {
602601
* @param {p5.Image} The image to be tinted
603602
* @return {canvas} The resulting tinted canvas
604603
*/
605-
p5.prototype._getTintedImageCanvas = function(img) {
606-
if (!img.canvas) {
607-
return img;
608-
}
609-
const pixels = Filters._toPixels(img.canvas);
610-
const tmpCanvas = document.createElement('canvas');
611-
tmpCanvas.width = img.canvas.width;
612-
tmpCanvas.height = img.canvas.height;
613-
const tmpCtx = tmpCanvas.getContext('2d');
614-
const id = tmpCtx.createImageData(img.canvas.width, img.canvas.height);
615-
const newPixels = id.data;
616-
617-
for (let i = 0; i < pixels.length; i += 4) {
618-
const r = pixels[i];
619-
const g = pixels[i + 1];
620-
const b = pixels[i + 2];
621-
const a = pixels[i + 3];
622-
623-
newPixels[i] = r * this._renderer._tint[0] / 255;
624-
newPixels[i + 1] = g * this._renderer._tint[1] / 255;
625-
newPixels[i + 2] = b * this._renderer._tint[2] / 255;
626-
newPixels[i + 3] = a * this._renderer._tint[3] / 255;
627-
}
628-
629-
tmpCtx.putImageData(id, 0, 0);
630-
return tmpCanvas;
631-
};
604+
p5.prototype._getTintedImageCanvas =
605+
p5.Renderer2D.prototype._getTintedImageCanvas;
632606

633607
/**
634608
* Set image mode. Modifies the location from which images are drawn by

src/math/p5.Vector.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,7 @@ p5.Vector.prototype.heading = function heading() {
14901490
*/
14911491

14921492
p5.Vector.prototype.setHeading = function setHeading(a) {
1493+
if (this.isPInst) a = this._toRadians(a);
14931494
let m = this.mag();
14941495
this.x = m * Math.cos(a);
14951496
this.y = m * Math.sin(a);

src/webgl/3d_primitives.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ p5.prototype.plane = function(width, height, detailX, detailY) {
9999
* Draw a box with given width, height and depth
100100
* @method box
101101
* @param {Number} [width] width of the box
102-
* @param {Number} [Height] height of the box
102+
* @param {Number} [height] height of the box
103103
* @param {Number} [depth] depth of the box
104104
* @param {Integer} [detailX] Optional number of triangle
105105
* subdivisions in x-dimension
80.7 KB
Loading

0 commit comments

Comments
 (0)