Rename GP_Context -> GP_Pixmap
[gfxprim.git] / demos / c_simple / gaussian_noise.c
blob8c0cb152ebc93888d6c930ea9d342fbdbf8688c8
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-2013 Cyril Hrubis <metan@ucw.cz> *
20 * *
21 *****************************************************************************/
25 Gaussian additive noise example.
29 #include <stdio.h>
30 #include <unistd.h>
31 #include <string.h>
32 #include <errno.h>
34 #include <GP.h>
36 static void help(const char *app)
38 printf("usage: %s -s float -m float input.img output.img\n\n", app);
39 printf(" -s [0,1] sigma in pixels\n");
40 printf(" -m [0,1] mu in pixels\n");
43 int main(int argc, char *argv[])
45 GP_Pixmap *img;
46 float sigma = 0.1, mu = 0.1;
47 int opt;
49 while ((opt = getopt(argc, argv, "s:m:")) != -1) {
50 switch (opt) {
51 case 's':
52 sigma = atof(optarg);
53 break;
54 case 'm':
55 mu = atof(optarg);
56 break;
57 default:
58 help(argv[0]);
59 return 1;
63 if (argc - optind != 2) {
64 help(argv[0]);
65 return 1;
68 img = GP_LoadImage(argv[optind], NULL);
70 if (img == NULL) {
71 fprintf(stderr, "Failed to load image '%s': %s\n",
72 argv[optind], strerror(errno));
73 return 1;
76 GP_Pixmap *res = GP_FilterGaussianNoiseAddAlloc(img, sigma, mu, NULL);
78 if (GP_SaveImage(res, argv[optind + 1], NULL)) {
79 fprintf(stderr, "Failed to save image '%s': %s",
80 argv[optind + 1], strerror(errno));
81 return 1;
84 return 0;