xm_image.c

Go to the documentation of this file.
00001 /**************************************************************************
00002 
00003 Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
00004 All Rights Reserved.
00005 
00006 Permission is hereby granted, free of charge, to any person obtaining a
00007 copy of this software and associated documentation files (the
00008 "Software"), to deal in the Software without restriction, including
00009 without limitation the rights to use, copy, modify, merge, publish,
00010 distribute, sub license, and/or sell copies of the Software, and to
00011 permit persons to whom the Software is furnished to do so, subject to
00012 the following conditions:
00013 
00014 The above copyright notice and this permission notice (including the
00015 next paragraph) shall be included in all copies or substantial portions
00016 of the Software.
00017 
00018 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
00022 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025 
00026 **************************************************************************/
00027 
00028 /*
00029  * Authors:
00030  *   Kevin E. Martin <kevin@precisioninsight.com>
00031  *   Brian Paul <brian@precisioninsight.com>
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         /* Always pad to 32 bits */
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: /* WARNING: architecture specific code */
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: /* WARNING: architecture specific code */
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 /* XFree86Server */

Generated on Tue Sep 29 06:25:18 2009 for Gallium3D by  doxygen 1.5.4