home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xibm.zip / ppc / ppcPixmap.c < prev    next >
C/C++ Source or Header  |  1989-11-07  |  6KB  |  193 lines

  1. /*
  2.  * Copyright IBM Corporation 1987,1988,1989
  3.  *
  4.  * All Rights Reserved
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software and its
  7.  * documentation for any purpose and without fee is hereby granted,
  8.  * provided that the above copyright notice appear in all copies and that 
  9.  * both that copyright notice and this permission notice appear in
  10.  * supporting documentation, and that the name of IBM not be
  11.  * used in advertising or publicity pertaining to distribution of the
  12.  * software without specific, written prior permission.
  13.  *
  14.  * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  15.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  16.  * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  17.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  18.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  19.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  20.  * SOFTWARE.
  21.  *
  22. */
  23.  
  24. /***********************************************************
  25. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  26. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  27.  
  28.                         All Rights Reserved
  29.  
  30. Permission to use, copy, modify, and distribute this software and its 
  31. documentation for any purpose and without fee is hereby granted, 
  32. provided that the above copyright notice appear in all copies and that
  33. both that copyright notice and this permission notice appear in 
  34. supporting documentation, and that the names of Digital or MIT not be
  35. used in advertising or publicity pertaining to distribution of the
  36. software without specific, written prior permission.  
  37.  
  38. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  39. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  40. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  41. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  42. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  43. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  44. SOFTWARE.
  45.  
  46. ******************************************************************/
  47.  
  48. #include "pixmapstr.h"
  49. #include "servermd.h"
  50. #include "mfb.h"
  51.  
  52. #include "OScompiler.h"
  53. #include "ibmTrace.h"
  54.  
  55. PixmapPtr
  56. ppcCreatePixmap( pScreen, width, height, depth )
  57.     ScreenPtr    pScreen ;
  58.     int        width ;
  59.     int        height ;
  60.     int        depth ;
  61. {
  62.     register PixmapPtr pPixmap ;
  63.     int size ;
  64.  
  65.     TRACE(("ppcCreatePixmap(pScreen=0x%x, width=%d, height=%d, depth=%d)\n", pScreen, width, height, depth)) ;
  66.  
  67.     if ( depth > 8 )
  68.     return (PixmapPtr) NULL ;
  69.  
  70.     size = PixmapBytePad(width, depth);
  71.     pPixmap = (PixmapPtr) Xalloc( sizeof (PixmapRec) + (height * size) ) ;
  72.     if ( !pPixmap )
  73.     return (PixmapPtr) NULL ;
  74.     pPixmap->drawable.type = DRAWABLE_PIXMAP ;
  75.     pPixmap->drawable.class = 0 ;
  76.     pPixmap->drawable.pScreen = pScreen ;
  77.     pPixmap->drawable.depth = depth ;
  78.     pPixmap->drawable.id = 0 ;
  79.     pPixmap->drawable.bitsPerPixel = ( depth == 1 ) ? 1 : 8 ;
  80.     pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER ;
  81.     pPixmap->drawable.x = 0 ;
  82.     pPixmap->drawable.y = 0 ;
  83.     pPixmap->drawable.width = width ;
  84.     pPixmap->drawable.height = height ;
  85.     pPixmap->devKind = size;
  86.     pPixmap->refcnt = 1 ;
  87.     size = height * pPixmap->devKind ;
  88.  
  89.     pPixmap->devPrivate.ptr = (pointer) (pPixmap + 1);
  90.     bzero( (char *) pPixmap->devPrivate.ptr, size ) ;
  91.     return pPixmap ;
  92. }
  93.  
  94. PixmapPtr
  95. ppcCopyPixmap(pSrc)
  96.     register PixmapPtr    pSrc;
  97. {
  98.     register PixmapPtr    pDst;
  99.     int        size;
  100.  
  101.     TRACE(("ppcCopyPixmap(pSrc=0x%x)\n", pSrc)) ;
  102.     size = pSrc->drawable.height * pSrc->devKind;
  103.     pDst = (PixmapPtr)xalloc(sizeof(PixmapRec) + size);
  104.     if (!pDst)
  105.     return NullPixmap;
  106.     pDst->drawable = pSrc->drawable;
  107.     pDst->drawable.id = 0;
  108.     pDst->drawable.serialNumber = NEXT_SERIAL_NUMBER;
  109.     pDst->devKind = pSrc->devKind;
  110.     pDst->refcnt = 1;
  111.     pDst->devPrivate.ptr = (pointer)(pDst + 1);
  112.     MOVE( (char *)pSrc->devPrivate.ptr, (char *)pDst->devPrivate.ptr, size ) ;
  113.     return pDst;
  114. }
  115.  
  116. /* 
  117.    see doc in server/ddx/mfb/mfbpixmap.c
  118. */
  119. void
  120. ppcPadPixmap(pPixmap)
  121.     PixmapPtr pPixmap ;
  122. {
  123.     TRACE(("ppcPadPixmap(pPixmap=0x%x)\n", pPixmap)) ;
  124. if ( pPixmap->drawable.depth == 1 )
  125.     mfbPadPixmap( pPixmap ) ;
  126. }
  127.  
  128. /* ppcdebugging routine -- 
  129. */
  130. #ifdef DEBUG
  131. void ppcDumpPixmap(pPix)
  132. PixmapPtr pPix ;
  133. unsigned char *psrc, *pline ;
  134. int i, j ;
  135. pline = pPix->devPrivate ;
  136. for ( i = 0 ; i < pPix->height ; i++ )
  137.     {
  138.     psrc = pline ;
  139.     for ( j = 0 ; j < pPix->width ; j++ )
  140.         {
  141.         ErrorF("%02x ",*psrc++) ;
  142.         }
  143.     ErrorF("\n") ;
  144.     pline = pline + pPix->devKind ;
  145.     }
  146. return ;
  147. }
  148. #endif
  149.  
  150. /* Rotates deep pixmap pPix by w pixels to the right on the screen. Assumes 
  151.  * that words are 32 bits wide, and that the least significant bit appears on 
  152.  * the left.
  153.  */
  154. void ppcRotatePixmap(pPix, rw)
  155.     PixmapPtr    pPix ;
  156.     register int rw ;
  157. {
  158.     unsigned char *pTempSrc, *pTempDst, *pRealDst ;
  159.     int        depth, h, i, wid, loc ;
  160.  
  161.     TRACE(("ppcRotatePixmap(pPix=0x%x, rw=%d)\n", pPix, rw)) ;
  162.     if (pPix == NullPixmap)
  163.         return ;
  164.     depth = pPix->drawable.depth ;
  165.     if ( depth == 1 ) {
  166.     mfbXRotatePixmap(pPix,rw) ;
  167.     return ;
  168.     }
  169.     if ( depth > 8 ) {
  170.     ErrorF("ppcRotatePixmap: too deep (%d)\n",depth) ;
  171.     return ;
  172.     }
  173.  
  174.     wid = pPix->drawable.width ;
  175.     rw %= wid ;
  176.     h = pPix->drawable.height ;
  177.     pTempDst = (unsigned char *) ALLOCATE_LOCAL(wid) ;
  178.     pTempSrc = pRealDst = (unsigned char *) pPix->devPrivate.ptr ;
  179.     while ( h-- ) {
  180.     for ( i = 0 ; i < wid ; i++ ) {
  181.         loc = i + rw ;
  182.         if ( loc >= wid )
  183.              loc -= wid ;
  184.         pTempDst[loc] = *pTempSrc++ ;
  185.     }
  186.     MOVE( (char *) pTempDst, (char *) pRealDst, wid) ;
  187.     pRealDst += wid ;
  188.     }
  189.     DEALLOCATE_LOCAL(pTempDst) ;
  190.     return ;
  191. }
  192.