mirror of
https://github.com/Nexoniarz/YAPF.git
synced 2026-11-02 20:44:27 +00:00
- yapf_encode() / yapf_free_buffer(): encode to memory; yapf_save uses it - yapf.c also compiles as C++ - `yapf compare`: size and decode speed of the original format vs YAPF, with a lossless check - bindings with tested examples: C++ (header-only), C# (P/Invoke), Rust (crate, builds the C code), Go (cgo), Java (FFM API, Java 22+), Zig (@cImport), LuaJIT (FFI), TypeScript types for the JS port; Python now encodes in memory - docs/LANGUAGES.md and examples/ with measured results - KDE Dolphin thumbnail plugin (KF6, CMake) - README: honest status for Photoshop / VS Code / Figma (not run in the apps yet) and macOS (cross-compiled only), platform table Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
29 lines
1.4 KiB
Java
29 lines
1.4 KiB
Java
// java --enable-native-access=ALL-UNNAMED -Dyapf.library=../../build/libyapf.so Example.java ../../other/YAPF.YAPF
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
import java.util.Arrays;
|
|
|
|
public class Example {
|
|
public static void main(String[] args) throws Exception {
|
|
Path path = Path.of(args.length > 0 ? args[0] : "../../other/YAPF.YAPF");
|
|
byte[] file = Files.readAllBytes(path);
|
|
|
|
Yapf.Image img = Yapf.decode(file); // first call also loads the library
|
|
double ms = Double.MAX_VALUE; // best of 10, as in a running program
|
|
for (int i = 0; i < 10; i++) {
|
|
long t = System.nanoTime();
|
|
img = Yapf.decode(file);
|
|
ms = Math.min(ms, (System.nanoTime() - t) / 1e6);
|
|
}
|
|
System.out.printf("%s: %dx%d, %d channels, decoded in %.2f ms%n", path, img.width(), img.height(), img.channels(), ms);
|
|
System.out.printf("file is %d bytes, %.1f%% of the raw pixels%n", file.length, 100.0 * file.length / img.pixels().length);
|
|
|
|
byte[] again = Yapf.encode(img);
|
|
System.out.printf("re-encoded: %d bytes, identical: %b%n", again.length, Arrays.equals(again, file));
|
|
|
|
byte[] rgb = new byte[64 * 64 * 3];
|
|
for (int i = 0; i < rgb.length; i++) rgb[i] = (byte) (i * 3);
|
|
Yapf.save(Path.of("java.yapf"), new Yapf.Image(64, 64, 3, rgb));
|
|
System.out.println("wrote java.yapf");
|
|
}
|
|
}
|