Rename GP_Context -> GP_Pixmap
[gfxprim.git] / libs / filters / GP_Laplace.c
blobe0510eb7a1db917e26bd5208934d970d311979e9
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_Pixmap *src, GP_Pixmap *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, 0, 0, src->w, src->h,
40 dst, 0, 0, kern, 3, 3, 1, callback))
41 return 1;
43 return 0;
46 GP_Pixmap *GP_FilterLaplaceAlloc(const GP_Pixmap *src,
47 GP_ProgressCallback *callback)
49 GP_Pixmap *ret = GP_PixmapCopy(src, 0);
51 if (ret == NULL)
52 return NULL;
54 if (GP_FilterLaplace(src, ret, callback)) {
55 GP_PixmapFree(ret);
56 return NULL;
59 return ret;
63 int GP_FilterEdgeSharpening(const GP_Pixmap *src, GP_Pixmap *dst,
64 float w, GP_ProgressCallback *callback)
66 /* Identity kernel */
67 float kern[9] = {0, 0, 0,
68 0, 1, 0,
69 0, 0, 0};
71 GP_DEBUG(1, "Laplace Edge Sharpening filter %ux%u w=%f",
72 src->w, src->h, w);
74 /* Create combined kernel */
75 kern[1] -= 1.00 * w;
76 kern[3] -= 1.00 * w;
77 kern[4] -= -4.00 * w;
78 kern[5] -= 1.00 * w;
79 kern[7] -= 1.00 * w;
81 if (GP_FilterLinearConvolution_Raw(src, 0, 0, src->w, src->h,
82 dst, 0, 0, kern, 3, 3, 1, callback))
83 return 1;
85 return 0;
88 GP_Pixmap *GP_FilterEdgeSharpeningAlloc(const GP_Pixmap *src, float w,
89 GP_ProgressCallback *callback)
91 GP_Pixmap *ret = GP_PixmapCopy(src, 0);
93 if (ret == NULL)
94 return NULL;
96 if (GP_FilterEdgeSharpening(src, ret, w, callback)) {
97 GP_PixmapFree(ret);
98 return NULL;
101 return ret;