diff options
Diffstat (limited to 'utils/wpseditor/screenshot')
-rw-r--r-- | utils/wpseditor/screenshot/main.c | 68 |
1 files changed, 42 insertions, 26 deletions
diff --git a/utils/wpseditor/screenshot/main.c b/utils/wpseditor/screenshot/main.c index fb81e069b0..72d75ab54d 100644 --- a/utils/wpseditor/screenshot/main.c +++ b/utils/wpseditor/screenshot/main.c | |||
@@ -70,23 +70,27 @@ static gdImagePtr backdrop; | |||
70 | extern gdImagePtr gdImageCreateFromBmp(FILE * inFile); | 70 | extern gdImagePtr gdImageCreateFromBmp(FILE * inFile); |
71 | extern char *get_current_dir_name (void) __THROW; | 71 | extern char *get_current_dir_name (void) __THROW; |
72 | 72 | ||
73 | static bool next_nl = false; | ||
74 | |||
73 | int _debug(const char* fmt,...) | 75 | int _debug(const char* fmt,...) |
74 | { | 76 | { |
75 | #if 0 /* Doesn't want to compile ?? */ | 77 | va_list ap; |
76 | struct va_list ap; | ||
77 | 78 | ||
78 | va_start(ap, fmt); | 79 | va_start(ap, fmt); |
79 | 80 | ||
80 | fprintf(stdout, "[DBG] "); | 81 | if(!next_nl) |
82 | fprintf(stdout, "[DBG] "); | ||
83 | |||
81 | vfprintf(stdout, fmt, ap); | 84 | vfprintf(stdout, fmt, ap); |
82 | fprintf(stdout, "\n"); | 85 | |
86 | if(fmt[strlen(fmt)-1] != 0xa) | ||
87 | next_nl = true; | ||
88 | else | ||
89 | next_nl = false; | ||
83 | 90 | ||
84 | va_end(ap); | 91 | va_end(ap); |
85 | 92 | ||
86 | return 0; | 93 | return 0; |
87 | #else | ||
88 | return -1; | ||
89 | #endif | ||
90 | } | 94 | } |
91 | 95 | ||
92 | void _putsxy(int x, int y, const unsigned char *str) | 96 | void _putsxy(int x, int y, const unsigned char *str) |
@@ -106,7 +110,7 @@ void _transparent_bitmap_part(const void *src, int src_x, int src_y, | |||
106 | gdImagePtr image; | 110 | gdImagePtr image; |
107 | int pink; | 111 | int pink; |
108 | 112 | ||
109 | DEBUGF2("transparent_bitmap_part(const void *src=%s, int src_x=%d, int src_y=%d, int stride=%d, int x=%d, int y=%d, int width=%d, int height=%d", (char*)src, src_x, src_y, stride, x, y, width, height); | 113 | DEBUGF2("transparent_bitmap_part(const void *src=%s, int src_x=%d, int src_y=%d, int stride=%d, int x=%d, int y=%d, int width=%d, int height=%d\n", (char*)src, src_x, src_y, stride, x, y, width, height); |
110 | 114 | ||
111 | _image = fopen(src, "rb"); | 115 | _image = fopen(src, "rb"); |
112 | if(_image == NULL) | 116 | if(_image == NULL) |
@@ -129,7 +133,7 @@ void _bitmap_part(const void *src, int src_x, int src_y, | |||
129 | FILE *_image; | 133 | FILE *_image; |
130 | gdImagePtr image; | 134 | gdImagePtr image; |
131 | 135 | ||
132 | DEBUGF2("bitmap_part(const void *src=%s, int src_x=%d, int src_y=%d, int stride=%d, int x=%d, int y=%d, int width=%d, int height=%d", (char*)src, src_x, src_y, stride, x, y, width, height); | 136 | DEBUGF2("bitmap_part(const void *src=%s, int src_x=%d, int src_y=%d, int stride=%d, int x=%d, int y=%d, int width=%d, int height=%d\n", (char*)src, src_x, src_y, stride, x, y, width, height); |
133 | 137 | ||
134 | _image = fopen(src, "rb"); | 138 | _image = fopen(src, "rb"); |
135 | if(_image == NULL) | 139 | if(_image == NULL) |
@@ -231,6 +235,7 @@ static int screenshot(char *model, char *wps, char *png) | |||
231 | char lib[255]; | 235 | char lib[255]; |
232 | void *handle; | 236 | void *handle; |
233 | FILE *out, *in; | 237 | FILE *out, *in; |
238 | int res; | ||
234 | 239 | ||
235 | in = fopen(wps, "rb"); | 240 | in = fopen(wps, "rb"); |
236 | if(in == NULL) | 241 | if(in == NULL) |
@@ -287,25 +292,19 @@ static int screenshot(char *model, char *wps, char *png) | |||
287 | api.read_bmp_file = &_read_bmp_file; | 292 | api.read_bmp_file = &_read_bmp_file; |
288 | api.debugf = &_debug; | 293 | api.debugf = &_debug; |
289 | 294 | ||
290 | wps_init(wps, &api, true); | 295 | res = wps_init(wps, &api, true); |
291 | 296 | if(res != 1) | |
292 | framebuffer = gdImageCreateTrueColor(api.getwidth(), api.getheight()); | ||
293 | |||
294 | _drawBackdrop(); | ||
295 | |||
296 | if(strcmp(api.get_model_name(), model) != 0) | ||
297 | { | 297 | { |
298 | fprintf(stderr, "[ERR] Model name doesn't match the one supplied by the library\n"); | 298 | fprintf(stderr, "[ERR] WPS wasn't correctly inited\n"); |
299 | fprintf(stderr, " %s <-> %s\n", model, api.get_model_name()); | ||
300 | dlclose(handle); | 299 | dlclose(handle); |
301 | fclose(out); | 300 | fclose(out); |
302 | gdImageDestroy(framebuffer); | ||
303 | gdImageDestroy(backdrop); | ||
304 | wps_init = NULL; | ||
305 | wps_display = NULL; | ||
306 | wps_refresh = NULL; | ||
307 | return -5; | 301 | return -5; |
308 | } | 302 | } |
303 | |||
304 | framebuffer = gdImageCreateTrueColor(api.getwidth(), api.getheight()); | ||
305 | |||
306 | _drawBackdrop(); | ||
307 | |||
309 | fprintf(stdout, "[INFO] Model: %s\n", api.get_model_name()); | 308 | fprintf(stdout, "[INFO] Model: %s\n", api.get_model_name()); |
310 | 309 | ||
311 | wpsdata.fontheight = getFont()->h; | 310 | wpsdata.fontheight = getFont()->h; |
@@ -323,7 +322,8 @@ static int screenshot(char *model, char *wps, char *png) | |||
323 | dlclose(handle); | 322 | dlclose(handle); |
324 | fclose(out); | 323 | fclose(out); |
325 | gdImageDestroy(framebuffer); | 324 | gdImageDestroy(framebuffer); |
326 | gdImageDestroy(backdrop); | 325 | if(backdrop != NULL) |
326 | gdImageDestroy(backdrop); | ||
327 | 327 | ||
328 | wps_init = NULL; | 328 | wps_init = NULL; |
329 | wps_display = NULL; | 329 | wps_display = NULL; |
@@ -334,8 +334,15 @@ static int screenshot(char *model, char *wps, char *png) | |||
334 | 334 | ||
335 | static void usage(void) | 335 | static void usage(void) |
336 | { | 336 | { |
337 | fprintf(stderr, "Usage: screenshot [-V] <MODEL> <WPS_FILE> <OUT_PNG>\n"); | 337 | fprintf(stderr, "Rockbox WPS screenshot utility\n"); |
338 | fprintf(stderr, "Example: screenshot h10_5gb iCatcher.wps out.png\n"); | 338 | fprintf(stderr, "Made by Maurus Cuelenaere\n"); |
339 | fprintf(stderr, "\n"); | ||
340 | fprintf(stderr, "Usage: screenshot [-V] <MODEL> <WPS> <OUT>.png\n"); | ||
341 | fprintf(stderr, " -> creates a PNG screenshot of the WPS for the specific MODEL\n"); | ||
342 | fprintf(stderr, " -> libwps_<MODEL>.so must be present in the same directory\n"); | ||
343 | fprintf(stderr, " -> -V sets verbose mode ON\n"); | ||
344 | fprintf(stderr, "\n"); | ||
345 | fprintf(stderr, "Example: screenshot IRIVER_H10_5GB iCatcher.wps out.png\n"); | ||
339 | } | 346 | } |
340 | 347 | ||
341 | int main(int argc, char ** argv) | 348 | int main(int argc, char ** argv) |
@@ -346,6 +353,15 @@ int main(int argc, char ** argv) | |||
346 | return -1; | 353 | return -1; |
347 | } | 354 | } |
348 | 355 | ||
356 | if(argv[1] == NULL || argv[2] == NULL || | ||
357 | argv[3] == NULL || | ||
358 | (strcmp(argv[1], "-V") == 0 && argv[4] == NULL) | ||
359 | ) | ||
360 | { | ||
361 | usage(); | ||
362 | return -1; | ||
363 | } | ||
364 | |||
349 | if(strcmp(argv[1], "-V") == 0) | 365 | if(strcmp(argv[1], "-V") == 0) |
350 | { | 366 | { |
351 | verbose = true; | 367 | verbose = true; |