dsh-skill-deterministic-pixel-art 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,23 +6,58 @@ Optional third-party DSH bundle carrying the original `deterministic-pixel-art`
6
6
  Skill, references, editable examples, Python renderer and recipes. Users and
7
7
  models can invoke it as needed; a same-name local Skill can take precedence.
8
8
 
9
- ## Build a local package
9
+ ## Already installed: start a conversation
10
10
 
11
- From a checkout with Python and the repository's development requirements:
11
+ Open a conversation in the same DSH profile where the plugin is installed and
12
+ enabled, then send:
12
13
 
13
- ```sh
14
- python -B tools/package_dsh.py --out dist/dsh-package
15
- npm pack ./dist/dsh-package --ignore-scripts --pack-destination dist
14
+ > Use deterministic-pixel-art to make a 16×16 pixel lantern with a transparent background. Read the Skill and check the available Python/Pillow environment first. Deliver the PNG, editable JSON and an 8× nearest-neighbor preview, and inspect the finished image.
15
+
16
+ After receiving the image, you can continue:
17
+
18
+ > Change only the lantern's metal outline to dark brown. Keep the glass and everything else unchanged. Preserve the first version and deliver a separate revised PNG with its editable source.
19
+
20
+ You can also provide an existing PNG and describe the region to change, what to
21
+ preserve and the intended result. You do not need to learn commands or JSON first.
22
+ Provide references or explicit requirements for a particular game style.
23
+
24
+ Expect a native-size PNG and editable source. An enlarged preview alone is not
25
+ enough. Desktop tools can deliver files directly; command-line-only environments
26
+ should return absolute file paths.
27
+
28
+ ## Installation and compatible versions
29
+
30
+ | Name | Purpose |
31
+ | --- | --- |
32
+ | Deterministic Pixel Art | Display name |
33
+ | `dsh-skill-deterministic-pixel-art` | npm package name |
34
+ | `deterministic-pixel-art` | Skill name to use in a conversation |
35
+
36
+ This directory targets bundle **0.1.2**, supporting DSH core and DSH Skill
37
+ **0.2.2-rc.1 through 0.2.2-rc.3**. Node must be **>=24.9.0** and Cordis
38
+ **~4.1.0**. Drawing requires Python **3.10+** and Pillow **>=10.4,<13**.
39
+ Earlier versions, future release candidates and stable releases are outside this
40
+ declaration. Desktop app and core versions differ; check the core with that
41
+ installation's `dsh --version`.
42
+
43
+ Use DSH's supported npm plugin installation method to install and enable the
44
+ package in the profile used for chat. CLI users with an existing working profile
45
+ can replace `YOUR-PROFILE` with its non-`desktop` profile name:
46
+
47
+ ```text
48
+ dsh plugin --profile YOUR-PROFILE add dsh-skill-deterministic-pixel-art@0.1.2
16
49
  ```
17
50
 
18
- The package output directory must be new. The archive has no installation
19
- scripts. Its initial compatibility range is DSH core **0.2.2-rc.1**, Node
20
- **>=24.9.0**, DSH Skill **0.2.2-rc.1** and Cordis **~4.1.0**. Other DSH versions
21
- are not claimed compatible.
51
+ If 0.1.2 is absent from the registry, it has not been published yet. Build a local
52
+ candidate using the [instructions below](#build-a-local-package); the old 0.1.0
53
+ package declares support for rc.1 only. The npm CLI does not manage Electron's
54
+ reserved `desktop` profile; use the desktop's plugin interface or bundled command.
55
+ npm installation does not require a marketplace listing.
22
56
 
23
- ## Install in a new command-line profile
57
+ ## Optional: create a command-line profile
24
58
 
25
- In DSH NEXT, run `dsh` inside **DSH Terminal**. Choose an unused profile name;
59
+ Skip this section if you already have a working profile. Use the official DSH CLI,
60
+ or run `dsh` inside **DSH Terminal** in DSH NEXT. Choose an unused profile name;
26
61
  the examples use `pixel-art`. Initialize it **once, before installing**:
27
62
  `--from-default-profile` replaces the target profile, including its plugins and
28
63
  local configuration. Do not rerun that initialization to start another task.
@@ -32,18 +67,18 @@ dsh --profile pixel-art --from-default-profile headless --help
32
67
  ```
