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-2013 Cyril Hrubis <metan@ucw.cz> *
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
,
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
,
61 new_callback
= callback
? &conv_callback
: NULL
;
63 if (GP_FilterVLinearConvolution_Raw(src
, x_src
, y_src
, w_src
, h_src
,
65 hkernel
, kw
, hkern_div
,
69 conv_callback
.callback
= v_callback
;
71 if (GP_FilterHLinearConvolution_Raw(dst
, x_src
, y_src
, w_src
, h_src
,
73 vkernel
, kh
, vkern_div
,
77 GP_ProgressCallbackDone(callback
);
81 void GP_FilterKernelPrint_Raw(float kernel
[], int kw
, int kh
, float kern_div
)
85 for (i
= 0; i
< kw
; i
++) {
88 printf("% 8.2f * | ", 1/kern_div
);
92 for (j
= 0; j
< kh
; j
++)
93 printf("% 8.2f ", kernel
[j
+ i
* kw
]);