087b4e4c3a7c81f02c4049c625ce981cde94eb76
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>
37 #include "glxheader.h"
46 #define ROUNDUP(nbytes, pad) ((((nbytes) + ((pad)-1)) / (pad)) * ((pad)>>3))
48 XMesaImage
*XMesaCreateImage(int bitsPerPixel
, int width
, int height
, char *data
)
52 image
= (XMesaImage
*)xalloc(sizeof(XMesaImage
));
56 image
->height
= height
;
58 /* Always pad to 32 bits */
59 image
->bytes_per_line
= ROUNDUP((bitsPerPixel
* width
), 32);
60 image
->bits_per_pixel
= bitsPerPixel
;
66 void XMesaDestroyImage(XMesaImage
*image
)
73 unsigned long XMesaGetPixel(XMesaImage
*image
, int x
, int y
)
75 CARD8
*row
= (CARD8
*)(image
->data
+ y
*image
->bytes_per_line
);
79 switch (image
->bits_per_pixel
) {
89 case 24: /* WARNING: architecture specific code */
91 return (((CARD32
)i8
[x
*3]) |
92 (((CARD32
)i8
[x
*3+1])<<8) |
93 (((CARD32
)i8
[x
*3+2])<<16));
103 #ifndef XMESA_USE_PUTPIXEL_MACRO
104 void XMesaPutPixel(XMesaImage
*image
, int x
, int y
, unsigned long pixel
)
106 CARD8
*row
= (CARD8
*)(image
->data
+ y
*image
->bytes_per_line
);
110 switch (image
->bits_per_pixel
) {
113 i8
[x
] = (CARD8
)pixel
;
118 i16
[x
] = (CARD16
)pixel
;
120 case 24: /* WARNING: architecture specific code */
122 i8
[x
*3] = (CARD8
)(p
);
123 i8
[x
*3+1] = (CARD8
)(p
>>8);
124 i8
[x
*3+2] = (CARD8
)(p
>>16);
127 i32
[x
] = (CARD32
)pixel
;
133 #endif /* XFree86Server */