2
This file is part of darktable,
3
copyright (c) 2009--2010 johannes hanika.
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.
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.
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/>.
22
#define _XOPEN_SOURCE 600 // for localtime_r
27
#include "common/dtpthread.h"
29
#include <sys/resource.h>
33
#include <glib/gi18n.h>
40
#define DT_MODULE_VERSION 3 // version of dt's module interface
41
#define DT_VERSION 36 // version of dt's database tables
42
#define DT_CONFIG_VERSION 34 // dt gconf var version
44
// every module has to define this:
46
#define DT_MODULE(MODVER) \
47
int dt_module_dt_version() \
49
return -DT_MODULE_VERSION; \
51
int dt_module_mod_version() \
56
#define DT_MODULE(MODVER) \
57
int dt_module_dt_version() \
59
return DT_MODULE_VERSION; \
61
int dt_module_mod_version() \
67
// ..to be able to compare it against this:
68
static inline int dt_version()
71
return -DT_MODULE_VERSION;
73
return DT_MODULE_VERSION;
78
#define M_PI 3.14159265358979323846
81
// NaN-safe clamping (NaN compares false, and will thus result in H)
82
#define CLAMPS(A, L, H) ((A) > (L) ? ((A) < (H) ? (A) : (H)) : (L))
87
struct dt_mipmap_cache_t;
88
struct dt_image_cache_t;
94
typedef enum dt_debug_thread_t
96
// powers of two, masking
100
DT_DEBUG_FSWATCH = 8,
102
DT_DEBUG_CAMCTL = 32,
103
DT_DEBUG_PWSTORAGE = 64,
104
DT_DEBUG_OPENCL = 128
108
typedef struct darktable_t
110
int32_t thumbnail_size;
113
GList *collection_listeners;
114
struct dt_conf_t *conf;
115
struct dt_develop_t *develop;
116
struct dt_lib_t *lib;
117
struct dt_view_manager_t *view_manager;
118
struct dt_control_t *control;
119
struct dt_gui_gtk_t *gui;
120
struct dt_mipmap_cache_t *mipmap_cache;
121
struct dt_image_cache_t *image_cache;
123
const struct dt_fswatch_t *fswatch;
124
const struct dt_pwstorage_t *pwstorage;
125
const struct dt_camctl_t *camctl;
126
const struct dt_collection_t *collection;
127
struct dt_points_t *points;
128
struct dt_imageio_t *imageio;
129
struct dt_opencl_t *opencl;
130
dt_pthread_mutex_t db_insert;
131
dt_pthread_mutex_t plugin_threadsafe;
143
extern darktable_t darktable;
144
extern const char dt_supported_extensions[];
146
int dt_init(int argc, char *argv[]);
148
void dt_print(dt_debug_thread_t thread, const char *msg, ...);
149
void dt_gettime_t(char *datetime, time_t t);
150
void dt_gettime(char *datetime);
151
void *dt_alloc_align(size_t alignment, size_t size);
152
void dt_get_datadir(char *datadir, size_t bufsize);
153
void dt_get_plugindir(char *datadir, size_t bufsize);
154
/** get the user directory of darktable, ~/.config/darktable */
155
void dt_get_user_config_dir(char *data, size_t bufsize);
156
/** get the user directory of darktable, ~/.cache/darktable */
157
void dt_get_user_cache_dir(char *data, size_t bufsize);
158
/** get the user local directory , ~/.local */
159
void dt_get_user_local_dir(char *data, size_t bufsize);
161
static inline double dt_get_wtime(void)
164
gettimeofday(&time, NULL);
165
return time.tv_sec - 1290608000 + (1.0/1000000.0)*time.tv_usec;
168
static inline void dt_get_times(dt_times_t *t)
171
if (darktable.unmuted & DT_DEBUG_PERF)
173
getrusage(RUSAGE_SELF, &ru);
174
t->clock = dt_get_wtime();
175
t->user = ru.ru_utime.tv_sec + ru.ru_utime.tv_usec * (1.0/1000000.0);
179
void dt_show_times(const dt_times_t *start, const char *prefix, const char *suffix, ...);
181
static inline int dt_get_num_threads()
184
return omp_get_num_procs();
190
static inline int dt_get_thread_num()
193
return omp_get_thread_num();
199
static inline float dt_log2f(const float f)
204
return logf(f)/logf(2.0f);
208
static inline float dt_fast_expf(const float x)
210
// meant for the range [-100.0f, 0.0f]. largest error ~ -0.06 at 0.0f.
211
// will get _a_lot_ worse for x > 0.0f (9000 at 10.0f)..
212
const int i1 = 0x3f800000u;
213
// e^x, the comment would be 2^x
214
const int i2 = 0x402DF854u;//0x40000000u;
215
// const int k = CLAMPS(i1 + x * (i2 - i1), 0x0u, 0x7fffffffu);
216
// without max clamping (doesn't work for large x, but is faster):
217
const int k0 = i1 + x * (i2 - i1);
218
const int k = k0 > 0 ? k0 : 0;
219
const float f = *(const float *)&k;