doc: filters.txt, context.txt: small fixes and clarifications.
[gfxprim.git] / libs / filters / GP_Laplace.c
blobb6a91a1e8b614f737d5481aad54defd72f9ff9d3
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 *****************************************************************************/
23 #include "core/GP_Debug.h"
24 #include "core/GP_GetPutPixel.h"
26 #include "GP_Linear.h"
28 #include "GP_Laplace.h"
30 int GP_FilterLaplace(const GP_Context *src, GP_Context *dst,
31 GP_ProgressCallback *callback)
33 GP_DEBUG(1, "Laplace filter %ux%u", src->w, src->h);
35 float kern[9] = {0, 1, 0,
36 1, -4, 1,
37 0, 1, 0};
39 if (GP_FilterLinearConvolution_Raw(src, dst, kern, 3, 3, 1, callback))
40 return 1;
42 return 0;
45 GP_Context *GP_FilterLaplaceAlloc(const GP_Context *src,
46 GP_ProgressCallback *callback)
48 GP_Context *ret = GP_ContextCopy(src, 0);
50 if (ret == NULL)
51 return NULL;
53 if (GP_FilterLaplace(src, ret, callback)) {
54 GP_ContextFree(ret);
55 return NULL;
58 return ret;
62 int GP_FilterEdgeSharpening(const GP_Context *src, GP_Context *dst,
63 float w, GP_ProgressCallback *callback)
65 /* Identity kernel */
66 float kern[9] = {0, 0, 0,
67 0, 1, 0,
68 0, 0, 0};
70 GP_DEBUG(1, "Laplace Edge Sharpening filter %ux%u w=%f",
71 src->w, src->h, w);
73 /* Create combined kernel */
74 kern[1] -= 1.00 * w;
75 kern[3] -= 1.00 * w;
76 kern[4] -= -4.00 * w;
77 kern[5] -= 1.00 * w;
78 kern[7] -= 1.00 * w;
80 GP_FilterKernelPrint(kern, 3, 3, 1);
82 if (GP_FilterLinearConvolution_Raw(src, dst, kern, 3, 3, 1, callback))
83 return 1;
85 return 0;
88 GP_Context *GP_FilterEdgeSharpeningAlloc(const GP_Context *src, float w,
89 GP_ProgressCallback *callback)
91 GP_Context *ret = GP_ContextCopy(src, 0);
93 if (ret == NULL)
94 return NULL;
96 if (GP_FilterEdgeSharpening(src, ret, w, callback)) {
97 GP_ContextFree(ret);
98 return NULL;
101 return ret;