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,
30 void RBevelImage(RImage
* image
, int bevel_type
)
36 if (image
->width
< 3 || image
->height
< 3)
41 if (bevel_type
> 0) { /* raised */
44 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 80;
45 ROperateLine(image
, RAddOperation
, 0, 0, w
- 1, 0, &cdelta
);
46 if (bevel_type
== RBEV_RAISED3
&& w
> 3)
47 ROperateLine(image
, RAddOperation
, 1, 1, w
- 3, 1, &cdelta
);
50 ROperateLine(image
, RAddOperation
, 0, 1, 0, h
- 1, &cdelta
);
51 if (bevel_type
== RBEV_RAISED3
&& h
> 3)
52 ROperateLine(image
, RAddOperation
, 1, 2, 1, h
- 3, &cdelta
);
56 color
.red
= color
.green
= color
.blue
= 0;
57 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 40;
58 if (bevel_type
== RBEV_RAISED2
|| bevel_type
== RBEV_RAISED3
) {
59 ROperateLine(image
, RSubtractOperation
, 0, h
- 2, w
- 3, h
- 2, &cdelta
);
60 RDrawLine(image
, 0, h
- 1, w
- 1, h
- 1, &color
);
62 ROperateLine(image
, RSubtractOperation
, 0, h
- 1, w
- 1, h
- 1, &cdelta
);
66 if (bevel_type
== RBEV_RAISED2
|| bevel_type
== RBEV_RAISED3
) {
67 ROperateLine(image
, RSubtractOperation
, w
- 2, 0, w
- 2, h
- 2, &cdelta
);
68 RDrawLine(image
, w
- 1, 0, w
- 1, h
- 2, &color
);
70 ROperateLine(image
, RSubtractOperation
, w
- 1, 0, w
- 1, h
- 2, &cdelta
);
74 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 40;
75 ROperateLine(image
, RSubtractOperation
, 0, 0, w
- 1, 0, &cdelta
); /* top */
76 ROperateLine(image
, RSubtractOperation
, 0, 1, 0, h
- 1, &cdelta
); /* left */
77 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 80;
78 ROperateLine(image
, RAddOperation
, 0, h
- 1, w
- 1, h
- 1, &cdelta
); /* bottom */
79 ROperateLine(image
, RAddOperation
, w
- 1, 0, w
- 1, h
- 2, &cdelta
); /* right */
83 void RFillImage(RImage
* image
, const RColor
* color
)
85 unsigned char *d
= image
->data
;
89 if (image
->format
== RRGBAFormat
) {
90 for (i
= 0; i
< image
->width
; i
++) {
96 lineSize
= image
->width
* 4;
97 for (i
= 1; i
< image
->height
; i
++, d
+= lineSize
) {
98 memcpy(d
, image
->data
, lineSize
);
101 for (i
= 0; i
< image
->width
; i
++) {
106 lineSize
= image
->width
* 3;
107 for (i
= 1; i
< image
->height
; i
++, d
+= lineSize
) {
108 memcpy(d
, image
->data
, lineSize
);
113 void RClearImage(RImage
* image
, const RColor
* color
)
115 unsigned char *d
= image
->data
;
119 if (color
->alpha
== 255) {
120 if (image
->format
== RRGBAFormat
) {
121 for (i
= 0; i
< image
->width
; i
++) {
127 lineSize
= image
->width
* 4;
128 for (i
= 1; i
< image
->height
; i
++, d
+= lineSize
) {
129 memcpy(d
, image
->data
, lineSize
);
132 for (i
= 0; i
< image
->width
; i
++) {
137 lineSize
= image
->width
* 3;
138 for (i
= 1; i
< image
->height
; i
++, d
+= lineSize
) {
139 memcpy(d
, image
->data
, lineSize
);
143 int bytes
= image
->width
* image
->height
;
144 int alpha
, nalpha
, r
, g
, b
, s
;
146 alpha
= color
->alpha
;
147 r
= color
->red
* alpha
;
148 g
= color
->green
* alpha
;
149 b
= color
->blue
* alpha
;
150 nalpha
= 255 - alpha
;
152 s
= (image
->format
== RRGBAFormat
) ? 4 : 3;
154 for (i
= 0; i
< bytes
; i
++, d
+= s
) {
155 d
[0] = (((int)d
[0] * nalpha
) + r
)/256;
156 d
[1] = (((int)d
[1] * nalpha
) + g
)/256;
157 d
[2] = (((int)d
[2] * nalpha
) + b
)/256;
162 static inline unsigned char clip(int c
)
166 return (unsigned char)c
;
169 void RLightImage(RImage
*image
, const RColor
*color
)
171 unsigned char *d
= image
->data
;
173 int alpha
, r
, g
, b
, s
;
175 s
= (image
->format
== RRGBAFormat
) ? 4 : 3;
176 dd
= d
+ s
*image
->width
*image
->height
;
182 alpha
= color
->alpha
;
184 if (r
== 0 && g
== 0 && b
== 0) {
185 for (; d
< dd
; d
+= s
) {
186 d
[0] = clip(((int)d
[0] * alpha
)/128);
187 d
[1] = clip(((int)d
[1] * alpha
)/128);
188 d
[2] = clip(((int)d
[2] * alpha
)/128);
191 for (; d
< dd
; d
+= s
) {
192 d
[0] = clip((((int)d
[0] * alpha
) + r
)/128);
193 d
[1] = clip((((int)d
[1] * alpha
) + g
)/128);
194 d
[2] = clip((((int)d
[2] * alpha
) + b
)/128);
199 const char *RMessageForError(int errorCode
)
206 return "could not open file";
209 return "error reading from file";
212 return "error writing to file";
215 return "out of memory";
218 return "out of color cells";
220 case RERR_BADIMAGEFILE
:
221 return "invalid or corrupted image file";
224 return "the image format in the file is not supported and can't be loaded";
227 return "image file does not contain requested image index";
229 case RERR_BADVISUALID
:
230 return "request for an invalid visual ID";
232 case RERR_STDCMAPFAIL
:
233 return "failed to create standard colormap";
236 return "internal X error";
240 return "internal error";