1 //---------------------------------------------------------------------------- 2 // Anti-Grain Geometry - Version 2.4 3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) 4 // 5 // Permission to copy, use, modify, sell and distribute this software 6 // is granted provided this copyright notice appears in all copies. 7 // This software is provided "as is" without express or implied 8 // warranty, and with no claim as to its suitability for any purpose. 9 // 10 //---------------------------------------------------------------------------- 11 // Contact: mcseem@antigrain.com 12 // mcseemagg@yahoo.com 13 // http://www.antigrain.com 14 //---------------------------------------------------------------------------- 15 // 16 // Adaptation for high precision colors has been sponsored by 17 // Liberty Technology Systems, Inc., visit http://lib-sys.com 18 // 19 // Liberty Technology Systems, Inc. is the provider of 20 // PostScript and PDF technology for software developers. 21 // 22 //---------------------------------------------------------------------------- 23 24 25 #ifndef AGG_SPAN_PATTERN_GRAY_INCLUDED 26 #define AGG_SPAN_PATTERN_GRAY_INCLUDED 27 28 #include "agg_basics.h" 29 30 namespace agg 31 { 32 33 //=======================================================span_pattern_gray 34 template<class Source> class span_pattern_gray 35 { 36 public: 37 typedef Source source_type; 38 typedef typename source_type::color_type color_type; 39 typedef typename color_type::value_type value_type; 40 typedef typename color_type::calc_type calc_type; 41 42 //-------------------------------------------------------------------- 43 span_pattern_gray() {} 44 span_pattern_gray(source_type& src, 45 unsigned offset_x, unsigned offset_y) : 46 m_src(&src), 47 m_offset_x(offset_x), 48 m_offset_y(offset_y), 49 m_alpha(color_type::base_mask) 50 {} 51 52 //-------------------------------------------------------------------- 53 void attach(source_type& v) { m_src = &v; } 54 source_type& source() { return *m_src; } 55 const source_type& source() const { return *m_src; } 56 57 //-------------------------------------------------------------------- 58 void offset_x(unsigned v) { m_offset_x = v; } 59 void offset_y(unsigned v) { m_offset_y = v; } 60 unsigned offset_x() const { return m_offset_x; } 61 unsigned offset_y() const { return m_offset_y; } 62 void alpha(value_type v) { m_alpha = v; } 63 value_type alpha() const { return m_alpha; } 64 65 //-------------------------------------------------------------------- 66 void prepare() {} 67 void generate(color_type* span, int x, int y, unsigned len) 68 { 69 x += m_offset_x; 70 y += m_offset_y; 71 const value_type* p = (const value_type*)m_src->span(x, y, len); 72 do 73 { 74 span->v = *p; 75 span->a = m_alpha; 76 p = m_src->next_x(); 77 ++span; 78 } 79 while(--len); 80 } 81 82 private: 83 source_type* m_src; 84 unsigned m_offset_x; 85 unsigned m_offset_y; 86 value_type m_alpha; 87 88 }; 89 90 } 91 92 #endif 93 94