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-2013 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
,
41 static int set_zoom_strategy(struct cfg_opt
*self
, unsigned int lineno
)
45 printf("ZoomStrategy = %s\n", self
->val
);
50 static int set_action(struct cfg_opt
*self
, unsigned int lineno
)
53 image_action_set(atoi(self
->key
), self
->val
);
57 static int set_opt(struct cfg_opt
*self
, unsigned int lineno
)
64 config
.floyd_steinberg
= 1;
70 config
.show_progress
= 1;
80 static int set_orientation(struct cfg_opt
*self
, unsigned int lineno
)
82 if (!strcmp("0", self
->val
)) {
83 config
.orientation
= ROTATE_0
;
87 if (!strcmp("90", self
->val
)) {
88 config
.orientation
= ROTATE_90
;
92 if (!strcmp("180", self
->val
)) {
93 config
.orientation
= ROTATE_180
;
97 if (!strcmp("270", self
->val
)) {
98 config
.orientation
= ROTATE_270
;
102 fprintf(stderr
, "ERROR: %u: Invalid orientation '%s'\n",
107 static int set_backend_init(struct cfg_opt
*self
, unsigned int lineno
)
109 if (strlen(self
->val
) + 1 >= sizeof(config
.backend_init
)) {
110 fprintf(stderr
, "ERROR: %u: Backend init string too long\n",
115 strcpy(config
.backend_init
, self
->val
);
120 static int set_slideshow(struct cfg_opt
*self
, unsigned int lineno
)
122 config
.slideshow_delay
= atof(self
->val
);
124 if (config
.slideshow_delay
== 0) {
125 fprintf(stderr
, "ERROR: %u: Invalid slideshow delay '%s'\n",
133 static int set_emulation(struct cfg_opt
*self
, unsigned int lineno
)
135 config
.emul_type
= GP_PixelTypeByName(optarg
);
137 if (config
.emul_type
== GP_PIXEL_UNKNOWN
) {
138 fprintf(stderr
, "ERROR: %u: Invalid pixel type '%s'\n",
146 static int help(struct cfg_opt
*self
, unsigned int lineno
)
155 static int man(struct cfg_opt
*self
, unsigned int lineno
)
164 struct cfg_opt spiv_opts
[] = {
171 .help
= "Shows this help",
174 {.name_space
= "Gui",
177 .opt_long
= "show-info",
180 .help
= "Show image info such as filename, size, etc...",
182 {.name_space
= "Gui",
183 .key
= "ShowProgress",
185 .opt_long
= "show-progress",
187 .help
= "Show progress bar when loading/resampling/... images",
189 {.name_space
= "Gui",
190 .key
= "SlideshowDelay",
192 .opt_long
= "slideshow-delay",
194 .set
= set_slideshow
,
195 .help
= "Delay between images in seconds (float) for slideshow",
197 {.name_space
= "Gui",
198 .key
= "UseFloydSteinberg",
200 .opt_long
= "floyd-steinberg",
203 .help
= "Turn on Floyd-Steinberg dithering",
205 {.name_space
= "Gui",
206 .key
= "Orientation",
208 .opt_long
= "orientation",
210 .set
= set_orientation
,
211 .help
= "Orientation, one of 0, 90, 180, 270",
213 {.name_space
= "Gui",
214 .key
= "BackendInit",
216 .opt_long
= "backend-init",
218 .set
= set_backend_init
,
219 .help
= "Backend init string, set it to 'help' for more info",
222 {.name_space
= "Zoom",
223 .key
= "ZoomStrategy",
225 .opt_long
= "zoom-strategy",
227 .set
= set_zoom_strategy
,
228 .help
= "Zoom strategy",
232 {.name_space
= "Actions",
235 .opt_long
= "action-1",
239 {.name_space
= "Actions",
242 .opt_long
= "action-2",
246 {.name_space
= "Actions",
249 .opt_long
= "action-3",
253 {.name_space
= "Actions",
256 .opt_long
= "action-4",
260 {.name_space
= "Actions",
263 .opt_long
= "action-5",
267 {.name_space
= "Actions",
270 .opt_long
= "action-6",
274 {.name_space
= "Actions",
277 .opt_long
= "action-7",
281 {.name_space
= "Actions",
284 .opt_long
= "action-8",
288 {.name_space
= "Actions",
291 .opt_long
= "action-9",
295 {.name_space
= "Actions",
298 .opt_long
= "action-10",
301 .help
= "Sets command line for action 1-10",
304 {.name_space
= "Devel",
307 .opt_long
= "timers",
310 .help
= "Turns on cpu and wall clock measurement (printed to stdout)",
312 {.name_space
= "Devel",
313 .key
= "BackendEmulation",
315 .opt_long
= "backend-emulation",
317 .set
= set_emulation
,
318 .help
= "Emulate different backend pixel type (G1, G2, RGB555, ...)",
320 {.name_space
= "Devel",
322 .opt_long
= "print-man",
325 .help
= "Prints spiv man page to stdout",
331 int spiv_config_load(const char *path
)
333 return cfg_load(spiv_opts
, path
);
336 int spiv_config_parse_args(int argc
, char *argv
[])
338 return cfg_getopt(spiv_opts
, argc
, argv
);
341 void spiv_config_print_help(void)
343 cfg_print_help(spiv_opts
);
346 void spiv_config_print_man(void)
348 cfg_print_man(spiv_opts
);