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

« back to all changes in this revision

Viewing changes to .pc/0004-reword-pop-up-message-about-missing-SSE2-instruction.patch/src/common/darktable.c

  • 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
 
#ifdef HAVE_CONFIG_H
19
 
#include "config.h"
20
 
#endif
21
 
#include "common/darktable.h"
22
 
#include "common/collection.h"
23
 
#include "common/exif.h"
24
 
#include "common/fswatch.h"
25
 
#include "common/pwstorage/pwstorage.h"
26
 
#ifdef HAVE_GPHOTO2
27
 
#include "common/camera_control.h"
28
 
#endif
29
 
#include "common/film.h"
30
 
#include "common/image.h"
31
 
#include "common/image_cache.h"
32
 
#include "common/imageio_module.h"
33
 
#include "common/points.h"
34
 
#include "common/opencl.h"
35
 
#include "develop/imageop.h"
36
 
#include "libs/lib.h"
37
 
#include "views/view.h"
38
 
#include "control/control.h"
39
 
#include "control/conf.h"
40
 
#include "gui/gtk.h"
41
 
#include <stdlib.h>
42
 
#include <stdio.h>
43
 
#include <string.h>
44
 
#include <glib.h>
45
 
#include <string.h>
46
 
#include <sys/param.h>
47
 
#include <unistd.h>
48
 
#ifdef _OPENMP
49
 
#  include <omp.h>
50
 
#endif
51
 
 
52
 
darktable_t darktable;
53
 
const char dt_supported_extensions[] = "3fr,arw,bay,bmq,cap,cine,cr2,crw,cs1,dc2,dcr,dng,erf,fff,exr,ia,iiq,jpg,jpeg,k25,kc2,kdc,mdc,mef,mos,mrw,nef,nrw,orf,pef,pfm,pxn,qtk,raf,raw,rdc,rw2,rwl,sr2,srf,sti,tif,tiff,x3f";
54
 
 
55
 
static int usage(const char *argv0)
56
 
{
57
 
  printf("usage: %s [-d {all,cache,control,dev,fswatch,camctl,perf,pwstorage,opencl}] [IMG_1234.{RAW,..}|image_folder/]", argv0);
58
 
#ifdef HAVE_OPENCL
59
 
  printf(" [--disable-opencl]");
60
 
#endif
61
 
  printf("\n");
62
 
  return 1;
63
 
}
64
 
 
65
 
typedef void (dt_signal_handler_t)(int) ;
66
 
static dt_signal_handler_t *_dt_sigill_old_handler = NULL;
67
 
 
68
 
static
69
 
