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
11
bindings/csharp/Example/Example.csproj
Normal file
11
bindings/csharp/Example/Example.csproj
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="../Yapf.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
25
bindings/csharp/Example/Program.cs
Normal file
25
bindings/csharp/Example/Program.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// dotnet run -- ../../../other/YAPF.YAPF (with yapf.dll / libyapf.so on the library path)
|
||||
using System.Diagnostics;
|
||||
using Yapf;
|
||||
|
||||
string path = args.Length > 0 ? args[0] : "../../../other/YAPF.YAPF";
|
||||
byte[] file = File.ReadAllBytes(path);
|
||||
|
||||
var img = YapfImage.Decode(file); // first call also loads the library / JIT
|
||||
double ms = double.MaxValue; // best of 10, as in a running program
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
img = YapfImage.Decode(file);
|
||||
ms = Math.Min(ms, sw.Elapsed.TotalMilliseconds);
|
||||
}
|
||||
Console.WriteLine($"{path}: {img.Width}x{img.Height}, {img.Channels} channels, decoded in {ms:F2} ms");
|
||||
Console.WriteLine($"file is {file.Length} bytes, {100.0 * file.Length / img.Pixels.Length:F1}% of the raw pixels");
|
||||
|
||||
byte[] again = img.Encode();
|
||||
Console.WriteLine($"re-encoded: {again.Length} bytes, identical: {again.AsSpan().SequenceEqual(file)}");
|
||||
|
||||
var rgba = new byte[64 * 64 * 4];
|
||||
for (int i = 0; i < rgba.Length; i += 4) { rgba[i] = (byte)(i / 4 % 64 * 4); rgba[i + 1] = 100; rgba[i + 2] = 200; rgba[i + 3] = 255; }
|
||||
new YapfImage(64, 64, 4, rgba).Save("csharp.yapf");
|
||||
Console.WriteLine("wrote csharp.yapf");
|
||||
Loading…
Reference in a new issue