⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 agg_span_image_filter_rgb.h

📁 这是VCF框架的代码
💻 H
📖 第 1 页 / 共 3 页
字号:
//----------------------------------------------------------------------------// Anti-Grain Geometry - Version 2.4// 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.////----------------------------------------------------------------------------// Contact: mcseem@antigrain.com//          mcseemagg@yahoo.com//          http://www.antigrain.com//----------------------------------------------------------------------------//// Adaptation for high precision colors 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_SPAN_IMAGE_FILTER_RGB_INCLUDED#define AGG_SPAN_IMAGE_FILTER_RGB_INCLUDED#include "agg_basics.h"#include "agg_color_rgba.h"#include "agg_span_image_filter.h"namespace agg{    //===============================================span_image_filter_rgb_nn    template<class Source, class Interpolator>     class span_image_filter_rgb_nn :     public span_image_filter<Source, Interpolator>    {    public:        typedef Source source_type;        typedef typename source_type::color_type color_type;        typedef typename source_type::order_type order_type;        typedef Interpolator interpolator_type;        typedef span_image_filter<source_type, interpolator_type> base_type;        typedef typename color_type::value_type value_type;        typedef typename color_type::calc_type calc_type;        enum base_scale_e        {            base_shift = color_type::base_shift,            base_mask  = color_type::base_mask        };        //--------------------------------------------------------------------        span_image_filter_rgb_nn() {}        span_image_filter_rgb_nn(source_type& src,                                  interpolator_type& inter) :            base_type(src, inter, 0)         {}        //--------------------------------------------------------------------        void generate(color_type* span, int x, int y, unsigned len)        {            base_type::interpolator().begin(x + base_type::filter_dx_dbl(),                                             y + base_type::filter_dy_dbl(), len);            do            {                base_type::interpolator().coordinates(&x, &y);                const value_type* fg_ptr = (const value_type*)                    base_type::source().span(x >> image_subpixel_shift,                                              y >> image_subpixel_shift,                                              1);                span->r = fg_ptr[order_type::R];                span->g = fg_ptr[order_type::G];                span->b = fg_ptr[order_type::B];                span->a = base_mask;                ++span;                ++base_type::interpolator();            } while(--len);        }    };    //==========================================span_image_filter_rgb_bilinear    template<class Source, class Interpolator>     class span_image_filter_rgb_bilinear :     public span_image_filter<Source, Interpolator>    {    public:        typedef Source source_type;        typedef typename source_type::color_type color_type;        typedef typename source_type::order_type order_type;        typedef Interpolator interpolator_type;        typedef span_image_filter<source_type, interpolator_type> base_type;        typedef typename color_type::value_type value_type;        typedef typename color_type::calc_type calc_type;        enum base_scale_e        {            base_shift = color_type::base_shift,            base_mask  = color_type::base_mask        };        //--------------------------------------------------------------------        span_image_filter_rgb_bilinear() {}        span_image_filter_rgb_bilinear(source_type& src,                                        interpolator_type& inter) :            base_type(src, inter, 0)         {}        //--------------------------------------------------------------------        void generate(color_type* span, int x, int y, unsigned len)        {            base_type::interpolator().begin(x + base_type::filter_dx_dbl(),                                             y + base_type::filter_dy_dbl(), len);            calc_type fg[3];            const value_type *fg_ptr;            do            {                int x_hr;                int y_hr;                base_type::interpolator().coordinates(&x_hr, &y_hr);                x_hr -= base_type::filter_dx_int();                y_hr -= base_type::filter_dy_int();                int x_lr = x_hr >> image_subpixel_shift;                int y_lr = y_hr >> image_subpixel_shift;                unsigned weight;                fg[0] =                 fg[1] =                 fg[2] = image_subpixel_scale * image_subpixel_scale / 2;                x_hr &= image_subpixel_mask;                y_hr &= image_subpixel_mask;                fg_ptr = (const value_type*)base_type::source().span(x_lr, y_lr, 2);                weight = (image_subpixel_scale - x_hr) *                          (image_subpixel_scale - y_hr);                fg[0] += weight * *fg_ptr++;                fg[1] += weight * *fg_ptr++;                fg[2] += weight * *fg_ptr;                fg_ptr = (const value_type*)base_type::source().next_x();                weight = x_hr * (image_subpixel_scale - y_hr);                fg[0] += weight * *fg_ptr++;                fg[1] += weight * *fg_ptr++;                fg[2] += weight * *fg_ptr;                fg_ptr = (const value_type*)base_type::source().next_y();                weight = (image_subpixel_scale - x_hr) * y_hr;                fg[0] += weight * *fg_ptr++;                fg[1] += weight * *fg_ptr++;                fg[2] += weight * *fg_ptr;                fg_ptr = (const value_type*)base_type::source().next_x();                weight = x_hr * y_hr;                fg[0] += weight * *fg_ptr++;                fg[1] += weight * *fg_ptr++;                fg[2] += weight * *fg_ptr;                span->r = value_type(fg[order_type::R] >> (image_subpixel_shift * 2));                span->g = value_type(fg[order_type::G] >> (image_subpixel_shift * 2));                span->b = value_type(fg[order_type::B] >> (image_subpixel_shift * 2));                span->a = base_mask;                ++span;                ++base_type::interpolator();            } while(--len);        }    };    //=====================================span_image_filter_rgb_bilinear_clip    template<class Source, class Interpolator>     class span_image_filter_rgb_bilinear_clip :     public span_image_filter<Source, Interpolator>    {    public:        typedef Source source_type;        typedef typename source_type::color_type color_type;        typedef typename source_type::order_type order_type;        typedef Interpolator interpolator_type;        typedef span_image_filter<source_type, interpolator_type> base_type;        typedef typename color_type::value_type value_type;        typedef typename color_type::calc_type calc_type;        enum base_scale_e        {            base_shift = color_type::base_shift,            base_mask  = color_type::base_mask        };        //--------------------------------------------------------------------        span_image_filter_rgb_bilinear_clip() {}        span_image_filter_rgb_bilinear_clip(source_type& src,                                             const color_type& back_color,                                            interpolator_type& inter) :            base_type(src, inter, 0),            m_back_color(back_color)        {}        const color_type& background_color() const { return m_back_color; }        void background_color(const color_type& v)   { m_back_color = v; }        //--------------------------------------------------------------------        void generate(color_type* span, int x, int y, unsigned len)        {            base_type::interpolator().begin(x + base_type::filter_dx_dbl(),                                             y + base_type::filter_dy_dbl(), len);            calc_type fg[3];            calc_type src_alpha;            value_type back_r = m_back_color.r;            value_type back_g = m_back_color.g;            value_type back_b = m_back_color.b;            value_type back_a = m_back_color.a;            const value_type *fg_ptr;            int maxx = base_type::source().width() - 1;            int maxy = base_type::source().height() - 1;            do            {                int x_hr;                int y_hr;                                base_type::interpolator().coordinates(&x_hr, &y_hr);                x_hr -= base_type::filter_dx_int();                y_hr -= base_type::filter_dy_int();                int x_lr = x_hr >> image_subpixel_shift;                int y_lr = y_hr >> image_subpixel_shift;                unsigned weight;                if(x_lr >= 0    && y_lr >= 0 &&                   x_lr <  maxx && y_lr <  maxy)                 {                    fg[0] =                     fg[1] =                     fg[2] = image_subpixel_scale * image_subpixel_scale / 2;                    x_hr &= image_subpixel_mask;                    y_hr &= image_subpixel_mask;                    fg_ptr = (const value_type*)                        base_type::source().row_ptr(y_lr) + x_lr + x_lr + x_lr;                    weight = (image_subpixel_scale - x_hr) *                              (image_subpixel_scale - y_hr);                    fg[0] += weight * *fg_ptr++;                    fg[1] += weight * *fg_ptr++;                    fg[2] += weight * *fg_ptr++;                    weight = x_hr * (image_subpixel_scale - y_hr);                    fg[0] += weight * *fg_ptr++;                    fg[1] += weight * *fg_ptr++;                    fg[2] += weight * *fg_ptr++;                    ++y_lr;                    fg_ptr = (const value_type*)                        base_type::source().row_ptr(y_lr) + x_lr + x_lr + x_lr;                    weight = (image_subpixel_scale - x_hr) * y_hr;                    fg[0] += weight * *fg_ptr++;                    fg[1] += weight * *fg_ptr++;                    fg[2] += weight * *fg_ptr++;                    weight = x_hr * y_hr;                    fg[0] += weight * *fg_ptr++;                    fg[1] += weight * *fg_ptr++;                    fg[2] += weight * *fg_ptr++;                    fg[0] >>= image_subpixel_shift * 2;                    fg[1] >>= image_subpixel_shift * 2;                    fg[2] >>= image_subpixel_shift * 2;                    src_alpha = base_mask;                }                else                {                    if(x_lr < -1   || y_lr < -1 ||                       x_lr > maxx || y_lr > maxy)                    {                        fg[order_type::R] = back_r;                        fg[order_type::G] = back_g;                        fg[order_type::B] = back_b;                        src_alpha         = back_a;                    }                    else                    {                        fg[0] =                         fg[1] =                         fg[2] =                         src_alpha = image_subpixel_scale * image_subpixel_scale / 2;                        x_hr &= image_subpixel_mask;                        y_hr &= image_subpixel_mask;                        weight = (image_subpixel_scale - x_hr) *                                  (image_subpixel_scale - y_hr);                        if(x_lr >= 0    && y_lr >= 0 &&

⌨️ 快捷键说明

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