author | Tero Marttila <terom@fixme.fi> |
Mon, 25 Jan 2010 04:34:02 +0200 | |
changeset 88 | 5cc2d044d368 |
parent 69 | 1d188aa94aee |
child 177 | b2768f3982f3 |
permissions | -rw-r--r-- |
0 | 1 |
#include "image.h" |
19
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
2 |
#include "ctx.h" |
56
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
3 |
#include "png.h" |
1
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
4 |
#include "cache.h" |
18 | 5 |
#include "tile.h" |
17
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
6 |
#include "error.h" |
4
49362b34116c
open cache as .tmp, and rename to .cache when done
Tero Marttila <terom@fixme.fi>
parents:
3
diff
changeset
|
7 |
#include "shared/util.h" |
19
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
8 |
#include "shared/log.h" |
0 | 9 |
|
1
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
10 |
#include <stdlib.h> |
54
4a25113cb2a4
add some additional pt_image_info fields for stat
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
11 |
#include <sys/stat.h> |
4a25113cb2a4
add some additional pt_image_info fields for stat
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
12 |
#include <unistd.h> |
6
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
13 |
#include <errno.h> |
1
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
14 |
|
17
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
15 |
static int pt_image_new (struct pt_image **image_ptr, struct pt_ctx *ctx, const char *path) |
0 | 16 |
{ |
17
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
17 |
struct pt_image *image; |
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
18 |
int err = 0; |
0 | 19 |
|
20 |
// alloc |
|
17
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
21 |
if ((image = calloc(1, sizeof(*image))) == NULL) |
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
22 |
JUMP_SET_ERROR(err, PT_ERR_MEM); |
0 | 23 |
|
17
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
24 |
if ((image->path = strdup(path)) == NULL) |
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
25 |
JUMP_SET_ERROR(err, PT_ERR_MEM); |
0 | 26 |
|
27 |
// init |
|
17
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
28 |
image->ctx = ctx; |
0 | 29 |
|
30 |
// ok |
|
17
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
31 |
*image_ptr = image; |
0 | 32 |
|
33 |
return 0; |
|
34 |
||
35 |
error: |
|
17
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
36 |
pt_image_destroy(image); |
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
37 |
|
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
38 |
return err; |
0 | 39 |
} |
40 |
||
41 |
/** |
|
1
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
42 |
* Build a filesystem path representing the appropriate path for this image's cache entry, and store it in the given |
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
43 |
* buffer. |
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
44 |
*/ |
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
45 |
static int pt_image_cache_path (struct pt_image *image, char *buf, size_t len) |
0 | 46 |
{ |
17
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
47 |
if (path_with_fext(image->path, buf, len, ".cache")) |
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
48 |
RETURN_ERROR(PT_ERR_PATH); |
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
49 |
|
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
50 |
return 0; |
1
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
51 |
} |
0 | 52 |
|
1
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
53 |
int pt_image_open (struct pt_image **image_ptr, struct pt_ctx *ctx, const char *path, int cache_mode) |
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
54 |
{ |
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
55 |
struct pt_image *image; |
6
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
56 |
char cache_path[1024]; |
17
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
57 |
int err; |
1
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
58 |
|
69
1d188aa94aee
pt_png_check, and fclose() pt_image_open_file
Tero Marttila <terom@fixme.fi>
parents:
64
diff
changeset
|
59 |
// verify that the path exists and looks like a PNG file |
1d188aa94aee
pt_png_check, and fclose() pt_image_open_file
Tero Marttila <terom@fixme.fi>
parents:
64
diff
changeset
|
60 |
if ((err = pt_png_check(path)) < 0) |
1d188aa94aee
pt_png_check, and fclose() pt_image_open_file
Tero Marttila <terom@fixme.fi>
parents:
64
diff
changeset
|
61 |
return err; |
1d188aa94aee
pt_png_check, and fclose() pt_image_open_file
Tero Marttila <terom@fixme.fi>
parents:
64
diff
changeset
|
62 |
|
1d188aa94aee
pt_png_check, and fclose() pt_image_open_file
Tero Marttila <terom@fixme.fi>
parents:
64
diff
changeset
|
63 |
if (err) |
1d188aa94aee
pt_png_check, and fclose() pt_image_open_file
Tero Marttila <terom@fixme.fi>
parents:
64
diff
changeset
|
64 |
// fail, not a PNG |
1d188aa94aee
pt_png_check, and fclose() pt_image_open_file
Tero Marttila <terom@fixme.fi>
parents:
64
diff
changeset
|
65 |
RETURN_ERROR(PT_ERR_IMG_FORMAT); |
0 | 66 |
|
67 |
// alloc |
|
17
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
68 |
if ((err = pt_image_new(&image, ctx, path))) |
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
69 |
return err; |
1
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
70 |
|
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
71 |
// compute cache file path |
17
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
72 |
if ((err = pt_image_cache_path(image, cache_path, sizeof(cache_path)))) |
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
73 |
JUMP_ERROR(err); |
0 | 74 |
|
9 | 75 |
// create the cache object for this image (doesn't yet open it) |
17
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
76 |
if ((err = pt_cache_new(&image->cache, cache_path, cache_mode))) |
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
77 |
JUMP_ERROR(err); |
0 | 78 |
|
79 |
// ok, ready for access |
|
1
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
80 |
*image_ptr = image; |
0 | 81 |
|
82 |
return 0; |
|
83 |
||
84 |
error: |
|
1
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
85 |
pt_image_destroy(image); |
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
86 |
|
17
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
87 |
return err; |
0 | 88 |
} |
1
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
89 |
|
56
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
90 |
int pt_image_open_file (struct pt_image *image, FILE **file_ptr) |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
91 |
{ |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
92 |
FILE *fp; |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
93 |
|
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
94 |
// open |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
95 |
if ((fp = fopen(image->path, "rb")) == NULL) |
69
1d188aa94aee
pt_png_check, and fclose() pt_image_open_file
Tero Marttila <terom@fixme.fi>
parents:
64
diff
changeset
|
96 |
RETURN_ERROR(PT_ERR_IMG_OPEN); |
56
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
97 |
|
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
98 |
// ok |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
99 |
*file_ptr = fp; |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
100 |
|
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
101 |
return 0; |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
102 |
} |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
103 |
|
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
104 |
/** |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
105 |
* Open the PNG image, and write out to the cache |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
106 |
*/ |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
107 |
int pt_image_update (struct pt_image *image, const struct pt_image_params *params) |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
108 |
{ |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
109 |
struct pt_png_img img; |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
110 |
int err = 0; |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
111 |
|
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
112 |
// pre-check enabled |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
113 |
if (!(image->cache->mode & PT_OPEN_UPDATE)) |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
114 |
RETURN_ERROR_ERRNO(PT_ERR_OPEN_MODE, EACCES); |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
115 |
|
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
116 |
// open .png |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
117 |
if ((err = pt_png_open(image, &img))) |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
118 |
return err; |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
119 |
|
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
120 |
// pass to cache object |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
121 |
if ((err = pt_cache_update(image->cache, &img, params))) |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
122 |
JUMP_ERROR(err); |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
123 |
|
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
124 |
error: |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
125 |
// clean up |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
126 |
pt_png_release_read(&img); |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
127 |
|
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
128 |
return err; |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
129 |
} |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
130 |
|
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
131 |
|
7
997906f5fd2d
mmap header, implement pt_image_info (post-update)
Tero Marttila <terom@fixme.fi>
parents:
6
diff
changeset
|
132 |
int pt_image_info (struct pt_image *image, const struct pt_image_info **info_ptr) |
997906f5fd2d
mmap header, implement pt_image_info (post-update)
Tero Marttila <terom@fixme.fi>
parents:
6
diff
changeset
|
133 |
{ |
54
4a25113cb2a4
add some additional pt_image_info fields for stat
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
134 |
struct stat st; |
17
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
135 |
|
56
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
136 |
// update info from cache |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
54
diff
changeset
|
137 |
pt_cache_info(image->cache, &image->info); |
54
4a25113cb2a4
add some additional pt_image_info fields for stat
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
138 |
|
4a25113cb2a4
add some additional pt_image_info fields for stat
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
139 |
// stat our info |
4a25113cb2a4
add some additional pt_image_info fields for stat
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
140 |
if (stat(image->path, &st) < 0) { |
4a25113cb2a4
add some additional pt_image_info fields for stat
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
141 |
// unknown |
4a25113cb2a4
add some additional pt_image_info fields for stat
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
142 |
image->info.image_mtime = 0; |
4a25113cb2a4
add some additional pt_image_info fields for stat
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
143 |
image->info.image_bytes = 0; |
4a25113cb2a4
add some additional pt_image_info fields for stat
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
144 |
|
4a25113cb2a4
add some additional pt_image_info fields for stat
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
145 |
} else { |
4a25113cb2a4
add some additional pt_image_info fields for stat
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
146 |
// store |
4a25113cb2a4
add some additional pt_image_info fields for stat
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
147 |
image->info.image_mtime = st.st_mtime; |
4a25113cb2a4
add some additional pt_image_info fields for stat
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
148 |
image->info.image_bytes = st.st_size; |
4a25113cb2a4
add some additional pt_image_info fields for stat
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
149 |
} |
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
|
150 |
|
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
|
151 |
// return pointer |
7
997906f5fd2d
mmap header, implement pt_image_info (post-update)
Tero Marttila <terom@fixme.fi>
parents:
6
diff
changeset
|
152 |
*info_ptr = &image->info; |
997906f5fd2d
mmap header, implement pt_image_info (post-update)
Tero Marttila <terom@fixme.fi>
parents:
6
diff
changeset
|
153 |
|
997906f5fd2d
mmap header, implement pt_image_info (post-update)
Tero Marttila <terom@fixme.fi>
parents:
6
diff
changeset
|
154 |
return 0; |
997906f5fd2d
mmap header, implement pt_image_info (post-update)
Tero Marttila <terom@fixme.fi>
parents:
6
diff
changeset
|
155 |
} |
997906f5fd2d
mmap header, implement pt_image_info (post-update)
Tero Marttila <terom@fixme.fi>
parents:
6
diff
changeset
|
156 |
|
8 | 157 |
int pt_image_status (struct pt_image *image) |
5
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
158 |
{ |
8 | 159 |
return pt_cache_status(image->cache, image->path); |
5
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
160 |
} |
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
161 |
|
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
162 |
|
25 | 163 |
int pt_image_load (struct pt_image *image) |
164 |
{ |
|
165 |
return pt_cache_open(image->cache); |
|
166 |
} |
|
167 |
||
18 | 168 |
int pt_image_tile_file (struct pt_image *image, const struct pt_tile_info *info, FILE *out) |
9 | 169 |
{ |
18 | 170 |
struct pt_tile tile; |
171 |
int err; |
|
9 | 172 |
|
18 | 173 |
// init |
19
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
174 |
if ((err = pt_tile_init_file(&tile, image->cache, info, out))) |
18 | 175 |
return err; |
176 |
||
177 |
// render |
|
19
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
178 |
if ((err = pt_tile_render(&tile))) |
17
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
179 |
JUMP_ERROR(err); |
9 | 180 |
|
18 | 181 |
// ok |
182 |
return 0; |
|
9 | 183 |
|
184 |
error: |
|
18 | 185 |
pt_tile_abort(&tile); |
186 |
||
187 |
return err; |
|
188 |
} |
|
189 |
||
190 |
int pt_image_tile_mem (struct pt_image *image, const struct pt_tile_info *info, char **buf_ptr, size_t *len_ptr) |
|
191 |
{ |
|
192 |
struct pt_tile tile; |
|
193 |
int err; |
|
194 |
||
195 |
// init |
|
19
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
196 |
if ((err = pt_tile_init_mem(&tile, image->cache, info))) |
18 | 197 |
return err; |
198 |
||
199 |
// render |
|
19
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
200 |
if ((err = pt_tile_render(&tile))) |
18 | 201 |
JUMP_ERROR(err); |
202 |
||
203 |
// ok |
|
204 |
*buf_ptr = tile.out.mem.base; |
|
205 |
*len_ptr = tile.out.mem.len; |
|
206 |
||
207 |
return 0; |
|
208 |
||
209 |
error: |
|
210 |
pt_tile_abort(&tile); |
|
9 | 211 |
|
17
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
212 |
return err; |
9 | 213 |
} |
214 |
||
64 | 215 |
/** |
216 |
* Async work func for pt_image_tile_async |
|
217 |
*/ |
|
19
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
218 |
static void _pt_image_tile_async (void *arg) |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
219 |
{ |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
220 |
struct pt_tile *tile = arg; |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
221 |
int err; |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
222 |
|
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
223 |
// do render op |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
224 |
if ((err = pt_tile_render(tile))) |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
225 |
log_warn_errno("pt_tile_render: %s", pt_strerror(err)); |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
226 |
|
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
227 |
// signal done |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
228 |
if (fclose(tile->out.file)) |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
229 |
log_warn_errno("fclose"); |
22
811c88041c06
cleanup pt_tile in _pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
19
diff
changeset
|
230 |
|
811c88041c06
cleanup pt_tile in _pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
19
diff
changeset
|
231 |
// cleanup |
811c88041c06
cleanup pt_tile in _pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
19
diff
changeset
|
232 |
pt_tile_destroy(tile); |
19
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
233 |
} |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
234 |
|
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
235 |
int pt_image_tile_async (struct pt_image *image, const struct pt_tile_info *info, FILE *out) |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
236 |
{ |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
237 |
struct pt_tile *tile; |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
238 |
int err; |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
239 |
|
64 | 240 |
// need a ctx for this |
241 |
if (!image->ctx) |
|
242 |
return -1; |
|
243 |
||
19
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
244 |
// alloc |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
245 |
if ((err = pt_tile_new(&tile))) |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
246 |
return err; |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
247 |
|
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
248 |
// init |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
249 |
if ((err = pt_tile_init_file(tile, image->cache, info, out))) |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
250 |
JUMP_ERROR(err); |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
251 |
|
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
252 |
// enqueue work |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
253 |
if ((err = pt_ctx_work(image->ctx, _pt_image_tile_async, tile))) |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
254 |
JUMP_ERROR(err); |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
255 |
|
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
256 |
// ok, running |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
257 |
return 0; |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
258 |
|
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
259 |
error: |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
260 |
pt_tile_destroy(tile); |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
261 |
|
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
262 |
return err; |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
263 |
} |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
264 |
|
1
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
265 |
void pt_image_destroy (struct pt_image *image) |
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
266 |
{ |
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
267 |
free(image->path); |
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
268 |
|
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
269 |
if (image->cache) |
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
270 |
pt_cache_destroy(image->cache); |
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
271 |
|
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
272 |
free(image); |
f3cde3db1fef
basic image/cache code compiles
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
273 |
} |
19
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
274 |