Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
image_cache.h
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2009-2011, 2014 johannes hanika.
4 Copyright (C) 2012 Richard Wonka.
5 Copyright (C) 2012, 2014, 2016 Tobias Ellinghaus.
6 Copyright (C) 2013 Simon Spannagel.
7 Copyright (C) 2020 Hanno Schwalm.
8 Copyright (C) 2020 JP Verrue.
9 Copyright (C) 2020-2021 Pascal Obry.
10 Copyright (C) 2022 Martin Baƙinka.
11 Copyright (C) 2025 Alynx Zhou.
12
13 darktable is free software: you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 darktable is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with darktable. If not, see <http://www.gnu.org/licenses/>.
25*/
26
27#ifndef DT_CACHES_IMAGE_CACHE_H
28#define DT_CACHES_IMAGE_CACHE_H
29
30#include "caches/cache.h"
31#include "common/image.h"
32
33#include <sqlite3.h>
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39/* Opaque, and there is no accessor: no function below takes a cache handle, so nothing
40 * outside this module needs one. */
42
43// what to do if an image struct is
44// released after writing.
46{
47 // write to db and queue xmp write
49 // only write to db
51 // only release the lock (no db write, no xmp)
52 // use that for multi-threading data safety
56
65void dt_image_cache_init(const gboolean verbose);
66void dt_image_cache_cleanup(void);
67void dt_image_cache_print(void);
68
69// Interim accessor (Strategy B, doc/globals-migration.md): implemented by the orchestrator; long-term the handle should be carried on the job/view context (Strategy C).
73gboolean dt_image_cache_is_ready(void);
74
75// One cached image (dt_image_t), for the GUI memory view.
77{
78 int32_t imgid;
79 size_t size; // bytes
80 char filename[128];
82
83// Current/max bytes used by the image cache.
84void dt_image_cache_get_usage(size_t *current, size_t *max);
85
86// Snapshot of all cached images (newly-allocated GArray of
87// dt_image_cache_stats_entry_t; free with g_array_free()).
89
90// blocks until it gets the image struct with this id for reading.
91// also does the sql query if the image is not in cache atm.
92// if id < 0, a newly wiped image struct shall be returned (for import).
93// this will silently start the garbage collector and free long-unused
94// cachelines to free up space if necessary.
95// if an entry is swapped out like this in the background, this is the latest
96// point where sql and xmp can be synched (unsafe setting).
97dt_image_t *dt_image_cache_get(const int32_t imgid, char mode);
98
99// same as read_get, but doesn't block and returns NULL if the image
100// is currently unavailable.
101dt_image_t *dt_image_cache_testget(const int32_t imgid, char mode);
102
103// same as get, but only for an image that is ALREADY cached: waits for the entry's lock when
104// an entry exists, as get() does, and returns NULL without creating one when it does not.
105// testget() cannot stand in for it -- it returns NULL for an entry someone holds this instant
106// as well as for no entry, and a caller writing the row in the first case writes behind a live
107// entry whose next release reverts it. For code that keeps an existing entry in step with a
108// row it writes, without pulling every image it visits into the cache (the XMP crawler).
109// An entry evicted between the check and the wait is reloaded from its row, as get() would:
110// one allocation, never a stale answer.
111dt_image_t *dt_image_cache_get_existing(const int32_t imgid, char mode);
112
113// like dt_image_cache_get/testget, but always reloads the image data from the database
114// before returning the cache entry.
115dt_image_t *dt_image_cache_get_reload(const int32_t imgid, char mode);
116
117// seed an image cache entry from an already-populated dt_image_t (no SQL).
118// returns 0 on insert, 1 if already present, -1 on failure.
119int dt_image_cache_seed(const dt_image_t *img);
120
121// Populate the common dt_image_t subset from a SQL row (shared with thumbtable).
122// Expected column order:
123// id, group_id, group_members, history_items, history_hash, mipmap_hash, film_id, version, width, height, orientation, flags,
124// import_timestamp, change_timestamp, export_timestamp, print_timestamp, exposure, exposure_bias, aperture, iso,
125// focal_length, focus_distance, datetime_taken, longitude, latitude, altitude, filename, fullpath, maker, model,
126// lens, folder, color_labels, crop, raw_parameters, color_matrix, colorspace, raw_black, raw_maximum,
127// aspect_ratio, output_width, output_height.
128//
129// IMPORTANT: this does not call dt_image_init(). Fields not present in the SQL row are left unchanged.
142
144// Register an IMAGE_INFO_CHANGED handler that force-reloads image cache entries.
145// This must be connected before any other handler, so everyone observes fresh data.
147
148// drops the read lock on an image struct
150
151// drops the write privileges on an image struct.
152// this triggers a write-through to sql, and if the setting
153// is present, also to xmp sidecar files (safe setting).
154// minimal mode only releases the lock without any write.
156
157// remove the image from the cache
158void dt_image_cache_remove(const int32_t imgid);
159
160// register timestamps in cache
161void dt_image_cache_set_export_timestamp(const int32_t imgid);
162void dt_image_cache_set_print_timestamp(const int32_t imgid);
163
164// return 1 if the image is invalid so we can bail out early
165int dt_image_invalid(const dt_image_t *img);
166
167#ifdef __cplusplus
168}
169#endif
170
171#endif // DT_CACHES_IMAGE_CACHE_H
172
173// clang-format off
174// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
175// vim: shiftwidth=2 expandtab tabstop=2 cindent
176// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
177// clang-format on
const float max
void dt_image_cache_set_print_timestamp(const int32_t imgid)
dt_image_t * dt_image_cache_get_existing(const int32_t imgid, char mode)
void dt_image_cache_write_release(dt_image_t *img, dt_image_cache_write_mode_t mode)
dt_image_t * dt_image_cache_testget(const int32_t imgid, char mode)
gboolean dt_image_cache_is_ready(void)
Has the image cache been initialised? Callers that run before dt_image_cache_init() or after its clea...
Definition image_cache.c:83
void dt_image_cache_get_usage(size_t *current, size_t *max)
GArray * dt_image_cache_get_entries_stats(void)
void dt_image_cache_set_export_timestamp(const int32_t imgid)
void dt_image_cache_init(const gboolean verbose)
Initialise the cache.
dt_image_cache_write_mode_t
Definition image_cache.h:46
@ DT_IMAGE_CACHE_RELAXED
Definition image_cache.h:50
@ DT_IMAGE_CACHE_MINIMAL
Definition image_cache.h:53
@ DT_IMAGE_CACHE_SAFE
Definition image_cache.h:48
void dt_image_derive_fields(dt_image_t *img)
Compute the fields the database does not store: rating, monochrome and HDR predicates,...
dt_image_t * dt_image_cache_get(const int32_t imgid, char mode)
dt_image_t * dt_image_cache_get_reload(const int32_t imgid, char mode)
int dt_image_invalid(const dt_image_t *img)
int dt_image_cache_seed(const dt_image_t *img)
void dt_image_cache_connect_info_changed_first(const struct dt_control_signal_t *ctlsig)
void dt_image_cache_print(void)
void dt_image_cache_remove(const int32_t imgid)
void dt_image_cache_read_release(const dt_image_t *img)
void dt_image_cache_cleanup(void)
Definition image_cache.h:77
char filename[128]
Definition image_cache.h:80
size_t size
Definition image_cache.h:79
int32_t imgid
Definition image_cache.h:78