Skip to content

Commit

Permalink
Previous floodfill improvements broke stuff again ...
Browse files Browse the repository at this point in the history
  • Loading branch information
Bios-Marcel committed Nov 9, 2024
1 parent 705aa1a commit abda4f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 3 additions & 4 deletions internal/frontend/resources/floodfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,15 @@ function pixelCompareAndSet(i, targetcolor, fillcolor, data) {
return false;
};

function fillUint8ClampedArray(data, x, y, color, width, height) {
if (!(data instanceof Uint8ClampedArray)) throw new Error("data must be an instance of Uint8ClampedArray");
function floodfillUint8ClampedArray(data, x, y, color, width, height) {
if (isNaN(width) || width < 1) throw new Error("argument 'width' must be a positive integer");
if (isNaN(height) || height < 1) throw new Error("argument 'height' must be a positive integer");
if (isNaN(x) || x < 0) throw new Error("argument 'x' must be a positive integer");
if (isNaN(y) || y < 0) throw new Error("argument 'y' must be a positive integer");
if (width * height * 4 !== data.length) throw new Error("width and height do not fit Uint8ClampedArray dimensions");

var xi = Math.floor(x);
var yi = Math.floor(y);
const xi = Math.floor(x);
const yi = Math.floor(y);

return floodfillData(data, xi, yi, color, width, height);
};
14 changes: 11 additions & 3 deletions internal/frontend/templates/lobby.html
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,15 @@
} else if (parsed.type === "line") {
drawLine(context, parsed.data.fromX * scaleDownFactor(), parsed.data.fromY * scaleDownFactor(), parsed.data.toX * scaleDownFactor(), parsed.data.toY * scaleDownFactor(), parsed.data.color, parsed.data.lineWidth * scaleDownFactor());
} else if (parsed.type === "fill") {
floodfillContext(context, parsed.data.x * scaleDownFactor(), parsed.data.y * scaleDownFactor(), parsed.data.color);
if (floodfillUint8ClampedArray(
imageData.data,
parsed.data.x * scaleDownFactor(),
parsed.data.y * scaleDownFactor(),
parsed.data.color,
imageData.width,
imageData.height)) {
context.putImageData(imageData, 0, 0);
}
} else if (parsed.type === "clear-drawing-board") {
clear(context);
} else if (parsed.type === "next-turn") {
Expand Down Expand Up @@ -1766,7 +1774,7 @@
.forEach(drawElement => {
const drawData = drawElement.data;
if (drawElement.type === "fill") {
fillUint8ClampedArray(
floodfillUint8ClampedArray(
imageData.data,
drawData.x * scaleFactor, drawData.y * scaleFactor,
drawData.color,
Expand Down Expand Up @@ -2005,7 +2013,7 @@
}, false);

function fillAndSendEvent(context, x, y, color) {
if (floodfillData(imageData.data, x, y, color, imageData.width, imageData.height)) {
if (floodfillUint8ClampedArray(imageData.data, x, y, color, imageData.width, imageData.height)) {
context.putImageData(imageData, 0, 0);
const fillInstruction = {
type: "fill",
Expand Down

0 comments on commit abda4f2

Please sign in to comment.