()
| 517 | } |
| 518 | |
| 519 | async processAutoMode() { |
| 520 | this.showProgress(20, '分析像素块结构...'); |
| 521 | |
| 522 | // 创建处理canvas |
| 523 | const canvas = document.createElement('canvas'); |
| 524 | const ctx = canvas.getContext('2d'); |
| 525 | |
| 526 | // 限制处理尺寸 |
| 527 | const maxSize = 2000; |
| 528 | const scale = Math.min(1, maxSize / Math.max(this.originalImage.width, this.originalImage.height)); |
| 529 | |
| 530 | canvas.width = Math.floor(this.originalImage.width * scale); |
| 531 | canvas.height = Math.floor(this.originalImage.height * scale); |
| 532 | |
| 533 | ctx.imageSmoothingEnabled = false; |
| 534 | ctx.drawImage(this.originalImage, 0, 0, canvas.width, canvas.height); |
| 535 | |
| 536 | this.showProgress(40, '检测像素块大小...'); |
| 537 | |
| 538 | const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height); |
| 539 | const detection = this.detectPixelBlockSize(imageData); |
| 540 | |
| 541 | this.showProgress(60, '缩放到基准像素...'); |
| 542 | |
| 543 | // 根据检测结果进行下采样 |
| 544 | if (detection.blockSize > 1) { |
| 545 | this.basePixelCanvas = this.downsampleToBase(canvas, detection.blockSize); |
| 546 | } else { |
| 547 | this.basePixelCanvas = this.pixelateToWidth(canvas, 64); // 默认宽度 |
| 548 | } |
| 549 | |
| 550 | this.showProgress(80, '优化颜色...'); |
| 551 | await this.applyColorQuantization(); |
| 552 | |
| 553 | this.showProgress(100, '完成处理'); |
| 554 | } |
| 555 | |
| 556 | async processManualMode() { |
| 557 | const targetWidth = parseInt(document.getElementById('targetWidth').value) || 64; |
no test coverage detected