Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
dev_snapshot.h
Go to the documentation of this file.
1/*
2 This file is part of ansel,
3 Copyright (C) 2025-2026 Guillaume STUTIN.
4
5 Ansel is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 Ansel is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with Ansel. If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef DT_DEVELOP_DEV_SNAPSHOT_H
19#define DT_DEVELOP_DEV_SNAPSHOT_H
20
21#include <cairo.h>
22#include <glib.h>
23#include <stdint.h>
24
25struct dt_develop_t;
26
27// A live render of one image's pipeline output, scoped to dev's current viewport (ROI) and
28// recomputed as pan/zoom change -- decoupled from any *other* dt_dev_pixelpipe_t, so it can show
29// an image other than (or a frozen past state of) the one currently open in darkroom, positioned
30// as if it were the live pipe's own output. See libs/snapshots.c (compare current edit against a
31// past history state) and libs/duplicate.c (preview another version of the same shot without
32// leaving darkroom).
33//
34// Opaque handle: the real state lives in a heap-allocated, refcounted dt_dev_snapshot_engine_t
35// (private to dev_snapshot.c) so that copying/moving a dt_dev_snapshot_t -- e.g. libs/snapshots.c
36// shuffling its fixed-size slot array on take/delete -- only ever copies a stable pointer, never
37// the engine itself. This matters because the "main" tier's accurate reprocess runs on a
38// background job (see dev_snapshot.c): the engine can outlive the dt_dev_snapshot_t handle that
39// created it for as long as that job still references it, and is only actually freed once both
40// the handle and any in-flight job have released their reference.
41typedef struct dt_dev_snapshot_t
42{
43 struct dt_dev_snapshot_engine_t *engine; // refcounted, owned (one reference held here). NULL if nothing captured.
45
46// Sets up snap to render imgid's pipeline output, matching `dev`'s current pan/zoom/scale, and
47// keeps recomputing on subsequent dt_dev_snapshot_draw() calls as dev's viewport changes -- same
48// ROI formula as dev->pipe itself, so only the visible window is ever processed, never the whole
49// image. The accurate reprocess after a pan/zoom change runs on a background job (Ansel's
50// existing control/jobs.h system), so it never blocks the GUI thread; a cheap fit-scale fallback
51// is shown while it is in flight.
52//
53// history_override/iop_order_override, if non-NULL, are used verbatim instead of imgid's own
54// on-disk history -- e.g. to capture a *live*, possibly-uncommitted edit from a dt_develop_t
55// that currently has imgid open. Ownership of both lists transfers to this call (freed
56// internally, win or lose) -- duplicate them first (dt_history_duplicate() /
57// dt_ioppr_iop_order_copy_deep()) if the caller still needs its own copy afterwards. Pass
58// NULL/NULL/-1 to render imgid's own persisted history as-is, with no live override.
59//
60// Returns FALSE on failure (e.g. the first, current-viewport render failed), in which case snap
61// is left cleared.
62gboolean dt_dev_snapshot_capture(dt_dev_snapshot_t *snap, struct dt_develop_t *dev, int32_t imgid,
63 GList *history_override, GList *iop_order_override,
64 int32_t history_end_override);
65
66// Releases snap's own reference to its engine (best-effort cancelling an in-flight recompute job)
67// and resets it to empty. Never blocks: if a background job is still running, it holds its own
68// reference and frees the engine itself once it finishes. Safe to call on an already-empty
69// snapshot.
71
72// TRUE once snap holds a captured, successfully-rendered image.
74
75// Paints snap into cri as if it were dev's own pipeline output, matching dev's current pan and
76// zoom, clipped to (clip_x, clip_y, clip_w, clip_h) in widget space. width/height must be the
77// full darkroom center-view widget size. Purely resizing/moving the clip rect (e.g. dragging a
78// compare split line) never triggers a reprocess, since it never touches dev->roi.
79//
80// If dev's viewport (pan/zoom) changed since the "main" tier's last successful render, an
81// accurate reprocess is requested on a background job (same immediacy as
82// dev->pipe's own worker loop, throttled only by "one job in flight at a time") instead of
83// running inline, and the fit-scale "preview" tier is drawn (cairo-transformed to approximate the
84// new viewport) in the meantime -- same fallback idea as darkroom.c's own main/preview cascade.
85// No-op if snap holds no image.
86void dt_dev_snapshot_draw(dt_dev_snapshot_t *snap, cairo_t *cri, struct dt_develop_t *dev,
87 int32_t width, int32_t height,
88 double clip_x, double clip_y, double clip_w, double clip_h);
89
90#endif // DT_DEVELOP_DEV_SNAPSHOT_H
91
92// clang-format off
93// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
94// vim: shiftwidth=2 expandtab tabstop=2 cindent
95// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
96// clang-format on
gboolean dt_dev_snapshot_capture(dt_dev_snapshot_t *snap, struct dt_develop_t *dev, int32_t imgid, GList *history_override, GList *iop_order_override, int32_t history_end_override)
void dt_dev_snapshot_draw(dt_dev_snapshot_t *snap, cairo_t *cri, struct dt_develop_t *dev, int32_t width, int32_t height, double clip_x, double clip_y, double clip_w, double clip_h)
void dt_dev_snapshot_clear(dt_dev_snapshot_t *snap)
gboolean dt_dev_snapshot_is_valid(const dt_dev_snapshot_t *snap)
uint32_t width
Definition mipmap_cache.c:0
uint32_t height
Definition mipmap_cache.c:1
struct dt_dev_snapshot_engine_t * engine