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