First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / xf4bpp / ppcImg.c
blob3691587aef81207cf1b660bceace5ab67c2774ae
1 /*
2 * Copyright IBM Corporation 1987,1988,1989
4 * All Rights Reserved
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.
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.
24 #ifdef HAVE_XORG_CONFIG_H
25 #include <xorg-config.h>
26 #endif
28 #include <stdlib.h>
30 #include "xf4bpp.h"
31 #include "OScompiler.h"
32 #include "mi.h"
33 #include "scrnintstr.h"
34 #include "servermd.h"
36 /* Was MIGETIMAGE -- public entry for the GetImage Request
37 * We're getting the image into a memory buffer. While we have to use GetSpans
38 * to read a line from the device ( since we don't know what that looks like ) ,
39 * we can just write into the destination buffer
41 * two different strategies are used, depending on whether we're getting the
42 * image in Z format or XY format
43 * Z format:
44 * Line at a time, GetSpans a line and bcopy it to the destination
45 * buffer, except that if the planemask is not all ones, we create a
46 * temporary pixmap and do a SetSpans into it ( to get bits turned off )
47 * and then another GetSpans to get stuff back ( because pixmaps are
48 * opaque, and we are passed in the memory to write into ) . This is
49 * completely ugly and slow but works, but the interfaces just aren't
50 * designed for this case. Life is hard.
51 * XY format:
52 * get the single plane specified in planemask
54 void
55 xf4bppGetImage( pDraw, sx, sy, w, h, format, planeMask, pdstLine )
56 DrawablePtr pDraw ;
57 int sx, sy, w, h ;
58 unsigned int format ;
59 unsigned long planeMask ;
60 char * pdstLine ;
62 #if 1
63 int depth, i, linelength, width ;
64 DDXPointRec pt ;
65 char *pbits ;
66 XID gcv[2] ;
67 PixmapPtr pPixmap = (PixmapPtr) NULL ;
68 GCPtr pGC ;
69 char *pDst = pdstLine ;
71 depth = pDraw->depth ;
72 if ( format == ZPixmap ) {
73 linelength = PixmapBytePad( w, depth ) ;
74 /* if ( pDraw->type == DRAWABLE_WINDOW ) { */
75 sx += pDraw->x ;
76 sy += pDraw->y ;
77 /* } */
78 if ( ( ( ( 1 << pDraw->depth ) - 1 ) & planeMask )
79 != (unsigned)( 1 << pDraw->depth ) - 1 ) {
80 pGC = GetScratchGC( depth, pDraw->pScreen ) ;
81 pPixmap = (PixmapPtr)
82 (* pDraw->pScreen->CreatePixmap)( pDraw->pScreen, w, h, depth ) ;
83 gcv[0] = GXcopy ;
84 gcv[1] = planeMask ;
85 DoChangeGC( pGC, GCPlaneMask | GCFunction, gcv, 0 ) ;
86 ValidateGC( (DrawablePtr)pPixmap, pGC ) ;
88 pbits = (char *)ALLOCATE_LOCAL(w);
90 for ( i = 0 ; i < h ; i++ ) {
91 pt.x = sx ;
92 pt.y = sy + i ;
93 width = w ;
94 (* pDraw->pScreen->GetSpans)( pDraw, w, &pt, &width, 1, pbits ) ;
95 pt.x = 0 ;
96 pt.y = i ;
97 width = w ;
98 if ( planeMask & ((1 << depth) - 1) ) /* GJA -- mfb bug */
99 (* pGC->ops->SetSpans)( (DrawablePtr)pPixmap, pGC, pbits, &pt, &width, 1, TRUE ) ;
100 (* pDraw->pScreen->GetSpans)( (DrawablePtr)pPixmap, w, &pt, &width, 1, pDst ) ;
101 pDst += linelength ;
104 DEALLOCATE_LOCAL(pbits) ;
105 (* pGC->pScreen->DestroyPixmap)( pPixmap ) ;
106 FreeScratchGC( pGC ) ;
107 return ;
110 for ( i = 0 ; i < h ; i++ ) {
111 pt.x = sx ;
112 pt.y = sy + i ;
113 width = w ;
114 (* pDraw->pScreen->GetSpans)( pDraw, w, &pt, &width, 1, pDst ) ;
115 pDst += linelength ;
118 else
119 #endif
120 miGetImage( pDraw, sx, sy, w, h, format, planeMask, pdstLine ) ;