diff options
author | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2011-03-05 21:12:31 +0000 |
---|---|---|
committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2011-03-05 21:12:31 +0000 |
commit | e1244a0dff7815ad325ae433bc890275916b4fe8 (patch) | |
tree | 9c69167fa5877951028b6addecccc20dc13ae0b5 /utils/wpseditor/screenshot/main.c | |
parent | 6538326ef2a46c11fa87e50cb7906e21cb6c42a4 (diff) | |
download | rockbox-e1244a0dff7815ad325ae433bc890275916b4fe8.tar.gz rockbox-e1244a0dff7815ad325ae433bc890275916b4fe8.zip |
Remove outdated and unmaintained wpseditor.
The wpseditor is superseded by the Theme Editor these days.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29528 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/wpseditor/screenshot/main.c')
-rw-r--r-- | utils/wpseditor/screenshot/main.c | 377 |
1 files changed, 0 insertions, 377 deletions
diff --git a/utils/wpseditor/screenshot/main.c b/utils/wpseditor/screenshot/main.c deleted file mode 100644 index 72d75ab54d..0000000000 --- a/utils/wpseditor/screenshot/main.c +++ /dev/null | |||
@@ -1,377 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2008 by Maurus Cuelenaere | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include <stdio.h> | ||
23 | #include <stdarg.h> | ||
24 | #include <string.h> | ||
25 | #include <dlfcn.h> | ||
26 | #include <unistd.h> | ||
27 | #include "gd.h" | ||
28 | #include "gdfonts.h" | ||
29 | #include "api.h" | ||
30 | |||
31 | #define DEBUGF1 _debug | ||
32 | #define DEBUGF2 if(verbose) _debug | ||
33 | |||
34 | #define getFont() gdFontGetSmall() | ||
35 | |||
36 | static struct trackstate mp3data = | ||
37 | { | ||
38 | (char*)"Test title", | ||
39 | (char*)"Test artist", | ||
40 | (char*)"Test album", | ||
41 | (char*)"Test genre", | ||
42 | (char*)"Test disc", | ||
43 | (char*)"Test track", | ||
44 | (char*)"Test year", | ||
45 | (char*)"Test composer", | ||
46 | (char*)"Test comment", | ||
47 | (char*)"Test album artist", | ||
48 | (char*)"Test grouping", | ||
49 | 1, /* int discnum */ | ||
50 | 1, /* int tracknum */ | ||
51 | 1, /* int version */ | ||
52 | 1, /* int layer */ | ||
53 | 2008, /* int year */ | ||
54 | |||
55 | 100, /* int length */ | ||
56 | 70 /* int elapsed */ | ||
57 | }; | ||
58 | |||
59 | static struct wpsstate wpsdata = {-20, -1, -1, 70, API_STATUS_FASTFORWARD}; | ||
60 | /* volume, fontheight, fontwidth, battery_level, audio_status */ | ||
61 | |||
62 | static struct proxy_api api; | ||
63 | static bool verbose = false; | ||
64 | static int (*wps_init)(const char* buff, struct proxy_api *api, bool isfile); | ||
65 | static int (*wps_display)(); | ||
66 | static int (*wps_refresh)(); | ||
67 | static gdImagePtr framebuffer; | ||
68 | static gdImagePtr backdrop; | ||
69 | |||
70 | extern gdImagePtr gdImageCreateFromBmp(FILE * inFile); | ||
71 | extern char *get_current_dir_name (void) __THROW; | ||
72 | |||
73 | static bool next_nl = false; | ||
74 | |||
75 | int _debug(const char* fmt,...) | ||
76 | { | ||
77 | va_list ap; | ||
78 | |||
79 | va_start(ap, fmt); | ||
80 | |||
81 | if(!next_nl) | ||
82 | fprintf(stdout, "[DBG] "); | ||
83 | |||
84 | vfprintf(stdout, fmt, ap); | ||
85 | |||
86 | if(fmt[strlen(fmt)-1] != 0xa) | ||
87 | next_nl = true; | ||
88 | else | ||
89 | next_nl = false; | ||
90 | |||
91 | va_end(ap); | ||
92 | |||
93 | return 0; | ||
94 | } | ||
95 | |||
96 | void _putsxy(int x, int y, const unsigned char *str) | ||
97 | { | ||
98 | struct viewport_api avp; | ||
99 | int black = gdImageColorAllocate(framebuffer, 0, 0, 0); | ||
100 | |||
101 | api.get_current_vp(&avp); | ||
102 | |||
103 | gdImageString(framebuffer, getFont(), x + avp.x, y + avp.y - avp.fontheight, (unsigned char*)str, black); | ||
104 | } | ||
105 | |||
106 | void _transparent_bitmap_part(const void *src, int src_x, int src_y, | ||
107 | int stride, int x, int y, int width, int height) | ||
108 | { | ||
109 | FILE *_image; | ||
110 | gdImagePtr image; | ||
111 | int pink; | ||
112 | |||
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); | ||
114 | |||
115 | _image = fopen(src, "rb"); | ||
116 | if(_image == NULL) | ||
117 | return; | ||
118 | |||
119 | image = gdImageCreateFromBmp(_image); | ||
120 | fclose(_image); | ||
121 | |||
122 | pink = gdTrueColor(255, 0, 255); | ||
123 | gdImageColorTransparent(image, pink); | ||
124 | |||
125 | gdImageCopy(framebuffer, image, x, y, src_x, src_y, width, height); | ||
126 | |||
127 | gdImageDestroy(image); | ||
128 | } | ||
129 | |||
130 | void _bitmap_part(const void *src, int src_x, int src_y, | ||
131 | int stride, int x, int y, int width, int height) | ||
132 | { | ||
133 | FILE *_image; | ||
134 | gdImagePtr image; | ||
135 | |||
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); | ||
137 | |||
138 | _image = fopen(src, "rb"); | ||
139 | if(_image == NULL) | ||
140 | return; | ||
141 | |||
142 | image = gdImageCreateFromBmp(_image); | ||
143 | fclose(_image); | ||
144 | |||
145 | gdImageCopy(framebuffer, image, x, y, src_x, src_y, width, height); | ||
146 | |||
147 | gdImageDestroy(image); | ||
148 | } | ||
149 | |||
150 | void _drawpixel(int x, int y) | ||
151 | { | ||
152 | int black = gdImageColorAllocate(framebuffer, 0, 0, 0); | ||
153 | gdImageSetPixel(framebuffer, x, y, black); | ||
154 | } | ||
155 | |||
156 | void _fillrect(int x, int y, int width, int height) | ||
157 | { | ||
158 | /* Don't draw this as backdrop is used */ | ||
159 | #if 0 | ||
160 | int black = gdImageColorAllocate(framebuffer, 0, 0, 0); | ||
161 | gdImageFilledRectangle(framebuffer, x, y, x+width, y+height, black); | ||
162 | #endif | ||
163 | } | ||
164 | |||
165 | void _hline(int x1, int x2, int y) | ||
166 | { | ||
167 | int black = gdImageColorAllocate(framebuffer, 0, 0, 0); | ||
168 | gdImageLine(framebuffer, x1, y, x2, y, black); | ||
169 | } | ||
170 | |||
171 | void _vline(int x, int y1, int y2) | ||
172 | { | ||
173 | int black = gdImageColorAllocate(framebuffer, 0, 0, 0); | ||
174 | gdImageLine(framebuffer, x, y1, x, y2, black); | ||
175 | } | ||
176 | |||
177 | void _clear_viewport(int x, int y, int w, int h, int color) | ||
178 | { | ||
179 | if(backdrop == NULL) | ||
180 | return; | ||
181 | |||
182 | gdImageCopy(framebuffer, backdrop, x, y, x, y, w, h); | ||
183 | } | ||
184 | |||
185 | static bool _load_wps_backdrop(char* filename) | ||
186 | { | ||
187 | FILE *image; | ||
188 | if(backdrop != NULL) | ||
189 | gdImageDestroy(backdrop); | ||
190 | |||
191 | DEBUGF2("load backdrop: %s", filename); | ||
192 | |||
193 | image = fopen(filename, "rb"); | ||
194 | if(image == NULL) | ||
195 | return false; | ||
196 | |||
197 | backdrop = gdImageCreateFromBmp(image); | ||
198 | fclose(image); | ||
199 | |||
200 | return true; | ||
201 | } | ||
202 | |||
203 | int _read_bmp_file(const char* filename, int *width, int *height) | ||
204 | { | ||
205 | FILE *_image; | ||
206 | gdImagePtr image; | ||
207 | |||
208 | DEBUGF2("load backdrop: %s", filename); | ||
209 | |||
210 | _image = fopen(filename, "rb"); | ||
211 | if(_image == NULL) | ||
212 | return 0; | ||
213 | |||
214 | image = gdImageCreateFromBmp(_image); | ||
215 | fclose(_image); | ||
216 | |||
217 | *width = image->sx; | ||
218 | *height = image->sy; | ||
219 | |||
220 | gdImageDestroy(image); | ||
221 | |||
222 | return 1; | ||
223 | } | ||
224 | |||
225 | static void _drawBackdrop() | ||
226 | { | ||
227 | if(backdrop == NULL) | ||
228 | return; | ||
229 | |||
230 | gdImageCopy(framebuffer, backdrop, 0, 0, 0, 0, backdrop->sx, backdrop->sy); | ||
231 | } | ||
232 | |||
233 | static int screenshot(char *model, char *wps, char *png) | ||
234 | { | ||
235 | char lib[255]; | ||
236 | void *handle; | ||
237 | FILE *out, *in; | ||
238 | int res; | ||
239 | |||
240 | in = fopen(wps, "rb"); | ||
241 | if(in == NULL) | ||
242 | { | ||
243 | fprintf(stderr, "[ERR] Cannot open WPS: %s\n", wps); | ||
244 | return -1; | ||
245 | } | ||
246 | fclose(in); | ||
247 | |||
248 | out = fopen(png, "wb"); | ||
249 | if(out == NULL) | ||
250 | { | ||
251 | fprintf(stderr, "[ERR] Cannot open PNG: %s\n", png); | ||
252 | return -2; | ||
253 | } | ||
254 | |||
255 | snprintf(lib, 255, "%s/libwps_%s.so", (char*)get_current_dir_name(), (char*)model); | ||
256 | handle = dlopen(lib, RTLD_LAZY); | ||
257 | if (!handle) | ||
258 | { | ||
259 | fprintf(stderr, "[ERR] Cannot open library: %s\n", dlerror()); | ||
260 | fclose(out); | ||
261 | return -3; | ||
262 | } | ||
263 | |||
264 | wps_init = dlsym(handle, "wps_init"); | ||
265 | wps_display = dlsym(handle, "wps_display"); | ||
266 | wps_refresh = dlsym(handle, "wps_refresh"); | ||
267 | |||
268 | if (!wps_init || !wps_display || !wps_refresh) | ||
269 | { | ||
270 | fprintf(stderr, "[ERR] Failed to resolve funcs!"); | ||
271 | dlclose(handle); | ||
272 | fclose(out); | ||
273 | return -4; | ||
274 | } | ||
275 | |||
276 | memset(&api, 0, sizeof(struct proxy_api)); | ||
277 | |||
278 | if(verbose) | ||
279 | api.verbose = 3; | ||
280 | else | ||
281 | api.verbose = 0; | ||
282 | |||
283 | api.putsxy = &_putsxy; | ||
284 | api.transparent_bitmap_part = &_transparent_bitmap_part; | ||
285 | api.bitmap_part = &_bitmap_part; | ||
286 | api.drawpixel = &_drawpixel; | ||
287 | api.fillrect = &_fillrect; | ||
288 | api.hline = &_hline; | ||
289 | api.vline = &_vline; | ||
290 | api.clear_viewport = &_clear_viewport; | ||
291 | api.load_wps_backdrop = &_load_wps_backdrop; | ||
292 | api.read_bmp_file = &_read_bmp_file; | ||
293 | api.debugf = &_debug; | ||
294 | |||
295 | res = wps_init(wps, &api, true); | ||
296 | if(res != 1) | ||
297 | { | ||
298 | fprintf(stderr, "[ERR] WPS wasn't correctly inited\n"); | ||
299 | dlclose(handle); | ||
300 | fclose(out); | ||
301 | return -5; | ||
302 | } | ||
303 | |||
304 | framebuffer = gdImageCreateTrueColor(api.getwidth(), api.getheight()); | ||
305 | |||
306 | _drawBackdrop(); | ||
307 | |||
308 | fprintf(stdout, "[INFO] Model: %s\n", api.get_model_name()); | ||
309 | |||
310 | wpsdata.fontheight = getFont()->h; | ||
311 | wpsdata.fontwidth = getFont()->w; | ||
312 | api.set_wpsstate(wpsdata); | ||
313 | api.set_trackstate(mp3data); | ||
314 | api.set_next_trackstate(mp3data); | ||
315 | |||
316 | _drawBackdrop(); | ||
317 | wps_refresh(); | ||
318 | gdImagePng(framebuffer, out); | ||
319 | |||
320 | fprintf(stdout, "[INFO] Image written\n"); | ||
321 | |||
322 | dlclose(handle); | ||
323 | fclose(out); | ||
324 | gdImageDestroy(framebuffer); | ||
325 | if(backdrop != NULL) | ||
326 | gdImageDestroy(backdrop); | ||
327 | |||
328 | wps_init = NULL; | ||
329 | wps_display = NULL; | ||
330 | wps_refresh = NULL; | ||
331 | |||
332 | return 0; | ||
333 | } | ||
334 | |||
335 | static void usage(void) | ||
336 | { | ||
337 | fprintf(stderr, "Rockbox WPS screenshot utility\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"); | ||
346 | } | ||
347 | |||
348 | int main(int argc, char ** argv) | ||
349 | { | ||
350 | if(argc < 4) | ||
351 | { | ||
352 | usage(); | ||
353 | return -1; | ||
354 | } | ||
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 | |||
365 | if(strcmp(argv[1], "-V") == 0) | ||
366 | { | ||
367 | verbose = true; | ||
368 | return screenshot(argv[2], argv[3], argv[4]); | ||
369 | } | ||
370 | else | ||
371 | { | ||
372 | verbose = false; | ||
373 | return screenshot(argv[1], argv[2], argv[3]); | ||
374 | } | ||
375 | |||
376 | return 0; | ||
377 | } | ||