MCPcopy Create free account
hub / github.com/32comic/image2pixel-web / nearestLabColor

Function nearestLabColor

web/js/algorithms.js:37–45  ·  view source on GitHub ↗
(r, g, b, labPalette)

Source from the content-addressed store, hash-verified

35}
36
37function nearestLabColor(r, g, b, labPalette) {
38 const srcLab = rgbToLab(r, g, b);
39 let minD = Infinity, best = labPalette[0];
40 for (const entry of labPalette) {
41 const d = labDistanceSq(srcLab, entry.lab);
42 if (d < minD) { minD = d; best = entry; }
43 }
44 return best.rgb;
45}
46
47// ============================================================
48// Palette Generation (returns palette without modifying imageData)

Callers 3

floydSteinbergDitherFunction · 0.85
processWithClassicLabFunction · 0.85

Calls 2

rgbToLabFunction · 0.85
labDistanceSqFunction · 0.85

Tested by

no test coverage detected