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,
34 *----------------------------------------------------------------------
36 * Apply 3x3 1 1 1 low pass, convolution mask to image.
39 *----------------------------------------------------------------------
41 int RBlurImage(RImage
* image
)
45 unsigned char *ptr
, *nptr
;
46 unsigned char *pptr
= NULL
, *tmpp
;
47 int ch
= image
->format
== RRGBAFormat
? 4 : 3;
49 pptr
= malloc(image
->width
* ch
);
51 RErrorCode
= RERR_NOMEMORY
;
54 #define MASK(prev, cur, next, ch)\
55 (*(prev-ch) + *prev + *(prev+ch)\
56 +*(cur-ch) + 2 * *cur + *(cur+ch)\
57 +*(next-ch) + *next + *(next+ch)) / 10
59 memcpy(pptr
, image
->data
, image
->width
* ch
);
62 nptr
= ptr
+ image
->width
* ch
;
70 for (y
= 1; y
< image
->height
- 1; y
++) {
72 for (x
= 1; x
< image
->width
- 1; x
++) {
74 *ptr
= MASK(pptr
, ptr
, nptr
, 3);
81 *ptr
= MASK(pptr
, ptr
, nptr
, 3);
88 *ptr
= MASK(pptr
, ptr
, nptr
, 3);
104 for (y
= 1; y
< image
->height
- 1; y
++) {
105 for (x
= 1; x
< image
->width
- 1; x
++) {
107 *ptr
= MASK(pptr
, ptr
, nptr
, 4);
114 *ptr
= MASK(pptr
, ptr
, nptr
, 4);
121 *ptr
= MASK(pptr
, ptr
, nptr
, 4);
128 *ptr
= MASK(pptr
, ptr
, nptr
, 4);