dsh-game-material-master 0.4.0 → 0.6.0

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.en.md CHANGED
@@ -19,11 +19,11 @@ no system image libraries required, and your assets are never uploaded to a thir
19
19
  > in place for one full turn, then the eight directions are cut out automatically; switch the method in
20
20
  > stage ① if you'd rather generate each direction separately).
21
21
  >
22
- > The sidebar entry also carries a **small chevron menu button**: click it to pop up the five features and
22
+ > The sidebar entry also carries a **small chevron menu button**: click it to pop up the six features and
23
23
  > jump straight into the one you want. Features you do not use can be turned off in settings (see
24
24
  > "Feature management").
25
25
 
26
- All four modules share the same "generate → review → re-run" workbench. Every stage can be **redone on its
26
+ All six modules share the same "generate → review → re-run" workbench. Every stage can be **redone on its
27
27
  own**, and every asset can be **approved item by item**. The "review mode" lets an agent approve each step
28
28
  and move on automatically, or stop at every step and wait for your go-ahead.
29
29
 
@@ -33,6 +33,7 @@ and move on automatically, or stop at every step and wait for your go-ahead.
33
33
  | **② Image generation** | Prompt (optionally with reference images) → images → green-screen keying | Clean transparent PNG character art / props |
34
34
  | **③ Sequence frames** | First/last frame or a reference video → generate video → extract frames → key | A horizontally laid out, loopable sequence |
35
35
  | **⑤ Map tile generation** | Isometric tiles → assemble a whole map | A tile pack (PNGs) + map PNG + layout JSON |
