fix: replace enhancement pipeline with CLAHE + normalise + gamma

CLAHE provides adaptive local contrast, normalise stretches the
histogram, and gamma adjusts exposure perceptually. Replaces the old
modulate/linear pipeline that compounded errors and darkened images.
Preset multipliers now include clahe and normalise entries.

Key fixes beyond the spec:
- maxSlope rounded to integer (Sharp requirement)
- White balance uses linear() instead of recomb() to avoid float-cast
  that breaks CLAHE in the libvips pipeline
- CLAHE tile size adapts to image dimensions (1x1 for tiny images)
- Gamma clamped to Sharp's valid range (1.0-3.0)
- Normalise lower/upper correctly mapped to percentile cutoffs
This commit is contained in:
SnapOtter
2026-05-09 11:24:00 +08:00
parent 4bcdc67aa0
commit b61be9e438
3 changed files with 131 additions and 19 deletions
@@ -33,6 +33,7 @@ async function processImageEnhancement(
) {
const outputFormat = await resolveOutputFormat(inputBuffer, filename);
const analysis = await analyzeImage(inputBuffer);
const meta = await sharp(inputBuffer).metadata();
let image = sharp(inputBuffer);
image = applyCorrections(
@@ -41,6 +42,7 @@ async function processImageEnhancement(
settings.mode,
settings.intensity,
settings.corrections,
{ width: meta.width ?? 1, height: meta.height ?? 1 },
);
const buffer = await image