mirror of
https://github.com/Nexoniarz/YAPF.git
synced 2026-11-03 04:54:26 +00:00
Extensions read YAPF 2; Nix package
- KDE thumbnailer: texture loader, decodes only the mip it needs; GPU blocks, 16-bit and float via the new yapf_tex_to_rgba8. Tested through KDE's plugin loader with KF6 from nixpkgs. - Photoshop: shows the tool's error message; HDR textures open as 32-bit (.hdr), 16-bit stays 16-bit; 16-bit documents save as 16-bit. - CLI: 16-bit PNG export, readable conversion errors. - default.nix: yapf tool, library, header, MIME type and thumbnailer (absolute store path); runs the test suite. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DVrVthWN8GsmgHGUhhsCYm
This commit is contained in:
parent
83588d8e2a
commit
a6c032d824
13 changed files with 336 additions and 48 deletions
|
|
@ -14,9 +14,11 @@
|
|||
if (!(files instanceof Array)) files = [files];
|
||||
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
var tmp = yapfTempFile(".png");
|
||||
// 8 / 16-bit images come through PNG (16 bits are kept); half,
|
||||
// float and BC6H HDR textures through Radiance .hdr (32-bit).
|
||||
var tmp = yapfTempFile(yapfIsHdr(files[i]) ? ".hdr" : ".png");
|
||||
if (!yapfRun([files[i].fsName, tmp.fsName], tmp)) {
|
||||
alert("Could not open " + files[i].name + ".\n\n" + YAPF_TOOL_HELP);
|
||||
alert("Could not open " + files[i].name + ".\n\n" + yapfFailText());
|
||||
return;
|
||||
}
|
||||
var doc = app.open(tmp);
|
||||
|
|
|
|||
|
|
@ -25,6 +25,16 @@ native plugin.
|
|||
|
||||
Instead of copying `yapf` next to the scripts you can put it on your `PATH`.
|
||||
|
||||
## What opens how
|
||||
|
||||
Every YAPF file the `yapf` tool reads (version 1 and 2): 8-bit images open
|
||||
as 8-bit documents, 16-bit textures as 16-bit documents, half / float and
|
||||
BC6H HDR textures as 32-bit documents (through Radiance `.hdr`), other GPU
|
||||
blocks (BC1–BC7) decoded to 8-bit. Cubes, arrays and animations open their
|
||||
first image. When a file cannot be opened, the alert shows the tool's
|
||||
reason (for example a damaged file). Saving keeps 8 or 16 bits per
|
||||
channel.
|
||||
|
||||
## Status
|
||||
|
||||
The scripts are written for Photoshop CC's ExtendScript and are not yet
|
||||
|
|
|
|||
|
|
@ -22,8 +22,10 @@
|
|||
try {
|
||||
if (copy.mode !== DocumentMode.RGB && copy.mode !== DocumentMode.GRAYSCALE)
|
||||
copy.changeMode(ChangeMode.RGB);
|
||||
if (copy.bitsPerChannel !== BitsPerChannelType.EIGHT)
|
||||
copy.bitsPerChannel = BitsPerChannelType.EIGHT;
|
||||
// 8 and 16 bits per channel are kept (16-bit becomes a 16-bit
|
||||
// YAPF texture); 32-bit documents are saved as 16-bit.
|
||||
if (copy.bitsPerChannel === BitsPerChannelType.THIRTYTWO)
|
||||
copy.bitsPerChannel = BitsPerChannelType.SIXTEEN;
|
||||
var opts = new PNGSaveOptions();
|
||||
opts.interlaced = false;
|
||||
copy.saveAs(tmp, opts, true, Extension.LOWERCASE);
|
||||
|
|
@ -35,6 +37,6 @@
|
|||
if (mips) args.push("--mips");
|
||||
var ok = yapfRun(args, out);
|
||||
tmp.remove();
|
||||
if (!ok) { alert("Could not write " + out.name + ".\n\n" + YAPF_TOOL_HELP); return; }
|
||||
if (!ok) { alert("Could not write " + out.name + ".\n\n" + yapfFailText()); return; }
|
||||
alert("Saved " + out.fsName + " (" + Math.round(out.length / 1024) + " KB)");
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -20,16 +20,52 @@ function yapfTool() {
|
|||
return names[0]; // rely on the PATH
|
||||
}
|
||||
|
||||
// Runs the tool; returns true when `expectOut` was produced.
|
||||
function yapfRun(args, expectOut) {
|
||||
// Runs the tool with its output (stdout) going to `stdoutFile` when given.
|
||||
// Returns the tool's error text ("" when it printed none).
|
||||
function yapfExec(args, stdoutFile) {
|
||||
var errFile = yapfTempFile(".txt");
|
||||
var cmd = yapfQuote(yapfTool());
|
||||
for (var i = 0; i < args.length; i++) cmd += " " + (args[i].charAt(0) === "-" ? args[i] : yapfQuote(args[i]));
|
||||
if (stdoutFile) cmd += " > " + yapfQuote(stdoutFile.fsName);
|
||||
cmd += " 2> " + yapfQuote(errFile.fsName);
|
||||
if (YAPF_IS_WINDOWS) cmd = '"' + cmd + '"'; // cmd.exe strips one pair of quotes
|
||||
if (expectOut.exists) expectOut.remove();
|
||||
app.system(cmd);
|
||||
var text = yapfReadText(errFile);
|
||||
errFile.remove();
|
||||
return text;
|
||||
}
|
||||
|
||||
function yapfReadText(f) {
|
||||
if (!f.exists || !f.open("r")) return "";
|
||||
var t = f.read();
|
||||
f.close();
|
||||
return t.replace(/\s+$/, "");
|
||||
}
|
||||
|
||||
// Runs the tool; returns true when `expectOut` was produced. The tool's
|
||||
// own message (why it failed) is left in yapfLastError.
|
||||
var yapfLastError = "";
|
||||
function yapfRun(args, expectOut) {
|
||||
if (expectOut.exists) expectOut.remove();
|
||||
yapfLastError = yapfExec(args, null);
|
||||
return expectOut.exists;
|
||||
}
|
||||
|
||||
// The tool's message, or the help text when the tool could not be run.
|
||||
function yapfFailText() {
|
||||
return /yapf: /.test(yapfLastError) ? yapfLastError : YAPF_TOOL_HELP;
|
||||
}
|
||||
|
||||
// True when a .yapf file holds float / HDR data (half, float, BC6H), so it
|
||||
// should open as a 32-bit document instead of a clamped 8-bit one.
|
||||
function yapfIsHdr(file) {
|
||||
var info = yapfTempFile(".txt");
|
||||
yapfExec(["info", file.fsName], info);
|
||||
var text = yapfReadText(info);
|
||||
info.remove();
|
||||
return /payload\s*:[^\n]*(half float|, float|BC6H)/.test(text);
|
||||
}
|
||||
|
||||
function yapfTempFile(ext) {
|
||||
return new File(Folder.temp.fsName + "/yapf_" + new Date().getTime() + "_" +
|
||||
Math.floor(Math.random() * 1e6) + ext);
|
||||
|
|
|
|||
Loading…
Reference in a new issue