Anti-Grain Geometry - AGG (libagg)
2.5
|
00001 //---------------------------------------------------------------------------- 00002 // Anti-Grain Geometry (AGG) - Version 2.5 00003 // A high quality rendering engine for C++ 00004 // Copyright (C) 2002-2006 Maxim Shemanarev 00005 // Contact: mcseem@antigrain.com 00006 // mcseemagg@yahoo.com 00007 // http://antigrain.com 00008 // 00009 // AGG is free software; you can redistribute it and/or 00010 // modify it under the terms of the GNU General Public License 00011 // as published by the Free Software Foundation; either version 2 00012 // of the License, or (at your option) any later version. 00013 // 00014 // AGG is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 // GNU General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU General Public License 00020 // along with AGG; if not, write to the Free Software 00021 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00022 // MA 02110-1301, USA. 00023 //---------------------------------------------------------------------------- 00024 00025 #ifndef AGG_SPAN_SUBDIV_ADAPTOR_INCLUDED 00026 #define AGG_SPAN_SUBDIV_ADAPTOR_INCLUDED 00027 00028 #include "agg_basics.h" 00029 00030 namespace agg 00031 { 00032 00033 //=================================================span_subdiv_adaptor 00034 template<class Interpolator, unsigned SubpixelShift = 8> 00035 class span_subdiv_adaptor 00036 { 00037 public: 00038 typedef Interpolator interpolator_type; 00039 typedef typename interpolator_type::trans_type trans_type; 00040 00041 enum sublixel_scale_e 00042 { 00043 subpixel_shift = SubpixelShift, 00044 subpixel_scale = 1 << subpixel_shift 00045 }; 00046 00047 00048 //---------------------------------------------------------------- 00049 span_subdiv_adaptor() : 00050 m_subdiv_shift(4), 00051 m_subdiv_size(1 << m_subdiv_shift), 00052 m_subdiv_mask(m_subdiv_size - 1) {} 00053 00054 span_subdiv_adaptor(interpolator_type& interpolator, 00055 unsigned subdiv_shift = 4) : 00056 m_subdiv_shift(subdiv_shift), 00057 m_subdiv_size(1 << m_subdiv_shift), 00058 m_subdiv_mask(m_subdiv_size - 1), 00059 m_interpolator(&interpolator) {} 00060 00061 span_subdiv_adaptor(interpolator_type& interpolator, 00062 double x, double y, unsigned len, 00063 unsigned subdiv_shift = 4) : 00064 m_subdiv_shift(subdiv_shift), 00065 m_subdiv_size(1 << m_subdiv_shift), 00066 m_subdiv_mask(m_subdiv_size - 1), 00067 m_interpolator(&interpolator) 00068 { 00069 begin(x, y, len); 00070 } 00071 00072 00073 //---------------------------------------------------------------- 00074 const interpolator_type& interpolator() const { return *m_interpolator; } 00075 void interpolator(interpolator_type& intr) { m_interpolator = &intr; } 00076 00077 //---------------------------------------------------------------- 00078 const trans_type& transformer() const 00079 { 00080 return *m_interpolator->transformer(); 00081 } 00082 void transformer(const trans_type& trans) 00083 { 00084 m_interpolator->transformer(trans); 00085 } 00086 00087 //---------------------------------------------------------------- 00088 unsigned subdiv_shift() const { return m_subdiv_shift; } 00089 void subdiv_shift(unsigned shift) 00090 { 00091 m_subdiv_shift = shift; 00092 m_subdiv_size = 1 << m_subdiv_shift; 00093 m_subdiv_mask = m_subdiv_size - 1; 00094 } 00095 00096 //---------------------------------------------------------------- 00097 void begin(double x, double y, unsigned len) 00098 { 00099 m_pos = 1; 00100 m_src_x = iround(x * subpixel_scale) + subpixel_scale; 00101 m_src_y = y; 00102 m_len = len; 00103 if(len > m_subdiv_size) len = m_subdiv_size; 00104 m_interpolator->begin(x, y, len); 00105 } 00106 00107 //---------------------------------------------------------------- 00108 void operator++() 00109 { 00110 ++(*m_interpolator); 00111 if(m_pos >= m_subdiv_size) 00112 { 00113 unsigned len = m_len; 00114 if(len > m_subdiv_size) len = m_subdiv_size; 00115 m_interpolator->resynchronize(double(m_src_x) / double(subpixel_scale) + len, 00116 m_src_y, 00117 len); 00118 m_pos = 0; 00119 } 00120 m_src_x += subpixel_scale; 00121 ++m_pos; 00122 --m_len; 00123 } 00124 00125 //---------------------------------------------------------------- 00126 void coordinates(int* x, int* y) const 00127 { 00128 m_interpolator->coordinates(x, y); 00129 } 00130 00131 //---------------------------------------------------------------- 00132 void local_scale(int* x, int* y) const 00133 { 00134 m_interpolator->local_scale(x, y); 00135 } 00136 00137 00138 private: 00139 unsigned m_subdiv_shift; 00140 unsigned m_subdiv_size; 00141 unsigned m_subdiv_mask; 00142 interpolator_type* m_interpolator; 00143 int m_src_x; 00144 double m_src_y; 00145 unsigned m_pos; 00146 unsigned m_len; 00147 }; 00148 00149 } 00150 00151 #endif