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