Skip to content

Commit

Permalink
2.10.1
Browse files Browse the repository at this point in the history
  • Loading branch information
quinton-ashley committed Nov 22, 2024
1 parent b2aa9ed commit ec62afe
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "q5",
"version": "2.10.0",
"version": "2.10.1",
"description": "A sequel to p5.js that's optimized for interactive art",
"author": "quinton-ashley",
"contributors": [
Expand Down
16 changes: 9 additions & 7 deletions q5.js
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,9 @@ Q5.renderers.q2d.image = ($, q) => {
if (!sh) {
sh = drawable.height || drawable.videoHeight;
} else sh *= pd;
$.ctx.drawImage(drawable, sx * pd, sy * pd, sw, sh, dx, dy, dw, dh);
sx *= pd;
sy *= pd;
$.ctx.drawImage(drawable, sx, sy, sw, sh, dx, dy, dw, dh);

if ($._tint) {
$.ctx.save();
Expand All @@ -1368,21 +1370,21 @@ Q5.renderers.q2d.image = ($, q) => {
$.ctx.shadowBlur = 0;

if (img.canvas.alpha) {
img.tintImg ??= $.createImage(dw, dh);
if (img.tintImg.width != dw || img.tintImg.height != dh) {
img.tintImg.resize(dw, dh);
img.tintImg ??= $.createImage(img.w, img.h, { pixelDensity: pd });
if (img.tintImg.width != img.width || img.tintImg.height != img.height) {
img.tintImg.resize(img.w, img.h);
}

let tnt = img.tintImg.ctx;
tnt.globalCompositeOperation = 'copy';
tnt.fillStyle = $._tint;
tnt.fillRect(0, 0, dw, dh);
tnt.fillRect(0, 0, img.width, img.height);

tnt.globalCompositeOperation = 'destination-in';
tnt.drawImage(drawable, 0, 0, dw, dh);
tnt.drawImage(drawable, 0, 0, img.width, img.height);

$.ctx.globalCompositeOperation = 'multiply';
$.ctx.drawImage(img.tintImg.canvas, 0, 0, dw, dh, dx, dy, dw, dh);
$.ctx.drawImage(img.tintImg.canvas, sx, sy, sw, sh, dx, dy, dw, dh);
} else {
$.ctx.globalCompositeOperation = 'multiply';
$.ctx.fillStyle = $._tint;
Expand Down
2 changes: 1 addition & 1 deletion q5.min.js

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions src/q5-2d-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ Q5.renderers.q2d.image = ($, q) => {
if (!sh) {
sh = drawable.height || drawable.videoHeight;
} else sh *= pd;
$.ctx.drawImage(drawable, sx * pd, sy * pd, sw, sh, dx, dy, dw, dh);
sx *= pd;
sy *= pd;
$.ctx.drawImage(drawable, sx, sy, sw, sh, dx, dy, dw, dh);

if ($._tint) {
$.ctx.save();
Expand All @@ -124,21 +126,21 @@ Q5.renderers.q2d.image = ($, q) => {
$.ctx.shadowBlur = 0;

if (img.canvas.alpha) {
img.tintImg ??= $.createImage(dw, dh);
if (img.tintImg.width != dw || img.tintImg.height != dh) {
img.tintImg.resize(dw, dh);
img.tintImg ??= $.createImage(img.w, img.h, { pixelDensity: pd });
if (img.tintImg.width != img.width || img.tintImg.height != img.height) {
img.tintImg.resize(img.w, img.h);
}

let tnt = img.tintImg.ctx;
tnt.globalCompositeOperation = 'copy';
tnt.fillStyle = $._tint;
tnt.fillRect(0, 0, dw, dh);
tnt.fillRect(0, 0, img.width, img.height);

tnt.globalCompositeOperation = 'destination-in';
tnt.drawImage(drawable, 0, 0, dw, dh);
tnt.drawImage(drawable, 0, 0, img.width, img.height);

$.ctx.globalCompositeOperation = 'multiply';
$.ctx.drawImage(img.tintImg.canvas, 0, 0, dw, dh, dx, dy, dw, dh);
$.ctx.drawImage(img.tintImg.canvas, sx, sy, sw, sh, dx, dy, dw, dh);
} else {
$.ctx.globalCompositeOperation = 'multiply';
$.ctx.fillStyle = $._tint;
Expand Down

0 comments on commit ec62afe

Please sign in to comment.