33
68
 
34
69
  This initializes the profile without a model call. Then choose **one** installation
35
- method. When the official npm registry provides version **0.1.0**, use its exact
70
+ method. When the official npm registry provides version **0.1.2**, use its exact
36
71
  package version:
37
72
 
38
73
  ```text
39
- dsh plugin --profile pixel-art add dsh-skill-deterministic-pixel-art@0.1.0
74
+ dsh plugin --profile pixel-art add dsh-skill-deterministic-pixel-art@0.1.2
40
75
  ```
41
76
 
42
- If that version is unavailable, build the local archive above and use its absolute
43
- path instead; quote paths containing spaces:
77
+ For a local candidate, build the archive using the instructions below and use its
78
+ absolute path instead; quote paths containing spaces:
44
79
 
45
80
  ```text
46
- dsh plugin --profile pixel-art add "/absolute/path/to/dsh-skill-deterministic-pixel-art-0.1.0.tgz"
81
+ dsh plugin --profile pixel-art add "/absolute/path/to/dsh-skill-deterministic-pixel-art-0.1.2.tgz"
47
82
  ```
48
83
 
49
84
  Both methods install into `pixel-art`; Desktop uses a separate profile.
@@ -110,6 +145,12 @@ version before a model task. `ACCOUNT_SIGN_IN_REQUIRED` means the account route
110
145
  is unavailable: check the overlay, normal sign-in and `DSH_HOME`, rather than
111
146
  reinstalling the Skill. A same-name local Skill can override the bundled one.
112
147
 
148
+ On Windows, `sandbox-local: windows-acl workspace grant failed` can stop shell
149
+ commands before Python starts. Try a separate task folder under your user
150
+ directory, where your account has full control, while keeping `workspace-write`.
151
+ If it persists, use DSH's sandbox diagnostics; reinstalling this bundle does not
152
+ repair host permissions.
153
+
113
154
  ## Verification and sources
114
155
 
115
156
  Platform validation uses Windows DSH NEXT **2.0.22-next**, core **0.2.2-rc.1**,
@@ -117,6 +158,8 @@ Node **24.21.0**, Python **3.12.14** and Pillow **12.3.0**. Run
117
158
  `python -B tools/check_dsh.py` with Node/npm and development requirements to
118
159
  build and check the actual archive, real Skill services and relocated renderer.
119
160
  That check requires no model call.
161
+ CI uses `--skill-version` to check the three matching service versions on Windows
162
+ and Ubuntu.
120
163
 
121
164
  `tools/package_dsh.py` reuses the authoritative inputs in `skill-content/`,
122
165
  `src/`, `recipes/` and existing examples. Generated resources are not maintained
@@ -125,3 +168,16 @@ bundled. See LICENSE and NOTICE.md for licensing and sources.
125
168
 
126
169
  This project is not endorsed by DeepSeek. For native Skill installation, follow
