Skip to content

refactor: split canvas-rs into canvas and images workspace crates (zero external dependencies)#2

Merged
echosoar merged 2 commits intomainfrom
feature-png-test
Mar 31, 2026
Merged

refactor: split canvas-rs into canvas and images workspace crates (zero external dependencies)#2
echosoar merged 2 commits intomainfrom
feature-png-test

Conversation

@echosoar
Copy link
Copy Markdown
Owner

@echosoar echosoar commented Mar 30, 2026

Reorganises the project as a Cargo workspace with two separate crates, both with zero external dependencies:

Changes Made

  • canvas crate — core 2D drawing library that operates entirely on an in-memory RGBA pixel buffer. No external dependencies. to_data_url and to_blob have been removed from Canvas.
  • images crate — PNG encoding and decoding implemented entirely in pure Rust with no external dependencies. Exposes:
    • images::to_data_url(canvas: &Canvas) -> String — encodes a canvas as a data:image/png;base64,… URL
    • images::to_blob(canvas: &Canvas) -> Vec<u8> — returns raw PNG bytes for a canvas
    • images::from_png(bytes: &[u8]) -> Result<ImageData, String> — decodes a PNG byte slice into RGBA ImageData using a pure-Rust DEFLATE/zlib decoder

Both PNG encoding (zlib stored-block DEFLATE) and PNG decoding (zlib inflate + PNG filter reconstruction) are implemented from scratch with no third-party crates.

Testing

  • ✅ All tests pass across both crates
  • ✅ Integration tests moved to images/tests/ and updated to use the new images::to_data_url, images::to_blob, and images::from_png API
  • ✅ Round-trip encode→decode verified for correctness

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@echosoar
Copy link
Copy Markdown
Owner Author

@copilot
把项目分为两个 crates,一个是 canvas,提供核心的能力,所有的处理都是基于 rgba 的颜色矩阵;另外一个是 images,提供 png 的decoding 和 encoding,可以把 rgba 矩阵转换为png图片,或者是把 png图片转换为 rgba 数据,所以 toDataUrl 和 toBlob 方法从 canvas 踢出,变成 images crate的方法,参数为输入一个canvas实例

Copy link
Copy Markdown

Copilot AI commented Mar 30, 2026

@copilot
把项目分为两个 crates,一个是 canvas,提供核心的能力,所有的处理都是基于 rgba 的颜色矩阵;另外一个是 images,提供 png 的decoding 和 encoding,��...

Done in cf5455e. The repo is now a Cargo workspace with two crates:

  • canvas — pure-Rust core drawing library, operates entirely on an RGBA pixel buffer, no external dependencies. to_data_url and to_blob have been removed from Canvas.
  • images — PNG encoding/decoding, depends on canvas and the png crate. Exposes:
    • images::to_data_url(canvas: &Canvas) -> String
    • images::to_blob(canvas: &Canvas) -> Vec<u8>
    • images::from_png(bytes: &[u8]) -> Result<ImageData, String>

Integration tests have been moved to images/tests/ and updated to use the new API.

Copilot AI changed the title fix: y refactor: split canvas-rs into canvas and images workspace crates Mar 30, 2026
@echosoar
Copy link
Copy Markdown
Owner Author

@copilot

我无法使用任何外部依赖,所以 images 里面无法依赖png库,png的encode 和decode 都需要源码重新实现

Copilot AI changed the title refactor: split canvas-rs into canvas and images workspace crates refactor: split canvas-rs into canvas and images workspace crates (zero external dependencies) Mar 30, 2026
@echosoar echosoar merged commit fd439a0 into main Mar 31, 2026
1 check passed
@echosoar echosoar deleted the feature-png-test branch March 31, 2026 12:19
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.

2 participants