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-2012 Cyril Hrubis <metan@ucw.cz> *
21 *****************************************************************************/
25 Convolution filter example.
35 struct callback_priv
{
40 static int progress_callback(GP_ProgressCallback
*self
)
42 struct callback_priv
*priv
= self
->priv
;
44 printf("\r%s '%s' %3.1f%%", priv
->op
, priv
->name
, self
->percentage
);
48 * It's important to return zero as non-zero return value
49 * aborts the operation.
54 int main(int argc
, char *argv
[])
57 struct callback_priv priv
;
58 GP_ProgressCallback callback
= {.callback
= progress_callback
,
62 fprintf(stderr
, "Takes an image as an parameter\n");
69 img
= GP_LoadImage(argv
[1], &callback
);
72 fprintf(stderr
, "Failed to load image '%s': %s\n", argv
[1],
80 GP_FilterKernel2D box
= {
85 0.0, 0.1, 1.0, 0.1, 0.0,
86 0.1, 0.5, 1.0, 0.5, 0.1,
87 1.0, 1.0, 1.0, 1.0, 1.0,
88 0.1, 0.5, 1.0, 0.5, 0.1,
89 0.0, 0.1, 1.0, 0.1, 0.0,
93 priv
.op
= "Linear Convolution";
96 * Blur in-place, inner rectangle of the image.
98 GP_FilterConvolutionEx(img
, img
->w
/4, img
->h
/4, img
->w
/2, img
->h
/2,
99 img
, img
->w
/4, img
->h
/4, &box
, &callback
);
104 priv
.name
= "out.png";
106 if (GP_SavePNG(img
, "out.png", &callback
)) {
107 fprintf(stderr
, "Failed to save image: %s", strerror(errno
));