Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
mipmap_cache.h
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2009-2014, 2016 johannes hanika.
4 Copyright (C) 2012 Richard Wonka.
5 Copyright (C) 2012, 2014-2016 Tobias Ellinghaus.
6 Copyright (C) 2014-2015 Pedro Côrte-Real.
7 Copyright (C) 2014-2016 Roman Lebedev.
8 Copyright (C) 2019, 2021 Aldric Renaudin.
9 Copyright (C) 2020-2021 Pascal Obry.
10 Copyright (C) 2021 Ralf Brown.
11 Copyright (C) 2022 Martin Bařinka.
12 Copyright (C) 2025 Alynx Zhou.
13 Copyright (C) 2025 Aurélien PIERRE.
14
15 darktable is free software: you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation, either version 3 of the License, or
18 (at your option) any later version.
19
20 darktable is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with darktable. If not, see <http://www.gnu.org/licenses/>.
27*/
28
29#pragma once
30
31#include "common/atomic.h"
32#include "common/cache.h"
33#include "common/colorspaces.h"
34#include "common/image.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40// sizes stored in the mipmap cache, set to fixed values in mipmap_cache.c
41typedef enum dt_mipmap_size_t {
42 DT_MIPMAP_0, // 360x225 px
43 DT_MIPMAP_1, // 720x450 px
44 DT_MIPMAP_2, // 1440x900 px
45 DT_MIPMAP_3, // Full HD 1080p
46 DT_MIPMAP_4, // 2560x1440 px
47 DT_MIPMAP_5, // 4K/UHD -
51 DT_MIPMAP_F, // unprocessed input float image downscaled to 720x450 or 1440x900 px for performance
52 DT_MIPMAP_FULL, // unprocessed input float image at original resolation
55
56// type to be passed to getter functions
58{
59 // only return when the requested buffer is loaded.
60 // blocks until that happens.
62 // don't actually acquire the lock if it is not
63 // in cache (i.e. would have to be loaded first)
66
67// struct to be alloc'ed by the client, filled by dt_mipmap_cache_get()
78
80{
81 // one cache per mipmap scale!
83
84 // a few stats on usage in this run.
85 // long int to give 32-bits on old archs, so __sync* calls will work.
86 long int stats_requests; // number of total requests
87 long int stats_near_match; // served with smaller mip res
88 long int stats_misses; // nothing returned at all.
89 long int stats_fetches; // texture was fetched (either as a stand-in or as per request)
90 long int stats_standin; // texture used as stand-in
92
93typedef struct dt_mipmap_cache_t
94{
95 // real width and height are stored per element
96 // (could be smaller than the max for this mip level,
97 // due to aspect ratio)
99 // size of an element inside buf
101
102 // one cache per mipmap level
106 char cachedir[PATH_MAX]; // cached sha1sum filename for faster access
108
109// dynamic memory allocation interface for imageio backend: a write locked
110// mipmap buffer is passed in, it might already contain a valid buffer. this
111// function takes care of re-allocating, if necessary.
113
117
118// get a buffer and lock according to mode ('r' or 'w').
119// see dt_mipmap_get_flags_t for explanation of the exact
120// behaviour. pass 0 as flags for the default (best effort)
121#define dt_mipmap_cache_get(A,B,C,D,E,F) dt_mipmap_cache_get_with_caller(A,B,C,D,E,F,__FILE__,__LINE__)
123 dt_mipmap_cache_t *cache,
125 const int32_t imgid,
126 const dt_mipmap_size_t mip,
128 const char mode,
129 const char *file,
130 int line);
131
132#define dt_mipmap_cache_get_with_shutdown(A,B,C,D,E,F,G) \
133 dt_mipmap_cache_get_with_caller_and_shutdown(A,B,C,D,E,F,G,__FILE__,__LINE__)
135 dt_mipmap_cache_t *cache,
137 const int32_t imgid,
138 const dt_mipmap_size_t mip,
140 const char mode,
141 dt_atomic_int *shutdown,
142 const char *file,
143 int line);
144
145// convenience function with fewer params
146#define dt_mipmap_cache_write_get(A,B,C,D) dt_mipmap_cache_write_get_with_caller(A,B,C,D,__FILE__,__LINE__)
148 dt_mipmap_cache_t *cache,
150 const int32_t imgid,
151 const int mip,
152 const char *file,
153 int line);
154
155// drop a lock
156#define dt_mipmap_cache_release(A, B) dt_mipmap_cache_release_with_caller(A, B, __FILE__, __LINE__)
158 int line);
159
160// remove thumbnails, so they will be regenerated:
161void dt_mipmap_cache_remove(dt_mipmap_cache_t *cache, const int32_t imgid, const gboolean flush_disk);
162void dt_mipmap_cache_remove_at_size(dt_mipmap_cache_t *cache, const int32_t imgid, const dt_mipmap_size_t mip, const gboolean flush_disk);
163
164// evict thumbnails from cache. They will be written to disc if not existing
165void dt_mimap_cache_evict(dt_mipmap_cache_t *cache, const int32_t imgid);
166
167// return the closest mipmap size
168// for the given window you wish to draw.
169// a dt_mipmap_size_t has always a fixed resolution associated with it,
170// depending on the user parameter for the maximum thumbnail dimensions.
171// actual resolution depends on the image and is only known after
172// the thumbnail is loaded.
174 const int32_t width, const int32_t height, const uint32_t imgid);
175
176// return the closest mipmap size fitting within the width × height boundary box.
177// Use that to flush a darkroom pipeline output into a cache line
179 const int32_t height, const uint32_t imgid);
180
181// Manually swap the image buffer of a mipmap cacheline from an existing uint8_t image
182void dt_mipmap_cache_swap_at_size(dt_mipmap_cache_t *cache, const int32_t imgid,
183 const dt_mipmap_size_t mip, const uint8_t *const buffer,
184 const int32_t width, const int32_t height, dt_colorspaces_color_profile_type_t profile);
185
186// copy over thumbnails. used by file operation that copies raw files, to speed up thumbnail generation.
187// only copies over the jpg backend on disk, doesn't directly affect the in-memory cache.
188void dt_mipmap_cache_copy_thumbnails(const dt_mipmap_cache_t *cache, const uint32_t dst_imgid, const uint32_t src_imgid);
189
190// get the full path of a cached thumbnail
191void dt_mipmap_get_cache_filename(char path[PATH_MAX], const dt_mipmap_cache_t *cache, dt_mipmap_size_t mip, const int32_t imgid);
192
193// get just the dir
194void dt_mipmap_get_cache_dir(char path[PATH_MAX], const dt_mipmap_cache_t *cache, dt_mipmap_size_t mip);
195
196
197#ifdef __cplusplus
198}
199#endif
200
201// clang-format off
202// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
203// vim: shiftwidth=2 expandtab tabstop=2 cindent
204// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
205// clang-format on
atomic_int dt_atomic_int
Definition atomic.h:66
int width
Definition bilateral.h:1
int height
Definition bilateral.h:1
dt_colorspaces_color_profile_type_t
Definition colorspaces.h:81
#define PATH_MAX
Definition darktable.h:1061
dt_mipmap_buffer_dsc_flags flags
Definition mipmap_cache.c:4
void dt_mipmap_cache_get_with_caller_and_shutdown(dt_mipmap_cache_t *cache, dt_mipmap_buffer_t *buf, const int32_t imgid, const dt_mipmap_size_t mip, const dt_mipmap_get_flags_t flags, const char mode, dt_atomic_int *shutdown, const char *file, int line)
Definition mipmap_cache.c:976
void * dt_mipmap_cache_alloc(dt_mipmap_buffer_t *buf, const dt_image_t *img)
Definition mipmap_cache.c:416
void dt_mipmap_cache_remove_at_size(dt_mipmap_cache_t *cache, const int32_t imgid, const dt_mipmap_size_t mip, const gboolean flush_disk)
Definition mipmap_cache.c:1148
void dt_mipmap_get_cache_filename(char path[PATH_MAX], const dt_mipmap_cache_t *cache, dt_mipmap_size_t mip, const int32_t imgid)
Definition mipmap_cache.c:183
void dt_mipmap_cache_init(dt_mipmap_cache_t *cache)
Definition mipmap_cache.c:701
void dt_mipmap_cache_write_get_with_caller(dt_mipmap_cache_t *cache, dt_mipmap_buffer_t *buf, const int32_t imgid, const int mip, const char *file, int line)
Definition mipmap_cache.c:1045
void dt_mipmap_cache_get_with_caller(dt_mipmap_cache_t *cache, dt_mipmap_buffer_t *buf, const int32_t imgid, const dt_mipmap_size_t mip, const dt_mipmap_get_flags_t flags, const char mode, const char *file, int line)
Definition mipmap_cache.c:969
void dt_mipmap_cache_remove(dt_mipmap_cache_t *cache, const int32_t imgid, const gboolean flush_disk)
Definition mipmap_cache.c:1171
void dt_mipmap_cache_cleanup(dt_mipmap_cache_t *cache)
Definition mipmap_cache.c:764
dt_mipmap_get_flags_t
Definition mipmap_cache.h:58
@ DT_MIPMAP_BLOCKING
Definition mipmap_cache.h:61
@ DT_MIPMAP_TESTLOCK
Definition mipmap_cache.h:64
void dt_mimap_cache_evict(dt_mipmap_cache_t *cache, const int32_t imgid)
Definition mipmap_cache.c:1178
void dt_mipmap_cache_swap_at_size(dt_mipmap_cache_t *cache, const int32_t imgid, const dt_mipmap_size_t mip, const uint8_t *const buffer, const int32_t width, const int32_t height, dt_colorspaces_color_profile_type_t profile)
Definition mipmap_cache.c:1095
void dt_mipmap_get_cache_dir(char path[PATH_MAX], const dt_mipmap_cache_t *cache, dt_mipmap_size_t mip)
Definition mipmap_cache.c:177
void dt_mipmap_cache_print(dt_mipmap_cache_t *cache)
Definition mipmap_cache.c:772
dt_mipmap_size_t dt_mipmap_cache_get_fitting_size(const dt_mipmap_cache_t *cache, const int32_t width, const int32_t height, const uint32_t imgid)
Definition mipmap_cache.c:1081
dt_mipmap_size_t
Definition mipmap_cache.h:41
@ DT_MIPMAP_6
Definition mipmap_cache.h:48
@ DT_MIPMAP_1
Definition mipmap_cache.h:43
@ DT_MIPMAP_4
Definition mipmap_cache.h:46
@ DT_MIPMAP_F
Definition mipmap_cache.h:51
@ DT_MIPMAP_7
Definition mipmap_cache.h:49
@ DT_MIPMAP_0
Definition mipmap_cache.h:42
@ DT_MIPMAP_5
Definition mipmap_cache.h:47
@ DT_MIPMAP_2
Definition mipmap_cache.h:44
@ DT_MIPMAP_NONE
Definition mipmap_cache.h:53
@ DT_MIPMAP_3
Definition mipmap_cache.h:45
@ DT_MIPMAP_FULL
Definition mipmap_cache.h:52
@ DT_MIPMAP_8
Definition mipmap_cache.h:50
dt_mipmap_size_t dt_mipmap_cache_get_matching_size(const dt_mipmap_cache_t *cache, const int32_t width, const int32_t height, const uint32_t imgid)
Definition mipmap_cache.c:1065
void dt_mipmap_cache_copy_thumbnails(const dt_mipmap_cache_t *cache, const uint32_t dst_imgid, const uint32_t src_imgid)
Definition mipmap_cache.c:1504
void dt_mipmap_cache_release_with_caller(dt_mipmap_cache_t *cache, dt_mipmap_buffer_t *buf, const char *file, int line)
Definition mipmap_cache.c:1050
Definition common/cache.h:33
Definition common/cache.h:48
Definition image.h:247
Definition mipmap_cache.h:69
dt_colorspaces_color_profile_type_t color_space
Definition mipmap_cache.h:75
dt_cache_entry_t * cache_entry
Definition mipmap_cache.h:76
dt_mipmap_size_t size
Definition mipmap_cache.h:70
int32_t imgid
Definition mipmap_cache.h:71
int32_t height
Definition mipmap_cache.h:72
float iscale
Definition mipmap_cache.h:73
uint8_t * buf
Definition mipmap_cache.h:74
int32_t width
Definition mipmap_cache.h:72
Definition mipmap_cache.h:80
dt_cache_t cache
Definition mipmap_cache.h:82
long int stats_standin
Definition mipmap_cache.h:90
long int stats_misses
Definition mipmap_cache.h:88
long int stats_fetches
Definition mipmap_cache.h:89
long int stats_near_match
Definition mipmap_cache.h:87
long int stats_requests
Definition mipmap_cache.h:86
Definition mipmap_cache.h:94
dt_mipmap_cache_one_t mip_full
Definition mipmap_cache.h:105
size_t max_height[DT_MIPMAP_NONE]
Definition mipmap_cache.h:98
dt_mipmap_cache_one_t mip_f
Definition mipmap_cache.h:104
char cachedir[PATH_MAX]
Definition mipmap_cache.h:106
dt_mipmap_cache_one_t mip_thumbs
Definition mipmap_cache.h:103
size_t max_width[DT_MIPMAP_NONE]
Definition mipmap_cache.h:98
size_t buffer_size[DT_MIPMAP_NONE]
Definition mipmap_cache.h:100