home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / dec / qdss / qdmisc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-05  |  6.4 KB  |  253 lines

  1. /***********************************************************
  2. Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Digital or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ******************************************************************/
  24.  
  25. #include "X.h"
  26. #include "Xproto.h"
  27.  
  28. #include "miscstruct.h"
  29. #include "gcstruct.h"
  30. #include "pixmapstr.h"
  31.  
  32. #include "qd.h"
  33.  
  34. void qdQueryBestSize(class, pwidth, pheight)
  35. int class;
  36. short *pwidth;
  37. short *pheight;
  38. {
  39.     int given, test;
  40.  
  41.     switch(class)
  42.     {
  43.       case CursorShape:
  44.       *pwidth = 16;
  45.       *pheight = 16;
  46.       break;
  47.       case TileShape:
  48.       case StippleShape:
  49.       given = *pwidth;
  50.       if (given >= 0) {
  51.           /* Return closest power of two not less than width, but <= 32 */
  52.           test = 16;
  53.           while(test > given)
  54.          test >>= 1;
  55.           if (test != given) test <<= 1;
  56.           *pwidth = test;
  57.       }
  58.       given = *pheight;
  59.       if (given >= 0) {
  60.           /* Return closest power of two not less than height, but <= 32 */
  61.           test = 16;
  62.           while(test > given)
  63.          test >>= 1;
  64.           if (test != given) test <<= 1;
  65.           *pheight = test;
  66.       }
  67.       break;
  68.     }
  69. }
  70.  
  71. #if 0
  72. /*
  73.  * A more convenient interface to ChangeGC.  Takes on the burden of
  74.  * knowing the required ordering of elements in the gc value argument
  75.  * to ChangeGC.
  76.  *
  77.  * pGCchanges is very temporary.  It is probably just allocated on the
  78.  * caller's stack.
  79.  */
  80. QDChangeGCHelper( prealGC, pGCchanges) 
  81.     GCPtr    prealGC;    /* the GC to be changed */
  82.     GCPtr    pGCchanges;    /* ephemeral GC struct */
  83. {
  84.     int        bit;
  85.     int        mask;
  86.     unsigned int * pval, * pv;
  87.  
  88.     pval = pv =
  89.     (unsigned int *) ALLOCATE_LOCAL( GCLastBit * sizeof (unsigned int));
  90.     
  91.     
  92.     for (   bit=0, mask=1;
  93.         bit<=GCLastBit;
  94.         bit++, mask<<=1)
  95.     {
  96.     switch( pGCchanges->stateChanges & mask)
  97.     {
  98.       case GCFunction:
  99.         *pv++ = pGCchanges->alu; break;
  100.       case GCPlaneMask:
  101.         *pv++ = pGCchanges->planemask; break;
  102.       case GCForeground:
  103.         *pv++ = pGCchanges->fgPixel; break;
  104.       case GCBackground:
  105.         *pv++ = pGCchanges->bgPixel; break;
  106.       case GCLineWidth:
  107.         *pv++ = pGCchanges->lineWidth; break;
  108.       case GCLineStyle:
  109.         *pv++ = pGCchanges->lineStyle; break;
  110.       case GCCapStyle:
  111.         *pv++ = pGCchanges->capStyle; break;
  112.       case GCJoinStyle:
  113.         *pv++ = pGCchanges->joinStyle; break;
  114.       case GCFillStyle:
  115.         *pv++ = pGCchanges->fillStyle; break;
  116.       case GCFillRule:
  117.         *pv++ = pGCchanges->fillRule; break;
  118.       case GCTile:
  119.         *pv++ = (unsigned int)pGCchanges->tile; break;
  120.       case GCStipple:
  121.         *pv++ = (unsigned int)pGCchanges->stipple; break;
  122.       case GCTileStipXOrigin:
  123.         *pv++ = pGCchanges->patOrg.x; break;
  124.       case GCTileStipYOrigin:
  125.         *pv++ = pGCchanges->patOrg.y; break;
  126.       case GCFont:
  127.         *pv++ = (unsigned int)pGCchanges->font; break;
  128.       case GCSubwindowMode:
  129.         *pv++ = pGCchanges->subWindowMode; break;
  130.       case GCGraphicsExposures:
  131.         *pv++ = pGCchanges->graphicsExposures; break;
  132.       case GCClipXOrigin:
  133.         *pv++ = pGCchanges->clipOrg.x; break;
  134.       case GCClipYOrigin:
  135.         *pv++ = pGCchanges->clipOrg.y; break;
  136.       case GCClipMask:
  137.         *pv++ = (unsigned int)pGCchanges->clientClip; break;
  138.       case GCDashOffset:
  139.         *pv++ = pGCchanges->dashOffset; break;
  140.       case GCDashList:
  141.         *pv++ = pGCchanges->numInDashList; break;
  142.       case GCArcMode:
  143.         *pv++ = pGCchanges->arcMode; break;
  144.     }
  145.     }
  146.     DoChangeGC( prealGC, pGCchanges->stateChanges, pval, TRUE);
  147.     DEALLOCATE_LOCAL(pval);
  148. }
  149. #endif
  150.  
  151. #define MAXCOL 79
  152. extern    int    Nchannels;
  153.  
  154. DumpPixmap( pDraw)
  155.     DrawablePtr    pDraw; /* dbx insists on type agreement for 'call' command */
  156. {
  157.     PixmapPtr    pPix = (PixmapPtr)pDraw;
  158.     int        rowct;
  159.     int        b;        /* counts bytes across a scanline */
  160.     int        bytesperblock;
  161.     int        blockstart = 0;
  162.     int        c;
  163.  
  164.    tlCancelPixmap(pDraw);
  165.     ErrorF(
  166.         "%s: address == %x\n\tw==%d\n\th==%d\n\trefcnt==%d\n\tdepth==%d\n\tdevPrivate==%x\n",
  167.     "DumpPixmap",
  168.     pPix,
  169.     QDPIX_WIDTH(pPix),
  170.     QDPIX_HEIGHT(pPix),
  171.     pPix->refcnt,
  172.     pPix->drawable.depth,
  173.     pPix->devPrivate );
  174.  
  175.     if ( pPix->drawable.depth == 1)
  176.     {
  177.     bytesperblock = MAXCOL/8;
  178.     for (    blockstart = 0;
  179.         blockstart < pPix->devKind;
  180.         blockstart += bytesperblock)
  181.     {
  182.         for ( rowct=0; rowct < QDPIX_HEIGHT(pPix); rowct++)
  183.         {
  184.         char    line[256];
  185.  
  186.         for (    b=blockstart;
  187.             b < min( bytesperblock+blockstart, pPix->devKind);
  188.             b++)
  189.         {
  190.             for (c=0; c<8; c++)
  191.              line[(b-blockstart)*8+c] = 
  192.                  (*(QD_PIX_DATA(pPix) +
  193.                 rowct * pPix->devKind + b) >> c) & 0x1
  194.                   ? '#' : '.';
  195.             line[(b-blockstart)*8+c]='\0';
  196.         }
  197.         ErrorF( "%s\n", line);
  198.         }
  199.         ErrorF( "\n");
  200.     }
  201.     }
  202.     else    /* 8 or 24 plane pixmap */
  203.     {
  204.     bytesperblock = MAXCOL;
  205.     for (    blockstart = 0;
  206.         blockstart < QDPIX_WIDTH(pPix);
  207.         blockstart += bytesperblock)
  208.     {
  209.         for ( rowct=0; rowct < QDPIX_HEIGHT(pPix) * Nchannels; rowct++)
  210.         {
  211.         char    line[256];
  212.  
  213.         for (    b=blockstart;
  214.             b < min( bytesperblock+blockstart, QDPIX_WIDTH(pPix));
  215.             b++)
  216.             line[(b-blockstart)] =   /* look at low bit */
  217.              *( QD_PIX_DATA(pPix)
  218.                  + rowct * QDPIX_WIDTH(pPix) + b) & 1
  219.               ? '#' : '.';
  220.         line[(b-blockstart)]='\0';
  221.         ErrorF( "%s\n", line);
  222.         }
  223.         ErrorF( "\n");
  224.     }
  225.     }
  226. }
  227.  
  228. unsigned
  229. power2ceiling( x)
  230.     register unsigned int x;
  231. {
  232.     register unsigned int z;
  233.  
  234.     for ( z = 1; z < -1; z<<=1)
  235.     if ( x <= z)
  236.         break;
  237.     return z;
  238. }
  239.  
  240. /* return index (0..) of bit turned on (assuming pow2) */
  241. int
  242. power2bit( x)
  243.     register unsigned int x;
  244. {
  245.     register int z;
  246.  
  247.     for ( z = 0; (unsigned) (1<<z) < (unsigned) (-1); z++)
  248.     if ( x <= 1<<z)
  249.         break;
  250.     return z;
  251. }
  252.  
  253.