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

« back to all changes in this revision

Viewing changes to src/common/image_cache.h

  • Committer: Bazaar Package Importer
  • Author(s): David Bremner
  • Date: 2011-04-14 23:42:12 UTC
  • Revision ID: james.westby@ubuntu.com-20110414234212-kuffcz5wiu18v6ra
Tags: upstream-0.8
ImportĀ upstreamĀ versionĀ 0.8

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 DT_IMAGE_CACHE_H
 
19
#define DT_IMAGE_CACHE_H
 
20
 
 
21
#include "common/image.h"
 
22
#include "common/dtpthread.h"
 
23
 
 
24
#include <inttypes.h>
 
25
 
 
26
/**
 
27
 * image cache to hold temporary representations
 
28
 * from sql queries.
 
29
 * fast access by img->id via sorted index,
 
30
 * which is updated each time a new image is alloc'ed or
 
31
 * an old image is kicked.
 
32
 * lru list maintained via linked list for fast updates.
 
33
 */
 
34
 
 
35
typedef struct dt_image_cache_line_t
 
36
{
 
37
  dt_image_t image;
 
38
  dt_image_lock_t lock;
 
39
  int16_t mru, lru;
 
40
}
 
41
dt_image_cache_line_t;
 
42
 
 
43
typedef struct dt_image_cache_t
 
44
{
 
45
  dt_pthread_mutex_t mutex;
 
46
  int32_t num_lines;
 
47
  dt_image_cache_line_t *line;
 
48
  int16_t *by_id;
 
49
  int16_t lru, mru;
 
50
}
 
51
dt_image_cache_t;
 
52
 
 
53
void dt_image_cache_init(dt_image_cache_t *cache, int32_t entries, const int32_t load_cached);
 
54
void dt_image_cache_cleanup(dt_image_cache_t *cache);
 
55
/** print some debug info. */
 
56
void dt_image_cache_print(dt_image_cache_t *cache);
 
57
 
 
58
/** returns alloc'ed image (newly or from cache) or NULL on failure.
 
59
 * lru is freed instead. there is no explicit interface for free.
 
60
 * result will have users lock incremented.
 
61
 * init image from db if it was not already loaded. */
 
62
dt_image_t *dt_image_cache_get(int32_t id, const char mode);
 
63
/** only use for import. */
 
64
dt_image_t *dt_image_cache_get_uninited(int32_t id, const char mode);
 
65
/** decrements users lock. */
 
66
void dt_image_cache_release(dt_image_t *img, const char mode);
 
67
/** synches this image and the db entry. */
 
68
void dt_image_cache_flush(dt_image_t *img);
 
69
/** same as above, but doesn't write the redundant sidecar files. */
 
70
void dt_image_cache_flush_no_sidecars(dt_image_t *img);
 
71
/** invalidates resources occupied by this image. */
 
72
void dt_image_cache_clear(int32_t id);
 
73
 
 
74
#endif