author | Tero Marttila <terom@fixme.fi> |
Sun, 24 Jan 2010 23:20:39 +0200 | |
changeset 55 | a3542e78ecd8 |
parent 52 | 148a120ea7d5 |
child 56 | d5e3089906da |
permissions | -rw-r--r-- |
0 | 1 |
#ifndef PNGTILE_CACHE_H |
2 |
#define PNGTILE_CACHE_H |
|
3 |
||
4 |
/** |
|
5 |
* @file |
|
6 |
* |
|
7 |
* Internal image cache implementation |
|
8 |
*/ |
|
9 |
#include "image.h" |
|
10 |
||
1
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
11 |
#include <stdint.h> |
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
12 |
#include <stdbool.h> |
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
13 |
|
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
14 |
#include <png.h> |
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
15 |
|
0 | 16 |
/** |
17 |
* State for cache access |
|
18 |
*/ |
|
19 |
struct pt_cache { |
|
1
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
20 |
/** Filesystem path to cache file */ |
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
21 |
char *path; |
0 | 22 |
|
1
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
23 |
/** The mode we are operating in, bitmask of PT_IMG_* */ |
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
24 |
int mode; |
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
25 |
|
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
26 |
/** Opened file */ |
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
27 |
int fd; |
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
28 |
|
7
997906f5fd2d
mmap header, implement pt_image_info (post-update)
Tero Marttila <terom@fixme.fi>
parents:
6
diff
changeset
|
29 |
/** The mmap'd header */ |
997906f5fd2d
mmap header, implement pt_image_info (post-update)
Tero Marttila <terom@fixme.fi>
parents:
6
diff
changeset
|
30 |
struct pt_cache_header *header; |
1
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
31 |
|
7
997906f5fd2d
mmap header, implement pt_image_info (post-update)
Tero Marttila <terom@fixme.fi>
parents:
6
diff
changeset
|
32 |
/** Memory-mapped file data, starting at PT_CACHE_HEADER_SIZE */ |
997906f5fd2d
mmap header, implement pt_image_info (post-update)
Tero Marttila <terom@fixme.fi>
parents:
6
diff
changeset
|
33 |
uint8_t *data; |
997906f5fd2d
mmap header, implement pt_image_info (post-update)
Tero Marttila <terom@fixme.fi>
parents:
6
diff
changeset
|
34 |
|
997906f5fd2d
mmap header, implement pt_image_info (post-update)
Tero Marttila <terom@fixme.fi>
parents:
6
diff
changeset
|
35 |
/** Size of the data segment in bytes, starting at PT_CACHE_HEADER_SIZE */ |
1
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
36 |
size_t size; |
0 | 37 |
}; |
38 |
||
39 |
/** |
|
7
997906f5fd2d
mmap header, implement pt_image_info (post-update)
Tero Marttila <terom@fixme.fi>
parents:
6
diff
changeset
|
40 |
* Size used to store the cache header |
1
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
41 |
*/ |
7
997906f5fd2d
mmap header, implement pt_image_info (post-update)
Tero Marttila <terom@fixme.fi>
parents:
6
diff
changeset
|
42 |
#define PT_CACHE_HEADER_SIZE 4096 |
1
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
43 |
|
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
44 |
/** |
0 | 45 |
* On-disk header |
46 |
*/ |
|
47 |
struct pt_cache_header { |
|
48 |
/** Pixel dimensions of image */ |
|
49 |
uint32_t width, height; |
|
50 |
||
51 |
/** Pixel format */ |
|
52 |
uint8_t bit_depth, color_type; |
|
53 |
||
6
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
2
diff
changeset
|
54 |
/** Number of png_color entries that follow */ |
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
2
diff
changeset
|
55 |
uint16_t num_palette; |
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
2
diff
changeset
|
56 |
|
15 | 57 |
/** Number of bytes per row */ |
0 | 58 |
uint32_t row_bytes; |
9 | 59 |
|
60 |
/** Number of bytes per pixel */ |
|
61 |
uint8_t col_bytes; |
|
6
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
2
diff
changeset
|
62 |
|
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
2
diff
changeset
|
63 |
/** Palette entries, up to 256 entries used */ |
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
2
diff
changeset
|
64 |
png_color palette[PNG_MAX_PALETTE_LENGTH]; |
52
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
15
diff
changeset
|
65 |
|
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
15
diff
changeset
|
66 |
/** Parameters used */ |
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
15
diff
changeset
|
67 |
struct pt_image_params params; |
0 | 68 |
}; |
69 |
||
70 |
/** |
|
52
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
15
diff
changeset
|
71 |
* Handle sparse data at this granularity (pixels) |
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
15
diff
changeset
|
72 |
*/ |
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
15
diff
changeset
|
73 |
#define PT_CACHE_BLOCK_SIZE 64 |
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
15
diff
changeset
|
74 |
|
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
15
diff
changeset
|
75 |
/** |
0 | 76 |
* Construct the image cache info object associated with the given image. |
77 |
*/ |
|
9 | 78 |
int pt_cache_new (struct pt_cache **cache_ptr, const char *path, int mode); |
0 | 79 |
|
80 |
/** |
|
8 | 81 |
* Verify if the cached data eixsts, or has become stale compared to the given original file. |
82 |
* |
|
83 |
* @return one of pt_cache_status; <0 on error, 0 if fresh, >0 otherwise |
|
0 | 84 |
*/ |
8 | 85 |
int pt_cache_status (struct pt_cache *cache, const char *img_path); |
0 | 86 |
|
87 |
/** |
|
10
6806a90d934f
make pt_cache_open no-op if already open, pt_image_info -> pt_cache_info
Tero Marttila <terom@fixme.fi>
parents:
9
diff
changeset
|
88 |
* Get info for the cached image, open it if not already open. |
6806a90d934f
make pt_cache_open no-op if already open, pt_image_info -> pt_cache_info
Tero Marttila <terom@fixme.fi>
parents:
9
diff
changeset
|
89 |
*/ |
6806a90d934f
make pt_cache_open no-op if already open, pt_image_info -> pt_cache_info
Tero Marttila <terom@fixme.fi>
parents:
9
diff
changeset
|
90 |
int pt_cache_info (struct pt_cache *cache, struct pt_image_info *info); |
6806a90d934f
make pt_cache_open no-op if already open, pt_image_info -> pt_cache_info
Tero Marttila <terom@fixme.fi>
parents:
9
diff
changeset
|
91 |
|
6806a90d934f
make pt_cache_open no-op if already open, pt_image_info -> pt_cache_info
Tero Marttila <terom@fixme.fi>
parents:
9
diff
changeset
|
92 |
/** |
0 | 93 |
* Update the cache data from the given PNG image. |
94 |
*/ |
|
52
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
15
diff
changeset
|
95 |
int pt_cache_update_png (struct pt_cache *cache, png_structp png, png_infop info, const struct pt_image_params *params); |
0 | 96 |
|
1
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
97 |
/** |
10
6806a90d934f
make pt_cache_open no-op if already open, pt_image_info -> pt_cache_info
Tero Marttila <terom@fixme.fi>
parents:
9
diff
changeset
|
98 |
* Open the existing .cache for use. If already opened, does nothing. |
9 | 99 |
*/ |
100 |
int pt_cache_open (struct pt_cache *cache); |
|
101 |
||
102 |
/** |
|
103 |
* Render out a PNG tile as given, into the established png object, up to (but not including) the png_write_end. |
|
104 |
* |
|
105 |
* If the cache is not yet open, this will open it |
|
106 |
*/ |
|
107 |
int pt_cache_tile_png (struct pt_cache *cache, png_structp png, png_infop info, const struct pt_tile_info *ti); |
|
108 |
||
109 |
/** |
|
1
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
110 |
* Release all resources associated with the given cache object without any cleanup. |
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
111 |
*/ |
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
112 |
void pt_cache_destroy (struct pt_cache *cache); |
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
113 |
|
0 | 114 |
#endif |