agg_rasterizer_compound_aa.h

来自「这是VCF框架的代码」· C头文件 代码 · 共 600 行 · 第 1/2 页

H
600
字号
//----------------------------------------------------------------------------// Anti-Grain Geometry - Version 2.3// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)//// Permission to copy, use, modify, sell and distribute this software // is granted provided this copyright notice appears in all copies. // This software is provided "as is" without express or implied// warranty, and with no claim as to its suitability for any purpose.////----------------------------------------------------------------------------//// The author gratefully acknowleges the support of David Turner, // Robert Wilhelm, and Werner Lemberg - the authors of the FreeType // libray - in producing this work. See http://www.freetype.org for details.////----------------------------------------------------------------------------// Contact: mcseem@antigrain.com//          mcseemagg@yahoo.com//          http://www.antigrain.com//----------------------------------------------------------------------------//// Adaptation for 32-bit screen coordinates has been sponsored by // Liberty Technology Systems, Inc., visit http://lib-sys.com//// Liberty Technology Systems, Inc. is the provider of// PostScript and PDF technology for software developers.// //----------------------------------------------------------------------------#ifndef AGG_RASTERIZER_COMPOUND_AA_INCLUDED#define AGG_RASTERIZER_COMPOUND_AA_INCLUDED#include "agg_rasterizer_cells_aa.h"#include "agg_rasterizer_sl_clip.h"namespace agg{    //-----------------------------------------------------------cell_style_aa    // A pixel cell. There're no constructors defined and it was done     // intentionally in order to avoid extra overhead when allocating an     // array of cells.    struct cell_style_aa    {        int   x;        int   y;        int   cover;        int   area;        int16 left, right;        void initial()        {            x     = 0x7FFFFFFF;            y     = 0x7FFFFFFF;            cover = 0;            area  = 0;            left  = -1;            right = -1;        }        void style(const cell_style_aa& c)        {            left  = c.left;            right = c.right;        }        int not_equal(int ex, int ey, const cell_style_aa& c) const        {            return (ex - x) | (ey - y) | (left - c.left) | (right - c.right);        }    };    //==================================================rasterizer_compound_aa    template<class Clip=rasterizer_sl_clip_int> class rasterizer_compound_aa    {        struct style_info         {             unsigned start_cell;            unsigned num_cells;            int      last_x;        };        struct cell_info        {            int x, area, cover;         };    public:        typedef Clip                     clip_type;        typedef typename Clip::conv_type conv_type;        enum aa_scale_e        {            aa_shift  = 8,            aa_scale  = 1 << aa_shift,            aa_mask   = aa_scale - 1,            aa_scale2 = aa_scale * 2,            aa_mask2  = aa_scale2 - 1        };        //--------------------------------------------------------------------        rasterizer_compound_aa() :             m_outline(),            m_clipper(),            m_filling_rule(fill_non_zero),            m_styles(),  // Active Styles            m_ast(),     // Active Style Table (unique values)            m_asm(),     // Active Style Mask             m_cells(),            m_min_style(0x7FFFFFFF),            m_max_style(-0x7FFFFFFF),            m_scan_y(0x7FFFFFFF)        {}        //--------------------------------------------------------------------        void reset();         void reset_clipping();        void clip_box(double x1, double y1, double x2, double y2);        void filling_rule(filling_rule_e filling_rule);        //--------------------------------------------------------------------        void styles(int left, int right);        void move_to(int x, int y);        void line_to(int x, int y);        void move_to_d(double x, double y);        void line_to_d(double x, double y);        void add_vertex(double x, double y, unsigned cmd);        void edge(int x1, int y1, int x2, int y2);        void edge_d(double x1, double y1, double x2, double y2);        //-------------------------------------------------------------------        template<class VertexSource>        void add_path(VertexSource& vs, unsigned path_id=0)        {            double x;            double y;            unsigned cmd;            vs.rewind(path_id);            if(m_outline.sorted()) reset();            while(!is_stop(cmd = vs.vertex(&x, &y)))            {                add_vertex(x, y, cmd);            }        }                //--------------------------------------------------------------------        int min_x()     const { return m_outline.min_x(); }        int min_y()     const { return m_outline.min_y(); }        int max_x()     const { return m_outline.max_x(); }        int max_y()     const { return m_outline.max_y(); }        int min_style() const { return m_min_style; }        int max_style() const { return m_max_style; }        //--------------------------------------------------------------------        void sort();        bool rewind_scanlines();        unsigned sweep_styles();        unsigned style(unsigned style_idx) const;        //--------------------------------------------------------------------        bool navigate_scanline(int y);         bool hit_test(int tx, int ty);        //--------------------------------------------------------------------        AGG_INLINE unsigned calculate_alpha(int area) const        {            int cover = area >> (poly_subpixel_shift*2 + 1 - aa_shift);            if(cover < 0) cover = -cover;            if(m_filling_rule == fill_even_odd)            {                cover &= aa_mask2;                if(cover > aa_scale)                {                    cover = aa_scale2 - cover;                }            }            if(cover > aa_mask) cover = aa_mask;            return cover;        }        //--------------------------------------------------------------------        // Sweeps one scanline with one style index. The style ID can be         // determined by calling style().         template<class Scanline> bool sweep_scanline(Scanline& sl, int style_idx)        {            int scan_y = m_scan_y - 1;            if(scan_y > m_outline.max_y()) return false;            sl.reset_spans();            if(style_idx < 0) style_idx = 0;            else              style_idx++;            const style_info& st = m_styles[m_ast[style_idx]];            unsigned num_cells = st.num_cells;            cell_info* cell = &m_cells[st.start_cell];            int cover = 0;            while(num_cells--)            {                unsigned alpha;                int x = cell->x;                int area = cell->area;                cover += cell->cover;                ++cell;                if(area)                {                    alpha = calculate_alpha((cover << (poly_subpixel_shift + 1)) - area);                    sl.add_cell(x, alpha);                    x++;                }                if(num_cells && cell->x > x)                {                    alpha = calculate_alpha(cover << (poly_subpixel_shift + 1));                    if(alpha)                    {                        sl.add_span(x, cell->x - x, alpha);                    }                }            }            if(sl.num_spans() == 0) return false;            sl.finalize(scan_y);            return true;        }    private:        void add_style(int style_id);        //--------------------------------------------------------------------        // Disable copying        rasterizer_compound_aa(const rasterizer_compound_aa<Clip>&);        const rasterizer_compound_aa<Clip>&         operator = (const rasterizer_compound_aa<Clip>&);    private:        rasterizer_cells_aa<cell_style_aa> m_outline;        clip_type              m_clipper;        filling_rule_e         m_filling_rule;        pod_vector<style_info> m_styles;  // Active Styles        pod_vector<unsigned>   m_ast;     // Active Style Table (unique values)        pod_vector<int8u>      m_asm;     // Active Style Mask         pod_vector<cell_info>  m_cells;        int      m_min_style;        int      m_max_style;        int      m_scan_y;    };    //------------------------------------------------------------------------    template<class Clip>     void rasterizer_compound_aa<Clip>::reset()     {         m_outline.reset();         m_min_style =  0x7FFFFFFF;        m_max_style = -0x7FFFFFFF;        m_scan_y    =  0x7FFFFFFF;    }    //------------------------------------------------------------------------    template<class Clip>     void rasterizer_compound_aa<Clip>::filling_rule(filling_rule_e filling_rule)     {         m_filling_rule = filling_rule;     }    //------------------------------------------------------------------------    template<class Clip>     void rasterizer_compound_aa<Clip>::clip_box(double x1, double y1,                                                 double x2, double y2)    {        reset();        m_clipper.clip_box(conv_type::upscale(x1), conv_type::upscale(y1),                            conv_type::upscale(x2), conv_type::upscale(y2));    }    //------------------------------------------------------------------------    template<class Clip>     void rasterizer_compound_aa<Clip>::reset_clipping()    {        reset();        m_clipper.reset_clipping();

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?