]> Dogcows Code - chaz/openbox/blob - render/gradient.c
80 cols everywhere
[chaz/openbox] / render / gradient.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3 gradient.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
6 Copyright (c) 2003 Derek Foreman
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 See the COPYING file for a copy of the GNU General Public License.
19 */
20
21 #include "render.h"
22 #include "gradient.h"
23 #include "color.h"
24 #include <glib.h>
25
26 static void highlight(RrSurface *s, RrPixel32 *x, RrPixel32 *y,
27 gboolean raised);
28 static void gradient_parentrelative(RrAppearance *a, gint w, gint h);
29 static void gradient_solid(RrAppearance *l, gint w, gint h);
30 static void gradient_splitvertical(RrAppearance *a, gint w, gint h);
31 static void gradient_vertical(RrSurface *sf, gint w, gint h);
32 static void gradient_horizontal(RrSurface *sf, gint w, gint h);
33 static void gradient_mirrorhorizontal(RrSurface *sf, gint w, gint h);
34 static void gradient_diagonal(RrSurface *sf, gint w, gint h);
35 static void gradient_crossdiagonal(RrSurface *sf, gint w, gint h);
36 static void gradient_pyramid(RrSurface *sf, gint inw, gint inh);
37
38 void RrRender(RrAppearance *a, gint w, gint h)
39 {
40 RrPixel32 *data = a->surface.pixel_data;
41 RrPixel32 current;
42 guint r,g,b;
43 gint off, x;
44
45 switch (a->surface.grad) {
46 case RR_SURFACE_PARENTREL:
47 gradient_parentrelative(a, w, h);
48 break;
49 case RR_SURFACE_SOLID:
50 gradient_solid(a, w, h);
51 break;
52 case RR_SURFACE_SPLIT_VERTICAL:
53 gradient_splitvertical(a, w, h);
54 break;
55 case RR_SURFACE_VERTICAL:
56 gradient_vertical(&a->surface, w, h);
57 break;
58 case RR_SURFACE_HORIZONTAL:
59 gradient_horizontal(&a->surface, w, h);
60 break;
61 case RR_SURFACE_MIRROR_HORIZONTAL:
62 gradient_mirrorhorizontal(&a->surface, w, h);
63 break;
64 case RR_SURFACE_DIAGONAL:
65 gradient_diagonal(&a->surface, w, h);
66 break;
67 case RR_SURFACE_CROSS_DIAGONAL:
68 gradient_crossdiagonal(&a->surface, w, h);
69 break;
70 case RR_SURFACE_PYRAMID:
71 gradient_pyramid(&a->surface, w, h);
72 break;
73 default:
74 g_assert_not_reached(); /* unhandled gradient */
75 return;
76 }
77
78 if (a->surface.interlaced) {
79 gint i;
80 RrPixel32 *p;
81
82 r = a->surface.interlace_color->r;
83 g = a->surface.interlace_color->g;
84 b = a->surface.interlace_color->b;
85 current = (r << RrDefaultRedOffset)
86 + (g << RrDefaultGreenOffset)
87 + (b << RrDefaultBlueOffset);
88 p = data;
89 for (i = 0; i < h; i += 2, p += w)
90 for (x = 0; x < w; ++x, ++p)
91 *p = current;
92 }
93
94 if (a->surface.relief == RR_RELIEF_FLAT && a->surface.border) {
95 r = a->surface.border_color->r;
96 g = a->surface.border_color->g;
97 b = a->surface.border_color->b;
98 current = (r << RrDefaultRedOffset)
99 + (g << RrDefaultGreenOffset)
100 + (b << RrDefaultBlueOffset);
101 for (off = 0, x = 0; x < w; ++x, off++) {
102 *(data + off) = current;
103 *(data + off + ((h-1) * w)) = current;
104 }
105 for (off = 0, x = 0; x < h; ++x, off++) {
106 *(data + (off * w)) = current;
107 *(data + (off * w) + w - 1) = current;
108 }
109 }
110
111 if (a->surface.relief != RR_RELIEF_FLAT) {
112 if (a->surface.bevel == RR_BEVEL_1) {
113 for (off = 1, x = 1; x < w - 1; ++x, off++)
114 highlight(&a->surface, data + off,
115 data + off + (h-1) * w,
116 a->surface.relief==RR_RELIEF_RAISED);
117 for (off = 0, x = 0; x < h; ++x, off++)
118 highlight(&a->surface, data + off * w,
119 data + off * w + w - 1,
120 a->surface.relief==RR_RELIEF_RAISED);
121 }
122
123 if (a->surface.bevel == RR_BEVEL_2) {
124 for (off = 2, x = 2; x < w - 2; ++x, off++)
125 highlight(&a->surface, data + off + w,
126 data + off + (h-2) * w,
127 a->surface.relief==RR_RELIEF_RAISED);
128 for (off = 1, x = 1; x < h-1; ++x, off++)
129 highlight(&a->surface, data + off * w + 1,
130 data + off * w + w - 2,
131 a->surface.relief==RR_RELIEF_RAISED);
132 }
133 }
134 }
135
136 static void highlight(RrSurface *s, RrPixel32 *x, RrPixel32 *y, gboolean raised)
137 {
138 gint r, g, b;
139
140 RrPixel32 *up, *down;
141 if (raised) {
142 up = x;
143 down = y;
144 } else {
145 up = y;
146 down = x;
147 }
148
149 r = (*up >> RrDefaultRedOffset) & 0xFF;
150 r += (r * s->bevel_light_adjust) >> 8;
151 g = (*up >> RrDefaultGreenOffset) & 0xFF;
152 g += (g * s->bevel_light_adjust) >> 8;
153 b = (*up >> RrDefaultBlueOffset) & 0xFF;
154 b += (b * s->bevel_light_adjust) >> 8;
155 if (r > 0xFF) r = 0xFF;
156 if (g > 0xFF) g = 0xFF;
157 if (b > 0xFF) b = 0xFF;
158 *up = (r << RrDefaultRedOffset) + (g << RrDefaultGreenOffset)
159 + (b << RrDefaultBlueOffset);
160
161 r = (*down >> RrDefaultRedOffset) & 0xFF;
162 r -= (r * s->bevel_dark_adjust) >> 8;
163 g = (*down >> RrDefaultGreenOffset) & 0xFF;
164 g -= (g * s->bevel_dark_adjust) >> 8;
165 b = (*down >> RrDefaultBlueOffset) & 0xFF;
166 b -= (b * s->bevel_dark_adjust) >> 8;
167 *down = (r << RrDefaultRedOffset) + (g << RrDefaultGreenOffset)
168 + (b << RrDefaultBlueOffset);
169 }
170
171 static void create_bevel_colors(RrAppearance *l)
172 {
173 gint r, g, b;
174
175 /* light color */
176 r = l->surface.primary->r;
177 r += (r * l->surface.bevel_light_adjust) >> 8;
178 g = l->surface.primary->g;
179 g += (g * l->surface.bevel_light_adjust) >> 8;
180 b = l->surface.primary->b;
181 b += (b * l->surface.bevel_light_adjust) >> 8;
182 if (r > 0xFF) r = 0xFF;
183 if (g > 0xFF) g = 0xFF;
184 if (b > 0xFF) b = 0xFF;
185 g_assert(!l->surface.bevel_light);
186 l->surface.bevel_light = RrColorNew(l->inst, r, g, b);
187
188 /* dark color */
189 r = l->surface.primary->r;
190 r -= (r * l->surface.bevel_dark_adjust) >> 8;
191 g = l->surface.primary->g;
192 g -= (g * l->surface.bevel_dark_adjust) >> 8;
193 b = l->surface.primary->b;
194 b -= (b * l->surface.bevel_dark_adjust) >> 8;
195 g_assert(!l->surface.bevel_dark);
196 l->surface.bevel_dark = RrColorNew(l->inst, r, g, b);
197 }
198
199 static void gradient_parentrelative(RrAppearance *a, gint w, gint h)
200 {
201 RrPixel32 *source, *dest;
202 gint sw, sh, partial_w, partial_h, i;
203
204 g_assert (a->surface.parent);
205 g_assert (a->surface.parent->w);
206
207 sw = a->surface.parent->w;
208 sh = a->surface.parent->h;
209
210 /* This is a little hack. When a texture is parentrelative, and the same
211 area as the parent, and has a bevel, it will draw its bevel on top
212 of the parent's, amplifying it. So instead, rerender the child with
213 the parent's settings, but the child's bevel and interlace */
214 if (a->surface.relief != RR_RELIEF_FLAT &&
215 (a->surface.parent->surface.relief != RR_RELIEF_FLAT ||
216 a->surface.parent->surface.border) &&
217 !a->surface.parentx && !a->surface.parenty &&
218 sw == w && sh == h)
219 {
220 RrSurface old = a->surface;
221 a->surface = a->surface.parent->surface;
222
223 /* turn these off for the parent */
224 a->surface.relief = RR_RELIEF_FLAT;
225 a->surface.border = FALSE;
226
227 a->surface.pixel_data = old.pixel_data;
228
229 RrRender(a, w, h);
230 a->surface = old;
231 } else {
232 source = (a->surface.parent->surface.pixel_data +
233 a->surface.parentx + sw * a->surface.parenty);
234 dest = a->surface.pixel_data;
235
236 if (a->surface.parentx + w > sw) {
237 partial_w = sw - a->surface.parentx;
238 } else partial_w = w;
239
240 if (a->surface.parenty + h > sh) {
241 partial_h = sh - a->surface.parenty;
242 } else partial_h = h;
243
244 for (i = 0; i < partial_h; i++, source += sw, dest += w) {
245 memcpy(dest, source, partial_w * sizeof(RrPixel32));
246 }
247 }
248 }
249
250 static void gradient_solid(RrAppearance *l, gint w, gint h)
251 {
252 gint i;
253 RrPixel32 pix;
254 RrPixel32 *data = l->surface.pixel_data;
255 RrSurface *sp = &l->surface;
256 gint left = 0, top = 0, right = w - 1, bottom = h - 1;
257
258 pix = (sp->primary->r << RrDefaultRedOffset)
259 + (sp->primary->g << RrDefaultGreenOffset)
260 + (sp->primary->b << RrDefaultBlueOffset);
261
262 for (i = 0; i < w * h; i++)
263 *data++ = pix;
264
265 if (sp->interlaced)
266 return;
267
268 XFillRectangle(RrDisplay(l->inst), l->pixmap, RrColorGC(sp->primary),
269 0, 0, w, h);
270
271 switch (sp->relief) {
272 case RR_RELIEF_RAISED:
273 if (!sp->bevel_dark)
274 create_bevel_colors(l);
275
276 switch (sp->bevel) {
277 case RR_BEVEL_1:
278 XDrawLine(RrDisplay(l->inst), l->pixmap, RrColorGC(sp->bevel_dark),
279 left, bottom, right, bottom);
280 XDrawLine(RrDisplay(l->inst), l->pixmap, RrColorGC(sp->bevel_dark),
281 right, bottom, right, top);
282
283 XDrawLine(RrDisplay(l->inst), l->pixmap,RrColorGC(sp->bevel_light),
284 left, top, right, top);
285 XDrawLine(RrDisplay(l->inst), l->pixmap,RrColorGC(sp->bevel_light),
286 left, bottom, left, top);
287 break;
288 case RR_BEVEL_2:
289 XDrawLine(RrDisplay(l->inst), l->pixmap, RrColorGC(sp->bevel_dark),
290 left + 2, bottom - 1, right - 2, bottom - 1);
291 XDrawLine(RrDisplay(l->inst), l->pixmap, RrColorGC(sp->bevel_dark),
292 right - 1, bottom - 1, right - 1, top + 1);
293
294 XDrawLine(RrDisplay(l->inst), l->pixmap,RrColorGC(sp->bevel_light),
295 left + 2, top + 1, right - 2, top + 1);
296 XDrawLine(RrDisplay(l->inst), l->pixmap,RrColorGC(sp->bevel_light),
297 left + 1, bottom - 1, left + 1, top + 1);
298 break;
299 default:
300 g_assert_not_reached(); /* unhandled BevelType */
301 }
302 break;
303 case RR_RELIEF_SUNKEN:
304 if (!sp->bevel_dark)
305 create_bevel_colors(l);
306
307 switch (sp->bevel) {
308 case RR_BEVEL_1:
309 XDrawLine(RrDisplay(l->inst), l->pixmap,RrColorGC(sp->bevel_light),
310 left, bottom, right, bottom);
311 XDrawLine(RrDisplay(l->inst), l->pixmap,RrColorGC(sp->bevel_light),
312 right, bottom, right, top);
313
314 XDrawLine(RrDisplay(l->inst), l->pixmap, RrColorGC(sp->bevel_dark),
315 left, top, right, top);
316 XDrawLine(RrDisplay(l->inst), l->pixmap, RrColorGC(sp->bevel_dark),
317 left, bottom, left, top);
318 break;
319 case RR_BEVEL_2:
320 XDrawLine(RrDisplay(l->inst), l->pixmap,RrColorGC(sp->bevel_light),
321 left + 2, bottom - 1, right - 2, bottom - 1);
322 XDrawLine(RrDisplay(l->inst), l->pixmap,RrColorGC(sp->bevel_light),
323 right - 1, bottom - 1, right - 1, top + 1);
324
325 XDrawLine(RrDisplay(l->inst), l->pixmap, RrColorGC(sp->bevel_dark),
326 left + 2, top + 1, right - 2, top + 1);
327 XDrawLine(RrDisplay(l->inst), l->pixmap, RrColorGC(sp->bevel_dark),
328 left + 1, bottom - 1, left + 1, top + 1);
329 break;
330 default:
331 g_assert_not_reached(); /* unhandled BevelType */
332 }
333 break;
334 case RR_RELIEF_FLAT:
335 if (sp->border) {
336 XDrawRectangle(RrDisplay(l->inst), l->pixmap,
337 RrColorGC(sp->border_color),
338 left, top, right, bottom);
339 }
340 break;
341 default:
342 g_assert_not_reached(); /* unhandled ReliefType */
343 }
344 }
345
346 /* * * * * * * * * * * * * * GRADIENT MAGIC WOOT * * * * * * * * * * * * * * */
347
348 #define VARS(x) \
349 guint color##x[3]; \
350 gint len##x, cdelta##x[3], error##x[3] = { 0, 0, 0 }, inc##x[3]; \
351 gboolean bigslope##x[3] /* color slope > 1 */
352
353 #define SETUP(x, from, to, w) \
354 len##x = w; \
355 \
356 color##x[0] = from->r; \
357 color##x[1] = from->g; \
358 color##x[2] = from->b; \
359 \
360 cdelta##x[0] = to->r - from->r; \
361 cdelta##x[1] = to->g - from->g; \
362 cdelta##x[2] = to->b - from->b; \
363 \
364 if (cdelta##x[0] < 0) { \
365 cdelta##x[0] = -cdelta##x[0]; \
366 inc##x[0] = -1; \
367 } else \
368 inc##x[0] = 1; \
369 if (cdelta##x[1] < 0) { \
370 cdelta##x[1] = -cdelta##x[1]; \
371 inc##x[1] = -1; \
372 } else \
373 inc##x[1] = 1; \
374 if (cdelta##x[2] < 0) { \
375 cdelta##x[2] = -cdelta##x[2]; \
376 inc##x[2] = -1; \
377 } else \
378 inc##x[2] = 1; \
379 bigslope##x[0] = cdelta##x[0] > w;\
380 bigslope##x[1] = cdelta##x[1] > w;\
381 bigslope##x[2] = cdelta##x[2] > w
382
383 #define COLOR_RR(x, c) \
384 c->r = color##x[0]; \
385 c->g = color##x[1]; \
386 c->b = color##x[2]
387
388 #define COLOR(x) \
389 ((color##x[0] << RrDefaultRedOffset) + \
390 (color##x[1] << RrDefaultGreenOffset) + \
391 (color##x[2] << RrDefaultBlueOffset))
392
393 #define INCREMENT(x, i) \
394 (inc##x[i])
395
396 #define NEXT(x) \
397 { \
398 gint i; \
399 for (i = 2; i >= 0; --i) { \
400 if (!cdelta##x[i]) continue; \
401 \
402 if (!bigslope##x[i]) { \
403 /* Y (color) is dependant on X */ \
404 error##x[i] += cdelta##x[i]; \
405 if ((error##x[i] << 1) >= len##x) { \
406 color##x[i] += INCREMENT(x, i); \
407 error##x[i] -= len##x; \
408 } \
409 } else { \
410 /* X is dependant on Y (color) */ \
411 while (1) { \
412 color##x[i] += INCREMENT(x, i); \
413 error##x[i] += len##x; \
414 if ((error##x[i] << 1) >= cdelta##x[i]) { \
415 error##x[i] -= cdelta##x[i]; \
416 break; \
417 } \
418 } \
419 } \
420 } \
421 }
422
423 static void gradient_splitvertical(RrAppearance *a, gint w, gint h)
424 {
425 gint x, y1, y2, y3;
426 RrSurface *sf = &a->surface;
427 RrPixel32 *data = sf->pixel_data;
428 RrPixel32 current;
429 gint y1sz, y2sz, y3sz;
430
431 VARS(y1);
432 VARS(y2);
433 VARS(y3);
434
435 /* if h <= 5, then a 0 or 1px middle gradient.
436 if h > 5, then always a 1px middle gradient.
437 */
438 if (h <= 5) {
439 y1sz = MAX(h/2, 0);
440 y2sz = (h < 3 ? 0 : h % 2);
441 y3sz = MAX(h/2, 1);
442 }
443 else {
444 y1sz = h/2 - (1 - (h % 2));
445 y2sz = 1;
446 y3sz = h/2;
447 }
448
449 SETUP(y1, sf->split_primary, sf->primary, y1sz);
450 if (y2sz) {
451 /* setup to get the colors _in between_ these other 2 */
452 SETUP(y2, sf->primary, sf->secondary, y2sz + 2);
453 NEXT(y2); /* skip the first one, its the same as the last of y1 */
454 }
455 SETUP(y3, sf->secondary, sf->split_secondary, y3sz);
456
457 for (y1 = y1sz; y1 > 0; --y1) {
458 current = COLOR(y1);
459 for (x = w - 1; x >= 0; --x)
460 *(data++) = current;
461
462 NEXT(y1);
463 }
464
465 for (y2 = y2sz; y2 > 0; --y2) {
466 current = COLOR(y2);
467 for (x = w - 1; x >= 0; --x)
468 *(data++) = current;
469
470 NEXT(y2);
471 }
472
473 for (y3 = y3sz; y3 > 0; --y3) {
474 current = COLOR(y3);
475 for (x = w - 1; x >= 0; --x)
476 *(data++) = current;
477
478 NEXT(y3);
479 }
480 }
481
482 static void gradient_horizontal(RrSurface *sf, gint w, gint h)
483 {
484 gint x, y;
485 RrPixel32 *data = sf->pixel_data, *datav;
486 RrPixel32 current;
487
488 VARS(x);
489 SETUP(x, sf->primary, sf->secondary, w);
490
491 for (x = w - 1; x > 0; --x) { /* 0 -> w-1 */
492 current = COLOR(x);
493 datav = data;
494 for (y = h - 1; y >= 0; --y) { /* 0 -> h */
495 *datav = current;
496 datav += w;
497 }
498 ++data;
499
500 NEXT(x);
501 }
502 current = COLOR(x);
503 for (y = h - 1; y >= 0; --y) /* 0 -> h */
504 *(data + y * w) = current;
505 }
506
507 static void gradient_mirrorhorizontal(RrSurface *sf, gint w, gint h)
508 {
509 gint x, y;
510 RrPixel32 *data = sf->pixel_data, *datav;
511 RrPixel32 current;
512
513 VARS(x);
514 SETUP(x, sf->primary, sf->secondary, w/2);
515
516 if (w > 1) {
517 for (x = w - 1; x > w/2-1; --x) { /* 0 -> w-1 */
518 current = COLOR(x);
519 datav = data;
520 for (y = h - 1; y >= 0; --y) { /* 0 -> h */
521 *datav = current;
522 datav += w;
523 }
524 ++data;
525
526 NEXT(x);
527 }
528 SETUP(x, sf->secondary, sf->primary, w/2);
529 for (x = w/2 - 1; x > 0; --x) { /* 0 -> w-1 */
530 current = COLOR(x);
531 datav = data;
532 for (y = h - 1; y >= 0; --y) { /* 0 -> h */
533 *datav = current;
534 datav += w;
535 }
536 ++data;
537
538 NEXT(x);
539 }
540 }
541 current = COLOR(x);
542 for (y = h - 1; y >= 0; --y) /* 0 -> h */
543 *(data + y * w) = current;
544 }
545
546 static void gradient_vertical(RrSurface *sf, gint w, gint h)
547 {
548 gint x, y;
549 RrPixel32 *data = sf->pixel_data;
550 RrPixel32 current;
551
552 VARS(y);
553 SETUP(y, sf->primary, sf->secondary, h);
554
555 for (y = h - 1; y > 0; --y) { /* 0 -> h-1 */
556 current = COLOR(y);
557 for (x = w - 1; x >= 0; --x) /* 0 -> w */
558 *(data++) = current;
559
560 NEXT(y);
561 }
562 current = COLOR(y);
563 for (x = w - 1; x >= 0; --x) /* 0 -> w */
564 *(data++) = current;
565 }
566
567
568 static void gradient_diagonal(RrSurface *sf, gint w, gint h)
569 {
570 gint x, y;
571 RrPixel32 *data = sf->pixel_data;
572 RrColor left, right;
573 RrColor extracorner;
574
575 VARS(lefty);
576 VARS(righty);
577 VARS(x);
578
579 extracorner.r = (sf->primary->r + sf->secondary->r) / 2;
580 extracorner.g = (sf->primary->g + sf->secondary->g) / 2;
581 extracorner.b = (sf->primary->b + sf->secondary->b) / 2;
582
583 SETUP(lefty, sf->primary, (&extracorner), h);
584 SETUP(righty, (&extracorner), sf->secondary, h);
585
586 for (y = h - 1; y > 0; --y) { /* 0 -> h-1 */
587 COLOR_RR(lefty, (&left));
588 COLOR_RR(righty, (&right));
589
590 SETUP(x, (&left), (&right), w);
591
592 for (x = w - 1; x > 0; --x) { /* 0 -> w-1 */
593 *(data++) = COLOR(x);
594
595 NEXT(x);
596 }
597 *(data++) = COLOR(x);
598
599 NEXT(lefty);
600 NEXT(righty);
601 }
602 COLOR_RR(lefty, (&left));
603 COLOR_RR(righty, (&right));
604
605 SETUP(x, (&left), (&right), w);
606
607 for (x = w - 1; x > 0; --x) { /* 0 -> w-1 */
608 *(data++) = COLOR(x);
609
610 NEXT(x);
611 }
612 *data = COLOR(x);
613 }
614
615 static void gradient_crossdiagonal(RrSurface *sf, gint w, gint h)
616 {
617 gint x, y;
618 RrPixel32 *data = sf->pixel_data;
619 RrColor left, right;
620 RrColor extracorner;
621
622 VARS(lefty);
623 VARS(righty);
624 VARS(x);
625
626 extracorner.r = (sf->primary->r + sf->secondary->r) / 2;
627 extracorner.g = (sf->primary->g + sf->secondary->g) / 2;
628 extracorner.b = (sf->primary->b + sf->secondary->b) / 2;
629
630 SETUP(lefty, (&extracorner), sf->secondary, h);
631 SETUP(righty, sf->primary, (&extracorner), h);
632
633 for (y = h - 1; y > 0; --y) { /* 0 -> h-1 */
634 COLOR_RR(lefty, (&left));
635 COLOR_RR(righty, (&right));
636
637 SETUP(x, (&left), (&right), w);
638
639 for (x = w - 1; x > 0; --x) { /* 0 -> w-1 */
640 *(data++) = COLOR(x);
641
642 NEXT(x);
643 }
644 *(data++) = COLOR(x);
645
646 NEXT(lefty);
647 NEXT(righty);
648 }
649 COLOR_RR(lefty, (&left));
650 COLOR_RR(righty, (&right));
651
652 SETUP(x, (&left), (&right), w);
653
654 for (x = w - 1; x > 0; --x) { /* 0 -> w-1 */
655 *(data++) = COLOR(x);
656
657 NEXT(x);
658 }
659 *data = COLOR(x);
660 }
661
662 static void gradient_pyramid(RrSurface *sf, gint inw, gint inh)
663 {
664 gint x, y, w = (inw >> 1) + 1, h = (inh >> 1) + 1;
665 RrPixel32 *data = sf->pixel_data;
666 RrPixel32 *end = data + inw*inh - 1;
667 RrPixel32 current;
668 RrColor left, right;
669 RrColor extracorner;
670
671 VARS(lefty);
672 VARS(righty);
673 VARS(x);
674
675 extracorner.r = (sf->primary->r + sf->secondary->r) / 2;
676 extracorner.g = (sf->primary->g + sf->secondary->g) / 2;
677 extracorner.b = (sf->primary->b + sf->secondary->b) / 2;
678
679 SETUP(lefty, (&extracorner), sf->secondary, h);
680 SETUP(righty, sf->primary, (&extracorner), h);
681
682 for (y = h - 1; y > 0; --y) { /* 0 -> h-1 */
683 COLOR_RR(lefty, (&left));
684 COLOR_RR(righty, (&right));
685
686 SETUP(x, (&left), (&right), w);
687
688 for (x = w - 1; x > 0; --x) { /* 0 -> w-1 */
689 current = COLOR(x);
690 *(data+x) = current;
691 *(data+inw-x) = current;
692 *(end-x) = current;
693 *(end-(inw-x)) = current;
694
695 NEXT(x);
696 }
697 current = COLOR(x);
698 *(data+x) = current;
699 *(data+inw-x) = current;
700 *(end-x) = current;
701 *(end-(inw-x)) = current;
702
703 data+=inw;
704 end-=inw;
705
706 NEXT(lefty);
707 NEXT(righty);
708 }
709 COLOR_RR(lefty, (&left));
710 COLOR_RR(righty, (&right));
711
712 SETUP(x, (&left), (&right), w);
713
714 for (x = w - 1; x > 0; --x) { /* 0 -> w-1 */
715 current = COLOR(x);
716 *(data+x) = current;
717 *(data+inw-x) = current;
718 *(end-x) = current;
719 *(end-(inw-x)) = current;
720
721 NEXT(x);
722 }
723 current = COLOR(x);
724 *(data+x) = current;
725 *(data+inw-x) = current;
726 *(end-x) = current;
727 *(end-(inw-x)) = current;
728 }
729
This page took 0.074433 seconds and 4 git commands to generate.