mirror of
https://github.com/Nexoniarz/YAPF.git
synced 2026-11-02 20:44:27 +00:00
yapf.load_texture / decode_texture expose every surface and the texture description; rgba_float() for display (blocks decoded, 16-bit / float kept). Blender imports 16-bit / HDR as float images packed as EXR, decodes GPU blocks, follows the normal-map convention (DirectX flip, Z rebuilt for XY normals). Errors say why. Tested in Blender 4.4.3. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DVrVthWN8GsmgHGUhhsCYm
1.6 KiB
1.6 KiB
yapf.py — YAPF in Python
import yapf
img = yapf.load("texture.yapf") # or yapf.decode(data)
print(img.width, img.height, img.channels, img.mip_levels)
img.pixels # bytes, rows top to bottom
yapf.save("copy.yapf", img) # or yapf.encode(img) -> bytes
yapf.save("new.yapf", yapf.Image(w, h, 4, rgba_bytes))
It uses the C library through ctypes when it finds one:
- the file named by the
YAPF_LIBRARYenvironment variable, libyapf.so/libyapf.dylib/yapf.dllnext toyapf.py, or inlib/<platform>/beside it (e.g.lib/windows-x64/yapf.dll),- the system library path (
sudo make installinstalls one).
Without the library it falls back to a pure-Python decoder that needs
numpy (decoding only; about 1.4 s for a 4K image). yapf.backend()
tells you which one is in use.
Example: YAPF_LIBRARY=../../build/libyapf.so python3 example.py ../../other/YAPF.YAPF
Textures (YAPF 2)
tex = yapf.load_texture("albedo.yapf") # any v1 / v2 file, needs the C library
tex.payload, tex.format, tex.sample, tex.channels, tex.mip_levels
tex.shape, tex.layers, tex.frames, tex.channel_map, tex.normal, tex.notes
raw = tex.surface(frame=0, layer=0, face=0, mip=0) # bytes as stored (GPU blocks / samples)
rgba = tex.rgba_float() # numpy float32 (h, w, 4) for display
yapf.load / yapf.decode still return 8-bit images; on a texture they
cannot represent they raise YapfError saying so. Errors name the
reason (damaged, truncated, not YAPF, newer version).