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/cache.h"
32#include "common/colorspaces.h"
33#include "common/image.h"
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39// sizes stored in the mipmap cache, set to fixed values in mipmap_cache.c
40typedef enum dt_mipmap_size_t {
41 DT_MIPMAP_0, // 360x225 px
42 DT_MIPMAP_1, // 720x450 px
43 DT_MIPMAP_2, // 1440x900 px
44 DT_MIPMAP_3, // Full HD 1080p
45 DT_MIPMAP_4, // 2560x1440 px
46 DT_MIPMAP_5, // 4K/UHD -
50 DT_MIPMAP_F, // unprocessed input float image downscaled to 720x450 or 1440x900 px for performance
51 DT_MIPMAP_FULL, // unprocessed input float image at original resolation
54
55// type to be passed to getter functions
57{
58 // only return when the requested buffer is loaded.
59 // blocks until that happens.
61 // don't actually acquire the lock if it is not
62 // in cache (i.e. would have to be loaded first)
65
66// struct to be alloc'ed by the client, filled by dt_mipmap_cache_get()
77
79{
80 // one cache per mipmap scale!
82
83 // a few stats on usage in this run.
84 // long int to give 32-bits on old archs, so __sync* calls will work.
85 long int stats_requests; // number of total requests
86 long int stats_near_match; // served with smaller mip res
87 long int stats_misses; // nothing returned at all.
88 long int stats_fetches; // texture was fetched (either as a stand-in or as per request)
89 long int stats_standin; // texture used as stand-in
91
92typedef struct dt_mipmap_cache_t
93{
94 // real width and height are stored per element
95 // (could be smaller than the max for this mip level,
96 // due to aspect ratio)
98 // size of an element inside buf
100
101 // one cache per mipmap level
105 char cachedir[PATH_MAX]; // cached sha1sum filename for faster access
107
108// dynamic memory allocation interface for imageio backend: a write locked
109// mipmap buffer is passed in, it might already contain a valid buffer. this
110// function takes care of re-allocating, if necessary.
112
116
117// get a buffer and lock according to mode ('r' or 'w').
118// see dt_mipmap_get_flags_t for explanation of the exact
119// behaviour. pass 0 as flags for the default (best effort)
120#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__)
122 dt_mipmap_cache_t *cache,
124 const int32_t imgid,
125 const dt_mipmap_size_t mip,
127 const char mode,
128 const char *file,
129 int line);
130
131// convenience function with fewer params
132#define dt_mipmap_cache_write_get(A,B,C,D) dt_mipmap_cache_write_get_with_caller(A,B,C,D,__FILE__,__LINE__)
134 dt_mipmap_cache_t *cache,
136 const int32_t imgid,
137 const int mip,
138 const char *file,
139 int line);
140
141// drop a lock
142#define dt_mipmap_cache_release(A, B) dt_mipmap_cache_release_with_caller(A, B, __FILE__, __LINE__)
144 int line);
145
146// remove thumbnails, so they will be regenerated:
147void dt_mipmap_cache_remove(dt_mipmap_cache_t *cache, const int32_t imgid, const gboolean flush_disk);
148void 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);
149
150// evict thumbnails from cache. They will be written to disc if not existing
151void dt_mimap_cache_evict(dt_mipmap_cache_t *cache, const int32_t imgid);
152
153// return the closest mipmap size
154// for the given window you wish to draw.
155// a dt_mipmap_size_t has always a fixed resolution associated with it,
156// depending on the user parameter for the maximum thumbnail dimensions.
157// actual resolution depends on the image and is only known after
158// the thumbnail is loaded.
160 const dt_mipmap_cache_t *cache,
161 const int32_t width,
162 const int32_t height);
163
164// copy over thumbnails. used by file operation that copies raw files, to speed up thumbnail generation.
165// only copies over the jpg backend on disk, doesn't directly affect the in-memory cache.
166void dt_mipmap_cache_copy_thumbnails(const dt_mipmap_cache_t *cache, const uint32_t dst_imgid, const uint32_t src_imgid);
167
168#ifdef __cplusplus
169}
170#endif
171
172// clang-format off
173// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
174// vim: shiftwidth=2 expandtab tabstop=2 cindent
175// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
176// clang-format on
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:994
dt_mipmap_buffer_dsc_flags flags
Definition mipmap_cache.c:4
void * dt_mipmap_cache_alloc(dt_mipmap_buffer_t *buf, const dt_image_t *img)
Definition mipmap_cache.c:425
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:1068
void dt_mipmap_cache_init(dt_mipmap_cache_t *cache)
Definition mipmap_cache.c:714
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:1034
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:966
void dt_mipmap_cache_remove(dt_mipmap_cache_t *cache, const int32_t imgid, const gboolean flush_disk)
Definition mipmap_cache.c:1091
void dt_mipmap_cache_cleanup(dt_mipmap_cache_t *cache)
Definition mipmap_cache.c:777
dt_mipmap_get_flags_t
Definition mipmap_cache.h:57
@ DT_MIPMAP_BLOCKING
Definition mipmap_cache.h:60
@ DT_MIPMAP_TESTLOCK
Definition mipmap_cache.h:63
void dt_mimap_cache_evict(dt_mipmap_cache_t *cache, const int32_t imgid)
Definition mipmap_cache.c:1098
void dt_mipmap_cache_print(dt_mipmap_cache_t *cache)
Definition mipmap_cache.c:785
dt_mipmap_size_t
Definition mipmap_cache.h:40
@ DT_MIPMAP_6
Definition mipmap_cache.h:47
@ DT_MIPMAP_1
Definition mipmap_cache.h:42
@ DT_MIPMAP_4
Definition mipmap_cache.h:45
@ DT_MIPMAP_F
Definition mipmap_cache.h:50
@ DT_MIPMAP_7
Definition mipmap_cache.h:48
@ DT_MIPMAP_0
Definition mipmap_cache.h:41
@ DT_MIPMAP_5
Definition mipmap_cache.h:46
@ DT_MIPMAP_2
Definition mipmap_cache.h:43
@ DT_MIPMAP_NONE
Definition mipmap_cache.h:52
@ DT_MIPMAP_3
Definition mipmap_cache.h:44
@ DT_MIPMAP_FULL
Definition mipmap_cache.h:51
@ DT_MIPMAP_8
Definition mipmap_cache.h:49
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:1423
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:1039
dt_mipmap_size_t dt_mipmap_cache_get_matching_size(const dt_mipmap_cache_t *cache, const int32_t width, const int32_t height)
Definition mipmap_cache.c:1054
Definition common/cache.h:33
Definition common/cache.h:48
Definition common/image.h:247
Definition mipmap_cache.h:68
dt_colorspaces_color_profile_type_t color_space
Definition mipmap_cache.h:74
dt_cache_entry_t * cache_entry
Definition mipmap_cache.h:75
dt_mipmap_size_t size
Definition mipmap_cache.h:69
int32_t imgid
Definition mipmap_cache.h:70
int32_t height
Definition mipmap_cache.h:71
float iscale
Definition mipmap_cache.h:72
uint8_t * buf
Definition mipmap_cache.h:73
int32_t width
Definition mipmap_cache.h:71
Definition mipmap_cache.h:79
dt_cache_t cache
Definition mipmap_cache.h:81
long int stats_standin
Definition mipmap_cache.h:89
long int stats_misses
Definition mipmap_cache.h:87
long int stats_fetches
Definition mipmap_cache.h:88
long int stats_near_match
Definition mipmap_cache.h:86
long int stats_requests
Definition mipmap_cache.h:85
Definition mipmap_cache.h:93
dt_mipmap_cache_one_t mip_full
Definition mipmap_cache.h:104
size_t max_height[DT_MIPMAP_NONE]
Definition mipmap_cache.h:97
dt_mipmap_cache_one_t mip_f
Definition mipmap_cache.h:103
char cachedir[PATH_MAX]
Definition mipmap_cache.h:105
dt_mipmap_cache_one_t mip_thumbs
Definition mipmap_cache.h:102
size_t max_width[DT_MIPMAP_NONE]
Definition mipmap_cache.h:97
size_t buffer_size[DT_MIPMAP_NONE]
Definition mipmap_cache.h:99