dsh-game-material-master 0.10.2 → 0.11.1

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/lib/config.js CHANGED
@@ -8,6 +8,7 @@ import { mkdir, readFile, rename, stat, writeFile } from "node:fs/promises";
8
8
  import { homedir } from "node:os";
9
9
  import { join } from "node:path";
10
10
  import { DEFAULT_ROW_ORDER } from "./directions.js";
11
+ import { DEFAULT_KEY_COLOR, normalizeKeyColor } from "./keycolor.js";
11
12
  import { STUDIO_MODULES } from "./links.js";
12
13
  import { MUSIC_DEFAULT_MODEL } from "./musicmodels.js";
13
14
  import { SFX_DEFAULT_BASE_URL, SFX_DEFAULT_FORMAT, SFX_DEFAULT_MODEL, SFX_DEFAULT_SAMPLE_RATE, sfxFormatOrDefault, sfxSampleRateOrDefault } from "./sfxapi.js";
@@ -225,6 +226,7 @@ export const DEFAULT_CONFIG = {
225
226
  fillRatio: 0.94,
226
227
  bottomMargin: 2,
227
228
  cropInset: 0,
229
+ keyColor: DEFAULT_KEY_COLOR,
228
230
  keyLow: 14,
229
231
  keyHigh: 80,
230
232
  despill: 0.65,
@@ -316,7 +318,7 @@ export function normalizeConfig(input) {
316
318
  toapisBaseUrl: asString(raw.toapisBaseUrl, DEFAULT_CONFIG.toapisBaseUrl).trim(),
317
319
  toapisApiKey: asString(raw.toapisApiKey, DEFAULT_CONFIG.toapisApiKey).trim(),
318
320
  toapisImageModel: asString(raw.toapisImageModel, DEFAULT_CONFIG.toapisImageModel).trim(),
319
- toapisImageSize: asString(raw.toapisImageSize, DEFAULT_CONFIG.toapisImageSize).trim(),
321
+ toapisImageSize: asString(raw.toapisImageSize, DEFAULT_CONFIG.toapisImageSize).trim() || DEFAULT_CONFIG.toapisImageSize,
320
322
  toapisImageQuality: asString(raw.toapisImageQuality, DEFAULT_CONFIG.toapisImageQuality).trim(),
321
323
  toapisImageBackground: raw.toapisImageBackground === "transparent" || raw.toapisImageBackground === "opaque" ? raw.toapisImageBackground : "auto",
322
324
  toapisVideo: asBool(raw.toapisVideo, DEFAULT_CONFIG.toapisVideo),
@@ -332,7 +334,7 @@ export function normalizeConfig(input) {
332
334
  customBaseUrl: asString(raw.customBaseUrl, DEFAULT_CONFIG.customBaseUrl).replace(/\/+$/, ""),
333
335
  customApiKey: asString(raw.customApiKey, DEFAULT_CONFIG.customApiKey),
334
336
  customModel: asString(raw.customModel, DEFAULT_CONFIG.customModel),
335
- customSize: asString(raw.customSize, DEFAULT_CONFIG.customSize),
337
+ customSize: asString(raw.customSize, DEFAULT_CONFIG.customSize).trim() || DEFAULT_CONFIG.customSize,
336
338
  customNegativePrompt: asString(raw.customNegativePrompt, DEFAULT_CONFIG.customNegativePrompt),
337
339
  customSteps: asInt(raw.customSteps, DEFAULT_CONFIG.customSteps, 1, 150),
338
340
  // 上限放到 30:有些后端把 CFG 当纯缩放用;下限 0 = 完全不看提示词(罕见但合法)。
@@ -347,7 +349,7 @@ export function normalizeConfig(input) {
347
349
  arkBaseUrl: asString(raw.arkBaseUrl, DEFAULT_CONFIG.arkBaseUrl).replace(/\/+$/, ""),
348
350
  arkModel: asString(raw.arkModel, DEFAULT_CONFIG.arkModel),
349
351
  arkRedrawModel: asString(raw.arkRedrawModel, DEFAULT_CONFIG.arkRedrawModel),
350
- arkSize: asString(raw.arkSize, DEFAULT_CONFIG.arkSize),
352
+ arkSize: asString(raw.arkSize, DEFAULT_CONFIG.arkSize).trim() || DEFAULT_CONFIG.arkSize,
351
353
  arkWatermark: asBool(raw.arkWatermark, DEFAULT_CONFIG.arkWatermark),
352
354
  arkTimeoutMs: asInt(raw.arkTimeoutMs, DEFAULT_CONFIG.arkTimeoutMs, 10000, 900000),
353
355
  minimaxApiKey: asString(raw.minimaxApiKey, DEFAULT_CONFIG.minimaxApiKey),
@@ -397,6 +399,7 @@ export function normalizeConfig(input) {
397
399
  fillRatio: asNumber(raw.fillRatio, DEFAULT_CONFIG.fillRatio, 0.5, 1),
398
400
  bottomMargin: asInt(raw.bottomMargin, DEFAULT_CONFIG.bottomMargin, 0, 64),
399
401
  cropInset: asNumber(raw.cropInset, DEFAULT_CONFIG.cropInset, 0, 0.2),
402
+ keyColor: normalizeKeyColor(raw.keyColor, DEFAULT_CONFIG.keyColor),
400
403
  keyLow,
401
404
  keyHigh,
402
405
  despill: asNumber(raw.despill, DEFAULT_CONFIG.despill, 0, 1),
@@ -358,6 +358,39 @@ function patchLoadImage(node, name) {
358
358
  }
359
359
  return touched;
360
360
  }
361
+ /**
362
+ * 没写 `{{width}}` / `{{height}}` 时的兜底:直接改空 latent 节点的宽高。
363
+ *
364
+ * 这是「改了尺寸也不生效」的常见原因:用户从 ComfyUI 导出的 API 工作流里,
365
+ * `EmptyLatentImage` 的宽高是写死的数字,而插件只替换占位符、不碰写死的值。
366
+ * 只改**本身是数字**的输入(连线的输入是数组,跳过),并且只认 `Empty*`
367
+ * 这一类节点,避免把放大节点 / 参考图尺寸一起改掉。
368
+ */
369
+ function patchLatentSize(node, width, height) {
370
+ if (Array.isArray(node))
371
+ return node.some((item) => patchLatentSize(item, width, height));
372
+ if (node === null || typeof node !== "object")
373
+ return false;
374
+ const record = node;
375
+ let touched = false;
376
+ const classType = typeof record.class_type === "string" ? record.class_type : "";
377
+ const inputs = record.inputs;
378
+ if (/empty/i.test(classType) && inputs !== null && typeof inputs === "object") {
379
+ if (typeof inputs.width === "number" || (typeof inputs.width === "string" && /^\d+$/.test(inputs.width))) {
380
+ inputs.width = width;
381
+ touched = true;
382
+ }
383
+ if (typeof inputs.height === "number" || (typeof inputs.height === "string" && /^\d+$/.test(inputs.height))) {
384
+ inputs.height = height;
385
+ touched = true;
386
+ }
387
+ }
388
+ for (const value of Object.values(record)) {
389
+ if (patchLatentSize(value, width, height))
390
+ touched = true;
391
+ }
392
+ return touched;
393
+ }
361
394
  function comfyOutputImages(outputs) {
362
395
  const found = [];
363
396
  if (outputs === null || typeof outputs !== "object")
@@ -431,6 +464,16 @@ async function generateComfyUi(request, context) {
431
464
  if (imageNames.length > 0 && !used.has("image")) {
432
465
  patchLoadImage(workflow, imageNames[0]);
433
466
  }
467
+ /**
468
+ * 工作流里没写 width / height 占位符时,把尺寸写进空 latent 节点 —— 否则
469
+ * 用户在设置里改输出尺寸,ComfyUI 仍然按工作流里写死的值出图(典型表现:
470
+ * 「改了也不行,永远 1254×1254」)。
471
+ */
472
+ if (!used.has("width") || !used.has("height")) {
473
+ const size = parseSizeSpec(request.size);
474
+ if (size !== undefined)
475
+ patchLatentSize(workflow, size.width, size.height);
476
+ }
434
477
  const clientId = `gmm-${Date.now().toString(36)}-${Math.floor(Math.random() * 1e6).toString(36)}`;
435
478
  const queued = await fetchOrThrow(joinUrl(base, "/prompt"), {
436
479
  method: "POST",
package/lib/directions.js CHANGED
@@ -25,6 +25,7 @@
25
25
  * 4. upLeft / upRight ← back
26
26
  * 5. left / right ← front + back
27
27
  */
28
+ import { DEFAULT_KEY_COLOR, applyKeyColorToPrompt } from "./keycolor.js";
28
29
  /** 把任意输入规整成提示词语言;认不出来的一律按中文。 */
29
30
  export function normalizePromptLang(value) {
30
31
  return typeof value === "string" && value.trim().toLowerCase().startsWith("en") ? "en" : "zh";
@@ -266,19 +267,24 @@ const TEMPLATES = {
266
267
  * 英文界面下把中文提示词发出去,模型照样能画,但用户读不懂自己在调什么。
267
268
  * @param lang - 目标语言;省略按中文。
268
269
  */
269
- export function defaultPrompts(lang = "zh") {
270
+ export function defaultPrompts(lang = "zh", keyColor = DEFAULT_KEY_COLOR) {
270
271
  const template = TEMPLATES[lang] ?? TEMPLATES.zh;
272
+ const colorLang = lang === "en" ? "en" : "zh";
271
273
  const images = {};
272
274
  for (const direction of DIRECTIONS) {
273
275
  const facing = lang === "en" ? direction.facingEn : direction.facing;
274
276
  const visibility = lang === "en" ? direction.visibilityEn : direction.visibility;
275
- images[direction.key] = fillImagePrompt(template.image, facing, visibility);
277
+ images[direction.key] = applyKeyColorToPrompt(fillImagePrompt(template.image, facing, visibility), keyColor, colorLang);
276
278
  }
277
- return { images, video: template.video, turn: template.turn };
279
+ return {
280
+ images,
281
+ video: applyKeyColorToPrompt(template.video, keyColor, colorLang),
282
+ turn: applyKeyColorToPrompt(template.turn, keyColor, colorLang)
283
+ };
278
284
  }
279
285
  /** 把八方向默认提示词装配成一张表(每个方向一份,可单独编辑)。 */
280
- export function defaultImagePrompts(lang = "zh") {
281
- return defaultPrompts(lang).images;
286
+ export function defaultImagePrompts(lang = "zh", keyColor = DEFAULT_KEY_COLOR) {
287
+ return defaultPrompts(lang, keyColor).images;
282
288
  }
283
289
  /**
284
290
  * 把「还是内置默认值」的提示词换成目标语言的默认值。
@@ -289,9 +295,9 @@ export function defaultImagePrompts(lang = "zh") {
289
295
  *
290
296
  * @returns 是否真的改了——没改就别写盘。
291
297
  */
292
- export function localizePrompts(prompts, lang) {
293
- const target = defaultPrompts(lang);
294
- const other = defaultPrompts(lang === "en" ? "zh" : "en");
298
+ export function localizePrompts(prompts, lang, keyColor = DEFAULT_KEY_COLOR) {
299
+ const target = defaultPrompts(lang, keyColor);
300
+ const other = defaultPrompts(lang === "en" ? "zh" : "en", keyColor);
295
301
  let changed = false;
296
302
  for (const key of DIRECTION_KEYS) {
297
303
  const current = prompts.images?.[key];
@@ -322,3 +328,58 @@ export function localizePrompts(prompts, lang) {
322
328
  }
323
329
  return changed;
324
330
  }
331
+ /**
332
+ * 把项目里**所有**仍是内置默认句式的提示词换成目标底色。
333
+ *
334
+ * 与 `localizePrompts` 是同一套「只认逐字等于默认值」的思路,只是维度从语言
335
+ * 换成了背景色。用户手改过一句,就一个字都不动;老项目里存的「纯绿幕 #00FF00」
336
+ * 会在下次读取 / 生成时自动变成新配色。
337
+ *
338
+ * 中英两种句式都跑一遍:项目可能是在英文界面下建的,也可能中途切过语言。
339
+ */
340
+ export function applyKeyColorToPrompts(prompts, keyColor) {
341
+ let changed = false;
342
+ const apply = (text) => {
343
+ const zh = applyKeyColorToPrompt(text, keyColor, "zh");
344
+ return applyKeyColorToPrompt(zh, keyColor, "en");
345
+ };
346
+ if (prompts.images !== undefined) {
347
+ for (const key of DIRECTION_KEYS) {
348
+ const current = prompts.images[key];
349
+ if (typeof current !== "string")
350
+ continue;
351
+ const next = apply(current);
352
+ if (next !== current) {
353
+ prompts.images[key] = next;
354
+ changed = true;
355
+ }
356
+ }
357
+ }
358
+ if (typeof prompts.video === "string") {
359
+ const next = apply(prompts.video);
360
+ if (next !== prompts.video) {
361
+ prompts.video = next;
362
+ changed = true;
363
+ }
364
+ }
365
+ if (typeof prompts.turn === "string") {
366
+ const next = apply(prompts.turn);
367
+ if (next !== prompts.turn) {
368
+ prompts.turn = next;
369
+ changed = true;
370
+ }
371
+ }
372
+ if (prompts.videoPerDirection !== undefined && prompts.videoPerDirection !== null) {
373
+ for (const key of Object.keys(prompts.videoPerDirection)) {
374
+ const current = prompts.videoPerDirection[key];
375
+ if (typeof current !== "string")
376
+ continue;
377
+ const next = apply(current);
378
+ if (next !== current) {
379
+ prompts.videoPerDirection[key] = next;
380
+ changed = true;
381
+ }
382
+ }
383
+ }
384
+ return changed;
385
+ }
@@ -0,0 +1,185 @@
1
+ /**
2
+ * 位图上的极简绘制原语(Agent 检查图 / 网格 / 标记叠加用)。
3
+ *
4
+ * 这里只做「像素画布上画线 / 圆 / 菱形 / 数字」这几件事,不参与地图几何:
5
+ * 坐标由 `maprender` / `isorender` 从宿主计划算好,本文件只负责落像素。
6
+ *
7
+ * 为什么不用 canvas:宿主半区没有 DOM;PNG 导出走的是同一套 RGBA 缓冲区,
8
+ * 预览与导出必须共享同一条路径。数字用内置 3×5 点阵,中文名不画在图上
9
+ * (几十个中文名字常驻会糊成一片,界面悬停看名字即可)。
10
+ */
11
+ function clampByte(value) {
12
+ return Math.max(0, Math.min(255, Math.round(value)));
13
+ }
14
+ function clampAlpha(value) {
15
+ return Math.max(0, Math.min(1, value));
16
+ }
17
+ /** source-over 混合一个像素;越界直接忽略。 */
18
+ export function blendPixel(bitmap, x, y, color, alpha = 1) {
19
+ const px = Math.round(x);
20
+ const py = Math.round(y);
21
+ if (px < 0 || py < 0 || px >= bitmap.width || py >= bitmap.height)
22
+ return;
23
+ const a = clampAlpha(alpha);
24
+ if (a <= 0)
25
+ return;
26
+ const index = (py * bitmap.width + px) * 4;
27
+ const dst = bitmap.rgba;
28
+ const da = dst[index + 3] / 255;
29
+ const outA = a + da * (1 - a);
30
+ if (outA <= 0)
31
+ return;
32
+ const mix = (source, target) => clampByte((source * a + target * da * (1 - a)) / outA);
33
+ dst[index] = mix(color[0], dst[index]);
34
+ dst[index + 1] = mix(color[1], dst[index + 1]);
35
+ dst[index + 2] = mix(color[2], dst[index + 2]);
36
+ dst[index + 3] = clampByte(outA * 255);
37
+ }
38
+ export function fillRect(bitmap, x, y, width, height, color, alpha = 1) {
39
+ const x0 = Math.max(0, Math.floor(x));
40
+ const y0 = Math.max(0, Math.floor(y));
41
+ const x1 = Math.min(bitmap.width, Math.ceil(x + width));
42
+ const y1 = Math.min(bitmap.height, Math.ceil(y + height));
43
+ for (let py = y0; py < y1; py++)
44
+ for (let px = x0; px < x1; px++)
45
+ blendPixel(bitmap, px, py, color, alpha);
46
+ }
47
+ export function strokeRect(bitmap, x, y, width, height, color, alpha = 1, thickness = 1) {
48
+ const t = Math.max(1, Math.round(thickness));
49
+ fillRect(bitmap, x, y, width, t, color, alpha);
50
+ fillRect(bitmap, x, y + height - t, width, t, color, alpha);
51
+ fillRect(bitmap, x, y, t, height, color, alpha);
52
+ fillRect(bitmap, x + width - t, y, t, height, color, alpha);
53
+ }
54
+ /** Bresenham 直线,厚度用方形刷子近似。 */
55
+ export function drawLine(bitmap, x0, y0, x1, y1, color, alpha = 1, thickness = 1) {
56
+ let ax = Math.round(x0);
57
+ let ay = Math.round(y0);
58
+ const bx = Math.round(x1);
59
+ const by = Math.round(y1);
60
+ const dx = Math.abs(bx - ax);
61
+ const dy = Math.abs(by - ay);
62
+ const sx = ax < bx ? 1 : -1;
63
+ const sy = ay < by ? 1 : -1;
64
+ let err = dx - dy;
65
+ const t = Math.max(1, Math.round(thickness));
66
+ const half = Math.floor((t - 1) / 2);
67
+ while (true) {
68
+ fillRect(bitmap, ax - half, ay - half, t, t, color, alpha);
69
+ if (ax === bx && ay === by)
70
+ break;
71
+ const e2 = err * 2;
72
+ if (e2 > -dy) {
73
+ err -= dy;
74
+ ax += sx;
75
+ }
76
+ if (e2 < dx) {
77
+ err += dx;
78
+ ay += sy;
79
+ }
80
+ }
81
+ }
82
+ export function fillCircle(bitmap, cx, cy, radius, color, alpha = 1) {
83
+ const r = Math.max(0, radius);
84
+ const x0 = Math.floor(cx - r);
85
+ const x1 = Math.ceil(cx + r);
86
+ const y0 = Math.floor(cy - r);
87
+ const y1 = Math.ceil(cy + r);
88
+ for (let y = y0; y <= y1; y++) {
89
+ for (let x = x0; x <= x1; x++) {
90
+ const dx = x - cx;
91
+ const dy = y - cy;
92
+ if (dx * dx + dy * dy <= r * r)
93
+ blendPixel(bitmap, x, y, color, alpha);
94
+ }
95
+ }
96
+ }
97
+ export function strokeCircle(bitmap, cx, cy, radius, color, alpha = 1, thickness = 1) {
98
+ const r = Math.max(0, radius);
99
+ const inner = Math.max(0, r - Math.max(1, thickness));
100
+ const x0 = Math.floor(cx - r);
101
+ const x1 = Math.ceil(cx + r);
102
+ const y0 = Math.floor(cy - r);
103
+ const y1 = Math.ceil(cy + r);
104
+ for (let y = y0; y <= y1; y++) {
105
+ for (let x = x0; x <= x1; x++) {
106
+ const dx = x - cx;
107
+ const dy = y - cy;
108
+ const d2 = dx * dx + dy * dy;
109
+ if (d2 <= r * r && d2 >= inner * inner)
110
+ blendPixel(bitmap, x, y, color, alpha);
111
+ }
112
+ }
113
+ }
114
+ /** 2:1 菱形(等距地格 / 地图 cell 轮廓)。 */
115
+ export function fillDiamond(bitmap, cx, cy, rx, ry, color, alpha = 1) {
116
+ if (rx <= 0 || ry <= 0)
117
+ return;
118
+ for (let dy = -ry; dy <= ry; dy++) {
119
+ const half = rx * (1 - Math.abs(dy) / ry);
120
+ const x0 = Math.round(cx - half);
121
+ const x1 = Math.round(cx + half);
122
+ for (let x = x0; x <= x1; x++)
123
+ blendPixel(bitmap, x, cy + dy, color, alpha);
124
+ }
125
+ }
126
+ export function strokeDiamond(bitmap, cx, cy, rx, ry, color, alpha = 1, thickness = 1) {
127
+ drawLine(bitmap, cx - rx, cy, cx, cy - ry, color, alpha, thickness);
128
+ drawLine(bitmap, cx, cy - ry, cx + rx, cy, color, alpha, thickness);
129
+ drawLine(bitmap, cx + rx, cy, cx, cy + ry, color, alpha, thickness);
130
+ drawLine(bitmap, cx, cy + ry, cx - rx, cy, color, alpha, thickness);
131
+ }
132
+ /** 3×5 点阵数字;只画 0-9,其他字符留空。 */
133
+ const DIGITS = {
134
+ "0": ["111", "101", "101", "101", "111"],
135
+ "1": ["010", "110", "010", "010", "111"],
136
+ "2": ["111", "001", "111", "100", "111"],
137
+ "3": ["111", "001", "111", "001", "111"],
138
+ "4": ["101", "101", "111", "001", "001"],
139
+ "5": ["111", "100", "111", "001", "111"],
140
+ "6": ["111", "100", "111", "101", "111"],
141
+ "7": ["111", "001", "010", "010", "010"],
142
+ "8": ["111", "101", "111", "101", "111"],
143
+ "9": ["111", "101", "111", "001", "111"]
144
+ };
145
+ /**
146
+ * 以 (cx,cy) 为中心画一串数字。`height` 是字高(像素),宽度按 3:5 推。
147
+ * 返回实际绘制宽度,方便调用方排版。
148
+ */
149
+ export function drawDigits(bitmap, text, cx, cy, height, color, alpha = 1) {
150
+ const chars = String(text).split("").filter((char) => DIGITS[char] !== undefined);
151
+ if (chars.length === 0)
152
+ return 0;
153
+ const scale = Math.max(1, Math.floor(Math.max(1, height) / 5));
154
+ const glyphWidth = 3 * scale;
155
+ const gap = scale;
156
+ const total = chars.length * glyphWidth + (chars.length - 1) * gap;
157
+ let x = Math.round(cx - total / 2);
158
+ const y = Math.round(cy - (5 * scale) / 2);
159
+ for (const char of chars) {
160
+ const rows = DIGITS[char];
161
+ for (let row = 0; row < 5; row++) {
162
+ for (let col = 0; col < 3; col++) {
163
+ if (rows[row][col] === "1")
164
+ fillRect(bitmap, x + col * scale, y + row * scale, scale, scale, color, alpha);
165
+ }
166
+ }
167
+ x += glyphWidth + gap;
168
+ }
169
+ return total;
170
+ }
171
+ /** 棋盘格背景(透明图在聊天里不容易看清;检查图默认铺一层很淡的格)。 */
172
+ export function checkerBackground(bitmap, size = 8, light = [244, 244, 244], dark = [224, 224, 224]) {
173
+ const cell = Math.max(1, Math.round(size));
174
+ for (let y = 0; y < bitmap.height; y++) {
175
+ const rowDark = Math.floor(y / cell) % 2 === 1;
176
+ for (let x = 0; x < bitmap.width; x++) {
177
+ const color = (Math.floor(x / cell) % 2 === 1) !== rowDark ? light : dark;
178
+ const index = (y * bitmap.width + x) * 4;
179
+ bitmap.rgba[index] = color[0];
180
+ bitmap.rgba[index + 1] = color[1];
181
+ bitmap.rgba[index + 2] = color[2];
182
+ bitmap.rgba[index + 3] = 255;
183
+ }
184
+ }
185
+ }
package/lib/imagegen.js CHANGED
@@ -16,11 +16,12 @@ import { mkdir, readFile, rm, stat, writeFile } from "node:fs/promises";
16
16
  import { basename, join, resolve, sep } from "node:path";
17
17
  import { randomUUID } from "node:crypto";
18
18
  import { imageJobsRoot, loadConfig } from "./config.js";
19
- import { generateImageWithProvider, imageModelOf, imageSizeOf, imageWatermarkOf, assertImageProviderReady, imageUsesConfiguredSize } from "./imageprovider.js";
19
+ import { generateImageWithProvider, imageModelOf, imageSizeOf, imageWatermarkOf, assertImageProviderReady } from "./imageprovider.js";
20
20
  import { decodeToRgba, mimeOf, toDataUri } from "./media.js";
21
21
  import { keyGreen } from "./chroma.js";
22
22
  import { encodePng } from "./png.js";
23
23
  import { appendJobLog, messageOf, readJson, writeJsonAtomic } from "./jsonio.js";
24
+ import { normalizeKeyColor } from "./keycolor.js";
24
25
  const JOB_ID_PATTERN = /^i[a-z0-9]{4,40}$/;
25
26
  export function imageJobDir(id) {
26
27
  return join(imageJobsRoot(), id);
@@ -63,6 +64,7 @@ export async function createImageJob(name) {
63
64
  },
64
65
  keying: {
65
66
  enabled: false,
67
+ keyColor: config.keyColor,
66
68
  keyLow: config.keyLow,
67
69
  keyHigh: config.keyHigh,
68
70
  despill: config.despill,
@@ -154,6 +156,8 @@ function normalizeImageJob(raw) {
154
156
  },
155
157
  keying: {
156
158
  enabled: raw?.keying?.enabled === true,
159
+ // 老任务没有这个字段:留空,抠像时回落到当前全局配置。
160
+ keyColor: typeof raw?.keying?.keyColor === "string" ? normalizeKeyColor(raw.keying.keyColor) : "",
157
161
  keyLow: num(raw?.keying?.keyLow, 14),
158
162
  keyHigh: num(raw?.keying?.keyHigh, 80),
159
163
  despill: num(raw?.keying?.despill, 0.65),
@@ -165,6 +169,7 @@ function normalizeImageJob(raw) {
165
169
  log: Array.isArray(raw?.log) ? raw.log.slice(-200) : []
166
170
  };
167
171
  }
172
+ /** 归一化时没有配置可读;用默认绿,后续生成时仍会跟随配置。 */
168
173
  function num(value, fallback) {
169
174
  const n = typeof value === "number" ? value : Number.parseFloat(String(value ?? ""));
170
175
  return Number.isFinite(n) ? n : fallback;
@@ -212,12 +217,17 @@ export async function generateImageItem(jobId, index) {
212
217
  assertImageProviderReady(config);
213
218
  // 生图模型同样是全局设置(设置 → 游戏素材大师 → 生图后端),任务只跟随、不覆盖。
214
219
  job.settings.model = imageModelOf(config);
215
- // 自定义后端的尺寸是全局参数(任务上的 size 是火山方舟时代的遗留),跟着配置走。
216
- if (imageUsesConfiguredSize(config))
217
- job.settings.size = imageSizeOf(config);
220
+ /**
221
+ * 输出尺寸是**全局设置**(和生图模型同一条思路):所有模块 / 所有后端共用。
222
+ *
223
+ * 历史坑:自定义 / ToAPIs 后端会覆盖任务上的 size,火山方舟却保留任务级副本,
224
+ * 于是「改了设置里的尺寸」在旧任务上永远不生效 —— 用户看到的就是「总是同一个尺寸」。
225
+ * 现在任务只跟随、不覆盖;界面上的尺寸输入框直接改全局配置。
226
+ */
227
+ job.settings.size = imageSizeOf(config);
218
228
  const item = job.items[index] ?? { index, status: "empty", source: "generated" };
219
229
  job.items[index] = { ...item, status: "running", error: undefined };
220
- appendJobLog(job.log, "info", `开始生成第 ${index + 1} 张`);
230
+ appendJobLog(job.log, "info", `开始生成第 ${index + 1} 张(尺寸 ${job.settings.size})`);
221
231
  await writeImageJob(job);
222
232
  try {
223
233
  const refs = await Promise.all(job.refs.map((ref) => toDataUri(imageAssetPath(jobId, ref.file), mimeOf(ref.file))));
@@ -267,8 +277,10 @@ export async function keyItem(job, index) {
267
277
  const item = job.items[index];
268
278
  if (item?.file === undefined)
269
279
  return;
280
+ const config = await loadConfig();
270
281
  const decoded = await decodeToRgba(imageAssetPath(job.id, item.file), 2048);
271
282
  const result = keyGreen(decoded.rgba, decoded.width, decoded.height, {
283
+ keyColor: job.keying.keyColor || config.keyColor,
272
284
  keyLow: job.keying.keyLow,
273
285
  keyHigh: job.keying.keyHigh,
274
286
  despill: job.keying.despill,
@@ -15,8 +15,13 @@ import { assertToapisReady, generateToapisImage } from "./toapis.js";
15
15
  import { generateImage } from "./ark.js";
16
16
  import { CUSTOM_PROTOCOL_DEFAULTS, loadConfig } from "./config.js";
17
17
  import { CustomImageError, generateCustomImage } from "./customimage.js";
18
- /** Non-Ark backends take their size from their own provider settings. */
19
- export function imageUsesConfiguredSize(config) { return config.imageProvider !== "ark"; }
18
+ /**
19
+ * 所有后端都使用同一份全局输出尺寸。
20
+ *
21
+ * 历史行为是「Ark 保留任务级尺寸、自定义后端只读全局」,导致同一个设置页里
22
+ * 改尺寸时好时坏;现在统一成全局参数。保留这个函数是为了兼容旧的调用方 / 自检。
23
+ */
24
+ export function imageUsesConfiguredSize(_config) { return true; }
20
25
  /** Only Ark supports a separate redraw model; other backends retain their selected model. */
21
26
  export function imageRedrawModelOf(config) {
22
27
  return config.imageProvider === "ark" ? config.arkRedrawModel.trim() || config.arkModel : imageModelOf(config);