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"
34 void RBevelImage(RImage
* image
, int bevel_type
)
40 if (image
->width
< 3 || image
->height
< 3)
45 if (bevel_type
> 0) { /* raised */
48 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 80;
49 ROperateLine(image
, RAddOperation
, 0, 0, w
- 1, 0, &cdelta
);
50 if (bevel_type
== RBEV_RAISED3
&& w
> 3)
51 ROperateLine(image
, RAddOperation
, 1, 1, w
- 3, 1, &cdelta
);
54 ROperateLine(image
, RAddOperation
, 0, 1, 0, h
- 1, &cdelta
);
55 if (bevel_type
== RBEV_RAISED3
&& h
> 3)
56 ROperateLine(image
, RAddOperation
, 1, 2, 1, h
- 3, &cdelta
);
60 color
.red
= color
.green
= color
.blue
= 0;
61 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 40;
62 if (bevel_type
== RBEV_RAISED2
|| bevel_type
== RBEV_RAISED3
) {
63 ROperateLine(image
, RSubtractOperation
, 0, h
- 2, w
- 3, h
- 2, &cdelta
);
64 RDrawLine(image
, 0, h
- 1, w
- 1, h
- 1, &color
);
66 ROperateLine(image
, RSubtractOperation
, 0, h
- 1, w
- 1, h
- 1, &cdelta
);
70 if (bevel_type
== RBEV_RAISED2
|| bevel_type
== RBEV_RAISED3
) {
71 ROperateLine(image
, RSubtractOperation
, w
- 2, 0, w
- 2, h
- 2, &cdelta
);
72 RDrawLine(image
, w
- 1, 0, w
- 1, h
- 2, &color
);
74 ROperateLine(image
, RSubtractOperation
, w
- 1, 0, w
- 1, h
- 2, &cdelta
);
78 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 40;
79 ROperateLine(image
, RSubtractOperation
, 0, 0, w
- 1, 0, &cdelta
); /* top */
80 ROperateLine(image
, RSubtractOperation
, 0, 1, 0, h
- 1, &cdelta
); /* left */
81 cdelta
.red
= cdelta
.green
= cdelta
.blue
= 80;
82 ROperateLine(image
, RAddOperation
, 0, h
- 1, w
- 1, h
- 1, &cdelta
); /* bottom */
83 ROperateLine(image
, RAddOperation
, w
- 1, 0, w
- 1, h
- 2, &cdelta
); /* right */
87 void RFillImage(RImage
* image
, const RColor
* color
)
89 unsigned char *d
= image
->data
;
93 if (image
->format
== RRGBAFormat
) {
94 for (i
= 0; i
< image
->width
; i
++) {
100 lineSize
= image
->width
* 4;
101 for (i
= 1; i
< image
->height
; i
++, d
+= lineSize
) {
102 memcpy(d
, image
->data
, lineSize
);
105 for (i
= 0; i
< image
->width
; i
++) {
110 lineSize
= image
->width
* 3;
111 for (i
= 1; i
< image
->height
; i
++, d
+= lineSize
) {
112 memcpy(d
, image
->data
, lineSize
);
117 void RClearImage(RImage
* image
, const RColor
* color
)
119 unsigned char *d
= image
->data
;
123 if (color
->alpha
== 255) {
124 if (image
->format
== RRGBAFormat
) {
125 for (i
= 0; i
< image
->width
; i
++) {
131 lineSize
= image
->width
* 4;
132 for (i
= 1; i
< image
->height
; i
++, d
+= lineSize
) {
133 memcpy(d
, image
->data
, lineSize
);
136 for (i
= 0; i
< image
->width
; i
++) {
141 lineSize
= image
->width
* 3;
142 for (i
= 1; i
< image
->height
; i
++, d
+= lineSize
) {
143 memcpy(d
, image
->data
, lineSize
);
147 int bytes
= image
->width
* image
->height
;
148 int alpha
, nalpha
, r
, g
, b
, s
;
150 alpha
= color
->alpha
;
151 r
= color
->red
* alpha
;
152 g
= color
->green
* alpha
;
153 b
= color
->blue
* alpha
;
154 nalpha
= 255 - alpha
;
156 s
= (image
->format
== RRGBAFormat
) ? 4 : 3;
158 for (i
= 0; i
< bytes
; i
++, d
+= s
) {
159 d
[0] = (((int)d
[0] * nalpha
) + r
)/256;
160 d
[1] = (((int)d
[1] * nalpha
) + g
)/256;
161 d
[2] = (((int)d
[2] * nalpha
) + b
)/256;
166 static inline unsigned char clip(int c
)
170 return (unsigned char)c
;
173 void RLightImage(RImage
*image
, const RColor
*color
)
175 unsigned char *d
= image
->data
;
177 int alpha
, r
, g
, b
, s
;
179 s
= (image
->format
== RRGBAFormat
) ? 4 : 3;
180 dd
= d
+ s
*image
->width
*image
->height
;
186 alpha
= color
->alpha
;
188 if (r
== 0 && g
== 0 && b
== 0) {
189 for (; d
< dd
; d
+= s
) {
190 d
[0] = clip(((int)d
[0] * alpha
)/128);
191 d
[1] = clip(((int)d
[1] * alpha
)/128);
192 d
[2] = clip(((int)d
[2] * alpha
)/128);
195 for (; d
< dd
; d
+= s
) {
196 d
[0] = clip((((int)d
[0] * alpha
) + r
)/128);
197 d
[1] = clip((((int)d
[1] * alpha
) + g
)/128);
198 d
[2] = clip((((int)d
[2] * alpha
) + b
)/128);
203 const char *RMessageForError(int errorCode
)
207 return _("no error");
210 return _("could not open file");
213 return _("error reading from file");
216 return _("error writing to file");
219 return _("out of memory");
222 return _("out of color cells");
224 case RERR_BADIMAGEFILE
:
225 return _("invalid or corrupted image file");
228 return _("image format is not supported");
231 return _("file does not contain requested image index");
233 case RERR_BADVISUALID
:
234 return _("request for an invalid Visual ID");
236 case RERR_STDCMAPFAIL
:
237 return _("failed to create X standard colormap");
240 return _("internal X error");
244 return _("internal error");
250 * Setup internationalization on startup
252 * For historical reason, the WRaster library does not have a function that
253 * user is supposed to call to initialise the library. Because we need to do
254 * some stuff now, we rely on the compiler attribute to tell this function
255 * has to be called automatically when library is loaded.
257 void WLIB_CONSTRUCTOR(RStartup
) (void)
259 const char *locale_path
;
261 locale_path
= getenv("NLSPATH");
262 if (locale_path
== NULL
)
263 locale_path
= LOCALEDIR
;
265 bindtextdomain("WRaster", locale_path
);
270 * cleaning third-party libs at shutdown
278 r_destroy_conversion_tables();