forked from darktable-org/darktable
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdarktable.h
More file actions
381 lines (341 loc) · 9.75 KB
/
Copy pathdarktable.h
File metadata and controls
381 lines (341 loc) · 9.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
/*
This file is part of darktable,
copyright (c) 2009--2012 johannes hanika.
darktable is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
darktable is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with darktable. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DARKTABLE_H
#define DARKTABLE_H
// just to be sure. the build system should set this for us already:
#if defined __DragonFly__ || defined __FreeBSD__ || \
defined __NetBSD__ || defined __OpenBSD__
#define _WITH_DPRINTF
#elif !defined _XOPEN_SOURCE
#define _XOPEN_SOURCE 700 // for localtime_r and dprintf
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "common/dtpthread.h"
#include "common/database.h"
#include "common/utility.h"
#include <lua.h>
#include <lauxlib.h>
#include <time.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <stdio.h>
#include <inttypes.h>
#include <sqlite3.h>
#include <glib/gi18n.h>
#include <glib.h>
#include <math.h>
#include <sys/types.h>
#include <unistd.h>
#ifdef __APPLE__
#include <mach/mach.h>
#include <sys/sysctl.h>
#endif
#if defined(__DragonFly__) || defined(__FreeBSD__)
typedef unsigned int u_int;
#include <sys/types.h>
#include <sys/sysctl.h>
#endif
#if defined(__NetBSD__) || defined(__OpenBSD__)
#include <sys/param.h>
#include <sys/sysctl.h>
#endif
#ifdef _OPENMP
#include <omp.h>
#else
#define omp_get_max_threads() 1
#define omp_get_thread_num() 0
#endif
#define DT_MODULE_VERSION 6 // version of dt's module interface
#define DT_VERSION 36 // version of dt's database tables
#define DT_CONFIG_VERSION 34 // dt conf var version
// every module has to define this:
#ifdef _DEBUG
#define DT_MODULE(MODVER) \
int dt_module_dt_version() \
{\
return -DT_MODULE_VERSION; \
}\
int dt_module_mod_version() \
{\
return MODVER; \
}
#else
#define DT_MODULE(MODVER) \
int dt_module_dt_version() \
{\
return DT_MODULE_VERSION; \
}\
int dt_module_mod_version() \
{\
return MODVER; \
}
#endif
// ..to be able to compare it against this:
static inline int dt_version()
{
#ifdef _DEBUG
return -DT_MODULE_VERSION;
#else
return DT_MODULE_VERSION;
#endif
}
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
// Golden number (1+sqrt(5))/2
#ifndef PHI
#define PHI 1.61803398874989479F
#endif
// 1/PHI
#ifndef INVPHI
#define INVPHI 0.61803398874989479F
#endif
// NaN-safe clamping (NaN compares false, and will thus result in H)
#define CLAMPS(A, L, H) ((A) > (L) ? ((A) < (H) ? (A) : (H)) : (L))
struct dt_gui_gtk_t;
struct dt_control_t;
struct dt_develop_t;
struct dt_mipmap_cache_t;
struct dt_image_cache_t;
struct dt_lib_t;
struct dt_conf_t;
struct dt_points_t;
struct dt_imageio_t;
struct dt_bauhaus_t;
typedef enum dt_debug_thread_t
{
// powers of two, masking
DT_DEBUG_CACHE = 1,
DT_DEBUG_CONTROL = 2,
DT_DEBUG_DEV = 4,
DT_DEBUG_FSWATCH = 8,
DT_DEBUG_PERF = 16,
DT_DEBUG_CAMCTL = 32,
DT_DEBUG_PWSTORAGE = 64,
DT_DEBUG_OPENCL = 128,
DT_DEBUG_SQL = 256,
DT_DEBUG_MEMORY = 512,
DT_DEBUG_LUA = 1024,
}
dt_debug_thread_t;
#define DT_CPU_FLAG_SSE 1
#define DT_CPU_FLAG_SSE2 2
#define DT_CPU_FLAG_SSE3 4
typedef struct darktable_t
{
uint32_t cpu_flags;
int32_t num_openmp_threads;
int32_t thumbnail_width, thumbnail_height;
int32_t unmuted;
GList *iop;
GList *collection_listeners;
struct dt_conf_t *conf;
struct dt_develop_t *develop;
struct dt_lib_t *lib;
struct dt_view_manager_t *view_manager;
struct dt_control_t *control;
struct dt_control_signal_t *signals;
struct dt_gui_gtk_t *gui;
struct dt_mipmap_cache_t *mipmap_cache;
struct dt_image_cache_t *image_cache;
struct dt_bauhaus_t *bauhaus;
const struct dt_database_t *db;
const struct dt_fswatch_t *fswatch;
const struct dt_pwstorage_t *pwstorage;
const struct dt_camctl_t *camctl;
const struct dt_collection_t *collection;
struct dt_selection_t *selection;
struct dt_points_t *points;
struct dt_imageio_t *imageio;
struct dt_opencl_t *opencl;
struct dt_blendop_t *blendop;
dt_pthread_mutex_t db_insert;
dt_pthread_mutex_t plugin_threadsafe;
char *progname;
char *datadir;
char *plugindir;
char *tmpdir;
char *configdir;
char *cachedir;
lua_State *lua_state;
}
darktable_t;
typedef struct
{
double clock;
double user;
}
dt_times_t;
extern darktable_t darktable;
extern const char dt_supported_extensions[];
int dt_init(int argc, char *argv[], const int init_gui);
void dt_cleanup();
void dt_print(dt_debug_thread_t thread, const char *msg, ...);
void dt_gettime_t(char *datetime, time_t t);
void dt_gettime(char *datetime);
void *dt_alloc_align(size_t alignment, size_t size);
static inline double dt_get_wtime(void)
{
struct timeval time;
gettimeofday(&time, NULL);
return time.tv_sec - 1290608000 + (1.0/1000000.0)*time.tv_usec;
}
static inline void dt_get_times(dt_times_t *t)
{
struct rusage ru;
if (darktable.unmuted & DT_DEBUG_PERF)
{
getrusage(RUSAGE_SELF, &ru);
t->clock = dt_get_wtime();
t->user = ru.ru_utime.tv_sec + ru.ru_utime.tv_usec * (1.0/1000000.0);
}
}
void dt_show_times(const dt_times_t *start, const char *prefix, const char *suffix, ...);
/** \brief check if file is a supported image */
gboolean dt_supported_image(const gchar *filename);
static inline int dt_get_num_threads()
{
#ifdef _OPENMP
return omp_get_num_procs();
#else
return 1;
#endif
}
static inline int dt_get_thread_num()
{
#ifdef _OPENMP
return omp_get_thread_num();
#else
return 0;
#endif
}
static inline float dt_log2f(const float f)
{
#ifdef __GLIBC__
return log2f(f);
#else
return logf(f)/logf(2.0f);
#endif
}
static inline float dt_fast_expf(const float x)
{
// meant for the range [-100.0f, 0.0f]. largest error ~ -0.06 at 0.0f.
// will get _a_lot_ worse for x > 0.0f (9000 at 10.0f)..
const int i1 = 0x3f800000u;
// e^x, the comment would be 2^x
const int i2 = 0x402DF854u;//0x40000000u;
// const int k = CLAMPS(i1 + x * (i2 - i1), 0x0u, 0x7fffffffu);
// without max clamping (doesn't work for large x, but is faster):
const int k0 = i1 + x * (i2 - i1);
const int k = k0 > 0 ? k0 : 0;
const float f = *(const float *)&k;
return f;
}
static inline void dt_print_mem_usage()
{
#if defined(__linux__)
char *line = NULL;
size_t len = 128;
char vmsize[64];
char vmpeak[64];
char vmrss[64];
char vmhwm[64];
FILE *f;
char pidstatus[128];
snprintf(pidstatus, 128, "/proc/%u/status", (uint32_t)getpid());
f = fopen(pidstatus, "r");
if (!f) return;
/* read memory size data from /proc/pid/status */
while (getline(&line, &len, f) != -1)
{
if (!strncmp(line, "VmPeak:", 7))
strncpy(vmpeak, line + 8, 64);
else if (!strncmp(line, "VmSize:", 7))
strncpy(vmsize, line + 8, 64);
else if (!strncmp(line, "VmRSS:", 6))
strncpy(vmrss, line + 8, 64);
else if (!strncmp(line, "VmHWM:", 6))
strncpy(vmhwm, line + 8, 64);
}
free(line);
fclose(f);
fprintf(stderr, "[memory] max address space (vmpeak): %15s"
"[memory] cur address space (vmsize): %15s"
"[memory] max used memory (vmhwm ): %15s"
"[memory] cur used memory (vmrss ): %15s",
vmpeak, vmsize, vmhwm, vmrss);
#elif defined(__APPLE__)
struct task_basic_info t_info;
mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;
if (KERN_SUCCESS != task_info(mach_task_self(),
TASK_BASIC_INFO, (task_info_t)&t_info,
&t_info_count))
{
fprintf(stderr, "[memory] task memory info unknown.\n");
return;
}
// Report in kB, to match output of /proc on Linux.
fprintf(stderr, "[memory] max address space (vmpeak): %15s\n"
"[memory] cur address space (vmsize): %12llu kB\n"
"[memory] max used memory (vmhwm ): %15s\n"
"[memory] cur used memory (vmrss ): %12llu kB\n",
"unknown", (uint64_t)t_info.virtual_size / 1024,
"unknown", (uint64_t)t_info.resident_size / 1024);
#else
fprintf(stderr, "dt_print_mem_usage() currently unsupported on this platform\n");
#endif
}
static inline size_t
dt_get_total_memory()
{
#if defined(__linux__)
FILE *f = fopen("/proc/meminfo", "rb");
if(!f) return 0;
size_t mem = 0;
char *line = NULL;
size_t len = 0;
if(getline(&line, &len, f) != -1)
mem = atol(line + 10);
fclose(f);
if(len > 0)
free(line);
return mem;
#elif defined(__APPLE__) || \
defined(__DragonFly__) || \
defined(__FreeBSD__) || \
defined(__NetBSD__) || \
defined(__OpenBSD__)
#if defined(__APPLE__)
int mib[2] = { CTL_HW, HW_MEMSIZE };
#else
int mib[2] = { CTL_HW, HW_PHYSMEM };
#endif
uint64_t physical_memory;
size_t length = sizeof(uint64_t);
sysctl(mib, 2, (void *)&physical_memory, &length, (void *)NULL, 0);
return physical_memory / 1024;
#else
// assume 2GB until we have a better solution.
fprintf(stderr, "Unknown memory size. Assuming 2GB\n");
return 2097152;
#endif
}
void dt_configure_defaults();
#endif
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh
// vim: shiftwidth=2 expandtab tabstop=2 cindent
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-space on;