Files
aigc-home/docs/hel-892/resize-compare-document-evidence/build_definition.py
T

663 lines
27 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""One source-bound interpolation comparison document; no execution contract."""
from __future__ import annotations
import hashlib
import json
from pathlib import Path
REPO = Path(__file__).resolve().parents[3]
OUT = Path(__file__).resolve().parent
REF = OUT.parent / "resize-compare-reference"
PATHS = [
"example_ComfyUI_workflows/0-基础处理:图像合并-音频分离-视频截取合并-图像视频放大/高清放大/图像放大比较.json"
]
def canonical(v):
return json.dumps(v, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode()
def build(index=0):
raw = (REPO / PATHS[index]).read_bytes()
g = json.loads(raw)
entries = json.loads((REF / "sources.json").read_bytes())["sources"]
refs = []
def ref(key, file, first, last, claim):
e = next(e for e in entries if e["id"] == key and e["file"] == file)
refs.append(
{
**e,
"local_file": "../resize-compare-reference/" + e["local_file"],
"lines": [first, last],
"claim": claim,
}
)
return len(refs) - 1
image = ref(
"load",
"nodes.py",
1626,
1700,
"准确core0.3.50 LoadImage枚举、素材检查和IMAGE/MASK;素材本身未取得",
)
ref("load", "nodes.py", 1957, 1959, "准确core0.3.50 LoadImage注册")
scale = ref(
"core",
"nodes.py",
1778,
1806,
"准确core0.3.65 ImageScale具名schema、零尺寸条件和common_upscale调用",
)
preview = ref(
"core",
"nodes.py",
1561,
1628,
"PreviewImage继承SaveImage,无数据出口,只临时PNG及ui.images描述符",
)
ref("core", "nodes.py", 1957, 1967, "准确核心节点注册")
maximum = ref(
"core", "nodes.py", 52, 52, "MAX_RESOLUTION=16384;KJ从宿主nodes导入,不证明真实宿主版本"
)
util = ref(
"core",
"comfy/utils.py",
858,
900,
"lanczos经8bit PIL重采样与common_upscale裁剪/插值;不执行媒体",
)
kj = ref(
"kj",
"nodes/image_nodes.py",
2376,
2502,
"KJ准确schema与resize实现;无mask输入或输出,源接口冲突保留",
)
ref("kj", "nodes/image_nodes.py", 21, 21, "KJ MAX_RESOLUTION来自运行宿主nodes,宿主版本未知")
ref("kj", "__init__.py", 75, 85, "准确KJ ImageResizeKJv2注册")
restore = ref(
"layer",
"py/image_scale_restore_v2.py",
7,
132,
"准确ScaleRestore schema、original_size优先及by_scale/长度分支、最小4像素与返回",
)
aspect = ref(
"layer",
"py/image_scale_by_aspect_ratio_v2.py",
8,
186,
"准确AspectRatio schema、original/custom、None长度不采用、对齐及返回",
)
fit = ref("layer", "py/imagefunc.py", 591, 618, "letterbox居中填色、crop居中裁剪、fill直接伸缩")
rounding = ref("layer", "py/imagefunc.py", 1967, 1973, "向上取整到倍数;不同于KJ向下取整")
ref("layer", "__init__.py", 29, 48, "LayerStyle包逐模块合并注册,未执行")
impact = ref(
"impact",
"modules/impact/logics.py",
239,
255,
"准确8.25.1 ImpactInt整数默认0、范围0到sys.maxsize及原样返回",
)
ref("impact", "__init__.py", 48, 48, "ImpactPack logics导入")
ref("impact", "__init__.py", 259, 259, "ImpactInt注册")
display = ref(
"rgthree",
"py/display_any.py",
6,
50,
"准确发布包DisplayAny接source并只返回ui.text;保存显示文本不是模型参数",
)
displayjs = ref(
"rgthree",
"web/comfyui/display_any.js",
1,
35,
"只读output控件;serializeValue返回空字符串/onExecuted更新",
)
ref("rgthree", "py/constants.py", 2, 5, "Display Any (rgthree)准确命名")
ref("rgthree", "__init__.py", 47, 54, "DisplayAny准确注册")
front = ref(
"frontend",
"src/lib/litegraph/src/LGraphNode.ts",
917,
925,
"仅参考假设frontend1.45.20位置恢复,跳过serialize=false;源无前端版本",
)
ref(
"frontend",
"src/lib/litegraph/src/LGraphNode.ts",
972,
984,
"仅参考假设位置序列化;不证明目标实际恢复",
)
upload = ref(
"frontend",
"src/extensions/core/uploadImage.ts",
10,
40,
"仅参考假设为image_upload节点补IMAGEUPLOAD前端输入,不是后端参数",
)
ref("frontend", "src/scripts/widgets.ts", 305, 308, "仅参考假设IMAGEUPLOAD控件构造入口")
uploadfile = next(e["file"] for e in entries if e["file"].endswith("useImageUploadWidget.ts"))
ref(
"frontend",
uploadfile,
1,
len(
(REF / next(e["local_file"] for e in entries if e["file"] == uploadfile))
.read_text()
.splitlines()
),
"仅参考假设上传控件行为;源保存image原样保留,未上传",
)
for key in ["load", "core", "kj", "layer", "impact", "rgthree", "frontend"]:
e = next(e for e in entries if e["id"] == key and "LICENSE" in e["file"])
ref(
key,
e["file"],
1,
len((REF / e["local_file"]).read_text().splitlines()),
"准确来源许可文本;发布包Git绑定未知,前端仅显式假设",
)
# Entries describe concrete source positions; no named values are fabricated.
specifications = {
1: [
(
"image",
"输入图片文件名",
"未显式指定默认;输入目录图片排序枚举",
"文件名",
"依赖准确运行目录和素材;不存在或校验失败不能加载",
"选择四条缩放链共同的输入图片。当前仅保存文件名,不能推出素材存在或原始宽高。",
image,
),
(
"upload",
"上传控件保存占位",
"后端无upload参数;参考前端自动补控件",
"前端状态",
"保存字符串image;准确宿主前端及扩展恢复未知",
"保留上传控件位置的image占位,它不是第二张图片或后端参数,也不是已完成上传;参考前端serialize=false不恢复此位置,不能把源占位当已恢复参数。",
upload,
),
],
4: [
(
"upscale_method",
"核心重采样方法",
"未显式默认;首选项nearest-exact",
"枚举",
"nearest-exact/bilinear/area/bicubic/lanczos",
"核心分支保存nearest-exact,用最近邻精确模式调整像素;不表示模型超分或画质提升。",
scale,
),
(
"width",
"核心分支宽度缓存",
"512",
"像素",
"INT 0~16384,step1;0按另一轴推算;两轴0直接返回",
"缓存480被11.value经边14覆盖;当前外线480。crop=disabled按请求宽高伸缩,实际像素未测。",
scale,
),
(
"height",
"核心分支高度缓存",
"512",
"像素",
"INT 0~16384,step1;0按另一轴推算",
"缓存720被12.value经边11覆盖;当前外线720,不从保存缓存推实际输出。",
scale,
),
(
"crop",
"核心裁剪开关",
"未显式默认;首选项disabled",
"枚举",
"disabled/center",
"当前disabled不裁剪,按两轴伸缩;center才按中心裁切以匹配比例。",
scale,
),
],
11: [
(
"value",
"共同宽度整数",
"0",
"整数;接宽度时为像素",
"INT 0~sys.maxsize,step1;资源上限另受下游约束",
"保存480原样输出,边9接2.width、边14接4.width;不是所有分支的统一宽度。",
impact,
)
],
12: [
(
"value",
"高度及长度整数",
"0",
"整数;长度输入为像素",
"INT 0~sys.maxsize,step1;不是内存或图像尺寸保证",
(
"保存720;边10接2.height、11接4.height、12接5.scale_by_len"
"gth、13接7.scale_to_length。后两项在当前分支不用于计算尺寸。"
),
impact,
)
],
2: [
(
"width",
"KJ宽度缓存",
"512",
"像素",
"INT 0~宿主MAX_RESOLUTION,step1;宿主未知,core0.3.65参考上限16384",
"缓存480被11.value经边9覆盖;stretch直接缩放,divisible_by再向下对齐。",
kj,
),
(
"height",
"KJ高度缓存",
"512",
"像素",
"INT 0~宿主MAX_RESOLUTION,step1",
"缓存720被12.value经边10覆盖;与480均为16倍数,但未实际输出图片。",
kj,
),
(
"upscale_method",
"KJ重采样方法",
"未显式默认;首选项nearest-exact",
"枚举",
"nearest-exact/bilinear/area/bicubic/lanczos;gpu不支持lanczos",
"保存lanczos且device=cpu;经common_upscale的PIL插值,不是加载超分模型,实际效果未知。",
kj,
),
(
"keep_proportion",
"KJ比例处理",
"源码显式False(与枚举类型不一致);不改写为stretch",
"枚举",
"stretch/resize/pad/pad_edge/crop;保存值有效性与默认冲突分开",
"当前stretch直接按两轴伸缩,不走保比例、填边或裁剪分支;可能改变原图比例,素材宽高未知。",
kj,
),
(
"pad_color",
"KJ填充颜色",
"0, 0, 0",
"RGB文本",
"STRING;仅pad/pad_edge路径调用填边",
"保存黑色0, 0, 0,当前stretch不采用该颜色。",
kj,
),
(
"crop_position",
"KJ裁剪位置",
"center",
"枚举",
"center/top/bottom/left/right;仅crop分支",
"保存center仅在crop决定裁剪起点,当前stretch不裁剪也不采用此位置。",
kj,
),
(
"divisible_by",
"KJ尺寸倍数",
"2",
"像素倍数",
"INT 0~512,step1;>1向下取整,0/1不对齐",
"保存16,width/height分别减去除16余数;当前外接480/720整除,不据此保证运行成功。",
kj,
),
(
"device",
"KJ处理设备",
"schema未显式;首项cpu,函数默认cpu",
"设备枚举",
"cpu/gpu;gpu+lanczos主动抛错",
"保存cpu,把输入副本放CPU处理并返回CPU图像;不证明素材、依赖或设备资源可用。",
kj,
),
],
5: [
(
"scale",
"恢复分支倍率",
"1",
"倍数",
"FLOAT 0.01~100,step0.01;源JSON为int1",
"当前by_scale且original_size未接,按原宽高乘1取int并至少4;不是模型放大,不保证像素完全不变。",
restore,
),
(
"method",
"恢复分支重采样",
"未显式默认;首项lanczos",
"枚举",
"lanczos/bicubic/hamming/bilinear/box/nearest",
"保存lanczos,经PIL RGB resize;是否改善观感未知。",
restore,
),
(
"scale_by",
"恢复分支尺寸方式",
"未显式默认;首项by_scale",
"枚举",
"by_scale/longest/shortest/width/height/total_pixel(kilo pixel)",
"当前by_scale走倍率,不采用scale_by_length。若original_size非空优先使用其两轴,但本图该口未接。",
restore,
),
(
"scale_by_length",
"恢复分支长度缓存",
"1024",
"像素;total_pixel模式为千像素",
"INT 4~99999999,step1;仅长度/面积分支采用",
"缓存720由12.value经边12覆盖为720;当前by_scale不读取它计算尺寸,不能称该支固定720。",
restore,
),
],
7: [
(
"aspect_ratio",
"比例分支目标比例",
"未显式默认;首项original",
"枚举",
"original/custom/1:1/3:2/4:3/16:9/2:3/3:4/9:16",
"保存original从输入宽高取比例;不是custom的1:1。",
aspect,
),
(
"proportional_width",
"自定比例宽",
"1",
"比例份数",
"INT 1~1e8,step1;仅custom读取",
"保存1,当前original不使用该值计算目标比例。",
aspect,
),
(
"proportional_height",
"自定比例高",
"1",
"比例份数",
"INT 1~1e8,step1;仅custom读取",
"保存1,当前original不使用该值,不据两项1声称方图。",
aspect,
),
(
"fit",
"比例分支适配方式",
"未显式默认;首项letterbox",
"枚举",
"letterbox/crop/fill",
"letterbox保比例缩放后居中放入背景画布;两轴分别向上对齐可能产生边框,实际范围依赖原尺寸。",
fit,
),
(
"method",
"比例分支重采样",
"未显式默认;首项lanczos",
"枚举",
"lanczos/bicubic/hamming/bilinear/box/nearest",
"保存lanczos,供适配图片的PIL resize使用,不保证画质。",
aspect,
),
(
"round_to_multiple",
"比例分支倍数对齐",
"未显式默认;首项字符串8",
"像素倍数枚举",
"8/16/32/64/128/256/512/None,全部字符串",
"源保存字符串8而非JSON int;目标宽高各向上取整到8倍数,不是KJ向下取整。",
rounding,
),
(
"scale_to_side",
"比例分支缩放基准",
"未显式默认;首项字符串None",
"枚举",
"None/longest/shortest/width/height/total_pixel(kilo pixel)",
"当前字符串None走原尺寸比例分支,不采用scale_to_length=720;随后仍执行8倍数对齐及letterbox。",
aspect,
),
(
"scale_to_length",
"比例分支长度缓存",
"1024",
"像素;total_pixel模式为千像素",
"INT 4~1e8,step1;按scale_to_side分支读取",
"缓存720由12.value经边13覆盖;当前None分支不用于最终尺寸,不能称720长边。",
aspect,
),
(
"background_color",
"比例分支背景色",
"#000000",
"颜色字符串",
"STRING;letterbox用PIL颜色创建背景",
"保存#000000黑色,在letterbox画布居中贴图时用于未覆盖区域;是否有可见边框依赖原尺寸与对齐。",
fit,
),
],
}
dims = {
13: ("2", "width"),
14: ("2", "height"),
15: ("5", "width"),
16: ("5", "height"),
17: ("7", "width"),
18: ("7", "height"),
}
fields = []
zero = []
for i, n in enumerate(g["nodes"]):
if n["type"] == "PreviewImage":
assert n["widgets_values"] == []
zero.append(
dict(
node_id=str(n["id"]),
class_type=n["type"],
pointer=f"/nodes/{i}/widgets_values",
effect=(
"源保存空[],零位置。图像经准确core0.3.65 PreviewImage写临时PNG并返回"
"ui.images,RETURN_TYPES为空,无图像数据输出;未实跑。"
),
evidence=[preview],
)
)
continue
specs = specifications.get(n["id"])
if n["id"] in dims:
src, dim = dims[n["id"]]
specs = [
(
"output",
"显示" + ("宽度" if dim == "width" else "高度") + "文本",
"前端创建STRING输出框;没有后端output输入",
"显示文本",
"只读前端STRING,序列化返回空字符串;不是实际宽高",
"节点"
+ str(n["id"])
+ "接"
+ src
+ "."
+ dim
+ ",当前保存空字符串;执行后的ui.text才会更新显示,不能把空串当0或已测结果。",
displayjs,
)
]
assert len(specs) == len(n["widgets_values"])
for k, (name, label, default, unit, limits, effect, ev) in enumerate(specs):
ptr = f"/nodes/{i}/widgets_values/{k}"
inp = next(
(j for j, x in enumerate(n["inputs"]) if x.get("widget", {}).get("name") == name),
None,
)
v = n["widgets_values"][k]
field_type = n["inputs"][inp]["type"] if inp is not None else "前端STRING"
link = n["inputs"][inp]["link"] if inp is not None else None
fields.append(
dict(
node_id=str(n["id"]),
scope="root",
class_type=n["type"],
field=name,
label=label,
pointer=ptr,
input_pointer=f"/nodes/{i}/inputs/{inp}" if inp is not None else ptr,
value=v,
json_type=type(v).__name__,
type=field_type,
role="frontend_control"
if name in ["upload", "output"]
else "linked_cache"
if link is not None
else "scalar",
schema_default=default,
unit=unit,
limits=limits,
effect=effect,
execution_note=f"节点{n['id']}保存mode0;源无具名保存表,不制造具名保存值。"
+ (
f"源输入边{link}覆盖该缓存;"
if link is not None
else "该控件无源输入边覆盖;"
)
+ "前端恢复仅参考假设,目标/宿主未知;未构造prompt、未实跑。",
evidence=list(
dict.fromkeys(
[ev, front]
+ ([display] if name == "output" else [])
+ ([util, maximum] if n["id"] in [2, 4] else [])
+ ([aspect] if n["id"] == 7 else [])
)
),
)
)
assert len(fields) == 35 and len(zero) == 4
overview = (
"这张图把同一张图片送到四条缩放链分别预览,并显示三个插件分支的宽高。它没有模型超分节点或比较滑块"
",也没有正式保存节点。480/720只覆盖KJ和核心分支的宽高;另外两支当前不采用外接720长度"
"。素材尺寸、接口恢复与实际效果未知;仅供参考,转换和生成保持关闭。"
)
flow = [
overview,
"17节点/20物理边,全mode0,无子图、无源Note;35标量保存位置含6空字符串与1上传占位,四Preview空[]各为零位置。",
(
"四并行链:1.LoadImage→2.ImageResizeKJv2→3.PreviewImag"
"e;1→4.ImageScale→8.PreviewImage;1→5.ImageScaleRe"
"storeV2→9.PreviewImage;1→7.ImageScaleByAspectRat"
"ioV2→10.PreviewImage。没有比较滑块、模型超分或正式SaveImage。"
),
(
"11.ImpactInt保存480,边9/14分别覆盖2.width/4.width;12保存7"
"20,边10/11分别覆盖2.height/4.height,边12/13分别覆盖5.scale"
"_by_length/7.scale_to_length。缓存仍保留,不构造prompt。"
),
(
"5保存scale为JSON int1但schema为FLOAT;original_size未接,"
"scale_by=by_scale按原宽高乘倍率并至少4像素,不采用外接长度720。只有long"
"est/shortest/width/height/total_pixel分支才采用长度,ori"
"ginal_size若有值则优先。"
),
(
"7保存original与custom宽高1/1,当前用原图比例;scale_to_side是字符"
"串None,故不采用720长度;再将宽高各向上取8倍数。letterbox按比例缩放、居中贴黑底"
",不保证与原图逐像素一致。"
),
(
"2当前stretch/lanczos/cpu,width480、height720经过divis"
"ible_by16向下对齐;pad_color与crop_position在当前stretch不"
"参与。准确KJ源码keep_proportion默认False与枚举不一致,保留原文;gpu+l"
"anczos抛错仅静态条件。"
),
(
"源2保存可选mask输入及第四mask出口,但准确f7eb33ab实现没有mask输入或输出、只"
"有IMAGE/width/height三出口。该接口冲突未修图、不借新版补齐,实际恢复与运行仍未"
"知,转换关闭。"
),
(
"4当前nearest-exact/disabled,直接按请求宽高伸缩;六DisplayAny分"
"别13/14显示2.width/height,15/16显示5.width/height,17/"
"18显示7.width/height。它们保存空文本,仅ui.text更新,不是比较器或测量证据"
"。"
),
(
"未接:1.MASK;源2.mask输入与mask出口;5.mask及original_size输"
"入、mask及original_size出口;7.mask输入、mask及original_si"
"ze出口。3/8/9/10无数据输出。没有模型节点,不编造模型依赖。"
),
(
"准确core0.3.65 PreviewImage继承RETURN_TYPES=(),写temp"
" PNG返回ui.images文件描述符而无result数据出口;不是正式输出保证。图片名只文本"
",实际素材存在/尺寸/设备/内存/像素及效果均未知。"
),
(
"身份分层:LoadImage声明core0.3.50,ImageScale及四Preview声明"
"0.3.65;KJ与LayerStyle按各自完整提交,ImpactPack8.25.1和rgt"
"hree1.0.2510052058固定发布包SHA256,发布包Git绑定未知。源extra只"
"有ds,无frontendVersion;frontend1.45.20仅恢复/序列化参考假设,"
"不称宿主版本。"
),
(
"UE7.1只在源LoadImage和KJ节点properties声明;可连接表、mask接口与实"
"际扩展恢复顺序未知,不重复历史调查。源无widgets_values_named,只有位置与可得"
"inputs.widget.name指针,未制造具名保存值。"
),
(
"旧33块1034位置+25注释逐对象冻结;新增35保存位置/0注释,现34图1069+25仅参考"
"。155停用未检查、定稿0/必要实跑0/新增转换0,145UI仍9参考候选136关闭;case0"
"6排除。"
),
*["原边 root " + json.dumps(e, ensure_ascii=False) for e in g["links"]],
]
versions = [
e["id"] + "→" + e["commit"] for e in json.loads((REF / "identities.json").read_bytes())
]
for key in ["impact", "rgthree", "frontend"]:
e = next(e for e in entries if e["id"] == key)
versions.append(
key
+ "→"
+ e["commit"]
+ (";Git绑定未知" if key != "frontend" else ";仅参考假设1.45.20,源前端未知")
)
return dict(
source_path=PATHS[index],
source_sha1=hashlib.sha1(raw).hexdigest(),
source_sha256=hashlib.sha256(raw).hexdigest(),
canonical_sha256=hashlib.sha256(canonical(g)).hexdigest(),
notice="仅固定来源参考;KJ接口冲突、前端恢复/素材尺寸/设备/实际效果未知,转换关闭、未实跑。",
user_overview=overview,
versions=versions,
counts=dict(
saved_fields=35,
source_nodes=17,
physical_edges=20,
source_notes=0,
history_objects=0,
linked_saved_fields=6,
frontend_only=7,
final_scalars=0,
final_prompt_constructed=False,
),
fields=fields,
sources=refs,
comments=[],
flow=flow,
flow_evidence=list(range(len(refs))),
zero_saved_nodes=zero,
boundaries=[],
steps=[
overview,
"操作1:只读核对四链、输入素材文件名和外线覆盖,保留停用,不上传图片。",
"操作2:区分当前长度未采用与尺寸对齐、KJ接口冲突,先核准确运行定义;不改源或构造prompt。",
"操作3:全量完成并审核前仅读参考说明;实际尺寸、设备及质量仍未测。",
],
)