equal
deleted
inserted
replaced
6 * |
6 * |
7 * Internal image cache implementation |
7 * Internal image cache implementation |
8 */ |
8 */ |
9 #include "image.h" |
9 #include "image.h" |
10 |
10 |
|
11 #include <stdint.h> |
|
12 #include <stdbool.h> |
|
13 |
|
14 #include <png.h> |
|
15 |
11 /** |
16 /** |
12 * State for cache access |
17 * State for cache access |
13 */ |
18 */ |
14 struct pt_cache { |
19 struct pt_cache { |
|
20 /** Filesystem path to cache file */ |
|
21 char *path; |
15 |
22 |
|
23 /** The mode we are operating in, bitmask of PT_IMG_* */ |
|
24 int mode; |
|
25 |
|
26 /** Opened file */ |
|
27 int fd; |
|
28 |
|
29 /** Memory-mapped file data, from the second page on */ |
|
30 uint8_t *mmap; |
|
31 |
|
32 /** Size of the mmap'd segment in bytes */ |
|
33 size_t size; |
16 }; |
34 }; |
|
35 |
|
36 /** |
|
37 * Size of a cache file page in bytes |
|
38 */ |
|
39 #define PT_CACHE_PAGE 4096 |
17 |
40 |
18 /** |
41 /** |
19 * On-disk header |
42 * On-disk header |
20 */ |
43 */ |
21 struct pt_cache_header { |
44 struct pt_cache_header { |
30 }; |
53 }; |
31 |
54 |
32 /** |
55 /** |
33 * Construct the image cache info object associated with the given image. |
56 * Construct the image cache info object associated with the given image. |
34 */ |
57 */ |
35 int pt_cache_open (struct pt_cache **cache_ptr, struct pt_image *img, int mode); |
58 int pt_cache_open (struct pt_cache **cache_ptr, const char *path, int mode); |
36 |
59 |
37 /** |
60 /** |
38 * Verify if the cached data is still fresh compared to the original. |
61 * Verify if the cached data has become stale compared to the given original file. |
39 */ |
62 */ |
40 bool pt_cache_fresh (struct pt_cache *cache); |
63 int pt_cache_stale (struct pt_cache *cache, const char *orig_path); |
41 |
64 |
42 /** |
65 /** |
43 * Update the cache data from the given PNG image. |
66 * Update the cache data from the given PNG image. |
44 */ |
67 */ |
45 int pt_cache_update_png (struct pt_cache *cache, png_structp png, png_infop info); |
68 int pt_cache_update_png (struct pt_cache *cache, png_structp png, png_infop info); |
46 |
69 |
|
70 /** |
|
71 * Release all resources associated with the given cache object without any cleanup. |
|
72 */ |
|
73 void pt_cache_destroy (struct pt_cache *cache); |
|
74 |
47 #endif |
75 #endif |