36
+ | **⑥ Map editor** (experimental, **fully local, zero cost**) | Pick a tileset → paint directly (rebuilt after AsLib's RPG Map Maker: one screen, icon-only, no jargon) | PNG + save-file JSON (wrapping map, auto-tiling, animated tiles); tick what to export and multiple files come as one ZIP download |
36
37
  | ~~④ Rigged animation~~ | Part extraction → assembly → skeletal animation → Spine / DragonBones atlas | **Experimental, not covered in this document** |
37
38
 
38
39
  > 💡 **Module ⑤ "Map tile generation" is built on one idea: geometry by code, content by AI.**
@@ -42,6 +43,28 @@ and move on automatically, or stop at every step and wait for your go-ahead.
42
43
  > re-assembling with the same seed is pixel-identical. Measured: letting the model draw the diamond freely
43
44
  > gives ratios of 1.03–1.55 (nowhere near 2:1), while template filling hits 100%.
44
45
 
46
+ > 💡 **Module ⑥ "Map editor" is modelled after the RPG Map Maker in [AsPJT/AsLib](https://github.com/AsPJT/AsLib/tree/master) and rebuilt as one screen, icon-only, with no jargon.**
47
+ > The asset palette and twelve icon buttons sit on the left, the canvas on the right. **Pick one tileset image and start
48
+ > painting**. "Assets" opens a **list of images plus an "Add image" button**: the dialog asks for the
49
+ > **image file / name / cell size / usage / animation** (hover any control for an explanation) and the properties
50
+ > are then **fixed for good -- delete the image and add it again to change them**. Leave the cell size empty and
51
+ > it is detected from the image. The built-in set (4 autotile sheets + 1 prop grid, the water animating on 2
52
+ > frames) is in the list by default, can be deleted just like your own, and "Restore built-ins" brings it back;
53
+ > its properties cannot be edited. To animate **your own plain sheets**, pick "**Flip-book**" when adding (one
54
+ > row per page); autotile sheets need no setting -- their variants are the frames, and the list shows
55
+ > "Animates: N frames". Map size and cell size are both free-form; the map **wraps around on all four sides** at
56
+ > the data level (auto-tiling joins the top/bottom and left/right edges). The canvas cannot be dragged off the
57
+ > map — it stops at the edge and the map's top-left lines up with the canvas — and the blank area outside cannot
58
+ > be painted
59
+ > ("try the built-in tileset" — its water already has a 2-frame animation). To animate **your own plain
60
+ > sheets**, pick "**Flip-book**" under "Does it animate?" in the Assets card: like a flip-book, each row is one
61
+ > page, and the card states the result ("Animates: N rows = N frames"). Autotile-block sheets need no setting —
62
+ > their variants are the frames. You can also generate random terrain, a maze or a continent in one go.
63
+ > **Not a single model call is made — so nothing is billed.**
64
+
65
+ > 🏷️ **Creating anything in any of the six modules asks for a name first**: the field is pre-filled with the
66
+ > default (just press Enter to keep it), and cancelling creates nothing. Map projects can also be renamed later.
67
+
45
68
  > ⚠️ **Module ④ "Rigged animation" is still experimental and not yet finished**: the quality of part extraction
46
69
  > depends on the image model, automatic assembly and bone inference frequently need manual correction on real
47
70
  > character art (agent visual priors or manual dragging), and the exported Spine / DragonBones output has not
@@ -149,8 +172,8 @@ without spending anything on generation.
149
172
  2. Optional: drop in **reference images** (up to 10); with references present, it runs image-to-image. To cite
150
173
  several of them, refer to "image one", "image two" in the prompt.
151
174
  3. Pick the model / size / count and click **Generate**.
152
- 4. In the results area, review **image by image**: approve, download the PNG, regenerate, delete. The background
153
- percentage is shown right there so you can judge how clean the keying is.
175
+ 4. In the results area, review **image by image**: approve, download the original / download the PNG (the keyed
176
+ result), regenerate, delete. The background percentage is shown right there so you can judge how clean the keying is.
154
177
 
155
178
  ![Image generation · prompt and reference images](https://raw.githubusercontent.com/universe-st/dsh-game-material-master/main/docs/images/gmm-06-image.png)
156
179
 
@@ -189,7 +212,7 @@ flowchart LR
189
212
 
190
213
  ## Driving it from chat
191
214
 
192
- **Every feature of all four modules** (including the experimental rigged animation) **is available through
215
+ **Every feature of all six modules** (including the experimental rigged animation, map tiles and the map editor) **is available through
193
216
  chat**. The plugin registers the whole pipeline as `game_material_*` tools, so an agent can drive it forward,
194
217
  wait, review, and also stop at each step for you to approve.
195
218
 
@@ -221,7 +244,7 @@ dsh plugin --profile web add /path/to/dsh-game-material-master
221
244
  ```
222
245
 
223
246
  The package is published to npm: [dsh-game-material-master](https://www.npmjs.com/package/dsh-game-material-master)
224
- (currently `0.1.1`, `latest`). It has no runtime dependencies, so `dsh plugin add` is all you need.
247
+ (currently `0.6.0`, `latest`). It has no runtime dependencies, so `dsh plugin add` is all you need.
225
248
 
226
249
  After installing, **restart DSH** (the host half is loaded at startup). The browser half is read from
227
250
  `lib/client.js` on disk on each request, so refreshing the browser is enough for it to take effect.
@@ -288,7 +311,7 @@ the host side (the host has no access to the locale service), so the browser hal
288
311
  along every time it reads a project or resets prompts.
289
312
 
290
313
  Scope note: **localization covers the browser half's UI text and the built-in default prompts** — the workbench
291
- title, the four module tabs, every card's buttons and notice bars, dialogs, the settings page, the review
314
+ title, the six module tabs, every card's buttons and notice bars, dialogs, the settings page, the review
292
315
  controls, and the default prompts. Two categories remain in Chinese, because DSH currently only exposes the
293
316
  locale service to the browser half:
294
317
 
@@ -317,8 +340,9 @@ Everything in the UI that you can click, change or approve is bilingual.
317
340
  ├── projects/<id>/ eight-direction sheet (source / images / videos / frames / keyed / preview / out)
318
341
  ├── image-jobs/<id>/ image generation
319
342
  ├── sequence-jobs/<id>/ sequence frames
320
- └── rig-jobs/<id>/ rigged animation (experimental: sheet / parts / layout / rig / atlas)
321
- └── tile-jobs/<id>/ map tiles (template / raw / cell / decor / map / export)
343
+ ├── rig-jobs/<id>/ rigged animation (experimental: sheet / parts / layout / rig / atlas)
344
+ ├── tile-jobs/<id>/ map tiles (template / raw / cell / decor / map / export)
345
+ └── map-jobs/<id>/ map editor (project.json / map.json / tilesets / preview / export)
322
346
  ```
323
347
 
324
348
  > Map tiles keep the **raw generation output** in `raw/`: after changing regularisation parameters such as
@@ -375,6 +399,27 @@ The screenshots in this document were taken by Playwright against the real UI; t
375
399
  - MiniMax occasionally rejects content on moderation (about 10% in practice); just reword to a more neutral
376
400
  prompt and retry.
377
401
 
402
+ ## Credits
403
+
404
+ - **Module ⑥ "Map editor" is modelled after the RPG Map Maker in
405
+ [AsPJT/AsLib](https://github.com/AsPJT/AsLib/tree/master).** What was borrowed is its **interaction and
406
+ layout** (one screen: tile palette plus an icon toolbar on the left, canvas on the right; the pen / eraser /
407
+ bucket / pipette / hand tools together with single-layer preview, layer up-down and undo-redo; click a
408
+ palette tile to pick a brush, a red frame marking the current one, wheel to zoom, drag to pan) and two
409
+ **geometry conventions**:
410
+ 1. **The map wraps around** — auto-tiling works modulo the map size, so the top/bottom and left/right
411
+ edges join up (a data-level property); the camera is clamped inside the map (dragging stops at the
412
+ edge, with the map's top-left aligned to the canvas) and nothing can be painted outside it;
413
+ 2. **A2 auto-tiling** — a 64×160 sheet is 2 variants × 5 shapes; each cell is drawn as four 16px quadrants,
414
+ and each quadrant is picked from one 5-state table over left / up / up-left. Both the small-cell index
415
+ formula and the fact that "1-based index − 1 == AsLib's chip index" come from its `AsMap.hpp`.
416
+
417
+ Its code is **CC0**; this plugin re-implements the behaviour in TypeScript and **does not copy its source**.
418
+ - ⚠️ **The `Picture/MapChip/*_pipo.png` tiles shipped in the AsLib repository belong to a third party and are
419
+ not bundled here** (its README states "Third party content is copyrighted by its respective owners").
420
+ The built-in tileset is generated procedurally on this machine by `scripts/make-map-sample-tileset.mjs`,
421
+ to the same A2 spec.
422
+
378
423
  ## License
379
424
 
380
425
  [MIT](LICENSE)
package/README.md CHANGED
@@ -16,10 +16,10 @@
16
16
  > 侧栏点「游戏素材大师」→ 设置里填两个 API Key → 新建项目、上传设定图 → 点「生成转圈视频」
17
17
  >(默认路径:角色原地匀速转一圈,再自动截出八个方向;要逐方向生图就在阶段①切一下方式)。
18
18
  >
19
- > 侧栏那个入口上还有一个**小折角菜单按钮**:点它直接弹出五个功能,一步跳进要用的那个;
19
+ > 侧栏那个入口上还有一个**小折角菜单按钮**:点它直接弹出六个功能,一步跳进要用的那个;
20
20
  > 不用的功能可以在设置里关掉(见「功能管理」)。
21
21
 
22
- 四个模块共用同一套「生成 → 验收 → 重跑」工作台。每个阶段都能**单独重做**,每份产物都能
22
+ 六个模块共用同一套「生成 → 验收 → 重跑」工作台。每个阶段都能**单独重做**,每份产物都能
23
23
  **逐项打「通过」**;「审核模式」可以选 agent 自动审完就往下走,也可以选每一步停下来等你点头。
24
24
 
25
25
  | 模块 | 做什么 | 走完能拿到 |
@@ -28,6 +28,7 @@
28
28
  | **② 图片生成** | 提示词(可带参考图)→ 出图 → 抠绿幕 | 干净透明的 PNG 立绘 / 道具 |
29
29
  | **③ 序列帧生成** | 首尾帧或参考视频 → 生成视频 → 抽帧 → 抠像 | 横向排布、可循环播放的序列帧 |
30
30
  | **⑤ 45°地图地块生成**(实验性) | 45° 等距地块 → 铺成整张地图 | 地块包(PNG)+ 地图 PNG + 布局 JSON |
31
+ | **⑥ 地图编辑器**(实验性,**全本地零计费**) | 选一张素材图 → 直接画(参照 AsLib 的 RPG Map Maker 重做:一屏、纯图标、零术语) | PNG + 存档 JSON(地图四周环绕、自动连接、动画地块);勾几项就导几项,多个产物自动打成一个 ZIP 下载 |
31
32
  | ~~④ 骨骼动画生成~~ | 拆件 → 装配 → 骨骼动画 → Spine / DragonBones 图集 | **实验性功能,本文不展示** |
32
33
 
33
34
  > 💡 **模块⑤「45°地图地块生成」的核心思路是「几何交给代码,内容交给 AI」。**
@@ -36,6 +37,23 @@
36
37
  > 好处是**几何永远精确**——地块拼起来不会有缝,换种子重铺逐像素可复现。
37
38
  > 实测「让模型自由画菱形」的比例只有 1.03~1.55(对不上 2:1),而模板填充的达标率是 100%。
38
39
 
40
+ > 💡 **模块⑥「地图编辑器」借鉴了 [AsPJT/AsLib](https://github.com/AsPJT/AsLib/tree/master) 的 RPG Map Maker,按它重做为一屏、纯图标、零术语。**
41
+ > 左边是素材调色板与 12 个图标按钮,右边就是画布。**「素材」点开是一张素材列表 + 一个「新增素材」**:
42
+ > 新增时弹窗口填**素材图 / 名字 / 格子大小 / 用法 / 会动吗**(鼠标移上去都有解释),一步填完
43
+ > **属性就定下来了,之后只能删掉重来**;尺寸不用你算,留空就按图片尺寸自动识别。
44
+ > 内置素材默认就在列表里(自带 4 张自动连接图 + 1 张道具,水自带 2 帧动画),
45
+ > 同样可以删,删错了点「恢复默认素材」一键拿回来 —— 它的属性不允许改。
46
+ > 想让**自己的普通素材**也动,新增时选「**翻页图**」—— 像手翻书,每一行是一页;
47
+ > 拼块自动连接素材不用设,它的变体本来就是帧,列表上直接标出「会动 N 帧」。
48
+ > 地图大小、格子大小都能随便填(宽高各填各的);
49
+ > **四周环绕**在数据层:自动连接会把上下、左右两边接起来。画布拖不出地图 —— 拖到边就停,
50
+ > 地图左上角对齐后不会再乱动,图外那片空白也画不上;
51
+ > 还能一键生成随机地形 / 迷宫 / 大陆。
52
+ > **一次模型调用都没有,也就不花钱。**
53
+
54
+ > 🏷️ **六个模块的新建都先问一个名字**:输入框里已经填好默认名(直接回车就用默认值),点取消则不会创建;
55
+ > 地图项目还能随时「重命名」。
56
+
39
57
  > ⚠️ **模块④「骨骼动画生成」仍是实验性功能,尚未完善**:拆件质量取决于生图模型,自动装配与骨骼推导
40
58
  > 对真实立绘经常需要人工校正(agent 视觉先验或手工拖放),导出的 Spine / DragonBones 产物也还没经过
41
59
  > 足够的引擎侧验证。界面上该模块带「实验性」角标,并在每次进入时弹窗说明。本文只展示前三个模块。
@@ -123,7 +141,7 @@ flowchart LR
123
141
  1. 写主提示词;需要跨批次复用的共同要求(比如「不要出现文字水印」)写进**统一附加提示词**。
124
142
  2. 可选:拖入**参考图**(最多 10 张),有参考图时走图生图;引用多张可在提示词里写「图一」「图二」。
125
143
  3. 选好模型 / 尺寸 / 张数,点**生成**。
126
- 4. 结果区**逐张**看:通过、下载 PNG、重新生成、删除;背景占比会直接标出来,判断抠像干不干净。
144
+ 4. 结果区**逐张**看:通过、下载原图 / 下载 PNG(抠像结果)、重新生成、删除;背景占比会直接标出来,判断抠像干不干净。
127
145
 
128
146
  ![图片生成 · 提示词与参考图](https://raw.githubusercontent.com/universe-st/dsh-game-material-master/main/docs/images/gmm-06-image.png)
129
147
 
@@ -160,7 +178,7 @@ flowchart LR
160
178
 
161
179
  ## 用对话驱动
162
180
 
163
- 四个模块(含实验性的骨骼动画)的**全部功能都能通过对话调用**。插件把整条流水线注册成
181
+ 六个模块(含实验性的骨骼动画、地图地块与地图编辑器)的**全部功能都能通过对话调用**。插件把整条流水线注册成
164
182
  `game_material_*` 工具,agent 能自己推进、等待、审查,也可以在每一步停下来让你验收。
165
183
 
166
184
  | 工具 | 作用 |
@@ -190,7 +208,7 @@ dsh plugin --profile web add /path/to/dsh-game-material-master
190
208
  ```
191
209
 
192
210
  包已发布到 npm:[dsh-game-material-master](https://www.npmjs.com/package/dsh-game-material-master)
193
- (当前 `0.1.1`,`latest`)。本包没有运行时依赖,`dsh plugin add` 拉下来即可用。
211
+ (当前 `0.6.0`,`latest`)。本包没有运行时依赖,`dsh plugin add` 拉下来即可用。
194
212
 
195
213
  装完**重启 DSH**(宿主半区在启动时装入)。浏览器半区按磁盘上的 `lib/client.js` 现取,
196
214
  刷新浏览器即可生效。
@@ -215,7 +233,7 @@ dsh plugin --profile web add /path/to/dsh-game-material-master
215
233
  | 视频模型 | 默认 `MiniMax-H3`(v2 协议);Hailuo / I2V 走 v1;优云智算版 H3 显式选择 |
216
234
  | Base URL | 主机根,不含 `/v1` `/v2`。国内 `api.minimax.cn`,国际 `api.minimaxi.com` |
217
235
  | 默认参数 | 单格宽高、抽帧张数、像素块边长、抠像阈值等 |
218
- | 功能管理 | 逐个开关五个模块:关掉的模块界面上不再出现,**对话里的 AI 也调不到**(见下) |
236
+ | 功能管理 | 逐个开关六个模块:关掉的模块界面上不再出现,**对话里的 AI 也调不到**(见下) |
219
237
 
220
238
  Key 只写入本机 `<DSH_HOME>/game-material-master/config.json`,界面回显始终脱敏。
221
239
  **模型是插件级设置,三个模块共用**,切换模型后任务自动对齐新档位。
@@ -235,7 +253,7 @@ Key 只写入本机 `<DSH_HOME>/game-material-master/config.json`,界面回显
235
253
  ## 界面语言
236
254
 
237
255
  **插件界面跟随 DSH 自身的语言设置**(设置 → 通用 → 语言),中文 / 英文都是一等公民,
238
- 切换**即时生效**、不用刷新页面:工作台标题、四个模块页签、每一张卡片的按钮、提示条、
256
+ 切换**即时生效**、不用刷新页面:工作台标题、六个模块页签、每一张卡片的按钮、提示条、
239
257
  弹窗与设置页全部跟着走。
240
258
 
241
259
  实现上不猜也不复制 DSH 的语言状态,而是接 DSH 的 `locale` 服务
@@ -249,7 +267,7 @@ Key 只写入本机 `<DSH_HOME>/game-material-master/config.json`,界面回显
249
267
  所以浏览器半区每次读项目、重置提示词时把当前语言一起带过去。
250
268
 
251
269
  范围说明:**多语言覆盖的是浏览器半区的界面文案与内置默认提示词**——工作台标题、
252
- 四个模块页签、每一张卡片的按钮与提示条、弹窗、设置页、验收控件、默认提示词。
270
+ 六个模块页签、每一张卡片的按钮与提示条、弹窗、设置页、验收控件、默认提示词。
253
271
  以下两类仍是中文,因为 DSH 目前只把 locale 服务提供给浏览器半区:
254
272
 
255
273
  - **运行日志里由宿主写入的行**(「开始生成「南 · 正对镜头」」「…生成完成,用时 12.3 秒」等)
@@ -273,7 +291,8 @@ Key 只写入本机 `<DSH_HOME>/game-material-master/config.json`,界面回显
273
291
  ├── image-jobs/<id>/ 图片生成
274
292
  ├── sequence-jobs/<id>/ 序列帧生成
275
293
  ├── rig-jobs/<id>/ 骨骼动画(实验性:sheet / parts / layout / rig / atlas)
276
- └── tile-jobs/<id>/ 地图地块(template / raw / cell / decor / map / export)
294
+ ├── tile-jobs/<id>/ 地图地块(template / raw / cell / decor / map / export)
295
+ └── map-jobs/<id>/ 地图编辑器(project.json / map.json / tilesets / preview / export)
277
296
  ```
278
297
 
279
298
  > 地图地块的 `raw/` 会**保留原始生成结果**:改了单元格尺寸之类的规整参数后,
@@ -330,6 +349,23 @@ T("第 {n0} 帧", { n0: index + 1 }) // 带插值,英
330
349
  - 也可以在 [GitHub Issues](https://github.com/universe-st/dsh-game-material-master/issues)
331
350
  提 issue 或直接发 PR。
332
351
 
352
+ ## 致谢
353
+
354
+ - **模块⑥「地图编辑器」借鉴了 [AsPJT/AsLib](https://github.com/AsPJT/AsLib/tree/master) 的 RPG Map Maker。**
355
+ 具体借鉴的是它的**交互与界面**(一屏:左边素材调色板 + 图标工具栏、右边画布;画笔 / 橡皮 / 油漆桶 /
356
+ 吸管 / 抓手 + 单层预览 + 图层上下 + 撤销重做这一组工具;点调色板选笔刷、红框标当前笔刷、
357
+ 滚轮缩放、拖动平移)和两处**几何约定**:
358
+ 1. **地图四周环绕** —— 自动连接的邻域判断取模,上下 / 左右两边接得上(数据层语义);
359
+ 相机被夹在地图内(拖到边就停、地图左上角与画布左上角对齐),图外不落笔;
360
+ 2. **A2 拼块自动连接** —— 一张 64×160 的图 = 2 变体 × 5 形状,一格拆成四个 16px 象限,
361
+ 每个象限按「左 / 上 / 左上」查同一张 5 状态表;小格的挑选公式,以及
362
+ 「1-based 序号 − 1 == AsLib 的 chip 下标」这条对应关系,都出自它的 `AsMap.hpp`。
363
+
364
+ 它的代码是 **CC0**;本插件是照它的行为用 TypeScript 重写的,**没有拷贝它的源码**。
365
+ - ⚠️ **AsLib 仓库里的 `Picture/MapChip/*_pipo.png` 素材属于第三方,没有打包进本插件**
366
+ (它的 README 写明 "Third party content is copyrighted by its respective owners")。
367
+ 内置素材由 `scripts/make-map-sample-tileset.mjs` 按同样的 A2 规格在本机程序化生成。
368
+
333
369
  ## 许可
334
370
 
335
371
  [MIT](LICENSE)
@@ -1,14 +1,17 @@
1
1
  /**
2
- * 地图地块模块的图像编解码与基础像素操作。
2
+ * 图像编解码与基础像素操作 —— **全插件共用**(原名 `tilemedia.ts`)。
3
3
  *
4
- * 这一层只做「字节 ↔ RGBA 缓冲区」和几个原语(PNG 头、颜色统计、菱形遮罩)。
5
- * 一切几何算法都在 `tilegeom.ts`,拼图在 `tilemap.ts`。
4
+ * 这一层只做「字节 ↔ RGBA 缓冲区」和几个与业务无关的原语
5
+ * (PNG 头、颜色统计、前景/背景掩码、包围盒)。地块几何在 `tilegeom.ts`、
6
+ * 拼图在 `tilemap.ts`、地图编辑器在 `mapgeom.ts` / `maprender.ts` ——
7
+ * 它们都只是这里的调用方,所以这个文件不叫 `tile*`。
6
8
  *
7
9
  * 为什么 PNG 解码走 ffmpeg:仓库**没有任何运行时依赖**(见 AGENTS.md),
8
10
  * 手写 PNG 解码器要处理 5 种 filter 类型,而 ffmpeg 已经是本插件的既有依赖
9
11
  * (抽帧、抠像都用它)。这里把调用集中成一个函数,以后要换只改一处。
10
12
  */
11
13
  import { spawn } from "node:child_process";
14
+ import { readFile } from "node:fs/promises";
12
15
  import { encodePng } from "./png.js";
13
16
  import { ffmpegPath } from "./media.js";
14
17
  /** PNG 头里的尺寸(不解码像素,用来做廉价校验)。 */
@@ -86,6 +89,21 @@ function runFfmpeg(args) {
86
89
  export async function decodeFile(file, maxEdge = 0) {
87
90
  return decodeImage(file, maxEdge);
88
91
  }
92
+ /**
93
+ * 只问尺寸、不要像素。
94
+ *
95
+ * PNG 直接读文件头(零成本);JPEG / WebP / GIF 让 ffmpeg 解一帧成 PNG 再读头。
96
+ * 图集导入只需要知道「几乘几」,为了这个把几千万像素全解出来是白等。
97
+ */
98
+ export async function probeImageSize(file) {
99
+ const head = await readFile(file).catch(() => undefined);
100
+ if (head !== undefined) {
101
+ const size = pngSize(head);
102
+ if (size !== undefined)
103
+ return size;
104
+ }
105
+ return probeDecodedSize(file, 0);
106
+ }
89
107
  /** 编码落盘用的 PNG 字节。 */
90
108
  export function encodeBitmap(bitmap) {
91
109
  return encodePng(bitmap.rgba, bitmap.width, bitmap.height);