1 /*****************************************************************************
2 * This file is part of gfxprim library. *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
19 * Copyright (C) 2009-2014 Cyril Hrubis <metan@ucw.cz> *
21 *****************************************************************************/
28 #include "image_actions.h"
29 #include "spiv_config.h"
32 * These are default config values, you can hardcompile yours here.
34 struct spiv_config config
= {
37 .backend_init
= "X11",
38 .emul_type
= GP_PIXEL_UNKNOWN
,
39 .zoom_strategy
= ZOOM_IMAGE_DOWNSCALE
,
40 .win_strategy
= ZOOM_WIN_FIXED
,
50 static int set_zoom_strategy(struct cfg_opt
*self
, unsigned int lineno
)
54 switch (self
->val
[0]) {
57 config
.win_strategy
= ZOOM_WIN_RESIZABLE
;
61 config
.win_strategy
= ZOOM_WIN_FIXED
;
66 switch (self
->val
[0]) {
69 config
.zoom_strategy
= 0;
73 config
.zoom_strategy
= ZOOM_IMAGE_UPSCALE
;
77 config
.zoom_strategy
= ZOOM_IMAGE_DOWNSCALE
;
81 config
.zoom_strategy
= ZOOM_IMAGE_UPSCALE
|
88 fprintf(stderr
, "ERROR: %u: Invalid zoom strategy '%s'\n",
93 static int set_win_max_size(struct cfg_opt
*self
, unsigned int lineno
)
97 if (sscanf(self
->val
, "%ux%u", &w
, &h
) != 2) {
98 fprintf(stderr
, "ERROR: %u: Invalid max window size '%s'\n",
103 config
.max_win_w
= w
;
104 config
.max_win_h
= h
;
108 static int set_action(struct cfg_opt
*self
, unsigned int lineno
)
111 image_action_set(atoi(self
->key
), self
->val
);
115 static int set_opt(struct cfg_opt
*self
, unsigned int lineno
)
122 config
.floyd_steinberg
= 1;
125 config
.full_screen
= 1;
128 config
.show_info
= 1;
131 config
.show_progress
= 1;
137 config
.exif_autorotate
= 0;
144 static int set_orientation(struct cfg_opt
*self
, unsigned int lineno
)
146 if (!strcmp("0", self
->val
)) {
147 config
.orientation
= ROTATE_0
;
151 if (!strcmp("90", self
->val
)) {
152 config
.orientation
= ROTATE_90
;
156 if (!strcmp("180", self
->val
)) {
157 config
.orientation
= ROTATE_180
;
161 if (!strcmp("270", self
->val
)) {
162 config
.orientation
= ROTATE_270
;
166 fprintf(stderr
, "ERROR: %u: Invalid orientation '%s'\n",
171 static int set_backend_init(struct cfg_opt
*self
, unsigned int lineno
)
173 if (strlen(self
->val
) + 1 >= sizeof(config
.backend_init
)) {
174 fprintf(stderr
, "ERROR: %u: Backend init string too long\n",
179 strcpy(config
.backend_init
, self
->val
);
184 static int set_slideshow(struct cfg_opt
*self
, unsigned int lineno
)
186 config
.slideshow_delay
= atof(self
->val
);
188 if (config
.slideshow_delay
== 0) {
189 fprintf(stderr
, "ERROR: %u: Invalid slideshow delay '%s'\n",
197 static int set_emulation(struct cfg_opt
*self
, unsigned int lineno
)
199 config
.emul_type
= GP_PixelTypeByName(optarg
);
201 if (config
.emul_type
== GP_PIXEL_UNKNOWN
) {
202 fprintf(stderr
, "ERROR: %u: Invalid pixel type '%s'\n",
210 int load_font_face(GP_TextStyle
*style
, const char *path
, unsigned int height
,
214 static GP_FontFace
*old_font
= NULL
;
216 font
= GP_FontFaceLoad(path
, 0, height
);
219 fprintf(stderr
, "ERROR: %u: Failed to load font '%s'\n",
224 GP_FontFaceFree(old_font
);
225 style
->font
= old_font
= font
;
230 static int set_font(struct cfg_opt
*self
, unsigned int lineno
)
232 static GP_TextStyle style
= {NULL
, 0, 0, 1, 1, 0};
234 if (load_font_face(&style
, self
->val
, config
.font_height
, lineno
))
237 free(config
.font_path
);
238 config
.font_path
= strdup(self
->val
);
239 config
.style
= &style
;
244 static int set_font_height(struct cfg_opt
*self
, unsigned int lineno
)
246 int height
= atoi(self
->val
);
249 fprintf(stderr
, "ERROR: %u: Wrong font height '%s'\n",
254 config
.font_height
= height
;
257 return load_font_face(config
.style
, config
.font_path
,
258 config
.font_height
, lineno
);
264 static int help(struct cfg_opt
*self
, unsigned int lineno
)
273 static int man(struct cfg_opt
*self
, unsigned int lineno
)
282 struct cfg_opt spiv_opts
[] = {
289 .help
= "Shows this help",
292 {.name_space
= "Gui",
295 .opt_long
= "show-info",
298 .help
= "Show image info such as filename, size, etc...",
300 {.name_space
= "Gui",
302 .opt_long
= "font-path",
305 .help
= "Path to TTF font to be used in GUI",
307 {.name_space
= "Gui",
309 .opt_long
= "font-height",
311 .set
= set_font_height
,
312 .help
= "TTF font height in pixels",
314 {.name_space
= "Gui",
315 .key
= "ShowProgress",
317 .opt_long
= "show-progress",
319 .help
= "Show progress bar when loading/resampling/... images",
321 {.name_space
= "Gui",
322 .key
= "SlideshowDelay",
324 .opt_long
= "slideshow-delay",
326 .set
= set_slideshow
,
327 .help
= "Delay between images in seconds (float) for slideshow",
329 {.name_space
= "Gui",
332 .opt_long
= "dithering",
335 .help
= "Turn on Floyd-Steinberg dithering",
337 {.name_space
= "Gui",
338 .key
= "Orientation",
340 .opt_long
= "orientation",
342 .set
= set_orientation
,
343 .help
= "Orientation, one of 0, 90, 180, 270",
345 {.name_space
= "Gui",
346 .key
= "DisableExifAutorotate",
348 .opt_long
= "disable_exif_autorotate",
351 .help
= "Disables automatic rotation by EXIF",
353 {.name_space
= "Gui",
356 .opt_long
= "full-screen",
359 .help
= "Start fullscreen.",
361 {.name_space
= "Gui",
362 .key
= "BackendInit",
364 .opt_long
= "backend-init",
366 .set
= set_backend_init
,
367 .help
= "Backend init string, set it to 'help' for more info",
370 {.name_space
= "Zoom",
373 .opt_long
= "window-size",
375 .set
= set_zoom_strategy
,
376 .help
= "Window size, resizeable (-wr) or fixed (-wf)",
378 {.name_space
= "Zoom",
379 .key
= "ZoomStrategy",
381 .opt_long
= "zoom-strategy",
383 .set
= set_zoom_strategy
,
384 .help
= "Zoom strategy, none (-zn), upscale (-zu), "
385 "downscale (-zd) or both (-zb)",
387 {.name_space
= "Zoom",
390 .opt_long
= "max-win-size",
392 .set
= set_win_max_size
,
393 .help
= "Window maximal size, 800x600 for example",
397 {.name_space
= "Actions",
400 .opt_long
= "action-1",
404 {.name_space
= "Actions",
407 .opt_long
= "action-2",
411 {.name_space
= "Actions",
414 .opt_long
= "action-3",
418 {.name_space
= "Actions",
421 .opt_long
= "action-4",
425 {.name_space
= "Actions",
428 .opt_long
= "action-5",
432 {.name_space
= "Actions",
435 .opt_long
= "action-6",
439 {.name_space
= "Actions",
442 .opt_long
= "action-7",
446 {.name_space
= "Actions",
449 .opt_long
= "action-8",
453 {.name_space
= "Actions",
456 .opt_long
= "action-9",
460 {.name_space
= "Actions",
463 .opt_long
= "action-10",
466 .help
= "Sets command line for action 1-10",
469 {.name_space
= "Devel",
472 .opt_long
= "timers",
475 .help
= "Turns on cpu and wall clock measurement (printed to stdout)",
477 {.name_space
= "Devel",
478 .key
= "BackendEmulation",
480 .opt_long
= "backend-emulation",
482 .set
= set_emulation
,
483 .help
= "Emulate different backend pixel type (G1, G2, RGB555, ...)",
485 {.name_space
= "Devel",
487 .opt_long
= "print-man",
490 .help
= "Prints spiv man page to stdout",
496 int spiv_config_load(const char *path
)
498 return cfg_load(spiv_opts
, path
);
501 int spiv_config_parse_args(int argc
, char *argv
[])
503 return cfg_getopt(spiv_opts
, argc
, argv
);
506 void spiv_config_print_help(void)
508 cfg_print_help(spiv_opts
);
511 void spiv_config_print_man(void)
513 cfg_print_man(spiv_opts
);