2 * Raster graphics library
4 * Copyright (c) 1997 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., 675 Mass Ave, Cambridge, MA 02139, USA.
23 /* AIX requires this to be the first thing in the file. */
25 # define alloca __builtin_alloca
33 # ifndef alloca /* predefined by HP cc +Olibcalls */
49 *----------------------------------------------------------------------
51 * Apply 3x3 1 1 1 low pass, convolution mask to image.
54 *----------------------------------------------------------------------
57 RBlurImage(RImage
*image
)
61 unsigned char *r
, *g
, *b
, *a
;
62 unsigned char *pr
=NULL
, *pg
=NULL
, *pb
=NULL
, *pa
=NULL
;
64 #define MASK(c,pc,p) ((*c+ *c + *(c-1) + *(c+1) + pc[p] + pc[p-1] + pc[p+1] \
65 + *(c+w) + *(c+w-1) + *(c+w+1))/10)
67 pr
= (unsigned char*)alloca(image
->width
*sizeof(char));
71 pg
= (unsigned char*)alloca(image
->width
*sizeof(char));
75 pb
= (unsigned char*)alloca(image
->width
*sizeof(char));
79 pa
= (unsigned char*)alloca(image
->width
*sizeof(char));
90 for (x
=0; x
<image
->width
; x
++) {
98 for (y
=1; y
<image
->height
-1; y
++) {
107 for (x
=1; x
<image
->width
-1; x
++) {
109 *(r
++) = MASK(r
,pr
,x
);
113 *(g
++) = MASK(g
,pg
,x
);
117 *(b
++) = MASK(b
,pb
,x
);
133 RErrorCode
= RERR_NOMEMORY
;
143 REdgeDetectImage(RImage
*image
)
145 register int x
, y
, d1
, d2
, d3
, d4
, rsum
;
147 unsigned char *r
, *g
, *b
, *a
;
148 unsigned char *dr
, *dg
, *db
, *da
;
149 unsigned char *pr
=NULL
, *pg
=NULL
, *pb
=NULL
, *pa
=NULL
;
153 image2
= RCloneImage(image
);
155 pr
= alloca(image
->width
*sizeof(char));
159 pg
= alloca(image
->width
*sizeof(char));
163 pb
= alloca(image
->width
*sizeof(char));
167 pa
= alloca(image
->width
*sizeof(char));
177 dr
= image2
->data
[0];
178 dg
= image2
->data
[1];
179 db
= image2
->data
[2];
180 da
= image2
->data
[3];
183 for (x
=0; x
<image
->width
; x
++) {
191 for (y
=1; y
<image
->height
-1; y
++) {
200 for (x
=1; x
<image
->width
-1; x
++) {
201 d1
= r
[w
+1] - r
[-w
-1];
203 d3
= r
[-w
+1] - r
[w
-1];
207 if (rsum
< 0) rsum
= -rsum
;
208 d1
= d1
- d2
- d4
; /* vertical gradient */
209 if (d1
< 0) d1
= -d1
;
210 if (d1
> rsum
) rsum
= d1
;
215 d1
= g
[w
+1] - g
[-w
-1];
217 d3
= g
[-w
+1] - g
[w
-1];
221 if (rsum
< 0) rsum
= -rsum
;
222 d1
= d1
- d2
- d4
; /* vertical gradient */
223 if (d1
< 0) d1
= -d1
;
224 if (d1
> rsum
) rsum
= d1
;
229 d1
= b
[w
+1] - b
[-w
-1];
231 d3
= b
[-w
+1] - b
[w
-1];
235 if (rsum
< 0) rsum
= -rsum
;
236 d1
= d1
- d2
- d4
; /* vertical gradient */
237 if (d1
< 0) d1
= -d1
;
238 if (d1
> rsum
) rsum
= d1
;
262 RDestroyImage(image2
);
272 RSmoothImage(RImage
*image
)
276 unsigned char *r
, *g
, *b
, *a
;
284 for (y
=0; y
<image
->height
- 1; y
++) {
285 for (x
=0; x
<image
->width
- 1; x
++) {
286 v
= *r
+ 2 * *(r
+ 1) + 2 * *(r
+ w
) + *(r
+ w
+ 1);
289 v
= *g
+ 2 * *(g
+ 1) + 2 * *(g
+ w
) + *(g
+ w
+ 1);
292 v
= *b
+ 2 * *(b
+ 1) + 2 * *(b
+ w
) + *(b
+ w
+ 1);
297 v
= 3 * *r
+ 3 * *(r
+ w
);
300 v
= 3 * *g
+ 3 * *(g
+ w
);
303 v
= 3 * *b
+ 3 * *(b
+ w
);
308 for (x
=0; x
<image
->width
- 1; x
++) {
309 v
= 3 * *r
+ 3 * *(r
+ 1);
312 v
= 3 * *g
+ 3 * *(g
+ 1);
315 v
= 3 * *b
+ 3 * *(b
+ 1);