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

Function quantizeToFixedPalette

web/js/main.js:440–450  ·  view source on GitHub ↗
(imageData, palette)

Source from the content-addressed store, hash-verified

438}
439
440function quantizeToFixedPalette(imageData, palette) {
441 const d = imageData.data;
442 for (let i=0; i<d.length; i+=4) {
443 let minD = Infinity, best = palette[0];
444 for (const c of palette) {
445 const dist = (d[i]-c[0])**2 + (d[i+1]-c[1])**2 + (d[i+2]-c[2])**2;
446 if (dist < minD) { minD = dist; best = c; }
447 }
448 d[i]=best[0]; d[i+1]=best[1]; d[i+2]=best[2];
449 }
450}
451
452function medianCutQuantization(imageData, colorCount) {
453 // Simplified version for brevity, keeping the core logic from original

Callers 2

processImageFunction · 0.85
medianCutQuantizationFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected