image.c revision 546
294N/A/*
294N/A * Copyright (c) 1988-91 by Patrick J. Naughton.
294N/A *
294N/A * Permission to use, copy, modify, and distribute this software and its
294N/A * documentation for any purpose and without fee is hereby granted,
294N/A * provided that the above copyright notice appear in all copies and that
294N/A * both that copyright notice and this permission notice appear in
294N/A * supporting documentation.
294N/A *
294N/A * This file is provided AS IS with no warranties of any kind. The author
294N/A * shall have no liability with respect to the infringement of copyrights,
294N/A * trade secrets or any patents by this file or any part thereof. In no
294N/A * event will the author be liable for any lost revenue or profits or
294N/A * other special, indirect and consequential damages.
294N/A */
294N/A
294N/A/*
294N/A * Copyright 1994 Sun Microsystems, Inc. All rights reserved.
294N/A * Use is subject to license terms.
294N/A *
294N/A * Permission is hereby granted, free of charge, to any person obtaining a
294N/A * copy of this software and associated documentation files (the
294N/A * "Software"), to deal in the Software without restriction, including
294N/A * without limitation the rights to use, copy, modify, merge, publish,
294N/A * distribute, and/or sell copies of the Software, and to permit persons
851N/A * to whom the Software is furnished to do so, provided that the above
294N/A * copyright notice(s) and this permission notice appear in all copies of
294N/A * the Software and that both the above copyright notice(s) and this
294N/A * permission notice appear in supporting documentation.
294N/A *
294N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
294N/A * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
294N/A * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
294N/A * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
294N/A * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
294N/A * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
294N/A * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
294N/A * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
294N/A * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
294N/A *
294N/A * Except as contained in this notice, the name of a copyright holder
294N/A * shall not be used in advertising or otherwise to promote the sale, use
294N/A * or other dealings in this Software without prior written authorization
294N/A * of the copyright holder.
294N/A */
294N/A
294N/A#ifndef lint
294N/Astatic char sccsid[] = "@(#)image.c 35.3 08/09/18 XLOCK";
294N/A#endif
294N/A/*-
294N/A * image.c - image bouncer for xlock, the X Window System lockscreen.
294N/A *
294N/A * Copyright (c) 1991 by Patrick J. Naughton.
294N/A *
294N/A * See xlock.c for copying information.
294N/A *
294N/A * Revision History:
294N/A * 29-Jul-90: Written.
294N/A */
294N/A
294N/A#include "xlock.h"
294N/A#include "sunlogo.bit"
294N/A
294N/Astatic XImage logo = {
294N/A 0, 0, /* width, height */
294N/A 0, XYBitmap, 0, /* xoffset, format, data */
294N/A LSBFirst, 8, /* byte-order, bitmap-unit */
294N/A LSBFirst, 8, 1 /* bitmap-bit-order, bitmap-pad, depth */
294N/A};
294N/A
294N/A#define MAXICONS 1024
294N/A
294N/Atypedef struct {
294N/A int x;
294N/A int y;
294N/A} point;
294N/A
294N/Atypedef struct {
294N/A int width;
294N/A int height;
294N/A int nrows;
294N/A int ncols;
294N/A int xb;
294N/A int yb;
294N/A int iconmode;
294N/A int iconcount;
294N/A point icons[MAXICONS];
294N/A long startTime;
294N/A} imagestruct;
294N/A
294N/Aextern XColor ssblack[];
294N/Aextern XColor sswhite[];
294N/A
294N/Astatic imagestruct ims[MAXSCREENS];
294N/A
294N/Avoid
294N/Adrawimage(win)
294N/A Window win;
294N/A{
294N/A imagestruct *ip = &ims[screen];
294N/A int i;
294N/A
294N/A XSetForeground(dsp, Scr[screen].gc, ssblack[screen].pixel);
294N/A for (i = 0; i < ip->iconcount; i++) {
294N/A if (!ip->iconmode)
294N/A XFillRectangle(dsp, win, Scr[screen].gc,
294N/A ip->xb + sunlogo_width * ip->icons[i].x,
294N/A ip->yb + sunlogo_height * ip->icons[i].y,
294N/A sunlogo_width, sunlogo_height);
294N/A
294N/A ip->icons[i].x = random() % ip->ncols;
294N/A ip->icons[i].y = random() % ip->nrows;
294N/A }
294N/A if (Scr[screen].npixels == 2)
294N/A XSetForeground(dsp, Scr[screen].gc, sswhite[screen].pixel);
294N/A for (i = 0; i < ip->iconcount; i++) {
294N/A if (Scr[screen].npixels > 2)
294N/A XSetForeground(dsp, Scr[screen].gc,
294N/A Scr[screen].pixels[random() % Scr[screen].npixels]);
294N/A
294N/A XPutImage(dsp, win, Scr[screen].gc, &logo,
294N/A 0, 0,
294N/A ip->xb + sunlogo_width * ip->icons[i].x,
294N/A ip->yb + sunlogo_height * ip->icons[i].y,
294N/A sunlogo_width, sunlogo_height);
294N/A }
294N/A}
294N/A
294N/Avoid
294N/Ainitimage(win)
294N/A Window win;
294N/A{
294N/A XWindowAttributes xgwa;
294N/A imagestruct *ip = &ims[screen];
294N/A
294N/A ip->startTime = seconds();
294N/A
294N/A logo.data = (char *) sunlogo_bits;
294N/A logo.width = sunlogo_width;
294N/A logo.height = sunlogo_height;
294N/A logo.bytes_per_line = (sunlogo_width + 7) / 8;
294N/A
294N/A XGetWindowAttributes(dsp, win, &xgwa);
294N/A ip->width = xgwa.width;
294N/A ip->height = xgwa.height;
294N/A ip->ncols = ip->width / sunlogo_width;
294N/A ip->nrows = ip->height / sunlogo_height;
294N/A ip->iconmode = (ip->ncols < 2 || ip->nrows < 2);
294N/A if (ip->iconmode) {
294N/A ip->xb = 0;
294N/A ip->yb = 0;
294N/A ip->iconcount = 1; /* icon mode */
294N/A } else {
294N/A ip->xb = (ip->width - sunlogo_width * ip->ncols) / 2;
294N/A ip->yb = (ip->height - sunlogo_height * ip->nrows) / 2;
294N/A ip->iconcount = batchcount;
294N/A if ((ip->iconcount) > MAXICONS)
294N/A ip->iconcount = MAXICONS;
294N/A }
294N/A XSetForeground(dsp, Scr[screen].gc, ssblack[screen].pixel);
294N/A XFillRectangle(dsp, win, Scr[screen].gc, 0, 0, ip->width, ip->height);
294N/A}
294N/A