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.
29 void RBevelImage(RImage * image, int bevel_type)
35 if (image->width < 3 || image->height < 3)
40 if (bevel_type > 0) { /* raised */
43 cdelta.red = cdelta.green = cdelta.blue = 80;
44 ROperateLine(image, RAddOperation, 0, 0, w - 1, 0, &cdelta);
45 if (bevel_type == RBEV_RAISED3 && w > 3)
46 ROperateLine(image, RAddOperation, 1, 1, w - 3, 1, &cdelta);
49 ROperateLine(image, RAddOperation, 0, 1, 0, h - 1, &cdelta);
50 if (bevel_type == RBEV_RAISED3 && h > 3)
51 ROperateLine(image, RAddOperation, 1, 2, 1, h - 3, &cdelta);
55 color.red = color.green = color.blue = 0;
56 cdelta.red = cdelta.green = cdelta.blue = 40;
57 if (bevel_type == RBEV_RAISED2 || bevel_type == RBEV_RAISED3) {
58 ROperateLine(image, RSubtractOperation, 0, h - 2, w - 3, h - 2, &cdelta);
59 RDrawLine(image, 0, h - 1, w - 1, h - 1, &color);
61 ROperateLine(image, RSubtractOperation, 0, h - 1, w - 1, h - 1, &cdelta);
65 if (bevel_type == RBEV_RAISED2 || bevel_type == RBEV_RAISED3) {
66 ROperateLine(image, RSubtractOperation, w - 2, 0, w - 2, h - 2, &cdelta);
67 RDrawLine(image, w - 1, 0, w - 1, h - 2, &color);
69 ROperateLine(image, RSubtractOperation, w - 1, 0, w - 1, h - 2, &cdelta);
73 cdelta.red = cdelta.green = cdelta.blue = 40;
74 ROperateLine(image, RSubtractOperation, 0, 0, w - 1, 0, &cdelta); /* top */
75 ROperateLine(image, RSubtractOperation, 0, 1, 0, h - 1, &cdelta); /* left */
76 cdelta.red = cdelta.green = cdelta.blue = 80;
77 ROperateLine(image, RAddOperation, 0, h - 1, w - 1, h - 1, &cdelta); /* bottom */
78 ROperateLine(image, RAddOperation, w - 1, 0, w - 1, h - 2, &cdelta); /* right */
82 void RFillImage(RImage * image, RColor * color)
84 unsigned char *d = image->data;
88 if (image->format == RRGBAFormat) {
89 for (i = 0; i < image->width; i++) {
95 lineSize = image->width * 4;
96 for (i = 1; i < image->height; i++, d += lineSize) {
97 memcpy(d, image->data, lineSize);
100 for (i = 0; i < image->width; i++) {
105 lineSize = image->width * 3;
106 for (i = 1; i < image->height; i++, d += lineSize) {
107 memcpy(d, image->data, lineSize);
112 void RClearImage(RImage * image, RColor * color)
114 unsigned char *d = image->data;
118 if (color->alpha == 255) {
119 if (image->format == RRGBAFormat) {
120 for (i = 0; i < image->width; i++) {
126 lineSize = image->width * 4;
127 for (i = 1; i < image->height; i++, d += lineSize) {
128 memcpy(d, image->data, lineSize);
131 for (i = 0; i < image->width; i++) {
136 lineSize = image->width * 3;
137 for (i = 1; i < image->height; i++, d += lineSize) {
138 memcpy(d, image->data, lineSize);
142 int bytes = image->width * image->height;
143 int alpha, nalpha, r, g, b;
145 alpha = color->alpha;
146 r = color->red * alpha;
147 g = color->green * alpha;
148 b = color->blue * alpha;
149 nalpha = 255 - alpha;
151 for (i = 0; i < bytes; i++) {
152 *d = (((int)*d * nalpha) + r) / 256;
154 *d = (((int)*d * nalpha) + g) / 256;
156 *d = (((int)*d * nalpha) + b) / 256;
158 if (image->format == RRGBAFormat) {
165 const char *RMessageForError(int errorCode)
172 return "could not open file";
175 return "error reading from file";
178 return "error writing to file";
181 return "out of memory";
184 return "out of color cells";
186 case RERR_BADIMAGEFILE:
187 return "invalid or corrupted image file";
190 return "the image format in the file is not supported and can't be loaded";
193 return "image file does not contain requested image index";
195 case RERR_BADVISUALID:
196 return "request for an invalid visual ID";
198 case RERR_STDCMAPFAIL:
199 return "failed to create standard colormap";
202 return "internal X error";
206 return "internal error";