mirror of
https://github.com/Nexoniarz/YAPF.git
synced 2026-11-03 04:54:26 +00:00
Language bindings, KDE thumbnails, yapf compare, in-memory encoding
- 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>
This commit is contained in:
parent
2ca726e3af
commit
d7f494a0c9
52 changed files with 1926 additions and 106 deletions
33
bindings/zig/example.zig
Normal file
33
bindings/zig/example.zig
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
// YAPF from Zig: the C header is imported directly.
|
||||
// zig run example.zig ../../yapf.c -I../.. -lc -O ReleaseFast
|
||||
// (Uses only the C API plus std.debug.print, so it works across Zig versions.)
|
||||
const std = @import("std");
|
||||
const c = @cImport({
|
||||
@cInclude("yapf.h");
|
||||
@cInclude("time.h");
|
||||
});
|
||||
|
||||
pub fn main() !void {
|
||||
const path: [:0]const u8 = "../../other/YAPF.YAPF";
|
||||
|
||||
var img: *c.yapf_image_t = c.yapf_load(path.ptr) orelse return error.CannotLoad;
|
||||
var best: c.clock_t = std.math.maxInt(c.clock_t); // best of 10 decodes
|
||||
for (0..10) |_| {
|
||||
const t = c.clock();
|
||||
const again = c.yapf_load(path.ptr) orelse return error.CannotLoad;
|
||||
best = @min(best, c.clock() - t);
|
||||
c.yapf_free(img);
|
||||
img = again;
|
||||
}
|
||||
defer c.yapf_free(img);
|
||||
std.debug.print("{s}: {d}x{d}, {d} channels, decoded in {d:.2} ms\n", .{
|
||||
path, img.width, img.height, img.channels, @as(f64, @floatFromInt(best)) * 1000.0 / @as(f64, @floatFromInt(c.CLOCKS_PER_SEC)),
|
||||
});
|
||||
|
||||
var data: ?*anyopaque = null;
|
||||
var size: usize = 0;
|
||||
if (c.yapf_encode(img, &data, &size) != c.YAPF_OK) return error.EncodeFailed;
|
||||
defer c.yapf_free_buffer(data);
|
||||
const raw = @as(f64, @floatFromInt(img.width * img.height * img.channels));
|
||||
std.debug.print("encoded: {d} bytes, {d:.1}% of the raw pixels\n", .{ size, 100.0 * @as(f64, @floatFromInt(size)) / raw });
|
||||
}
|
||||
Loading…
Reference in a new issue