Skip to content

Commit

Permalink
Make work better on Safari by manual posterization
Browse files Browse the repository at this point in the history
  • Loading branch information
tomayac committed Sep 28, 2023
1 parent a39f451 commit 5d7967e
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 22 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions docs/assets/index-c3c47574.js → docs/assets/index-567ccd08.js

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
}
</script>
<base target="_blank" />
<script type="module" crossorigin src="/assets/index-c3c47574.js"></script>
<script type="module" crossorigin src="/assets/index-567ccd08.js"></script>
<link rel="stylesheet" href="/assets/style-02ad85c7.css">
<link rel="manifest" href="/manifest.webmanifest"></head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion docs/sw.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 29 additions & 4 deletions src/js/preprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,41 @@ if (supportsOffscreenCanvas) {
canvasMain.width = width;
canvasMain.height = height;
ctxMain.clearRect(0, 0, width, height);
ctxMain.filter = getFilterString();
ctxMain.setTransform(1, 0, 0, 1, width / 2, height / 2);
const rotate = Number(filterInputs[SCALE_ROTATION.rotation].value);
ctxMain.rotate((rotate * Math.PI) / 180);
ctxMain.drawImage(
inputImage,
(-factor * inputImage.naturalWidth * shrinkFactor) / 2,
(-factor * inputImage.naturalHeight * shrinkFactor) / 2,
);
return ctxMain.getImageData(0, 0, width, height);
const rotate = Number(filterInputs[SCALE_ROTATION.rotation].value);
ctxMain.rotate((rotate * Math.PI) / 180);
ctxMain.filter = getFilterString();
const imgData = ctxMain.getImageData(
0,
0,
canvasMain.width,
canvasMain.height,
);
const redSteps = filterInputs[COLORS.red].value;
const greenSteps = filterInputs[COLORS.green].value;
const blueSteps = filterInputs[COLORS.blue].value;
const alphaSteps = filterInputs[COLORS.alpha].value + 1;
for (let i = 0; i < imgData.data.length; i += 4) {
imgData.data[i] =
Math.floor((imgData.data[i] / 255) * (redSteps - 1)) *
(255 / (redSteps - 1));
imgData.data[i + 1] =
Math.floor((imgData.data[i + 1] / 255) * (greenSteps - 1)) *
(255 / (greenSteps - 1));
imgData.data[i + 2] =
Math.floor((imgData.data[i + 2] / 255) * (blueSteps - 1)) *
(255 / (blueSteps - 1));
imgData.data[i + 3] =
Math.floor((imgData.data[i + 3] / 255) * (alphaSteps - 1)) *
(255 / (alphaSteps - 1));
}
ctxMain.putImageData(imgData, 0, 0);
return imgData;
};
}

Expand Down

0 comments on commit 5d7967e

Please sign in to comment.