fix(pixelation): exclude external and transparent cells from color counting
This commit is contained in:
@@ -835,7 +835,7 @@ export default function Home() {
|
||||
// 2. 统计初始颜色数量
|
||||
const initialColorCounts: { [key: string]: number } = {};
|
||||
initialMappedData.flat().forEach(cell => {
|
||||
if (cell && cell.key) {
|
||||
if (cell && cell.key && !cell.isExternal && cell.key !== TRANSPARENT_KEY) {
|
||||
initialColorCounts[cell.key] = (initialColorCounts[cell.key] || 0) + 1;
|
||||
}
|
||||
});
|
||||
@@ -854,7 +854,7 @@ export default function Home() {
|
||||
|
||||
// 4. 复制初始数据,准备合并
|
||||
const mergedData: MappedPixel[][] = initialMappedData.map(row =>
|
||||
row.map(cell => ({...cell, isExternal: false}))
|
||||
row.map(cell => ({ ...cell, isExternal: cell.isExternal ?? false }))
|
||||
);
|
||||
|
||||
// 5. 处理相似颜色合并
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { transparentColorData } from './pixelEditingUtils';
|
||||
|
||||
// 定义像素化模式
|
||||
export enum PixelationMode {
|
||||
Dominant = 'dominant', // 卡通模式(主色)
|
||||
@@ -207,12 +209,12 @@ export function calculatePixelGrid(
|
||||
const closestBead = findClosestPaletteColor(representativeRgb, palette);
|
||||
finalCellColorData = { key: closestBead.key, color: closestBead.hex };
|
||||
} else {
|
||||
// 如果单元格为空或全透明,使用备用色
|
||||
finalCellColorData = { key: t1FallbackColor.key, color: t1FallbackColor.hex };
|
||||
// 如果单元格为空或全透明,标记为透明/外部
|
||||
finalCellColorData = { ...transparentColorData };
|
||||
}
|
||||
mappedData[j][i] = finalCellColorData;
|
||||
}
|
||||
}
|
||||
console.log(`Pixel grid calculation complete for mode: ${mode}`);
|
||||
return mappedData;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user