Skip to content

feat(pixel-grid): add explicit grid reconstructor - #495

Open
huyanxius wants to merge 5 commits into
1024XEngineer:mainfrom
huyanxius:feat/491-pixel-grid-reconstructor
Open

feat(pixel-grid): add explicit grid reconstructor#495
huyanxius wants to merge 5 commits into
1024XEngineer:mainfrom
huyanxius:feat/491-pixel-grid-reconstructor

Conversation

@huyanxius

Copy link
Copy Markdown
Collaborator

新增一个与检测器和业务应用均解耦的显式网格重建器:调用方给定网格后,本地模块输出每格单色的原生 1x PNG。

Why

网格识别与像素重建是两种不同职责。把重建逻辑绑定在检测器或生成管线中,会导致后续替换检测算法时同时改动颜色恢复,并把本地工具扩散到现有业务路径。

Changes

  • 新增独立 Rust library 与 stdin/stdout CLI,只接收 PNG/JPEG、colsrowscolors 并输出 PNG。
  • 使用两阶段结构标签投票与原色恢复,使 colors 只控制结构聚类,不硬性截断最终全局色板。
  • 钳制密集网格的负三角权重,避免颜色外插产生荧光坏点。
  • 在解码和算法分配前限制 32MiB 输入、4MP 像素和 128MiB 保守工作集。
  • 增加独立 path-filter CI、MIT 许可证和固定上游版本说明。

Implementation

  • 模块位于 backend/native/pixel_grid_reconstructor/,不导入检测器、windup_app、工作流、生成 API、数据库或媒体服务。
  • 网格参数是唯一空间契约;模块不推断像素密度,也不包含自动检测特例。
  • 工作集估算覆盖源图、标签、cells × labels 投票矩阵、颜色/透明度累加器、轴缓冲与编码重叠,溢出使用 checked arithmetic。

Verification

  • cargo fmt --check:通过。
  • cargo test --release --locked --offline:9 项测试通过,0 项失败。
  • cargo clippy --release --locked --offline -- -D warnings:通过。
  • git diff --check upstream/main...HEAD:通过。
  • GitHub Actions:等待远端分支触发。

Scope

Development Context

  • 关键开发约束:重建器只消费显式网格;保留当前认可的像素密度;解决坏点但不强制 16 色、不引入黑色;必须与检测和生成管线解耦。
  • 人工 Review 说明:合并前请后端负责同学重点确认工作集预算、两阶段颜色恢复和 CLI 参数契约;本 PR 不以本地及独立代码验收代替仓库人工 Review。

Related Issues

Closes #491

Refs #489

Detected grids need a separate local stage that can rebuild one color per cell.

Add deterministic two-stage reconstruction with bounded memory and explicit grid arguments.

Images can now be rebuilt without invoking detection, application services, or generation flows.
The native reconstructor needs a reproducible package boundary and dependency graph.

Add the Rust manifest, locked dependencies, and local target exclusion.

The reconstruction module can now build independently with deterministic inputs.
Explicit reconstruction must preserve source colors without creating dense-grid artifacts.

Cover exact cells, uncapped final palettes, bad points, input limits, and working-set rejection.

Color and resource regressions now fail before this module reaches the application layer.
The extracted reconstruction algorithm must remain traceable and license compliant.

Document its explicit-grid contract, two-stage color behavior, fixed upstream revision, and MIT terms.

Maintainers can review the reuse boundary without consulting the generation codebase.
The standalone reconstructor needs a narrow gate independent of backend CI.

Run format and locked release tests only for reconstructor paths and its workflow.

Reconstruction changes now receive isolated validation without touching generation jobs.
@vercel

vercel Bot commented Aug 20, 2026

Copy link
Copy Markdown

Deployment failed for project windup with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/huyan-s-projects1?upgradeToPro=build-rate-limit

@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

审查了独立重建器的输入边界、两阶段标签/颜色恢复、透明度多数票、CLI 参数契约、工作集估算以及 path-filter CI。发现透明 PNG 的可见颜色恢复仍会受到透明像素 RGB 元数据影响,建议在合并前修正。固定 SHA 范围的 git diff --check 通过;本环境未安装 cargo,因此无法复跑 Rust 测试。

let cell = cell_y[y] * cols + cell_x[x];
let weight = weight_y[y] * weight_x[x] + 1e-4;
let rgb = [
rgba[source_offset] as f64 / 255.0,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Exclude transparent RGB values from visible color averaging

When a cell is majority-opaque, this loop still adds every source pixel's RGB to fallback_sum and, if its label wins, to color_sum, regardless of alpha. The k-means sample deliberately uses only opaque pixels, so a common PNG with opaque red content and transparent padding whose stored RGB is blue can produce a visible blended/purple cell even though the transparent RGB should not affect the reconstructed color. Keep the existing alpha-majority calculation, but exclude transparent pixels from the color sums and their denominator (while retaining a sensible fallback for cells with no opaque pixels).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(pixel-grid): add an explicit grid reconstructor

1 participant