* 应用颜色量化
()
| 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 | // 简单的双边滤波去除噪点 |
no test coverage detected