1: /* Copyright 1985 Massachusetts Institute of Technology */ 2: 3: /* Routines to cache bitmaps and pixmaps in the frame buffer memory: 4: * 5: * StoreBitmap Creates a bitmap 6: * FreeBitmap Frees the storage taken by a bitmap 7: * CharBitmap Creates a bitmap from a font character 8: * StorePixmap Creates a pixmap 9: * FreePixmap Frees the storage taken by a pixmap 10: * MakePixmap Create a pixmap from a bitmap 11: * PixmapSave Save a region of the screen 12: * PixmapGet Read a region of the screen 13: * 14: */ 15: 16: #include "ddxqvss.h" 17: #include "vstagbl.h" 18: #include <errno.h> 19: 20: extern int errno; 21: 22: 23: char *Xalloc(), *AllocateSpace(); 24: PIXMAP *MakePixmap(); 25: 26: BITMAP *StoreBitmap (width, height, data) 27: int width, height; 28: char *data; 29: { 30: register BITMAP *bm; 31: int size; 32: 33: bm = (BITMAP *) Xalloc (sizeof (BITMAP)); 34: bm->width = width; 35: bm->height = height; 36: bm->refcnt = 1; 37: 38: size = BitmapSize(width, height); 39: if ((bm->data = (caddr_t) malloc (size)) == NULL) { 40: free ((caddr_t) bm); 41: return (NULL); 42: } 43: 44: bcopy (data, bm->data, size); 45: 46: return (bm); 47: } 48: 49: FreeBitmap (bitmap) 50: register BITMAP *bitmap; 51: { 52: free ((caddr_t) bitmap->data); 53: free ((caddr_t) bitmap); 54: } 55: 56: BITMAP *CharBitmap (c, font) 57: unsigned c; 58: register FONT *font; 59: { 60: int width; 61: register BITMAP *bm; 62: 63: if (c < font->first || c > font->last) { 64: errno = EINVAL; 65: return (NULL); 66: } 67: if (font->fixed) 68: width = font->avg_width; 69: else 70: width = FDATA(font)->widths[c - font->first]; 71: if (width == 0) { 72: errno = EINVAL; 73: return (NULL); 74: } 75: bm = (BITMAP *) Xalloc (sizeof (BITMAP)); 76: bm->width = width; 77: bm->height = font->height; 78: bm->refcnt = 1; 79: if ((bm->data = 80: (caddr_t) malloc (BitmapSize(width, bm->height))) == NULL) { 81: free ((caddr_t) bm); 82: errno = ENOMEM; 83: return (NULL); 84: } 85: 86: CopyText ((caddr_t) &c, 1, font, bm); 87: return (bm); 88: } 89: 90: /*ARGSUSED*/ 91: PIXMAP *StorePixmap (width, height, format, data) 92: int width, height, format; 93: char *data; 94: { 95: register BITMAP *bm; 96: register PIXMAP *pm; 97: 98: bm = (BITMAP *) StoreBitmap (width, height, data); 99: if (bm == NULL) 100: return (NULL); 101: bm->refcnt = 0; 102: if (pm = MakePixmap (bm, 1, 0)) 103: return (pm); 104: FreeBitmap (bm); 105: return (NULL); 106: } 107: 108: FreePixmap (pixmap) 109: register PIXMAP *pixmap; 110: { 111: register BITMAP *bm; 112: 113: if (pixmap->kind) { 114: bm = PDATA(pixmap); 115: if (--bm->refcnt == 0) 116: FreeBitmap (bm); 117: } 118: free ((caddr_t) pixmap); 119: } 120: 121: PIXMAP constpix0 = {1, 1, 1, 1, ConstantPixmap, (caddr_t) 0}; 122: PIXMAP constpix1 = {1, 1, 1, 1, ConstantPixmap, (caddr_t) 1}; 123: 124: PIXMAP *MakePixmap (xymask, fore, back) 125: register BITMAP *xymask; 126: int fore, back; 127: { 128: register PIXMAP *pm; 129: 130: if (xymask == NULL || !((fore ^ back) & 1)) { 131: if (fore & 1) 132: pm = &constpix1; 133: else 134: pm = &constpix0; 135: pm->refcnt++; 136: return (pm); 137: } 138: 139: pm = (PIXMAP *) Xalloc (sizeof (PIXMAP)); 140: pm->width = xymask->width; 141: pm->height = xymask->height; 142: pm->refcnt = 1; 143: xymask->refcnt++; 144: pm->kind = BitmapPixmap; 145: pm->data = (caddr_t) xymask; 146: if (xymask->width == 16 && xymask->height == 16) { 147: pm->tile = CanBeTiled; 148: } else { 149: pm->tile = CannotBeTiled; 150: } 151: /* save a bit to indicate if we have to invert the source */ 152: 153: if (back & 1) 154: pm->kind |= InvertFlag; 155: return (pm); 156: } 157: 158: PIXMAP *PixmapSave (srcx, srcy, width, height) 159: int srcx, srcy, width, height; 160: { 161: register BITMAP *bm; 162: PIXMAP *pm; 163: extern BITMAP pbm; 164: 165: bm = (BITMAP *) Xalloc (sizeof (BITMAP)); 166: bm->width = width; 167: bm->height = height; 168: bm->refcnt = 0; 169: 170: if ((bm->data = 171: (caddr_t) malloc (BitmapSize(width, height))) == NULL) { 172: free ((caddr_t) bm); 173: return (NULL); 174: } 175: copyrmsk(VSTA$K_SRC_BITMAP, (short *) pbm.data, pbm.width, pbm.height, 176: srcx, srcy, width, height, 177: (short *) bm->data, width, height, 178: 0, 0, GXcopy, 0, 0); 179: if (pm = MakePixmap (bm, 1, 0)) 180: return (pm); 181: FreeBitmap (bm); 182: return (NULL); 183: } 184: 185: /*ARGSUSED*/ 186: PixmapGet (srcx, srcy, width, height, client, format, swapit) 187: int srcx, srcy, width, height, client, format; 188: { 189: PIXMAP *pm; 190: BITMAP *bm; 191: int slop; 192: char padding[2]; 193: int size = BitmapSize(width, height); 194: slop = (width * height) & 2; 195: pm = PixmapSave (srcx, srcy, width, height); 196: bm = (BITMAP *) pm->data; 197: if (swapit) 198: Swap_shorts ( (short *) bm->data, size >> 1 ); 199: Write (client, bm->data, size); 200: FreePixmap(pm); 201: if (slop) 202: Write (client, padding, slop); 203: }