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#pragma once
28
29#include "common/cache.h"
30#include "common/image.h"
31
32#include <sqlite3.h>
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38typedef struct dt_image_cache_t
39{
41}
43
44// what to do if an image struct is
45// released after writing.
47{
48 // write to db and queue xmp write
50 // only write to db
52 // only release the lock (no db write, no xmp)
53 // use that for multi-threading data safety
57
61
62// blocks until it gets the image struct with this id for reading.
63// also does the sql query if the image is not in cache atm.
64// if id < 0, a newly wiped image struct shall be returned (for import).
65// this will silently start the garbage collector and free long-unused
66// cachelines to free up space if necessary.
67// if an entry is swapped out like this in the background, this is the latest
68// point where sql and xmp can be synched (unsafe setting).
69dt_image_t *dt_image_cache_get(dt_image_cache_t *cache, const int32_t imgid, char mode);
70
71// same as read_get, but doesn't block and returns NULL if the image
72// is currently unavailable.
73dt_image_t *dt_image_cache_testget(dt_image_cache_t *cache, const int32_t imgid, char mode);
74
75// like dt_image_cache_get/testget, but always reloads the image data from the database
76// before returning the cache entry.
77dt_image_t *dt_image_cache_get_reload(dt_image_cache_t *cache, const int32_t imgid, char mode);
78
79// seed an image cache entry from an already-populated dt_image_t (no SQL).
80// returns 0 on insert, 1 if already present, -1 on failure.
81int dt_image_cache_seed(dt_image_cache_t *cache, const dt_image_t *img);
82
83// Populate the common dt_image_t subset from a SQL row (shared with thumbtable).
84// Expected column order:
85// id, group_id, group_members, history_items, history_hash, mipmap_hash, film_id, version, width, height, orientation, flags,
86// import_timestamp, change_timestamp, export_timestamp, print_timestamp, exposure, exposure_bias, aperture, iso,
87// focal_length, focus_distance, datetime_taken, longitude, latitude, altitude, filename, fullpath, maker, model,
88// lens, folder, color_labels, crop, raw_parameters, color_matrix, colorspace, raw_black, raw_maximum,
89// aspect_ratio, output_width, output_height.
90//
91// IMPORTANT: this does not call dt_image_init(). Fields not present in the SQL row are left unchanged.
92void dt_image_from_stmt(dt_image_t *info, sqlite3_stmt *stmt);
93
95// Register an IMAGE_INFO_CHANGED handler that force-reloads image cache entries.
96// This must be connected before any other handler, so everyone observes fresh data.
98
99// drops the read lock on an image struct
101
102// drops the write privileges on an image struct.
103// this triggers a write-through to sql, and if the setting
104// is present, also to xmp sidecar files (safe setting).
105// minimal mode only releases the lock without any write.
107
108// remove the image from the cache
109void dt_image_cache_remove(dt_image_cache_t *cache, const int32_t imgid);
110
111// register timestamps in cache
112void dt_image_cache_set_export_timestamp(dt_image_cache_t *cache, const int32_t imgid);
113void dt_image_cache_set_print_timestamp(dt_image_cache_t *cache, const int32_t imgid);
114
115// return 1 if the image is invalid so we can bail out early
116int dt_image_invalid(const dt_image_t *img);
117
118#ifdef __cplusplus
119}
120#endif
121
122// clang-format off
123// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
124// vim: shiftwidth=2 expandtab tabstop=2 cindent
125// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
126// clang-format on
void dt_image_cache_cleanup(dt_image_cache_t *cache)
Definition image_cache.c:313
void dt_image_cache_init(dt_image_cache_t *cache)
Definition image_cache.c:295
void dt_image_cache_read_release(dt_image_cache_t *cache, const dt_image_t *img)
Definition image_cache.c:451
dt_image_t * dt_image_cache_get_reload(dt_image_cache_t *cache, const int32_t imgid, char mode)
Definition image_cache.c:373
dt_image_cache_write_mode_t
Definition image_cache.h:47
@ DT_IMAGE_CACHE_RELAXED
Definition image_cache.h:51
@ DT_IMAGE_CACHE_MINIMAL
Definition image_cache.h:54
@ DT_IMAGE_CACHE_SAFE
Definition image_cache.h:49
void dt_image_from_stmt(dt_image_t *info, sqlite3_stmt *stmt)
Definition image_cache.c:157
dt_image_t * dt_image_cache_get(dt_image_cache_t *cache, const int32_t imgid, char mode)
Definition image_cache.c:341
int dt_image_cache_seed(dt_image_cache_t *cache, const dt_image_t *img)
Definition image_cache.c:412
void dt_image_cache_set_export_timestamp(dt_image_cache_t *cache, const int32_t imgid)
Definition image_cache.c:616
int dt_image_invalid(const dt_image_t *img)
Definition image_cache.c:407
void dt_image_cache_write_release(dt_image_cache_t *cache, dt_image_t *img, dt_image_cache_write_mode_t mode)
Definition image_cache.c:464
void dt_image_cache_remove(dt_image_cache_t *cache, const int32_t imgid)
Definition image_cache.c:611
void dt_image_cache_connect_info_changed_first(const struct dt_control_signal_t *ctlsig)
Definition image_cache.c:443
dt_image_t * dt_image_cache_testget(dt_image_cache_t *cache, const int32_t imgid, char mode)
Definition image_cache.c:359
void dt_image_cache_set_print_timestamp(dt_image_cache_t *cache, const int32_t imgid)
Definition image_cache.c:625
void dt_image_cache_print(dt_image_cache_t *cache)
Definition image_cache.c:334
Definition common/cache.h:48
Definition signal.c:50
Definition image_cache.h:39
dt_cache_t cache
Definition image_cache.h:40
Definition common/image.h:247