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
65
extensions/vscode/extension.js
Normal file
65
extensions/vscode/extension.js
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
// YAPF image preview for VS Code — a read-only custom editor for *.yapf.
|
||||
// Copyright 2026 Nexoniarz — Apache License 2.0.
|
||||
const vscode = require('vscode');
|
||||
|
||||
class YapfPreviewProvider {
|
||||
constructor(context) { this.context = context; }
|
||||
|
||||
openCustomDocument(uri) { return { uri, dispose() {} }; }
|
||||
|
||||
async resolveCustomEditor(document, panel) {
|
||||
const media = vscode.Uri.joinPath(this.context.extensionUri, 'media');
|
||||
panel.webview.options = { enableScripts: true, localResourceRoots: [media] };
|
||||
panel.webview.html = this.html(panel.webview, media);
|
||||
|
||||
const send = async () => {
|
||||
try {
|
||||
const bytes = await vscode.workspace.fs.readFile(document.uri);
|
||||
panel.webview.postMessage({ type: 'file', name: document.uri.path.split('/').pop(), bytes });
|
||||
} catch (e) {
|
||||
panel.webview.postMessage({ type: 'error', message: String(e.message || e) });
|
||||
}
|
||||
};
|
||||
panel.webview.onDidReceiveMessage((m) => { if (m.type === 'ready') send(); });
|
||||
|
||||
// Reload when the file changes on disk.
|
||||
const folder = vscode.Uri.joinPath(document.uri, '..');
|
||||
const name = document.uri.path.split('/').pop();
|
||||
const watcher = vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(folder, name));
|
||||
watcher.onDidChange(send);
|
||||
panel.onDidDispose(() => watcher.dispose());
|
||||
}
|
||||
|
||||
html(webview, media) {
|
||||
const uri = (f) => webview.asWebviewUri(vscode.Uri.joinPath(media, f));
|
||||
const nonce = Math.random().toString(36).slice(2) + Date.now().toString(36);
|
||||
return `<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="Content-Security-Policy"
|
||||
content="default-src 'none'; img-src ${webview.cspSource} data: blob:; style-src ${webview.cspSource}; script-src 'nonce-${nonce}';">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="${uri('preview.css')}">
|
||||
<title>YAPF Preview</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="bar"><span id="info">Loading…</span><span id="controls"></span></div>
|
||||
<div id="stage"><canvas id="canvas"></canvas></div>
|
||||
<div id="error" hidden></div>
|
||||
<script nonce="${nonce}" src="${uri('yapf.js')}"></script>
|
||||
<script nonce="${nonce}" src="${uri('preview.js')}"></script>
|
||||
</body>
|
||||
</html>`;
|
||||
}
|
||||
}
|
||||
|
||||
function activate(context) {
|
||||
context.subscriptions.push(vscode.window.registerCustomEditorProvider(
|
||||
'yapf.preview', new YapfPreviewProvider(context),
|
||||
{ webviewOptions: { retainContextWhenHidden: true }, supportsMultipleEditorsPerDocument: true }));
|
||||
}
|
||||
|
||||
function deactivate() {}
|
||||
|
||||
module.exports = { activate, deactivate };
|
||||
Loading…
Reference in a new issue