1: /* $Header: bitpix.c,v 10.3 86/02/01 15:46:25 tony Rel $ */
   2: /* Routines to cache bitmaps and pixmaps in the frame buffer memory:
   3:  *
   4:  *	StoreBitmap	Creates a bitmap
   5:  *	FreeBitmap	Frees the storage taken by a bitmap
   6:  *	CharBitmap	Creates a bitmap from a font character
   7:  *	StorePixmap	Creates a pixmap
   8:  *	FreePixmap	Frees the storage taken by a pixmap
   9:  *	MakePixmap	Create a pixmap from a bitmap
  10:  *	PixmapSave	Save a region of the screen
  11:  *	PixmapGet	Read a region of the screen
  12:  *
  13:  */
  14: 
  15: /****************************************************************************
  16:  *									    *
  17:  *  Copyright (c) 1983, 1984 by						    *
  18:  *  DIGITAL EQUIPMENT CORPORATION, Maynard, Massachusetts.		    *
  19:  *  All rights reserved.						    *
  20:  * 									    *
  21:  *  This software is furnished on an as-is basis and may be used and copied *
  22:  *  only with inclusion of the above copyright notice. This software or any *
  23:  *  other copies thereof may be provided or otherwise made available to     *
  24:  *  others only for non-commercial purposes.  No title to or ownership of   *
  25:  *  the software is hereby transferred.					    *
  26:  * 									    *
  27:  *  The information in this software is  subject to change without notice   *
  28:  *  and  should  not  be  construed as  a commitment by DIGITAL EQUIPMENT   *
  29:  *  CORPORATION.							    *
  30:  * 									    *
  31:  *  DIGITAL assumes no responsibility for the use  or  reliability of its   *
  32:  *  software on equipment which is not supplied by DIGITAL.		    *
  33:  * 									    *
  34:  *									    *
  35:  ****************************************************************************/
  36: 
  37: #include "vs100.h"
  38: #include <errno.h>
  39: 
  40: extern int errno;
  41: extern BitMap screen;
  42: extern int VSReloc;
  43: 
  44: char *Xalloc(), *AllocateSpace();
  45: VSArea *VSAlloc();
  46: PIXMAP *MakePixmap();
  47: 
  48: BITMAP *StoreBitmap (width, height, data)
  49:     int width, height;
  50:     char *data;
  51: {
  52:     register BITMAP *bm;
  53:     int size;
  54: 
  55:     bm = (BITMAP *) Xalloc (sizeof (BITMAP));
  56:     bm->width = width;
  57:     bm->height = height;
  58:     bm->refcnt = 1;
  59: 
  60:     size = BitmapSize(width, height);
  61:     if ((bm->data = (caddr_t) VSAlloc (size, BITMAP_TYPE)) == NULL) {
  62:         free ((caddr_t) bm);
  63:         return (NULL);
  64:     }
  65:     if (MoveBufferDown (data, BDATA(bm)->vsPtr, size)) {
  66:         FreeBitmap (bm);
  67:         return (NULL);
  68:     }
  69:     return (bm);
  70: }
  71: 
  72: FreeBitmap (bitmap)
  73:     register BITMAP *bitmap;
  74: {
  75:     VSFree (BDATA(bitmap));
  76:     free ((caddr_t) bitmap);
  77: }
  78: 
  79: BITMAP *CharBitmap (c, font)
  80:     unsigned c;
  81:     register FONT *font;
  82: {
  83:     int width;
  84:     register BITMAP *bm;
  85: 
  86:     if (c < font->first || c > font->last) {
  87:         errno = EINVAL;
  88:         return (NULL);
  89:     }
  90:     if (font->fixed)
  91:         width = font->avg_width;
  92:     else
  93:         width = FDATA(font)->widths[c - font->first];
  94:     if (width == 0) {
  95:         errno = EINVAL;
  96:         return (NULL);
  97:     }
  98:     bm = (BITMAP *) Xalloc (sizeof (BITMAP));
  99:     bm->width = width;
 100:     bm->height = font->height;
 101:     bm->refcnt = 1;
 102:     if ((bm->data = (caddr_t) VSAlloc (BitmapSize(width, bm->height),
 103:                        BITMAP_TYPE)) == NULL) {
 104:         free ((caddr_t) bm);
 105:         errno = ENOMEM;
 106:         return (NULL);
 107:     }
 108: 
 109:     CopyText ((caddr_t) &c, 1, font, bm);
 110:     return (bm);
 111: }
 112: 
 113: /*ARGSUSED*/
 114: PIXMAP *StorePixmap (width, height, format, data)
 115:     int width, height, format;
 116:     char *data;
 117: {
 118:     register BITMAP *bm;
 119:     register PIXMAP *pm;
 120: 
 121:     bm = (BITMAP *) StoreBitmap (width, height, data);
 122:     if (bm == NULL)
 123:         return (NULL);
 124:     bm->refcnt = 0;
 125:     if (pm = MakePixmap (bm, 1, 0))
 126:         return (pm);
 127:     FreeBitmap (bm);
 128:     return (NULL);
 129: }
 130: 
 131: FreePixmap (pixmap)
 132:     register PIXMAP *pixmap;
 133: {
 134: #ifdef HTCROCK
 135:     register TilePriv *tp;
 136: #endif
 137:     register BITMAP *bm;
 138: 
 139:     if (pixmap->kind) {
 140: #ifdef HTCROCK
 141:         if (pixmap->kind & 2) {
 142:         tp = TDATA(pixmap);
 143:         bm = tp->bitmap;
 144:         free ((caddr_t) tp);
 145:         } else
 146: #endif
 147:         bm = PDATA(pixmap);
 148:         if (--bm->refcnt == 0)
 149:         FreeBitmap (bm);
 150:     }
 151:     free ((caddr_t) pixmap);
 152: }
 153: 
 154: PIXMAP constpix0 = {1, 1, 1, 1, 0, (caddr_t) 0};
 155: PIXMAP constpix1 = {1, 1, 1, 1, 0, (caddr_t) 1};
 156: 
 157: PIXMAP *MakePixmap (xymask, fore, back)
 158:     register BITMAP *xymask;
 159:     int fore, back;
 160: {
 161: #ifdef HTCROCK
 162:     register TilePriv *tp;
 163: #endif
 164:     register PIXMAP *pm;
 165: 
 166:     if (xymask == NULL || !((fore ^ back) & 1)) {
 167:         if (fore & 1)
 168:         pm = &constpix1;
 169:         else
 170:         pm = &constpix0;
 171:         pm->refcnt++;
 172:         return (pm);
 173:     }
 174: 
 175:     pm = (PIXMAP *) Xalloc (sizeof (PIXMAP));
 176:     pm->width = xymask->width;
 177:     pm->height = xymask->height;
 178:     pm->refcnt = 1;
 179:     xymask->refcnt++;
 180:     if (xymask->width == 16 && xymask->height == 16) {
 181:         pm->tile = 1;
 182:         pm->kind = 2;
 183: #ifdef HTCROCK
 184:         tp = (TilePriv *) Xalloc (sizeof (TilePriv));
 185:         tp->bitmap = xymask;
 186:         pm->data = (caddr_t) tp;
 187:         if (MoveBufferUp (BDATA(xymask)->vsPtr, (char *) tp->data, 32)) {
 188:         FreePixmap (pm);
 189:         return (NULL);
 190:         }
 191: #else
 192:         pm->data = (caddr_t) xymask;
 193: #endif
 194:     } else {
 195:         pm->tile = 0;
 196:         pm->kind = 1;
 197:         pm->data = (caddr_t) xymask;
 198:     }
 199:     if (back & 1)
 200:         pm->kind |= 0x10;
 201:     return (pm);
 202: }
 203: 
 204: PIXMAP *PixmapSave (srcx, srcy, width, height)
 205:     int srcx, srcy, width, height;
 206: {
 207:     register BITMAP *bm;
 208:     PIXMAP *pm;
 209:     register CopyAreaPacket *cap;
 210: #define h ((PacketHeader *) cap->cap_head)
 211: #define src ((SubBitmap *) cap->cap_source.image)
 212: #define dst ((SubBitmap *) cap->cap_destImage)
 213: #define size ((Extent *) cap->cap_maskSize)
 214: 
 215:     bm = (BITMAP *) Xalloc (sizeof (BITMAP));
 216:     bm->width = width;
 217:     bm->height = height;
 218:     bm->refcnt = 0;
 219: 
 220:     if ((bm->data = (caddr_t) VSAlloc (BitmapSize(width, height),
 221:                        BITMAP_TYPE)) == NULL) {
 222:         free ((caddr_t) bm);
 223:         return (NULL);
 224:     }
 225: 
 226:     cap = (CopyAreaPacket *) AllocateSpace (sizeof (CopyAreaPacket));
 227:     if (cap == NULL) {
 228:         FreeBitmap (bm);
 229:         return (NULL);
 230:     }
 231: 
 232:     h->ph_copyMod.m_mask = 0;
 233:     h->ph_copyMod.m_map = 0;
 234:     h->ph_copyMod.m_clipping = 0;
 235:     h->ph_copyMod.m_source = 1;
 236:     h->ph_opcode = COPY_AREA;
 237:     *(long *) h->ph_next = NULL;
 238: 
 239:     *(BitMap *) src->sb_base = screen;
 240:     src->sb_x = srcx;
 241:     src->sb_y = srcy;
 242:     size->e_height = height;
 243:     size->e_width = width;
 244: 
 245:     *(caddr_t *)dst->sb_address = BDATA(bm)->vsPtr;
 246:     dst->sb_height = height;
 247:     dst->sb_width = width;
 248:     dst->sb_bitsPerPixel = 1;
 249:     dst->sb_x = dst->sb_y = 0;
 250: 
 251:     WritePacket ((caddr_t) cap);
 252: 
 253:     if (pm = MakePixmap (bm, 1, 0))
 254:         return (pm);
 255:     FreeBitmap (bm);
 256:     return (NULL);
 257: #undef h
 258: #undef src
 259: #undef dst
 260: #undef size
 261: }
 262: 
 263: /*ARGSUSED*/
 264: PixmapGet (srcx, srcy, width, height, client, format, swapit)
 265:     int srcx, srcy, width, height, client, format, swapit;
 266: {
 267:     int slop, width1, num, bytes;
 268:     char padding[2];
 269:     register CopyAreaPacket *cap;
 270: #define h ((PacketHeader *) cap->cap_head)
 271: #define src ((SubBitmap *) cap->cap_source.image)
 272: #define dst ((SubBitmap *) cap->cap_destImage)
 273: #define size ((Extent *) cap->cap_maskSize)
 274: 
 275:     width1 = BitmapSize(width, 1);
 276:     slop = (width1 * height) & 2;
 277:     num = VBUFSIZE / width1;
 278:     while (height) {
 279:         if (height < num)
 280:         num = height;
 281:         bytes = num * width1;
 282:         cap = (CopyAreaPacket *) AllocateSpace (sizeof (CopyAreaPacket) +
 283:                             bytes);
 284:         if (cap == NULL)
 285:         return;
 286:         h->ph_copyMod.m_mask = 0;
 287:         h->ph_copyMod.m_map = 0;
 288:         h->ph_copyMod.m_clipping = 0;
 289:         h->ph_copyMod.m_source = 1;
 290:         h->ph_opcode = COPY_AREA;
 291:         *(long *) h->ph_next = NULL;
 292: 
 293:         *(BitMap *) src->sb_base = screen;
 294:         src->sb_x = srcx;
 295:         src->sb_y = srcy;
 296:         size->e_height = num;
 297:         size->e_width = width;
 298: 
 299:         *(caddr_t *)dst->sb_address = (caddr_t) cap +
 300:                       sizeof (CopyAreaPacket) +
 301:                       VSReloc;
 302:         dst->sb_height = num;
 303:         dst->sb_width = width;
 304:         dst->sb_bitsPerPixel = 1;
 305:         dst->sb_x = dst->sb_y = 0;
 306: 
 307:         WritePacket ((caddr_t) cap);
 308:         SynchWrites ();
 309:         if (swapit)
 310:         Swap_shorts ((short *) ((caddr_t) cap + sizeof (CopyAreaPacket)),
 311:                  bytes >> 1);
 312:         Write (client, (caddr_t) cap + sizeof (CopyAreaPacket), bytes);
 313:         height -= num;
 314:         srcy += num;
 315:     }
 316:     if (slop)
 317:         Write (client, padding, slop);
 318: #undef h
 319: #undef src
 320: #undef dst
 321: #undef size
 322: }

Defined functions

CharBitmap defined in line 79; never used
FreeBitmap defined in line 72; used 7 times
FreePixmap defined in line 131; used 1 times
MakePixmap defined in line 157; used 3 times
PixmapGet defined in line 264; never used
PixmapSave defined in line 204; never used
StoreBitmap defined in line 48; used 1 times
StorePixmap defined in line 114; never used

Defined variables

constpix0 defined in line 154; used 1 times
constpix1 defined in line 155; used 1 times

Defined macros

dst defined in line 272; used 14 times
h defined in line 270; used 14 times
size defined in line 273; used 10 times
src defined in line 271; used 8 times
Last modified: 1986-02-01
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1563
Valid CSS Valid XHTML 1.0 Strict