summaryrefslogtreecommitdiff
path: root/addons/image
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 15:58:05 -0300
committerGabriel Schneider <[email protected]>2026-11-06 17:53:43 -0300
commite9f9f65ace7650a02cee6bf2b2eb466522485834 (patch)
treecaf5b7a2344b8da002f3952e3225e0db38b492fc /addons/image
parent75e4787be773c8cbfd2e60e59d409b9556898365 (diff)
downloadpardes-e9f9f65ace7650a02cee6bf2b2eb466522485834.tar.gz
pardes-e9f9f65ace7650a02cee6bf2b2eb466522485834.zip
kinds #36, the five kinds on ABI 3: fake.c with every function (view painting each view's size, search through found, FakeJob cancel) and PA_PICTURES, snake, life and image over the module's prefix and open(path, bytes), image without a record (a Restore reads its file), and pdf.c ported mechanically (tick into pa_tick with its [P/N] prefix, a table of the views it is told, its strip laid out for the view its last key or click came from, the text layer painted for a window of glyphs and read on the tick while some view shows text, a body read keeping nothing, search through found, the record its fit, tint and place, PA_PICTURES); the goldens moved once, said in the report: the art words from the first frame, fake's view line, a pane ticked when opened or loaded, a view told after a frame re-wrapped its tag
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'addons/image')
-rw-r--r--addons/image/image.zig42
1 files changed, 13 insertions, 29 deletions
diff --git a/addons/image/image.zig b/addons/image/image.zig
index fbcc501d..88ae1e2d 100644
--- a/addons/image/image.zig
+++ b/addons/image/image.zig
@@ -1,7 +1,7 @@
//! image.zig: pictures as a pardes addon (.png .jpg .gif .bmp .ppm .pgm .tga).
-//! A pane keeps its file's bytes (its record in a dump) and decodes them on
-//! a job with stb_image (stb.c), at most max_dim pixels a side; the core
-//! shows the RGBA fitted to the pane (or as glyph art, its Petscii word).
+//! A pane decodes its file's bytes on a job with stb_image (stb.c), at most
+//! max_dim pixels a side; the core shows the RGBA fitted to the pane (or as
+//! glyph art, its Petscii word). It has no record: a Restore reads the file.
const std = @import("std");
const addon = @import("addon");
@@ -31,29 +31,26 @@ fn info(bytes: []const u8) ?[2]u32 {
}
pub const Image = struct {
- raw: []const u8 = &.{}, // the file's bytes
w: u32 = 0,
h: u32 = 0,
rgba: ?[]const u8 = null, // w x h, once its job is done
- pub const head: addon.Head = .{ .name = "image", .version = 1, .exts = ".png .jpg .jpeg .gif .bmp .ppm .pgm .tga" };
+ pub const head: addon.Head = .{ .name = "image", .version = 1, .exts = ".png .jpg .jpeg .gif .bmp .ppm .pgm .tga", .pictures = true };
- /// The bytes kept, and decoded on a job.
- fn keep(im: *Image, bytes: []const u8) void {
- im.raw = addon.arena.dupe(u8, bytes) catch return;
- if (bytes.len > 0) _ = addon.job(im.raw);
- }
-
- /// One it cannot read (corrupt, truncated, not what its name says) is
- /// refused, rather than shown as a blank pane.
- pub fn open(im: *Image, bytes: ?[]const u8) void {
+ /// Decoded on a job; one it cannot read (corrupt, truncated, not what
+ /// its name says) is refused, rather than shown as a blank pane.
+ pub fn open(_: *Image, _: ?[]const u8, bytes: ?[]const u8) void {
const b = bytes orelse return;
if (info(b) == null) return addon.say("not an image pardes can read", .err);
- im.keep(b);
+ _ = addon.job(b);
+ }
+
+ /// The core follows it with its art words and the path.
+ pub fn prefix(_: *const Image, w: *std.Io.Writer) !void {
+ try w.writeAll("img");
}
pub fn paint(im: *const Image, w: addon.Window, out: addon.Paint) void {
- out.prefix("img", .{}); // the core follows it with its art words and the path
const rgba = im.rgba orelse return;
out.place(.{ .rgba = rgba.ptr, .w = im.w, .h = im.h, .src = .{ .w = im.w, .h = im.h }, .dst = .{ .w = w.cols, .h = w.rows } });
}
@@ -90,19 +87,6 @@ pub const Image = struct {
im.rgba = addon.arena.dupe(u8, out[8..]) catch return;
im.w, im.h = .{ w, h };
}
-
- /// The record is the file's bytes.
- pub fn dump(im: *const Image, buf: []u8) usize {
- if (im.raw.len <= buf.len) @memcpy(buf[0..im.raw.len], im.raw);
- return im.raw.len;
- }
-
- /// On a state with no picture (a Restore's), the record's; one open
- /// made from the file as it is now (it changed on disk) keeps that one.
- pub fn load(im: *Image, bytes: []const u8, _: u32) bool {
- if (im.raw.len == 0) im.keep(bytes);
- return true;
- }
};
pub export const pardes_addon = addon.ops(Image);