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
47
bindings/go/example/main.go
Normal file
47
bindings/go/example/main.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
// go run ./example ../../other/YAPF.YAPF
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
yapf "github.com/Nexoniarz/YAPF/bindings/go"
|
||||
)
|
||||
|
||||
func main() {
|
||||
path := "../../other/YAPF.YAPF"
|
||||
if len(os.Args) > 1 {
|
||||
path = os.Args[1]
|
||||
}
|
||||
file, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
img, err := yapf.Decode(file)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
best := time.Hour // best of 10, as in a running program
|
||||
for i := 0; i < 10; i++ {
|
||||
t := time.Now()
|
||||
img, _ = yapf.Decode(file)
|
||||
best = min(best, time.Since(t))
|
||||
}
|
||||
fmt.Printf("%s: %dx%d, %d channels, decoded in %.2f ms\n", path, img.Width, img.Height,
|
||||
img.Channels, float64(best.Microseconds())/1000)
|
||||
fmt.Printf("file is %d bytes, %.1f%% of the raw pixels\n", len(file), 100*float64(len(file))/float64(len(img.Pixels)))
|
||||
|
||||
again, _ := yapf.Encode(img)
|
||||
fmt.Printf("re-encoded: %d bytes, identical: %v\n", len(again), bytes.Equal(again, file))
|
||||
|
||||
px := make([]byte, 128*128)
|
||||
for i := range px {
|
||||
px[i] = byte(i % 128 * 2)
|
||||
}
|
||||
if err := yapf.Save("go.yapf", &yapf.Image{Width: 128, Height: 128, Channels: 1, Flags: yapf.FlagSRGB, Pixels: px}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("wrote go.yapf")
|
||||
}
|
||||
Loading…
Reference in a new issue