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"
33 void RBevelImage(RImage
* image
, int bevel_type
)
39 if (image
->width
< 3 || image
->height
< 3)
44 if (bevel_type
> 0) { /* raised */
47 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 80;
48 ROperateLine(image
, RAddOperation
, 0, 0, w
- 1, 0, &cdelta
);
49 if (bevel_type
== RBEV_RAISED3
&& w
> 3)
50 ROperateLine(image
, RAddOperation
, 1, 1, w
- 3, 1, &cdelta
);
53 ROperateLine(image
, RAddOperation
, 0, 1, 0, h
- 1, &cdelta
);
54 if (bevel_type
== RBEV_RAISED3
&& h
> 3)
55 ROperateLine(image
, RAddOperation
, 1, 2, 1, h
- 3, &cdelta
);
59 color
.red
= color
.green
= color
.blue
= 0;
60 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 40;
61 if (bevel_type
== RBEV_RAISED2
|| bevel_type
== RBEV_RAISED3
) {
62 ROperateLine(image
, RSubtractOperation
, 0, h
- 2, w
- 3, h
- 2, &cdelta
);
63 RDrawLine(image
, 0, h
- 1, w
- 1, h
- 1, &color
);
65 ROperateLine(image
, RSubtractOperation
, 0, h
- 1, w
- 1, h
- 1, &cdelta
);
69 if (bevel_type
== RBEV_RAISED2
|| bevel_type
== RBEV_RAISED3
) {
70 ROperateLine(image
, RSubtractOperation
, w
- 2, 0, w
- 2, h
- 2, &cdelta
);
71 RDrawLine(image
, w
- 1, 0, w
- 1, h
- 2, &color
);
73 ROperateLine(image
, RSubtractOperation
, w
- 1, 0, w
- 1, h
- 2, &cdelta
);
77 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 40;
78 ROperateLine(image
, RSubtractOperation
, 0, 0, w
- 1, 0, &cdelta
); /* top */
79 ROperateLine(image
, RSubtractOperation
, 0, 1, 0, h
- 1, &cdelta
); /* left */
80 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 80;
81 ROperateLine(image
, RAddOperation
, 0, h
- 1, w
- 1, h
- 1, &cdelta
); /* bottom */
82 ROperateLine(image
, RAddOperation
, w
- 1, 0, w
- 1, h
- 2, &cdelta
); /* right */
86 void RFillImage(RImage
* image
, const RColor
* color
)
88 unsigned char *d
= image
->data
;
92 if (image
->format
== RRGBAFormat
) {
93 for (i
= 0; i
< image
->width
; i
++) {
99 lineSize
= image
->width
* 4;
100 for (i
= 1; i
< image
->height
; i
++, d
+= lineSize
) {
101 memcpy(d
, image
->data
, lineSize
);
104 for (i
= 0; i
< image
->width
; i
++) {
109 lineSize
= image
->width
* 3;
110 for (i
= 1; i
< image
->height
; i
++, d
+= lineSize
) {
111 memcpy(d
, image
->data
, lineSize
);
116 void RClearImage(RImage
* image
, const RColor
* color
)
118 unsigned char *d
= image
->data
;
122 if (color
->alpha
== 255) {
123 if (image
->format
== RRGBAFormat
) {
124 for (i
= 0; i
< image
->width
; i
++) {
130 lineSize
= image
->width
* 4;
131 for (i
= 1; i
< image
->height
; i
++, d
+= lineSize
) {
132 memcpy(d
, image
->data
, lineSize
);
135 for (i
= 0; i
< image
->width
; i
++) {
140 lineSize
= image
->width
* 3;
141 for (i
= 1; i
< image
->height
; i
++, d
+= lineSize
) {
142 memcpy(d
, image
->data
, lineSize
);
146 int bytes
= image
->width
* image
->height
;
147 int alpha
, nalpha
, r
, g
, b
, s
;
149 alpha
= color
->alpha
;
150 r
= color
->red
* alpha
;
151 g
= color
->green
* alpha
;
152 b
= color
->blue
* alpha
;
153 nalpha
= 255 - alpha
;
155 s
= (image
->format
== RRGBAFormat
) ? 4 : 3;
157 for (i
= 0; i
< bytes
; i
++, d
+= s
) {
158 d
[0] = (((int)d
[0] * nalpha
) + r
)/256;
159 d
[1] = (((int)d
[1] * nalpha
) + g
)/256;
160 d
[2] = (((int)d
[2] * nalpha
) + b
)/256;
165 static inline unsigned char clip(int c
)
169 return (unsigned char)c
;
172 void RLightImage(RImage
*image
, const RColor
*color
)
174 unsigned char *d
= image
->data
;
176 int alpha
, r
, g
, b
, s
;
178 s
= (image
->format
== RRGBAFormat
) ? 4 : 3;
179 dd
= d
+ s
*image
->width
*image
->height
;
185 alpha
= color
->alpha
;
187 if (r
== 0 && g
== 0 && b
== 0) {
188 for (; d
< dd
; d
+= s
) {
189 d
[0] = clip(((int)d
[0] * alpha
)/128);
190 d
[1] = clip(((int)d
[1] * alpha
)/128);
191 d
[2] = clip(((int)d
[2] * alpha
)/128);
194 for (; d
< dd
; d
+= s
) {
195 d
[0] = clip((((int)d
[0] * alpha
) + r
)/128);
196 d
[1] = clip((((int)d
[1] * alpha
) + g
)/128);
197 d
[2] = clip((((int)d
[2] * alpha
) + b
)/128);
202 const char *RMessageForError(int errorCode
)
209 return "could not open file";
212 return "error reading from file";
215 return "error writing to file";
218 return "out of memory";
221 return "out of color cells";
223 case RERR_BADIMAGEFILE
:
224 return "invalid or corrupted image file";
227 return "the image format in the file is not supported and can't be loaded";
230 return "image file does not contain requested image index";
232 case RERR_BADVISUALID
:
233 return "request for an invalid visual ID";
235 case RERR_STDCMAPFAIL
:
236 return "failed to create standard colormap";
239 return "internal X error";
243 return "internal error";
248 * cleaning third-party libs at shutdown
256 r_destroy_conversion_tables();