Fix typo in license headers
[oweals/cde.git] / cde / programs / dtscreen / image.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: image.c /main/3 1995/11/02 16:07:35 rswiston $ */
24 /*
25  */
26 /*                                                                      *
27  * (c) Copyright 1993, 1994 Hewlett-Packard Company                     *
28  * (c) Copyright 1993, 1994 International Business Machines Corp.       *
29  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.                      *
30  * (c) Copyright 1993, 1994 Novell, Inc.                                *
31  */
32 /*-
33  * image.c - image bouncer for dtscreen, the X Window System lockscreen.
34  *
35  * Copyright (c) 1991 by Patrick J. Naughton.
36  *
37  * See dtscreen.c for copying information.
38  *
39  * Revision History:
40  * 29-Jul-90: Written.
41  */
42
43 #include "dtscreen.h"
44 #include "xlogo.bit"
45 #include <stdlib.h>
46
47 static XImage logo = {
48     0, 0,                       /* width, height */
49     0, XYBitmap, 0,             /* xoffset, format, data */
50     LSBFirst, 8,                /* byte-order, bitmap-unit */
51     LSBFirst, 8, 1              /* bitmap-bit-order, bitmap-pad, depth */
52 };
53
54 #define MAXICONS 256
55
56 typedef struct {
57     int         x;
58     int         y;
59 }           point;
60
61 typedef struct {
62     int         width;
63     int         height;
64     int         nrows;
65     int         ncols;
66     int         xb;
67     int         yb;
68     int         iconmode;
69     int         iconcount;
70     point       icons[MAXICONS];
71     long        startTime;
72 }           imagestruct;
73
74 void
75 drawimage(perwindow *pwin)
76 {
77     imagestruct *ip;
78     int         i;
79
80     ip = (imagestruct *)pwin->data;
81     XSetForeground(dsp, pwin->gc, BlackPixelOfScreen(pwin->perscreen->screen));
82     for (i = 0; i < ip->iconcount; i++) {
83         if (!ip->iconmode)
84             XFillRectangle(dsp, pwin->w, pwin->gc,
85                            ip->xb + xlogo_width * ip->icons[i].x,
86                            ip->yb + xlogo_height * ip->icons[i].y,
87                            xlogo_width, xlogo_height);
88
89         ip->icons[i].x = random() % ip->ncols;
90         ip->icons[i].y = random() % ip->nrows;
91     }
92     if (pwin->perscreen->npixels == 2)
93       XSetForeground(dsp, pwin->gc, WhitePixelOfScreen(pwin->perscreen->screen));
94     for (i = 0; i < ip->iconcount; i++) {
95         if (pwin->perscreen->npixels > 2)
96             XSetForeground(dsp, pwin->gc,
97                  pwin->perscreen->pixels[random() % pwin->perscreen->npixels]);
98
99         XPutImage(dsp, pwin->w, pwin->gc, &logo,
100                   0, 0,
101                   ip->xb + xlogo_width * ip->icons[i].x,
102                   ip->yb + xlogo_height * ip->icons[i].y,
103                   xlogo_width, xlogo_height);
104     }
105 }
106
107 void
108 initimage(perwindow *pwin)
109 {
110     XWindowAttributes xgwa;
111     imagestruct *ip;
112
113     if (pwin->data) free(pwin->data);
114     pwin->data = (void *)malloc(sizeof(imagestruct));
115     memset(pwin->data, '\0', sizeof(imagestruct));
116     ip = (imagestruct *)pwin->data;
117     ip->startTime = seconds();
118
119     logo.data = (char *) xlogo_bits;
120     logo.width = xlogo_width;
121     logo.height = xlogo_height;
122     logo.bytes_per_line = (xlogo_width + 7) / 8;
123
124     XGetWindowAttributes(dsp, pwin->w, &xgwa);
125     ip->width = xgwa.width;
126     ip->height = xgwa.height;
127     ip->ncols = ip->width / xlogo_width;
128     ip->nrows = ip->height / xlogo_height;
129     ip->iconmode = (ip->ncols < 2 || ip->nrows < 2);
130     if (ip->iconmode) {
131         ip->xb = 0;
132         ip->yb = 0;
133         ip->iconcount = 1;      /* icon mode */
134     } else {
135         ip->xb = (ip->width - xlogo_width * ip->ncols) / 2;
136         ip->yb = (ip->height - xlogo_height * ip->nrows) / 2;
137         ip->iconcount = batchcount;
138     }
139     XSetForeground(dsp, pwin->gc, BlackPixelOfScreen(pwin->perscreen->screen));
140     XFillRectangle(dsp, pwin->w, pwin->gc, 0, 0, ip->width, ip->height);
141 }