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 / ppcImg.c < prev    next >
C/C++ Source or Header  |  1989-11-14  |  5KB  |  153 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. /* $Header: /andrew/X11/r3src/r3plus/server/ddx/ibm/ppc/RCS/ppcImg.c,v 9.2 89/05/07 15:27:33 paul Exp $ */
  25. /* $Source: /andrew/X11/r3src/r3plus/server/ddx/ibm/ppc/RCS/ppcImg.c,v $ */
  26.  
  27. #ifndef lint
  28. static char *rcsid = "$Header: /andrew/X11/r3src/r3plus/server/ddx/ibm/ppc/RCS/ppcImg.c,v 9.2 89/05/07 15:27:33 paul Exp $";
  29. #endif
  30.  
  31. #include "X.h"
  32. #include "misc.h"
  33. #include "gcstruct.h"
  34. #include "pixmapstr.h"
  35. #include "windowstr.h"
  36. #include "scrnintstr.h"
  37. #include "regionstr.h"
  38. #include "servermd.h"
  39.  
  40. #include "OScompiler.h"
  41.  
  42. #include "ppc.h"
  43. #include "ibmTrace.h"
  44.  
  45. /* GETBITSPERPIXEL -- Find out how many bits per pixel are supported at
  46.  * this depth -- another helper function
  47.  */
  48. static
  49. int
  50. GetBitsPerPixel( depth ) 
  51.     int    depth ;
  52. {
  53.     register int     i ;
  54.  
  55.     for ( i = screenInfo.numPixmapFormats ; i-- ; ) 
  56.     if ( screenInfo.formats[i].depth == depth ) 
  57.         return screenInfo.formats[i].bitsPerPixel ;
  58.     return 1 ;
  59. }
  60.  
  61. /* Was MIGETIMAGE -- public entry for the GetImage Request
  62.  * We're getting the image into a memory buffer. While we have to use GetSpans
  63.  * to read a line from the device ( since we don't know what that looks like ) ,
  64.  * we can just write into the destination buffer
  65.  *
  66.  * two different strategies are used, depending on whether we're getting the
  67.  * image in Z format or XY format
  68.  * Z format:
  69.  * Line at a time, GetSpans a line and bcopy it to the destination
  70.  * buffer, except that if the planemask is not all ones, we create a
  71.  * temporary pixmap and do a SetSpans into it ( to get bits turned off ) 
  72.  * and then another GetSpans to get stuff back ( because pixmaps are
  73.  * opaque, and we are passed in the memory to write into ) .  This is
  74.  * completely ugly and slow but works, but the interfaces just aren't
  75.  * designed for this case.  Life is hard.
  76.  * XY format:
  77.  * get the single plane specified in planemask
  78.  */
  79. void
  80. ppcGetImage( pDraw, sx, sy, w, h, format, planeMask, pdstLine ) 
  81.     DrawablePtr pDraw ;
  82.     int    sx, sy, w, h ;
  83.     unsigned int format ;
  84.     unsigned long int planeMask ;
  85.     pointer         pdstLine ;
  86. {
  87.     int        depth, i, linelength, width ;
  88.     DDXPointRec    pt ;
  89.     unsigned char *pbits ;
  90.     unsigned long int    gcv[2] ;
  91.     PixmapPtr    pPixmap = (PixmapPtr) NULL ;
  92.     GCPtr    pGC ;
  93.     unsigned char *pDst = (unsigned char *) pdstLine ;
  94.  
  95.     depth = pDraw->depth ;
  96.     if ( format == ZPixmap ) {
  97.     linelength = PixmapBytePad( w, depth ) ;
  98.     if ( pDraw->type == DRAWABLE_WINDOW ) {
  99.         sx += pDraw->x ;
  100.         sy += pDraw->y ;
  101.     }
  102.     if ( ( ( ( 1 << pDraw->depth ) - 1 ) & planeMask )
  103.          != ( 1 << pDraw->depth ) - 1 ) {
  104.         pGC = GetScratchGC( depth, pDraw->pScreen ) ;
  105.         pPixmap = (PixmapPtr)
  106.           (* pDraw->pScreen->CreatePixmap)( pDraw->pScreen, w, h, depth ) ;
  107.         gcv[0] = GXcopy ;
  108.         gcv[1] = planeMask ;
  109.         DoChangeGC( pGC, GCPlaneMask | GCFunction, gcv, 0 ) ;
  110.         ValidateGC( pPixmap, pGC ) ;
  111.  
  112.         pbits = (unsigned char *)ALLOCATE_LOCAL(w);
  113.  
  114.         for ( i = 0 ; i < h ; i++ ) {
  115.         pt.x = sx ;
  116.         pt.y = sy + i ;
  117.         width = w ;
  118.         (* pDraw->pScreen->GetSpans)( pDraw, w, &pt, &width, 1, pbits ) ;
  119.         pt.x = 0 ;
  120.         pt.y = 0 ;
  121.         width = w ;
  122.         (* pGC->ops->SetSpans)( pPixmap, pGC, pbits, &pt, &width, 1, TRUE ) ;
  123.         (* pDraw->pScreen->GetSpans)( pPixmap, w, &pt, &width, 1, pDst ) ;
  124.         pDst += linelength ;
  125.         }
  126.  
  127.         DEALLOCATE_LOCAL(pbits) ;
  128.         (* pGC->pScreen->DestroyPixmap)( pPixmap ) ;
  129.         FreeScratchGC( pGC ) ;
  130.         return ;
  131.     }
  132.  
  133.     for ( i = 0 ; i < h ; i++ ) {
  134.         pt.x = sx ;
  135.         pt.y = sy + i ;
  136.         width = w ;
  137.         (* pDraw->pScreen->GetSpans)( pDraw, w, &pt, &width, 1, pDst ) ;
  138.         pDst += linelength ;
  139.     }
  140.     }
  141.     else if ( ( pDraw->type == DRAWABLE_PIXMAP )
  142.       || ( GetBitsPerPixel( depth ) == 1 ) ) {
  143.     miGetImage( pDraw, sx, sy, w, h, format, planeMask, pdstLine ) ;
  144.     }
  145.     else {
  146.     sx += pDraw->x ;
  147.     sy += pDraw->y ;
  148.     (* ( (ppcScrnPriv *) pDraw->pScreen->devPrivate )->planeRead )( 
  149.                 ffs( planeMask ) - 1, sx, sy, w, h, pDst ) ;
  150.     }
  151.     return ;
  152. }
  153.