| Server IP : 217.154.3.148 / Your IP : 216.73.216.90 Web Server : Apache System : Linux blissful-wright.217-154-3-148.plesk.page 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64 User : gracious-boyd_hfhh1h8vo9n ( 10000) PHP Version : 8.3.31 Disable Function : opcache_get_status MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/vhosts/gracious-boyd.217-154-3-148.plesk.page/nextjs/lib/render/ |
Upload File : |
import { maskAnd, maskMinus, morphDilate } from '@/utils/maskOps'
function uniqSorted(lines: number[], extent: number): number[] {
return Array.from(
new Set(
(lines ?? [])
.filter((v) => Number.isFinite(v))
.map((v) => Math.round(v))
.filter((v) => v >= 0 && v <= extent),
),
).sort((a, b) => a - b)
}
export type GroutMaskResult = {
groutMask: Uint8Array // 0/255
width: number
height: number
}
export function buildGroutMaskFromGrid(opts: {
width: number
height: number
vlines: number[]
hlines: number[]
groutWidthPx: number
tilesMask?: Uint8Array | null // 0/255
tilesDilatePx?: number // restrict grout to slightly expanded tiles region
}): GroutMaskResult {
const width = Math.max(1, Math.round(opts.width))
const height = Math.max(1, Math.round(opts.height))
const groutWidthPx = Math.max(1, Math.round(opts.groutWidthPx))
const half = Math.max(0, Math.floor(groutWidthPx / 2))
const v = uniqSorted(opts.vlines ?? [], width)
const h = uniqSorted(opts.hlines ?? [], height)
const groutMask = new Uint8Array(width * height)
const markVertical = (x0: number) => {
const xStart = Math.max(0, x0 - half)
const xEnd = Math.min(width - 1, x0 + half)
for (let x = xStart; x <= xEnd; x++) {
for (let y = 0; y < height; y++) {
groutMask[y * width + x] = 255
}
}
}
const markHorizontal = (y0: number) => {
const yStart = Math.max(0, y0 - half)
const yEnd = Math.min(height - 1, y0 + half)
for (let y = yStart; y <= yEnd; y++) {
const row = y * width
for (let x = 0; x < width; x++) groutMask[row + x] = 255
}
}
for (const x of v) markVertical(x)
for (const y of h) markHorizontal(y)
if (opts.tilesMask) {
const dil = morphDilate(
opts.tilesMask,
width,
height,
Math.max(0, Math.round(opts.tilesDilatePx ?? 2)),
)
const restricted = maskAnd(groutMask, dil)
return { groutMask: restricted, width, height }
}
return { groutMask, width, height }
}
export function subtractGroutFromTiles(tilesMask: Uint8Array, groutMask: Uint8Array): Uint8Array {
return maskMinus(tilesMask, groutMask)
}