Back to index

lightning-sunbird  0.9+nobinonly
icint.h
Go to the documentation of this file.
00001 /*
00002  * Copyright © 2003 Carl Worth
00003  *
00004  * Permission to use, copy, modify, distribute, and sell this software and its
00005  * documentation for any purpose is hereby granted without fee, provided that
00006  * the above copyright notice appear in all copies and that both that
00007  * copyright notice and this permission notice appear in supporting
00008  * documentation, and that the name of Carl Worth not be used in
00009  * advertising or publicity pertaining to distribution of the software without
00010  * specific, written prior permission.  Carl Worth makes no
00011  * representations about the suitability of this software for any purpose.  It
00012  * is provided "as is" without express or implied warranty.
00013  *
00014  * CARL WORTH DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
00015  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
00016  * EVENT SHALL CARL WORTH BE LIABLE FOR ANY SPECIAL, INDIRECT OR
00017  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
00018  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
00019  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00020  * PERFORMANCE OF THIS SOFTWARE.
00021  */
00022 
00023 #ifndef _ICINT_H_
00024 #define _ICINT_H_
00025 
00026 #ifdef HAVE_CONFIG_H
00027 #  include "config.h"
00028 #endif
00029 
00030 #include "pixman.h"
00031 
00032 #include <stdlib.h>
00033 #include <string.h>
00034 #include <limits.h>
00035 
00036 #include "slim_internal.h"
00037 
00038 /* Include NSPR's prcpucfg.h for endianness information */
00039 #include "prcpucfg.h"
00040 
00041 #ifndef __GNUC__
00042 #define __inline
00043 #endif
00044 
00045 #if defined(__GNUC__)
00046 #define INLINE __inline__
00047 #else
00048 #define INLINE
00049 #endif
00050 
00051 #define MIN(a,b) ((a) < (b) ? (a) : (b))
00052 #define MAX(a,b) ((a) > (b) ? (a) : (b))
00053 
00054 /* C89 has implementation-defined behavior for % with negative operands.
00055    C99 has well-defined behavior which is that / with integers rounds toward zero
00056        and a%b is defined so that (a/b)*b + a%b == a.
00057 
00058    The C99 version gives negative remainders rather than the modulus
00059    in [0 .. b-1] that we want. This macro avoids using % with negative
00060    operands to avoid both problems.
00061 
00062    a and b are integers. b > 0.
00063 */
00064 #define MOD(a, b) ((b) == 1 ? 0 : (a) >= 0 ? (a) % (b) : (b) - (-(a) - 1) % (b) - 1)
00065 
00066 typedef struct _FbPoint {
00067        int16_t    x,y ;
00068 } FbPoint;
00069 
00070 typedef unsigned int Mask;
00071 
00072 
00073 #define GXcopy              0x3
00074 #define GXor         0x7
00075 #define ClipByChildren  0
00076 #define PolyEdgeSharp   0
00077 #define PolyModePrecise 0
00078 #define CPClipMask      (1 << 6)
00079 #define CPLastBit       11
00080 
00081 
00082 /* Define any names that the server code will be expecting in
00083  * terms of libpixman names. */
00084 
00085 typedef uint8_t                    CARD8;
00086 typedef uint16_t            CARD16;
00087 typedef uint32_t            CARD32;
00088 typedef int16_t                    INT16;
00089 
00090 typedef int                 Bool;
00091 #define FALSE 0
00092 #define TRUE  1
00093 
00094 typedef pixman_bits_t              FbBits;
00095 typedef pixman_image_t*            PicturePtr;
00096 typedef pixman_box16_t             BoxRec;
00097 typedef pixman_box16_t*            BoxPtr;
00098 
00099 typedef pixman_point_fixed_t       xPointFixed;
00100 typedef pixman_line_fixed_t xLineFixed;
00101 typedef pixman_trapezoid_t  xTrapezoid;
00102 typedef pixman_triangle_t   xTriangle;
00103 
00104 /* These few definitions avoid me needing to include servermd.h and misc.h from Xserver/include */
00105 #ifndef BITMAP_SCANLINE_PAD
00106 #define BITMAP_SCANLINE_PAD  32
00107 #define LOG2_BITMAP_PAD            5
00108 #define LOG2_BYTES_PER_SCANLINE_PAD       2
00109 #endif
00110 
00111 #define LSBFirst 0
00112 #define MSBFirst 1
00113 
00114 #if defined(WORDS_BIGENDIAN) || defined(IS_BIG_ENDIAN)
00115 #  define IMAGE_BYTE_ORDER MSBFirst
00116 #  define BITMAP_BIT_ORDER MSBFirst
00117 #else
00118 #  define IMAGE_BYTE_ORDER LSBFirst
00119 #  define BITMAP_BIT_ORDER LSBFirst
00120 #endif
00121 
00122 
00123 #define MAXSHORT SHRT_MAX
00124 #define MINSHORT SHRT_MIN
00125 
00126 /* XXX: What do we need from here?
00127 #include "picture.h"
00128 */
00129 
00130 
00131 
00132 #include "pixman.h"
00133 
00134 /* XXX: Most of this file is straight from fb.h and I imagine we can
00135    drop quite a bit of it. Once the real ic code starts to come
00136    together I can probably figure out what is not needed here. */
00137 
00138 #define FB_UNIT          (1 << FB_SHIFT)
00139 #define FB_HALFUNIT (1 << (FB_SHIFT-1))
00140 #define FB_MASK          (FB_UNIT - 1)
00141 #define FB_ALLONES  ((pixman_bits_t) -1)
00142     
00143 /* whether to bother to include 24bpp support */
00144 #ifndef ICNO24BIT
00145 #define FB_24BIT
00146 #endif
00147 
00148 /*
00149  * Unless otherwise instructed, ic includes code to advertise 24bpp
00150  * windows with 32bpp image format for application compatibility
00151  */
00152 
00153 #ifdef FB_24BIT
00154 #ifndef ICNO24_32
00155 #define FB_24_32BIT
00156 #endif
00157 #endif
00158 
00159 #define FB_STIP_SHIFT       LOG2_BITMAP_PAD
00160 #define FB_STIP_UNIT (1 << FB_STIP_SHIFT)
00161 #define FB_STIP_MASK (FB_STIP_UNIT - 1)
00162 #define FB_STIP_ALLONES     ((FbStip) -1)
00163     
00164 #define FB_STIP_ODDSTRIDE(s)       (((s) & (FB_MASK >> FB_STIP_SHIFT)) != 0)
00165 #define FB_STIP_ODDPTR(p)   ((((long) (p)) & (FB_MASK >> 3)) != 0)
00166     
00167 #define FbStipStrideToBitsStride(s) (((s) >> (FB_SHIFT - FB_STIP_SHIFT)))
00168 #define FbBitsStrideToStipStride(s) (((s) << (FB_SHIFT - FB_STIP_SHIFT)))
00169     
00170 #define FbFullMask(n)   ((n) == FB_UNIT ? FB_ALLONES : ((((FbBits) 1) << n) - 1))
00171 
00172 
00173 typedef uint32_t         FbStip;
00174 typedef int              FbStride;
00175 
00176 
00177 #ifdef FB_DEBUG
00178 extern void fbValidateDrawable(DrawablePtr d);
00179 extern void fbInitializeDrawable(DrawablePtr d);
00180 extern void fbSetBits (FbStip *bits, int stride, FbStip data);
00181 #define FB_HEAD_BITS   (FbStip) (0xbaadf00d)
00182 #define FB_TAIL_BITS   (FbStip) (0xbaddf0ad)
00183 #else
00184 #define fbValidateDrawable(d)
00185 #define fdInitializeDrawable(d)
00186 #endif
00187 
00188 #if BITMAP_BIT_ORDER == LSBFirst
00189 #define FbScrLeft(x,n)      ((x) >> (n))
00190 #define FbScrRight(x,n)     ((x) << (n))
00191 /* #define FbLeftBits(x,n)  ((x) & ((((FbBits) 1) << (n)) - 1)) */
00192 #define FbLeftStipBits(x,n) ((x) & ((((FbStip) 1) << (n)) - 1))
00193 #define FbStipMoveLsb(x,s,n)       (FbStipRight (x,(s)-(n)))
00194 #define FbPatternOffsetBits 0
00195 #else
00196 #define FbScrLeft(x,n)      ((x) << (n))
00197 #define FbScrRight(x,n)     ((x) >> (n))
00198 /* #define FbLeftBits(x,n)  ((x) >> (FB_UNIT - (n))) */
00199 #define FbLeftStipBits(x,n) ((x) >> (FB_STIP_UNIT - (n)))
00200 #define FbStipMoveLsb(x,s,n)       (x)
00201 #define FbPatternOffsetBits (sizeof (FbBits) - 1)
00202 #endif
00203 
00204 #define FbStipLeft(x,n)     FbScrLeft(x,n)
00205 #define FbStipRight(x,n) FbScrRight(x,n)
00206 
00207 #define FbRotLeft(x,n)      FbScrLeft(x,n) | (n ? FbScrRight(x,FB_UNIT-n) : 0)
00208 #define FbRotRight(x,n)     FbScrRight(x,n) | (n ? FbScrLeft(x,FB_UNIT-n) : 0)
00209 
00210 #define FbRotStipLeft(x,n)  FbStipLeft(x,n) | (n ? FbStipRight(x,FB_STIP_UNIT-n) : 0)
00211 #define FbRotStipRight(x,n)  FbStipRight(x,n) | (n ? FbStipLeft(x,FB_STIP_UNIT-n) : 0)
00212 
00213 #define FbLeftMask(x)           ( ((x) & FB_MASK) ? \
00214                           FbScrRight(FB_ALLONES,(x) & FB_MASK) : 0)
00215 #define FbRightMask(x)          ( ((FB_UNIT - (x)) & FB_MASK) ? \
00216                           FbScrLeft(FB_ALLONES,(FB_UNIT - (x)) & FB_MASK) : 0)
00217 
00218 #define FbLeftStipMask(x)   ( ((x) & FB_STIP_MASK) ? \
00219                           FbStipRight(FB_STIP_ALLONES,(x) & FB_STIP_MASK) : 0)
00220 #define FbRightStipMask(x)  ( ((FB_STIP_UNIT - (x)) & FB_STIP_MASK) ? \
00221                           FbScrLeft(FB_STIP_ALLONES,(FB_STIP_UNIT - (x)) & FB_STIP_MASK) : 0)
00222 
00223 #define FbBitsMask(x,w)     (FbScrRight(FB_ALLONES,(x) & FB_MASK) & \
00224                       FbScrLeft(FB_ALLONES,(FB_UNIT - ((x) + (w))) & FB_MASK))
00225 
00226 #define FbStipMask(x,w)     (FbStipRight(FB_STIP_ALLONES,(x) & FB_STIP_MASK) & \
00227                       FbStipLeft(FB_STIP_ALLONES,(FB_STIP_UNIT - ((x)+(w))) & FB_STIP_MASK))
00228 
00229 
00230 #define FbMaskBits(x,w,l,n,r) { \
00231     n = (w); \
00232     r = FbRightMask((x)+n); \
00233     l = FbLeftMask(x); \
00234     if (l) { \
00235        n -= FB_UNIT - ((x) & FB_MASK); \
00236        if (n < 0) { \
00237            n = 0; \
00238            l &= r; \
00239            r = 0; \
00240        } \
00241     } \
00242     n >>= FB_SHIFT; \
00243 }
00244 
00245 #ifdef ICNOPIXADDR
00246 #define FbMaskBitsBytes(x,w,copy,l,lb,n,r,rb) FbMaskBits(x,w,l,n,r)
00247 #define FbDoLeftMaskByteRRop(dst,lb,l,and,xor) { \
00248     *dst = FbDoMaskRRop(*dst,and,xor,l); \
00249 }
00250 #define FbDoRightMaskByteRRop(dst,rb,r,and,xor) { \
00251     *dst = FbDoMaskRRop(*dst,and,xor,r); \
00252 }
00253 #else
00254 
00255 #define FbByteMaskInvalid   0x10
00256 
00257 #define FbPatternOffset(o,t)  ((o) ^ (FbPatternOffsetBits & ~(sizeof (t) - 1)))
00258 
00259 #define FbPtrOffset(p,o,t)         ((t *) ((CARD8 *) (p) + (o)))
00260 #define FbSelectPatternPart(xor,o,t)      ((xor) >> (FbPatternOffset (o,t) << 3))
00261 #define FbStorePart(dst,off,t,xor) (*FbPtrOffset(dst,off,t) = \
00262                                     FbSelectPart(xor,off,t))
00263 #ifndef FbSelectPart
00264 #define FbSelectPart(x,o,t) FbSelectPatternPart(x,o,t)
00265 #endif
00266 
00267 #define FbMaskBitsBytes(x,w,copy,l,lb,n,r,rb) { \
00268     n = (w); \
00269     lb = 0; \
00270     rb = 0; \
00271     r = FbRightMask((x)+n); \
00272     if (r) { \
00273        /* compute right byte length */ \
00274        if ((copy) && (((x) + n) & 7) == 0) { \
00275            rb = (((x) + n) & FB_MASK) >> 3; \
00276        } else { \
00277            rb = FbByteMaskInvalid; \
00278        } \
00279     } \
00280     l = FbLeftMask(x); \
00281     if (l) { \
00282        /* compute left byte length */ \
00283        if ((copy) && ((x) & 7) == 0) { \
00284            lb = ((x) & FB_MASK) >> 3; \
00285        } else { \
00286            lb = FbByteMaskInvalid; \
00287        } \
00288        /* subtract out the portion painted by leftMask */ \
00289        n -= FB_UNIT - ((x) & FB_MASK); \
00290        if (n < 0) { \
00291            if (lb != FbByteMaskInvalid) { \
00292               if (rb == FbByteMaskInvalid) { \
00293                   lb = FbByteMaskInvalid; \
00294               } else if (rb) { \
00295                   lb |= (rb - lb) << (FB_SHIFT - 3); \
00296                   rb = 0; \
00297               } \
00298            } \
00299            n = 0; \
00300            l &= r; \
00301            r = 0; \
00302        }\
00303     } \
00304     n >>= FB_SHIFT; \
00305 }
00306 
00307 #if FB_SHIFT == 6
00308 #define FbDoLeftMaskByteRRop6Cases(dst,xor) \
00309     case (sizeof (FbBits) - 7) | (1 << (FB_SHIFT - 3)): \
00310        FbStorePart(dst,sizeof (FbBits) - 7,CARD8,xor); \
00311        break; \
00312     case (sizeof (FbBits) - 7) | (2 << (FB_SHIFT - 3)): \
00313        FbStorePart(dst,sizeof (FbBits) - 7,CARD8,xor); \
00314        FbStorePart(dst,sizeof (FbBits) - 6,CARD8,xor); \
00315        break; \
00316     case (sizeof (FbBits) - 7) | (3 << (FB_SHIFT - 3)): \
00317        FbStorePart(dst,sizeof (FbBits) - 7,CARD8,xor); \
00318        FbStorePart(dst,sizeof (FbBits) - 6,CARD16,xor); \
00319        break; \
00320     case (sizeof (FbBits) - 7) | (4 << (FB_SHIFT - 3)): \
00321        FbStorePart(dst,sizeof (FbBits) - 7,CARD8,xor); \
00322        FbStorePart(dst,sizeof (FbBits) - 6,CARD16,xor); \
00323        FbStorePart(dst,sizeof (FbBits) - 4,CARD8,xor); \
00324        break; \
00325     case (sizeof (FbBits) - 7) | (5 << (FB_SHIFT - 3)): \
00326        FbStorePart(dst,sizeof (FbBits) - 7,CARD8,xor); \
00327        FbStorePart(dst,sizeof (FbBits) - 6,CARD16,xor); \
00328        FbStorePart(dst,sizeof (FbBits) - 4,CARD16,xor); \
00329        break; \
00330     case (sizeof (FbBits) - 7) | (6 << (FB_SHIFT - 3)): \
00331        FbStorePart(dst,sizeof (FbBits) - 7,CARD8,xor); \
00332        FbStorePart(dst,sizeof (FbBits) - 6,CARD16,xor); \
00333        FbStorePart(dst,sizeof (FbBits) - 4,CARD16,xor); \
00334        FbStorePart(dst,sizeof (FbBits) - 2,CARD8,xor); \
00335        break; \
00336     case (sizeof (FbBits) - 7): \
00337        FbStorePart(dst,sizeof (FbBits) - 7,CARD8,xor); \
00338        FbStorePart(dst,sizeof (FbBits) - 6,CARD16,xor); \
00339        FbStorePart(dst,sizeof (FbBits) - 4,CARD32,xor); \
00340        break; \
00341     case (sizeof (FbBits) - 6) | (1 << (FB_SHIFT - 3)): \
00342        FbStorePart(dst,sizeof (FbBits) - 6,CARD8,xor); \
00343        break; \
00344     case (sizeof (FbBits) - 6) | (2 << (FB_SHIFT - 3)): \
00345        FbStorePart(dst,sizeof (FbBits) - 6,CARD16,xor); \
00346        break; \
00347     case (sizeof (FbBits) - 6) | (3 << (FB_SHIFT - 3)): \
00348        FbStorePart(dst,sizeof (FbBits) - 6,CARD16,xor); \
00349        FbStorePart(dst,sizeof (FbBits) - 4,CARD8,xor); \
00350        break; \
00351     case (sizeof (FbBits) - 6) | (4 << (FB_SHIFT - 3)): \
00352        FbStorePart(dst,sizeof (FbBits) - 6,CARD16,xor); \
00353        FbStorePart(dst,sizeof (FbBits) - 4,CARD16,xor); \
00354        break; \
00355     case (sizeof (FbBits) - 6) | (5 << (FB_SHIFT - 3)): \
00356        FbStorePart(dst,sizeof (FbBits) - 6,CARD16,xor); \
00357        FbStorePart(dst,sizeof (FbBits) - 4,CARD16,xor); \
00358        FbStorePart(dst,sizeof (FbBits) - 2,CARD8,xor); \
00359        break; \
00360     case (sizeof (FbBits) - 6): \
00361        FbStorePart(dst,sizeof (FbBits) - 6,CARD16,xor); \
00362        FbStorePart(dst,sizeof (FbBits) - 4,CARD32,xor); \
00363        break; \
00364     case (sizeof (FbBits) - 5) | (1 << (FB_SHIFT - 3)): \
00365        FbStorePart(dst,sizeof (FbBits) - 5,CARD8,xor); \
00366        break; \
00367     case (sizeof (FbBits) - 5) | (2 << (FB_SHIFT - 3)): \
00368        FbStorePart(dst,sizeof (FbBits) - 5,CARD8,xor); \
00369        FbStorePart(dst,sizeof (FbBits) - 4,CARD8,xor); \
00370        break; \
00371     case (sizeof (FbBits) - 5) | (3 << (FB_SHIFT - 3)): \
00372        FbStorePart(dst,sizeof (FbBits) - 5,CARD8,xor); \
00373        FbStorePart(dst,sizeof (FbBits) - 4,CARD16,xor); \
00374        break; \
00375     case (sizeof (FbBits) - 5) | (4 << (FB_SHIFT - 3)): \
00376        FbStorePart(dst,sizeof (FbBits) - 5,CARD8,xor); \
00377        FbStorePart(dst,sizeof (FbBits) - 4,CARD16,xor); \
00378        FbStorePart(dst,sizeof (FbBits) - 2,CARD8,xor); \
00379        break; \
00380     case (sizeof (FbBits) - 5): \
00381        FbStorePart(dst,sizeof (FbBits) - 5,CARD8,xor); \
00382        FbStorePart(dst,sizeof (FbBits) - 4,CARD32,xor); \
00383        break; \
00384     case (sizeof (FbBits) - 4) | (1 << (FB_SHIFT - 3)): \
00385        FbStorePart(dst,sizeof (FbBits) - 4,CARD8,xor); \
00386        break; \
00387     case (sizeof (FbBits) - 4) | (2 << (FB_SHIFT - 3)): \
00388        FbStorePart(dst,sizeof (FbBits) - 4,CARD16,xor); \
00389        break; \
00390     case (sizeof (FbBits) - 4) | (3 << (FB_SHIFT - 3)): \
00391        FbStorePart(dst,sizeof (FbBits) - 4,CARD16,xor); \
00392        FbStorePart(dst,sizeof (FbBits) - 2,CARD8,xor); \
00393        break; \
00394     case (sizeof (FbBits) - 4): \
00395        FbStorePart(dst,sizeof (FbBits) - 4,CARD32,xor); \
00396        break;
00397 
00398 #define FbDoRightMaskByteRRop6Cases(dst,xor) \
00399     case 4: \
00400        FbStorePart(dst,0,CARD32,xor); \
00401        break; \
00402     case 5: \
00403        FbStorePart(dst,0,CARD32,xor); \
00404        FbStorePart(dst,4,CARD8,xor); \
00405        break; \
00406     case 6: \
00407        FbStorePart(dst,0,CARD32,xor); \
00408        FbStorePart(dst,4,CARD16,xor); \
00409        break; \
00410     case 7: \
00411        FbStorePart(dst,0,CARD32,xor); \
00412        FbStorePart(dst,4,CARD16,xor); \
00413        FbStorePart(dst,6,CARD8,xor); \
00414        break;
00415 #else
00416 #define FbDoLeftMaskByteRRop6Cases(dst,xor)
00417 #define FbDoRightMaskByteRRop6Cases(dst,xor)
00418 #endif
00419 
00420 #define FbDoLeftMaskByteRRop(dst,lb,l,and,xor) { \
00421     switch (lb) { \
00422     FbDoLeftMaskByteRRop6Cases(dst,xor) \
00423     case (sizeof (FbBits) - 3) | (1 << (FB_SHIFT - 3)): \
00424        FbStorePart(dst,sizeof (FbBits) - 3,CARD8,xor); \
00425        break; \
00426     case (sizeof (FbBits) - 3) | (2 << (FB_SHIFT - 3)): \
00427        FbStorePart(dst,sizeof (FbBits) - 3,CARD8,xor); \
00428        FbStorePart(dst,sizeof (FbBits) - 2,CARD8,xor); \
00429        break; \
00430     case (sizeof (FbBits) - 2) | (1 << (FB_SHIFT - 3)): \
00431        FbStorePart(dst,sizeof (FbBits) - 2,CARD8,xor); \
00432        break; \
00433     case sizeof (FbBits) - 3: \
00434        FbStorePart(dst,sizeof (FbBits) - 3,CARD8,xor); \
00435     case sizeof (FbBits) - 2: \
00436        FbStorePart(dst,sizeof (FbBits) - 2,CARD16,xor); \
00437        break; \
00438     case sizeof (FbBits) - 1: \
00439        FbStorePart(dst,sizeof (FbBits) - 1,CARD8,xor); \
00440        break; \
00441     default: \
00442        *dst = FbDoMaskRRop(*dst, and, xor, l); \
00443        break; \
00444     } \
00445 }
00446 
00447 
00448 #define FbDoRightMaskByteRRop(dst,rb,r,and,xor) { \
00449     switch (rb) { \
00450     case 1: \
00451        FbStorePart(dst,0,CARD8,xor); \
00452        break; \
00453     case 2: \
00454        FbStorePart(dst,0,CARD16,xor); \
00455        break; \
00456     case 3: \
00457        FbStorePart(dst,0,CARD16,xor); \
00458        FbStorePart(dst,2,CARD8,xor); \
00459        break; \
00460     FbDoRightMaskByteRRop6Cases(dst,xor) \
00461     default: \
00462        *dst = FbDoMaskRRop (*dst, and, xor, r); \
00463     } \
00464 }
00465 #endif
00466 
00467 #define FbMaskStip(x,w,l,n,r) { \
00468     n = (w); \
00469     r = FbRightStipMask((x)+n); \
00470     l = FbLeftStipMask(x); \
00471     if (l) { \
00472        n -= FB_STIP_UNIT - ((x) & FB_STIP_MASK); \
00473        if (n < 0) { \
00474            n = 0; \
00475            l &= r; \
00476            r = 0; \
00477        } \
00478     } \
00479     n >>= FB_STIP_SHIFT; \
00480 }
00481 
00482 /*
00483  * These macros are used to transparently stipple
00484  * in copy mode; the expected usage is with 'n' constant
00485  * so all of the conditional parts collapse into a minimal
00486  * sequence of partial word writes
00487  *
00488  * 'n' is the bytemask of which bytes to store, 'a' is the address
00489  * of the FbBits base unit, 'o' is the offset within that unit
00490  *
00491  * The term "lane" comes from the hardware term "byte-lane" which
00492  */
00493 
00494 #define FbLaneCase1(n,a,o)  ((n) == 0x01 ? \
00495                           (*(CARD8 *) ((a)+FbPatternOffset(o,CARD8)) = \
00496                            fgxor) : 0)
00497 #define FbLaneCase2(n,a,o)  ((n) == 0x03 ? \
00498                           (*(CARD16 *) ((a)+FbPatternOffset(o,CARD16)) = \
00499                            fgxor) : \
00500                           ((void)FbLaneCase1((n)&1,a,o), \
00501                                 FbLaneCase1((n)>>1,a,(o)+1)))
00502 #define FbLaneCase4(n,a,o)  ((n) == 0x0f ? \
00503                           (*(CARD32 *) ((a)+FbPatternOffset(o,CARD32)) = \
00504                            fgxor) : \
00505                           ((void)FbLaneCase2((n)&3,a,o), \
00506                                 FbLaneCase2((n)>>2,a,(o)+2)))
00507 #define FbLaneCase8(n,a,o)  ((n) == 0x0ff ? (*(FbBits *) ((a)+(o)) = fgxor) : \
00508                           ((void)FbLaneCase4((n)&15,a,o), \
00509                                 FbLaneCase4((n)>>4,a,(o)+4)))
00510 
00511 #if FB_SHIFT == 6
00512 #define FbLaneCase(n,a)   FbLaneCase8(n,(CARD8 *) (a),0)
00513 #endif
00514 
00515 #if FB_SHIFT == 5
00516 #define FbLaneCase(n,a)   FbLaneCase4(n,(CARD8 *) (a),0)
00517 #endif
00518 
00519 /* Rotate a filled pixel value to the specified alignement */
00520 #define FbRot24(p,b)     (FbScrRight(p,b) | FbScrLeft(p,24-(b)))
00521 #define FbRot24Stip(p,b)    (FbStipRight(p,b) | FbStipLeft(p,24-(b)))
00522 
00523 /* step a filled pixel value to the next/previous FB_UNIT alignment */
00524 #define FbNext24Pix(p)      (FbRot24(p,(24-FB_UNIT%24)))
00525 #define FbPrev24Pix(p)      (FbRot24(p,FB_UNIT%24))
00526 #define FbNext24Stip(p)     (FbRot24(p,(24-FB_STIP_UNIT%24)))
00527 #define FbPrev24Stip(p)     (FbRot24(p,FB_STIP_UNIT%24))
00528 
00529 /* step a rotation value to the next/previous rotation value */
00530 #if FB_UNIT == 64
00531 #define FbNext24Rot(r)        ((r) == 16 ? 0 : (r) + 8)
00532 #define FbPrev24Rot(r)        ((r) == 0 ? 16 : (r) - 8)
00533 
00534 #if IMAGE_BYTE_ORDER == MSBFirst
00535 #define FbFirst24Rot(x)            (((x) + 8) % 24)
00536 #else
00537 #define FbFirst24Rot(x)            ((x) % 24)
00538 #endif
00539 
00540 #endif
00541 
00542 #if FB_UNIT == 32
00543 #define FbNext24Rot(r)        ((r) == 0 ? 16 : (r) - 8)
00544 #define FbPrev24Rot(r)        ((r) == 16 ? 0 : (r) + 8)
00545 
00546 #if IMAGE_BYTE_ORDER == MSBFirst
00547 #define FbFirst24Rot(x)            (((x) + 16) % 24)
00548 #else
00549 #define FbFirst24Rot(x)            ((x) % 24)
00550 #endif
00551 #endif
00552 
00553 #define FbNext24RotStip(r)        ((r) == 0 ? 16 : (r) - 8)
00554 #define FbPrev24RotStip(r)        ((r) == 16 ? 0 : (r) + 8)
00555 
00556 /* Whether 24-bit specific code is needed for this filled pixel value */
00557 #define FbCheck24Pix(p)     ((p) == FbNext24Pix(p))
00558 
00559 #define FbGetPixels(icpixels, pointer, _stride_, _bpp_, xoff, yoff) { \
00560     (pointer) = icpixels->data; \
00561     (_stride_) = icpixels->stride / sizeof(pixman_bits_t); \
00562     (_bpp_) = icpixels->bpp; \
00563     (xoff) = icpixels->x; /* XXX: fb.h had this ifdef'd to constant 0. Why? */ \
00564     (yoff) = icpixels->y; /* XXX: fb.h had this ifdef'd to constant 0. Why? */ \
00565 }
00566 
00567 #define FbGetStipPixels(icpixels, pointer, _stride_, _bpp_, xoff, yoff) { \
00568     (pointer) = (FbStip *) icpixels->data; \
00569     (_stride_) = icpixels->stride / sizeof(FbStip); \
00570     (_bpp_) = icpixels->bpp; \
00571     (xoff) = icpixels->x; \
00572     (yoff) = icpixels->y; \
00573 }
00574 
00575 #ifdef FB_OLD_SCREEN
00576 #define BitsPerPixel(d) (\
00577     ((1 << PixmapWidthPaddingInfo[d].padBytesLog2) * 8 / \
00578     (PixmapWidthPaddingInfo[d].padRoundUp+1)))
00579 #endif
00580 
00581 #define FbPowerOfTwo(w)         (((w) & ((w) - 1)) == 0)
00582 /*
00583  * Accelerated tiles are power of 2 width <= FB_UNIT
00584  */
00585 #define FbEvenTile(w)           ((w) <= FB_UNIT && FbPowerOfTwo(w))
00586 /*
00587  * Accelerated stipples are power of 2 width and <= FB_UNIT/dstBpp
00588  * with dstBpp a power of 2 as well
00589  */
00590 #define FbEvenStip(w,bpp)   ((w) * (bpp) <= FB_UNIT && FbPowerOfTwo(w) && FbPowerOfTwo(bpp))
00591 
00592 /*
00593  * icblt.c
00594  */
00595 pixman_private void
00596 fbBlt (pixman_bits_t   *src, 
00597        FbStride      srcStride,
00598        int    srcX,
00599        
00600        FbBits   *dst,
00601        FbStride dstStride,
00602        int    dstX,
00603        
00604        int    width, 
00605        int    height,
00606        
00607        int    alu,
00608        FbBits pm,
00609        int    bpp,
00610        
00611        Bool   reverse,
00612        Bool   upsidedown);
00613 
00614 pixman_private void
00615 fbBlt24 (pixman_bits_t          *srcLine,
00616         FbStride   srcStride,
00617         int       srcX,
00618 
00619         FbBits           *dstLine,
00620         FbStride   dstStride,
00621         int       dstX,
00622 
00623         int       width, 
00624         int       height,
00625 
00626         int       alu,
00627         FbBits           pm,
00628 
00629         Bool      reverse,
00630         Bool      upsidedown);
00631     
00632 pixman_private void
00633 fbBltStip (FbStip   *src,
00634           FbStride srcStride,          /* in FbStip units, not FbBits units */
00635           int     srcX,
00636           
00637           FbStip   *dst,
00638           FbStride dstStride,          /* in FbStip units, not FbBits units */
00639           int     dstX,
00640 
00641           int     width, 
00642           int     height,
00643 
00644           int     alu,
00645           FbBits   pm,
00646           int     bpp);
00647     
00648 /*
00649  * icbltone.c
00650  */
00651 pixman_private void
00652 fbBltOne (FbStip   *src,
00653          FbStride srcStride,
00654          int     srcX,
00655          FbBits   *dst,
00656          FbStride dstStride,
00657          int     dstX,
00658          int     dstBpp,
00659 
00660          int     width,
00661          int     height,
00662 
00663          FbBits   fgand,
00664          FbBits   fbxor,
00665          FbBits   bgand,
00666          FbBits   bgxor);
00667  
00668 #ifdef FB_24BIT
00669 pixman_private void
00670 fbBltOne24 (FbStip    *src,
00671          FbStride  srcStride,          /* FbStip units per scanline */
00672          int      srcX,         /* bit position of source */
00673          FbBits    *dst,
00674          FbStride  dstStride,          /* FbBits units per scanline */
00675          int      dstX,         /* bit position of dest */
00676          int      dstBpp,       /* bits per destination unit */
00677 
00678          int      width,        /* width in bits of destination */
00679          int      height,       /* height in scanlines */
00680 
00681          FbBits    fgand,       /* rrop values */
00682          FbBits    fgxor,
00683          FbBits    bgand,
00684          FbBits    bgxor);
00685 #endif
00686 
00687 /*
00688  * icstipple.c
00689  */
00690 
00691 pixman_private void
00692 fbTransparentSpan (pixman_bits_t   *dst,
00693                  pixman_bits_t   stip,
00694                  pixman_bits_t   fgxor,
00695                  int     n);
00696 
00697 pixman_private void
00698 fbEvenStipple (pixman_bits_t   *dst,
00699               FbStride dstStride,
00700               int    dstX,
00701               int    dstBpp,
00702 
00703               int    width,
00704               int    height,
00705 
00706               FbStip   *stip,
00707               FbStride      stipStride,
00708               int    stipHeight,
00709 
00710               FbBits   fgand,
00711               FbBits   fgxor,
00712               FbBits   bgand,
00713               FbBits   bgxor,
00714 
00715               int    xRot,
00716               int    yRot);
00717 
00718 pixman_private void
00719 fbOddStipple (pixman_bits_t *dst,
00720              FbStride       dstStride,
00721              int     dstX,
00722              int     dstBpp,
00723 
00724              int     width,
00725              int     height,
00726 
00727              FbStip  *stip,
00728              FbStride       stipStride,
00729              int     stipWidth,
00730              int     stipHeight,
00731 
00732              FbBits  fgand,
00733              FbBits  fgxor,
00734              FbBits  bgand,
00735              FbBits  bgxor,
00736 
00737              int     xRot,
00738              int     yRot);
00739 
00740 pixman_private void
00741 fbStipple (pixman_bits_t   *dst,
00742           FbStride dstStride,
00743           int     dstX,
00744           int     dstBpp,
00745 
00746           int     width,
00747           int     height,
00748 
00749           FbStip   *stip,
00750           FbStride stipStride,
00751           int     stipWidth,
00752           int     stipHeight,
00753           Bool           even,
00754 
00755           FbBits   fgand,
00756           FbBits   fgxor,
00757           FbBits   bgand,
00758           FbBits   bgxor,
00759 
00760           int     xRot,
00761           int     yRot);
00762 
00763 /* XXX: Is depth redundant here? */
00764 struct pixman_format {
00765     int              format_code;
00766     int              depth;
00767     int              red, redMask;
00768     int              green, greenMask;
00769     int              blue, blueMask;
00770     int              alpha, alphaMask;
00771 };
00772 
00773 typedef struct _FbPixels {
00774     pixman_bits_t           *data;
00775     unsigned int     width;
00776     unsigned int     height;
00777     unsigned int     depth;
00778     unsigned int     bpp;
00779     unsigned int     stride;
00780     int                     x;
00781     int                     y;
00782     unsigned int     refcnt;
00783 } FbPixels;
00784 
00785 /* XXX: This is to avoid including colormap.h from the server includes */
00786 typedef uint32_t Pixel;
00787 
00788 /* icutil.c */
00789 pixman_private pixman_bits_t
00790 fbReplicatePixel (Pixel p, int bpp);
00791 
00792 /* fbtrap.c */
00793 
00794 pixman_private void
00795 fbRasterizeTrapezoid (pixman_image_t             *pMask,
00796                     const pixman_trapezoid_t  *pTrap,
00797                     int            x_off,
00798                     int            y_off);
00799 
00800 /* XXX: This is to avoid including gc.h from the server includes */
00801 /* clientClipType field in GC */
00802 #define CT_NONE                    0
00803 #define CT_PIXMAP           1
00804 #define CT_REGION           2
00805 #define CT_UNSORTED         6
00806 #define CT_YSORTED          10
00807 #define CT_YXSORTED         14
00808 #define CT_YXBANDED         18
00809 
00810 #include "icimage.h"
00811 
00812 /* iccolor.c */
00813 
00814 /* GCC 3.4 supports a "population count" builtin, which on many targets is
00815    implemented with a single instruction.  There is a fallback definition
00816    in libgcc in case a target does not have one, which should be just as
00817    good as the static function below.  */
00818 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
00819 # if __INT_MIN__ == 0x7fffffff
00820 #  define _FbOnes(mask)            __builtin_popcount(mask)
00821 # else
00822 #  define _FbOnes(mask)            __builtin_popcountl((mask) & 0xffffffff)
00823 # endif
00824 #else
00825 # define ICINT_NEED_IC_ONES
00826 int
00827 _FbOnes(unsigned long mask);
00828 #endif
00829 
00830 /* icformat.c */
00831 
00832 pixman_private void
00833 pixman_format_init (pixman_format_t *format, int format_code);
00834 
00835 /* icimage.c */
00836 
00837 pixman_private pixman_image_t *
00838 pixman_image_createForPixels (FbPixels    *pixels,
00839                      pixman_format_t      *format);
00840 
00841 /* icpixels.c */
00842 
00843 pixman_private FbPixels *
00844 FbPixelsCreate (int width, int height, int depth);
00845 
00846 pixman_private FbPixels *
00847 FbPixelsCreateForData (pixman_bits_t *data, int width, int height, int depth, int bpp, int stride);
00848 
00849 pixman_private void
00850 FbPixelsDestroy (FbPixels *pixels);
00851 
00852 /* ictransform.c */
00853 
00854 pixman_private int
00855 pixman_transform_point (pixman_transform_t       *transform,
00856                 pixman_vector_t    *vector);
00857 
00858 /* Avoid unnessecary PLT entries.  */
00859 
00860 slim_hidden_proto(pixman_image_create)
00861 slim_hidden_proto(pixman_color_to_pixel)
00862 slim_hidden_proto(pixman_format_init)
00863 slim_hidden_proto(pixman_image_destroy)
00864 slim_hidden_proto(pixman_fill_rectangles)
00865 slim_hidden_proto(pixman_image_set_component_alpha)
00866 slim_hidden_proto(pixman_image_set_repeat)
00867 slim_hidden_proto(pixman_composite)
00868 
00869 
00870 #include "icrop.h"
00871 
00872 /* XXX: For now, I'm just wholesale pasting Xserver/render/picture.h here: */
00873 #ifndef _PICTURE_H_
00874 #define _PICTURE_H_
00875 
00876 typedef struct _DirectFormat       *DirectFormatPtr;
00877 typedef struct _PictFormat  *PictFormatPtr;
00878 
00879 /*
00880  * While the protocol is generous in format support, the
00881  * sample implementation allows only packed RGB and GBR
00882  * representations for data to simplify software rendering,
00883  */
00884 #define PICT_FORMAT(bpp,type,a,r,g,b)     (((bpp) << 24) |  \
00885                                     ((type) << 16) | \
00886                                     ((a) << 12) | \
00887                                     ((r) << 8) | \
00888                                     ((g) << 4) | \
00889                                     ((b)))
00890 
00891 /*
00892  * gray/color formats use a visual index instead of argb
00893  */
00894 #define PICT_VISFORMAT(bpp,type,vi)       (((bpp) << 24) |  \
00895                                     ((type) << 16) | \
00896                                     ((vi)))
00897 
00898 #define PICT_FORMAT_BPP(f)  (((f) >> 24)       )
00899 #define PICT_FORMAT_TYPE(f) (((f) >> 16) & 0xff)
00900 #define PICT_FORMAT_A(f)    (((f) >> 12) & 0x0f)
00901 #define PICT_FORMAT_R(f)    (((f) >>  8) & 0x0f)
00902 #define PICT_FORMAT_G(f)    (((f) >>  4) & 0x0f)
00903 #define PICT_FORMAT_B(f)    (((f)      ) & 0x0f)
00904 #define PICT_FORMAT_RGB(f)  (((f)      ) & 0xfff)
00905 #define PICT_FORMAT_VIS(f)  (((f)      ) & 0xffff)
00906 
00907 #define PICT_TYPE_OTHER     0
00908 #define PICT_TYPE_A  1
00909 #define PICT_TYPE_ARGB      2
00910 #define PICT_TYPE_ABGR      3
00911 #define PICT_TYPE_COLOR     4
00912 #define PICT_TYPE_GRAY      5
00913 
00914 #define PICT_FORMAT_COLOR(f)       (PICT_FORMAT_TYPE(f) & 2)
00915 
00916 /* 32bpp formats */
00917 #define PICT_a8r8g8b8       PICT_FORMAT(32,PICT_TYPE_ARGB,8,8,8,8)
00918 #define PICT_x8r8g8b8       PICT_FORMAT(32,PICT_TYPE_ARGB,0,8,8,8)
00919 #define PICT_a8b8g8r8       PICT_FORMAT(32,PICT_TYPE_ABGR,8,8,8,8)
00920 #define PICT_x8b8g8r8       PICT_FORMAT(32,PICT_TYPE_ABGR,0,8,8,8)
00921 
00922 /* 24bpp formats */
00923 #define PICT_r8g8b8  PICT_FORMAT(24,PICT_TYPE_ARGB,0,8,8,8)
00924 #define PICT_b8g8r8  PICT_FORMAT(24,PICT_TYPE_ABGR,0,8,8,8)
00925 
00926 /* 16bpp formats */
00927 #define PICT_r5g6b5  PICT_FORMAT(16,PICT_TYPE_ARGB,0,5,6,5)
00928 #define PICT_b5g6r5  PICT_FORMAT(16,PICT_TYPE_ABGR,0,5,6,5)
00929 
00930 #define PICT_a1r5g5b5       PICT_FORMAT(16,PICT_TYPE_ARGB,1,5,5,5)
00931 #define PICT_x1r5g5b5       PICT_FORMAT(16,PICT_TYPE_ARGB,0,5,5,5)
00932 #define PICT_a1b5g5r5       PICT_FORMAT(16,PICT_TYPE_ABGR,1,5,5,5)
00933 #define PICT_x1b5g5r5       PICT_FORMAT(16,PICT_TYPE_ABGR,0,5,5,5)
00934 #define PICT_a4r4g4b4       PICT_FORMAT(16,PICT_TYPE_ARGB,4,4,4,4)
00935 #define PICT_x4r4g4b4       PICT_FORMAT(16,PICT_TYPE_ARGB,0,4,4,4)
00936 #define PICT_a4b4g4r4       PICT_FORMAT(16,PICT_TYPE_ABGR,4,4,4,4)
00937 #define PICT_x4b4g4r4       PICT_FORMAT(16,PICT_TYPE_ABGR,0,4,4,4)
00938 
00939 /* 8bpp formats */
00940 #define PICT_a8             PICT_FORMAT(8,PICT_TYPE_A,8,0,0,0)
00941 #define PICT_r3g3b2  PICT_FORMAT(8,PICT_TYPE_ARGB,0,3,3,2)
00942 #define PICT_b2g3r3  PICT_FORMAT(8,PICT_TYPE_ABGR,0,3,3,2)
00943 #define PICT_a2r2g2b2       PICT_FORMAT(8,PICT_TYPE_ARGB,2,2,2,2)
00944 #define PICT_a2b2g2r2       PICT_FORMAT(8,PICT_TYPE_ABGR,2,2,2,2)
00945 
00946 #define PICT_c8             PICT_FORMAT(8,PICT_TYPE_COLOR,0,0,0,0)
00947 #define PICT_g8             PICT_FORMAT(8,PICT_TYPE_GRAY,0,0,0,0)
00948 
00949 /* 4bpp formats */
00950 #define PICT_a4             PICT_FORMAT(4,PICT_TYPE_A,4,0,0,0)
00951 #define PICT_r1g2b1  PICT_FORMAT(4,PICT_TYPE_ARGB,0,1,2,1)
00952 #define PICT_b1g2r1  PICT_FORMAT(4,PICT_TYPE_ABGR,0,1,2,1)
00953 #define PICT_a1r1g1b1       PICT_FORMAT(4,PICT_TYPE_ARGB,1,1,1,1)
00954 #define PICT_a1b1g1r1       PICT_FORMAT(4,PICT_TYPE_ABGR,1,1,1,1)
00955                                 
00956 #define PICT_c4             PICT_FORMAT(4,PICT_TYPE_COLOR,0,0,0,0)
00957 #define PICT_g4             PICT_FORMAT(4,PICT_TYPE_GRAY,0,0,0,0)
00958 
00959 /* 1bpp formats */
00960 #define PICT_a1             PICT_FORMAT(1,PICT_TYPE_A,1,0,0,0)
00961 
00962 #define PICT_g1             PICT_FORMAT(1,PICT_TYPE_GRAY,0,0,0,0)
00963 
00964 /*
00965  * For dynamic indexed visuals (GrayScale and PseudoColor), these control the 
00966  * selection of colors allocated for drawing to Pictures.  The default
00967  * policy depends on the size of the colormap:
00968  *
00969  * Size              Default Policy
00970  * ----------------------------
00971  *  < 64      PolicyMono
00972  *  < 256     PolicyGray
00973  *  256              PolicyColor (only on PseudoColor)
00974  *
00975  * The actual allocation code lives in miindex.c, and so is
00976  * austensibly server dependent, but that code does:
00977  *
00978  * PolicyMono     Allocate no additional colors, use black and white
00979  * PolicyGray     Allocate 13 gray levels (11 cells used)
00980  * PolicyColor           Allocate a 4x4x4 cube and 13 gray levels (71 cells used)
00981  * PolicyAll      Allocate as big a cube as possible, fill with gray (all)
00982  *
00983  * Here's a picture to help understand how many colors are
00984  * actually allocated (this is just the gray ramp):
00985  *
00986  *                 gray level
00987  * all   0000 1555 2aaa 4000 5555 6aaa 8000 9555 aaaa bfff d555 eaaa ffff
00988  * b/w   0000                                                        ffff
00989  * 4x4x4                     5555                aaaa
00990  * extra      1555 2aaa 4000      6aaa 8000 9555      bfff d555 eaaa
00991  *
00992  * The default colormap supplies two gray levels (black/white), the
00993  * 4x4x4 cube allocates another two and nine more are allocated to fill
00994  * in the 13 levels.  When the 4x4x4 cube is not allocated, a total of
00995  * 11 cells are allocated.
00996  */   
00997 
00998 #define PictureCmapPolicyInvalid    -1
00999 #define PictureCmapPolicyDefault    0
01000 #define PictureCmapPolicyMono          1
01001 #define PictureCmapPolicyGray          2
01002 #define PictureCmapPolicyColor         3
01003 #define PictureCmapPolicyAll           4
01004 
01005 extern int PictureCmapPolicy pixman_private;
01006 
01007 int    PictureParseCmapPolicy (const char *name);
01008 
01009 /* Fixed point updates from Carl Worth, USC, Information Sciences Institute */
01010 
01011 #ifdef WIN32
01012 typedef __int64             xFixed_32_32;
01013 #else
01014 #  if defined(__alpha__) || defined(__alpha) || \
01015       defined(ia64) || defined(__ia64__) || \
01016       defined(__sparc64__) || \
01017       defined(__s390x__) || \
01018       defined(x86_64) || defined (__x86_64__)
01019 typedef long         xFixed_32_32;
01020 # else
01021 #  if defined(__GNUC__) && \
01022     ((__GNUC__ > 2) || \
01023      ((__GNUC__ == 2) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ > 7)))
01024 __extension__
01025 #  endif
01026 typedef long long int       xFixed_32_32;
01027 # endif
01028 #endif
01029 
01030 typedef xFixed_32_32        xFixed_48_16;
01031 typedef uint32_t            xFixed_1_31;
01032 typedef uint32_t            xFixed_1_16;
01033 typedef int32_t             xFixed_16_16;
01034 
01035 /*
01036  * An unadorned "xFixed" is the same as xFixed_16_16, 
01037  * (since it's quite common in the code) 
01038  */
01039 typedef       xFixed_16_16  xFixed;
01040 #define XFIXED_BITS  16
01041 
01042 #define xFixedToInt(f)      (int) ((f) >> XFIXED_BITS)
01043 #define IntToxFixed(i)      ((xFixed) (i) << XFIXED_BITS)
01044 #define xFixedE             ((xFixed) 1)
01045 #define xFixed1             (IntToxFixed(1))
01046 #define xFixed1MinusE       (xFixed1 - xFixedE)
01047 #define xFixedFrac(f)       ((f) & xFixed1MinusE)
01048 #define xFixedFloor(f)      ((f) & ~xFixed1MinusE)
01049 #define xFixedCeil(f)       xFixedFloor((f) + xFixed1MinusE)
01050 
01051 #define xFixedFraction(f)   ((f) & xFixed1MinusE)
01052 #define xFixedMod2(f)              ((f) & (xFixed1 | xFixed1MinusE))
01053 
01054 /* whether 't' is a well defined not obviously empty trapezoid */
01055 #define xTrapezoidValid(t)  ((t)->left.p1.y != (t)->left.p2.y && \
01056                           (t)->right.p1.y != (t)->right.p2.y && \
01057                           (int) ((t)->bottom - (t)->top) > 0)
01058 
01059 /*
01060  * Standard NTSC luminance conversions:
01061  *
01062  *  y = r * 0.299 + g * 0.587 + b * 0.114
01063  *
01064  * Approximate this for a bit more speed:
01065  *
01066  *  y = (r * 153 + g * 301 + b * 58) / 512
01067  *
01068  * This gives 17 bits of luminance; to get 15 bits, lop the low two
01069  */
01070 
01071 #define CvtR8G8B8toY15(s)   (((((s) >> 16) & 0xff) * 153 + \
01072                               (((s) >>  8) & 0xff) * 301 + \
01073                               (((s)      ) & 0xff) * 58) >> 2)
01074 
01075 #endif /* _PICTURE_H_ */
01076 
01077 
01078 /* Macros needed by fbpict.c */
01079 
01080 #define cvt8888to0565(s)    ((((s) >> 3) & 0x001f) | \
01081                           (((s) >> 5) & 0x07e0) | \
01082                           (((s) >> 8) & 0xf800))
01083 #define cvt0565to0888(s)    (((((s) << 3) & 0xf8) | (((s) >> 2) & 0x7)) | \
01084                           ((((s) << 5) & 0xfc00) | (((s) >> 1) & 0x300)) | \
01085                           ((((s) << 8) & 0xf80000) | (((s) << 3) & 0x70000)))
01086 
01087 #if IMAGE_BYTE_ORDER == MSBFirst
01088 #define Fetch24(a)  ((unsigned long) (a) & 1 ? \
01089                    ((*(a) << 16) | *((CARD16 *) ((a)+1))) : \
01090                    ((*((CARD16 *) (a)) << 8) | *((a)+2)))
01091 #define Store24(a,v) ((unsigned long) (a) & 1 ? \
01092                     ((*(a) = (CARD8) ((v) >> 16)), \
01093                      (*((CARD16 *) ((a)+1)) = (CARD16) (v))) : \
01094                     ((*((CARD16 *) (a)) = (CARD16) ((v) >> 8)), \
01095                      (*((a)+2) = (CARD8) (v))))
01096 #else
01097 #define Fetch24(a)  ((unsigned long) (a) & 1 ? \
01098                    ((*(a)) | (*((CARD16 *) ((a)+1)) << 8)) : \
01099                    ((*((CARD16 *) (a))) | (*((a)+2) << 16)))
01100 #define Store24(a,v) ((unsigned long) (a) & 1 ? \
01101                     ((*(a) = (CARD8) (v)), \
01102                      (*((CARD16 *) ((a)+1)) = (CARD16) ((v) >> 8))) : \
01103                     ((*((CARD16 *) (a)) = (CARD16) (v)),\
01104                      (*((a)+2) = (CARD8) ((v) >> 16))))
01105 #endif
01106 
01107 #endif /* _ICINT_H_ */