39 lines
2.4 KiB
Python
39 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Measure candidate tile seams against unchanged installed neighbours; no image edits."""
|
|
import argparse,json,re
|
|
from pathlib import Path
|
|
from PIL import Image,ImageChops,ImageStat
|
|
|
|
def edge_difference(a,b,axis):
|
|
if a.size!=b.size or axis not in ['x','y']:raise ValueError('Matching dimensions and explicit axis required')
|
|
w,h=a.size
|
|
aa=a.crop((w-1,0,w,h) if axis=='x' else (0,h-1,w,h)).convert('RGB')
|
|
bb=b.crop((0,0,1,h) if axis=='x' else (0,0,w,1)).convert('RGB')
|
|
delta=ImageChops.difference(aa,bb);stats=ImageStat.Stat(delta)
|
|
return {'mean_rgb_delta':sum(stats.mean)/3,'maximum_channel_delta':max(x[1] for x in stats.extrema)}
|
|
|
|
def run(root):
|
|
rows=json.loads((root/'candidate-assets.json').read_text());candidates={}
|
|
for r in rows:
|
|
m=re.fullmatch(r'world/minimaps/azeroth/map(\d+)_(\d+)\.blp',r['path'])
|
|
if not m:raise ValueError('Terrain seam audit requires terrain candidates')
|
|
candidates[int(m[1]),int(m[2])]=Path(r['file'])
|
|
def before(tile):return root/f'native-minimaps/world/minimaps/azeroth/map{tile[0]}_{tile[1]}.blp'
|
|
def read(path):
|
|
im=Image.open(path);im.load();return im.convert('RGB')
|
|
seams=[];missing=[];seen=set()
|
|
for x,y in sorted(candidates):
|
|
for a,b,axis in [((x,y),(x+1,y),'x'),((x-1,y),(x,y),'x'),((x,y),(x,y+1),'y'),((x,y-1),(x,y),'y')]:
|
|
key=(a,b)
|
|
if key in seen:continue
|
|
seen.add(key)
|
|
if not before(a).exists() or not before(b).exists():missing.append([a,b]);continue
|
|
old=edge_difference(read(before(a)),read(before(b)),axis)
|
|
new=edge_difference(read(candidates.get(a,before(a))),read(candidates.get(b,before(b))),axis)
|
|
seams.append({'a':a,'b':b,'axis':axis,'candidate_boundary':(a in candidates)!=(b in candidates),'before':old,'after':new,'mean_delta_increase':new['mean_rgb_delta']-old['mean_rgb_delta']})
|
|
report={'seams':seams,'missing_neighbours':missing,'scope':'Encoded top-mip RGB edge discontinuity; reports measurements, not a visual approval threshold'}
|
|
(root/'seams.json').write_text(json.dumps(report,indent=2)+'\n')
|
|
print('Seams',len(seams),'missing',len(missing),'worst mean increase',round(max(x['mean_delta_increase'] for x in seams),3))
|
|
if __name__=='__main__':
|
|
p=argparse.ArgumentParser(description=__doc__);p.add_argument('root',type=Path);run(p.parse_args().root)
|