Rename GP_Context -> GP_Pixmap
[gfxprim.git] / libs / filters / GP_LinearConvolution.c
blob6012edc344827ca7cd8953c2c2fc88ae68146585
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 *****************************************************************************/
23 #include "core/GP_Pixmap.h"
24 #include "core/GP_Debug.h"
26 #include "GP_Linear.h"
28 static int h_callback(GP_ProgressCallback *self)
30 GP_ProgressCallback *callback = self->priv;
32 callback->percentage = self->percentage / 2;
33 return callback->callback(callback);
36 static int v_callback(GP_ProgressCallback *self)
38 GP_ProgressCallback *callback = self->priv;
40 callback->percentage = self->percentage / 2 + 50;
41 return callback->callback(callback);
44 int GP_FilterVHLinearConvolution_Raw(const GP_Pixmap *src,
45 GP_Coord x_src, GP_Coord y_src,
46 GP_Size w_src, GP_Size h_src,
47 GP_Pixmap *dst,
48 GP_Coord x_dst, GP_Coord y_dst,
49 float hkernel[], uint32_t kw, float hkern_div,
50 float vkernel[], uint32_t kh, float vkern_div,
51 GP_ProgressCallback *callback)
53 GP_ProgressCallback *new_callback;
55 GP_ProgressCallback conv_callback = {
56 .callback = h_callback,
57 .priv = callback,
60 return 0;
61 new_callback = callback ? &conv_callback : NULL;
63 if (GP_FilterVLinearConvolution_Raw(src, x_src, y_src, w_src, h_src,
64 dst, x_dst, y_dst,
65 hkernel, kw, hkern_div,
66 new_callback))
67 return 1;
69 conv_callback.callback = v_callback;
71 if (GP_FilterHLinearConvolution_Raw(dst, x_src, y_src, w_src, h_src,
72 dst, x_dst, y_dst,
73 vkernel, kh, vkern_div,
74 new_callback))
75 return 1;
77 GP_ProgressCallbackDone(callback);
78 return 0;
81 void GP_FilterKernelPrint_Raw(float kernel[], int kw, int kh, float kern_div)
83 int i, j;
85 for (i = 0; i < kw; i++) {
87 if (i == kw/2)
88 printf("% 8.2f * | ", 1/kern_div);
89 else
90 printf(" | ");
92 for (j = 0; j < kh; j++)
93 printf("% 8.2f ", kernel[j + i * kw]);
95 printf("|\n");