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.
31 RBevelImage(RImage
*image
, int bevel_type
)
37 if (image
->width
<3 || image
->height
<3)
42 if (bevel_type
>0) { /* raised */
45 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 80;
46 ROperateLine(image
, RAddOperation
, 0, 0, w
-1, 0, &cdelta
);
47 if (bevel_type
==RBEV_RAISED3
&& w
>3)
48 ROperateLine(image
, RAddOperation
, 1, 1, w
-3, 1,&cdelta
);
51 ROperateLine(image
, RAddOperation
, 0, 1, 0, h
-1, &cdelta
);
52 if (bevel_type
==RBEV_RAISED3
&& h
>3)
53 ROperateLine(image
, RAddOperation
, 1, 2, 1, h
-3, &cdelta
);
57 color
.red
= color
.green
= color
.blue
= 0;
58 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 40;
59 if (bevel_type
==RBEV_RAISED2
|| bevel_type
==RBEV_RAISED3
) {
60 ROperateLine(image
, RSubtractOperation
, 0, h
-2, w
-3,
62 RDrawLine(image
, 0, h
-1, w
-1, h
-1, &color
);
64 ROperateLine(image
, RSubtractOperation
, 0, h
-1, w
-1, h
-1,
69 if (bevel_type
==RBEV_RAISED2
|| bevel_type
==RBEV_RAISED3
) {
70 ROperateLine(image
, RSubtractOperation
, w
-2, 0, w
-2, h
-2,
72 RDrawLine(image
, w
-1, 0, w
-1, h
-2, &color
);
74 ROperateLine(image
, RSubtractOperation
, w
-1, 0, w
-1, h
-2,
79 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 40;
80 ROperateLine(image
, RSubtractOperation
, 0, 0, w
-1, 0,
82 ROperateLine(image
, RSubtractOperation
, 0, 1, 0, h
-1,
84 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 80;
85 ROperateLine(image
, RAddOperation
, 0, h
-1, w
-1, h
-1, &cdelta
); /* bottom */
86 ROperateLine(image
, RAddOperation
, w
-1, 0, w
-1, h
-2, &cdelta
); /* right */
92 RFillImage(RImage
*image
, RColor
*color
)
94 unsigned char *d
= image
->data
;
98 if (image
->format
== RRGBAFormat
) {
99 for (i
= 0; i
< image
->width
; i
++) {
105 lineSize
= image
->width
*4;
106 for (i
= 1; i
< image
->height
; i
++, d
+=lineSize
) {
107 memcpy(d
, image
->data
, lineSize
);
110 for (i
= 0; i
< image
->width
; i
++) {
115 lineSize
= image
->width
*3;
116 for (i
= 1; i
< image
->height
; i
++, d
+=lineSize
) {
117 memcpy(d
, image
->data
, lineSize
);
124 RClearImage(RImage
*image
, RColor
*color
)
126 unsigned char *d
= image
->data
;
130 if (color
->alpha
==255) {
131 if (image
->format
== RRGBAFormat
) {
132 for (i
= 0; i
< image
->width
; i
++) {
138 lineSize
= image
->width
*4;
139 for (i
= 1; i
< image
->height
; i
++, d
+=lineSize
) {
140 memcpy(d
, image
->data
, lineSize
);
143 for (i
= 0; i
< image
->width
; i
++) {
148 lineSize
= image
->width
*3;
149 for (i
= 1; i
< image
->height
; i
++, d
+=lineSize
) {
150 memcpy(d
, image
->data
, lineSize
);
154 int bytes
= image
->width
*image
->height
;
155 int alpha
, nalpha
, r
, g
, b
;
157 alpha
= color
->alpha
;
158 r
= color
->red
* alpha
;
159 g
= color
->green
* alpha
;
160 b
= color
->blue
* alpha
;
161 nalpha
= 255 - alpha
;
163 for (i
=0; i
<bytes
; i
++) {
164 *d
= (((int)*d
* nalpha
) + r
)/256; d
++;
165 *d
= (((int)*d
* nalpha
) + g
)/256; d
++;
166 *d
= (((int)*d
* nalpha
) + b
)/256; d
++;
167 if (image
->format
== RRGBAFormat
) {
175 RMessageForError(int errorCode
)
182 return "could not open file";
185 return "error reading from file";
188 return "error writing to file";
191 return "out of memory";
194 return "out of color cells";
196 case RERR_BADIMAGEFILE
:
197 return "invalid or corrupted image file";
200 return "the image format in the file is not supported and can't be loaded";
203 return "image file does not contain requested image index";
205 case RERR_BADVISUALID
:
206 return "request for an invalid visual ID";
208 case RERR_STDCMAPFAIL
:
209 return "failed to create standard colormap";
212 return "internal X error";
216 return "internal error";