Back to index

lightning-sunbird  0.9+nobinonly
renderedge.h
Go to the documentation of this file.
00001 /*
00002  * $Id: renderedge.h,v 1.3.4.1 2005/09/27 23:09:03 vladimir%pobox.com Exp $
00003  *
00004  * Copyright © 2004 Keith Packard
00005  *
00006  * Permission to use, copy, modify, distribute, and sell this software and its
00007  * documentation for any purpose is hereby granted without fee, provided that
00008  * the above copyright notice appear in all copies and that both that
00009  * copyright notice and this permission notice appear in supporting
00010  * documentation, and that the name of Keith Packard not be used in
00011  * advertising or publicity pertaining to distribution of the software without
00012  * specific, written prior permission.  Keith Packard makes no
00013  * representations about the suitability of this software for any purpose.  It
00014  * is provided "as is" without express or implied warranty.
00015  *
00016  * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
00017  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
00018  * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
00019  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
00020  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
00021  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00022  * PERFORMANCE OF THIS SOFTWARE.
00023  */
00024 
00025 #ifndef _RENDEREDGE_H_
00026 #define _RENDEREDGE_H_
00027 
00028 #include "pixman-xserver-compat.h"
00029 
00030 /* Here is a drawing of the sample grid for the 4-bit alpha case,
00031    along with indications of the various defined terms:
00032 
00033                 STEP_Y_SMALL
00034 ┌─────┬─────┬─────┐  ↓
00035 │•••••│•••••│•••••│ ─── ⟵── Y_FRAC_FIRST
00036 │•••••│•••••│•••••│ ───
00037 │•••••│•••••│•••••│  ↑  ⟵── Y_FRAC_LAST
00038 ├─────┼─────┼─────┤
00039 │•••••│•••••│•••••│
00040 │•••••│•••••│•••••│  ↓
00041 │•••••│•••••│•••••│ ───
00042 ├─────┼─────┼─────┤ STEP_Y_BIG
00043 │•••••│•••••│•••••│ ───
00044 │•••••│•••••│•••••│  ↑
00045 │•••••│•••••│•••••│
00046 └─────┴─────┴─────┘
00047  │   │ ││ ⟶│ │⟵STEP_X_BIG
00048  │   │⟶││⟵STEP_X_SMALL
00049  │   │
00050  │   └ X_FRAC_LAST
00051 
00052  └ X_FRAC_FIRST
00053 
00054 N = 4         (# of bits of alpha)
00055 MAX_ALPHA = 15       (# of samples per pixel)
00056 N_X_FRAC = 5  (# of sample columns per pixel)
00057 N_Y_FRAC = 3  (# of sample rows per column)
00058 STEP_X_SMALL  (distance between sample columns within a pixel)
00059 STEP_X_BIG    (distance between sample columns across pixel boundaries)
00060 STEP_Y_SMALL  (distance between sample rows within a pixel)
00061 STEP_Y_BIG    (distance between sample rows across pixel boundaries)
00062 X_FRAC_FIRST  (sub-pixel position of first sample column in pixel)
00063 X_FRAC_LAST   (sub-pixel position of last  sample column in pixel)
00064 Y_FRAC_FIRST  (sub-pixel position of first sample row in pixel)
00065 Y_FRAC_LAST   (sub-pixel position of last  sample row pixel)
00066 
00067 */
00068 
00069 #define MAX_ALPHA(n) ((1 << (n)) - 1)
00070 #define N_Y_FRAC(n)  ((n) == 1 ? 1 : (1 << ((n)/2)) - 1)
00071 #define N_X_FRAC(n)  ((1 << ((n)/2)) + 1)
00072 
00073 #define STEP_Y_SMALL(n)     (xFixed1 / N_Y_FRAC(n))
00074 #define STEP_Y_BIG(n)       (xFixed1 - (N_Y_FRAC(n) - 1) * STEP_Y_SMALL(n))
00075 
00076 #define Y_FRAC_FIRST(n)     (STEP_Y_SMALL(n) / 2)
00077 #define Y_FRAC_LAST(n)      (Y_FRAC_FIRST(n) + (N_Y_FRAC(n) - 1) * STEP_Y_SMALL(n))
00078 
00079 #define STEP_X_SMALL(n)     (xFixed1 / N_X_FRAC(n))
00080 #define STEP_X_BIG(n)       (xFixed1 - (N_X_FRAC(n) - 1) * STEP_X_SMALL(n))
00081 
00082 #define X_FRAC_FIRST(n)     (STEP_X_SMALL(n) / 2)
00083 #define X_FRAC_LAST(n)      (X_FRAC_FIRST(n) + (N_X_FRAC(n) - 1) * STEP_X_SMALL(n))
00084 
00085 #define RenderSamplesX(x,n) ((n) == 1 ? 0 : (xFixedFrac (x) + X_FRAC_FIRST(n)) / STEP_X_SMALL(n))
00086 
00087 /*
00088  * An edge structure.  This represents a single polygon edge
00089  * and can be quickly stepped across small or large gaps in the
00090  * sample grid
00091  */
00092 
00093 typedef struct {
00094     xFixed   x;
00095     xFixed   e;
00096     xFixed   stepx;
00097     xFixed   signdx;
00098     xFixed   dy;
00099     xFixed   dx;
00100 
00101     xFixed   stepx_small;
00102     xFixed   stepx_big;
00103     xFixed   dx_small;
00104     xFixed   dx_big;
00105 } RenderEdge;
00106 
00107 /*
00108  * Step across a small sample grid gap
00109  */
00110 #define RenderEdgeStepSmall(edge) { \
00111     (edge)->x += (edge)->stepx_small;   \
00112     (edge)->e += (edge)->dx_small;     \
00113     if ((edge)->e > 0)                 \
00114     {                           \
00115        (edge)->e -= (edge)->dy;        \
00116        (edge)->x += (edge)->signdx;    \
00117     }                           \
00118 }
00119 
00120 /*
00121  * Step across a large sample grid gap
00122  */
00123 #define RenderEdgeStepBig(edge) {   \
00124     (edge)->x += (edge)->stepx_big;           \
00125     (edge)->e += (edge)->dx_big;       \
00126     if ((edge)->e > 0)                 \
00127     {                           \
00128        (edge)->e -= (edge)->dy;        \
00129        (edge)->x += (edge)->signdx;    \
00130     }                           \
00131 }
00132 
00133 xFixed
00134 RenderSampleCeilY (xFixed y, int bpp);
00135 
00136 xFixed
00137 RenderSampleFloorY (xFixed y, int bpp);
00138 
00139 void
00140 RenderEdgeStep (RenderEdge *e, int n);
00141 
00142 void
00143 RenderEdgeInit (RenderEdge  *e,
00144               int           bpp,
00145               xFixed        y_start,
00146               xFixed        x_top,
00147               xFixed        y_top,
00148               xFixed        x_bot,
00149               xFixed        y_bot);
00150 
00151 void
00152 RenderLineFixedEdgeInit (RenderEdge *e,
00153                       int       bpp,
00154                       xFixed           y,
00155                       const pixman_line_fixed_t *line,
00156                       int       x_off,
00157                       int       y_off);
00158 
00159 #endif /* _RENDEREDGE_H_ */