author | Tero Marttila <terom@fixme.fi> |
Tue, 29 Dec 2009 15:34:18 +0200 | |
changeset 15 | 01de253f3bbf |
parent 13 | 294201975f8c |
permissions | -rw-r--r-- |
0 | 1 |
#ifndef PNGTILE_H |
2 |
#define PNGTILE_H |
|
3 |
||
4 |
/** |
|
5 |
* @file |
|
6 |
* |
|
7 |
* Tile-based access to large PNG images. |
|
8 |
*/ |
|
6
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
9 |
#include <stddef.h> |
9 | 10 |
#include <stdio.h> // for FILE* |
0 | 11 |
|
12 |
/** |
|
13 |
* "Global" context shared between images |
|
14 |
*/ |
|
15 |
struct pt_ctx; |
|
16 |
||
17 |
/** |
|
18 |
* Per-image state |
|
19 |
*/ |
|
20 |
struct pt_image; |
|
21 |
||
6
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
22 |
/** Bitmask for pt_image_open modes */ |
15 | 23 |
enum pt_open_mode { |
6
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
24 |
/** Update cache if needed */ |
11 | 25 |
PT_OPEN_UPDATE = 0x01, |
6
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
26 |
|
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
27 |
/** Accept stale cache */ |
15 | 28 |
// TODO: PT_OPEN_STALE = 0x02, |
6
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
29 |
}; |
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
30 |
|
8 | 31 |
/** |
32 |
* Values for pt_image_cached |
|
33 |
*/ |
|
34 |
enum pt_cache_status { |
|
35 |
/** Cache status could not be determined */ |
|
36 |
PT_CACHE_ERROR = -1, |
|
37 |
||
38 |
/** Cache is fresh */ |
|
39 |
PT_CACHE_FRESH = 0, |
|
40 |
||
41 |
/** Cache does not exist */ |
|
42 |
PT_CACHE_NONE = 1, |
|
43 |
||
44 |
/** Cache exists, but is stale */ |
|
45 |
PT_CACHE_STALE = 2, |
|
46 |
}; |
|
47 |
||
6
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
48 |
/** Metadata info for image */ |
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
49 |
struct pt_image_info { |
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
50 |
/** Dimensions of image */ |
7
997906f5fd2d
mmap header, implement pt_image_info (post-update)
Tero Marttila <terom@fixme.fi>
parents:
6
diff
changeset
|
51 |
size_t width, height; |
0 | 52 |
}; |
53 |
||
13
294201975f8c
fix clip_x bug, and reject images that are completely out of bounds
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
54 |
/** |
294201975f8c
fix clip_x bug, and reject images that are completely out of bounds
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
55 |
* Info for image tile |
294201975f8c
fix clip_x bug, and reject images that are completely out of bounds
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
56 |
* |
294201975f8c
fix clip_x bug, and reject images that are completely out of bounds
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
57 |
* The tile may safely overlap with the edge of the image, but it should not be entirely outside of the image |
294201975f8c
fix clip_x bug, and reject images that are completely out of bounds
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
58 |
*/ |
9 | 59 |
struct pt_tile_info { |
60 |
/** Dimensions of output image */ |
|
61 |
size_t width, height; |
|
62 |
||
63 |
/** Pixel coordinates of top-left corner */ |
|
64 |
size_t x, y; |
|
65 |
||
66 |
/** Zoom factor (out < zero < in) */ |
|
67 |
// TODO: int zoom; |
|
68 |
}; |
|
69 |
||
11 | 70 |
/** |
71 |
* TODO: impl |
|
72 |
*/ |
|
0 | 73 |
int pt_ctx_new (struct pt_ctx **ctx_ptr); |
74 |
||
75 |
/** |
|
76 |
* Open a new pt_image for use. |
|
77 |
* |
|
78 |
* @param img_ptr returned pt_image handle |
|
79 |
* @param ctx global state to use |
|
80 |
* @param path filesystem path to .png file |
|
11 | 81 |
* @param mode combination of PT_OPEN_* flags |
0 | 82 |
*/ |
5
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
83 |
int pt_image_open (struct pt_image **image_ptr, struct pt_ctx *ctx, const char *png_path, int cache_mode); |
0 | 84 |
|
5
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
85 |
/** |
6
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
86 |
* Get the image's metadata |
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
87 |
*/ |
7
997906f5fd2d
mmap header, implement pt_image_info (post-update)
Tero Marttila <terom@fixme.fi>
parents:
6
diff
changeset
|
88 |
int pt_image_info (struct pt_image *image, const struct pt_image_info **info_ptr); |
6
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
89 |
|
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
90 |
/** |
8 | 91 |
* Check the given image's cache is stale - in other words, if the image needs to be update()'d. |
92 |
* |
|
93 |
* @return one of pt_cache_status |
|
5
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
94 |
*/ |
8 | 95 |
int pt_image_status (struct pt_image *image); |
0 | 96 |
|
5
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
97 |
/** |
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
98 |
* Update the given image's cache. |
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
99 |
*/ |
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
100 |
int pt_image_update (struct pt_image *image); |
0 | 101 |
|
6
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
102 |
/** |
9 | 103 |
* Render a PNG tile to a stream. |
104 |
* |
|
105 |
* The PNG data will be written to the given stream, which will be flushed, but not closed. |
|
106 |
*/ |
|
107 |
int pt_image_tile (struct pt_image *image, const struct pt_tile_info *info, FILE *out); |
|
108 |
||
109 |
/** |
|
6
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
110 |
* Release the given pt_image without any clean shutdown |
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
111 |
*/ |
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
112 |
void pt_image_destroy (struct pt_image *image); |
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
113 |
|
0 | 114 |
#endif |