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