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) 2011-2021 darktable developers.
4
5 darktable is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 darktable is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with darktable. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#pragma once
20
21#include "common/cache.h"
22#include "common/colorspaces.h"
23#include "common/image.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29// sizes stored in the mipmap cache, set to fixed values in mipmap_cache.c
30typedef enum dt_mipmap_size_t {
31 DT_MIPMAP_0, // 360x225 px
32 DT_MIPMAP_1, // 720x450 px
33 DT_MIPMAP_2, // 1440x900 px
34 DT_MIPMAP_3, // Full HD 1080p
35 DT_MIPMAP_4, // 2560x1440 px
36 DT_MIPMAP_5, // 4K/UHD -
40 DT_MIPMAP_F, // unprocessed input float image downscaled to 720x450 or 1440x900 px for performance
41 DT_MIPMAP_FULL, // unprocessed input float image at original resolation
44
45// type to be passed to getter functions
47{
48 // only return when the requested buffer is loaded.
49 // blocks until that happens.
51 // don't actually acquire the lock if it is not
52 // in cache (i.e. would have to be loaded first)
55
56// struct to be alloc'ed by the client, filled by dt_mipmap_cache_get()
67
69{
70 // one cache per mipmap scale!
72
73 // a few stats on usage in this run.
74 // long int to give 32-bits on old archs, so __sync* calls will work.
75 long int stats_requests; // number of total requests
76 long int stats_near_match; // served with smaller mip res
77 long int stats_misses; // nothing returned at all.
78 long int stats_fetches; // texture was fetched (either as a stand-in or as per request)
79 long int stats_standin; // texture used as stand-in
81
82typedef struct dt_mipmap_cache_t
83{
84 // real width and height are stored per element
85 // (could be smaller than the max for this mip level,
86 // due to aspect ratio)
88 // size of an element inside buf
90
91 // one cache per mipmap level
95 char cachedir[PATH_MAX]; // cached sha1sum filename for faster access
97
98// dynamic memory allocation interface for imageio backend: a write locked
99// mipmap buffer is passed in, it might already contain a valid buffer. this
100// function takes care of re-allocating, if necessary.
102
106
107// get a buffer and lock according to mode ('r' or 'w').
108// see dt_mipmap_get_flags_t for explanation of the exact
109// behaviour. pass 0 as flags for the default (best effort)
110#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__)
112 dt_mipmap_cache_t *cache,
114 const int32_t imgid,
115 const dt_mipmap_size_t mip,
117 const char mode,
118 const char *file,
119 int line);
120
121// convenience function with fewer params
122#define dt_mipmap_cache_write_get(A,B,C,D) dt_mipmap_cache_write_get_with_caller(A,B,C,D,__FILE__,__LINE__)
124 dt_mipmap_cache_t *cache,
126 const int32_t imgid,
127 const int mip,
128 const char *file,
129 int line);
130
131// drop a lock
132#define dt_mipmap_cache_release(A, B) dt_mipmap_cache_release_with_caller(A, B, __FILE__, __LINE__)
134 int line);
135
136// remove thumbnails, so they will be regenerated:
137void dt_mipmap_cache_remove(dt_mipmap_cache_t *cache, const int32_t imgid, const gboolean flush_disk);
138void 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);
139
140// evict thumbnails from cache. They will be written to disc if not existing
141void dt_mimap_cache_evict(dt_mipmap_cache_t *cache, const int32_t imgid);
142
143// return the closest mipmap size
144// for the given window you wish to draw.
145// a dt_mipmap_size_t has always a fixed resolution associated with it,
146// depending on the user parameter for the maximum thumbnail dimensions.
147// actual resolution depends on the image and is only known after
148// the thumbnail is loaded.
150 const dt_mipmap_cache_t *cache,
151 const int32_t width,
152 const int32_t height);
153
154// copy over thumbnails. used by file operation that copies raw files, to speed up thumbnail generation.
155// only copies over the jpg backend on disk, doesn't directly affect the in-memory cache.
156void dt_mipmap_cache_copy_thumbnails(const dt_mipmap_cache_t *cache, const uint32_t dst_imgid, const uint32_t src_imgid);
157
158#ifdef __cplusplus
159}
160#endif
161
162// clang-format off
163// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
164// vim: shiftwidth=2 expandtab tabstop=2 cindent
165// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
166// clang-format on
int width
Definition bilateral.h:1
int height
Definition bilateral.h:1
dt_colorspaces_color_profile_type_t
Definition colorspaces.h:61
#define PATH_MAX
Definition darktable.h:824
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:358
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:975
void dt_mipmap_cache_init(dt_mipmap_cache_t *cache)
Definition mipmap_cache.c:626
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:941
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:873
void dt_mipmap_cache_remove(dt_mipmap_cache_t *cache, const int32_t imgid, const gboolean flush_disk)
Definition mipmap_cache.c:998
void dt_mipmap_cache_cleanup(dt_mipmap_cache_t *cache)
Definition mipmap_cache.c:689
dt_mipmap_get_flags_t
Definition mipmap_cache.h:47
@ DT_MIPMAP_BLOCKING
Definition mipmap_cache.h:50
@ DT_MIPMAP_TESTLOCK
Definition mipmap_cache.h:53
void dt_mimap_cache_evict(dt_mipmap_cache_t *cache, const int32_t imgid)
Definition mipmap_cache.c:1005
void dt_mipmap_cache_print(dt_mipmap_cache_t *cache)
Definition mipmap_cache.c:697
dt_mipmap_size_t
Definition mipmap_cache.h:30
@ DT_MIPMAP_6
Definition mipmap_cache.h:37
@ DT_MIPMAP_1
Definition mipmap_cache.h:32
@ DT_MIPMAP_4
Definition mipmap_cache.h:35
@ DT_MIPMAP_F
Definition mipmap_cache.h:40
@ DT_MIPMAP_7
Definition mipmap_cache.h:38
@ DT_MIPMAP_0
Definition mipmap_cache.h:31
@ DT_MIPMAP_5
Definition mipmap_cache.h:36
@ DT_MIPMAP_2
Definition mipmap_cache.h:33
@ DT_MIPMAP_NONE
Definition mipmap_cache.h:42
@ DT_MIPMAP_3
Definition mipmap_cache.h:34
@ DT_MIPMAP_FULL
Definition mipmap_cache.h:41
@ DT_MIPMAP_8
Definition mipmap_cache.h:39
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:1301
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:946
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:961
Definition cache.h:27
Definition cache.h:42
Definition common/image.h:195
Definition mipmap_cache.h:58
dt_colorspaces_color_profile_type_t color_space
Definition mipmap_cache.h:64
dt_cache_entry_t * cache_entry
Definition mipmap_cache.h:65
dt_mipmap_size_t size
Definition mipmap_cache.h:59
int32_t imgid
Definition mipmap_cache.h:60
int32_t height
Definition mipmap_cache.h:61
float iscale
Definition mipmap_cache.h:62
uint8_t * buf
Definition mipmap_cache.h:63
int32_t width
Definition mipmap_cache.h:61
Definition mipmap_cache.h:69
dt_cache_t cache
Definition mipmap_cache.h:71
long int stats_standin
Definition mipmap_cache.h:79
long int stats_misses
Definition mipmap_cache.h:77
long int stats_fetches
Definition mipmap_cache.h:78
long int stats_near_match
Definition mipmap_cache.h:76
long int stats_requests
Definition mipmap_cache.h:75
Definition mipmap_cache.h:83
dt_mipmap_cache_one_t mip_full
Definition mipmap_cache.h:94
size_t max_height[DT_MIPMAP_NONE]
Definition mipmap_cache.h:87
dt_mipmap_cache_one_t mip_f
Definition mipmap_cache.h:93
char cachedir[PATH_MAX]
Definition mipmap_cache.h:95
dt_mipmap_cache_one_t mip_thumbs
Definition mipmap_cache.h:92
size_t max_width[DT_MIPMAP_NONE]
Definition mipmap_cache.h:87
size_t buffer_size[DT_MIPMAP_NONE]
Definition mipmap_cache.h:89