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

Method applyColorQuantization

pixelizer.js:664–683  ·  view source on GitHub ↗

* 应用颜色量化

()

Source from the content-addressed store, hash-verified

662 * 应用颜色量化
663 */
664 async applyColorQuantization() {
665 if (!this.basePixelCanvas) return;
666
667 const colorCount = parseInt(document.getElementById('pixelColorCount').value) || 32;
668 const prefilterStrength = parseInt(document.getElementById('prefilterStrength').value) || 30;
669 const enableDithering = document.getElementById('enableDithering').checked;
670
671 const ctx = this.basePixelCanvas.getContext('2d');
672 const imageData = ctx.getImageData(0, 0, this.basePixelCanvas.width, this.basePixelCanvas.height);
673
674 // 预滤波去噪
675 if (prefilterStrength > 0) {
676 this.applyPrefilter(imageData, prefilterStrength / 100);
677 }
678
679 // 颜色量化
680 await this.quantizeColors(imageData, colorCount, enableDithering);
681
682 ctx.putImageData(imageData, 0, 0);
683 }
684
685 applyPrefilter(imageData, strength) {
686 // 简单的双边滤波去除噪点

Callers 3

processAutoModeMethod · 0.95
processManualModeMethod · 0.95
updatePreviewIfNeededMethod · 0.95

Calls 2

applyPrefilterMethod · 0.95
quantizeColorsMethod · 0.95

Tested by

no test coverage detected