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 *****************************************************************************/
23 #include "core/GP_Debug.h"
25 #include "GP_Linear.h"
27 #include "GP_Convolution.h"
28 int GP_FilterConvolutionEx(const GP_Context
*src
,
29 GP_Coord x_src
, GP_Coord y_src
,
30 GP_Size w_src
, GP_Coord h_src
,
32 GP_Coord x_dst
, GP_Coord y_dst
,
33 const GP_FilterKernel2D
*kernel
,
34 GP_ProgressCallback
*callback
)
36 GP_CHECK(src
->pixel_type
== dst
->pixel_type
);
38 /* Check that destination is large enough */
39 GP_CHECK(x_dst
+ (GP_Coord
)w_src
<= (GP_Coord
)dst
->w
);
40 GP_CHECK(y_dst
+ (GP_Coord
)h_src
<= (GP_Coord
)dst
->h
);
42 /* The source pixel coordinates are clamped inside of the filter */
44 GP_DEBUG(1, "Linear convolution kernel size %ux%u",
45 kernel
->w
, kernel
->h
);
47 return GP_FilterLinearConvolution_Raw(src
, x_src
, y_src
, w_src
, h_src
,
48 dst
, x_dst
, y_dst
, kernel
->kernel
,
49 kernel
->w
, kernel
->h
, kernel
->div
,
53 GP_Context
*GP_FilterConvolutionExAlloc(const GP_Context
*src
,
54 GP_Coord x_src
, GP_Coord y_src
,
55 GP_Size w_src
, GP_Size h_src
,
56 const GP_FilterKernel2D
*kernel
,
57 GP_ProgressCallback
*callback
)
59 GP_Context
*ret
= GP_ContextAlloc(w_src
, h_src
, src
->pixel_type
);
61 GP_DEBUG(1, "Linear convolution kernel size %ux%u",
62 kernel
->w
, kernel
->h
);
67 if (GP_FilterLinearConvolution_Raw(src
, x_src
, y_src
, w_src
, h_src
,
68 ret
, 0, 0, kernel
->kernel
, kernel
->w
,
69 kernel
->h
, kernel
->div
, callback
)) {