()
| 554 | } |
| 555 | |
| 556 | async processManualMode() { |
| 557 | const targetWidth = parseInt(document.getElementById('targetWidth').value) || 64; |
| 558 | |
| 559 | this.showProgress(30, '按目标宽度像素化...'); |
| 560 | |
| 561 | // 创建处理canvas |
| 562 | const canvas = document.createElement('canvas'); |
| 563 | const ctx = canvas.getContext('2d'); |
| 564 | |
| 565 | // 限制处理尺寸 |
| 566 | const maxSize = 2000; |
| 567 | const scale = Math.min(1, maxSize / Math.max(this.originalImage.width, this.originalImage.height)); |
| 568 | |
| 569 | canvas.width = Math.floor(this.originalImage.width * scale); |
| 570 | canvas.height = Math.floor(this.originalImage.height * scale); |
| 571 | |
| 572 | ctx.imageSmoothingEnabled = false; |
| 573 | ctx.drawImage(this.originalImage, 0, 0, canvas.width, canvas.height); |
| 574 | |
| 575 | this.showProgress(60, '生成基准像素图...'); |
| 576 | this.basePixelCanvas = this.pixelateToWidth(canvas, targetWidth); |
| 577 | |
| 578 | this.showProgress(80, '优化颜色...'); |
| 579 | await this.applyColorQuantization(); |
| 580 | |
| 581 | this.showProgress(100, '完成处理'); |
| 582 | } |
| 583 | |
| 584 | /** |
| 585 | * 下采样到基准像素图 |
no test coverage detected