Fix: attempt for clipping bug - not fixed yet
This commit is contained in:
@@ -45,6 +45,8 @@ const FALLBACK_HUE_MIN = 255;
|
||||
const FALLBACK_HUE_MAX = 355;
|
||||
const FALLBACK_SAT_MIN = 0.15;
|
||||
const FALLBACK_VAL_MIN = 0.04;
|
||||
const STRONG_MAGENTA_RB_MIN = 72;
|
||||
const STRONG_MAGENTA_DOMINANCE = 24;
|
||||
const HALO_HUE_MIN = 245;
|
||||
const HALO_HUE_MAX = 355;
|
||||
const HALO_SAT_MIN = 0.15;
|
||||
@@ -148,6 +150,16 @@ export class PixiPetRenderer {
|
||||
PixiPetRenderer.isHueInRange(h, CONNECTED_HUE_MIN, CONNECTED_HUE_MAX) &&
|
||||
s >= CONNECTED_SAT_MIN &&
|
||||
v >= CONNECTED_VAL_MIN
|
||||
) {
|
||||
isKeyLike[idx] = 1;
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
PixiPetRenderer.isStrongMagentaFamily(
|
||||
data[offset],
|
||||
data[offset + 1],
|
||||
data[offset + 2]
|
||||
)
|
||||
) {
|
||||
isKeyLike[idx] = 1;
|
||||
}
|
||||
@@ -212,6 +224,11 @@ export class PixiPetRenderer {
|
||||
(PixiPetRenderer.isHueInRange(h, FALLBACK_HUE_MIN, FALLBACK_HUE_MAX) &&
|
||||
s >= FALLBACK_SAT_MIN &&
|
||||
v >= FALLBACK_VAL_MIN) ||
|
||||
PixiPetRenderer.isStrongMagentaFamily(
|
||||
data[offset],
|
||||
data[offset + 1],
|
||||
data[offset + 2]
|
||||
) ||
|
||||
maxDistanceFromHardKey <= 96
|
||||
) {
|
||||
data[offset + 3] = 0;
|
||||
@@ -219,6 +236,69 @@ export class PixiPetRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
// Deterministic last pass: remove any border-connected magenta-family background.
|
||||
head = 0;
|
||||
tail = 0;
|
||||
removedBg.fill(0);
|
||||
const enqueueIfMagentaBorder = (x: number, y: number): void => {
|
||||
const idx = indexFor(x, y);
|
||||
if (removedBg[idx] === 1) {
|
||||
return;
|
||||
}
|
||||
const offset = channelOffset(idx);
|
||||
if (data[offset + 3] === 0) {
|
||||
return;
|
||||
}
|
||||
if (
|
||||
!PixiPetRenderer.isStrongMagentaFamily(
|
||||
data[offset],
|
||||
data[offset + 1],
|
||||
data[offset + 2]
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
removedBg[idx] = 1;
|
||||
queue[tail] = idx;
|
||||
tail += 1;
|
||||
};
|
||||
|
||||
for (let x = 0; x < width; x += 1) {
|
||||
enqueueIfMagentaBorder(x, 0);
|
||||
enqueueIfMagentaBorder(x, height - 1);
|
||||
}
|
||||
for (let y = 1; y < height - 1; y += 1) {
|
||||
enqueueIfMagentaBorder(0, y);
|
||||
enqueueIfMagentaBorder(width - 1, y);
|
||||
}
|
||||
|
||||
while (head < tail) {
|
||||
const idx = queue[head];
|
||||
head += 1;
|
||||
const x = idx % width;
|
||||
const y = Math.floor(idx / width);
|
||||
if (x > 0) {
|
||||
enqueueIfMagentaBorder(x - 1, y);
|
||||
}
|
||||
if (x + 1 < width) {
|
||||
enqueueIfMagentaBorder(x + 1, y);
|
||||
}
|
||||
if (y > 0) {
|
||||
enqueueIfMagentaBorder(x, y - 1);
|
||||
}
|
||||
if (y + 1 < height) {
|
||||
enqueueIfMagentaBorder(x, y + 1);
|
||||
}
|
||||
}
|
||||
|
||||
for (let idx = 0; idx < pixelCount; idx += 1) {
|
||||
if (removedBg[idx] !== 1) {
|
||||
continue;
|
||||
}
|
||||
const offset = channelOffset(idx);
|
||||
data[offset + 3] = 0;
|
||||
}
|
||||
|
||||
for (let y = 0; y < height; y += 1) {
|
||||
for (let x = 0; x < width; x += 1) {
|
||||
const idx = indexFor(x, y);
|
||||
@@ -314,6 +394,15 @@ export class PixiPetRenderer {
|
||||
return hue >= min || hue <= max;
|
||||
}
|
||||
|
||||
private static isStrongMagentaFamily(r: number, g: number, b: number): boolean {
|
||||
const minRb = Math.min(r, b);
|
||||
return (
|
||||
r >= STRONG_MAGENTA_RB_MIN &&
|
||||
b >= STRONG_MAGENTA_RB_MIN &&
|
||||
g + STRONG_MAGENTA_DOMINANCE <= minRb
|
||||
);
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
if (this.disposed) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user