mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix: CLAHE tile size and alpha channel corruption in image enhancement
CLAHE width/height is tile size in pixels, not tile count. A 3px tile on a 992x1088 image created ~330x360 independent histogram regions, producing crosshatch/etching artifacts. Now uses image_dimension/8 (clamped 8-256) for ~8 tiles per axis. Also strips alpha before enhancement and re-joins after to prevent CLAHE/normalise/linear from corrupting transparency.
This commit is contained in:
@@ -41,8 +41,18 @@ async function processImageEnhancement(
|
||||
const outputFormat = await resolveOutputFormat(inputBuffer, filename);
|
||||
const analysis = await analyzeImage(inputBuffer);
|
||||
const meta = await sharp(inputBuffer).metadata();
|
||||
const hasAlpha = meta.hasAlpha === true;
|
||||
|
||||
let alphaBuffer: Buffer | undefined;
|
||||
if (hasAlpha) {
|
||||
alphaBuffer = await sharp(inputBuffer).extractChannel(3).toBuffer();
|
||||
}
|
||||
|
||||
let image = sharp(inputBuffer);
|
||||
if (hasAlpha) {
|
||||
image = image.removeAlpha();
|
||||
}
|
||||
|
||||
image = applyCorrections(
|
||||
image,
|
||||
analysis.corrections,
|
||||
@@ -56,6 +66,13 @@ async function processImageEnhancement(
|
||||
.toFormat(outputFormat.format, { quality: outputFormat.quality })
|
||||
.toBuffer();
|
||||
|
||||
if (alphaBuffer) {
|
||||
buffer = await sharp(buffer)
|
||||
.joinChannel(alphaBuffer)
|
||||
.toFormat(outputFormat.format, { quality: outputFormat.quality })
|
||||
.toBuffer();
|
||||
}
|
||||
|
||||
if (settings.deepEnhance && isToolInstalled("noise-removal")) {
|
||||
try {
|
||||
const jobId = randomUUID();
|
||||
|
||||
Reference in New Issue
Block a user