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// One cached image (dt_image_t), for the GUI memory view.
64{
65 int32_t imgid;
66 size_t size; // bytes
67 char filename[128];
69
70// Current/max bytes used by the image cache.
71void dt_image_cache_get_usage(dt_image_cache_t *cache, size_t *current, size_t *max);
72
73// Snapshot of all cached images (newly-allocated GArray of
74// dt_image_cache_stats_entry_t; free with g_array_free()).
76
77// blocks until it gets the image struct with this id for reading.
78// also does the sql query if the image is not in cache atm.
79// if id < 0, a newly wiped image struct shall be returned (for import).
80// this will silently start the garbage collector and free long-unused
81// cachelines to free up space if necessary.
82// if an entry is swapped out like this in the background, this is the latest
83// point where sql and xmp can be synched (unsafe setting).
84dt_image_t *dt_image_cache_get(dt_image_cache_t *cache, const int32_t imgid, char mode);
85
86// same as read_get, but doesn't block and returns NULL if the image
87// is currently unavailable.
88dt_image_t *dt_image_cache_testget(dt_image_cache_t *cache, const int32_t imgid, char mode);
89
90// like dt_image_cache_get/testget, but always reloads the image data from the database
91// before returning the cache entry.
92dt_image_t *dt_image_cache_get_reload(dt_image_cache_t *cache, const int32_t imgid, char mode);
93
94// seed an image cache entry from an already-populated dt_image_t (no SQL).
95// returns 0 on insert, 1 if already present, -1 on failure.
96int dt_image_cache_seed(dt_image_cache_t *cache, const dt_image_t *img);
97
98// Populate the common dt_image_t subset from a SQL row (shared with thumbtable).
99// Expected column order:
100// id, group_id, group_members, history_items, history_hash, mipmap_hash, film_id, version, width, height, orientation, flags,
101// import_timestamp, change_timestamp, export_timestamp, print_timestamp, exposure, exposure_bias, aperture, iso,
102// focal_length, focus_distance, datetime_taken, longitude, latitude, altitude, filename, fullpath, maker, model,
103// lens, folder, color_labels, crop, raw_parameters, color_matrix, colorspace, raw_black, raw_maximum,
104// aspect_ratio, output_width, output_height.
105//
106// IMPORTANT: this does not call dt_image_init(). Fields not present in the SQL row are left unchanged.
107void dt_image_from_stmt(dt_image_t *info, sqlite3_stmt *stmt);
108
110// Register an IMAGE_INFO_CHANGED handler that force-reloads image cache entries.
111// This must be connected before any other handler, so everyone observes fresh data.
113
114// drops the read lock on an image struct
116
117// drops the write privileges on an image struct.
118// this triggers a write-through to sql, and if the setting
119// is present, also to xmp sidecar files (safe setting).
120// minimal mode only releases the lock without any write.
122
123// remove the image from the cache
124void dt_image_cache_remove(dt_image_cache_t *cache, const int32_t imgid);
125
126// register timestamps in cache
127void dt_image_cache_set_export_timestamp(dt_image_cache_t *cache, const int32_t imgid);
128void dt_image_cache_set_print_timestamp(dt_image_cache_t *cache, const int32_t imgid);
129
130// return 1 if the image is invalid so we can bail out early
131int dt_image_invalid(const dt_image_t *img);
132
133#ifdef __cplusplus
134}
135#endif
136
137// clang-format off
138// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
139// vim: shiftwidth=2 expandtab tabstop=2 cindent
140// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
141// clang-format on
const float max
void dt_image_cache_cleanup(dt_image_cache_t *cache)
void dt_image_cache_init(dt_image_cache_t *cache)
void dt_image_cache_read_release(dt_image_cache_t *cache, const dt_image_t *img)
void dt_image_cache_get_usage(dt_image_cache_t *cache, size_t *current, size_t *max)
dt_image_t * dt_image_cache_get_reload(dt_image_cache_t *cache, const int32_t imgid, char mode)
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)
dt_image_t * dt_image_cache_get(dt_image_cache_t *cache, const int32_t imgid, char mode)
int dt_image_cache_seed(dt_image_cache_t *cache, const dt_image_t *img)
void dt_image_cache_set_export_timestamp(dt_image_cache_t *cache, const int32_t imgid)
int dt_image_invalid(const dt_image_t *img)
void dt_image_cache_write_release(dt_image_cache_t *cache, dt_image_t *img, dt_image_cache_write_mode_t mode)
void dt_image_cache_remove(dt_image_cache_t *cache, const int32_t imgid)
void dt_image_cache_connect_info_changed_first(const struct dt_control_signal_t *ctlsig)
GArray * dt_image_cache_get_entries_stats(dt_image_cache_t *cache)
dt_image_t * dt_image_cache_testget(dt_image_cache_t *cache, const int32_t imgid, char mode)
void dt_image_cache_set_print_timestamp(dt_image_cache_t *cache, const int32_t imgid)
void dt_image_cache_print(dt_image_cache_t *cache)
Definition image_cache.h:64
char filename[128]
Definition image_cache.h:67
size_t size
Definition image_cache.h:66
int32_t imgid
Definition image_cache.h:65
dt_cache_t cache
Definition image_cache.h:40