45e9809aff7304721fddb95654901b32195c9c7avboxsync/*
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Copyright © 2004 Keith Packard
45e9809aff7304721fddb95654901b32195c9c7avboxsync *
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Permission to use, copy, modify, distribute, and sell this software and its
45e9809aff7304721fddb95654901b32195c9c7avboxsync * documentation for any purpose is hereby granted without fee, provided that
45e9809aff7304721fddb95654901b32195c9c7avboxsync * the above copyright notice appear in all copies and that both that
45e9809aff7304721fddb95654901b32195c9c7avboxsync * copyright notice and this permission notice appear in supporting
45e9809aff7304721fddb95654901b32195c9c7avboxsync * documentation, and that the name of Keith Packard not be used in
45e9809aff7304721fddb95654901b32195c9c7avboxsync * advertising or publicity pertaining to distribution of the software without
45e9809aff7304721fddb95654901b32195c9c7avboxsync * specific, written prior permission. Keith Packard makes no
45e9809aff7304721fddb95654901b32195c9c7avboxsync * representations about the suitability of this software for any purpose. It
45e9809aff7304721fddb95654901b32195c9c7avboxsync * is provided "as is" without express or implied warranty.
45e9809aff7304721fddb95654901b32195c9c7avboxsync *
45e9809aff7304721fddb95654901b32195c9c7avboxsync * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
45e9809aff7304721fddb95654901b32195c9c7avboxsync * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
45e9809aff7304721fddb95654901b32195c9c7avboxsync * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
45e9809aff7304721fddb95654901b32195c9c7avboxsync * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
45e9809aff7304721fddb95654901b32195c9c7avboxsync * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
45e9809aff7304721fddb95654901b32195c9c7avboxsync * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
45e9809aff7304721fddb95654901b32195c9c7avboxsync * PERFORMANCE OF THIS SOFTWARE.
45e9809aff7304721fddb95654901b32195c9c7avboxsync */
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync#ifndef _RENDEREDGE_H_
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define _RENDEREDGE_H_
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync#include "picturestr.h"
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define MAX_ALPHA(n) ((1 << (n)) - 1)
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define N_Y_FRAC(n) ((n) == 1 ? 1 : (1 << ((n)/2)) - 1)
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define N_X_FRAC(n) ((1 << ((n)/2)) + 1)
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define STEP_Y_SMALL(n) (xFixed1 / N_Y_FRAC(n))
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define STEP_Y_BIG(n) (xFixed1 - (N_Y_FRAC(n) - 1) * STEP_Y_SMALL(n))
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define Y_FRAC_FIRST(n) (STEP_Y_SMALL(n) / 2)
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define Y_FRAC_LAST(n) (Y_FRAC_FIRST(n) + (N_Y_FRAC(n) - 1) * STEP_Y_SMALL(n))
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define STEP_X_SMALL(n) (xFixed1 / N_X_FRAC(n))
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define STEP_X_BIG(n) (xFixed1 - (N_X_FRAC(n) - 1) * STEP_X_SMALL(n))
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define X_FRAC_FIRST(n) (STEP_X_SMALL(n) / 2)
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define X_FRAC_LAST(n) (X_FRAC_FIRST(n) + (N_X_FRAC(n) - 1) * STEP_X_SMALL(n))
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define RenderSamplesX(x,n) ((n) == 1 ? 0 : (xFixedFrac (x) + X_FRAC_FIRST(n)) / STEP_X_SMALL(n))
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync/*
45e9809aff7304721fddb95654901b32195c9c7avboxsync * An edge structure. This represents a single polygon edge
45e9809aff7304721fddb95654901b32195c9c7avboxsync * and can be quickly stepped across small or large gaps in the
45e9809aff7304721fddb95654901b32195c9c7avboxsync * sample grid
45e9809aff7304721fddb95654901b32195c9c7avboxsync */
45e9809aff7304721fddb95654901b32195c9c7avboxsynctypedef pixman_edge_t RenderEdge;
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync/*
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Step across a small sample grid gap
45e9809aff7304721fddb95654901b32195c9c7avboxsync */
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define RenderEdgeStepSmall(edge) { \
45e9809aff7304721fddb95654901b32195c9c7avboxsync edge->x += edge->stepx_small; \
45e9809aff7304721fddb95654901b32195c9c7avboxsync edge->e += edge->dx_small; \
45e9809aff7304721fddb95654901b32195c9c7avboxsync if (edge->e > 0) \
45e9809aff7304721fddb95654901b32195c9c7avboxsync { \
45e9809aff7304721fddb95654901b32195c9c7avboxsync edge->e -= edge->dy; \
45e9809aff7304721fddb95654901b32195c9c7avboxsync edge->x += edge->signdx; \
45e9809aff7304721fddb95654901b32195c9c7avboxsync } \
45e9809aff7304721fddb95654901b32195c9c7avboxsync}
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync/*
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Step across a large sample grid gap
45e9809aff7304721fddb95654901b32195c9c7avboxsync */
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define RenderEdgeStepBig(edge) { \
45e9809aff7304721fddb95654901b32195c9c7avboxsync edge->x += edge->stepx_big; \
45e9809aff7304721fddb95654901b32195c9c7avboxsync edge->e += edge->dx_big; \
45e9809aff7304721fddb95654901b32195c9c7avboxsync if (edge->e > 0) \
45e9809aff7304721fddb95654901b32195c9c7avboxsync { \
45e9809aff7304721fddb95654901b32195c9c7avboxsync edge->e -= edge->dy; \
45e9809aff7304721fddb95654901b32195c9c7avboxsync edge->x += edge->signdx; \
45e9809aff7304721fddb95654901b32195c9c7avboxsync } \
45e9809aff7304721fddb95654901b32195c9c7avboxsync}
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncxFixed
45e9809aff7304721fddb95654901b32195c9c7avboxsyncRenderSampleCeilY (xFixed y, int bpp);
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncxFixed
45e9809aff7304721fddb95654901b32195c9c7avboxsyncRenderSampleFloorY (xFixed y, int bpp);
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncvoid
45e9809aff7304721fddb95654901b32195c9c7avboxsyncRenderEdgeStep (RenderEdge *e, int n);
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncvoid
45e9809aff7304721fddb95654901b32195c9c7avboxsyncRenderEdgeInit (RenderEdge *e,
45e9809aff7304721fddb95654901b32195c9c7avboxsync int bpp,
45e9809aff7304721fddb95654901b32195c9c7avboxsync xFixed y_start,
45e9809aff7304721fddb95654901b32195c9c7avboxsync xFixed x_top,
45e9809aff7304721fddb95654901b32195c9c7avboxsync xFixed y_top,
45e9809aff7304721fddb95654901b32195c9c7avboxsync xFixed x_bot,
45e9809aff7304721fddb95654901b32195c9c7avboxsync xFixed y_bot);
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncvoid
45e9809aff7304721fddb95654901b32195c9c7avboxsyncRenderLineFixedEdgeInit (RenderEdge *e,
45e9809aff7304721fddb95654901b32195c9c7avboxsync int bpp,
45e9809aff7304721fddb95654901b32195c9c7avboxsync xFixed y,
45e9809aff7304721fddb95654901b32195c9c7avboxsync xLineFixed *line,
45e9809aff7304721fddb95654901b32195c9c7avboxsync int x_off,
45e9809aff7304721fddb95654901b32195c9c7avboxsync int y_off);
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync#endif /* _RENDEREDGE_H_ */