6 static void highlight(RrPixel32
*x
, RrPixel32
*y
, gboolean raised
);
7 static void gradient_solid(RrAppearance
*l
, int w
, int h
);
8 static void gradient_vertical(RrSurface
*sf
, int w
, int h
);
9 static void gradient_horizontal(RrSurface
*sf
, int w
, int h
);
10 static void gradient_diagonal(RrSurface
*sf
, int w
, int h
);
11 static void gradient_crossdiagonal(RrSurface
*sf
, int w
, int h
);
12 static void gradient_pyramid(RrSurface
*sf
, int inw
, int inh
);
14 void RrRender(RrAppearance
*a
, int w
, int h
)
16 RrPixel32
*data
= a
->surface
.pixel_data
;
21 switch (a
->surface
.grad
) {
22 case RR_SURFACE_SOLID
:
23 gradient_solid(a
, w
, h
);
25 case RR_SURFACE_VERTICAL
:
26 gradient_vertical(&a
->surface
, w
, h
);
28 case RR_SURFACE_HORIZONTAL
:
29 gradient_horizontal(&a
->surface
, w
, h
);
31 case RR_SURFACE_DIAGONAL
:
32 gradient_diagonal(&a
->surface
, w
, h
);
34 case RR_SURFACE_CROSS_DIAGONAL
:
35 gradient_crossdiagonal(&a
->surface
, w
, h
);
37 case RR_SURFACE_PYRAMID
:
38 gradient_pyramid(&a
->surface
, w
, h
);
41 g_assert_not_reached(); /* unhandled gradient */
45 if (a
->surface
.relief
== RR_RELIEF_FLAT
&& a
->surface
.border
) {
46 r
= a
->surface
.border_color
->r
;
47 g
= a
->surface
.border_color
->g
;
48 b
= a
->surface
.border_color
->b
;
49 current
= (r
<< RrDefaultRedOffset
)
50 + (g
<< RrDefaultGreenOffset
)
51 + (b
<< RrDefaultBlueOffset
);
52 for (off
= 0, x
= 0; x
< w
; ++x
, off
++) {
53 *(data
+ off
) = current
;
54 *(data
+ off
+ ((h
-1) * w
)) = current
;
56 for (off
= 0, x
= 0; x
< h
; ++x
, off
++) {
57 *(data
+ (off
* w
)) = current
;
58 *(data
+ (off
* w
) + w
- 1) = current
;
62 if (a
->surface
.relief
!= RR_RELIEF_FLAT
) {
63 if (a
->surface
.bevel
== RR_BEVEL_1
) {
64 for (off
= 1, x
= 1; x
< w
- 1; ++x
, off
++)
66 data
+ off
+ (h
-1) * w
,
67 a
->surface
.relief
==RR_RELIEF_RAISED
);
68 for (off
= 0, x
= 0; x
< h
; ++x
, off
++)
69 highlight(data
+ off
* w
,
70 data
+ off
* w
+ w
- 1,
71 a
->surface
.relief
==RR_RELIEF_RAISED
);
74 if (a
->surface
.bevel
== RR_BEVEL_2
) {
75 for (off
= 2, x
= 2; x
< w
- 2; ++x
, off
++)
76 highlight(data
+ off
+ w
,
77 data
+ off
+ (h
-2) * w
,
78 a
->surface
.relief
==RR_RELIEF_RAISED
);
79 for (off
= 1, x
= 1; x
< h
-1; ++x
, off
++)
80 highlight(data
+ off
* w
+ 1,
81 data
+ off
* w
+ w
- 2,
82 a
->surface
.relief
==RR_RELIEF_RAISED
);
86 if (a
->surface
.interlaced
) {
90 r
= a
->surface
.interlace_color
->r
;
91 g
= a
->surface
.interlace_color
->g
;
92 b
= a
->surface
.interlace_color
->b
;
93 current
= (r
<< RrDefaultRedOffset
)
94 + (g
<< RrDefaultGreenOffset
)
95 + (b
<< RrDefaultBlueOffset
);
97 for (i
= 0; i
< h
; i
+= 2, p
+= w
)
98 for (x
= 0; x
< w
; ++x
, ++p
)
104 static void highlight(RrPixel32
*x
, RrPixel32
*y
, gboolean raised
)
108 RrPixel32
*up
, *down
;
116 r
= (*up
>> RrDefaultRedOffset
) & 0xFF;
118 g
= (*up
>> RrDefaultGreenOffset
) & 0xFF;
120 b
= (*up
>> RrDefaultBlueOffset
) & 0xFF;
122 if (r
> 0xFF) r
= 0xFF;
123 if (g
> 0xFF) g
= 0xFF;
124 if (b
> 0xFF) b
= 0xFF;
125 *up
= (r
<< RrDefaultRedOffset
) + (g
<< RrDefaultGreenOffset
)
126 + (b
<< RrDefaultBlueOffset
);
128 r
= (*down
>> RrDefaultRedOffset
) & 0xFF;
129 r
= (r
>> 1) + (r
>> 2);
130 g
= (*down
>> RrDefaultGreenOffset
) & 0xFF;
131 g
= (g
>> 1) + (g
>> 2);
132 b
= (*down
>> RrDefaultBlueOffset
) & 0xFF;
133 b
= (b
>> 1) + (b
>> 2);
134 *down
= (r
<< RrDefaultRedOffset
) + (g
<< RrDefaultGreenOffset
)
135 + (b
<< RrDefaultBlueOffset
);
138 static void create_bevel_colors(RrAppearance
*l
)
143 r
= l
->surface
.primary
->r
;
145 g
= l
->surface
.primary
->g
;
147 b
= l
->surface
.primary
->b
;
149 if (r
> 0xFF) r
= 0xFF;
150 if (g
> 0xFF) g
= 0xFF;
151 if (b
> 0xFF) b
= 0xFF;
152 g_assert(!l
->surface
.bevel_light
);
153 l
->surface
.bevel_light
= RrColorNew(l
->inst
, r
, g
, b
);
156 r
= l
->surface
.primary
->r
;
157 r
= (r
>> 1) + (r
>> 2);
158 g
= l
->surface
.primary
->g
;
159 g
= (g
>> 1) + (g
>> 2);
160 b
= l
->surface
.primary
->b
;
161 b
= (b
>> 1) + (b
>> 2);
162 g_assert(!l
->surface
.bevel_dark
);
163 l
->surface
.bevel_dark
= RrColorNew(l
->inst
, r
, g
, b
);
166 static void gradient_solid(RrAppearance
*l
, int w
, int h
)
170 RrSurface
*sp
= &l
->surface
;
171 int left
= 0, top
= 0, right
= w
- 1, bottom
= h
- 1;
173 pix
= (sp
->primary
->r
<< RrDefaultRedOffset
)
174 + (sp
->primary
->g
<< RrDefaultGreenOffset
)
175 + (sp
->primary
->b
<< RrDefaultBlueOffset
);
177 for (a
= 0; a
< w
; a
++)
178 for (b
= 0; b
< h
; b
++)
179 sp
->pixel_data
[a
+ b
* w
] = pix
;
181 XFillRectangle(RrDisplay(l
->inst
), l
->pixmap
, RrColorGC(sp
->primary
),
184 if (sp
->interlaced
) {
185 for (i
= 0; i
< h
; i
+= 2)
186 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
,
187 RrColorGC(sp
->interlace_color
),
191 switch (sp
->relief
) {
192 case RR_RELIEF_RAISED
:
194 create_bevel_colors(l
);
198 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
, RrColorGC(sp
->bevel_dark
),
199 left
, bottom
, right
, bottom
);
200 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
, RrColorGC(sp
->bevel_dark
),
201 right
, bottom
, right
, top
);
203 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
,RrColorGC(sp
->bevel_light
),
204 left
, top
, right
, top
);
205 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
,RrColorGC(sp
->bevel_light
),
206 left
, bottom
, left
, top
);
209 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
, RrColorGC(sp
->bevel_dark
),
210 left
+ 1, bottom
- 2, right
- 2, bottom
- 2);
211 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
, RrColorGC(sp
->bevel_dark
),
212 right
- 2, bottom
- 2, right
- 2, top
+ 1);
214 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
,RrColorGC(sp
->bevel_light
),
215 left
+ 1, top
+ 1, right
- 2, top
+ 1);
216 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
,RrColorGC(sp
->bevel_light
),
217 left
+ 1, bottom
- 2, left
+ 1, top
+ 1);
220 g_assert_not_reached(); /* unhandled BevelType */
223 case RR_RELIEF_SUNKEN
:
225 create_bevel_colors(l
);
229 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
,RrColorGC(sp
->bevel_light
),
230 left
, bottom
, right
, bottom
);
231 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
,RrColorGC(sp
->bevel_light
),
232 right
, bottom
, right
, top
);
234 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
, RrColorGC(sp
->bevel_dark
),
235 left
, top
, right
, top
);
236 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
, RrColorGC(sp
->bevel_dark
),
237 left
, bottom
, left
, top
);
240 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
,RrColorGC(sp
->bevel_light
),
241 left
+ 1, bottom
- 2, right
- 2, bottom
- 2);
242 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
,RrColorGC(sp
->bevel_light
),
243 right
- 2, bottom
- 2, right
- 2, top
+ 1);
245 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
, RrColorGC(sp
->bevel_dark
),
246 left
+ 1, top
+ 1, right
- 2, top
+ 1);
247 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
, RrColorGC(sp
->bevel_dark
),
248 left
+ 1, bottom
- 2, left
+ 1, top
+ 1);
252 g_assert_not_reached(); /* unhandled BevelType */
257 XDrawRectangle(RrDisplay(l
->inst
), l
->pixmap
,
258 RrColorGC(sp
->border_color
),
259 left
, top
, right
, bottom
);
263 g_assert_not_reached(); /* unhandled ReliefType */
267 /* * * * * * * * * * * * * * GRADIENT MAGIC WOOT * * * * * * * * * * * * * * */
270 unsigned int color##x[3]; \
271 int len##x, cdelta##x[3], error##x[3] = { 0, 0, 0 }, inc##x[3]; \
272 gboolean bigslope##x[3] /* color slope > 1 */
274 #define SETUP(x, from, to, w) \
277 color##x[0] = from->r; \
278 color##x[1] = from->g; \
279 color##x[2] = from->b; \
281 cdelta##x[0] = to->r - from->r; \
282 cdelta##x[1] = to->g - from->g; \
283 cdelta##x[2] = to->b - from->b; \
285 if (cdelta##x[0] < 0) { \
286 cdelta##x[0] = -cdelta##x[0]; \
290 if (cdelta##x[1] < 0) { \
291 cdelta##x[1] = -cdelta##x[1]; \
295 if (cdelta##x[2] < 0) { \
296 cdelta##x[2] = -cdelta##x[2]; \
300 bigslope##x[0] = cdelta##x[0] > w;\
301 bigslope##x[1] = cdelta##x[1] > w;\
302 bigslope##x[2] = cdelta##x[2] > w
304 #define COLOR_RR(x, c) \
305 c->r = color##x[0]; \
306 c->g = color##x[1]; \
310 ((color##x[0] << RrDefaultRedOffset) + \
311 (color##x[1] << RrDefaultGreenOffset) + \
312 (color##x[2] << RrDefaultBlueOffset))
314 #define INCREMENT(x, i) \
320 for (i = 2; i >= 0; --i) { \
321 if (!cdelta##x[i]) continue; \
323 if (!bigslope##x[i]) { \
324 /* Y (color) is dependant on X */ \
325 error##x[i] += cdelta##x[i]; \
326 if ((error##x[i] << 1) >= len##x) { \
327 color##x[i] += INCREMENT(x, i); \
328 error##x[i] -= len##x; \
331 /* X is dependant on Y (color) */ \
333 color##x[i] += INCREMENT(x, i); \
334 error##x[i] += len##x; \
335 if ((error##x[i] << 1) >= cdelta##x[i]) { \
336 error##x[i] -= cdelta##x[i]; \
344 static void gradient_horizontal(RrSurface
*sf
, int w
, int h
)
347 RrPixel32
*data
= sf
->pixel_data
, *datav
;
351 SETUP(x
, sf
->primary
, sf
->secondary
, w
);
353 for (x
= w
- 1; x
> 0; --x
) { /* 0 -> w-1 */
356 for (y
= h
- 1; y
>= 0; --y
) { /* 0 -> h */
365 for (y
= h
- 1; y
>= 0; --y
) /* 0 -> h */
366 *(data
+ y
* w
) = current
;
369 static void gradient_vertical(RrSurface
*sf
, int w
, int h
)
372 RrPixel32
*data
= sf
->pixel_data
;
376 SETUP(y
, sf
->primary
, sf
->secondary
, h
);
378 for (y
= h
- 1; y
> 0; --y
) { /* 0 -> h-1 */
380 for (x
= w
- 1; x
>= 0; --x
) /* 0 -> w */
386 for (x
= w
- 1; x
>= 0; --x
) /* 0 -> w */
391 static void gradient_diagonal(RrSurface
*sf
, int w
, int h
)
394 RrPixel32
*data
= sf
->pixel_data
;
402 extracorner
.r
= (sf
->primary
->r
+ sf
->secondary
->r
) / 2;
403 extracorner
.g
= (sf
->primary
->g
+ sf
->secondary
->g
) / 2;
404 extracorner
.b
= (sf
->primary
->b
+ sf
->secondary
->b
) / 2;
406 SETUP(lefty
, sf
->primary
, (&extracorner
), h
);
407 SETUP(righty
, (&extracorner
), sf
->secondary
, h
);
409 for (y
= h
- 1; y
> 0; --y
) { /* 0 -> h-1 */
410 COLOR_RR(lefty
, (&left
));
411 COLOR_RR(righty
, (&right
));
413 SETUP(x
, (&left
), (&right
), w
);
415 for (x
= w
- 1; x
> 0; --x
) { /* 0 -> w-1 */
416 *(data
++) = COLOR(x
);
420 *(data
++) = COLOR(x
);
425 COLOR_RR(lefty
, (&left
));
426 COLOR_RR(righty
, (&right
));
428 SETUP(x
, (&left
), (&right
), w
);
430 for (x
= w
- 1; x
> 0; --x
) { /* 0 -> w-1 */
431 *(data
++) = COLOR(x
);
438 static void gradient_crossdiagonal(RrSurface
*sf
, int w
, int h
)
441 RrPixel32
*data
= sf
->pixel_data
;
449 extracorner
.r
= (sf
->primary
->r
+ sf
->secondary
->r
) / 2;
450 extracorner
.g
= (sf
->primary
->g
+ sf
->secondary
->g
) / 2;
451 extracorner
.b
= (sf
->primary
->b
+ sf
->secondary
->b
) / 2;
453 SETUP(lefty
, (&extracorner
), sf
->secondary
, h
);
454 SETUP(righty
, sf
->primary
, (&extracorner
), h
);
456 for (y
= h
- 1; y
> 0; --y
) { /* 0 -> h-1 */
457 COLOR_RR(lefty
, (&left
));
458 COLOR_RR(righty
, (&right
));
460 SETUP(x
, (&left
), (&right
), w
);
462 for (x
= w
- 1; x
> 0; --x
) { /* 0 -> w-1 */
463 *(data
++) = COLOR(x
);
467 *(data
++) = COLOR(x
);
472 COLOR_RR(lefty
, (&left
));
473 COLOR_RR(righty
, (&right
));
475 SETUP(x
, (&left
), (&right
), w
);
477 for (x
= w
- 1; x
> 0; --x
) { /* 0 -> w-1 */
478 *(data
++) = COLOR(x
);
485 static void gradient_pyramid(RrSurface
*sf
, int inw
, int inh
)
487 int x
, y
, w
= (inw
>> 1) + 1, h
= (inh
>> 1) + 1;
488 RrPixel32
*data
= sf
->pixel_data
;
489 RrPixel32
*end
= data
+ inw
*inh
- 1;
498 extracorner
.r
= (sf
->primary
->r
+ sf
->secondary
->r
) / 2;
499 extracorner
.g
= (sf
->primary
->g
+ sf
->secondary
->g
) / 2;
500 extracorner
.b
= (sf
->primary
->b
+ sf
->secondary
->b
) / 2;
502 SETUP(lefty
, (&extracorner
), sf
->secondary
, h
);
503 SETUP(righty
, sf
->primary
, (&extracorner
), h
);
505 for (y
= h
- 1; y
> 0; --y
) { /* 0 -> h-1 */
506 COLOR_RR(lefty
, (&left
));
507 COLOR_RR(righty
, (&right
));
509 SETUP(x
, (&left
), (&right
), w
);
511 for (x
= w
- 1; x
> 0; --x
) { /* 0 -> w-1 */
514 *(data
+inw
-x
) = current
;
516 *(end
-(inw
-x
)) = current
;
522 *(data
+inw
-x
) = current
;
524 *(end
-(inw
-x
)) = current
;
532 COLOR_RR(lefty
, (&left
));
533 COLOR_RR(righty
, (&right
));
535 SETUP(x
, (&left
), (&right
), w
);
537 for (x
= w
- 1; x
> 0; --x
) { /* 0 -> w-1 */
540 *(data
+inw
-x
) = current
;
542 *(end
-(inw
-x
)) = current
;
548 *(data
+inw
-x
) = current
;
550 *(end
-(inw
-x
)) = current
;