(imageData, palette)
| 438 | } |
| 439 | |
| 440 | function 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 | |
| 452 | function medianCutQuantization(imageData, colorCount) { |
| 453 | // Simplified version for brevity, keeping the core logic from original |
no outgoing calls
no test coverage detected