2 * Raster graphics library
4 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
31 *----------------------------------------------------------------------
33 * Apply 3x3 1 1 1 low pass, convolution mask to image.
36 *----------------------------------------------------------------------
38 int RBlurImage(RImage
* image
)
42 unsigned char *ptr
, *nptr
;
43 unsigned char *pptr
= NULL
, *tmpp
;
44 int ch
= image
->format
== RRGBAFormat
? 4 : 3;
46 pptr
= malloc(image
->width
* ch
);
48 RErrorCode
= RERR_NOMEMORY
;
51 #define MASK(prev, cur, next, ch)\
52 (*(prev-ch) + *prev + *(prev+ch)\
53 +*(cur-ch) + 2 * *cur + *(cur+ch)\
54 +*(next-ch) + *next + *(next+ch)) / 10
56 memcpy(pptr
, image
->data
, image
->width
* ch
);
59 nptr
= ptr
+ image
->width
* ch
;
67 for (y
= 1; y
< image
->height
- 1; y
++) {
69 for (x
= 1; x
< image
->width
- 1; x
++) {
71 *ptr
= MASK(pptr
, ptr
, nptr
, 3);
78 *ptr
= MASK(pptr
, ptr
, nptr
, 3);
85 *ptr
= MASK(pptr
, ptr
, nptr
, 3);
101 for (y
= 1; y
< image
->height
- 1; y
++) {
102 for (x
= 1; x
< image
->width
- 1; x
++) {
104 *ptr
= MASK(pptr
, ptr
, nptr
, 4);
111 *ptr
= MASK(pptr
, ptr
, nptr
, 4);
118 *ptr
= MASK(pptr
, ptr
, nptr
, 4);
125 *ptr
= MASK(pptr
, ptr
, nptr
, 4);