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., 675 Mass Ave, Cambridge, MA 02139, USA.
29 void RBevelImage(RImage
* image
, int bevel_type
)
35 if (image
->width
< 3 || image
->height
< 3)
40 if (bevel_type
> 0) { /* raised */
43 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 80;
44 ROperateLine(image
, RAddOperation
, 0, 0, w
- 1, 0, &cdelta
);
45 if (bevel_type
== RBEV_RAISED3
&& w
> 3)
46 ROperateLine(image
, RAddOperation
, 1, 1, w
- 3, 1, &cdelta
);
49 ROperateLine(image
, RAddOperation
, 0, 1, 0, h
- 1, &cdelta
);
50 if (bevel_type
== RBEV_RAISED3
&& h
> 3)
51 ROperateLine(image
, RAddOperation
, 1, 2, 1, h
- 3, &cdelta
);
55 color
.red
= color
.green
= color
.blue
= 0;
56 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 40;
57 if (bevel_type
== RBEV_RAISED2
|| bevel_type
== RBEV_RAISED3
) {
58 ROperateLine(image
, RSubtractOperation
, 0, h
- 2, w
- 3, h
- 2, &cdelta
);
59 RDrawLine(image
, 0, h
- 1, w
- 1, h
- 1, &color
);
61 ROperateLine(image
, RSubtractOperation
, 0, h
- 1, w
- 1, h
- 1, &cdelta
);
65 if (bevel_type
== RBEV_RAISED2
|| bevel_type
== RBEV_RAISED3
) {
66 ROperateLine(image
, RSubtractOperation
, w
- 2, 0, w
- 2, h
- 2, &cdelta
);
67 RDrawLine(image
, w
- 1, 0, w
- 1, h
- 2, &color
);
69 ROperateLine(image
, RSubtractOperation
, w
- 1, 0, w
- 1, h
- 2, &cdelta
);
73 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 40;
74 ROperateLine(image
, RSubtractOperation
, 0, 0, w
- 1, 0, &cdelta
); /* top */
75 ROperateLine(image
, RSubtractOperation
, 0, 1, 0, h
- 1, &cdelta
); /* left */
76 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 80;
77 ROperateLine(image
, RAddOperation
, 0, h
- 1, w
- 1, h
- 1, &cdelta
); /* bottom */
78 ROperateLine(image
, RAddOperation
, w
- 1, 0, w
- 1, h
- 2, &cdelta
); /* right */
82 void RFillImage(RImage
* image
, RColor
* color
)
84 unsigned char *d
= image
->data
;
88 if (image
->format
== RRGBAFormat
) {
89 for (i
= 0; i
< image
->width
; i
++) {
95 lineSize
= image
->width
* 4;
96 for (i
= 1; i
< image
->height
; i
++, d
+= lineSize
) {
97 memcpy(d
, image
->data
, lineSize
);
100 for (i
= 0; i
< image
->width
; i
++) {
105 lineSize
= image
->width
* 3;
106 for (i
= 1; i
< image
->height
; i
++, d
+= lineSize
) {
107 memcpy(d
, image
->data
, lineSize
);
112 void RClearImage(RImage
* image
, RColor
* color
)
114 unsigned char *d
= image
->data
;
118 if (color
->alpha
== 255) {
119 if (image
->format
== RRGBAFormat
) {
120 for (i
= 0; i
< image
->width
; i
++) {
126 lineSize
= image
->width
* 4;
127 for (i
= 1; i
< image
->height
; i
++, d
+= lineSize
) {
128 memcpy(d
, image
->data
, lineSize
);
131 for (i
= 0; i
< image
->width
; i
++) {
136 lineSize
= image
->width
* 3;
137 for (i
= 1; i
< image
->height
; i
++, d
+= lineSize
) {
138 memcpy(d
, image
->data
, lineSize
);
142 int bytes
= image
->width
* image
->height
;
143 int alpha
, nalpha
, r
, g
, b
, s
;
145 alpha
= color
->alpha
;
146 r
= color
->red
* alpha
;
147 g
= color
->green
* alpha
;
148 b
= color
->blue
* alpha
;
149 nalpha
= 255 - alpha
;
151 s
= (image
->format
== RRGBAFormat
) ? 4 : 3;
153 for (i
= 0; i
< bytes
; i
++, d
+= s
) {
154 d
[0] = (((int)d
[0] * nalpha
) + r
)/256;
155 d
[1] = (((int)d
[1] * nalpha
) + g
)/256;
156 d
[2] = (((int)d
[2] * nalpha
) + b
)/256;
161 static __inline__
unsigned char clip(int c
)
165 return (unsigned char)c
;
168 void RLightImage(RImage
*image
, RColor
*color
)
170 unsigned char *d
= image
->data
;
172 int alpha
, r
, g
, b
, s
;
174 s
= (image
->format
== RRGBAFormat
) ? 4 : 3;
175 dd
= d
+ s
*image
->width
*image
->height
;
181 alpha
= color
->alpha
;
183 if (r
== 0 && g
== 0 && b
== 0) {
184 for (; d
< dd
; d
+= s
) {
185 d
[0] = clip(((int)d
[0] * alpha
)/128);
186 d
[1] = clip(((int)d
[1] * alpha
)/128);
187 d
[2] = clip(((int)d
[2] * alpha
)/128);
190 for (; d
< dd
; d
+= s
) {
191 d
[0] = clip((((int)d
[0] * alpha
) + r
)/128);
192 d
[1] = clip((((int)d
[1] * alpha
) + g
)/128);
193 d
[2] = clip((((int)d
[2] * alpha
) + b
)/128);
198 const char *RMessageForError(int errorCode
)
205 return "could not open file";
208 return "error reading from file";
211 return "error writing to file";
214 return "out of memory";
217 return "out of color cells";
219 case RERR_BADIMAGEFILE
:
220 return "invalid or corrupted image file";
223 return "the image format in the file is not supported and can't be loaded";
226 return "image file does not contain requested image index";
228 case RERR_BADVISUALID
:
229 return "request for an invalid visual ID";
231 case RERR_STDCMAPFAIL
:
232 return "failed to create standard colormap";
235 return "internal X error";
239 return "internal error";