author | Tero Marttila <terom@qmsk.net> |
Sat, 04 Oct 2014 03:03:17 +0300 | |
changeset 174 | 58c9e2de0dd4 |
parent 112 | bd964d3551eb |
permissions | -rw-r--r-- |
74 | 1 |
#include "shared/log.h" |
2 |
||
3 |
#include "pngtile.h" |
|
4 |
||
5 |
#include <getopt.h> |
|
96
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
6 |
#include <string.h> |
74 | 7 |
#include <stdio.h> |
98 | 8 |
#include <unistd.h> |
74 | 9 |
#include <stdbool.h> |
10 |
||
101
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
11 |
enum option_names { |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
12 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
13 |
_OPT_LONGONLY = 255, |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
14 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
15 |
OPT_BENCHMARK, |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
16 |
OPT_RANDOMIZE, |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
17 |
}; |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
18 |
|
74 | 19 |
/** |
20 |
* Command-line options |
|
21 |
*/ |
|
22 |
static const struct option options[] = { |
|
23 |
{ "help", false, NULL, 'h' }, |
|
24 |
{ "quiet", false, NULL, 'q' }, |
|
25 |
{ "verbose", false, NULL, 'v' }, |
|
26 |
{ "debug", false, NULL, 'D' }, |
|
27 |
{ "force-update", false, NULL, 'U' }, |
|
28 |
{ "no-update", false, NULL, 'N' }, |
|
29 |
{ "background", true, NULL, 'B' }, |
|
30 |
{ "width", true, NULL, 'W' }, |
|
31 |
{ "height", true, NULL, 'H' }, |
|
32 |
{ "x", true, NULL, 'x' }, |
|
33 |
{ "y", true, NULL, 'y' }, |
|
34 |
{ "zoom", true, NULL, 'z' }, |
|
96
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
35 |
{ "out", true, NULL, 'o' }, |
74 | 36 |
{ "threads", true, NULL, 'j' }, |
101
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
37 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
38 |
// --long-only options |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
39 |
{ "benchmark", true, NULL, OPT_BENCHMARK }, |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
40 |
{ "randomize", false, NULL, OPT_RANDOMIZE }, |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
41 |
{ 0, 0, 0, 0 } |
74 | 42 |
}; |
43 |
||
44 |
/** |
|
45 |
* Print usage/help info on stderr |
|
46 |
*/ |
|
47 |
void help (const char *argv0) |
|
48 |
{ |
|
49 |
fprintf(stderr, "Usage: %s [options] <image> [...]\n", argv0); |
|
50 |
fprintf(stderr, |
|
51 |
"Open each of the given image files, check cache status, optionally update their cache, display image info, and\n" |
|
52 |
"optionally render a tile of each.\n" |
|
53 |
"\n" |
|
101
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
54 |
"\t-h, --help show this help and exit\n" |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
55 |
"\t-q, --quiet supress informational output\n" |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
56 |
"\t-v, --verbose display more informational output\n" |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
57 |
"\t-D, --debug equivalent to -v\n" |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
58 |
"\t-U, --force-update unconditionally update image caches\n" |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
59 |
"\t-N, --no-update do not update the image cache\n" |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
60 |
"\t-B, --background set background pattern for sparse cache file: 0xHH..\n" |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
61 |
"\t-W, --width PX set tile width\n" |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
62 |
"\t-H, --height PX set tile height\n" |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
63 |
"\t-x, --x PX set tile x offset\n" |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
64 |
"\t-y, --y PX set tile y offset\n" |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
65 |
"\t-z, --zoom ZL set zoom factor (<0)\n" |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
66 |
"\t-o, --out FILE set tile output file\n" |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
67 |
"\t-j, --threads N number of threads\n" |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
68 |
"\t--benchmark N do N tile renders\n" |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
69 |
"\t--randomize randomize tile x/y coords\n" |
74 | 70 |
); |
71 |
} |
|
72 |
||
101
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
73 |
unsigned long parse_uint (const char *val, const char *name) |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
74 |
{ |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
75 |
char *endptr; |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
76 |
long int out; |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
77 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
78 |
// decode |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
79 |
out = strtol(val, &endptr, 0); |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
80 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
81 |
// validate |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
82 |
if (*endptr || out < 0) |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
83 |
EXIT_ERROR(EXIT_FAILURE, "Invalid value for %s: %s", name, val); |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
84 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
85 |
// ok |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
86 |
return out; |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
87 |
} |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
88 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
89 |
signed long parse_sint (const char *val, const char *name) |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
90 |
{ |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
91 |
char *endptr; |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
92 |
long int out; |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
93 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
94 |
// decode |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
95 |
out = strtol(val, &endptr, 0); |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
96 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
97 |
// validate |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
98 |
if (*endptr) |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
99 |
EXIT_ERROR(EXIT_FAILURE, "Invalid value for %s: %s", name, val); |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
100 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
101 |
// ok |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
102 |
return out; |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
103 |
} |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
104 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
105 |
long randrange (long start, long end) |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
106 |
{ |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
107 |
return start + (rand() * (end - start) / RAND_MAX); |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
108 |
} |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
109 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
110 |
/** |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
111 |
* Randomize tile x/y with given image info |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
112 |
*/ |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
113 |
void randomize_tile (struct pt_tile_info *ti, const struct pt_image_info *info) |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
114 |
{ |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
115 |
ti->x = randrange(0, info->img_width - ti->width); |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
116 |
ti->y = randrange(0, info->img_height - ti->height); |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
117 |
} |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
118 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
119 |
/** |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
120 |
* Render a tile |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
121 |
*/ |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
122 |
int do_tile (struct pt_ctx *ctx, struct pt_image *image, const struct pt_tile_info *ti, const char *out_path) |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
123 |
{ |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
124 |
FILE *out_file = NULL; |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
125 |
char tmp_name[] = "pt-tile-XXXXXX"; |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
126 |
int err = 0; |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
127 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
128 |
if (!out_path) { |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
129 |
int fd; |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
130 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
131 |
// temporary file for output |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
132 |
if ((fd = mkstemp(tmp_name)) < 0) { |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
133 |
log_errno("mkstemp"); |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
134 |
goto error; |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
135 |
} |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
136 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
137 |
out_path = tmp_name; |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
138 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
139 |
// open out |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
140 |
if ((out_file = fdopen(fd, "wb")) == NULL) { |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
141 |
log_errno("fdopen"); |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
142 |
goto error; |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
143 |
} |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
144 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
145 |
} else if (strcmp(out_path, "-") == 0) { |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
146 |
// use stdout |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
147 |
if ((out_file = fdopen(STDOUT_FILENO, "wb")) == NULL) { |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
148 |
log_errno("fdopen: STDOUT_FILENO"); |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
149 |
goto error; |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
150 |
} |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
151 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
152 |
} else { |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
153 |
// use file |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
154 |
if ((out_file = fopen(out_path, "wb")) == NULL) { |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
155 |
log_errno("fopen: %s", out_path); |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
156 |
goto error; |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
157 |
} |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
158 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
159 |
} |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
160 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
161 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
162 |
if (ctx) { |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
163 |
// render |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
164 |
log_info("\tAsync render tile %zux%zu@(%zu,%zu) -> %s", ti->width, ti->height, ti->x, ti->y, out_path); |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
165 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
166 |
if ((err = pt_image_tile_async(image, ti, out_file))) { |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
167 |
log_errno("pt_image_tile_async: %s", pt_strerror(err)); |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
168 |
goto error; |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
169 |
} |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
170 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
171 |
// will close it itself |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
172 |
out_file = NULL; |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
173 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
174 |
} else { |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
175 |
// render |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
176 |
log_info("\tRender tile %zux%zu@(%zu,%zu) -> %s", ti->width, ti->height, ti->x, ti->y, out_path); |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
177 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
178 |
if ((err = pt_image_tile_file(image, ti, out_file))) { |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
179 |
log_errno("pt_image_tile_file: %s", pt_strerror(err)); |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
180 |
goto error; |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
181 |
} |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
182 |
} |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
183 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
184 |
error: |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
185 |
// cleanup |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
186 |
if (out_file && fclose(out_file)) |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
187 |
log_warn_errno("fclose: out_file"); |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
188 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
189 |
return err; |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
190 |
} |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
191 |
|
74 | 192 |
int main (int argc, char **argv) |
193 |
{ |
|
194 |
int opt; |
|
101
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
195 |
bool force_update = false, no_update = false, randomize = false; |
96
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
196 |
struct pt_tile_info ti = { |
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
197 |
.width = 800, |
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
198 |
.height = 600, |
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
199 |
.x = 0, |
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
200 |
.y = 0, |
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
201 |
.zoom = 0 |
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
202 |
}; |
74 | 203 |
struct pt_image_params update_params = { }; |
96
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
204 |
const char *out_path = NULL; |
101
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
205 |
int threads = 0, benchmark = 0; |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
206 |
int err; |
74 | 207 |
|
208 |
// parse arguments |
|
96
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
209 |
while ((opt = getopt_long(argc, argv, "hqvDUNB:W:H:x:y:z:o:j:", options, NULL)) != -1) { |
74 | 210 |
switch (opt) { |
211 |
case 'h': |
|
212 |
// display help |
|
213 |
help(argv[0]); |
|
214 |
||
215 |
return EXIT_SUCCESS; |
|
216 |
||
217 |
case 'q': |
|
218 |
// supress excess log output |
|
101
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
219 |
set_log_level(LOG_WARN); break; |
74 | 220 |
|
221 |
case 'v': |
|
222 |
case 'D': |
|
223 |
// display additional output |
|
101
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
224 |
set_log_level(LOG_DEBUG); break; |
74 | 225 |
|
226 |
case 'U': |
|
227 |
// force update of image caches |
|
101
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
228 |
force_update = true; break; |
74 | 229 |
|
230 |
case 'N': |
|
231 |
// supress update of image caches |
|
101
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
232 |
no_update = true; break; |
74 | 233 |
|
234 |
case 'B': |
|
235 |
// background pattern |
|
236 |
{ |
|
237 |
unsigned int b1 = 0, b2 = 0, b3 = 0, b4 = 0; |
|
238 |
||
239 |
// parse 0xXXXXXXXX |
|
240 |
if (sscanf(optarg, "0x%02x%02x%02x%02x", &b1, &b2, &b3, &b4) < 1) |
|
241 |
FATAL("Invalid hex value for -B/--background: %s", optarg); |
|
242 |
||
243 |
// store |
|
244 |
update_params.background_color[0] = b1; |
|
245 |
update_params.background_color[1] = b2; |
|
246 |
update_params.background_color[2] = b3; |
|
247 |
update_params.background_color[3] = b4; |
|
248 |
||
249 |
} break; |
|
250 |
||
251 |
case 'W': |
|
101
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
252 |
ti.width = parse_uint(optarg, "--width"); break; |
74 | 253 |
|
254 |
case 'H': |
|
101
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
255 |
ti.height = parse_uint(optarg, "--height"); break; |
74 | 256 |
|
257 |
case 'x': |
|
101
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
258 |
ti.x = parse_uint(optarg, "--x"); break; |
74 | 259 |
|
260 |
case 'y': |
|
101
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
261 |
ti.y = parse_uint(optarg, "--y"); break; |
74 | 262 |
|
263 |
case 'z': |
|
101
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
264 |
ti.zoom = parse_sint(optarg, "--zoom"); break; |
74 | 265 |
|
96
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
266 |
case 'o': |
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
267 |
// output file |
101
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
268 |
out_path = optarg; break; |
96
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
269 |
|
74 | 270 |
case 'j': |
101
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
271 |
threads = parse_uint(optarg, "--threads"); break; |
74 | 272 |
|
101
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
273 |
case OPT_BENCHMARK: |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
274 |
benchmark = parse_uint(optarg, "--benchmark"); break; |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
275 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
276 |
case OPT_RANDOMIZE: |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
277 |
randomize = true; break; |
74 | 278 |
|
279 |
case '?': |
|
280 |
// useage error |
|
281 |
help(argv[0]); |
|
282 |
||
283 |
return EXIT_FAILURE; |
|
284 |
||
285 |
default: |
|
286 |
// getopt??? |
|
287 |
FATAL("getopt_long returned unknown code %d", opt); |
|
288 |
} |
|
289 |
} |
|
290 |
||
291 |
// end-of-arguments? |
|
292 |
if (!argv[optind]) |
|
293 |
EXIT_WARN(EXIT_FAILURE, "No images given"); |
|
294 |
||
295 |
||
296 |
||
297 |
struct pt_ctx *ctx = NULL; |
|
298 |
struct pt_image *image = NULL; |
|
299 |
enum pt_cache_status status; |
|
96
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
300 |
|
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
301 |
if (threads) { |
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
302 |
// build ctx |
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
303 |
log_debug("Construct pt_ctx with %d threads", threads); |
74 | 304 |
|
96
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
305 |
if ((err = pt_ctx_new(&ctx, threads))) |
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
306 |
EXIT_ERROR(EXIT_FAILURE, "pt_ctx_new: threads=%d", threads); |
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
307 |
} |
74 | 308 |
|
309 |
// process each image in turn |
|
310 |
log_debug("Processing %d images...", argc - optind); |
|
311 |
||
312 |
for (int i = optind; i < argc; i++) { |
|
313 |
const char *img_path = argv[i]; |
|
314 |
||
315 |
log_debug("Loading image from: %s...", img_path); |
|
316 |
||
317 |
// open |
|
318 |
if ((err = pt_image_open(&image, ctx, img_path, PT_OPEN_UPDATE))) { |
|
319 |
log_errno("pt_image_open: %s: %s", img_path, pt_strerror(err)); |
|
320 |
continue; |
|
321 |
} |
|
322 |
||
323 |
log_info("Opened image at: %s", img_path); |
|
324 |
||
325 |
// check if stale |
|
326 |
if ((status = pt_image_status(image)) < 0) { |
|
327 |
log_errno("pt_image_status: %s: %s", img_path, pt_strerror(status)); |
|
328 |
goto error; |
|
329 |
} |
|
330 |
||
331 |
// update if stale |
|
332 |
if (status != PT_CACHE_FRESH || force_update) { |
|
333 |
if (status == PT_CACHE_NONE) |
|
112 | 334 |
log_info("\tImage cache is missing"); |
74 | 335 |
|
336 |
else if (status == PT_CACHE_STALE) |
|
112 | 337 |
log_info("\tImage cache is stale"); |
74 | 338 |
|
339 |
else if (status == PT_CACHE_INCOMPAT) |
|
112 | 340 |
log_info("\tImage cache is incompatible"); |
74 | 341 |
|
342 |
else if (status == PT_CACHE_FRESH) |
|
112 | 343 |
log_info("\tImage cache is fresh"); |
77 | 344 |
|
345 |
else |
|
346 |
log_warn("\tImage cache status is unknown"); |
|
74 | 347 |
|
348 |
if (!no_update) { |
|
112 | 349 |
log_info("\tUpdating image cache..."); |
74 | 350 |
|
351 |
if ((err = pt_image_update(image, &update_params))) { |
|
102
a4d1e046ed3e
fail main if an image update fails...
Tero Marttila <terom@fixme.fi>
parents:
101
diff
changeset
|
352 |
log_error("pt_image_update: %s: %s", img_path, pt_strerror(err)); |
a4d1e046ed3e
fail main if an image update fails...
Tero Marttila <terom@fixme.fi>
parents:
101
diff
changeset
|
353 |
goto error; |
74 | 354 |
} |
355 |
||
112 | 356 |
log_debug("\tUpdated image cache"); |
74 | 357 |
|
358 |
} else { |
|
359 |
log_warn("\tSupressing cache update"); |
|
360 |
} |
|
361 |
||
362 |
} else { |
|
363 |
log_debug("\tImage cache is fresh"); |
|
96
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
364 |
|
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
365 |
// ensure it's loaded |
112 | 366 |
log_info("\tLoad image cache..."); |
96
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
367 |
|
102
a4d1e046ed3e
fail main if an image update fails...
Tero Marttila <terom@fixme.fi>
parents:
101
diff
changeset
|
368 |
if ((err = pt_image_load(image))) { |
96
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
369 |
log_errno("pt_image_load: %s", pt_strerror(err)); |
102
a4d1e046ed3e
fail main if an image update fails...
Tero Marttila <terom@fixme.fi>
parents:
101
diff
changeset
|
370 |
goto error; |
a4d1e046ed3e
fail main if an image update fails...
Tero Marttila <terom@fixme.fi>
parents:
101
diff
changeset
|
371 |
} |
74 | 372 |
} |
373 |
||
374 |
// show info |
|
375 |
const struct pt_image_info *info; |
|
376 |
||
377 |
if ((err = pt_image_info(image, &info))) { |
|
378 |
log_warn_errno("pt_image_info: %s: %s", img_path, pt_strerror(err)); |
|
379 |
||
380 |
} else { |
|
77 | 381 |
log_info("\tImage dimensions: %zux%zu (%zu bpp)", info->img_width, info->img_height, info->img_bpp); |
74 | 382 |
log_info("\tImage mtime=%ld, bytes=%zu", (long) info->image_mtime, info->image_bytes); |
77 | 383 |
log_info("\tCache mtime=%ld, bytes=%zu, blocks=%zu (%zu bytes), version=%d", |
384 |
(long) info->cache_mtime, info->cache_bytes, info->cache_blocks, info->cache_blocks * 512, info->cache_version |
|
74 | 385 |
); |
386 |
} |
|
387 |
||
388 |
// render tile? |
|
101
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
389 |
if (benchmark) { |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
390 |
log_info("\tRunning %d %stile renders...", benchmark, randomize ? "randomized " : ""); |
96
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
391 |
|
101
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
392 |
// n times |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
393 |
for (int i = 0; i < benchmark; i++) { |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
394 |
// randomize x, y |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
395 |
if (randomize) |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
396 |
randomize_tile(&ti, info); |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
397 |
|
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
398 |
if (do_tile(ctx, image, &ti, out_path)) |
98 | 399 |
goto error; |
74 | 400 |
} |
401 |
||
101
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
402 |
} else if (out_path) { |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
403 |
// randomize x, y |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
404 |
if (randomize) |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
405 |
randomize_tile(&ti, info); |
74 | 406 |
|
101
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
407 |
// just once |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
408 |
if (do_tile(ctx, image, &ti, out_path)) |
578d90d0cf92
refactor main.c into do_tile, add --benchmark, --randomize
Tero Marttila <terom@fixme.fi>
parents:
98
diff
changeset
|
409 |
goto error; |
74 | 410 |
|
411 |
} |
|
412 |
// cleanup |
|
96
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
413 |
// XXX: leak because of async |
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
414 |
if (!ctx) |
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
415 |
pt_image_destroy(image); |
102
a4d1e046ed3e
fail main if an image update fails...
Tero Marttila <terom@fixme.fi>
parents:
101
diff
changeset
|
416 |
|
a4d1e046ed3e
fail main if an image update fails...
Tero Marttila <terom@fixme.fi>
parents:
101
diff
changeset
|
417 |
continue; |
a4d1e046ed3e
fail main if an image update fails...
Tero Marttila <terom@fixme.fi>
parents:
101
diff
changeset
|
418 |
|
a4d1e046ed3e
fail main if an image update fails...
Tero Marttila <terom@fixme.fi>
parents:
101
diff
changeset
|
419 |
error: |
a4d1e046ed3e
fail main if an image update fails...
Tero Marttila <terom@fixme.fi>
parents:
101
diff
changeset
|
420 |
// quit |
a4d1e046ed3e
fail main if an image update fails...
Tero Marttila <terom@fixme.fi>
parents:
101
diff
changeset
|
421 |
EXIT_ERROR(EXIT_FAILURE, "Processing image failed: %s", img_path); |
74 | 422 |
} |
96
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
423 |
|
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
424 |
if (ctx) { |
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
425 |
log_info("Waiting for images to finish..."); |
74 | 426 |
|
96
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
427 |
// wait for tile operations to finish... |
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
428 |
pt_ctx_shutdown(ctx); |
b7f6473c4adf
change pngtile to accept --out
Tero Marttila <terom@fixme.fi>
parents:
85
diff
changeset
|
429 |
} |
74 | 430 |
|
431 |
log_info("Done"); |
|
432 |
||
433 |
return 0; |
|
434 |
} |
|
435 |