6af773f538439deded6efce07c9dc6eab0cbd0b1
1 /**************************************************************************
3 Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sub license, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
14 The above copyright notice and this permission notice (including the
15 next paragraph) shall be included in all copies or substantial portions
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
22 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 * Kevin E. Martin <kevin@precisioninsight.com>
31 * Brian Paul <brian@precisioninsight.com>
34 #ifdef HAVE_DIX_CONFIG_H
35 #include <dix-config.h>
40 #include "xf86glx_util.h"
47 #define ROUNDUP(nbytes, pad) ((((nbytes) + ((pad)-1)) / (pad)) * ((pad)>>3))
49 XMesaImage
*XMesaCreateImage(int bitsPerPixel
, int width
, int height
, char *data
)
53 image
= (XMesaImage
*)xalloc(sizeof(XMesaImage
));
57 image
->height
= height
;
59 /* Always pad to 32 bits */
60 image
->bytes_per_line
= ROUNDUP((bitsPerPixel
* width
), 32);
61 image
->bits_per_pixel
= bitsPerPixel
;
67 void XMesaDestroyImage(XMesaImage
*image
)
74 unsigned long XMesaGetPixel(XMesaImage
*image
, int x
, int y
)
76 CARD8
*row
= (CARD8
*)(image
->data
+ y
*image
->bytes_per_line
);
80 switch (image
->bits_per_pixel
) {
90 case 24: /* WARNING: architecture specific code */
92 return (((CARD32
)i8
[x
*3]) |
93 (((CARD32
)i8
[x
*3+1])<<8) |
94 (((CARD32
)i8
[x
*3+2])<<16));
104 #ifndef XMESA_USE_PUTPIXEL_MACRO
105 void XMesaPutPixel(XMesaImage
*image
, int x
, int y
, unsigned long pixel
)
107 CARD8
*row
= (CARD8
*)(image
->data
+ y
*image
->bytes_per_line
);
111 switch (image
->bits_per_pixel
) {
114 i8
[x
] = (CARD8
)pixel
;
119 i16
[x
] = (CARD16
)pixel
;
121 case 24: /* WARNING: architecture specific code */
123 i8
[x
*3] = (CARD8
)(p
);
124 i8
[x
*3+1] = (CARD8
)(p
>>8);
125 i8
[x
*3+2] = (CARD8
)(p
>>16);
128 i32
[x
] = (CARD32
)pixel
;
134 void XMesaPutImageHelper(ScreenPtr display
,
135 DrawablePtr d
, GCPtr gc
,
137 int src_x
, int src_y
,
138 int dest_x
, int dest_y
,
139 unsigned int width
, unsigned int height
)
141 /* NOT_DONE: Verify that the following works for all depths */
142 char *src
= (image
->data
+
143 src_y
* image
->bytes_per_line
+
144 ((src_x
* image
->bits_per_pixel
) >> 3));
147 (*gc
->ops
->PutImage
)(d
, gc
, d
->depth
, dest_x
, dest_y
, width
, height
,