1 /* xscreensaver, Copyright (c) 2001 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 (Display *dpy, Window window,
57 int x, int y, int width, int height)
63 GC gc = XCreateGC (dpy, window, 0, &gcv);
65 XWindowAttributes xgwa;
66 XGetWindowAttributes (dpy, window, &xgwa);
69 for (j = 0; j < sizeof(colors) / sizeof(*colors); j++)
74 for (ncols = 0; ncols < sizeof(*colors) / sizeof(**colors); ncols++)
75 if (!colors[j][ncols]) break;
77 y2 = height * ypct / 100;
78 h = y2 - y; /* avoid roundoff fencepost */
79 for (i = 0; i < ncols; i++)
82 const char *color = colors[j][i];
83 int x2 = x + (width * (i+1) / ncols);
84 int w = x2 - x1; /* avoid roundoff fencepost */
85 if (! XParseColor (dpy, cmap, color, &xcolor))
87 xcolor.flags = DoRed|DoGreen|DoBlue;
88 if (!XAllocColor (dpy, cmap, &xcolor))
90 XSetForeground (dpy, gc, xcolor.pixel);
91 XFillRectangle (dpy, window, gc, x1, y, w, h);
99 /* Add in the xscreensaver logo */
101 unsigned long *pixels; /* ignored - unfreed */
103 unsigned long bg = ~0;
104 Pixmap logo_mask = 0;
105 Pixmap logo_map = xscreensaver_logo (dpy, window, cmap, bg,
106 &pixels, &npixels, &logo_mask,
111 int logo_width, logo_height;
113 int h = height * heights[0] / 100;
115 XGetGeometry (dpy, logo_map, &root, &x1, &y1,
116 &logo_width, &logo_height, &bw, &d);
117 x1 = x + (w - logo_width) / 2;
118 y1 = y + (h - logo_height) / 2;
121 XSetClipMask (dpy, gc, logo_mask);
122 XSetClipOrigin (dpy, gc, x1, y1);
124 XCopyArea (dpy, logo_map, window, gc,
125 0, 0, logo_width, logo_height, x1, y1);
126 XFreePixmap (dpy, logo_map);
128 XFreePixmap (dpy, logo_mask);