Clear glyph pixels when all channels differ < 35

Fixes #3892
Also helps with #3877
This commit is contained in:
Daniel Imms
2022-07-10 07:22:33 -07:00
parent b6885a67e7
commit 89b320a5e2
2 changed files with 10 additions and 8 deletions
@@ -588,7 +588,8 @@ export class WebglCharAtlas implements IDisposable {
}
/**
* Makes a partiicular rgb color in an ImageData completely transparent.
* Makes a particular rgb color and colors that are nearly the same in an ImageData completely
* transparent.
* @returns True if the result is "empty", meaning all pixels are fully transparent.
*/
function clearColor(imageData: ImageData, color: IColor): boolean {
@@ -597,9 +598,9 @@ function clearColor(imageData: ImageData, color: IColor): boolean {
const g = color.rgba >>> 16 & 0xFF;
const b = color.rgba >>> 8 & 0xFF;
for (let offset = 0; offset < imageData.data.length; offset += 4) {
if (imageData.data[offset] === r &&
imageData.data[offset + 1] === g &&
imageData.data[offset + 2] === b) {
if (Math.abs(imageData.data[offset] - r) +
Math.abs(imageData.data[offset + 1] - g) +
Math.abs(imageData.data[offset + 2] - b) < 35) {
imageData.data[offset + 3] = 0;
} else {
isEmpty = false;
@@ -383,7 +383,8 @@ export class NoneCharAtlas extends BaseCharAtlas {
}
/**
* Makes a partiicular rgb color in an ImageData completely transparent.
* Makes a particular rgb color and colors that are nearly the same in an ImageData completely
* transparent.
* @returns True if the result is "empty", meaning all pixels are fully transparent.
*/
function clearColor(imageData: ImageData, color: IColor): boolean {
@@ -392,9 +393,9 @@ function clearColor(imageData: ImageData, color: IColor): boolean {
const g = color.rgba >>> 16 & 0xFF;
const b = color.rgba >>> 8 & 0xFF;
for (let offset = 0; offset < imageData.data.length; offset += 4) {
if (imageData.data[offset] === r &&
imageData.data[offset + 1] === g &&
imageData.data[offset + 2] === b) {
if (Math.abs(imageData.data[offset] - r) +
Math.abs(imageData.data[offset + 1] - g) +
Math.abs(imageData.data[offset + 2] - b) < 35) {
imageData.data[offset + 3] = 0;
} else {
isEmpty = false;