mirror of
https://github.com/Nexoniarz/YAPF.git
synced 2026-11-03 04:54:26 +00:00
YAPF v1: fast byte-aligned format, SIMD, tools and plugins
Format (version 1, replaces the earlier experimental versions): - per-tile YCoCg-R or subtract-green colour transform, 8-bit modular - 12 row filters per 8-row band (Left, Gradient, Up-right, Up-average, Up 1-8 rows), none with more than a one-add serial dependency - residuals in groups of 8 at the group's width (w bits x 8 = w bytes), 4-bit control codes with repeat-previous-width runs chosen by DP - constant and stored tiles, independent 64x64 tiles, mips, GPU hints - all sizes validated before decoding; corrupt input is rejected Library: - SIMD on by default: SSSE3 (runtime CPUID check; GCC, Clang, MSVC, MinGW) and NEON on ARM64; -DYAPF_NO_SIMD for plain C - yapf_load_memory, yapf_load_mt, yapf_load_memory_mt - 6-10x faster decoding than PNG (stb_image) on one core; -O2 and -O3 builds perform the same - fixes for macOS (sysconf) and the Windows import library exports Tools and integrations: - `yapf` CLI: convert PNG/JPG/TGA/BMP/PSD/GIF <-> YAPF, info, bench, thumbnail, mips - JavaScript and Python bindings (byte-identical to the C encoder) - GIMP 3 plugin: exports the flattened image, optional mipmaps - Blender extension: import (also as plane), export, drag and drop - VS Code preview, Figma plugin, Photoshop scripts, Linux MIME type and thumbnailer - Makefile, updated build.sh / build.bat, tools/build_release.sh - tests/test_yapf.c (784 checks) and bindings/js/test.js Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
b9b8c93a22
commit
2ca726e3af
48 changed files with 14905 additions and 710 deletions
59
extensions/blender/build.py
Normal file
59
extensions/blender/build.py
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Package the Blender extension: python3 extensions/blender/build.py [libs_dir]
|
||||
|
||||
Writes dist/yapf_image-blender.zip, ready for Blender's
|
||||
Edit > Preferences > Get Extensions > Install from Disk.
|
||||
|
||||
libs_dir (optional) holds prebuilt libraries as <platform>/<file>, e.g.
|
||||
linux-x64/libyapf.so, windows-x64/yapf.dll, macos-arm64/libyapf.dylib
|
||||
(tools/build_libs.sh makes them). Without libraries the extension still
|
||||
imports .yapf files using numpy, but cannot export. If no libs_dir is
|
||||
given, a library for this machine is built with `cc` when available.
|
||||
"""
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import zipfile
|
||||
|
||||
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
|
||||
SRC = os.path.join(ROOT, "extensions", "blender", "yapf_image")
|
||||
sys.path.insert(0, os.path.join(ROOT, "bindings", "python"))
|
||||
import yapf # noqa: E402 (for the platform folder name)
|
||||
|
||||
|
||||
def host_lib(tmp):
|
||||
name = {"win32": "yapf.dll", "darwin": "libyapf.dylib"}.get(sys.platform, "libyapf.so")
|
||||
out = os.path.join(tmp, yapf._platform_dir(), name)
|
||||
os.makedirs(os.path.dirname(out), exist_ok=True)
|
||||
cc = shutil.which("cc") or shutil.which("gcc") or shutil.which("clang")
|
||||
if not cc:
|
||||
return None
|
||||
cmd = [cc, "-O2", "-std=c99", "-shared", "-fPIC", os.path.join(ROOT, "yapf.c"), "-o", out, "-pthread"]
|
||||
return tmp if subprocess.call(cmd) == 0 else None
|
||||
|
||||
|
||||
def main():
|
||||
tmp = tempfile.mkdtemp()
|
||||
libs = sys.argv[1] if len(sys.argv) > 1 else host_lib(tmp)
|
||||
os.makedirs(os.path.join(ROOT, "dist"), exist_ok=True)
|
||||
out = os.path.join(ROOT, "dist", "yapf_image-blender.zip")
|
||||
with zipfile.ZipFile(out, "w", zipfile.ZIP_DEFLATED) as z:
|
||||
for f in ("__init__.py", "blender_manifest.toml"):
|
||||
z.write(os.path.join(SRC, f), f)
|
||||
z.write(os.path.join(ROOT, "bindings", "python", "yapf.py"), "yapf.py")
|
||||
z.write(os.path.join(ROOT, "LICENSE"), "LICENSE")
|
||||
if libs:
|
||||
for plat in sorted(os.listdir(libs)):
|
||||
for f in sorted(os.listdir(os.path.join(libs, plat))):
|
||||
if f.endswith((".so", ".dll", ".dylib")):
|
||||
z.write(os.path.join(libs, plat, f), "lib/%s/%s" % (plat, f))
|
||||
print(" bundled lib/%s/%s" % (plat, f))
|
||||
shutil.rmtree(tmp, ignore_errors=True)
|
||||
print("wrote", out)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Reference in a new issue