127
170
  [INSTALL.md](https://github.com/Chenamel/deterministic-pixel-art/blob/main/INSTALL.md).
171
+
172
+ ## Build a local package
173
+
174
+ Only source development and local candidate acceptance need this section. From a
175
+ checkout with Python and the repository's development requirements:
176
+
177
+ ```sh
178
+ python -B tools/package_dsh.py --out dist/dsh-package
179
+ npm pack ./dist/dsh-package --ignore-scripts --pack-destination dist
180
+ ```
181
+
182
+ The package output directory must be new. The archive has no installation scripts;
183
+ ordinary use can install the npm package directly.
package/README.zh-CN.md CHANGED
@@ -6,22 +6,52 @@
6
6
  说明、Python 工具、配方和可编辑示例。用户与模型都可按需调用;同名本地 Skill
7
7
  可以优先使用。
8
8
 
9
- ## 生成本地包
9
+ ## 已安装:直接开始对话
10
10
 
11
- 在源码仓库安装 Python 和开发依赖后运行:
11
+ 在已安装并启用插件的同一个 DSH 配置中开启对话,发送:
12
12
 
13
- ```sh
14
- python -B tools/package_dsh.py --out dist/dsh-package
15
- npm pack ./dist/dsh-package --ignore-scripts --pack-destination dist
13
+ > 请使用 deterministic-pixel-art,制作一个 16×16、透明背景的像素提灯。先读取这个 Skill 并检查可用的 Python/Pillow 环境。交付 PNG、可继续修改的 JSON,以及 8 倍最近邻预览;完成后看图检查。
14
+
15
+ 拿到图片后可以继续说:
16
+
17
+ > 只把提灯的金属边框改成深棕色,玻璃和其他部分保持原样。保留初版,另交修改后的 PNG 和源文件。
18
+
19
+ 也可以提供已有 PNG,指出要修改的区域、保留的部分及目标效果。不必先学习命令
20
+ 或 JSON;需要特定游戏风格时,提供参考图或明确要求。
21
+
22
+ 应收到原尺寸 PNG 和可编辑源文件。只有放大预览图还不够;桌面可直接交付文件,
23
+ 仅命令行环境则应返回文件的绝对路径。
24
+
25
+ ## 安装与兼容版本
26
+
27
+ | 名称 | 用途 |
28
+ | --- | --- |
29
+ | Deterministic Pixel Art | 展示名称 |
30
+ | `dsh-skill-deterministic-pixel-art` | npm 安装包名 |
31
+ | `deterministic-pixel-art` | 对话中使用的 Skill 名称 |
32
+
33
+ 本目录对应 bundle **0.1.2**,支持 DSH core 与 DSH Skill
34
+ **0.2.2-rc.1 至 0.2.2-rc.3**。Node 要求 **>=24.9.0**,Cordis 为
35
+ **~4.1.0**;绘图需要 Python **3.10+**、Pillow **>=10.4,<13**。
36
+ 更早版本、未来 rc 及正式版不在兼容声明内。桌面应用版本与内核版本不同,可用
37
+ 该安装的 `dsh --version` 核对内核。
38
+
39
+ 通过 DSH 支持的 npm 插件安装入口,将包装入实际用于聊天的配置并启用。
40
+ 已有正常配置的 CLI 用户,可将 `YOUR-PROFILE` 换成自己的非 `desktop` profile:
41
+
42
+ ```text
43
+ dsh plugin --profile YOUR-PROFILE add dsh-skill-deterministic-pixel-art@0.1.2
16
44
  ```
17
45
 
18
- 生成目录必须不存在。包没有安装脚本。首版限定 DSH core **0.2.2-rc.1**、Node
19
- **>=24.9.0**;宿主需提供 DSH Skill **0.2.2-rc.1** 和 Cordis **~4.1.0**。
20
- 其他 DSH 版本未声明兼容。
46
+ 若 registry 尚无 0.1.2,说明该版本尚未发布;本地候选按文末的
47
+ [打包说明](#生成本地包)生成,不要将仅声明 rc.1 的旧 0.1.0 当作新版替代。
48
+ npm CLI 不管理 Electron 专用的 `desktop` profile;桌面使用其自身的插件入口
49
+ 或内置命令。npm 安装无需等待市场收录。
21
50
 
22
- ## 在新配置中安装
51
+ ## 可选:新建命令行配置
23
52
 
24
- 在 DSH NEXT 的 **DSH Terminal** 中运行 `dsh`,选择未使用过的 profile 名称;
53
+ 已有可用配置可以跳过本节。使用官方 DSH CLI,或在 DSH NEXT 的
54
+ **DSH Terminal** 中运行 `dsh`,选择未使用过的 profile 名称;
25
55
  以下用 `pixel-art`。**先初始化一次,再安装插件**:`--from-default-profile`
26
56
  会替换目标 profile,包括其中的插件和本地配置。以后启动任务不要重复初始化。
27
57
 
@@ -30,16 +60,16 @@ dsh --profile pixel-art --from-default-profile headless --help
30
60
  ```
31
61
 
32
62
  这条命令初始化配置,不调用模型。随后**选择一种**安装方式。官方 npm registry
33
- 提供 **0.1.0** 时,使用精确包版本:
63
+ 提供 **0.1.2** 时,使用精确包版本:
34
64
 
35
65
  ```text
36
- dsh plugin --profile pixel-art add dsh-skill-deterministic-pixel-art@0.1.0
66
+ dsh plugin --profile pixel-art add dsh-skill-deterministic-pixel-art@0.1.2
37
67
  ```
38
68
 
39
- 若该版本不可用,按前文生成本地归档,改用其绝对路径;含空格路径保留引号:
69
+ 本地候选按文末说明生成归档,改用其绝对路径;含空格路径保留引号:
40
70
 
41
71
  ```text
42
- dsh plugin --profile pixel-art add "/absolute/path/to/dsh-skill-deterministic-pixel-art-0.1.0.tgz"
72
+ dsh plugin --profile pixel-art add "/absolute/path/to/dsh-skill-deterministic-pixel-art-0.1.2.tgz"
43
73
  ```
44
74
 
45
75
  两种方式都安装到 `pixel-art`;Desktop 使用独立的 profile。
@@ -99,12 +129,18 @@ shell 检查 Python 和 Pillow。缺少它们属于运行前置条件,安装 b
99
129
  表示账户路线不可用,应检查 overlay、正常登录和 `DSH_HOME`,不必重装 Skill。
100
130
  同名本地 Skill 会覆盖随包版本。
101
131
 
132
+ Windows 若出现 `sandbox-local: windows-acl workspace grant failed`,shell 命令
133
+ 可能在 Python 启动前就被阻止。可保持 `workspace-write`,先将任务副本放到用户
134
+ 目录下、当前账户具有完全控制权限的独立文件夹再试。若仍失败,使用 DSH 的沙箱
135
+ 诊断;重装本 bundle 无法修复宿主目录权限。
136
+
102
137
  ## 验证与来源
103
138
 
104
139
  本机验证基线为 Windows DSH NEXT **2.0.22-next**、core **0.2.2-rc.1**、Node
105
140
  **24.21.0**、Python **3.12.14**、Pillow **12.3.0**。
106
141
  `python -B tools/check_dsh.py` 需要 Node/npm 和开发依赖,检查实际归档、真实
107
142
  Skill 服务与搬移后的绘图工具,不需要模型调用。
143
+ CI 在 Windows 和 Ubuntu 分别用 `--skill-version` 检查三版配套服务。
108
144
 
109
145
  `tools/package_dsh.py` 复用 `skill-content/`、`src/`、`recipes/` 与原示例目录的
110
146
  权威输入;不手工维护生成资源,不建立第二套绘制引擎。`skill-manifest.json`
@@ -113,3 +149,14 @@ Skill 服务与搬移后的绘图工具,不需要模型调用。
113
149
  本项目不是 DeepSeek 官方插件。也可以按原仓库的
114
150
  [INSTALL.md](https://github.com/Chenamel/deterministic-pixel-art/blob/main/INSTALL.md)
115
151
  直接安装原生 Skill。
152
+
153
+ ## 生成本地包
154
+
155
+ 仅源码开发或本地候选验收需要本节。在源码仓库安装 Python 和开发依赖后运行:
156
+
157
+ ```sh
158
+ python -B tools/package_dsh.py --out dist/dsh-package
159
+ npm pack ./dist/dsh-package --ignore-scripts --pack-destination dist
160
+ ```
161
+
162
+ 生成目录必须不存在。包没有安装脚本;通常使用者直接安装 npm 包即可。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-skill-deterministic-pixel-art",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Third-party DSH bundle for the Deterministic Pixel Art Skill and its editable PNG tools.",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -34,11 +34,11 @@
34
34
  },
35
35
  "engines": {
36
36
  "node": ">=24.9.0",
37
- "dsh": "0.2.2-rc.1"
37
+ "dsh": ">=0.2.2-rc.1 <=0.2.2-rc.3"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "@deepseek-ai/cordis": "~4.1.0",
41
- "@deepseek-ai/dsh-skill": "0.2.2-rc.1"
41
+ "@deepseek-ai/dsh-skill": ">=0.2.2-rc.1 <=0.2.2-rc.3"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@deepseek-ai/cordis": "~4.1.0",
@@ -73,21 +73,21 @@
73
73
  "references/sources.md": "72d8ef7cc656e9b632d6c35b92c431598cf32254c26cd97056c85286eedd646b",
74
74
  "references/text-workflow.md": "7cd64f3235004d0b23e6e2d837a4b46569d4407d24a9ac99fe1fd32491e0ce20",
75
75
  "references/ui.md": "fccea168e299771f55e8ce6794ee29895f6ec1f53d2cc7a443385f9f8039fe25",
76
- "references/workflows.md": "75886884455fde045149245dad4812378f7ddc4d86256a00429b80b2acf503fd",
76
+ "references/workflows.md": "4be0b69e3f71c9450573e0fe6a4036ea4471f2721b0a8c60d46d2fdb55fa830e",
77
77
  "requirements.txt": "41b54a6fb2918667ca47a61d73b522629d84490f3d78f0f20b21135faba10d35",
78
78
  "scripts/pixel_art.py": "48e5bbd53e402b5e82b0ab16ea52e9d0bb166040a0bbcfd570b3198d7b56f17f",
79
- "scripts/pixelart/__init__.py": "67b04f56c8ead2c04ef32584f946d060e5202ca1756116c6d520cf6cdaddb2e0",
79
+ "scripts/pixelart/__init__.py": "61f4a6629df4288f90f9aca9f37e7679cb0fbd502b8ca5f677ad3b0d74c13577",
80
80
  "scripts/pixelart/__main__.py": "935a1c1166b0c1ea35a82256345000bf2c73ded718d77773bc27a71ecce28f7d",
81
81
  "scripts/pixelart/analysis.py": "2d8b8c0d3edd9ec809202dcb83d5cc5a49cebe46583a0793d9689c117b3d3771",
82
82
  "scripts/pixelart/assembly.py": "d83b77642a008142afa912d9deeacbcda069f3a66e62097c01d2e4d140f12dfe",
83
- "scripts/pixelart/cli.py": "058468120a5d9344acade5dfa5ec8ef5ed128d418efbeaac987fbb64c6272fe1",
83
+ "scripts/pixelart/cli.py": "8afbc527d18058a369deff7bfc74a1f52a7a317bda8e4ce11a307f626b01e458",
84
84
  "scripts/pixelart/compat.py": "98aa940594f525dab4f58c91012f1dbb1f24615c36b7f317be5a433af81cf203",
85
85
  "scripts/pixelart/context.py": "d15774a0f2bd076c1d5258a47d157b4d776d00fd4a934d89f6ecf12539c0acd1",
86
86
  "scripts/pixelart/core.py": "7f4ee5643f5dbb03b57408ed5b75a4fe0d492e86a64e4fa9c9de2fb29b5cd7c7",
87
- "scripts/pixelart/edit.py": "409d6c0e74cd95089e527713e856f07ad5a4cea1d88164838eb9463dc2d99d23",
87
+ "scripts/pixelart/edit.py": "eb13999e67a1c8483ab662f6117b4db2289f13b0b9dbc01c74f780b50e2a4681",
88
88
  "scripts/pixelart/ingest.py": "781e3bd693f1cc408d4aed7eab0f07008602c2c375941b5cbd6749fff31c7bb4",
89
89
  "scripts/pixelart/jsonio.py": "5da4f59c9c8deeba79fda0c8c12863097e12bcf360e68bbb280f7cac62e57b6f",
90
- "scripts/pixelart/metadata.py": "24bfb80b11b1c56e9c17c8cb34a8f785b145fba7f8efa081349ea67e09681f31",
90
+ "scripts/pixelart/metadata.py": "afc784afb2549b591be5416ce444c6c0a8d1ab8563c291454c079f9eaade47d2",
91
91
  "scripts/pixelart/output.py": "c3c17d615c388c6c2f65555b3a69ab38243e44830245371217c572a0fca193d0",
92
92
  "scripts/pixelart/presets.py": "89b5fa58e1c14818a38918a1dc47875347c67f24e09df580e750e29a10312941",
93
93
  "scripts/pixelart/review.py": "871be22819e6b44446c92935f03fc46a94efafa6b7cdb2801c359403de16cd4e",
@@ -21,6 +21,8 @@ Try `assets/workflows/atlas-before.png`, `atlas-before-layout.json` and `atlas-r
21
21
 
22
22
  `replace-cell --image-out ... --metadata ...` writes the complete atlas block and a fresh `rgba_sha256`. A standalone cell render correctly has no atlas block; that does not describe the metadata produced by atlas replacement. No manual sidecar construction is needed.
23
23
 
24
+ Embedded layout records are limited to 256 KiB of serialized UTF-8, including JSON escapes for non-ASCII names. `render --embed-metadata` and `recolor` reject oversized records before publishing any outputs. Separate layout JSON files and in-memory layouts do not share this embedded-record limit. For a large layout, render without `--embed-metadata` and keep the `--metadata` sidecar; reduce or split the layout before using `recolor`, which always embeds a fresh record.
25
+
24
26
  ## Candidates without overwriting evidence
25
27
 
26
28
  When exploring variants, give each a directory such as `candidates/v01/` containing its spec, PNG, fresh layout and optional review. Use `v02/` for another candidate; keep paths meaningful rather than repeatedly occupying a shared `final.*`. After selecting a result, write the delivery paths. This is a useful convention, not a requirement to produce alternatives for every small edit.
@@ -31,6 +33,8 @@ A later revision can use another candidate directory, or an explicit `--force` r
31
33
 
32
34
  `verify` compares all decoded RGBA, including RGB under alpha zero. Repeat `--allow-region X Y W H` for multiple rectangles. `--allow-mask allowed.png` accepts nonzero L/1 intensity or RGBA/LA alpha; RGB-only masks are rejected. Regions/mask combine by union. Mask size must match. A hollow border needs a hollow mask, not its enclosing rectangle.
33
35
 
36
+ Candidate, baseline and mask must be single-frame PNGs with at most 8-bit channels. Unsupported formats, higher bit depths and animations exit 2; they are not silently reduced to 8-bit pixels or a first frame. Python `verify_edit` accepts decoded `1`, `L`, `LA`, `P`, `RGB` or `RGBA` images and single-frame masks with the channels above. Pass original decoded inputs: converting modes or copying a frame before verification can discard evidence the API cannot recover.
37
+
34
38
  Exit codes: 0 valid boundary; 1 outside changes; 2 input/output error. `--out verification.json` saves counts, outside xywh bbox, up to 64 coordinates and omitted count. This does not judge appearance or state meaning. `validate` checks the image against its specified rules.
35
39
 
36
40
  ## Scoped color variants
@@ -4,7 +4,7 @@ from .spec import render
4
4
 
5
5
  __all__ = ['Canvas', 'PixelArtError', 'color', 'make_preview', 'outline', 'render', 'validate',
6
6
  'inspect_image', 'image_to_spec','replace_cell','recolor_image','verify_edit','assemble']
7
- __version__ = '1.2.2'
7
+ __version__ = '1.3.0'
8
8
 
9
9
 
10
10
  def inspect_image(image, context=None, *, region=None, cell=None, grid=False, comparison=None, metadata=None):
@@ -27,7 +27,7 @@ def read_image(path):
27
27
  return opened.copy()
28
28
 
29
29
 
30
- def _read_recolor_png(path):
30
+ def _read_edit_png(path, operation):
31
31
  """Reject unsupported source/mask formats before copying away frame info."""
32
32
  from .core import dimensions
33
33
 
@@ -38,13 +38,15 @@ def _read_recolor_png(path):
38
38
  or header[:8] != b'\x89PNG\r\n\x1a\n'
39
39
  or header[12:16] != b'IHDR'
40
40
  ):
41
- raise PixelArtError('recolor: expected a PNG input')
41
+ raise PixelArtError(f'{operation}: expected a PNG input')
42
42
  if header[24] > 8:
43
- raise PixelArtError('recolor: PNG bit depth above 8 is not supported')
43
+ raise PixelArtError(f'{operation}: PNG bit depth above 8 is not supported')
44
44
  with Image.open(path) as opened:
45
45
  dimensions(opened.size)
46
46
  if getattr(opened, 'n_frames', 1) != 1:
47
- raise PixelArtError('recolor: animated/multiframe PNG is not supported')
47
+ raise PixelArtError(
48
+ f'{operation}: animated/multiframe PNG is not supported'
49
+ )
48
50
  return opened.copy()
49
51
 
50
52
 
@@ -260,10 +262,12 @@ def main(argv=None):
260
262
 
261
263
  check_alias([args.image, args.compare, args.allow_mask], [args.out])
262
264
  report = verify_edit(
263
- read_image(args.image),
264
- read_image(args.compare),
265
+ _read_edit_png(args.image, 'verify.image'),
266
+ _read_edit_png(args.compare, 'verify.compare'),
265
267
  regions=args.allow_region,
266
- mask=read_image(args.allow_mask) if args.allow_mask else None,
268
+ mask=_read_edit_png(args.allow_mask, 'verify.mask')
269
+ if args.allow_mask
270
+ else None,
267
271
  )
268
272
  if args.out:
269
273
  publish(
@@ -281,8 +285,10 @@ def main(argv=None):
281
285
  [args.image, args.allow_mask, args.metadata],
282
286
  [args.out, args.report, args.metadata_out],
283
287
  )
284
- source = _read_recolor_png(args.image)
285
- mask = _read_recolor_png(args.allow_mask) if args.allow_mask else None
288
+ source = _read_edit_png(args.image, 'recolor')
289
+ mask = (
290
+ _read_edit_png(args.allow_mask, 'recolor') if args.allow_mask else None
291
+ )
286
292
  context, layout_verification = merge_layout(
287
293
  source, metadata=read_json(args.metadata) if args.metadata else None
288
294
  )
@@ -6,6 +6,16 @@ from .core import PixelArtError,color,dimensions
6
6
  from .context import _box
7
7
 
8
8
 
9
+ def _check_edit_image(image, where):
10
+ dimensions(image.size)
11
+ if getattr(image, 'n_frames', 1) != 1:
12
+ raise PixelArtError(f'{where}: animated/multiframe images are not supported')
13
+ if image.mode not in ('1', 'L', 'LA', 'P', 'RGB', 'RGBA'):
14
+ raise PixelArtError(
15
+ f'{where}: requires decoded 8-bit grayscale, palette, RGB or RGBA pixels'
16
+ )
17
+
18
+
9
19
  def replace_cell(spec,name,replacement):
10
20
  """Return a new valid atlas spec; no I/O and no change to the original."""
11
21
  from .spec import render
@@ -32,6 +42,8 @@ def _allowed_mask(size,regions,mask,where):
32
42
  x,y,w,h=_box(region,size,where+'.region')
33
43
  pen.rectangle((x,y,x+w-1,y+h-1),fill=255)
34
44
  if mask is not None:
45
+ if getattr(mask, 'n_frames', 1) != 1:
46
+ raise PixelArtError(f'{where}.mask: animated/multiframe masks are not supported')
35
47
  if mask.size!=size:raise PixelArtError(f'{where}.mask: dimensions must match')
36
48
  if mask.mode in ('RGBA','LA'):channel=mask.getchannel('A')
37
49
  elif mask.mode in ('L','1'):channel=mask.convert('L')
@@ -49,11 +61,7 @@ def recolor_image(image,mapping,*,regions=None,mask=None):
49
61
  object selection takes place. Returned pixels do not inherit PNG metadata;
50
62
  callers must validate source layout and publish a fresh output record.
51
63
  """
52
- dimensions(image.size)
53
- if getattr(image,'n_frames',1)!=1:
54
- raise PixelArtError('recolor: animated/multiframe images are not supported')
55
- if image.mode not in ('1','L','LA','P','RGB','RGBA'):
56
- raise PixelArtError('recolor: requires decoded 8-bit grayscale, palette, RGB or RGBA pixels')
64
+ _check_edit_image(image, 'recolor')
57
65
  pairs=list(mapping.items()) if isinstance(mapping,Mapping) else mapping
58
66
  if not isinstance(pairs,(list,tuple)) or not pairs:
59
67
  raise PixelArtError('recolor.mapping: expected a nonempty mapping or list of color pairs')
@@ -97,7 +105,8 @@ def verify_edit(image,comparison,*,regions=None,mask=None):
97
105
  nonzero intensity (L/1); RGB masks are rejected to avoid an all-allowed trap.
98
106
  All reported rectangles are [x,y,width,height]. No artwork is changed.
99
107
  """
100
- dimensions(image.size)
108
+ _check_edit_image(image, 'verify.image')
109
+ _check_edit_image(comparison, 'verify.compare')
101
110
  if image.size!=comparison.size:raise PixelArtError('verify: comparison dimensions must match')
102
111
  allowed=_allowed_mask(image.size,regions,mask,'verify')
103
112
  raw=image.convert('RGBA').tobytes();old=comparison.convert('RGBA').tobytes();permissions=allowed.tobytes()
@@ -11,6 +11,12 @@ from .core import PixelArtError
11
11
  from .jsonio import parse_json
12
12
 
13
13
  PNG_KEY = 'pixelart:layout'
14
+ MAX_LAYOUT_BYTES = 256 * 1024
15
+
16
+
17
+ def _check_record_size(text, source):
18
+ if len(text.encode('utf-8')) > MAX_LAYOUT_BYTES:
19
+ raise PixelArtError(f'{source} metadata exceeds 256 KiB')
14
20
 
15
21
 
16
22
  def rgba_digest(image):
@@ -28,8 +34,12 @@ def encode_png(image, metadata=None):
28
34
  buffer = BytesIO()
29
35
  options = {}
30
36
  if metadata is not None:
37
+ serialized = json.dumps(
38
+ metadata, ensure_ascii=True, sort_keys=True, separators=(',', ':')
39
+ )
40
+ _check_record_size(serialized, 'embedded')
31
41
  info = PngInfo()
32
- info.add_text(PNG_KEY, json.dumps(metadata, ensure_ascii=True, sort_keys=True, separators=(',', ':')))
42
+ info.add_text(PNG_KEY, serialized)
33
43
  options['pnginfo'] = info
34
44
  image.save(buffer, format='PNG', **options)
35
45
  return buffer.getvalue()
@@ -55,8 +65,7 @@ def merge_layout(image, context=None, metadata=None, *, require_bound_atlas=Fals
55
65
  if record is None:
56
66
  continue
57
67
  if isinstance(record, str):
58
- if len(record.encode('utf-8')) > 262144:
59
- raise PixelArtError(f'{source} metadata exceeds 256 KiB')
68
+ _check_record_size(record, source)
60
69
  record = parse_json(record)
61
70
  if not isinstance(record, Mapping) or set(record)-{'version','size','mode','atlas','rgba_sha256'}:
62
71
  raise PixelArtError(f'{source} metadata: unknown fields or not an object')