~ubuntu-branches/ubuntu/saucy/darktable/saucy

« back to all changes in this revision

Viewing changes to .pc/0002-Added-initial-runtime-cpu-checks-for-detecting-simd-.patch/src/common/darktable.h

  • Committer: Bazaar Package Importer
  • Author(s): David Bremner
  • Date: 2011-07-12 09:36:46 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110712093646-yp9dbxan44dmw15h
Tags: 0.9-1
* New upstream release.
* Remove all patches now upstream; only patch for
  -Wno-error=unused-but-set-variable remains.
* Bump Standards-Version to 3.9.2 (no changes)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    This file is part of darktable,
3
 
    copyright (c) 2009--2010 johannes hanika.
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
 
#ifndef DARKTABLE_H
19
 
#define DARKTABLE_H
20
 
 
21
 
#ifndef _XOPEN_SOURCE
22
 
#define _XOPEN_SOURCE 600 // for localtime_r
23
 
#endif
24
 
#ifdef HAVE_CONFIG_H
25
 
#include "config.h"
26
 
#endif
27
 
#include "common/dtpthread.h"
28
 
#include <time.h>
29
 
#include <sys/resource.h>
30
 
#include <sys/time.h>
31
 
#include <inttypes.h>
32
 
#include <sqlite3.h>
33
 
#include <glib/gi18n.h>
34
 
#include <glib.h>
35
 
#include <math.h>
36
 
#ifdef _OPENMP
37
 
#include <omp.h>
38
 
#endif
39
 
 
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
43
 
 
44
 
// every module has to define this:
45
 
#ifdef _DEBUG
46
 
#define DT_MODULE(MODVER) \
47
 
int dt_module_dt_version() \
48
 
{\
49
 
  return -DT_MODULE_VERSION; \
50
 
}\
51
 
int dt_module_mod_version() \
52
 
{\
53
 
  return MODVER; \
54
 
}
55
 
#else
56
 
#define DT_MODULE(MODVER) \
57
 
int dt_module_dt_version() \
58
 
{\
59
 
  return DT_MODULE_VERSION; \
60
 
}\
61
 
int dt_module_mod_version() \
62
 
{\
63
 
  return MODVER; \
64
 
}
65
 
#endif
66
 
 
67
 
// ..to be able to compare it against this:
68
 
static inline int dt_version()
69
 
{
70
 
#ifdef _DEBUG
71
 
  return -DT_MODULE_VERSION;
72
 
#else
73
 
  return DT_MODULE_VERSION;
74
 
#endif
75
 
}
76
 
 
77
 
#ifndef M_PI
78
 
#define M_PI 3.14159265358979323846
79
 
#endif
80
 
 
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))
83
 
 
84
 
struct dt_gui_gtk_t;
85
 
struct dt_control_t;
86
 
struct dt_develop_t;
87
 
struct dt_mipmap_cache_t;
88
 
struct dt_image_cache_t;
89
 
struct dt_lib_t;
90
 
struct dt_conf_t;
91
 
struct dt_points_t;
92
 
struct dt_imageio_t;
93
 
 
94
 
typedef enum dt_debug_thread_t
95
 
{
96
 
  // powers of two, masking
97
 
  DT_DEBUG_CACHE = 1,
98
 
  DT_DEBUG_CONTROL = 2,
99
 
  DT_DEBUG_DEV = 4,
100
 
  DT_DEBUG_FSWATCH = 8,
101
 
  DT_DEBUG_PERF = 16,
102
 
  DT_DEBUG_CAMCTL = 32,
103
 
  DT_DEBUG_PWSTORAGE = 64,
104
 
  DT_DEBUG_OPENCL = 128
105
 
}
106
 
dt_debug_thread_t;
107
 
 
108
 
typedef struct darktable_t
109
 
{
110
 
  int32_t thumbnail_size;
111
 
  int32_t unmuted;
112
 
  GList                          *iop;
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;
122
 
  sqlite3                        *db;
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;
132
 
  char *progname;
133
 
}
134
 
darktable_t;
135
 
 
136
 
typedef struct
137
 
{
138
 
  double clock;
139
 
  double user;
140
 
}
141
 
dt_times_t;
142
 
 
143
 
extern darktable_t darktable;
144
 
extern const char dt_supported_extensions[];
145
 
 
146
 
int dt_init(int argc, char *argv[]);
147
 
void dt_cleanup();
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);
160
 
 
161
 
static inline double dt_get_wtime(void)
162
 
{
163
 
  struct timeval time;
164
 
  gettimeofday(&time, NULL);
165
 
  return time.tv_sec - 1290608000 + (1.0/1000000.0)*time.tv_usec;
166
 
}
167
 
 
168
 
static inline void dt_get_times(dt_times_t *t)
169
 
{
170
 
  struct rusage ru;
171
 
  if (darktable.unmuted & DT_DEBUG_PERF)
172
 
  {
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);
176
 
  }
177
 
}
178
 
 
179
 
void dt_show_times(const dt_times_t *start, const char *prefix, const char *suffix, ...);
180
 
 
181
 
static inline int dt_get_num_threads()
182
 
{
183
 
#ifdef _OPENMP
184
 
  return omp_get_num_procs();
185
 
#else
186
 
  return 1;
187
 
#endif
188
 
}
189
 
 
190
 
static inline int dt_get_thread_num()
191
 
{
192
 
#ifdef _OPENMP
193
 
  return omp_get_thread_num();
194
 
#else
195
 
  return 0;
196
 
#endif
197
 
}
198
 
 
199
 
static inline float dt_log2f(const float f)
200
 
{
201
 
#ifdef __GLIBC__
202
 
  return log2f(f);
203
 
#else
204
 
  return logf(f)/logf(2.0f);
205
 
#endif
206
 
}
207
 
 
208
 
static inline float dt_fast_expf(const float x)
209
 
{
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;
220
 
  return f;
221
 
}
222
 
 
223
 
#endif