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

Class Pixelizer

pixelizer.js:13–1224  ·  view source on GitHub ↗

* Pixelizer - Advanced Pixel Art Converter * Copyright (c) 2024 CatPixelArt.com. All Rights Reserved. * * 核心功能: * 1. 自动识别整数倍放大的像素画 * 2. AI生成图片的不规则像素块识别 * 3. 颜色量化与噪点处理 * 4. 手动网格对齐 * 5. 1000%放大导出和打印

Source from the content-addressed store, hash-verified

11 */
12
13class Pixelizer {
14 constructor() {
15 this.originalImage = null;
16 this.processedCanvas = null;
17 this.basePixelCanvas = null;
18 this.gridOffsetX = 0;
19 this.gridOffsetY = 0;
20 this.isProcessing = false;
21 this.currentWorker = null;
22
23 // 对齐相关状态
24 this.isDragging = false;
25 this.dragTarget = null;
26 this.guideLines = null;
27
28 this.initializeEventListeners();
29 }
30
31 initializeEventListeners() {
32 // 上传相关
33 const uploadZone = document.getElementById('uploadZone');
34 const fileInput = document.getElementById('pixelImageInput');
35 const uploadButton = uploadZone?.querySelector('.upload-button');
36
37 if (uploadZone) {
38 uploadZone.addEventListener('click', () => fileInput?.click());
39 uploadZone.addEventListener('dragover', this.handleDragOver.bind(this));
40 uploadZone.addEventListener('dragleave', this.handleDragLeave.bind(this));
41 uploadZone.addEventListener('drop', this.handleDrop.bind(this));
42 }
43
44 if (fileInput) {
45 fileInput.addEventListener('change', this.handleFileSelect.bind(this));
46 }
47
48 // 模式切换
49 const detectionModeInputs = document.querySelectorAll('input[name="detectionMode"]');
50 detectionModeInputs.forEach(input => {
51 input.addEventListener('change', this.handleModeChange.bind(this));
52 });
53
54 // 滑块控制
55 this.initializeSliderControls();
56
57
58 // 网格显示开关
59 const showGridCheckbox = document.getElementById('showPixelGrid');
60
61 if (showGridCheckbox) {
62 showGridCheckbox.addEventListener('change', () => {
63 this.updateGridDisplay();
64 });
65 }
66
67 // 导出按钮
68 const exportButton = document.getElementById('exportPNG');
69 const printButton = document.getElementById('printResult');
70

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected