diff options
| author | Paul Buetow <paul@buetow.org> | 2026-07-12 17:51:22 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-07-12 17:51:22 +0300 |
| commit | 6b0f2de39c2d8b9e8d346abd8548024da4ae8185 (patch) | |
| tree | 29e67e6a75488b4fdd34756be3944c4262e0b85a /src/loader/detect.h | |
| parent | 51b47a0130005bd19039422d027da23ff46dd6b8 (diff) | |
showimage: loader, detect, viewer widget, EXIF orientation, tests (gt0)
M1 (task gt0): show one image with zoom/pan.
- src/loader/detect.{c,h}: magic-byte format sniffing (JPEG/PNG/GIF/WebP/
TIFF/ICO/JXL/AVIF/HEIF) -> GgazeFormat; pure, no I/O, unit-testable.
- src/loader/loader.{c,h}: loader_load() sniffs the header and dispatches to
the first registered backend; GgazeLoaderBackend struct; pixbuf is the
fallback (last, accepts UNKNOWN). M1 ships only the pixbuf backend.
- src/loader/backends/pixbuf.c: GdkPixbufLoader decode +
gdk_pixbuf_apply_embedded_orientation (decision #26) -> GdkTexture via
gdk_memory_texture_new (avoids the deprecated gdk_texture_new_for_pixbuf).
- src/viewer.{c,h}: GgazeViewer : GtkWidget custom widget (decision #31) —
fit/100%/in/out zoom, cursor-centered zoom, drag-to-pan with clamping,
dark background, GtkSnapshot render nodes.
- src/window.c: open -> loader_load -> viewer_set_texture -> stack 'large'.
- tests: unit test_detect (13 cases) + test_loader_pixbuf (plain/rotated-EXIF
8x4 orient6->4x8/png/rgba/missing/unsupported jxl-avif-heif/corrupt),
integration test_open_and_show (fixture + rotated + ./sample-images
skip-if-absent). 6/6 green; detect 97% / loader 91% / pixbuf 87% coverage.
- fixtures: gen.py produces plain.jpg, rot6.jpg, small.png, rgba.png.
- AGENTS.md: documents the ./sample-images optional test corpus convention.
Sub-agent review fixes: use-after-free of c_name in ggaze_window_open
(BLOCKER), gtk_stack_get_pages leak in test_window (BLOCKER), coverage gap,
dead branch, viewer measure, _prefix/_cb naming, include order, extern in
header, pan clamp, stale comments — all addressed.
Diffstat (limited to 'src/loader/detect.h')
| -rw-r--r-- | src/loader/detect.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/loader/detect.h b/src/loader/detect.h new file mode 100644 index 0000000..95e549c --- /dev/null +++ b/src/loader/detect.h @@ -0,0 +1,40 @@ +#ifndef GGAZE_DETECT_H +#define GGAZE_DETECT_H + +/*:* + * ggaze — image format detection + * + * Content-sniffing (magic bytes), never extension-based. detect_format() takes + * the first N bytes of a file and returns the detected GgazeFormat. The loader + * uses this to dispatch to the right backend; see docs/architecture.md "Image + * decode" and docs/tech-stack.md. + * + * Copyright (c) 2026 ggaze contributors + * SPDX-License-Identifier: GPL-3.0-or-later + *:*/ + +#include <glib.h> + +G_BEGIN_DECLS + +typedef enum { + GGAZE_FMT_UNKNOWN = 0, + GGAZE_FMT_JPEG, /* FF D8 FF */ + GGAZE_FMT_PNG, /* 89 50 4E 47 0D 0A 1A 0A */ + GGAZE_FMT_GIF, /* "GIF8" */ + GGAZE_FMT_WEBP, /* RIFF .... WEBP */ + GGAZE_FMT_TIFF, /* II 2A 00 | MM 00 2A */ + GGAZE_FMT_ICO, /* 00 00 01 00 */ + GGAZE_FMT_JXL, /* FF 0A | "....JXL " container */ + GGAZE_FMT_AVIF, /* ftyp avif/avis */ + GGAZE_FMT_HEIF /* ftyp heic/heix/mif1 */ +} GgazeFormat; + +/* Sniff p_head (u_len bytes) and return the detected format. Never reads + * past u_len. Returns GGAZE_FMT_UNKNOWN if the buffer is too short or + * unrecognized. */ +GgazeFormat detect_format(const guint8 *p_head, gsize u_len); + +G_END_DECLS + +#endif /* GGAZE_DETECT_H */
\ No newline at end of file |
