Rename GP_Context -> GP_Pixmap
[gfxprim.git] / demos / c_simple / filters_symmetry.c
blob926445354f9a03b7ea07383b5a24900c0a3d2e3d
1 /*****************************************************************************
2 * This file is part of gfxprim library. *
3 * *
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. *
8 * *
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. *
13 * *
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 *
18 * *
19 * Copyright (C) 2009-2012 Cyril Hrubis <metan@ucw.cz> *
20 * *
21 *****************************************************************************/
25 Symmetry filter example.
29 #include <stdio.h>
30 #include <string.h>
31 #include <errno.h>
32 #include <getopt.h>
34 #include <GP.h>
36 static void usage_and_exit(int ret)
38 int i;
39 printf("filter_symmetry [-d debug_level] -s {");
41 for (i = 0; GP_FilterSymmetryNames[i+1] != NULL; i++)
42 printf("%s, ", GP_FilterSymmetryNames[i]);
44 printf("%s} image_in image_out\n", GP_FilterSymmetryNames[i]);
46 exit(ret);
49 int main(int argc, char *argv[])
51 GP_Pixmap *src, *res;
52 const char *symmetry = NULL;
53 int opt, sym, debug = 0;
55 /* Parse program options */
56 while ((opt = getopt(argc, argv, "d:hs:")) != -1) {
57 switch (opt) {
58 case 's':
59 symmetry = optarg;
60 break;
61 case 'h':
62 usage_and_exit(0);
63 break;
64 case 'd':
65 debug = atoi(optarg);
66 break;
67 default:
68 usage_and_exit(1);
72 /* Turn on debug messages */
73 GP_SetDebugLevel(debug);
75 if (symmetry == NULL) {
76 printf("Symmetry not specified\n");
77 usage_and_exit(1);
80 if (argc - optind != 2) {
81 printf("Input and output image not specified\n");
82 usage_and_exit(1);
85 sym = GP_FilterSymmetryByName(symmetry);
87 if (sym < 0) {
88 printf("Invalid symmetry name '%s'\n", symmetry);
89 usage_and_exit(1);
92 /* Load Image */
93 src = GP_LoadImage(argv[optind], NULL);
95 if (src == NULL) {
96 fprintf(stderr, "Failed to load image '%s': %s\n",
97 argv[optind], strerror(errno));
98 return 1;
101 /* Apply a symmetry filter */
102 res = GP_FilterSymmetryAlloc(src, sym, NULL);
104 /* Save Image */
105 if (GP_SaveImage(res, argv[optind+1], NULL)) {
106 fprintf(stderr, "Failed to save image '%s': %s\n",
107 argv[optind+1], strerror(errno));
108 return 1;
111 /* Cleanup */
112 GP_PixmapFree(src);
113 GP_PixmapFree(res);
115 return 0;