void _dt_sigill_handler(int param) {
70
 
  
71
 
   GtkWidget *dlg = gtk_message_dialog_new(NULL,GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_(
72
 
"darktable has trapped an illegal instruction which probably mean that \
73
 
an invalid processor optimized codepath is used for your cpu, please try reproduce the crash running 'gdb darktable' from \
74
 
console and post backtrace log to mailing list with information about your CPU."));
75
 
    gtk_dialog_run(GTK_DIALOG(dlg));
76
 
  
77
 
  /* pass it further the old handler*/
78
 
  _dt_sigill_old_handler(param);
79
 
}
80
 
 
81
 
#if defined(__i386__) && defined(__PIC__)
82
 
#define cpuid(level, a, b, c, d) \
83
 
  __asm__ ("xchgl %%ebx, %1\n" \
84
 
        "cpuid\n" \
85
 
        "xchgl  %%ebx, %1\n" \
86
 
        : "=a" (a), "=r" (b), "=c" (c), "=d" (d)        \
87
 
        : "0" (level) \
88
 
      )
89
 
#else
90
 
#define cpuid(level, a, b, c, d) \
91
 
  __asm__ ("cpuid"      \
92
 
    : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \
93
 
    : "0" (level) \
94
 
    )
95
 
#endif
96
 
 
97
 
static 
98
 
void dt_check_cpu(int argc,char **argv) 
99
 
{
100
 
  /* hook up SIGILL handler */
101
 
  _dt_sigill_old_handler = signal(SIGILL,&_dt_sigill_handler);
102
 
 
103
 
  /* call cpuid for  SSE level */
104
 
  int ax,bx,cx,dx;
105
 
  cpuid(0x1,ax,bx,cx,dx);
106
 
  
107
 
  ax = bx = 0;
108
 
  char message[512]={0};
109
 
  strcat(message,_("SIMD extenstions found: "));
110
 
  if((cx & 1) && (darktable.cpu_flags |= DT_CPU_FLAG_SSE3))
111
 
    strcat(message,"SSE3 ");
112
 
  if( ((dx >> 26) & 1) && (darktable.cpu_flags |= DT_CPU_FLAG_SSE2))
113
 
    strcat(message,"SSE2 ");
114
 
  else if (((dx >> 25) & 1) && (darktable.cpu_flags |= DT_CPU_FLAG_SSE))
115
 
    strcat(message,"SSE ");
116
 
 
117
 
  /* for now, bail out if SSE2 is not availble */
118
 
  if(!(darktable.cpu_flags & DT_CPU_FLAG_SSE2))
119
 
  {
120
 
    gtk_init (&argc, &argv);
121
 
    
122
 
    GtkWidget *dlg = gtk_message_dialog_new(NULL,GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_(
123
 
"darktable is very cpu resource intensive and is using SSE2 SIMD instructions \
124
 
for heavy calculations, this is for a better user experience but also defines a minimum\
125
 
requirement of your processor.\n\nThe processor in YOUR system does NOT support this \
126
 
and darktable will now close down.\n\n%s"),message);
127
 
    
128
 
    gtk_dialog_run(GTK_DIALOG(dlg));
129
 
    
130
 
    exit(0);
131
 
  }
132
 
  
133
 
}
134
 
 
135
 
int dt_init(int argc, char *argv[])
136
 
{
137
 
#ifndef __SSE2__
138
 
  fprintf("[dt_init] unfortunately we depend on SSE2 instructions at this time.\n");
139
 
  fprintf("[dt_init] please contribute a backport patch (or buy a newer processor).\n");
140
 
  return 1;
141
 
#endif
142
 
  bindtextdomain (GETTEXT_PACKAGE, DARKTABLE_LOCALEDIR);
143
 
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
144
 
  textdomain (GETTEXT_PACKAGE);
145
 
 
146
 
  darktable.progname = argv[0];
147
 
 
148
 
  // database
149
 
  gchar *dbfilenameFromCommand = NULL;
150
 
 
151
 
#ifdef _OPENMP
152
 
  omp_set_num_threads(omp_get_num_procs());
153
 
#endif
154
 
  darktable.unmuted = 0;
155
 
  char *image_to_load = NULL;
156
 
  for(int k=1; k<argc; k++)
157
 
  {
158
 
    if(argv[k][0] == '-')
159
 
    {
160
 
      if(!strcmp(argv[k], "--help"))
161
 
      {
162
 
        return usage(argv[0]);
163
 
      }
164
 
      else if(!strcmp(argv[k], "--version"))
165
 
      {
166
 
        printf("this is "PACKAGE_STRING"\ncopyright (c) 2009-2011 johannes hanika\n"PACKAGE_BUGREPORT"\n");
167
 
        return 1;
168
 
      }
169
 
      else if(!strcmp(argv[k], "--library"))
170
 
      {
171
 
        dbfilenameFromCommand = argv[++k];
172
 
      }
173
 
      if(argv[k][1] == 'd' && argc > k+1)
174
 
      {
175
 
        if(!strcmp(argv[k+1], "all"))       darktable.unmuted = 0xffffffff;   // enable all debug information
176
 
        else if(!strcmp(argv[k+1], "cache"))     darktable.unmuted |= DT_DEBUG_CACHE;   // enable debugging for lib/film/cache module
177
 
        else if(!strcmp(argv[k+1], "control"))   darktable.unmuted |= DT_DEBUG_CONTROL; // enable debugging for scheduler module
178
 
        else if(!strcmp(argv[k+1], "dev"))       darktable.unmuted |= DT_DEBUG_DEV; // develop module
179
 
        else if(!strcmp(argv[k+1], "fswatch"))   darktable.unmuted |= DT_DEBUG_FSWATCH; // fswatch module
180
 
        else if(!strcmp(argv[k+1], "camctl"))    darktable.unmuted |= DT_DEBUG_CAMCTL; // camera control module
181
 
        else if(!strcmp(argv[k+1], "perf"))      darktable.unmuted |= DT_DEBUG_PERF; // performance measurements
182
 
        else if(!strcmp(argv[k+1], "pwstorage")) darktable.unmuted |= DT_DEBUG_PWSTORAGE; // pwstorage module
183
 
        else if(!strcmp(argv[k+1], "opencl"))    darktable.unmuted |= DT_DEBUG_OPENCL;    // gpu accel via opencl
184
 
        else return usage(argv[0]);
185
 
        k ++;
186
 
      }
187
 
    }
188
 
    else
189
 
    {
190
 
      image_to_load = argv[k];
191
 
    }
192
 
  }
193
 
 
194
 
 
195
 
  /* check cput caps */
196
 
  dt_check_cpu(argc,argv);
197
 
 
198
 
  
199
 
#ifdef HAVE_GEGL
200
 
  (void)setenv("GEGL_PATH", DARKTABLE_DATADIR"/gegl:/usr/lib/gegl-0.0", 1);
201
 
  gegl_init(&argc, &argv);
202
 
#endif
203
 
  // thread-safe init:
204
 
  dt_exif_init();
205
 
  char datadir[1024];
206
 
  dt_get_user_config_dir (datadir,1024);
207
 
  char filename[1024];
208
 
  snprintf(filename, 1024, "%s/darktablerc", datadir);
209
 
 
210
 
  // Initialize the filesystem watcher
211
 
  darktable.fswatch=dt_fswatch_new();
212
 
 
213
 
#ifdef HAVE_GPHOTO2
214
 
  // Initialize the camera control
215
 
  darktable.camctl=dt_camctl_new();
216
 
#endif
217
 
  // has to go first for settings needed by all the others.
218
 
  darktable.conf = (dt_conf_t *)malloc(sizeof(dt_conf_t));
219
 
  dt_conf_init(darktable.conf, filename);
220
 
 
221
 
  // get max lighttable thumbnail size:
222
 
  darktable.thumbnail_size = CLAMPS(dt_conf_get_int("plugins/lighttable/thumbnail_size"), 160, 1300);
223
 
  // and make sure it can be mip-mapped all the way from mip4 to mip0
224
 
  darktable.thumbnail_size /= 16;
225
 
  darktable.thumbnail_size *= 16;
226
 
 
227
 
  // Initialize the password storage engine
228
 
  darktable.pwstorage=dt_pwstorage_new();
229
 
 
230
 
  // check and migrate database into new XDG structure
231
 
  char dbfilename[2048]= {0};
232
 
  gchar *conf_db = dt_conf_get_string("database");
233
 
  if (conf_db && conf_db[0] != '/')
234
 
  {
235
 
    char *homedir = getenv ("HOME");
236
 
    snprintf (dbfilename,2048,"%s/%s", homedir, conf_db);
237
 
    if (g_file_test (dbfilename, G_FILE_TEST_EXISTS))
238
 
    {
239
 
      fprintf(stderr, "[init] moving database into new XDG directory structure\n");
240
 
      // move database into place
241
 
      char destdbname[2048]= {0};
242
 
      snprintf(destdbname,2048,"%s/%s",datadir,"library.db");
243
 
      if(!g_file_test (destdbname,G_FILE_TEST_EXISTS))
244
 
      {
245
 
        rename(dbfilename,destdbname);
246
 
        dt_conf_set_string("database","library.db");
247
 
      }
248
 
    }
249
 
    g_free(conf_db);
250
 
  }
251
 
 
252
 
  // check and migrate the cachedir
253
 
  char cachefilename[2048]= {0};
254
 
  char cachedir[2048]= {0};
255
 
  gchar *conf_cache = dt_conf_get_string("cachefile");
256
 
  if (conf_cache && conf_cache[0] != '/')
257
 
  {
258
 
    char *homedir = getenv ("HOME");
259
 
    snprintf (cachefilename,2048,"%s/%s",homedir, conf_cache);
260
 
    if (g_file_test (cachefilename,G_FILE_TEST_EXISTS))
261
 
    {
262
 
      fprintf(stderr, "[init] moving cache into new XDG directory structure\n");
263
 
      char destcachename[2048]= {0};
264
 
      snprintf(destcachename,2048,"%s/%s",cachedir,"mipmaps");
265
 
      if(!g_file_test (destcachename,G_FILE_TEST_EXISTS))
266
 
      {
267
 
        rename(cachefilename,destcachename);
268
 
        dt_conf_set_string("cachefile","mipmaps");
269
 
      }
270
 
    }
271
 
    g_free(conf_cache);
272
 
  }
273
 
 
274
 
  gchar * dbname = NULL;
275
 
  if ( dbfilenameFromCommand == NULL )
276
 
  {
277
 
    dbname = dt_conf_get_string ("database");
278
 
    if(!dbname)               snprintf(dbfilename, 1024, "%s/library.db", datadir);
279
 
    else if(dbname[0] != '/') snprintf(dbfilename, 1024, "%s/%s", datadir, dbname);
280
 
    else                      snprintf(dbfilename, 1024, "%s", dbname);
281
 
  }
282
 
  else
283
 
  {
284
 
    snprintf(dbfilename, 1024, "%s", dbfilenameFromCommand);
285
 
    dbname = g_file_get_basename (g_file_new_for_path(dbfilenameFromCommand));
286
 
  }
287
 
 
288
 
  int load_cached = 1;
289
 
  // if db file does not exist, also don't load the cache.
290
 
  if(!g_file_test(dbfilename, G_FILE_TEST_IS_REGULAR)) load_cached = 0;
291
 
  if(sqlite3_open(dbfilename, &(darktable.db)))
292
 
  {
293
 
    fprintf(stderr, "[init] could not open database ");
294
 
    if(dbname) fprintf(stderr, "`%s'!\n", dbname);
295
 
    else       fprintf(stderr, "\n");
296
 
#ifndef HAVE_GCONF
297
 
    fprintf(stderr, "[init] maybe your %s/darktablerc is corrupt?\n",datadir);
298
 
    dt_get_datadir(dbfilename, 512);
299
 
    fprintf(stderr, "[init] try `cp %s/darktablerc %s/darktablerc'\n", dbfilename,datadir);
300
 
#else
301
 
    fprintf(stderr, "[init] check your /apps/darktable/database gconf entry!\n");
302
 
#endif
303
 
    sqlite3_close(darktable.db);
304
 
    if (dbname != NULL) g_free(dbname);
305
 
    return 1;
306
 
  }
307
 
  if (dbname != NULL) g_free(dbname);
308
 
 
309
 
  dt_pthread_mutex_init(&(darktable.db_insert), NULL);
310
 
  dt_pthread_mutex_init(&(darktable.plugin_threadsafe), NULL);
311
 
 
312
 
  // initialize collection query
313
 
  darktable.collection_listeners = NULL;
314
 
  darktable.collection = dt_collection_new(NULL);
315
 
 
316
 
  darktable.opencl = (dt_opencl_t *)malloc(sizeof(dt_opencl_t));
317
 
  dt_opencl_init(darktable.opencl, argc, argv);
318
 
 
319
 
  darktable.points = (dt_points_t *)malloc(sizeof(dt_points_t));
320
 
  dt_points_init(darktable.points, dt_get_num_threads());
321
 
 
322
 
  darktable.control = (dt_control_t *)malloc(sizeof(dt_control_t));
323
 
  dt_control_init(darktable.control);
324
 
 
325
 
  int thumbnails = dt_conf_get_int ("mipmap_cache_thumbnails");
326
 
  thumbnails = MIN(1000, MAX(20, thumbnails));
327
 
 
328
 
  darktable.mipmap_cache = (dt_mipmap_cache_t *)malloc(sizeof(dt_mipmap_cache_t));
329
 
  dt_mipmap_cache_init(darktable.mipmap_cache, thumbnails);
330
 
 
331
 
  darktable.image_cache = (dt_image_cache_t *)malloc(sizeof(dt_image_cache_t));
332
 
  dt_image_cache_init(darktable.image_cache, MIN(10000, MAX(500, thumbnails)), load_cached);
333
 
 
334
 
  darktable.view_manager = (dt_view_manager_t *)malloc(sizeof(dt_view_manager_t));
335
 
  dt_view_manager_init(darktable.view_manager);
336
 
 
337
 
  darktable.gui = (dt_gui_gtk_t *)malloc(sizeof(dt_gui_gtk_t));
338
 
  if(dt_gui_gtk_init(darktable.gui, argc, argv)) return 1;
339
 
 
340
 
  // load the darkroom mode plugins once:
341
 
  dt_iop_load_modules_so();
342
 
 
343
 
  darktable.lib = (dt_lib_t *)malloc(sizeof(dt_lib_t));
344
 
  dt_lib_init(darktable.lib);
345
 
 
346
 
  dt_control_load_config(darktable.control);
347
 
  strncpy(darktable.control->global_settings.dbname, filename, 512); // overwrite if relocated.
348
 
 
349
 
  darktable.imageio = (dt_imageio_t *)malloc(sizeof(dt_imageio_t));
350
 
  dt_imageio_init(darktable.imageio);
351
 
 
352
 
  int id = 0;
353
 
  if(image_to_load)
354
 
  {
355
 
    char* filename;
356
 
    if(g_str_has_prefix(image_to_load, "file://"))
357
 
      image_to_load += strlen("file://");
358
 
    if(g_path_is_absolute(image_to_load) == FALSE)
359
 
    {
360
 
      char* current_dir = g_get_current_dir();
361
 
      char* tmp_filename = g_build_filename(current_dir, image_to_load, NULL);
362
 
      filename = (char*)g_malloc(sizeof(char)*MAXPATHLEN);
363
 
      if(realpath(tmp_filename, filename) == NULL)
364
 
      {
365
 
        dt_control_log(_("found strange path `%s'"), tmp_filename);
366
 
        g_free(current_dir);
367
 
        g_free(tmp_filename);
368
 
        g_free(filename);
369
 
        return 0;
370
 
      }
371
 
      g_free(current_dir);
372
 
      g_free(tmp_filename);
373
 
    }
374
 
    else
375
 
    {
376
 
      filename = g_strdup(image_to_load);
377
 
    }
378
 
 
379
 
    if(g_file_test(filename, G_FILE_TEST_IS_DIR))
380
 
    {
381
 
      // import a directory into a film roll
382
 
      unsigned int last_char = strlen(filename)-1;
383
 
      if(filename[last_char] == '/')
384
 
        filename[last_char] = '\0';
385
 
      id = dt_film_import(filename);
386
 
      if(id)
387
 
      {
388
 
        dt_film_open(id);
389
 
        dt_ctl_switch_mode_to(DT_LIBRARY);
390
 
      }
391
 
      else
392
 
      {
393
 
        dt_control_log(_("error loading directory `%s'"), filename);
394
 
      }
395
 
    }
396
 
    else
397
 
    {
398
 
      // import a single image
399
 
      gchar *directory = g_path_get_dirname((const gchar *)filename);
400
 
      dt_film_t film;
401
 
      const int filmid = dt_film_new(&film, directory);
402
 
      id = dt_image_import(filmid, filename, TRUE);
403
 
      g_free (directory);
404
 
      if(id)
405
 
      {
406
 
        dt_film_open(filmid);
407
 
        // make sure buffers are loaded (load full for testing)
408
 
        dt_image_t *img = dt_image_cache_get(id, 'r');
409
 
        dt_image_buffer_t buf = dt_image_get_blocking(img, DT_IMAGE_FULL, 'r');
410
 
        if(!buf)
411
 
        {
412
 
          id = 0;
413
 
          dt_image_cache_release(img, 'r');
414
 
          dt_control_log(_("file `%s' has unknown format!"), filename);
415
 
        }
416
 
        else
417
 
        {
418
 
          dt_image_release(img, DT_IMAGE_FULL, 'r');
419
 
          dt_image_cache_release(img, 'r');
420
 
          DT_CTL_SET_GLOBAL(lib_image_mouse_over_id, id);
421
 
          dt_ctl_switch_mode_to(DT_DEVELOP);
422
 
        }
423
 
      }
424
 
      else
425
 
      {
426
 
        dt_control_log(_("error loading file `%s'"), filename);
427
 
      }
428
 
    }
429
 
    g_free(filename);
430
 
  }
431
 
  if(!id)
432
 
  {
433
 
    dt_ctl_switch_mode_to(DT_LIBRARY);
434
 
  }
435
 
 
436
 
  return 0;
437
 
}
438
 
 
439
 
void dt_cleanup()
440
 
{
441
 
  dt_ctl_switch_mode_to(DT_MODE_NONE);
442
 
 
443
 
  dt_control_write_config(darktable.control);
444
 
  dt_control_shutdown(darktable.control);
445
 
 
446
 
  dt_lib_cleanup(darktable.lib);
447
 
  free(darktable.lib);
448
 
  dt_view_manager_cleanup(darktable.view_manager);
449
 
  free(darktable.view_manager);
450
 
  dt_imageio_cleanup(darktable.imageio);
451
 
  free(darktable.imageio);
452
 
  dt_gui_gtk_cleanup(darktable.gui);
453
 
  free(darktable.gui);
454
 
  dt_image_cache_cleanup(darktable.image_cache);
455
 
  free(darktable.image_cache);
456
 
  dt_mipmap_cache_cleanup(darktable.mipmap_cache);
457
 
  free(darktable.mipmap_cache);
458
 
  dt_control_cleanup(darktable.control);
459
 
  free(darktable.control);
460
 
  dt_conf_cleanup(darktable.conf);
461
 
  free(darktable.conf);
462
 
  dt_points_cleanup(darktable.points);
463
 
  free(darktable.points);
464
 
  dt_iop_unload_modules_so();
465
 
  dt_opencl_cleanup(darktable.opencl);
466
 
  free(darktable.opencl);
467
 
#ifdef HAVE_GPHOTO2
468
 
  dt_camctl_destroy(darktable.camctl);
469
 
#endif
470
 
  dt_pwstorage_destroy(darktable.pwstorage);
471
 
  dt_fswatch_destroy(darktable.fswatch);
472
 
 
473
 
  sqlite3_close(darktable.db);
474
 
  dt_pthread_mutex_destroy(&(darktable.db_insert));
475
 
  dt_pthread_mutex_destroy(&(darktable.plugin_threadsafe));
476
 
 
477
 
  dt_exif_cleanup();
478
 
#ifdef HAVE_GEGL
479
 
  gegl_exit();
480
 
#endif
481
 
}
482
 
 
483
 
void dt_print(dt_debug_thread_t thread, const char *msg, ...)
484
 
{
485
 
  if(darktable.unmuted & thread)
486
 
  {
487
 
    va_list ap;
488
 
    va_start(ap, msg);
489
 
    vprintf(msg, ap);
490
 
    va_end(ap);
491
 
  }
492
 
}
493
 
 
494
 
void dt_gettime_t(char *datetime, time_t t)
495
 
{
496
 
  struct tm tt;
497
 
  (void)localtime_r(&t, &tt);
498
 
  strftime(datetime, 20, "%Y:%m:%d %H:%M:%S", &tt);
499
 
}
500
 
 
501
 
void dt_gettime(char *datetime)
502
 
{
503
 
  dt_gettime_t(datetime, time(NULL));
504
 
}
505
 
 
506
 
void *dt_alloc_align(size_t alignment, size_t size)
507
 
{
508
 
#if defined(__MACH__) || defined(__APPLE__) || (defined(__FreeBSD_version) && __FreeBSD_version < 700013)
509
 
  return malloc(size);
510
 
#else
511
 
  void *ptr = NULL;
512
 
  if(posix_memalign(&ptr, alignment, size)) return NULL;
513
 
  return ptr;
514
 
#endif
515
 
}
516
 
 
517
 
void
518
 
dt_get_user_config_dir (char *data, size_t bufsize)
519
 
{
520
 
  g_snprintf (data,bufsize,"%s/.config/darktable",getenv("HOME"));
521
 
  if (g_file_test (data,G_FILE_TEST_EXISTS)==FALSE)
522
 
    g_mkdir_with_parents (data,0700);
523
 
}
524
 
 
525
 
void
526
 
dt_get_user_cache_dir (char *data, size_t bufsize)
527
 
{
528
 
  g_snprintf (data,bufsize,"%s/.cache/darktable",getenv("HOME"));
529
 
  if (g_file_test (data,G_FILE_TEST_EXISTS)==FALSE)
530
 
    g_mkdir_with_parents (data,0700);
531
 
}
532
 
 
533
 
 
534
 
void
535
 
dt_get_user_local_dir (char *data, size_t bufsize)
536
 
{
537
 
  g_snprintf(data,bufsize,"%s/.local",getenv("HOME"));
538
 
  if (g_file_test (data,G_FILE_TEST_EXISTS)==FALSE)
539
 
    g_mkdir_with_parents (data,0700);
540
 
 
541
 
}
542
 
 
543
 
void dt_get_plugindir(char *datadir, size_t bufsize)
544
 
{
545
 
#if defined(__MACH__) || defined(__APPLE__)
546
 
  gchar *curr = g_get_current_dir();
547
 
  int contains = 0;
548
 
  for(int k=0; darktable.progname[k] != 0; k++) if(darktable.progname[k] == '/')
549
 
    {
550
 
      contains = 1;
551
 
      break;
552
 
    }
553
 
  if(darktable.progname[0] == '/') // absolute path
554
 
    snprintf(datadir, bufsize, "%s", darktable.progname);
555
 
  else if(contains) // relative path
556
 
    snprintf(datadir, bufsize, "%s/%s", curr, darktable.progname);
557
 
  else
558
 
  {
559
 
    // no idea where we have been called. use compiled in path
560
 
    g_free(curr);
561
 
    snprintf(datadir, bufsize, "%s/darktable", DARKTABLE_LIBDIR);
562
 
    return;
563
 
  }
564
 
  size_t len = MIN(strlen(datadir), bufsize);
565
 
  char *t = datadir + len; // strip off bin/darktable
566
 
  for(; t>datadir && *t!='/'; t--);
567
 
  t--;
568
 
  if(*t == '.' && *(t-1) != '.')
569
 
  {
570
 
    for(; t>datadir && *t!='/'; t--);
571
 
    t--;
572
 
  }
573
 
  for(; t>datadir && *t!='/'; t--);
574
 
  strcpy(t, "/lib/darktable");
575
 
  g_free(curr);
576
 
#else
577
 
  snprintf(datadir, bufsize, "%s/darktable", DARKTABLE_LIBDIR);
578
 
#endif
579
 
}
580
 
 
581
 
void dt_get_datadir(char *datadir, size_t bufsize)
582
 
{
583
 
#if defined(__MACH__) || defined(__APPLE__)
584
 
  gchar *curr = g_get_current_dir();
585
 
  int contains = 0;
586
 
  for(int k=0; darktable.progname[k] != 0; k++) if(darktable.progname[k] == '/')
587
 
    {
588
 
      contains = 1;
589
 
      break;
590
 
    }
591
 
  if(darktable.progname[0] == '/') // absolute path
592
 
    snprintf(datadir, bufsize, "%s", darktable.progname);
593
 
  else if(contains) // relative path
594
 
    snprintf(datadir, bufsize, "%s/%s", curr, darktable.progname);
595
 
  else
596
 
  {
597
 
    // no idea where we have been called. use compiled in path
598
 
    g_free(curr);
599
 
    snprintf(datadir, bufsize, "%s", DARKTABLE_DATADIR);
600
 
    return;
601
 
  }
602
 
  size_t len = MIN(strlen(datadir), bufsize);
603
 
  char *t = datadir + len; // strip off bin/darktable
604
 
  for(; t>datadir && *t!='/'; t--);
605
 
  t--;
606
 
  if(*t == '.' && *(t-1) != '.')
607
 
  {
608
 
    for(; t>datadir && *t!='/'; t--);
609
 
    t--;
610
 
  }
611
 
  for(; t>datadir && *t!='/'; t--);
612
 
  strcpy(t, "/share/darktable");
613
 
  g_free(curr);
614
 
#else
615
 
  snprintf(datadir, bufsize, "%s", DARKTABLE_DATADIR);
616
 
#endif
617
 
}
618
 
 
619
 
void dt_show_times(const dt_times_t *start, const char *prefix, const char *suffix, ...)
620
 
{
621
 
  dt_times_t end;
622
 
  char buf[120];                /* Arbitrary size, should be lots big enough for everything used in DT */
623
 
  int i;
624
 
 
625
 
  /* Skip all the calculations an everything if -d perf isn't on */
626
 
  if (darktable.unmuted & DT_DEBUG_PERF)
627
 
  {
628
 
    dt_get_times(&end);
629
 
    i = sprintf(buf, "%s took %.3f secs (%.3f CPU)", prefix, end.clock - start->clock, end.user - start->user);
630
 
    if (suffix != NULL)
631
 
    {
632
 
      va_list ap;
633
 
      va_start(ap, suffix);
634
 
      buf[i++] = ' ';
635
 
      vsnprintf(buf + i, sizeof buf - i, suffix, ap);
636
 
      va_end(ap);
637
 
    }
638
 
    dt_print(DT_DEBUG_PERF, "%s\n", buf);
639
 
  }
640
 
}