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,
29 #include "imgformat.h"
32 void RBevelImage(RImage
* image
, int bevel_type
)
38 if (image
->width
< 3 || image
->height
< 3)
43 if (bevel_type
> 0) { /* raised */
46 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 80;
47 ROperateLine(image
, RAddOperation
, 0, 0, w
- 1, 0, &cdelta
);
48 if (bevel_type
== RBEV_RAISED3
&& w
> 3)
49 ROperateLine(image
, RAddOperation
, 1, 1, w
- 3, 1, &cdelta
);
52 ROperateLine(image
, RAddOperation
, 0, 1, 0, h
- 1, &cdelta
);
53 if (bevel_type
== RBEV_RAISED3
&& h
> 3)
54 ROperateLine(image
, RAddOperation
, 1, 2, 1, h
- 3, &cdelta
);
58 color
.red
= color
.green
= color
.blue
= 0;
59 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 40;
60 if (bevel_type
== RBEV_RAISED2
|| bevel_type
== RBEV_RAISED3
) {
61 ROperateLine(image
, RSubtractOperation
, 0, h
- 2, w
- 3, h
- 2, &cdelta
);
62 RDrawLine(image
, 0, h
- 1, w
- 1, h
- 1, &color
);
64 ROperateLine(image
, RSubtractOperation
, 0, h
- 1, w
- 1, h
- 1, &cdelta
);
68 if (bevel_type
== RBEV_RAISED2
|| bevel_type
== RBEV_RAISED3
) {
69 ROperateLine(image
, RSubtractOperation
, w
- 2, 0, w
- 2, h
- 2, &cdelta
);
70 RDrawLine(image
, w
- 1, 0, w
- 1, h
- 2, &color
);
72 ROperateLine(image
, RSubtractOperation
, w
- 1, 0, w
- 1, h
- 2, &cdelta
);
76 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 40;
77 ROperateLine(image
, RSubtractOperation
, 0, 0, w
- 1, 0, &cdelta
); /* top */
78 ROperateLine(image
, RSubtractOperation
, 0, 1, 0, h
- 1, &cdelta
); /* left */
79 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 80;
80 ROperateLine(image
, RAddOperation
, 0, h
- 1, w
- 1, h
- 1, &cdelta
); /* bottom */
81 ROperateLine(image
, RAddOperation
, w
- 1, 0, w
- 1, h
- 2, &cdelta
); /* right */
85 void RFillImage(RImage
* image
, const RColor
* color
)
87 unsigned char *d
= image
->data
;
91 if (image
->format
== RRGBAFormat
) {
92 for (i
= 0; i
< image
->width
; i
++) {
98 lineSize
= image
->width
* 4;
99 for (i
= 1; i
< image
->height
; i
++, d
+= lineSize
) {
100 memcpy(d
, image
->data
, lineSize
);
103 for (i
= 0; i
< image
->width
; i
++) {
108 lineSize
= image
->width
* 3;
109 for (i
= 1; i
< image
->height
; i
++, d
+= lineSize
) {
110 memcpy(d
, image
->data
, lineSize
);
115 void RClearImage(RImage
* image
, const RColor
* color
)
117 unsigned char *d
= image
->data
;
121 if (color
->alpha
== 255) {
122 if (image
->format
== RRGBAFormat
) {
123 for (i
= 0; i
< image
->width
; i
++) {
129 lineSize
= image
->width
* 4;
130 for (i
= 1; i
< image
->height
; i
++, d
+= lineSize
) {
131 memcpy(d
, image
->data
, lineSize
);
134 for (i
= 0; i
< image
->width
; i
++) {
139 lineSize
= image
->width
* 3;
140 for (i
= 1; i
< image
->height
; i
++, d
+= lineSize
) {
141 memcpy(d
, image
->data
, lineSize
);
145 int bytes
= image
->width
* image
->height
;
146 int alpha
, nalpha
, r
, g
, b
, s
;
148 alpha
= color
->alpha
;
149 r
= color
->red
* alpha
;
150 g
= color
->green
* alpha
;
151 b
= color
->blue
* alpha
;
152 nalpha
= 255 - alpha
;
154 s
= (image
->format
== RRGBAFormat
) ? 4 : 3;
156 for (i
= 0; i
< bytes
; i
++, d
+= s
) {
157 d
[0] = (((int)d
[0] * nalpha
) + r
)/256;
158 d
[1] = (((int)d
[1] * nalpha
) + g
)/256;
159 d
[2] = (((int)d
[2] * nalpha
) + b
)/256;
164 static inline unsigned char clip(int c
)
168 return (unsigned char)c
;
171 void RLightImage(RImage
*image
, const RColor
*color
)
173 unsigned char *d
= image
->data
;
175 int alpha
, r
, g
, b
, s
;
177 s
= (image
->format
== RRGBAFormat
) ? 4 : 3;
178 dd
= d
+ s
*image
->width
*image
->height
;
184 alpha
= color
->alpha
;
186 if (r
== 0 && g
== 0 && b
== 0) {
187 for (; d
< dd
; d
+= s
) {
188 d
[0] = clip(((int)d
[0] * alpha
)/128);
189 d
[1] = clip(((int)d
[1] * alpha
)/128);
190 d
[2] = clip(((int)d
[2] * alpha
)/128);
193 for (; d
< dd
; d
+= s
) {
194 d
[0] = clip((((int)d
[0] * alpha
) + r
)/128);
195 d
[1] = clip((((int)d
[1] * alpha
) + g
)/128);
196 d
[2] = clip((((int)d
[2] * alpha
) + b
)/128);
201 const char *RMessageForError(int errorCode
)
208 return "could not open file";
211 return "error reading from file";
214 return "error writing to file";
217 return "out of memory";
220 return "out of color cells";
222 case RERR_BADIMAGEFILE
:
223 return "invalid or corrupted image file";
226 return "the image format in the file is not supported and can't be loaded";
229 return "image file does not contain requested image index";
231 case RERR_BADVISUALID
:
232 return "request for an invalid visual ID";
234 case RERR_STDCMAPFAIL
:
235 return "failed to create standard colormap";
238 return "internal X error";
242 return "internal error";
247 * cleaning third-party libs at shutdown