1 /* xscreensaver, Copyright (c) 2001-2018 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"
19 #include "../hacks/ximage-loader.h"
21 static const char * const colors[7][18] = {
22 { "#CCCCCC", "#FFFF00", "#00FFFF", "#00FF00", /* tall bars */
23 "#FF00FF", "#FF0000", "#0000FF", "#000000",
26 "#000000", "#0000FF", "#FF0000", "#FF00FF", /* short rev bars */
27 "#00FF00", "#00FFFF", "#FFFF00", "#CCCCCC",
30 "#000000", 0 /* blank */
32 "#FFFFFF", "#EEEEEE", "#DDDDDD", "#CCCCCC", /* gray ramp */
33 "#BBBBBB", "#AAAAAA", "#999999", "#888888",
34 "#777777", "#666666", "#555555", "#444444",
35 "#333333", "#222222", "#111111", "#000000"
37 "#000000", "#111111", "#222222", "#333333", /* gray rev ramp */
38 "#444444", "#555555", "#666666", "#777777",
39 "#888888", "#999999", "#AAAAAA", "#BBBBBB",
40 "#CCCCCC", "#DDDDDD", "#EEEEEE", "#FFFFFF"
42 "#000000", 0 /* blank */
44 "#FF00FF", "#FF00FF", "#FF00FF", /* blacklevel row */
45 "#FFFFFF", "#FFFFFF", "#FFFFFF",
46 "#0000AD", "#0000AD", "#0000AD",
47 "#131313", "#131313", "#131313",
48 "#000000", "#000000", "#262626",
49 "#000000", "#000000", "#000000"
53 static const int heights[7] = { 63, 10, 1, 5, 5, 1, 15 }; /* percentages */
57 draw_colorbars (Screen *screen, Visual *visual,
58 Drawable drawable, Colormap cmap,
59 int x, int y, int width, int height,
60 Pixmap logo, Pixmap logo_mask)
62 Display *dpy = DisplayOfScreen (screen);
66 GC gc = XCreateGC (dpy, drawable, 0, &gcv);
68 if (width <= 0 || height <= 0)
73 XGetGeometry (dpy, drawable,
75 (unsigned int *) &width,
76 (unsigned int *) &height,
80 for (j = 0; j < sizeof(colors) / sizeof(*colors); j++)
85 for (ncols = 0; ncols < sizeof(*colors) / sizeof(**colors); ncols++)
86 if (!colors[j][ncols]) break;
88 y2 = height * ypct / 100;
89 h = y2 - y; /* avoid roundoff fencepost */
90 for (i = 0; i < ncols; i++)
93 const char *color = colors[j][i];
94 int x2 = x + (width * (i+1) / ncols);
95 int w = x2 - x1; /* avoid roundoff fencepost */
96 if (! XParseColor (dpy, cmap, color, &xcolor))
98 xcolor.flags = DoRed|DoGreen|DoBlue;
99 if (!XAllocColor (dpy, cmap, &xcolor))
101 XSetForeground (dpy, gc, xcolor.pixel);
102 XFillRectangle (dpy, drawable, gc, x1, y, w, h);
108 /* Add in the xscreensaver logo */
113 unsigned int logo_width, logo_height, bw, d;
115 XGetGeometry (dpy, logo, &r, &x, &y, &logo_width, &logo_height, &bw, &d);
117 h = height * heights[0] / 100;
118 x1 = x + (w - (int) logo_width) / 2;
119 y1 = y + (h - (int) logo_height) / 2;
122 XSetClipMask (dpy, gc, logo_mask);
123 XSetClipOrigin (dpy, gc, x1, y1);
125 XCopyArea (dpy, logo, drawable, gc, 0, 0,
126 logo_width, logo_height, x1, y1);