1 /* xscreensaver, Copyright (c) 2001, 2003 Jamie Zawinski <jwz@jwz.org>
3 * Permission to use, copy, modify, distribute, and sell this software and its
4 * documentation for any purpose is hereby granted without fee, provided that
5 * the above copyright notice appear in all copies and that both that
6 * copyright notice and this permission notice appear in supporting
7 * documentation. No representations are made about the suitability of this
8 * software for any purpose. It is provided "as is" without express or
12 /* This file contains code for drawing NTSC colorbars.
13 A couple of things use this.
17 #include "resources.h"
18 #include "colorbars.h"
20 static const char * const colors[7][18] = {
21 { "#CCCCCC", "#FFFF00", "#00FFFF", "#00FF00", /* tall bars */
22 "#FF00FF", "#FF0000", "#0000FF", "#000000",
25 "#000000", "#0000FF", "#FF0000", "#FF00FF", /* short rev bars */
26 "#00FF00", "#00FFFF", "#FFFF00", "#CCCCCC",
29 "#000000", 0 /* blank */
31 "#FFFFFF", "#EEEEEE", "#DDDDDD", "#CCCCCC", /* gray ramp */
32 "#BBBBBB", "#AAAAAA", "#999999", "#888888",
33 "#777777", "#666666", "#555555", "#444444",
34 "#333333", "#222222", "#111111", "#000000"
36 "#000000", "#111111", "#222222", "#333333", /* gray rev ramp */
37 "#444444", "#555555", "#666666", "#777777",
38 "#888888", "#999999", "#AAAAAA", "#BBBBBB",
39 "#CCCCCC", "#DDDDDD", "#EEEEEE", "#FFFFFF"
41 "#000000", 0 /* blank */
43 "#FF00FF", "#FF00FF", "#FF00FF", /* blacklevel row */
44 "#FFFFFF", "#FFFFFF", "#FFFFFF",
45 "#0000AD", "#0000AD", "#0000AD",
46 "#131313", "#131313", "#131313",
47 "#000000", "#000000", "#262626",
48 "#000000", "#000000", "#000000"
52 static const int heights[7] = { 63, 10, 1, 5, 5, 1, 15 }; /* percentages */
56 draw_colorbars (Screen *screen, Visual *visual,
57 Drawable drawable, Colormap cmap,
58 int x, int y, int width, int height)
60 Display *dpy = DisplayOfScreen (screen);
65 GC gc = XCreateGC (dpy, drawable, 0, &gcv);
67 if (width <= 0 || height <= 0)
72 XGetGeometry (dpy, drawable,
74 (unsigned int *) &width,
75 (unsigned int *) &height,
79 for (j = 0; j < sizeof(colors) / sizeof(*colors); j++)
84 for (ncols = 0; ncols < sizeof(*colors) / sizeof(**colors); ncols++)
85 if (!colors[j][ncols]) break;
87 y2 = height * ypct / 100;
88 h = y2 - y; /* avoid roundoff fencepost */
89 for (i = 0; i < ncols; i++)
92 const char *color = colors[j][i];
93 int x2 = x + (width * (i+1) / ncols);
94 int w = x2 - x1; /* avoid roundoff fencepost */
95 if (! XParseColor (dpy, cmap, color, &xcolor))
97 xcolor.flags = DoRed|DoGreen|DoBlue;
98 if (!XAllocColor (dpy, cmap, &xcolor))
100 XSetForeground (dpy, gc, xcolor.pixel);
101 XFillRectangle (dpy, drawable, gc, x1, y, w, h);
109 /* Add in the xscreensaver logo */
111 unsigned long *pixels; /* ignored - unfreed */
113 unsigned long bg = ~0;
114 Pixmap logo_mask = 0;
115 Pixmap logo_map = xscreensaver_logo (screen, visual, drawable, cmap, bg,
116 &pixels, &npixels, &logo_mask,
121 unsigned int logo_width, logo_height;
123 int h = height * heights[0] / 100;
126 XGetGeometry (dpy, logo_map, &root, &x1, &y1,
127 &logo_width, &logo_height, &bw, &d);
128 x1 = x + (w - (int) logo_width) / 2;
129 y1 = y + (h - (int) logo_height) / 2;
132 XSetClipMask (dpy, gc, logo_mask);
133 XSetClipOrigin (dpy, gc, x1, y1);
135 XCopyArea (dpy, logo_map, drawable, gc,
136 0, 0, logo_width, logo_height, x1, y1);
137 XFreePixmap (dpy, logo_map);
139 XFreePixmap (dpy, logo_mask);