home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xibm.zip / ibm8514 / brcPlane.c < prev    next >
C/C++ Source or Header  |  1991-10-02  |  3KB  |  98 lines

  1. /*
  2.  * $Id: brcPlane.c,v 1.1 1991/09/20 19:10:24 mtranle Exp $
  3.  *
  4.  * Copyright IBM Corporation 1987,1988,1989
  5.  *
  6.  * All Rights Reserved
  7.  *
  8.  * Permission to use, copy, modify, and distribute this software and its
  9.  * documentation for any purpose and without fee is hereby granted,
  10.  * provided that the above copyright notice appear in all copies and that 
  11.  * both that copyright notice and this permission notice appear in
  12.  * supporting documentation, and that the name of IBM not be
  13.  * used in advertising or publicity pertaining to distribution of the
  14.  * software without specific, written prior permission.
  15.  *
  16.  * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  17.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  18.  * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  19.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  21.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  22.  * SOFTWARE.
  23.  *
  24. */
  25.  
  26. #include "X.h"
  27. #include "Xmd.h"
  28. #include "servermd.h"
  29. #include "os.h"
  30.  
  31. #include "OScompiler.h"
  32.  
  33. #include "ibmTrace.h"
  34.  
  35. /***==================================================================***/
  36.  
  37.  
  38. /* Was MIGETPLANE -- gets a bitmap representing one plane of pDraw
  39.  * A helper used for CopyPlane and XY format GetImage
  40.  * No clever strategy here, we grab a scanline at a time, pull out the
  41.  * bits and then stuff them in a 1 bit deep map.
  42.  */
  43. unsigned long *
  44. ibm8514GetPlane( planeNum, sx, sy, w, h, result )
  45.     int planeNum ;    /* number of the bitPlane */
  46.     int sx, sy, w, h ;
  47.     unsigned long *result ;
  48. {
  49.     int i, j, k ;
  50.     register unsigned char *pp ;
  51.     unsigned char *pline ;
  52.     unsigned long int bit ;
  53. #if BITMAP_SCANLINE_UNIT == 8
  54.     register unsigned char tmpScanUnitOut ;
  55.     unsigned char *pScanUnitOut = (unsigned char *) result ;
  56. #endif
  57. #if BITMAP_SCANLINE_UNIT == 16
  58.     register CARD16 tmpScanUnitOut ;
  59.     CARD16 *pScanUnitOut = (CARD16 *) result ;
  60. #endif
  61. #if BITMAP_SCANLINE_UNIT == 32
  62.     register CARD32 tmpScanUnitOut ;
  63.     CARD32 *pScanUnitOut = (CARD32 *) result ;
  64. #endif
  65.  
  66. TRACE( ( "ibm8514GetPlane(%d,%d,%d,%d,%d,0x%X)\n",
  67.        planeNum, sx, sy, w, h, result ) ) ;
  68.  
  69.     pline = (unsigned char *) ALLOCATE_LOCAL( w ) ;
  70.  
  71.     for ( i = sy ; i < sy + h ; i++ ) {
  72.     /* Fetch the next line */
  73.     ibm8514ReadColorImage( sx, i, w, 1, pline, w ) ;
  74.     for ( j = 0, pp = pline, tmpScanUnitOut = 0, k = 0 ;
  75.           j < w ;
  76.           j++, pp++ ) {
  77.         bit = (unsigned long int) ( ( *pp >> planeNum ) & 1 ) ;
  78.         /* Now insert that bit into a bitmap in XY format */
  79. #if (BITMAP_BIT_ORDER == LSBFIRST)
  80.         bit >> = k ;
  81. #else
  82.         bit <<= ( ( BITMAP_SCANLINE_UNIT - 1 ) - k ) ;
  83. #endif
  84.         tmpScanUnitOut |= bit ;
  85.         if ( ++k == BITMAP_SCANLINE_UNIT ) {
  86.         *pScanUnitOut++ = tmpScanUnitOut ;
  87.         tmpScanUnitOut = 0 ;
  88.         k = 0 ;
  89.         }
  90.         }
  91.     if ( k )
  92.       *pScanUnitOut++ = tmpScanUnitOut ;
  93.     }
  94.     DEALLOCATE_LOCAL( pline ) ;
  95.  
  96.     return result ;
  97. }
  98.