author | Tero Marttila <terom@fixme.fi> |
Mon, 25 Jan 2010 02:58:00 +0200 | |
changeset 73 | 5dfb245b814d |
parent 68 | 70737d141172 |
permissions | -rw-r--r-- |
2 | 1 |
#include "shared/log.h" |
2 |
||
17
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
3 |
#include "pngtile.h" |
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
4 |
|
2 | 5 |
#include <getopt.h> |
6 |
#include <stdio.h> |
|
7 |
#include <stdbool.h> |
|
8 |
||
9 |
/** |
|
10 |
* Command-line options |
|
11 |
*/ |
|
12 |
static const struct option options[] = { |
|
6
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
13 |
{ "help", false, NULL, 'h' }, |
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
14 |
{ "quiet", false, NULL, 'q' }, |
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
15 |
{ "verbose", false, NULL, 'v' }, |
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
16 |
{ "debug", false, NULL, 'D' }, |
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
17 |
{ "force-update", false, NULL, 'U' }, |
56
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
18 |
{ "no-update", false, NULL, 'N' }, |
52
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
19 |
{ "background", true, NULL, 'B' }, |
9 | 20 |
{ "width", true, NULL, 'W' }, |
21 |
{ "height", true, NULL, 'H' }, |
|
22 |
{ "x", true, NULL, 'x' }, |
|
23 |
{ "y", true, NULL, 'y' }, |
|
34 | 24 |
{ "zoom", true, NULL, 'z' }, |
19
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
25 |
{ "threads", true, NULL, 'j' }, |
6
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
26 |
{ 0, 0, 0, 0 } |
2 | 27 |
}; |
28 |
||
29 |
/** |
|
30 |
* Print usage/help info on stderr |
|
31 |
*/ |
|
32 |
void help (const char *argv0) |
|
33 |
{ |
|
34 |
fprintf(stderr, "Usage: %s [options] <image> [...]\n", argv0); |
|
35 |
fprintf(stderr, |
|
68 | 36 |
"Open each of the given image files, check cache status, optionally update their cache, display image info, and\n" |
37 |
"optionally render a tile of each.\n" |
|
2 | 38 |
"\n" |
39 |
"\t-h, --help show this help and exit\n" |
|
40 |
"\t-q, --quiet supress informational output\n" |
|
41 |
"\t-v, --verbose display more informational output\n" |
|
42 |
"\t-D, --debug equivalent to -v\n" |
|
6
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
43 |
"\t-U, --force-update unconditionally update image caches\n" |
56
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
44 |
"\t-N, --no-update do not update the image cache\n" |
73
5dfb245b814d
docfix: README and --background
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
45 |
"\t-B, --background set background pattern for sparse cache file: 0xHH..\n" |
9 | 46 |
"\t-W, --width set tile width\n" |
47 |
"\t-H, --height set tile height\n" |
|
48 |
"\t-x, --x set tile x offset\n" |
|
49 |
"\t-y, --y set tile z offset\n" |
|
34 | 50 |
"\t-z, --zoom set zoom factor (<0)\n" |
19
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
51 |
"\t-j, --threads number of threads\n" |
2 | 52 |
); |
53 |
} |
|
54 |
||
55 |
int main (int argc, char **argv) |
|
56 |
{ |
|
57 |
int opt; |
|
56
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
58 |
bool force_update = false, no_update = false; |
34 | 59 |
struct pt_tile_info ti = {0, 0, 0, 0, 0}; |
52
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
60 |
struct pt_image_params update_params = { }; |
19
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
61 |
int threads = 2; |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
62 |
int tmp, err; |
2 | 63 |
|
64 |
// parse arguments |
|
56
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
65 |
while ((opt = getopt_long(argc, argv, "hqvDUNB:W:H:x:y:z:j:", options, NULL)) != -1) { |
2 | 66 |
switch (opt) { |
67 |
case 'h': |
|
68 |
// display help |
|
69 |
help(argv[0]); |
|
70 |
||
71 |
return EXIT_SUCCESS; |
|
72 |
||
73 |
case 'q': |
|
74 |
// supress excess log output |
|
75 |
set_log_level(LOG_WARN); |
|
76 |
||
77 |
break; |
|
78 |
||
79 |
case 'v': |
|
80 |
case 'D': |
|
81 |
// display additional output |
|
82 |
set_log_level(LOG_DEBUG); |
|
83 |
||
84 |
break; |
|
6
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
85 |
|
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
86 |
case 'U': |
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
87 |
// force update of image caches |
766df7c9b90d
--force-update and store palette
Tero Marttila <terom@fixme.fi>
parents:
5
diff
changeset
|
88 |
force_update = true; |
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 |
break; |
56
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
91 |
|
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
92 |
case 'N': |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
93 |
// supress update of image caches |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
94 |
no_update = true; |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
95 |
|
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
96 |
break; |
2 | 97 |
|
52
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
98 |
case 'B': |
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
99 |
// background pattern |
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
100 |
{ |
56
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
101 |
unsigned int b1 = 0, b2 = 0, b3 = 0, b4 = 0; |
52
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
102 |
|
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
103 |
// parse 0xXXXXXXXX |
56
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
104 |
if (sscanf(optarg, "0x%02x%02x%02x%02x", &b1, &b2, &b3, &b4) < 1) |
52
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
105 |
FATAL("Invalid hex value for -B/--background: %s", optarg); |
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
106 |
|
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
107 |
// store |
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
108 |
update_params.background_color[0] = b1; |
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
109 |
update_params.background_color[1] = b2; |
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
110 |
update_params.background_color[2] = b3; |
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
111 |
update_params.background_color[3] = b4; |
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
112 |
|
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
113 |
} break; |
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
114 |
|
9 | 115 |
case 'W': |
116 |
ti.width = strtol(optarg, NULL, 0); break; |
|
117 |
||
118 |
case 'H': |
|
119 |
ti.height = strtol(optarg, NULL, 0); break; |
|
120 |
||
121 |
case 'x': |
|
122 |
ti.x = strtol(optarg, NULL, 0); break; |
|
123 |
||
124 |
case 'y': |
|
125 |
ti.y = strtol(optarg, NULL, 0); break; |
|
126 |
||
34 | 127 |
case 'z': |
128 |
ti.zoom = strtol(optarg, NULL, 0); break; |
|
129 |
||
19
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
130 |
case 'j': |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
131 |
if ((tmp = strtol(optarg, NULL, 0)) < 1) |
52
148a120ea7d5
skip contiguous regions of some background color
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
132 |
FATAL("Invalid value for -j/--threads: %s", optarg); |
19
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
133 |
|
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
134 |
threads = tmp; break; |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
135 |
|
2 | 136 |
case '?': |
137 |
// useage error |
|
138 |
help(argv[0]); |
|
139 |
||
140 |
return EXIT_FAILURE; |
|
141 |
||
142 |
default: |
|
143 |
// getopt??? |
|
144 |
FATAL("getopt_long returned unknown code %d", opt); |
|
145 |
} |
|
146 |
} |
|
147 |
||
148 |
// end-of-arguments? |
|
149 |
if (!argv[optind]) |
|
150 |
EXIT_WARN(EXIT_FAILURE, "No images given"); |
|
151 |
||
152 |
||
153 |
||
154 |
struct pt_ctx *ctx = NULL; |
|
5
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
2
diff
changeset
|
155 |
struct pt_image *image = NULL; |
8 | 156 |
enum pt_cache_status status; |
2 | 157 |
|
19
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
158 |
// build ctx |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
159 |
log_debug("Construct pt_ctx with %d threads", threads); |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
160 |
|
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
161 |
if ((err = pt_ctx_new(&ctx, threads))) |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
162 |
EXIT_ERROR(EXIT_FAILURE, "pt_ctx_new: threads=%d", threads); |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
163 |
|
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
164 |
|
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
165 |
// process each image in turn |
2 | 166 |
log_debug("Processing %d images...", argc - optind); |
167 |
||
168 |
for (int i = optind; i < argc; i++) { |
|
169 |
const char *img_path = argv[i]; |
|
170 |
||
5
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
2
diff
changeset
|
171 |
log_debug("Loading image from: %s...", img_path); |
2 | 172 |
|
173 |
// open |
|
17
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
174 |
if ((err = pt_image_open(&image, ctx, img_path, PT_OPEN_UPDATE))) { |
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
175 |
log_errno("pt_image_open: %s: %s", img_path, pt_strerror(err)); |
2 | 176 |
continue; |
5
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
2
diff
changeset
|
177 |
} |
2 | 178 |
|
5
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
2
diff
changeset
|
179 |
log_info("Opened image at: %s", img_path); |
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
2
diff
changeset
|
180 |
|
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
2
diff
changeset
|
181 |
// check if stale |
8 | 182 |
if ((status = pt_image_status(image)) < 0) { |
17
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
183 |
log_errno("pt_image_status: %s: %s", img_path, pt_strerror(status)); |
5
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
2
diff
changeset
|
184 |
goto error; |
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
2
diff
changeset
|
185 |
} |
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
2
diff
changeset
|
186 |
|
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
2
diff
changeset
|
187 |
// update if stale |
8 | 188 |
if (status != PT_CACHE_FRESH || force_update) { |
189 |
if (status == PT_CACHE_NONE) |
|
26
72fd5ba8d8c1
use pt_image_load and fix output indent
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
190 |
log_debug("\tImage cache is missing"); |
8 | 191 |
|
192 |
else if (status == PT_CACHE_STALE) |
|
26
72fd5ba8d8c1
use pt_image_load and fix output indent
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
193 |
log_debug("\tImage cache is stale"); |
56
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
194 |
|
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
195 |
else if (status == PT_CACHE_INCOMPAT) |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
196 |
log_debug("\tImage cache is incompatible"); |
8 | 197 |
|
198 |
else if (status == PT_CACHE_FRESH) |
|
26
72fd5ba8d8c1
use pt_image_load and fix output indent
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
199 |
log_debug("\tImage cache is fresh"); |
56
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
200 |
|
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
201 |
if (!no_update) { |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
202 |
log_debug("\tUpdating image cache..."); |
8 | 203 |
|
56
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
204 |
if ((err = pt_image_update(image, &update_params))) { |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
205 |
log_warn_errno("pt_image_update: %s: %s", img_path, pt_strerror(err)); |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
206 |
} |
2 | 207 |
|
56
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
208 |
log_info("\tUpdated image cache"); |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
209 |
|
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
210 |
} else { |
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
211 |
log_warn("\tSupressing cache update"); |
5
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
2
diff
changeset
|
212 |
} |
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
2
diff
changeset
|
213 |
|
56
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
214 |
} else { |
26
72fd5ba8d8c1
use pt_image_load and fix output indent
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
215 |
log_debug("\tImage cache is fresh"); |
2 | 216 |
} |
5
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
2
diff
changeset
|
217 |
|
7
997906f5fd2d
mmap header, implement pt_image_info (post-update)
Tero Marttila <terom@fixme.fi>
parents:
6
diff
changeset
|
218 |
// show info |
56
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
219 |
const struct pt_image_info *info; |
7
997906f5fd2d
mmap header, implement pt_image_info (post-update)
Tero Marttila <terom@fixme.fi>
parents:
6
diff
changeset
|
220 |
|
56
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
221 |
if ((err = pt_image_info(image, &info))) { |
17
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
222 |
log_warn_errno("pt_image_info: %s: %s", img_path, pt_strerror(err)); |
7
997906f5fd2d
mmap header, implement pt_image_info (post-update)
Tero Marttila <terom@fixme.fi>
parents:
6
diff
changeset
|
223 |
|
54
4a25113cb2a4
add some additional pt_image_info fields for stat
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
224 |
} else { |
56
d5e3089906da
major refactoring of pt_cache, split off all PNG processing into pt_png
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
225 |
log_info("\tImage dimensions: %zux%zu", info->img_width, info->img_height); |
63 | 226 |
log_info("\tImage mtime=%ld, bytes=%zu", (long) info->image_mtime, info->image_bytes); |
227 |
log_info("\tCache mtime=%ld, bytes=%zu, blocks=%zu (%zu bytes)", |
|
228 |
(long) info->cache_mtime, info->cache_bytes, info->cache_blocks, info->cache_blocks * 512 |
|
54
4a25113cb2a4
add some additional pt_image_info fields for stat
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
229 |
); |
4a25113cb2a4
add some additional pt_image_info fields for stat
Tero Marttila <terom@fixme.fi>
parents:
52
diff
changeset
|
230 |
} |
7
997906f5fd2d
mmap header, implement pt_image_info (post-update)
Tero Marttila <terom@fixme.fi>
parents:
6
diff
changeset
|
231 |
|
9 | 232 |
// render tile? |
233 |
if (ti.width && ti.height) { |
|
23
9fd50fc1d223
render async tile to separate tempfile
Tero Marttila <terom@fixme.fi>
parents:
19
diff
changeset
|
234 |
char tmp_name[] = "pt-tile-XXXXXX"; |
9fd50fc1d223
render async tile to separate tempfile
Tero Marttila <terom@fixme.fi>
parents:
19
diff
changeset
|
235 |
int fd; |
9fd50fc1d223
render async tile to separate tempfile
Tero Marttila <terom@fixme.fi>
parents:
19
diff
changeset
|
236 |
FILE *out; |
9fd50fc1d223
render async tile to separate tempfile
Tero Marttila <terom@fixme.fi>
parents:
19
diff
changeset
|
237 |
|
9fd50fc1d223
render async tile to separate tempfile
Tero Marttila <terom@fixme.fi>
parents:
19
diff
changeset
|
238 |
// temporary file for output |
9fd50fc1d223
render async tile to separate tempfile
Tero Marttila <terom@fixme.fi>
parents:
19
diff
changeset
|
239 |
if ((fd = mkstemp(tmp_name)) < 0) { |
9fd50fc1d223
render async tile to separate tempfile
Tero Marttila <terom@fixme.fi>
parents:
19
diff
changeset
|
240 |
log_errno("mkstemp"); |
9fd50fc1d223
render async tile to separate tempfile
Tero Marttila <terom@fixme.fi>
parents:
19
diff
changeset
|
241 |
|
9fd50fc1d223
render async tile to separate tempfile
Tero Marttila <terom@fixme.fi>
parents:
19
diff
changeset
|
242 |
continue; |
9fd50fc1d223
render async tile to separate tempfile
Tero Marttila <terom@fixme.fi>
parents:
19
diff
changeset
|
243 |
} |
9 | 244 |
|
23
9fd50fc1d223
render async tile to separate tempfile
Tero Marttila <terom@fixme.fi>
parents:
19
diff
changeset
|
245 |
// open out |
9fd50fc1d223
render async tile to separate tempfile
Tero Marttila <terom@fixme.fi>
parents:
19
diff
changeset
|
246 |
if ((out = fdopen(fd, "w")) == NULL) { |
9fd50fc1d223
render async tile to separate tempfile
Tero Marttila <terom@fixme.fi>
parents:
19
diff
changeset
|
247 |
log_errno("fdopen"); |
9fd50fc1d223
render async tile to separate tempfile
Tero Marttila <terom@fixme.fi>
parents:
19
diff
changeset
|
248 |
|
9fd50fc1d223
render async tile to separate tempfile
Tero Marttila <terom@fixme.fi>
parents:
19
diff
changeset
|
249 |
continue; |
9fd50fc1d223
render async tile to separate tempfile
Tero Marttila <terom@fixme.fi>
parents:
19
diff
changeset
|
250 |
} |
26
72fd5ba8d8c1
use pt_image_load and fix output indent
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
251 |
|
72fd5ba8d8c1
use pt_image_load and fix output indent
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
252 |
// ensure it's loaded |
72fd5ba8d8c1
use pt_image_load and fix output indent
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
253 |
log_debug("\tLoad image cache..."); |
72fd5ba8d8c1
use pt_image_load and fix output indent
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
254 |
|
72fd5ba8d8c1
use pt_image_load and fix output indent
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
255 |
if ((err = pt_image_load(image))) |
72fd5ba8d8c1
use pt_image_load and fix output indent
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
256 |
log_errno("pt_image_load: %s", pt_strerror(err)); |
23
9fd50fc1d223
render async tile to separate tempfile
Tero Marttila <terom@fixme.fi>
parents:
19
diff
changeset
|
257 |
|
9fd50fc1d223
render async tile to separate tempfile
Tero Marttila <terom@fixme.fi>
parents:
19
diff
changeset
|
258 |
// render |
26
72fd5ba8d8c1
use pt_image_load and fix output indent
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
259 |
log_info("\tAsync render tile %zux%zu@(%zu,%zu) -> %s", ti.width, ti.height, ti.x, ti.y, tmp_name); |
72fd5ba8d8c1
use pt_image_load and fix output indent
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
260 |
|
23
9fd50fc1d223
render async tile to separate tempfile
Tero Marttila <terom@fixme.fi>
parents:
19
diff
changeset
|
261 |
|
9fd50fc1d223
render async tile to separate tempfile
Tero Marttila <terom@fixme.fi>
parents:
19
diff
changeset
|
262 |
if ((err = pt_image_tile_async(image, &ti, out))) |
17
baf3fe7c6354
add library error codes, and fix image fopen error handling
Tero Marttila <terom@fixme.fi>
parents:
11
diff
changeset
|
263 |
log_errno("pt_image_tile: %s: %s", img_path, pt_strerror(err)); |
9 | 264 |
} |
5
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
2
diff
changeset
|
265 |
|
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
2
diff
changeset
|
266 |
error: |
4b440fa03183
move stale-update logic to main
Tero Marttila <terom@fixme.fi>
parents:
2
diff
changeset
|
267 |
// cleanup |
19
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
268 |
// XXX: leak because of async: pt_image_destroy(image); |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
269 |
; |
2 | 270 |
} |
271 |
||
19
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
272 |
log_info("Waiting for images to finish..."); |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
273 |
|
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
274 |
// wait for tile operations to finish... |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
275 |
pt_ctx_shutdown(ctx); |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
276 |
|
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
277 |
log_info("Done"); |
ebcc49de97d0
implement pt_ctx threadpool and pt_image_tile_async
Tero Marttila <terom@fixme.fi>
parents:
18
diff
changeset
|
278 |
|
2 | 279 |
return 0; |
280 |
} |
|
281 |