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