Annotation of researchv9/X11/src/X.V11R1/lib/Xtk/GrayPixmap.c, revision 1.1

1.1     ! root        1: #ifndef lint
        !             2: static char rcsid[] = "$Header: GrayPixmap.c,v 1.5 87/09/12 16:37:19 swick Exp $";
        !             3: #endif lint
        !             4: 
        !             5: /*
        !             6:  * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
        !             7:  * 
        !             8:  *                         All Rights Reserved
        !             9:  * 
        !            10:  * Permission to use, copy, modify, and distribute this software and its 
        !            11:  * documentation for any purpose and without fee is hereby granted, 
        !            12:  * provided that the above copyright notice appear in all copies and that
        !            13:  * both that copyright notice and this permission notice appear in 
        !            14:  * supporting documentation, and that the name of Digital Equipment
        !            15:  * Corporation not be used in advertising or publicity pertaining to
        !            16:  * distribution of the software without specific, written prior permission.  
        !            17:  * 
        !            18:  * 
        !            19:  * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
        !            20:  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
        !            21:  * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
        !            22:  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
        !            23:  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
        !            24:  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
        !            25:  * SOFTWARE.
        !            26:  */
        !            27: 
        !            28: #include "Intrinsic.h"
        !            29: #include <stdio.h>
        !            30: 
        !            31: #define XtMalloc(s) malloc(s)
        !            32: 
        !            33: typedef struct _PixmapCache {
        !            34:     Screen *screen;
        !            35:     Pixmap pixmap;
        !            36:     struct _PixmapCache *next;
        !            37:   } CacheEntry;
        !            38: 
        !            39: static CacheEntry *pixmapCache = NULL;
        !            40: 
        !            41: Pixmap XtGrayPixmap( screen )
        !            42:     Screen *screen;
        !            43: /*
        !            44:  *     Creates a gray pixmap of depth DefaultDepth(screen)
        !            45:  *     caches these so that multiple requests share the pixmap
        !            46:  */
        !            47: {
        !            48:     register Display *display = DisplayOfScreen(screen);
        !            49:     XImage image;
        !            50:     CacheEntry *cachePtr;
        !            51:     Pixmap gray_pixmap;
        !            52:     GC gc;
        !            53:     XGCValues gcValues;
        !            54:     static unsigned short pixmap_bits[] = {
        !            55:        0xaaaa, 0xaaaa, 0x5555, 0x5555,
        !            56:        0xaaaa, 0xaaaa, 0x5555, 0x5555,
        !            57:        0xaaaa, 0xaaaa, 0x5555, 0x5555,
        !            58:        0xaaaa, 0xaaaa, 0x5555, 0x5555,
        !            59:        0xaaaa, 0xaaaa, 0x5555, 0x5555,
        !            60:        0xaaaa, 0xaaaa, 0x5555, 0x5555,
        !            61:        0xaaaa, 0xaaaa, 0x5555, 0x5555,
        !            62:        0xaaaa, 0xaaaa, 0x5555, 0x5555,
        !            63:        0xaaaa, 0xaaaa, 0x5555, 0x5555,
        !            64:        0xaaaa, 0xaaaa, 0x5555, 0x5555,
        !            65:        0xaaaa, 0xaaaa, 0x5555, 0x5555,
        !            66:        0xaaaa, 0xaaaa, 0x5555, 0x5555,
        !            67:        0xaaaa, 0xaaaa, 0x5555, 0x5555,
        !            68:        0xaaaa, 0xaaaa, 0x5555, 0x5555,
        !            69:        0xaaaa, 0xaaaa, 0x5555, 0x5555,
        !            70:        0xaaaa, 0xaaaa, 0x5555, 0x5555
        !            71:     };
        !            72: 
        !            73: #define pixmap_width 32
        !            74: #define pixmap_height 32
        !            75: 
        !            76:     /* see if we already have a pixmap suitable for this screen */
        !            77:     for (cachePtr = pixmapCache; cachePtr; cachePtr = cachePtr->next) {
        !            78:        if (cachePtr->screen == screen)
        !            79:            return( cachePtr->pixmap );
        !            80:     }
        !            81: 
        !            82:     /* nope, we'll have to construct one now */
        !            83:     image.height = pixmap_height;
        !            84:     image.width = pixmap_width;
        !            85:     image.xoffset = 0;
        !            86:     image.format = XYBitmap;
        !            87:     image.data = (char*) pixmap_bits;
        !            88:     image.byte_order = ImageByteOrder(display);
        !            89:     image.bitmap_pad = BitmapPad(display);
        !            90:     image.bitmap_bit_order = BitmapBitOrder(display);
        !            91:     image.bitmap_unit = BitmapUnit(display);
        !            92:     image.depth = 1;
        !            93:     image.bytes_per_line = pixmap_width/8;
        !            94:     image.obdata = NULL;
        !            95: 
        !            96:     gray_pixmap = XCreatePixmap( display, RootWindowOfScreen(screen), 
        !            97:                                 image.width, image.height,
        !            98:                                 (unsigned) DefaultDepthOfScreen(screen) );
        !            99: 
        !           100:     /* and insert it at the head of the cache */
        !           101:     cachePtr = (CacheEntry *)XtMalloc( sizeof(CacheEntry) );
        !           102:     cachePtr->screen = screen;
        !           103:     cachePtr->pixmap = gray_pixmap;
        !           104:     cachePtr->next = pixmapCache;
        !           105:     pixmapCache = cachePtr;
        !           106: 
        !           107:     /* now store the image into it */
        !           108:     gcValues.foreground = BlackPixelOfScreen(screen);
        !           109:     gcValues.background = WhitePixelOfScreen(screen);
        !           110:     gc = XCreateGC( display, RootWindowOfScreen(screen),
        !           111:                    GCForeground | GCBackground, &gcValues );
        !           112: 
        !           113:     XPutImage( display, gray_pixmap, gc, &image, 0, 0, 0, 0,
        !           114:               image.width, image.height);
        !           115: 
        !           116:     XFreeGC( display, gc );
        !           117: 
        !           118:     return( gray_pixmap );
        !           119: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.