00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <stdlib.h>
00035 #include <X11/Xmd.h>
00036
00037 #include "glxheader.h"
00038 #include "xmesaP.h"
00039
00040 #ifdef XFree86Server
00041
00042 #ifdef ROUNDUP
00043 #undef ROUNDUP
00044 #endif
00045
00046 #define ROUNDUP(nbytes, pad) ((((nbytes) + ((pad)-1)) / (pad)) * ((pad)>>3))
00047
00048 XMesaImage *XMesaCreateImage(int bitsPerPixel, int width, int height, char *data)
00049 {
00050 XMesaImage *image;
00051
00052 image = (XMesaImage *)xalloc(sizeof(XMesaImage));
00053
00054 if (image) {
00055 image->width = width;
00056 image->height = height;
00057 image->data = data;
00058
00059 image->bytes_per_line = ROUNDUP((bitsPerPixel * width), 32);
00060 image->bits_per_pixel = bitsPerPixel;
00061 }
00062
00063 return image;
00064 }
00065
00066 void XMesaDestroyImage(XMesaImage *image)
00067 {
00068 if (image->data)
00069 free(image->data);
00070 xfree(image);
00071 }
00072
00073 unsigned long XMesaGetPixel(XMesaImage *image, int x, int y)
00074 {
00075 CARD8 *row = (CARD8 *)(image->data + y*image->bytes_per_line);
00076 CARD8 *i8;
00077 CARD16 *i16;
00078 CARD32 *i32;
00079 switch (image->bits_per_pixel) {
00080 case 8:
00081 i8 = (CARD8 *)row;
00082 return i8[x];
00083 break;
00084 case 15:
00085 case 16:
00086 i16 = (CARD16 *)row;
00087 return i16[x];
00088 break;
00089 case 24:
00090 i8 = (CARD8 *)row;
00091 return (((CARD32)i8[x*3]) |
00092 (((CARD32)i8[x*3+1])<<8) |
00093 (((CARD32)i8[x*3+2])<<16));
00094 break;
00095 case 32:
00096 i32 = (CARD32 *)row;
00097 return i32[x];
00098 break;
00099 }
00100 return 0;
00101 }
00102
00103 #ifndef XMESA_USE_PUTPIXEL_MACRO
00104 void XMesaPutPixel(XMesaImage *image, int x, int y, unsigned long pixel)
00105 {
00106 CARD8 *row = (CARD8 *)(image->data + y*image->bytes_per_line);
00107 CARD8 *i8;
00108 CARD16 *i16;
00109 CARD32 *i32;
00110 switch (image->bits_per_pixel) {
00111 case 8:
00112 i8 = (CARD8 *)row;
00113 i8[x] = (CARD8)pixel;
00114 break;
00115 case 15:
00116 case 16:
00117 i16 = (CARD16 *)row;
00118 i16[x] = (CARD16)pixel;
00119 break;
00120 case 24:
00121 i8 = (CARD8 *)__row;
00122 i8[x*3] = (CARD8)(p);
00123 i8[x*3+1] = (CARD8)(p>>8);
00124 i8[x*3+2] = (CARD8)(p>>16);
00125 case 32:
00126 i32 = (CARD32 *)row;
00127 i32[x] = (CARD32)pixel;
00128 break;
00129 }
00130 }
00131 #endif
00132
00133 #endif