#!/usr/bin/env python3 # 储藏箱加宽用的贴图(构建时从玩家的游戏文件生成到 Gen/assets/NativeHUD/widestash,不进仓库;wide_stash.py 只拷)。用法:gen_widestash_art.py <原版 RomFS> # 全部做成原包同款 SpA1 v61 = DXT5 + 块线性。不用原始 RGBA(v31):1640×881 的 v31 游戏读出来有成排花点、切两张后大片花屏 # (本机宿主实测;选角页 401×1080 同类问题),而且显存是 DXT5 的 4 倍。 # ① 宽外框 MainPanelBG_Wide:取原包外框(两帧横排,第 1 帧 = 双面板)第 1 帧,在左半标题框中间(帧内 x 348,4 像素对齐) # 把 152..348 这 196 像素的压缩块再拼一份 = 左半宽 196 像素(392 布局单位)。只搬原图压缩块,不重新编码。 # ② 储藏箱底图(个人 / 共享 / 通用):解原图 → 格子区插 4 列、下段两侧花饰之间那整块右移 2 列居中、空出的两段补石纹 → 重新编码; # 宝石 / 材料 / 符文三页:原图两侧本就透明,左右各补 98 像素透明。编码按块取主轴两端为端点:原图本来就是 DXT5,块对齐处基本还原。 # Textures for stash widening (generated at build time from the player's game files into Gen/assets/NativeHUD/widestash, not committed to the repo; wide_stash.py only copies). Usage: gen_widestash_art.py # All made in the original package's SpA1 v61 format = DXT5 + block-linear. Raw RGBA (v31) is not used: a 1640×881 v31 is read by the game with rows of garbage dots, and with large areas of garbage after splitting into two images # (measured on the local host; same kind of problem as the 401×1080 character select page), and it takes 4 times the video memory of DXT5. # ① Wide outer frame MainPanelBG_Wide: take frame 1 of the original package's outer frame (two frames side by side, frame 1 = dual panel), and in the middle of the left half's title box (x 348 within the frame, 4-pixel aligned) # splice in one more copy of the compressed blocks of the 196 pixels 152..348 = left half 196 pixels wider (392 layout units). Only the original compressed blocks are moved, no re-encoding. # ② Stash base images (personal / shared / generic): decode the original → insert 4 columns in the grid area, shift the whole block between the two side ornaments in the lower section right 2 columns to center it, fill the two vacated segments with stone texture → re-encode; # the gem / material / rune pages: the original images are already transparent on both sides, so 98 transparent pixels are added on each side. Encoding takes the two ends of each block's principal axis as endpoints: the originals are already DXT5, so block-aligned areas are essentially restored. import ctypes as C, io, os, struct, subprocess, sys, tempfile import numpy as np from PIL import Image HERE = os.path.dirname(os.path.abspath(__file__)); DM = os.path.join(HERE, '..', '..'); ART = __import__('gen_paths').gen_dir('NativeHUD', 'widestash') sys.path.insert(0, HERE); import touch_layout X0, EX = 348, 196 # 宽外框插入点与插入宽度(像素,都是 4 的倍数) | Wide outer frame insertion point and insertion width (pixels, both multiples of 4) BG = {'StashPanelBG': 'stash/v2/stashpanelbg', 'StashPanelBGPersonal': 'stash/v2/stashpanelbgpersonal', 'StashPanelBGShared': 'stash/v2/stashpanelbgshared'} ADV = {'AdvancedStash_Gems_Console': 'stash/v2/additionalstash/advancedstash_gems_console', 'AdvancedStash_Consumables_Console': 'stash/v2/additionalstash/advancedstash_consumables_console', 'AdvancedStash_Runes_Console': 'stash/v2/additionalstash/advancedstash_runes_console'} # 底图加宽参数(像素,按原图列亮度 / 目测量):cut = 格子区插列处;yb = 格子区下沿(下段起点);mid = 两侧花饰之间那整块(金币框,共享页另有翻页底板)的左右边 # Base image widening parameters (pixels, measured from the original image's column brightness / by eye): cut = column insertion point in the grid area; yb = lower edge of the grid area (start of the lower section); mid = left and right edges of the whole block between the two side ornaments (gold box; the shared page also has a page-turn base plate) SPEC = {'StashPanelBG': dict(cut=133, yb=525, mid=(214, 438)), 'StashPanelBGPersonal': dict(cut=129, yb=515, mid=(216, 428)), 'StashPanelBGShared': dict(cut=129, yb=515, mid=(216, 428))} class Desc(C.Structure): _fields_ = [('target', C.c_int), ('format', C.c_int), ('flags', C.c_int), ('samples', C.c_int), ('width', C.c_uint32), ('height', C.c_uint32), ('depth', C.c_uint32), ('levels', C.c_uint32), ('stride', C.c_uint32), ('pkg_block_h', C.c_int)] class Layout(C.Structure): _fields_ = [('size', C.c_uint64), ('layer_size', C.c_uint64), ('align', C.c_uint32), ('layers', C.c_uint32), ('bpb', C.c_uint32), ('tileH', C.c_uint), ('tileD', C.c_uint)] def lib(): t = tempfile.mkdtemp(); p = os.path.join(t, 'bl.dll' if os.name == 'nt' else 'bl.dylib') win = ['-Wl,/EXPORT:nvn_tex_layout', '-Wl,/EXPORT:nvn_deswizzle', '-Wl,/EXPORT:nvn_swizzle'] if os.name == 'nt' else ['-fPIC'] # 同 romfs_art.py | same as romfs_art.py subprocess.run(['clang', '-O2', '-shared', *win, '-I' + os.path.join(DM, 'gfx', 'nvn'), '-I' + os.path.join(DM, 'gfx', 'tex'), '-o', p, os.path.join(DM, 'gfx', 'tex', 'nvn_deswizzle.c'), os.path.join(DM, 'gfx', 'nvn', 'nvn_tex.c')], check=True) L = C.CDLL(p); L.nvn_tex_layout.argtypes = [C.POINTER(Desc), C.POINTER(Layout)] L.nvn_deswizzle.argtypes = [C.POINTER(Desc), C.c_uint, C.c_uint, C.c_void_p, C.c_void_p, C.c_size_t] L.nvn_swizzle.argtypes = [C.POINTER(Desc), C.c_uint, C.c_uint, C.c_void_p, C.c_size_t, C.c_void_p] return L def orig(romfs, rel): for line in open(os.path.join(romfs, 'data', 'build_manifest.psv'), encoding='utf-8'): f = line.rstrip('\n').split('|') if len(f) >= 11 and f[9].lower().endswith('/ui/controller/panel/' + rel + '.sprite'): return touch_layout._read_entry(romfs, f) raise SystemExit('gen_widestash_art:包里没有 ' + rel) def desc(b, w, h): return Desc(1, 0x44, 0, 0, w, h, 1, 1, 0, b[23] + 1) # 0x44 = DXT5;块高参数取原图头第 23 字节(同解码处) | 0x44 = DXT5; the block height parameter is taken from byte 23 of the original image's header (same as at the decode site) def pack(L, hdr0, lin, w, h, fw, frames=1): """线性 DXT5 块 → 块线性,套原图头(改显示宽、宽、帧数、数据字节数)。 | Linear DXT5 blocks → block-linear, with the original image's header attached (display width, width, frame count, data byte count changed).""" d = desc(hdr0, w, h); lay = Layout(); L.nvn_tex_layout(C.byref(d), C.byref(lay)); dst = C.create_string_buffer(lay.size); src = C.create_string_buffer(lin, len(lin)) assert L.nvn_swizzle(C.byref(d), 0, 0, src, (w + 3) // 4 * 16, dst) == 0 hdr = bytearray(hdr0[:40]); struct.pack_into('nij', c, c); v = np.ones((len(blk), 3)) for _ in range(8): v = np.einsum('nij,nj->ni', cov, v); v /= np.maximum(np.linalg.norm(v, axis=1, keepdims=True), 1e-9) t = np.einsum('npi,ni->np', c, v); e0 = rgb[np.arange(len(blk)), t.argmax(1)]; e1 = rgb[np.arange(len(blk)), t.argmin(1)] def q565(e): r, g, b_ = (np.round(e[:, 0] * 31 / 255).astype(int), np.round(e[:, 1] * 63 / 255).astype(int), np.round(e[:, 2] * 31 / 255).astype(int)); return r << 11 | g << 5 | b_ def un565(c_): return np.stack([(c_ >> 11 & 31) * 255 / 31, (c_ >> 5 & 63) * 255 / 63, (c_ & 31) * 255 / 31], 1) c0, c1 = q565(e0), q565(e1); dm = c0 < c1; c0, c1 = np.where(dm, c1, c0), np.where(dm, c0, c1) p0, p1 = un565(c0), un565(c1); pal = np.stack([p0, p1, (2 * p0 + p1) / 3, (p0 + 2 * p1) / 3], 1) ci = ((rgb[:, :, None, :] - pal[:, None, :, :]) ** 2).sum(-1).argmin(2); ci[c0 == c1] = 0 a0, a1 = al.max(1).round().astype(int), al.min(1).round().astype(int) ap = np.stack([a0, a1] + [((7 - k) * a0 + k * a1) / 7 for k in range(1, 7)], 1); ai = np.abs(al[:, :, None] - ap[:, None, :]).argmin(2); ai[a0 == a1] = 0 out = bytearray() for n in range(len(blk)): ab = sum(int(ai[n, k]) << (3 * k) for k in range(16)); cb = sum(int(ci[n, k]) << (2 * k) for k in range(16)) out += struct.pack('