Back to index

lightning-sunbird  0.9+nobinonly
fbedgeimp.h
Go to the documentation of this file.
00001 /*
00002  * $Id: fbedgeimp.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 rasterizeSpan
00026 #endif
00027 
00028 static void
00029 rasterizeEdges (FbBits             *buf,
00030               int           width,
00031               int           stride,
00032               RenderEdge    *l,
00033               RenderEdge    *r,
00034               xFixed        t,
00035               xFixed        b)
00036 {
00037     xFixed  y = t;
00038     FbBits  *line;
00039     
00040     line = buf + xFixedToInt (y) * stride;
00041     
00042     for (;;)
00043     {
00044        xFixed lx, rx;
00045        int    lxi, rxi;
00046        
00047        /* clip X */
00048        lx = l->x;
00049        if (lx < 0)
00050            lx = 0;
00051        rx = r->x;
00052        if (xFixedToInt (rx) >= width)
00053            rx = IntToxFixed (width);
00054        
00055        /* Skip empty (or backwards) sections */
00056        if (rx > lx)
00057        {
00058 
00059            /* Find pixel bounds for span. */
00060            lxi = xFixedToInt (lx);
00061            rxi = xFixedToInt (rx);
00062 
00063 #if N_BITS == 1
00064            {
00065               FbBits  *a = line;
00066               FbBits  startmask, endmask;
00067               int        nmiddle;
00068               int        width = rxi - lxi;
00069               int        x = lxi;
00070 
00071               a += x >> FB_SHIFT;
00072               x &= FB_MASK;
00073 
00074               FbMaskBits (x, width, startmask, nmiddle, endmask);
00075               if (startmask)
00076                   *a++ |= startmask;
00077               while (nmiddle--)
00078                   *a++ = FB_ALLONES;
00079               if (endmask)
00080                   *a |= endmask;
00081            }
00082 #else
00083            {
00084               DefineAlpha(line,lxi);
00085               int        lxs, rxs;
00086 
00087               /* Sample coverage for edge pixels */
00088               lxs = RenderSamplesX (lx, N_BITS);
00089               rxs = RenderSamplesX (rx, N_BITS);
00090 
00091               /* Add coverage across row */
00092               if (lxi == rxi)
00093               {
00094                   AddAlpha (rxs - lxs);
00095               }
00096               else
00097               {
00098                   int       xi;
00099 
00100                   AddAlpha (N_X_FRAC(N_BITS) - lxs);
00101                   StepAlpha;
00102                   for (xi = lxi + 1; xi < rxi; xi++)
00103                   {
00104                      AddAlpha (N_X_FRAC(N_BITS));
00105                      StepAlpha;
00106                   }
00107                   /* Do not add in a 0 alpha here. This check is
00108                    * necessary to avoid a buffer overrun, (when rx
00109                    * is exactly on a pixel boundary). */
00110                   if (rxs)
00111                      AddAlpha (rxs);
00112               }
00113            }
00114 #endif
00115        }
00116 
00117        if (y == b)
00118            break;
00119 
00120 #if N_BITS > 1
00121        if (xFixedFrac (y) != Y_FRAC_LAST(N_BITS))
00122        {
00123            RenderEdgeStepSmall (l);
00124            RenderEdgeStepSmall (r);
00125            y += STEP_Y_SMALL(N_BITS);
00126        }
00127        else
00128 #endif
00129        {
00130            RenderEdgeStepBig (l);
00131            RenderEdgeStepBig (r);
00132            y += STEP_Y_BIG(N_BITS);
00133            line += stride;
00134        }
00135     }
00136 }
00137 
00138 #undef rasterizeSpan