├── CHANGES ├── MANIFEST.in ├── agg2 ├── README.txt ├── include │ ├── agg_bitset_iterator.h │ ├── agg_trans_warp_magnifier.h │ ├── agg_conv_bspline.h │ ├── agg_span_generator.h │ ├── agg_conv_segmentator.h │ ├── agg_conv_shorten_path.h │ ├── agg_vpgen_segmentator.h │ ├── agg_span_converter.h │ ├── agg_conv_marker_adaptor.h │ ├── agg_conv_unclose_polygon.h │ ├── agg_shorten_path.h │ ├── agg_arc.h │ ├── agg_render_scanlines.h │ ├── agg_span_solid.h │ ├── agg_embedded_raster_fonts.h │ ├── agg_vcgen_bspline.h │ ├── agg_conv_contour.h │ ├── agg_conv_dash.h │ ├── agg_span_allocator.h │ ├── agg_vcgen_markers_term.h │ ├── agg_vpgen_clip_polygon.h │ ├── agg_conv_transform.h │ ├── agg_arrowhead.h │ ├── dbg_new │ │ └── agg_dbg_new.h │ ├── util │ │ └── agg_color_conv.h │ ├── agg_rounded_rect.h │ ├── agg_conv_concat.h │ ├── agg_bspline.h │ ├── agg_vcgen_smooth_poly1.h │ ├── agg_span_interpolator_adaptor.h │ ├── agg_conv_smooth_poly1.h │ ├── platform │ │ ├── mac │ │ │ └── agg_mac_pmap.h │ │ └── win32 │ │ │ └── agg_win32_bmp.h │ ├── agg_conv_clip_polygon.h │ ├── agg_vcgen_contour.h │ ├── agg_conv_stroke.h │ ├── agg_span_pattern.h │ ├── agg_span_pattern_rgba32.h │ ├── agg_span_pattern_rgb24.h │ ├── agg_ellipse.h │ ├── agg_trans_single_path.h │ ├── agg_vcgen_dash.h │ ├── agg_ellipse_bresenham.h │ ├── agg_span_interpolator_trans.h │ ├── agg_span_interpolator_linear.h │ ├── agg_span_image_filter.h │ ├── agg_gamma_lut.h │ ├── ctrl │ │ ├── agg_ctrl.h │ │ ├── agg_gamma_spline.h │ │ └── agg_cbox_ctrl.h │ ├── agg_gray8.h │ ├── agg_gamma_functions.h │ ├── agg_bounding_rect.h │ ├── agg_pattern_filters_rgba8.h │ ├── agg_conv_adaptor_vpgen.h │ ├── agg_vcgen_vertex_sequence.h │ ├── agg_conv_close_polygon.h │ ├── agg_rasterizer_outline.h │ └── agg_vertex_iterator.h └── src │ ├── agg_trans_warp_magnifier.cpp │ ├── agg_vpgen_segmentator.cpp │ ├── agg_line_aa_basics.cpp │ ├── agg_arc.cpp │ ├── agg_vcgen_markers_term.cpp │ ├── agg_image_filters.cpp │ ├── agg_line_profile_aa.cpp │ ├── agg_arrowhead.cpp │ ├── ctrl │ └── agg_gamma_spline.cpp │ └── agg_vpgen_clip_polygon.cpp ├── setup.py ├── selftest.py └── README /CHANGES: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scottopell/aggdraw-64bits/HEAD/CHANGES -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README 2 | include MANIFEST.in 3 | 4 | recursive-include agg2/ * 5 | 6 | global-exclude *~ *.pyc 7 | -------------------------------------------------------------------------------- /agg2/README.txt: -------------------------------------------------------------------------------- 1 | 2 | The Anti-Grain Geometry Project 3 | A high quality rendering engine for C++ 4 | http://antigrain.com 5 | 6 | Anti-Grain Geometry - Version 2.0 7 | Copyright (C) 2002 Maxim Shemanarev (McSeem) 8 | 9 | Permission to copy, use, modify, sell and distribute this software 10 | is granted provided this copyright notice appears in all copies. 11 | This software is provided "as is" without express or implied 12 | warranty, and with no claim as to its suitability for any purpose. 13 | 14 | 15 | 16 | TODO: write compilation/installation stuff 17 | 18 | 19 | -------------------------------------------------------------------------------- /agg2/include/agg_bitset_iterator.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_BITSET_ITERATOR_INCLUDED 17 | #define AGG_BITSET_ITERATOR_INCLUDED 18 | 19 | #include "agg_basics.h" 20 | 21 | namespace agg 22 | { 23 | 24 | class bitset_iterator 25 | { 26 | public: 27 | bitset_iterator(const int8u* bits, unsigned offset = 0) : 28 | m_bits(bits + (offset >> 3)), 29 | m_mask(0x80 >> (offset & 7)) 30 | {} 31 | 32 | void operator ++ () 33 | { 34 | m_mask >>= 1; 35 | if(m_mask == 0) 36 | { 37 | ++m_bits; 38 | m_mask = 0x80; 39 | } 40 | } 41 | 42 | unsigned bit() const 43 | { 44 | return (*m_bits) & m_mask; 45 | } 46 | 47 | private: 48 | const int8u* m_bits; 49 | int8u m_mask; 50 | }; 51 | 52 | } 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /agg2/include/agg_trans_warp_magnifier.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_WARP_MAGNIFIER_INCLUDED 17 | #define AGG_WARP_MAGNIFIER_INCLUDED 18 | 19 | 20 | namespace agg 21 | { 22 | 23 | //----------------------------------------------------trans_warp_magnifier 24 | // 25 | // See Inmplementation agg_trans_warp_magnifier.cpp 26 | // 27 | class trans_warp_magnifier 28 | { 29 | public: 30 | trans_warp_magnifier() : m_xc(0.0), m_yc(0.0), m_magn(1.0), m_radius(1.0) {} 31 | 32 | void center(double x, double y) { m_xc = x; m_yc = y; } 33 | void magnification(double m) { m_magn = m; } 34 | void radius(double r) { m_radius = r; } 35 | 36 | void transform(double* x, double* y) const; 37 | void inverse_transform(double* x, double* y) const; 38 | 39 | private: 40 | double m_xc; 41 | double m_yc; 42 | double m_magn; 43 | double m_radius; 44 | }; 45 | 46 | 47 | } 48 | 49 | 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /agg2/src/agg_trans_warp_magnifier.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #include 17 | #include "agg_trans_warp_magnifier.h" 18 | 19 | namespace agg 20 | { 21 | 22 | //------------------------------------------------------------------------ 23 | void trans_warp_magnifier::transform(double* x, double* y) const 24 | { 25 | double dx = *x - m_xc; 26 | double dy = *y - m_yc; 27 | double r = sqrt(dx * dx + dy * dy); 28 | if(r < m_radius) 29 | { 30 | *x = m_xc + dx * m_magn; 31 | *y = m_yc + dy * m_magn; 32 | return; 33 | } 34 | 35 | double m = (r + m_radius * (m_magn - 1.0)) / r; 36 | *x = m_xc + dx * m; 37 | *y = m_yc + dy * m; 38 | } 39 | 40 | //------------------------------------------------------------------------ 41 | void trans_warp_magnifier::inverse_transform(double* x, double* y) const 42 | { 43 | trans_warp_magnifier t(*this); 44 | t.magnification(1.0 / m_magn); 45 | t.radius(m_radius * m_magn); 46 | t.transform(x, y); 47 | } 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /agg2/include/agg_conv_bspline.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_CONV_BSPLINE_INCLUDED 16 | #define AGG_CONV_BSPLINE_INCLUDED 17 | 18 | #include "agg_basics.h" 19 | #include "agg_vcgen_bspline.h" 20 | #include "agg_conv_adaptor_vcgen.h" 21 | 22 | 23 | namespace agg 24 | { 25 | 26 | //---------------------------------------------------------conv_bspline 27 | template 28 | struct conv_bspline : public conv_adaptor_vcgen 29 | { 30 | typedef conv_adaptor_vcgen base_type; 31 | 32 | conv_bspline(VertexSource& vs) : 33 | conv_adaptor_vcgen(vs) {} 34 | 35 | void interpolation_step(double v) { base_type::generator().interpolation_step(v); } 36 | double interpolation_step() const { return base_type::generator().interpolation_step(); } 37 | 38 | private: 39 | conv_bspline(const conv_bspline&); 40 | const conv_bspline& 41 | operator = (const conv_bspline&); 42 | }; 43 | 44 | } 45 | 46 | 47 | #endif 48 | 49 | -------------------------------------------------------------------------------- /agg2/include/agg_span_generator.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_SPAN_GENERATOR_INCLUDED 17 | #define AGG_SPAN_GENERATOR_INCLUDED 18 | 19 | #include "agg_basics.h" 20 | #include "agg_span_allocator.h" 21 | 22 | namespace agg 23 | { 24 | 25 | //==========================================================span_generator 26 | template class span_generator 27 | { 28 | public: 29 | typedef ColorT color_type; 30 | typedef Allocator alloc_type; 31 | 32 | //-------------------------------------------------------------------- 33 | span_generator(alloc_type& alloc) : m_alloc(&alloc) {} 34 | 35 | //-------------------------------------------------------------------- 36 | void allocator(alloc_type& alloc) { m_alloc = &alloc; } 37 | alloc_type& allocator() { return *m_alloc; } 38 | 39 | //-------------------------------------------------------------------- 40 | void prepare(unsigned max_span_len) 41 | { 42 | m_alloc->allocate(max_span_len); 43 | } 44 | 45 | private: 46 | alloc_type* m_alloc; 47 | }; 48 | } 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /agg2/include/agg_conv_segmentator.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_CONV_SEGMENTATOR_INCLUDED 17 | #define AGG_CONV_SEGMENTATOR_INCLUDED 18 | 19 | #include "agg_basics.h" 20 | #include "agg_conv_adaptor_vpgen.h" 21 | #include "agg_vpgen_segmentator.h" 22 | 23 | namespace agg 24 | { 25 | 26 | //========================================================conv_segmentator 27 | template 28 | struct conv_segmentator : public conv_adaptor_vpgen 29 | { 30 | typedef conv_adaptor_vpgen base_type; 31 | 32 | conv_segmentator(VertexSource& vs) : 33 | conv_adaptor_vpgen(vs) {} 34 | 35 | void approximation_scale(double s) { base_type::vpgen().approximation_scale(s); } 36 | double approximation_scale() const { return base_type::vpgen().approximation_scale(); } 37 | 38 | private: 39 | conv_segmentator(const conv_segmentator&); 40 | const conv_segmentator& 41 | operator = (const conv_segmentator&); 42 | }; 43 | 44 | 45 | } 46 | 47 | #endif 48 | 49 | -------------------------------------------------------------------------------- /agg2/include/agg_conv_shorten_path.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_CONV_SHORTEN_PATH_INCLUDED 17 | #define AGG_CONV_SHORTEN_PATH_INCLUDED 18 | 19 | #include "agg_basics.h" 20 | #include "agg_conv_adaptor_vcgen.h" 21 | #include "agg_vcgen_vertex_sequence.h" 22 | 23 | namespace agg 24 | { 25 | 26 | //=======================================================conv_shorten_path 27 | template class conv_shorten_path : 28 | public conv_adaptor_vcgen 29 | { 30 | public: 31 | typedef conv_adaptor_vcgen base_type; 32 | 33 | conv_shorten_path(VertexSource& vs) : 34 | conv_adaptor_vcgen(vs) 35 | { 36 | } 37 | 38 | void shorten(double s) { base_type::generator().shorten(s); } 39 | double shorten() const { return base_type::generator().shorten(); } 40 | 41 | private: 42 | conv_shorten_path(const conv_shorten_path&); 43 | const conv_shorten_path& 44 | operator = (const conv_shorten_path&); 45 | }; 46 | 47 | 48 | } 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /agg2/include/agg_vpgen_segmentator.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_VPGEN_SEGMENTATOR_INCLUDED 17 | #define AGG_VPGEN_SEGMENTATOR_INCLUDED 18 | 19 | #include 20 | #include "agg_basics.h" 21 | 22 | namespace agg 23 | { 24 | 25 | //=======================================================vpgen_segmentator 26 | // 27 | // See Implementation agg_vpgen_segmentator.cpp 28 | // 29 | class vpgen_segmentator 30 | { 31 | public: 32 | vpgen_segmentator() : m_approximation_scale(1.0) {} 33 | 34 | void approximation_scale(double s) { m_approximation_scale = s; } 35 | double approximation_scale() const { return m_approximation_scale; } 36 | 37 | void reset() { m_cmd = path_cmd_stop; } 38 | 39 | void move_to(double x, double y); 40 | void line_to(double x, double y); 41 | 42 | unsigned vertex(double* x, double* y); 43 | 44 | private: 45 | double m_approximation_scale; 46 | double m_x1; 47 | double m_y1; 48 | double m_dx; 49 | double m_dy; 50 | double m_dl; 51 | double m_ddl; 52 | unsigned m_cmd; 53 | }; 54 | 55 | 56 | 57 | } 58 | 59 | #endif 60 | 61 | -------------------------------------------------------------------------------- /agg2/include/agg_span_converter.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_SPAN_CONVERTER_INCLUDED 17 | #define AGG_SPAN_CONVERTER_INCLUDED 18 | 19 | #include "agg_basics.h" 20 | 21 | namespace agg 22 | { 23 | //----------------------------------------------------------span_converter 24 | template class span_converter 25 | { 26 | public: 27 | typedef typename SpanGenerator::color_type color_type; 28 | 29 | span_converter(SpanGenerator& span_gen, Conv& conv) : 30 | m_span_gen(&span_gen), m_conv(&conv) {} 31 | 32 | //-------------------------------------------------------------------- 33 | void prepare(unsigned max_span_len) 34 | { 35 | m_span_gen->prepare(max_span_len); 36 | } 37 | 38 | //-------------------------------------------------------------------- 39 | color_type* generate(int x, int y, unsigned len) 40 | { 41 | color_type* span = m_span_gen->generate(x, y, len); 42 | m_conv->convert(span, len); 43 | return span; 44 | } 45 | 46 | private: 47 | SpanGenerator* m_span_gen; 48 | Conv* m_conv; 49 | }; 50 | 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /agg2/include/agg_conv_marker_adaptor.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_CONV_MARKER_ADAPTOR_INCLUDED 17 | #define AGG_CONV_MARKER_ADAPTOR_INCLUDED 18 | 19 | #include "agg_basics.h" 20 | #include "agg_conv_adaptor_vcgen.h" 21 | #include "agg_vcgen_vertex_sequence.h" 22 | 23 | namespace agg 24 | { 25 | 26 | //=====================================================conv_marker_adaptor 27 | template 28 | struct conv_marker_adaptor : 29 | public conv_adaptor_vcgen 30 | { 31 | typedef Markers marker_type; 32 | typedef conv_adaptor_vcgen base_type; 33 | 34 | conv_marker_adaptor(VertexSource& vs) : 35 | conv_adaptor_vcgen(vs) 36 | { 37 | } 38 | 39 | void shorten(double s) { base_type::generator().shorten(s); } 40 | double shorten() const { return base_type::generator().shorten(); } 41 | 42 | private: 43 | conv_marker_adaptor(const conv_marker_adaptor&); 44 | const conv_marker_adaptor& 45 | operator = (const conv_marker_adaptor&); 46 | }; 47 | 48 | 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /agg2/src/agg_vpgen_segmentator.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #include 17 | #include "agg_vpgen_segmentator.h" 18 | 19 | namespace agg 20 | { 21 | 22 | void vpgen_segmentator::move_to(double x, double y) 23 | { 24 | m_x1 = x; 25 | m_y1 = y; 26 | m_dx = 0.0; 27 | m_dy = 0.0; 28 | m_dl = 2.0; 29 | m_cmd = path_cmd_move_to; 30 | } 31 | 32 | void vpgen_segmentator::line_to(double x, double y) 33 | { 34 | m_x1 += m_dx; 35 | m_y1 += m_dy; 36 | m_dx = x - m_x1; 37 | m_dy = y - m_y1; 38 | double len = sqrt(m_dx * m_dx + m_dy * m_dy) * m_approximation_scale; 39 | if(len < 1e-30) len = 1e-30; 40 | m_ddl = 1.0 / len; 41 | m_dl = (m_cmd == path_cmd_move_to) ? 0.0 : m_ddl; 42 | if(m_cmd == path_cmd_stop) m_cmd = path_cmd_line_to; 43 | } 44 | 45 | unsigned vpgen_segmentator::vertex(double* x, double* y) 46 | { 47 | if(m_cmd == path_cmd_stop) return path_cmd_stop; 48 | 49 | unsigned cmd = m_cmd; 50 | m_cmd = path_cmd_line_to; 51 | if(m_dl > 1.0) 52 | { 53 | m_dl = 1.0; 54 | m_cmd = path_cmd_stop; 55 | } 56 | *x = m_x1 + m_dx * m_dl; 57 | *y = m_y1 + m_dy * m_dl; 58 | m_dl += m_ddl; 59 | return cmd; 60 | } 61 | 62 | } 63 | 64 | -------------------------------------------------------------------------------- /agg2/include/agg_conv_unclose_polygon.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_CONV_UNCLOSE_POLYGON_INCLUDED 17 | #define AGG_CONV_UNCLOSE_POLYGON_INCLUDED 18 | 19 | #include "agg_basics.h" 20 | #include "agg_vertex_iterator.h" 21 | 22 | namespace agg 23 | { 24 | //====================================================conv_unclose_polygon 25 | template class conv_unclose_polygon 26 | { 27 | public: 28 | conv_unclose_polygon(VertexSource& vs) : m_source(&vs) {} 29 | 30 | void set_source(VertexSource& source) { m_source = &source; } 31 | 32 | void rewind(unsigned path_id) 33 | { 34 | m_source->rewind(path_id); 35 | } 36 | 37 | unsigned vertex(double* x, double* y) 38 | { 39 | unsigned cmd = m_source->vertex(x, y); 40 | if(is_end_poly(cmd)) cmd &= ~path_flags_close; 41 | return cmd; 42 | } 43 | 44 | typedef conv_unclose_polygon source_type; 45 | typedef vertex_iterator iterator; 46 | iterator begin(unsigned id) { return iterator(*this, id); } 47 | iterator end() { return iterator(path_cmd_stop); } 48 | 49 | private: 50 | conv_unclose_polygon(const conv_unclose_polygon&); 51 | const conv_unclose_polygon& 52 | operator = (const conv_unclose_polygon&); 53 | 54 | VertexSource* m_source; 55 | }; 56 | 57 | } 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /agg2/include/agg_shorten_path.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_SHORTEN_PATH_INCLUDED 17 | #define AGG_SHORTEN_PATH_INCLUDED 18 | 19 | #include "agg_basics.h" 20 | #include "agg_vertex_sequence.h" 21 | 22 | namespace agg 23 | { 24 | 25 | //===========================================================shorten_path 26 | template 27 | void shorten_path(VertexSequence& vs, double s, unsigned closed = 0) 28 | { 29 | typedef typename VertexSequence::value_type vertex_type; 30 | 31 | if(s > 0.0 && vs.size() > 1) 32 | { 33 | double d; 34 | int n = int(vs.size() - 2); 35 | while(n) 36 | { 37 | d = vs[n].dist; 38 | if(d > s) break; 39 | vs.remove_last(); 40 | s -= d; 41 | --n; 42 | } 43 | if(vs.size() < 2) 44 | { 45 | vs.remove_all(); 46 | } 47 | else 48 | { 49 | n = vs.size() - 1; 50 | vertex_type& prev = vs[n-1]; 51 | vertex_type& last = vs[n]; 52 | d = (prev.dist - s) / prev.dist; 53 | double x = prev.x + (last.x - prev.x) * d; 54 | double y = prev.y + (last.y - prev.y) * d; 55 | last.x = x; 56 | last.y = y; 57 | if(!prev(last)) vs.remove_last(); 58 | vs.close(closed != 0); 59 | } 60 | } 61 | } 62 | 63 | 64 | } 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /agg2/include/agg_arc.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // Arc vertex generator 17 | // 18 | //---------------------------------------------------------------------------- 19 | 20 | #ifndef AGG_ARC_INCLUDED 21 | #define AGG_ARC_INCLUDED 22 | 23 | #include 24 | #include "agg_basics.h" 25 | 26 | namespace agg 27 | { 28 | 29 | //=====================================================================arc 30 | // 31 | // See Implementation agg_arc.cpp 32 | // 33 | class arc 34 | { 35 | public: 36 | arc() : m_scale(1.0), m_initialized(false) {} 37 | arc(double x, double y, 38 | double rx, double ry, 39 | double a1, double a2, 40 | bool ccw=true); 41 | 42 | void init(double x, double y, 43 | double rx, double ry, 44 | double a1, double a2, 45 | bool ccw=true); 46 | 47 | void approximation_scale(double s); 48 | double approximation_scale() const { return m_scale; } 49 | 50 | void rewind(unsigned); 51 | unsigned vertex(double* x, double* y); 52 | 53 | private: 54 | void normalize(double a1, double a2, bool ccw); 55 | 56 | double m_x; 57 | double m_y; 58 | double m_rx; 59 | double m_ry; 60 | double m_angle; 61 | double m_start; 62 | double m_end; 63 | double m_scale; 64 | double m_da; 65 | bool m_ccw; 66 | bool m_initialized; 67 | unsigned m_path_cmd; 68 | }; 69 | 70 | 71 | } 72 | 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /agg2/include/agg_render_scanlines.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_RENDER_SCANLINES_INCLUDED 17 | #define AGG_RENDER_SCANLINES_INCLUDED 18 | 19 | #include "agg_basics.h" 20 | 21 | namespace agg 22 | { 23 | //========================================================render_scanlines 24 | template 25 | void render_scanlines(Rasterizer& ras, Scanline& sl, Renderer& ren) 26 | { 27 | if(ras.rewind_scanlines()) 28 | { 29 | sl.reset(ras.min_x(), ras.max_x()); 30 | ren.prepare(unsigned(ras.max_x() - ras.min_x() + 2)); 31 | 32 | while(ras.sweep_scanline(sl)) 33 | { 34 | ren.render(sl); 35 | } 36 | } 37 | } 38 | 39 | 40 | //========================================================render_all_paths 41 | template 43 | void render_all_paths(Rasterizer& ras, 44 | Scanline& sl, 45 | Renderer& r, 46 | VertexSource& vs, 47 | const ColorStorage& as, 48 | const PathId& id, 49 | unsigned num_paths) 50 | { 51 | for(unsigned i = 0; i < num_paths; i++) 52 | { 53 | ras.reset(); 54 | ras.add_path(vs, id[i]); 55 | r.color(as[i]); 56 | render_scanlines(ras, sl, r); 57 | } 58 | } 59 | 60 | 61 | } 62 | 63 | #endif 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /agg2/include/agg_span_solid.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // span_solid_rgba8 17 | // 18 | //---------------------------------------------------------------------------- 19 | 20 | #ifndef AGG_SPAN_SOLID_INCLUDED 21 | #define AGG_SPAN_SOLID_INCLUDED 22 | 23 | #include "agg_basics.h" 24 | #include "agg_span_generator.h" 25 | 26 | namespace agg 27 | { 28 | //--------------------------------------------------------------span_solid 29 | template > 30 | class span_solid : public span_generator 31 | { 32 | public: 33 | typedef Allocator alloc_type; 34 | typedef ColorT color_type; 35 | typedef span_generator base_type; 36 | 37 | //-------------------------------------------------------------------- 38 | span_solid(alloc_type& alloc) : base_type(alloc) {} 39 | 40 | //-------------------------------------------------------------------- 41 | void color(const color_type& c) { m_color = c; } 42 | const color_type& color() const { return m_color; } 43 | 44 | //-------------------------------------------------------------------- 45 | color_type* generate(int x, int y, unsigned len) 46 | { 47 | color_type* span = base_type::allocator().span(); 48 | do 49 | { 50 | *span++ = m_color; 51 | } 52 | while(--len); 53 | return base_type::allocator().span(); 54 | } 55 | 56 | private: 57 | color_type m_color; 58 | }; 59 | 60 | 61 | } 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /agg2/include/agg_embedded_raster_fonts.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_EMBEDDED_RASTER_FONTS_INCLUDED 17 | #define AGG_EMBEDDED_RASTER_FONTS_INCLUDED 18 | 19 | #include "agg_basics.h" 20 | 21 | namespace agg 22 | { 23 | extern const int8u gse4x6[]; 24 | extern const int8u gse4x8[]; 25 | extern const int8u gse5x7[]; 26 | extern const int8u gse5x9[]; 27 | extern const int8u gse6x12[]; 28 | extern const int8u gse6x9[]; 29 | extern const int8u gse7x11[]; 30 | extern const int8u gse7x11_bold[]; 31 | extern const int8u gse7x15[]; 32 | extern const int8u gse7x15_bold[]; 33 | extern const int8u gse8x16[]; 34 | extern const int8u gse8x16_bold[]; 35 | extern const int8u mcs11_prop[]; 36 | extern const int8u mcs11_prop_condensed[]; 37 | extern const int8u mcs12_prop[]; 38 | extern const int8u mcs13_prop[]; 39 | extern const int8u mcs5x10_mono[]; 40 | extern const int8u mcs5x11_mono[]; 41 | extern const int8u mcs6x10_mono[]; 42 | extern const int8u mcs6x11_mono[]; 43 | extern const int8u mcs7x12_mono_high[]; 44 | extern const int8u mcs7x12_mono_low[]; 45 | extern const int8u verdana12[]; 46 | extern const int8u verdana12_bold[]; 47 | extern const int8u verdana13[]; 48 | extern const int8u verdana13_bold[]; 49 | extern const int8u verdana14[]; 50 | extern const int8u verdana14_bold[]; 51 | extern const int8u verdana16[]; 52 | extern const int8u verdana16_bold[]; 53 | extern const int8u verdana17[]; 54 | extern const int8u verdana17_bold[]; 55 | extern const int8u verdana18[]; 56 | extern const int8u verdana18_bold[]; 57 | } 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /agg2/include/agg_vcgen_bspline.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_VCGEN_BSPLINE_INCLUDED 17 | #define AGG_VCGEN_BSPLINE_INCLUDED 18 | 19 | #include "agg_basics.h" 20 | #include "agg_array.h" 21 | #include "agg_bspline.h" 22 | 23 | 24 | namespace agg 25 | { 26 | 27 | //==========================================================vcgen_bspline 28 | class vcgen_bspline 29 | { 30 | enum status_e 31 | { 32 | initial, 33 | ready, 34 | polygon, 35 | end_poly, 36 | stop 37 | }; 38 | 39 | public: 40 | typedef pod_deque vertex_storage; 41 | 42 | vcgen_bspline(); 43 | 44 | void interpolation_step(double v) { m_interpolation_step = v; } 45 | double interpolation_step() const { return m_interpolation_step; } 46 | 47 | // Vertex Generator Interface 48 | void remove_all(); 49 | void add_vertex(double x, double y, unsigned cmd); 50 | 51 | // Vertex Source Interface 52 | void rewind(unsigned id); 53 | unsigned vertex(double* x, double* y); 54 | 55 | private: 56 | vcgen_bspline(const vcgen_bspline&); 57 | const vcgen_bspline& operator = (const vcgen_bspline&); 58 | 59 | vertex_storage m_src_vertices; 60 | bspline m_spline_x; 61 | bspline m_spline_y; 62 | double m_interpolation_step; 63 | unsigned m_closed; 64 | status_e m_status; 65 | unsigned m_src_vertex; 66 | double m_cur_abscissa; 67 | double m_max_abscissa; 68 | }; 69 | 70 | } 71 | 72 | 73 | #endif 74 | 75 | -------------------------------------------------------------------------------- /agg2/include/agg_conv_contour.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // conv_stroke 17 | // 18 | //---------------------------------------------------------------------------- 19 | #ifndef AGG_CONV_CONTOUR_INCLUDED 20 | #define AGG_CONV_CONTOUR_INCLUDED 21 | 22 | #include "agg_basics.h" 23 | #include "agg_vcgen_contour.h" 24 | #include "agg_conv_adaptor_vcgen.h" 25 | 26 | namespace agg 27 | { 28 | 29 | //-----------------------------------------------------------conv_contour 30 | template 31 | struct conv_contour : public conv_adaptor_vcgen 32 | { 33 | typedef conv_adaptor_vcgen base_type; 34 | 35 | conv_contour(VertexSource& vs) : 36 | conv_adaptor_vcgen(vs) 37 | { 38 | } 39 | 40 | void width(double w) { base_type::generator().width(w); } 41 | void miter_limit(double ml) { base_type::generator().miter_limit(ml); } 42 | void miter_limit_theta(double t) { base_type::generator().miter_limit_theta(t); } 43 | void auto_detect_orientation(bool v) { base_type::generator().auto_detect_orientation(v); } 44 | 45 | double width() const { return base_type::generator().width(); } 46 | double miter_limit() const { return base_type::generator().miter_limit(); } 47 | bool auto_detect_orientation() const { return base_type::generator().auto_detect_orientation(); } 48 | 49 | private: 50 | conv_contour(const conv_contour&); 51 | const conv_contour& 52 | operator = (const conv_contour&); 53 | }; 54 | 55 | } 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /agg2/include/agg_conv_dash.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // conv_dash 17 | // 18 | //---------------------------------------------------------------------------- 19 | #ifndef AGG_CONV_DASH_INCLUDED 20 | #define AGG_CONV_DASH_INCLUDED 21 | 22 | #include "agg_basics.h" 23 | #include "agg_vcgen_dash.h" 24 | #include "agg_conv_adaptor_vcgen.h" 25 | 26 | namespace agg 27 | { 28 | 29 | //---------------------------------------------------------------conv_dash 30 | template 31 | struct conv_dash : public conv_adaptor_vcgen 32 | { 33 | typedef Markers marker_type; 34 | typedef conv_adaptor_vcgen base_type; 35 | 36 | conv_dash(VertexSource& vs) : 37 | conv_adaptor_vcgen(vs) 38 | { 39 | } 40 | 41 | void remove_all_dashes() 42 | { 43 | base_type::generator().remove_all_dashes(); 44 | } 45 | 46 | void add_dash(double dash_len, double gap_len) 47 | { 48 | base_type::generator().add_dash(dash_len, gap_len); 49 | } 50 | 51 | void dash_start(double ds) 52 | { 53 | base_type::generator().dash_start(ds); 54 | } 55 | 56 | void shorten(double s) { base_type::generator().shorten(s); } 57 | double shorten() const { return base_type::generator().shorten(); } 58 | 59 | private: 60 | conv_dash(const conv_dash&); 61 | const conv_dash& 62 | operator = (const conv_dash&); 63 | }; 64 | 65 | 66 | } 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /agg2/include/agg_span_allocator.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_SPAN_ALLOCATOR_INCLUDED 17 | #define AGG_SPAN_ALLOCATOR_INCLUDED 18 | 19 | #include "agg_basics.h" 20 | 21 | namespace agg 22 | { 23 | //----------------------------------------------------------span_allocator 24 | template class span_allocator 25 | { 26 | public: 27 | typedef ColorT color_type; 28 | 29 | //-------------------------------------------------------------------- 30 | ~span_allocator() 31 | { 32 | delete [] m_span; 33 | } 34 | 35 | //-------------------------------------------------------------------- 36 | span_allocator() : 37 | m_max_span_len(0), 38 | m_span(0) 39 | { 40 | } 41 | 42 | //-------------------------------------------------------------------- 43 | color_type* allocate(unsigned max_span_len) 44 | { 45 | if(max_span_len > m_max_span_len) 46 | { 47 | delete [] m_span; 48 | m_span = new color_type[m_max_span_len = max_span_len]; 49 | } 50 | return m_span; 51 | } 52 | 53 | //-------------------------------------------------------------------- 54 | color_type* span() 55 | { 56 | return m_span; 57 | } 58 | 59 | private: 60 | //-------------------------------------------------------------------- 61 | span_allocator(const span_allocator&); 62 | const span_allocator& operator = (const span_allocator&); 63 | 64 | unsigned m_max_span_len; 65 | color_type* m_span; 66 | }; 67 | } 68 | 69 | 70 | #endif 71 | 72 | 73 | -------------------------------------------------------------------------------- /agg2/include/agg_vcgen_markers_term.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_VCGEN_MARKERS_TERM_INCLUDED 17 | #define AGG_VCGEN_MARKERS_TERM_INCLUDED 18 | 19 | #include "agg_basics.h" 20 | #include "agg_vertex_sequence.h" 21 | #include "agg_vertex_iterator.h" 22 | 23 | namespace agg 24 | { 25 | 26 | //======================================================vcgen_markers_term 27 | // 28 | // See Implemantation agg_vcgen_markers_term.cpp 29 | // Terminal markers generator (arrowhead/arrowtail) 30 | // 31 | //------------------------------------------------------------------------ 32 | class vcgen_markers_term 33 | { 34 | public: 35 | vcgen_markers_term() : m_curr_id(0), m_curr_idx(0) {} 36 | 37 | // Vertex Generator Interface 38 | void remove_all(); 39 | void add_vertex(double x, double y, unsigned cmd); 40 | 41 | // Vertex Source Interface 42 | void rewind(unsigned id); 43 | unsigned vertex(double* x, double* y); 44 | 45 | typedef vcgen_markers_term source_type; 46 | typedef vertex_iterator iterator; 47 | iterator begin(unsigned id) { return iterator(*this, id); } 48 | iterator end() { return iterator(path_cmd_stop); } 49 | 50 | private: 51 | vcgen_markers_term(const vcgen_markers_term&); 52 | const vcgen_markers_term& operator = (const vcgen_markers_term&); 53 | 54 | struct coord_type 55 | { 56 | double x, y; 57 | 58 | coord_type() {} 59 | coord_type(double x_, double y_) : x(x_), y(y_) {} 60 | }; 61 | 62 | typedef pod_deque coord_storage; 63 | 64 | coord_storage m_markers; 65 | unsigned m_curr_id; 66 | unsigned m_curr_idx; 67 | }; 68 | 69 | 70 | } 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /agg2/include/agg_vpgen_clip_polygon.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_VPGEN_CLIP_POLYGON_INCLUDED 17 | #define AGG_VPGEN_CLIP_POLYGON_INCLUDED 18 | 19 | #include "agg_basics.h" 20 | 21 | namespace agg 22 | { 23 | 24 | //======================================================vpgen_clip_polygon 25 | // 26 | // See Implementation agg_vpgen_clip_polygon.cpp 27 | // 28 | class vpgen_clip_polygon 29 | { 30 | public: 31 | vpgen_clip_polygon() : 32 | m_clip_box(0, 0, 1, 1), 33 | m_x1(0), 34 | m_y1(0), 35 | m_clip_flags(0), 36 | m_num_vertices(0), 37 | m_vertex(0), 38 | m_cmd(path_cmd_move_to) 39 | { 40 | } 41 | 42 | void clip_box(double x1, double y1, double x2, double y2) 43 | { 44 | m_clip_box.x1 = x1; 45 | m_clip_box.y1 = y1; 46 | m_clip_box.x2 = x2; 47 | m_clip_box.y2 = y2; 48 | m_clip_box.normalize(); 49 | } 50 | 51 | 52 | double x1() const { return m_clip_box.x1; } 53 | double y1() const { return m_clip_box.y1; } 54 | double x2() const { return m_clip_box.x2; } 55 | double y2() const { return m_clip_box.y2; } 56 | 57 | void reset(); 58 | void move_to(double x, double y); 59 | void line_to(double x, double y); 60 | unsigned vertex(double* x, double* y); 61 | 62 | private: 63 | unsigned clipping_flags(double x, double y); 64 | 65 | private: 66 | rect_d m_clip_box; 67 | double m_x1; 68 | double m_y1; 69 | unsigned m_clip_flags; 70 | double m_x[4]; 71 | double m_y[4]; 72 | unsigned m_num_vertices; 73 | unsigned m_vertex; 74 | unsigned m_cmd; 75 | }; 76 | 77 | } 78 | 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /agg2/include/agg_conv_transform.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // class conv_transform 17 | // 18 | //---------------------------------------------------------------------------- 19 | #ifndef AGG_CONV_TRANSFORM_INCLUDED 20 | #define AGG_CONV_TRANSFORM_INCLUDED 21 | 22 | #include "agg_basics.h" 23 | #include "agg_trans_affine.h" 24 | #include "agg_vertex_iterator.h" 25 | 26 | namespace agg 27 | { 28 | 29 | //----------------------------------------------------------conv_transform 30 | template class conv_transform 31 | { 32 | public: 33 | conv_transform(VertexSource& source, const Transformer& tr) : 34 | m_source(&source), m_trans(&tr) {} 35 | 36 | void set_source(VertexSource& source) { m_source = &source; } 37 | 38 | void rewind(unsigned id) 39 | { 40 | m_source->rewind(id); 41 | } 42 | 43 | unsigned vertex(double* x, double* y) 44 | { 45 | unsigned cmd = m_source->vertex(x, y); 46 | if(is_vertex(cmd)) 47 | { 48 | m_trans->transform(x, y); 49 | } 50 | return cmd; 51 | } 52 | 53 | void transformer(const Transformer& tr) 54 | { 55 | m_trans = &tr; 56 | } 57 | 58 | typedef conv_transform source_type; 59 | typedef vertex_iterator iterator; 60 | iterator begin(unsigned id) { return iterator(*this, id); } 61 | iterator end() { return iterator(path_cmd_stop); } 62 | 63 | private: 64 | conv_transform(const conv_transform&); 65 | const conv_transform& 66 | operator = (const conv_transform&); 67 | 68 | VertexSource* m_source; 69 | const Transformer* m_trans; 70 | }; 71 | 72 | 73 | } 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /agg2/include/agg_arrowhead.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // Simple arrowhead/arrowtail generator 17 | // 18 | //---------------------------------------------------------------------------- 19 | #ifndef AGG_ARROWHEAD_INCLUDED 20 | #define AGG_ARROWHEAD_INCLUDED 21 | 22 | #include "agg_basics.h" 23 | 24 | namespace agg 25 | { 26 | 27 | //===============================================================arrowhead 28 | // 29 | // See implementation agg_arrowhead.cpp 30 | // 31 | class arrowhead 32 | { 33 | public: 34 | arrowhead(); 35 | 36 | void head(double d1, double d2, double d3, double d4) 37 | { 38 | m_head_d1 = d1; 39 | m_head_d2 = d2; 40 | m_head_d3 = d3; 41 | m_head_d4 = d4; 42 | m_head_flag = true; 43 | } 44 | 45 | void head() { m_head_flag = true; } 46 | void no_head() { m_head_flag = false; } 47 | 48 | void tail(double d1, double d2, double d3, double d4) 49 | { 50 | m_tail_d1 = d1; 51 | m_tail_d2 = d2; 52 | m_tail_d3 = d3; 53 | m_tail_d4 = d4; 54 | m_tail_flag = true; 55 | } 56 | 57 | void tail() { m_tail_flag = true; } 58 | void no_tail() { m_tail_flag = false; } 59 | 60 | void rewind(unsigned id); 61 | unsigned vertex(double* x, double* y); 62 | 63 | private: 64 | double m_head_d1; 65 | double m_head_d2; 66 | double m_head_d3; 67 | double m_head_d4; 68 | double m_tail_d1; 69 | double m_tail_d2; 70 | double m_tail_d3; 71 | double m_tail_d4; 72 | bool m_head_flag; 73 | bool m_tail_flag; 74 | double m_coord[16]; 75 | unsigned m_cmd[8]; 76 | unsigned m_curr_id; 77 | unsigned m_curr_coord; 78 | }; 79 | 80 | } 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /agg2/include/dbg_new/agg_dbg_new.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // Debuging stuff for catching memory leaks and corruptions 17 | // 18 | //---------------------------------------------------------------------------- 19 | #ifndef AGG_DBG_NEW_INCLUDED 20 | #define AGG_DBG_NEW_INCLUDED 21 | 22 | #ifdef _WIN32 23 | #include 24 | #include 25 | #endif 26 | 27 | //#define AGG_DBG_NEW_CHECK_ADDR 28 | 29 | void* operator new (unsigned size, const char* file, int line); 30 | void* operator new [] (unsigned size, const char* file, int line); 31 | #define AGG_DBG_NEW_OPERATOR new(__FILE__, __LINE__) 32 | 33 | void operator delete(void *ptr) throw(); 34 | void operator delete [] (void *ptr) throw(); 35 | 36 | namespace agg 37 | { 38 | #ifdef _WIN32 39 | inline void printf(char* fmt, ...) 40 | { 41 | FILE* fd = fopen("stdout.txt", "at"); 42 | static char msg[1024]; 43 | va_list arg; 44 | va_start(arg, fmt); 45 | vsprintf(msg, fmt, arg); 46 | va_end(arg); 47 | fputs(msg, fd); 48 | fclose(fd); 49 | } 50 | #endif 51 | 52 | enum { max_dbg_new_level = 32 }; 53 | 54 | #ifdef AGG_DBG_NEW_CHECK_ADDR 55 | enum { max_allocations = 4096 }; 56 | #endif 57 | 58 | // All you need to watch for memory in heap is to declare an object 59 | // of this class in your main() or whatever function you need. 60 | // It will report you about all bad things happend to new/delete. 61 | // Try not to exceed the maximal nested level of declared watchdoggies 62 | // (max_dbg_new_level) 63 | class watchdoggy 64 | { 65 | public: 66 | watchdoggy(const char* file=0, int line=0, bool report_all=false); 67 | ~watchdoggy(); 68 | }; 69 | } 70 | 71 | #define AGG_WATCHDOGGY(name, report_all) \ 72 | agg::watchdoggy name(__FILE__, __LINE__, report_all); 73 | #endif 74 | 75 | #ifdef new 76 | #undef new 77 | #endif 78 | #define new AGG_DBG_NEW_OPERATOR 79 | 80 | -------------------------------------------------------------------------------- /agg2/include/util/agg_color_conv.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // Conversion from one colorspace/pixel format to another 17 | // 18 | //---------------------------------------------------------------------------- 19 | 20 | #ifndef AGG_COLOR_CONV_INCLUDED 21 | #define AGG_COLOR_CONV_INCLUDED 22 | 23 | #include 24 | #include "agg_basics.h" 25 | #include "agg_rendering_buffer.h" 26 | 27 | 28 | 29 | 30 | namespace agg 31 | { 32 | 33 | //--------------------------------------------------------------color_conv 34 | template 35 | void color_conv(rendering_buffer* dst, 36 | const rendering_buffer* src, 37 | CopyRow copy_row_functor) 38 | { 39 | unsigned width = src->width(); 40 | unsigned height = src->height(); 41 | 42 | if(dst->width() < width) width = dst->width(); 43 | if(dst->height() < height) height = dst->height(); 44 | 45 | if(width) 46 | { 47 | unsigned y; 48 | for(y = 0; y < height; y++) 49 | { 50 | copy_row_functor(dst->row(y), src->row(y), width); 51 | } 52 | } 53 | } 54 | 55 | 56 | //---------------------------------------------------------color_conv_row 57 | template 58 | void color_conv_row(unsigned char* dst, 59 | const unsigned char* src, 60 | unsigned width, 61 | CopyRow copy_row_functor) 62 | { 63 | copy_row_functor(dst, src, width); 64 | } 65 | 66 | 67 | //---------------------------------------------------------color_conv_same 68 | template class color_conv_same 69 | { 70 | public: 71 | void operator () (unsigned char* dst, 72 | const unsigned char* src, 73 | unsigned width) const 74 | { 75 | memmove(dst, src, width*BPP); 76 | } 77 | }; 78 | 79 | 80 | } 81 | 82 | 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /agg2/include/agg_rounded_rect.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // Rounded rectangle vertex generator 17 | // 18 | //---------------------------------------------------------------------------- 19 | 20 | #ifndef AGG_ROUNDED_RECT_INCLUDED 21 | #define AGG_ROUNDED_RECT_INCLUDED 22 | 23 | #include "agg_basics.h" 24 | #include "agg_arc.h" 25 | #include "agg_vertex_iterator.h" 26 | 27 | 28 | namespace agg 29 | { 30 | //------------------------------------------------------------rounded_rect 31 | // 32 | // See Implemantation agg_rounded_rect.cpp 33 | // 34 | class rounded_rect 35 | { 36 | public: 37 | rounded_rect() {} 38 | rounded_rect(double x1, double y1, double x2, double y2, double r); 39 | 40 | void rect(double x1, double y1, double x2, double y2); 41 | void radius(double r); 42 | void radius(double rx, double ry); 43 | void radius(double rx_bottom, double ry_bottom, double rx_top, double ry_top); 44 | void radius(double rx1, double ry1, double rx2, double ry2, 45 | double rx3, double ry3, double rx4, double ry4); 46 | void normalize_radius(); 47 | 48 | void approximation_scale(double s) { m_arc.approximation_scale(s); } 49 | double approximation_scale() const { return m_arc.approximation_scale(); } 50 | 51 | void rewind(unsigned); 52 | unsigned vertex(double* x, double* y); 53 | 54 | typedef rounded_rect source_type; 55 | typedef vertex_iterator iterator; 56 | iterator begin(unsigned id) { return iterator(*this, id); } 57 | iterator end() { return iterator(path_cmd_stop); } 58 | 59 | private: 60 | double m_x1; 61 | double m_y1; 62 | double m_x2; 63 | double m_y2; 64 | double m_rx1; 65 | double m_ry1; 66 | double m_rx2; 67 | double m_ry2; 68 | double m_rx3; 69 | double m_ry3; 70 | double m_rx4; 71 | double m_ry4; 72 | unsigned m_status; 73 | arc m_arc; 74 | }; 75 | 76 | } 77 | 78 | #endif 79 | 80 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # $Id: setup.py 2550 2005-10-10 12:54:55Z fredrik $ 4 | # Setup script for aggdraw 5 | # 6 | # Usage: 7 | # 8 | # To build in current directory: 9 | # $ python setup.py build_ext -i 10 | # 11 | # To build and install: 12 | # $ python setup.py install 13 | # 14 | 15 | from distutils.core import setup, Extension 16 | import os 17 | 18 | VERSION = "1.1-64bits" 19 | 20 | # tweak as necessary 21 | FREETYPE_ROOT = "../../kits/freetype-2.1.10" 22 | 23 | if not os.path.isdir(FREETYPE_ROOT): 24 | print "===", "freetype support disabled" 25 | FREETYPE_ROOT = None 26 | 27 | sources = [ 28 | # source code currently used by aggdraw 29 | # FIXME: link against AGG library instead? 30 | "agg2/src/agg_arc.cpp", 31 | "agg2/src/agg_bezier_arc.cpp", 32 | "agg2/src/agg_curves.cpp", 33 | "agg2/src/agg_path_storage.cpp", 34 | "agg2/src/agg_rasterizer_scanline_aa.cpp", 35 | "agg2/src/agg_trans_affine.cpp", 36 | "agg2/src/agg_vcgen_contour.cpp", 37 | # "agg2/src/agg_vcgen_dash.cpp", 38 | "agg2/src/agg_vcgen_stroke.cpp", 39 | ] 40 | 41 | defines = [] 42 | 43 | include_dirs = ["agg2/include"] 44 | library_dirs = [] 45 | 46 | libraries = [] 47 | 48 | if FREETYPE_ROOT: 49 | defines.append(("HAVE_FREETYPE2", None)) 50 | sources.extend([ 51 | "agg2/font_freetype/agg_font_freetype.cpp", 52 | ]) 53 | include_dirs.append("agg2/font_freetype") 54 | include_dirs.append(os.path.join(FREETYPE_ROOT, "include")) 55 | include_dirs.append(os.path.join(FREETYPE_ROOT, "include/freetype2")) 56 | library_dirs.append(os.path.join(FREETYPE_ROOT, "lib")) 57 | libraries.append("freetype") 58 | 59 | try: 60 | # add necessary to distutils (for backwards compatibility) 61 | from distutils.dist import DistributionMetadata 62 | DistributionMetadata.classifiers = None 63 | DistributionMetadata.download_url = None 64 | DistributionMetadata.platforms = None 65 | except: 66 | pass 67 | 68 | setup( 69 | 70 | name="aggdraw", 71 | version=VERSION, 72 | author="Fredrik Lundh", 73 | author_email="fredrik@pythonware.com", 74 | classifiers=[ 75 | "Development Status :: 4 - Beta", 76 | "Topic :: Multimedia :: Graphics", 77 | ], 78 | description="aggdraw -- high quality drawing interface for PIL", 79 | download_url="http://www.effbot.org/downloads#aggdraw", 80 | license="Python (MIT style)", 81 | platforms="Python 2.1 and later.", 82 | url="http://www.effbot.org/zone/aggdraw.htm", 83 | 84 | ext_modules = [ 85 | Extension("aggdraw", ["aggdraw.cxx"] + sources, 86 | define_macros=defines, 87 | include_dirs=include_dirs, 88 | library_dirs=library_dirs, libraries=libraries 89 | ) 90 | ] 91 | 92 | ) 93 | -------------------------------------------------------------------------------- /agg2/include/agg_conv_concat.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_CONV_CONCAT_INCLUDED 17 | #define AGG_CONV_CONCAT_INCLUDED 18 | 19 | #include "agg_basics.h" 20 | #include "agg_vertex_iterator.h" 21 | 22 | namespace agg 23 | { 24 | //=============================================================conv_concat 25 | // Concatenation of two paths. Usually used to combine lines or curves 26 | // with markers such as arrowheads 27 | template class conv_concat 28 | { 29 | public: 30 | conv_concat(VS1& source1, VS2& source2) : 31 | m_source1(&source1), m_source2(&source2), m_status(2) {} 32 | 33 | void set_source1(VS1& source) { m_source1 = &source; } 34 | void set_source2(VS2& source) { m_source2 = &source; } 35 | 36 | 37 | void rewind(unsigned id) 38 | { 39 | m_source1->rewind(id); 40 | m_source2->rewind(0); 41 | m_status = 0; 42 | } 43 | 44 | unsigned vertex(double* x, double* y) 45 | { 46 | unsigned cmd; 47 | if(m_status == 0) 48 | { 49 | cmd = m_source1->vertex(x, y); 50 | if(!is_stop(cmd)) return cmd; 51 | m_status = 1; 52 | } 53 | if(m_status == 1) 54 | { 55 | cmd = m_source2->vertex(x, y); 56 | if(!is_stop(cmd)) return cmd; 57 | m_status = 2; 58 | } 59 | return path_cmd_stop; 60 | } 61 | 62 | typedef conv_concat source_type; 63 | typedef vertex_iterator iterator; 64 | iterator begin(unsigned id) { return iterator(*this, id); } 65 | iterator end() { return iterator(path_cmd_stop); } 66 | 67 | private: 68 | conv_concat(const conv_concat&); 69 | const conv_concat& 70 | operator = (const conv_concat&); 71 | 72 | VS1* m_source1; 73 | VS2* m_source2; 74 | int m_status; 75 | 76 | }; 77 | } 78 | 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /agg2/include/agg_bspline.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // class bspline 17 | // 18 | //---------------------------------------------------------------------------- 19 | 20 | #ifndef AGG_BSPLINE_INCLUDED 21 | #define AGG_BSPLINE_INCLUDED 22 | 23 | #include "agg_basics.h" 24 | 25 | namespace agg 26 | { 27 | //----------------------------------------------------------------bspline 28 | // A very simple class of Bi-cubic Spline interpolation. 29 | // First call init(num, x[], y[]) where num - number of source points, 30 | // x, y - arrays of X and Y values respectively. Here Y must be a function 31 | // of X. It means that all the X-coordinates must be arranged in the ascending 32 | // order. 33 | // Then call get(x) that calculates a value Y for the respective X. 34 | // The class supports extrapolation, i.e. you can call get(x) where x is 35 | // outside the given with init() X-range. Extrapolation is a simple linear 36 | // function. 37 | // 38 | // See Implementation agg_bspline.cpp 39 | //------------------------------------------------------------------------ 40 | class bspline 41 | { 42 | public: 43 | ~bspline(); 44 | bspline(); 45 | bspline(int num); 46 | bspline(int num, const double* x, const double* y); 47 | 48 | void init(int num); 49 | void add_point(double x, double y); 50 | void prepare(); 51 | 52 | void init(int num, const double* x, const double* y); 53 | 54 | double get(double x) const; 55 | double get_stateful(double x) const; 56 | 57 | private: 58 | bspline(const bspline&); 59 | const bspline& operator = (const bspline&); 60 | 61 | static void bsearch(int n, const double *x, double x0, int *i); 62 | double extrapolation_left(double x) const; 63 | double extrapolation_right(double x) const; 64 | double interpolation(double x, int i) const; 65 | 66 | int m_max; 67 | int m_num; 68 | double* m_x; 69 | double* m_y; 70 | double* m_am; 71 | mutable int m_last_idx; 72 | }; 73 | 74 | 75 | } 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /agg2/include/agg_vcgen_smooth_poly1.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_VCGEN_SMOOTH_POLY1_INCLUDED 17 | #define AGG_VCGEN_SMOOTH_POLY1_INCLUDED 18 | 19 | #include "agg_basics.h" 20 | #include "agg_vertex_sequence.h" 21 | 22 | 23 | namespace agg 24 | { 25 | 26 | //======================================================vcgen_smooth_poly1 27 | // 28 | // See Implementation agg_vcgen_smooth_poly1.cpp 29 | // Smooth polygon generator 30 | // 31 | //------------------------------------------------------------------------ 32 | class vcgen_smooth_poly1 33 | { 34 | enum status_e 35 | { 36 | initial, 37 | ready, 38 | polygon, 39 | ctrl_b, 40 | ctrl_e, 41 | ctrl1, 42 | ctrl2, 43 | end_poly, 44 | stop 45 | }; 46 | 47 | public: 48 | typedef vertex_sequence vertex_storage; 49 | 50 | vcgen_smooth_poly1(); 51 | 52 | void smooth_value(double v) { m_smooth_value = v * 0.5; } 53 | double smooth_value() const { return m_smooth_value * 2.0; } 54 | 55 | // Vertex Generator Interface 56 | void remove_all(); 57 | void add_vertex(double x, double y, unsigned cmd); 58 | 59 | // Vertex Source Interface 60 | void rewind(unsigned id); 61 | unsigned vertex(double* x, double* y); 62 | 63 | private: 64 | vcgen_smooth_poly1(const vcgen_smooth_poly1&); 65 | const vcgen_smooth_poly1& operator = (const vcgen_smooth_poly1&); 66 | 67 | void calculate(const vertex_dist& v0, 68 | const vertex_dist& v1, 69 | const vertex_dist& v2, 70 | const vertex_dist& v3); 71 | 72 | vertex_storage m_src_vertices; 73 | double m_smooth_value; 74 | unsigned m_closed; 75 | status_e m_status; 76 | unsigned m_src_vertex; 77 | double m_ctrl1_x; 78 | double m_ctrl1_y; 79 | double m_ctrl2_x; 80 | double m_ctrl2_y; 81 | }; 82 | 83 | } 84 | 85 | 86 | #endif 87 | 88 | -------------------------------------------------------------------------------- /agg2/include/agg_span_interpolator_adaptor.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_SPAN_INTERPOLATOR_ADAPTOR_INCLUDED 17 | #define AGG_SPAN_INTERPOLATOR_ADAPTOR_INCLUDED 18 | 19 | #include "agg_basics.h" 20 | 21 | namespace agg 22 | { 23 | 24 | //===============================================span_interpolator_adaptor 25 | template 26 | class span_interpolator_adaptor : public Interpolator 27 | { 28 | public: 29 | typedef Interpolator base_type; 30 | typedef typename base_type::trans_type trans_type; 31 | typedef Distortion distortion_type; 32 | 33 | //-------------------------------------------------------------------- 34 | span_interpolator_adaptor() {} 35 | span_interpolator_adaptor(const trans_type& trans, 36 | const distortion_type& dist) : 37 | base_type(trans), 38 | m_distortion(&dist) 39 | { 40 | } 41 | 42 | //-------------------------------------------------------------------- 43 | span_interpolator_adaptor(const trans_type& trans, 44 | const distortion_type& dist, 45 | double x, double y, unsigned len) : 46 | base_type(trans, x, y, len), 47 | m_distortion(&dist) 48 | { 49 | } 50 | 51 | //-------------------------------------------------------------------- 52 | const distortion_type& distortion() const 53 | { 54 | return *m_distortion; 55 | } 56 | 57 | //-------------------------------------------------------------------- 58 | void distortion(const distortion_type& dist) 59 | { 60 | m_distortion = dist; 61 | } 62 | 63 | //-------------------------------------------------------------------- 64 | void coordinates(int* x, int* y) const 65 | { 66 | base_type::coordinates(x, y); 67 | m_distortion->calculate(x, y); 68 | } 69 | 70 | private: 71 | //-------------------------------------------------------------------- 72 | const distortion_type* m_distortion; 73 | }; 74 | } 75 | 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /agg2/include/agg_conv_smooth_poly1.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // Smooth polygon generator 17 | // 18 | //---------------------------------------------------------------------------- 19 | #ifndef AGG_CONV_SMOOTH_POLY1_INCLUDED 20 | #define AGG_CONV_SMOOTH_POLY1_INCLUDED 21 | 22 | #include "agg_basics.h" 23 | #include "agg_vcgen_smooth_poly1.h" 24 | #include "agg_conv_adaptor_vcgen.h" 25 | #include "agg_conv_curve.h" 26 | 27 | 28 | namespace agg 29 | { 30 | 31 | //-------------------------------------------------------conv_smooth_poly1 32 | template 33 | struct conv_smooth_poly1 : 34 | public conv_adaptor_vcgen 35 | { 36 | typedef conv_adaptor_vcgen base_type; 37 | 38 | conv_smooth_poly1(VertexSource& vs) : 39 | conv_adaptor_vcgen(vs) 40 | { 41 | } 42 | 43 | void smooth_value(double v) { base_type::generator().smooth_value(v); } 44 | double smooth_value() const { return base_type::generator().smooth_value(); } 45 | 46 | private: 47 | conv_smooth_poly1(const conv_smooth_poly1&); 48 | const conv_smooth_poly1& 49 | operator = (const conv_smooth_poly1&); 50 | }; 51 | 52 | 53 | 54 | //-------------------------------------------------conv_smooth_poly1_curve 55 | template 56 | struct conv_smooth_poly1_curve : 57 | public conv_curve > 58 | { 59 | conv_smooth_poly1_curve(VertexSource& vs) : 60 | conv_curve >(m_smooth), 61 | m_smooth(vs) 62 | { 63 | } 64 | 65 | void smooth_value(double v) { m_smooth.generator().smooth_value(v); } 66 | double smooth_value() const { return m_smooth.generator().smooth_value(); } 67 | 68 | private: 69 | conv_smooth_poly1_curve(const conv_smooth_poly1_curve&); 70 | const conv_smooth_poly1_curve& 71 | operator = (const conv_smooth_poly1_curve&); 72 | 73 | conv_smooth_poly1 m_smooth; 74 | }; 75 | 76 | } 77 | 78 | 79 | #endif 80 | 81 | -------------------------------------------------------------------------------- /agg2/include/platform/mac/agg_mac_pmap.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.0 3 | // Copyright (C) 2002 Maxim Shemanarev (McSeem) 4 | // Copyright (C) 2002 Hansruedi Baer (MacOS support) 5 | // 6 | // Permission to copy, use, modify, sell and distribute this software 7 | // is granted provided this copyright notice appears in all copies. 8 | // This software is provided "as is" without express or implied 9 | // warranty, and with no claim as to its suitability for any purpose. 10 | // 11 | //---------------------------------------------------------------------------- 12 | // Contact: mcseem@antigrain.com 13 | // mcseemagg@yahoo.com 14 | // http://www.antigrain.com 15 | // baer@karto.baug.eth.ch 16 | //---------------------------------------------------------------------------- 17 | // 18 | // class pixel_map 19 | // 20 | //---------------------------------------------------------------------------- 21 | #ifndef AGG_MAC_PMAP_INCLUDED 22 | #define AGG_MAC_PMAP_INCLUDED 23 | 24 | 25 | #include 26 | #include 27 | 28 | 29 | namespace agg 30 | { 31 | enum org_e 32 | { 33 | org_mono8 = 8, 34 | org_color16 = 16, 35 | org_color24 = 24, 36 | org_color32 = 32 37 | }; 38 | 39 | class pixel_map 40 | { 41 | public: 42 | ~pixel_map(); 43 | pixel_map(); 44 | 45 | public: 46 | void destroy(); 47 | void create(unsigned width, 48 | unsigned height, 49 | org_e org, 50 | unsigned clear_val=255); 51 | 52 | void clear(unsigned clear_val=255); 53 | bool load_from_qt(const char* filename); 54 | bool save_as_qt(const char* filename) const; 55 | 56 | void draw(WindowRef window, 57 | const Rect* device_rect=0, 58 | const Rect* bmp_rect=0) const; 59 | void draw(WindowRef window, int x, int y, double scale=1.0) const; 60 | void blend(WindowRef window, 61 | const Rect* device_rect=0, 62 | const Rect* bmp_rect=0) const; 63 | void blend(WindowRef window, int x, int y, double scale=1.0) const; 64 | 65 | unsigned char* buf(); 66 | unsigned width() const; 67 | unsigned height() const; 68 | int row_bytes() const; 69 | unsigned bpp() const { return m_bpp; } 70 | 71 | //Auxiliary static functions 72 | static unsigned calc_row_len(unsigned width, unsigned bits_per_pixel); 73 | private: 74 | pixel_map(const pixel_map&); 75 | const pixel_map& operator = (const pixel_map&); 76 | 77 | private: 78 | GWorldPtr m_pmap; 79 | unsigned char* m_buf; 80 | unsigned m_bpp; 81 | unsigned m_img_size; 82 | }; 83 | 84 | } 85 | 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /agg2/include/agg_conv_clip_polygon.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // Polygon clipping converter 17 | // There an optimized Liang-Basky algorithm is used. 18 | // The algorithm doesn't optimize the degenerate edges, i.e. it will never 19 | // break a closed polygon into two or more ones, instead, there will be 20 | // degenerate edges coinciding with the respective clipping boundaries. 21 | // This is a sub-optimal solution, because that optimization would require 22 | // extra, rather expensive math while the rasterizer tolerates it quite well, 23 | // without any considerable overhead. 24 | // 25 | //---------------------------------------------------------------------------- 26 | #ifndef AGG_CONV_CLIP_POLYGON_INCLUDED 27 | #define AGG_CONV_CLIP_POLYGON_INCLUDED 28 | 29 | #include "agg_basics.h" 30 | #include "agg_conv_adaptor_vpgen.h" 31 | #include "agg_vpgen_clip_polygon.h" 32 | #include "agg_vertex_iterator.h" 33 | 34 | namespace agg 35 | { 36 | 37 | //=======================================================conv_clip_polygon 38 | template 39 | struct conv_clip_polygon : public conv_adaptor_vpgen 40 | { 41 | typedef conv_adaptor_vpgen base_type; 42 | 43 | conv_clip_polygon(VertexSource& vs) : 44 | conv_adaptor_vpgen(vs) {} 45 | 46 | void clip_box(double x1, double y1, double x2, double y2) 47 | { 48 | base_type::vpgen().clip_box(x1, y1, x2, y2); 49 | } 50 | 51 | double x1() const { return base_type::vpgen().x1(); } 52 | double y1() const { return base_type::vpgen().y1(); } 53 | double x2() const { return base_type::vpgen().x2(); } 54 | double y2() const { return base_type::vpgen().y2(); } 55 | 56 | typedef conv_clip_polygon source_type; 57 | typedef vertex_iterator iterator; 58 | iterator begin(unsigned id) { return iterator(*this, id); } 59 | iterator end() { return iterator(path_cmd_stop); } 60 | 61 | private: 62 | conv_clip_polygon(const conv_clip_polygon&); 63 | const conv_clip_polygon& 64 | operator = (const conv_clip_polygon&); 65 | }; 66 | 67 | } 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /agg2/include/agg_vcgen_contour.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_VCGEN_CONTOUR_INCLUDED 17 | #define AGG_VCGEN_CONTOUR_INCLUDED 18 | 19 | #include "agg_basics.h" 20 | #include "agg_vertex_sequence.h" 21 | 22 | namespace agg 23 | { 24 | 25 | //----------------------------------------------------------vcgen_contour 26 | // 27 | // See Implementation agg_vcgen_contour.cpp 28 | // 29 | class vcgen_contour 30 | { 31 | enum status_e 32 | { 33 | initial, 34 | ready, 35 | outline, 36 | add_point, 37 | end_poly 38 | }; 39 | 40 | public: 41 | typedef vertex_sequence vertex_storage; 42 | 43 | vcgen_contour(); 44 | 45 | void width(double w) { m_width = w * 0.5; } 46 | void miter_limit(double ml) { m_miter_limit = ml; } 47 | void miter_limit_theta(double t); 48 | void auto_detect_orientation(bool v) { m_auto_detect = v; } 49 | 50 | double width() const { return m_width * 2.0; } 51 | double miter_limit() const { return m_miter_limit; } 52 | bool auto_detect_orientation() const { return m_auto_detect; } 53 | 54 | // Generator interface 55 | void remove_all(); 56 | void add_vertex(double x, double y, unsigned cmd); 57 | 58 | // Vertex Source Interface 59 | void rewind(unsigned id); 60 | unsigned vertex(double* x, double* y); 61 | 62 | private: 63 | vcgen_contour(const vcgen_contour&); 64 | const vcgen_contour& operator = (const vcgen_contour&); 65 | 66 | bool calc_miter(const vertex_dist& v0, 67 | const vertex_dist& v1, 68 | const vertex_dist& v2); 69 | 70 | vertex_storage m_src_vertices; 71 | double m_width; 72 | double m_abs_width; 73 | double m_signed_width; 74 | double m_miter_limit; 75 | status_e m_status; 76 | unsigned m_src_vertex; 77 | unsigned m_closed; 78 | unsigned m_orientation; 79 | bool m_auto_detect; 80 | double m_x1; 81 | double m_y1; 82 | double m_x2; 83 | double m_y2; 84 | }; 85 | 86 | } 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /agg2/include/agg_conv_stroke.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // conv_stroke 17 | // 18 | //---------------------------------------------------------------------------- 19 | #ifndef AGG_CONV_STROKE_INCLUDED 20 | #define AGG_CONV_STROKE_INCLUDED 21 | 22 | #include "agg_basics.h" 23 | #include "agg_vcgen_stroke.h" 24 | #include "agg_conv_adaptor_vcgen.h" 25 | 26 | namespace agg 27 | { 28 | 29 | //-------------------------------------------------------------conv_stroke 30 | template 31 | struct conv_stroke : 32 | public conv_adaptor_vcgen 33 | { 34 | typedef Markers marker_type; 35 | typedef conv_adaptor_vcgen base_type; 36 | 37 | conv_stroke(VertexSource& vs) : 38 | conv_adaptor_vcgen(vs) 39 | { 40 | } 41 | 42 | void line_cap(vcgen_stroke::line_cap_e lc) { base_type::generator().line_cap(lc); } 43 | void line_join(vcgen_stroke::line_join_e lj) { base_type::generator().line_join(lj); } 44 | 45 | vcgen_stroke::line_cap_e line_cap() const { return base_type::generator().line_cap(); } 46 | vcgen_stroke::line_join_e line_join() const { return base_type::generator().line_join(); } 47 | 48 | void width(double w) { base_type::generator().width(w); } 49 | void miter_limit(double ml) { base_type::generator().miter_limit(ml); } 50 | void miter_limit_theta(double t) { base_type::generator().miter_limit_theta(t); } 51 | void approximation_scale(double as) { base_type::generator().approximation_scale(as); } 52 | 53 | double width() const { return base_type::generator().width(); } 54 | double miter_limit() const { return base_type::generator().miter_limit(); } 55 | double approximation_scale() const { return base_type::generator().approximation_scale(); } 56 | 57 | void shorten(double s) { base_type::generator().shorten(s); } 58 | double shorten() const { return base_type::generator().shorten(); } 59 | 60 | private: 61 | conv_stroke(const conv_stroke&); 62 | const conv_stroke& 63 | operator = (const conv_stroke&); 64 | 65 | }; 66 | 67 | } 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /agg2/include/agg_span_pattern.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | 17 | #ifndef AGG_SPAN_PATTERN_INCLUDED 18 | #define AGG_SPAN_PATTERN_INCLUDED 19 | 20 | #include "agg_basics.h" 21 | #include "agg_rendering_buffer.h" 22 | #include "agg_span_generator.h" 23 | 24 | 25 | namespace agg 26 | { 27 | 28 | //--------------------------------------------------------span_pattern 29 | template 30 | class span_pattern : public span_generator 31 | { 32 | public: 33 | typedef ColorT color_type; 34 | typedef AlphaT alpha_type; 35 | typedef Allocator alloc_type; 36 | 37 | //---------------------------------------------------------------- 38 | span_pattern(alloc_type& alloc) : 39 | span_generator(alloc) 40 | {} 41 | 42 | //---------------------------------------------------------------- 43 | span_pattern(alloc_type& alloc, 44 | const rendering_buffer& src, 45 | unsigned offset_x, unsigned offset_y, 46 | alpha_type alpha) : 47 | span_generator(alloc), 48 | m_src(&src), 49 | m_offset_x(offset_x), 50 | m_offset_y(offset_y), 51 | m_alpha(alpha) 52 | {} 53 | 54 | //---------------------------------------------------------------- 55 | const rendering_buffer& source_image() const { return *m_src; } 56 | unsigned offset_x() const { return m_offset_x; } 57 | unsigned offset_y() const { return m_offset_y; } 58 | alpha_type alpha() const { return m_alpha; } 59 | 60 | //---------------------------------------------------------------- 61 | void source_image(const rendering_buffer& v) { m_src = &v; } 62 | void offset_x(unsigned v) { m_offset_x = v; } 63 | void offset_y(unsigned v) { m_offset_y = v; } 64 | void alpha(alpha_type v) { m_alpha = v; } 65 | 66 | //---------------------------------------------------------------- 67 | private: 68 | const rendering_buffer* m_src; 69 | unsigned m_offset_x; 70 | unsigned m_offset_y; 71 | alpha_type m_alpha; 72 | }; 73 | 74 | 75 | } 76 | 77 | #endif 78 | 79 | -------------------------------------------------------------------------------- /agg2/include/agg_span_pattern_rgba32.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | 17 | #ifndef AGG_SPAN_PATTERN_RGBA32_INCLUDED 18 | #define AGG_SPAN_PATTERN_RGBA32_INCLUDED 19 | 20 | #include "agg_basics.h" 21 | #include "agg_pixfmt_rgba32.h" 22 | #include "agg_span_pattern.h" 23 | 24 | namespace agg 25 | { 26 | 27 | //======================================================span_pattern_rgba32 28 | template > 29 | class span_pattern_rgba32 : public span_pattern 30 | { 31 | public: 32 | typedef Allocator alloc_type; 33 | typedef rgba8 color_type; 34 | typedef span_pattern base_type; 35 | 36 | //-------------------------------------------------------------------- 37 | span_pattern_rgba32(alloc_type& alloc) : base_type(alloc) {} 38 | 39 | //---------------------------------------------------------------- 40 | span_pattern_rgba32(alloc_type& alloc, 41 | const rendering_buffer& src, 42 | unsigned offset_x, unsigned offset_y) : 43 | base_type(alloc, src, offset_x, offset_y, 0) 44 | {} 45 | 46 | //-------------------------------------------------------------------- 47 | color_type* generate(int x, int y, unsigned len) 48 | { 49 | color_type* span = base_type::allocator().span(); 50 | unsigned sx = (base_type::offset_x() + x) % base_type::source_image().width(); 51 | unsigned wp = base_type::source_image().width() << 2; 52 | const int8u* p = base_type::source_image().row((base_type::offset_y() + y) % base_type::source_image().height()); 53 | p += sx << 2; 54 | do 55 | { 56 | span->r = p[Order::R]; 57 | span->g = p[Order::G]; 58 | span->b = p[Order::B]; 59 | span->a = p[Order::A]; 60 | p += 4; 61 | ++sx; 62 | ++span; 63 | if(sx >= base_type::source_image().width()) 64 | { 65 | sx -= base_type::source_image().width(); 66 | p -= wp; 67 | } 68 | } 69 | while(--len); 70 | return base_type::allocator().span(); 71 | } 72 | }; 73 | 74 | } 75 | 76 | #endif 77 | 78 | -------------------------------------------------------------------------------- /agg2/include/agg_span_pattern_rgb24.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | 17 | #ifndef AGG_SPAN_PATTERN_RGB24_INCLUDED 18 | #define AGG_SPAN_PATTERN_RGB24_INCLUDED 19 | 20 | #include "agg_basics.h" 21 | #include "agg_pixfmt_rgb24.h" 22 | #include "agg_span_pattern.h" 23 | 24 | namespace agg 25 | { 26 | 27 | //=======================================================span_pattern_rgb24 28 | template > 29 | class span_pattern_rgb24 : public span_pattern 30 | { 31 | public: 32 | typedef Allocator alloc_type; 33 | typedef rgba8 color_type; 34 | typedef span_pattern base_type; 35 | 36 | //-------------------------------------------------------------------- 37 | span_pattern_rgb24(alloc_type& alloc) : base_type(alloc) {} 38 | 39 | //---------------------------------------------------------------- 40 | span_pattern_rgb24(alloc_type& alloc, 41 | const rendering_buffer& src, 42 | unsigned offset_x, unsigned offset_y, 43 | int8u alpha = 255) : 44 | base_type(alloc, src, offset_x, offset_y, alpha) 45 | {} 46 | 47 | 48 | //-------------------------------------------------------------------- 49 | color_type* generate(int x, int y, unsigned len) 50 | { 51 | color_type* span = base_type::allocator().span(); 52 | unsigned sx = (base_type::offset_x() + x) % base_type::source_image().width(); 53 | unsigned wp = base_type::source_image().width() * 3; 54 | const int8u* p = base_type::source_image().row((base_type::offset_y() + y) % base_type::source_image().height()); 55 | p += sx * 3; 56 | do 57 | { 58 | span->r = p[Order::R]; 59 | span->g = p[Order::G]; 60 | span->b = p[Order::B]; 61 | span->a = base_type::alpha(); 62 | p += 3; 63 | ++sx; 64 | ++span; 65 | if(sx >= base_type::source_image().width()) 66 | { 67 | sx -= base_type::source_image().width(); 68 | p -= wp; 69 | } 70 | } 71 | while(--len); 72 | return base_type::allocator().span(); 73 | } 74 | }; 75 | 76 | } 77 | 78 | #endif 79 | 80 | -------------------------------------------------------------------------------- /agg2/src/agg_line_aa_basics.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #include 17 | #include "agg_line_aa_basics.h" 18 | 19 | namespace agg 20 | { 21 | //------------------------------------------------------------------------- 22 | // The number of the octant is determined as a 3-bit value as follows: 23 | // bit 0 = vertical flag 24 | // bit 1 = sx < 0 25 | // bit 2 = sy < 0 26 | // 27 | // [N] shows the number of the orthogonal quadrant 28 | // shows the number of the diagonal quadrant 29 | // <1> 30 | // [1] | [0] 31 | // . (3)011 | 001(1) . 32 | // . | . 33 | // . | . 34 | // . | . 35 | // (2)010 .|. 000(0) 36 | // <2> ----------.+.----------- <0> 37 | // (6)110 . | . 100(4) 38 | // . | . 39 | // . | . 40 | // . | . 41 | // (7)111 | 101(5) 42 | // [2] | [3] 43 | // <3> 44 | // 0,1,2,3,4,5,6,7 45 | int8u line_parameters::s_orthogonal_quadrant[8] = { 0,0,1,1,3,3,2,2 }; 46 | int8u line_parameters::s_diagonal_quadrant[8] = { 0,1,2,1,0,3,2,3 }; 47 | 48 | 49 | 50 | //------------------------------------------------------------------------- 51 | void bisectrix(const line_parameters& l1, 52 | const line_parameters& l2, 53 | int* x, int* y) 54 | { 55 | double k = double(l2.len) / double(l1.len); 56 | double tx = l2.x2 - (l2.x1 - l1.x1) * k; 57 | double ty = l2.y2 - (l2.y1 - l1.y1) * k; 58 | 59 | //All bisectrices must be on the right of the line 60 | //If the next point is on the left (l1 => l2.2) 61 | //then the bisectix should be rotated by 180 degrees. 62 | if(double(l2.x2 - l2.x1) * double(l2.y1 - l1.y1) < 63 | double(l2.y2 - l2.y1) * double(l2.x1 - l1.x1) + 100.0) 64 | { 65 | tx -= (tx - l2.x1) * 2.0; 66 | ty -= (ty - l2.y1) * 2.0; 67 | } 68 | 69 | // Check if the bisectrix is too short 70 | double dx = tx - l2.x1; 71 | double dy = ty - l2.y1; 72 | if((int)sqrt(dx * dx + dy * dy) < line_subpixel_size) 73 | { 74 | tx = (l2.x1 + l2.x1 + (l2.y1 - l1.y1) + (l2.y2 - l2.y1)) / 2; 75 | ty = (l2.y1 + l2.y1 - (l2.x1 - l1.x1) - (l2.x2 - l2.x1)) / 2; 76 | } 77 | *x = int(tx); 78 | *y = int(ty); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /agg2/include/agg_ellipse.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // class ellipse 17 | // 18 | //---------------------------------------------------------------------------- 19 | 20 | #ifndef AGG_ELLIPSE_INCLUDED 21 | #define AGG_ELLIPSE_INCLUDED 22 | 23 | #include "agg_basics.h" 24 | #include 25 | 26 | namespace agg 27 | { 28 | 29 | //----------------------------------------------------------------ellipse 30 | class ellipse 31 | { 32 | public: 33 | ellipse() : m_x(0.0), m_y(0.0), m_rx(1.0), m_ry(1.0), m_num(4), m_step(0) {} 34 | ellipse(double x, double y, double rx, double ry, unsigned num_steps) 35 | : m_x(x), m_y(y), m_rx(rx), m_ry(ry), m_num(num_steps), m_step(0) {} 36 | 37 | void init(double x, double y, double rx, double ry, unsigned num_steps); 38 | void approximation_scale(double scale); 39 | void rewind(unsigned id); 40 | unsigned vertex(double* x, double* y); 41 | 42 | private: 43 | double m_x; 44 | double m_y; 45 | double m_rx; 46 | double m_ry; 47 | unsigned m_num; 48 | unsigned m_step; 49 | }; 50 | 51 | 52 | //------------------------------------------------------------------------ 53 | inline void ellipse::init(double x, double y, double rx, double ry, unsigned num_steps) 54 | { 55 | m_x = x; 56 | m_y = y; 57 | m_rx = rx; 58 | m_ry = ry; 59 | m_num = num_steps; 60 | m_step = 0; 61 | } 62 | 63 | //------------------------------------------------------------------------ 64 | inline void ellipse::approximation_scale(double scale) 65 | { 66 | m_num = unsigned((fabs(m_rx) + fabs(m_ry) + 6.0) * scale); 67 | if(m_num < 6) m_num = 6; 68 | } 69 | 70 | //------------------------------------------------------------------------ 71 | inline void ellipse::rewind(unsigned) 72 | { 73 | m_step = 0; 74 | } 75 | 76 | //------------------------------------------------------------------------ 77 | inline unsigned ellipse::vertex(double* x, double* y) 78 | { 79 | if(m_step == m_num) 80 | { 81 | ++m_step; 82 | return path_cmd_end_poly | path_flags_close | path_flags_ccw; 83 | } 84 | if(m_step > m_num) return path_cmd_stop; 85 | double angle = double(m_step) / double(m_num) * 2.0 * pi; 86 | *x = m_x + cos(angle) * m_rx; 87 | *y = m_y + sin(angle) * m_ry; 88 | m_step++; 89 | return ((m_step == 1) ? path_cmd_move_to : path_cmd_line_to); 90 | } 91 | 92 | } 93 | 94 | 95 | 96 | #endif 97 | 98 | 99 | -------------------------------------------------------------------------------- /agg2/include/agg_trans_single_path.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_TRANS_SINGLE_PATH_INCLUDED 17 | #define AGG_TRANS_SINGLE_PATH_INCLUDED 18 | 19 | #include "agg_basics.h" 20 | #include "agg_vertex_sequence.h" 21 | 22 | namespace agg 23 | { 24 | 25 | // See also: agg_trans_single_path.cpp 26 | // 27 | //-------------------------------------------------------trans_single_path 28 | class trans_single_path 29 | { 30 | enum status_e 31 | { 32 | initial, 33 | making_path, 34 | ready 35 | }; 36 | 37 | public: 38 | typedef vertex_sequence vertex_storage; 39 | 40 | trans_single_path(); 41 | 42 | //-------------------------------------------------------------------- 43 | void base_length(double v) { m_base_length = v; } 44 | double base_length() const { return m_base_length; } 45 | 46 | //-------------------------------------------------------------------- 47 | void preserve_x_scale(bool f) { m_preserve_x_scale = f; } 48 | bool preserve_x_scale() const { return m_preserve_x_scale; } 49 | 50 | //-------------------------------------------------------------------- 51 | void reset(); 52 | void move_to(double x, double y); 53 | void line_to(double x, double y); 54 | void finalize_path(); 55 | 56 | //-------------------------------------------------------------------- 57 | template 58 | void add_path(VertexSource& vs, unsigned path_id=0) 59 | { 60 | double x; 61 | double y; 62 | 63 | unsigned cmd; 64 | vs.rewind(path_id); 65 | while(!is_stop(cmd = vs.vertex(&x, &y))) 66 | { 67 | if(is_move_to(cmd)) 68 | { 69 | move_to(x, y); 70 | } 71 | else 72 | { 73 | if(is_vertex(cmd)) 74 | { 75 | line_to(x, y); 76 | } 77 | } 78 | } 79 | finalize_path(); 80 | } 81 | 82 | //-------------------------------------------------------------------- 83 | double total_length() const; 84 | void transform(double *x, double *y) const; 85 | 86 | private: 87 | vertex_storage m_src_vertices; 88 | double m_base_length; 89 | double m_kindex; 90 | status_e m_status; 91 | bool m_preserve_x_scale; 92 | }; 93 | 94 | 95 | } 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /agg2/include/agg_vcgen_dash.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // Line dash generator 17 | // 18 | //---------------------------------------------------------------------------- 19 | #ifndef AGG_VCGEN_DASH_INCLUDED 20 | #define AGG_VCGEN_DASH_INCLUDED 21 | 22 | #include "agg_basics.h" 23 | #include "agg_vertex_sequence.h" 24 | #include "agg_vertex_iterator.h" 25 | 26 | namespace agg 27 | { 28 | 29 | //---------------------------------------------------------------vcgen_dash 30 | // 31 | // See Implementation agg_vcgen_dash.cpp 32 | // 33 | class vcgen_dash 34 | { 35 | enum 36 | { 37 | max_dashes = 32 38 | }; 39 | 40 | enum status_e 41 | { 42 | initial, 43 | ready, 44 | polyline, 45 | stop 46 | }; 47 | 48 | public: 49 | typedef vertex_sequence vertex_storage; 50 | 51 | vcgen_dash(); 52 | 53 | void remove_all_dashes(); 54 | void add_dash(double dash_len, double gap_len); 55 | void dash_start(double ds); 56 | 57 | void shorten(double s) { m_shorten = s; } 58 | double shorten() const { return m_shorten; } 59 | 60 | // Vertex Generator Interface 61 | void remove_all(); 62 | void add_vertex(double x, double y, unsigned cmd); 63 | 64 | // Vertex Source Interface 65 | void rewind(unsigned id); 66 | unsigned vertex(double* x, double* y); 67 | 68 | typedef vcgen_dash source_type; 69 | typedef vertex_iterator iterator; 70 | iterator begin(unsigned id) { return iterator(*this, id); } 71 | iterator end() { return iterator(path_cmd_stop); } 72 | 73 | private: 74 | vcgen_dash(const vcgen_dash&); 75 | const vcgen_dash& operator = (const vcgen_dash&); 76 | 77 | void calc_dash_start(double ds); 78 | 79 | double m_dashes[max_dashes]; 80 | double m_total_dash_len; 81 | unsigned m_num_dashes; 82 | double m_dash_start; 83 | double m_shorten; 84 | double m_curr_dash_start; 85 | unsigned m_curr_dash; 86 | double m_curr_rest; 87 | const vertex_dist* m_v1; 88 | const vertex_dist* m_v2; 89 | 90 | vertex_storage m_src_vertices; 91 | unsigned m_closed; 92 | status_e m_status; 93 | unsigned m_src_vertex; 94 | }; 95 | 96 | 97 | } 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /agg2/include/agg_ellipse_bresenham.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // Simple Bresenham interpolator for ellipsees 17 | // 18 | //---------------------------------------------------------------------------- 19 | 20 | #ifndef AGG_ELLIPSE_BRESENHAM_INCLUDED 21 | #define AGG_ELLIPSE_BRESENHAM_INCLUDED 22 | 23 | 24 | #include "agg_basics.h" 25 | 26 | 27 | namespace agg 28 | { 29 | 30 | //------------------------------------------ellipse_bresenham_interpolator 31 | class ellipse_bresenham_interpolator 32 | { 33 | public: 34 | ellipse_bresenham_interpolator(int rx, int ry) : 35 | m_rx2(rx * rx), 36 | m_ry2(ry * ry), 37 | m_two_rx2(m_rx2 << 1), 38 | m_two_ry2(m_ry2 << 1), 39 | m_dx(0), 40 | m_dy(0), 41 | m_inc_x(0), 42 | m_inc_y(-ry * m_two_rx2), 43 | m_cur_f(0) 44 | {} 45 | 46 | int dx() const { return m_dx; } 47 | int dy() const { return m_dy; } 48 | 49 | void operator++ () 50 | { 51 | int mx, my, mxy, min_m; 52 | int fx, fy, fxy; 53 | 54 | mx = fx = m_cur_f + m_inc_x + m_ry2; 55 | if(mx < 0) mx = -mx; 56 | 57 | my = fy = m_cur_f + m_inc_y + m_rx2; 58 | if(my < 0) my = -my; 59 | 60 | mxy = fxy = m_cur_f + m_inc_x + m_ry2 + m_inc_y + m_rx2; 61 | if(mxy < 0) mxy = -mxy; 62 | 63 | min_m = mx; 64 | bool flag = true; 65 | 66 | if(min_m > my) 67 | { 68 | min_m = my; 69 | flag = false; 70 | } 71 | 72 | m_dx = m_dy = 0; 73 | 74 | if(min_m > mxy) 75 | { 76 | m_inc_x += m_two_ry2; 77 | m_inc_y += m_two_rx2; 78 | m_cur_f = fxy; 79 | m_dx = 1; 80 | m_dy = 1; 81 | return; 82 | } 83 | 84 | if(flag) 85 | { 86 | m_inc_x += m_two_ry2; 87 | m_cur_f = fx; 88 | m_dx = 1; 89 | return; 90 | } 91 | 92 | m_inc_y += m_two_rx2; 93 | m_cur_f = fy; 94 | m_dy = 1; 95 | } 96 | 97 | private: 98 | int m_rx2; 99 | int m_ry2; 100 | int m_two_rx2; 101 | int m_two_ry2; 102 | int m_dx; 103 | int m_dy; 104 | int m_inc_x; 105 | int m_inc_y; 106 | int m_cur_f; 107 | 108 | }; 109 | 110 | } 111 | 112 | #endif 113 | 114 | -------------------------------------------------------------------------------- /agg2/include/agg_span_interpolator_trans.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // Horizontal span interpolator for use with an arbitrary transformer 17 | // The efficiency highly depends on the operations done in the transformer 18 | // 19 | //---------------------------------------------------------------------------- 20 | 21 | #ifndef AGG_SPAN_INTERPOLATOR_TRANS_INCLUDED 22 | #define AGG_SPAN_INTERPOLATOR_TRANS_INCLUDED 23 | 24 | #include "agg_basics.h" 25 | 26 | namespace agg 27 | { 28 | //=================================================span_interpolator_trans 29 | template 30 | class span_interpolator_trans 31 | { 32 | public: 33 | typedef Transformer trans_type; 34 | 35 | enum 36 | { 37 | subpixel_shift = SubpixelShift, 38 | subpixel_size = 1 << subpixel_shift 39 | }; 40 | 41 | //-------------------------------------------------------------------- 42 | span_interpolator_trans() {} 43 | span_interpolator_trans(const trans_type& trans) : m_trans(&trans) {} 44 | span_interpolator_trans(const trans_type& trans, 45 | double x, double y, unsigned) : 46 | m_trans(&trans) 47 | { 48 | begin(x, y, 0); 49 | } 50 | 51 | //---------------------------------------------------------------- 52 | const trans_type& transformer() const { return *m_trans; } 53 | void transformer(const trans_type& trans) { m_trans = &trans; } 54 | 55 | //---------------------------------------------------------------- 56 | void begin(double x, double y, unsigned) 57 | { 58 | m_x = x; 59 | m_y = y; 60 | transform(); 61 | } 62 | 63 | //---------------------------------------------------------------- 64 | void operator++() 65 | { 66 | m_x += 1.0; 67 | transform(); 68 | } 69 | 70 | //---------------------------------------------------------------- 71 | void coordinates(int* x, int* y) const 72 | { 73 | *x = m_ix; 74 | *y = m_iy; 75 | } 76 | 77 | private: 78 | //---------------------------------------------------------------- 79 | void transform() 80 | { 81 | double x = m_x; 82 | double y = m_y; 83 | m_trans->transform(&x, &y); 84 | m_ix = int(x * subpixel_size); 85 | m_iy = int(y * subpixel_size); 86 | } 87 | 88 | const trans_type* m_trans; 89 | double m_x; 90 | double m_y; 91 | int m_ix; 92 | int m_iy; 93 | }; 94 | 95 | } 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /agg2/src/agg_arc.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // Arc vertex generator 17 | // 18 | //---------------------------------------------------------------------------- 19 | 20 | #include 21 | #include "agg_arc.h" 22 | 23 | 24 | namespace agg 25 | { 26 | //------------------------------------------------------------------------ 27 | arc::arc(double x, double y, 28 | double rx, double ry, 29 | double a1, double a2, 30 | bool ccw) : 31 | m_x(x), m_y(y), m_rx(rx), m_ry(ry), m_scale(1.0) 32 | { 33 | normalize(a1, a2, ccw); 34 | } 35 | 36 | //------------------------------------------------------------------------ 37 | void arc::init(double x, double y, 38 | double rx, double ry, 39 | double a1, double a2, 40 | bool ccw) 41 | { 42 | m_x = x; m_y = y; 43 | m_rx = rx; m_ry = ry; 44 | normalize(a1, a2, ccw); 45 | } 46 | 47 | //------------------------------------------------------------------------ 48 | void arc::approximation_scale(double s) 49 | { 50 | m_scale = s; 51 | if(m_initialized) 52 | { 53 | normalize(m_start, m_end, m_ccw); 54 | } 55 | } 56 | 57 | //------------------------------------------------------------------------ 58 | void arc::rewind(unsigned) 59 | { 60 | m_path_cmd = path_cmd_move_to; 61 | m_angle = m_start; 62 | } 63 | 64 | //------------------------------------------------------------------------ 65 | unsigned arc::vertex(double* x, double* y) 66 | { 67 | if(is_stop(m_path_cmd)) return path_cmd_stop; 68 | if((m_angle < m_end) != m_ccw) 69 | { 70 | *x = m_x + cos(m_end) * m_rx; 71 | *y = m_y + sin(m_end) * m_ry; 72 | m_path_cmd = path_cmd_stop; 73 | return path_cmd_line_to; 74 | } 75 | 76 | *x = m_x + cos(m_angle) * m_rx; 77 | *y = m_y + sin(m_angle) * m_ry; 78 | 79 | m_angle += m_da; 80 | 81 | unsigned pf = m_path_cmd; 82 | m_path_cmd = path_cmd_line_to; 83 | return pf; 84 | } 85 | 86 | //------------------------------------------------------------------------ 87 | void arc::normalize(double a1, double a2, bool ccw) 88 | { 89 | m_da = fabs(1.0 / ((m_rx + m_ry) * 0.5 * m_scale)); 90 | if(ccw) 91 | { 92 | while(a2 < a1) a2 += pi * 2.0; 93 | } 94 | else 95 | { 96 | while(a1 < a2) a1 += pi * 2.0; 97 | m_da = -m_da; 98 | } 99 | m_ccw = ccw; 100 | m_start = a1; 101 | m_end = a2; 102 | m_initialized = true; 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /agg2/include/agg_span_interpolator_linear.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_SPAN_INTERPOLATOR_LINEAR_INCLUDED 17 | #define AGG_SPAN_INTERPOLATOR_LINEAR_INCLUDED 18 | 19 | #include "agg_basics.h" 20 | #include "agg_dda_line.h" 21 | #include "agg_trans_affine.h" 22 | 23 | namespace agg 24 | { 25 | 26 | //================================================span_interpolator_linear 27 | template 28 | class span_interpolator_linear 29 | { 30 | public: 31 | typedef Transformer trans_type; 32 | 33 | enum 34 | { 35 | subpixel_shift = SubpixelShift, 36 | subpixel_size = 1 << subpixel_shift 37 | }; 38 | 39 | //-------------------------------------------------------------------- 40 | span_interpolator_linear() {} 41 | span_interpolator_linear(const trans_type& trans) : m_trans(&trans) {} 42 | span_interpolator_linear(const trans_type& trans, 43 | double x, double y, unsigned len) : 44 | m_trans(&trans) 45 | { 46 | begin(x, y, len); 47 | } 48 | 49 | //---------------------------------------------------------------- 50 | const trans_type& transformer() const { return *m_trans; } 51 | void transformer(const trans_type& trans) { m_trans = &trans; } 52 | 53 | //---------------------------------------------------------------- 54 | void begin(double x, double y, unsigned len) 55 | { 56 | double tx; 57 | double ty; 58 | 59 | tx = x; 60 | ty = y; 61 | m_trans->transform(&tx, &ty); 62 | int x1 = int(tx * subpixel_size); 63 | int y1 = int(ty * subpixel_size); 64 | 65 | tx = x + len; 66 | ty = y; 67 | m_trans->transform(&tx, &ty); 68 | int x2 = int(tx * subpixel_size); 69 | int y2 = int(ty * subpixel_size); 70 | 71 | m_li_x = dda2_line_interpolator(x1, x2, len); 72 | m_li_y = dda2_line_interpolator(y1, y2, len); 73 | } 74 | 75 | //---------------------------------------------------------------- 76 | void operator++() 77 | { 78 | ++m_li_x; 79 | ++m_li_y; 80 | } 81 | 82 | //---------------------------------------------------------------- 83 | void coordinates(int* x, int* y) const 84 | { 85 | *x = m_li_x.y(); 86 | *y = m_li_y.y(); 87 | } 88 | 89 | private: 90 | const trans_type* m_trans; 91 | dda2_line_interpolator m_li_x; 92 | dda2_line_interpolator m_li_y; 93 | }; 94 | 95 | } 96 | 97 | 98 | 99 | #endif 100 | 101 | 102 | -------------------------------------------------------------------------------- /agg2/include/agg_span_image_filter.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // Image transformations with filtering. Span generator base class 17 | // 18 | //---------------------------------------------------------------------------- 19 | #ifndef AGG_SPAN_IMAGE_FILTER_INCLUDED 20 | #define AGG_SPAN_IMAGE_FILTER_INCLUDED 21 | 22 | #include "agg_basics.h" 23 | #include "agg_image_filters.h" 24 | #include "agg_rendering_buffer.h" 25 | #include "agg_span_generator.h" 26 | 27 | 28 | namespace agg 29 | { 30 | 31 | //--------------------------------------------------span_image_filter 32 | template 33 | class span_image_filter : public span_generator 34 | { 35 | public: 36 | typedef ColorT color_type; 37 | typedef Allocator alloc_type; 38 | typedef Interpolator interpolator_type; 39 | 40 | //---------------------------------------------------------------- 41 | span_image_filter(alloc_type& alloc) : 42 | span_generator(alloc) 43 | {} 44 | 45 | //---------------------------------------------------------------- 46 | span_image_filter(alloc_type& alloc, 47 | const rendering_buffer& src, 48 | const color_type& back_color, 49 | interpolator_type& interpolator, 50 | const image_filter_base* filter) : 51 | span_generator(alloc), 52 | m_src(&src), 53 | m_back_color(back_color), 54 | m_interpolator(&interpolator), 55 | m_filter(filter) 56 | {} 57 | 58 | //---------------------------------------------------------------- 59 | const rendering_buffer& source_image() const { return *m_src; } 60 | const color_type& background_color() const { return m_back_color; } 61 | const image_filter_base& filter() const { return *m_filter; } 62 | 63 | //---------------------------------------------------------------- 64 | void source_image(const rendering_buffer& v) { m_src = &v; } 65 | void background_color(const color_type& v) { m_back_color = v; } 66 | void interpolator(interpolator_type& v) { m_interpolator = &v; } 67 | void filter(const image_filter_base& v) { m_filter = &v; } 68 | 69 | //---------------------------------------------------------------- 70 | interpolator_type& interpolator() { return *m_interpolator; } 71 | 72 | //---------------------------------------------------------------- 73 | private: 74 | const rendering_buffer* m_src; 75 | color_type m_back_color; 76 | interpolator_type* m_interpolator; 77 | const image_filter_base* m_filter; 78 | }; 79 | 80 | 81 | } 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /agg2/include/agg_gamma_lut.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_GAMMA_LUT_INCLUDED 17 | #define AGG_GAMMA_LUT_INCLUDED 18 | 19 | #include 20 | #include "agg_basics.h" 21 | 22 | namespace agg 23 | { 24 | template class gamma_lut 28 | { 29 | public: 30 | enum 31 | { 32 | gamma_shift = GammaShift, 33 | gamma_size = 1 << gamma_shift, 34 | gamma_mask = gamma_size - 1 35 | }; 36 | 37 | enum 38 | { 39 | hi_res_shift = HiResShift, 40 | hi_res_size = 1 << hi_res_shift, 41 | hi_res_mask = hi_res_size - 1 42 | }; 43 | 44 | ~gamma_lut() 45 | { 46 | delete [] m_inv_gamma; 47 | delete [] m_dir_gamma; 48 | } 49 | 50 | gamma_lut() : 51 | m_gamma(1.0), 52 | m_dir_gamma(new HiResT[gamma_size]), 53 | m_inv_gamma(new LoResT[hi_res_size]) 54 | { 55 | unsigned i; 56 | for(i = 0; i < gamma_size; i++) 57 | { 58 | m_dir_gamma[i] = HiResT(i << (hi_res_shift - gamma_shift)); 59 | } 60 | 61 | for(i = 0; i < hi_res_size; i++) 62 | { 63 | m_inv_gamma[i] = LoResT(i >> (hi_res_shift - gamma_shift)); 64 | } 65 | } 66 | 67 | gamma_lut(double g) : 68 | m_gamma(1.0), 69 | m_dir_gamma(new HiResT[gamma_size]), 70 | m_inv_gamma(new LoResT[hi_res_size]) 71 | { 72 | gamma(g); 73 | } 74 | 75 | void gamma(double g) 76 | { 77 | m_gamma = g; 78 | 79 | unsigned i; 80 | for(i = 0; i < gamma_size; i++) 81 | { 82 | m_dir_gamma[i] = (HiResT)(pow(double(i) / double(gamma_mask), m_gamma) * double(hi_res_mask) + 0.5); 83 | } 84 | 85 | double inv_g = 1.0 / g; 86 | for(i = 0; i < hi_res_size; i++) 87 | { 88 | m_inv_gamma[i] = (LoResT)(pow(double(i) / double(hi_res_mask), inv_g) * double(gamma_mask) + 0.5); 89 | } 90 | } 91 | 92 | double gamma() const 93 | { 94 | return m_gamma; 95 | } 96 | 97 | HiResT dir(LoResT v) const 98 | { 99 | return m_dir_gamma[unsigned(v)]; 100 | } 101 | 102 | LoResT inv(HiResT v) const 103 | { 104 | return m_inv_gamma[unsigned(v)]; 105 | } 106 | 107 | private: 108 | double m_gamma; 109 | HiResT* m_dir_gamma; 110 | LoResT* m_inv_gamma; 111 | }; 112 | } 113 | 114 | #endif 115 | -------------------------------------------------------------------------------- /agg2/include/ctrl/agg_ctrl.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // Function render_ctrl 17 | // 18 | //---------------------------------------------------------------------------- 19 | 20 | #ifndef AGG_CTRL_INCLUDED 21 | #define AGG_CTRL_INCLUDED 22 | 23 | #include "agg_trans_affine.h" 24 | #include "agg_renderer_scanline.h" 25 | 26 | namespace agg 27 | { 28 | 29 | //--------------------------------------------------------------------ctrl 30 | class ctrl 31 | { 32 | public: 33 | //-------------------------------------------------------------------- 34 | ctrl(double x1, double y1, double x2, double y2, bool flip_y) : 35 | m_x1(x1), m_y1(y1), m_x2(x2), m_y2(y2), 36 | m_flip_y(flip_y), 37 | m_mtx(0) 38 | { 39 | } 40 | 41 | //-------------------------------------------------------------------- 42 | virtual bool in_rect(double x, double y) const = 0; 43 | virtual bool on_mouse_button_down(double x, double y) = 0; 44 | virtual bool on_mouse_button_up(double x, double y) = 0; 45 | virtual bool on_mouse_move(double x, double y, bool button_flag) = 0; 46 | virtual bool on_arrow_keys(bool left, bool right, bool down, bool up) = 0; 47 | 48 | //-------------------------------------------------------------------- 49 | void transform(const trans_affine& mtx) { m_mtx = &mtx; } 50 | void no_transform() { m_mtx = 0; } 51 | 52 | //-------------------------------------------------------------------- 53 | void transform_xy(double* x, double* y) const 54 | { 55 | if(m_flip_y) *y = m_y1 + m_y2 - *y; 56 | if(m_mtx) m_mtx->transform(x, y); 57 | } 58 | 59 | //-------------------------------------------------------------------- 60 | void inverse_transform_xy(double* x, double* y) const 61 | { 62 | if(m_mtx) m_mtx->inverse_transform(x, y); 63 | if(m_flip_y) *y = m_y1 + m_y2 - *y; 64 | } 65 | 66 | private: 67 | ctrl(const ctrl&); 68 | const ctrl& operator = (const ctrl&); 69 | 70 | protected: 71 | double m_x1; 72 | double m_y1; 73 | double m_x2; 74 | double m_y2; 75 | 76 | private: 77 | bool m_flip_y; 78 | const trans_affine* m_mtx; 79 | }; 80 | 81 | 82 | //-------------------------------------------------------------------- 83 | template 84 | void render_ctrl(Rasterizer& ras, Scanline& sl, Renderer& r, Ctrl& c) 85 | { 86 | unsigned i; 87 | for(i = 0; i < c.num_paths(); i++) 88 | { 89 | ras.reset(); 90 | ras.add_path(c, i); 91 | r.color(c.color(i)); 92 | render_scanlines(ras, sl, r); 93 | } 94 | } 95 | 96 | 97 | } 98 | 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /agg2/include/agg_gray8.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // color type gray8 17 | // 18 | //---------------------------------------------------------------------------- 19 | 20 | #ifndef AGG_GRAY8_INCLUDED 21 | #define AGG_GRAY8_INCLUDED 22 | 23 | #include "agg_basics.h" 24 | #include "agg_color_rgba.h" 25 | #include "agg_color_rgba8.h" 26 | 27 | namespace agg 28 | { 29 | 30 | //===================================================================gray8 31 | struct gray8 32 | { 33 | int8u v; 34 | int8u a; 35 | 36 | //-------------------------------------------------------------------- 37 | gray8() {} 38 | 39 | //-------------------------------------------------------------------- 40 | gray8(unsigned v_, unsigned a_=255) : 41 | v(int8u(v_)), a(int8u(a_)) {} 42 | 43 | //-------------------------------------------------------------------- 44 | gray8(const rgba& c) : 45 | v(int8u((0.299*c.r + 0.587*c.g + 0.114*c.b) * 255.0 + 0.5)), 46 | a(int8u(c.a*255.0)) {} 47 | 48 | //-------------------------------------------------------------------- 49 | gray8(const rgba8& c) : 50 | v((c.r*77 + c.g*150 + c.b*29) >> 8), 51 | a(c.a) {} 52 | 53 | //-------------------------------------------------------------------- 54 | void clear() 55 | { 56 | v = a = 0; 57 | } 58 | 59 | //-------------------------------------------------------------------- 60 | const gray8& transparent() 61 | { 62 | a = 0; 63 | return *this; 64 | } 65 | 66 | //-------------------------------------------------------------------- 67 | void opacity(double a_) 68 | { 69 | if(a_ < 0.0) a_ = 0.0; 70 | if(a_ > 1.0) a_ = 1.0; 71 | a = int8u(a_ * 255.0); 72 | } 73 | 74 | //-------------------------------------------------------------------- 75 | double opacity() const 76 | { 77 | return double(a) / 255.0; 78 | } 79 | 80 | //-------------------------------------------------------------------- 81 | gray8 gradient(gray8 c, double k) const 82 | { 83 | gray8 ret; 84 | int ik = int(k * 256); 85 | ret.v = int8u(int(v) + (((int(c.v) - int(v)) * ik) >> 8)); 86 | ret.a = int8u(int(a) + (((int(c.a) - int(a)) * ik) >> 8)); 87 | return ret; 88 | } 89 | 90 | //-------------------------------------------------------------------- 91 | gray8 pre() const 92 | { 93 | return gray8((v*a) >> 8, a); 94 | 95 | } 96 | 97 | //-------------------------------------------------------------------- 98 | static gray8 no_color() { return gray8(0,0); } 99 | }; 100 | 101 | 102 | } 103 | 104 | 105 | 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /agg2/src/agg_vcgen_markers_term.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // Terminal markers generator (arrowhead/arrowtail) 17 | // 18 | //---------------------------------------------------------------------------- 19 | 20 | #include "agg_vcgen_markers_term.h" 21 | 22 | namespace agg 23 | { 24 | 25 | //------------------------------------------------------------------------ 26 | void vcgen_markers_term::remove_all() 27 | { 28 | m_markers.remove_all(); 29 | } 30 | 31 | 32 | //------------------------------------------------------------------------ 33 | void vcgen_markers_term::add_vertex(double x, double y, unsigned cmd) 34 | { 35 | if(is_move_to(cmd)) 36 | { 37 | if(m_markers.size() & 1) 38 | { 39 | // Initial state, the first coordinate was added. 40 | // If two of more calls of start_vertex() occures 41 | // we just modify the last one. 42 | m_markers.modify_last(coord_type(x, y)); 43 | } 44 | else 45 | { 46 | m_markers.add(coord_type(x, y)); 47 | } 48 | } 49 | else 50 | { 51 | if(is_vertex(cmd)) 52 | { 53 | if(m_markers.size() & 1) 54 | { 55 | // Initial state, the first coordinate was added. 56 | // Add three more points, 0,1,1,0 57 | m_markers.add(coord_type(x, y)); 58 | m_markers.add(m_markers[m_markers.size() - 1]); 59 | m_markers.add(m_markers[m_markers.size() - 3]); 60 | } 61 | else 62 | { 63 | if(m_markers.size()) 64 | { 65 | // Replace two last points: 0,1,1,0 -> 0,1,2,1 66 | m_markers[m_markers.size() - 1] = m_markers[m_markers.size() - 2]; 67 | m_markers[m_markers.size() - 2] = coord_type(x, y); 68 | } 69 | } 70 | } 71 | } 72 | } 73 | 74 | 75 | //------------------------------------------------------------------------ 76 | void vcgen_markers_term::rewind(unsigned id) 77 | { 78 | m_curr_id = id * 2; 79 | m_curr_idx = m_curr_id; 80 | } 81 | 82 | 83 | //------------------------------------------------------------------------ 84 | unsigned vcgen_markers_term::vertex(double* x, double* y) 85 | { 86 | if(m_curr_id > 2 || m_curr_idx >= m_markers.size()) 87 | { 88 | return path_cmd_stop; 89 | } 90 | const coord_type& c = m_markers[m_curr_idx]; 91 | *x = c.x; 92 | *y = c.y; 93 | if(m_curr_idx & 1) 94 | { 95 | m_curr_idx += 3; 96 | return path_cmd_line_to; 97 | } 98 | ++m_curr_idx; 99 | return path_cmd_move_to; 100 | } 101 | 102 | 103 | } 104 | -------------------------------------------------------------------------------- /agg2/include/agg_gamma_functions.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_GAMMA_FUNCTIONS_INCLUDED 17 | #define AGG_GAMMA_FUNCTIONS_INCLUDED 18 | 19 | #include 20 | #include "agg_basics.h" 21 | 22 | namespace agg 23 | { 24 | //===============================================================gamma_none 25 | struct gamma_none 26 | { 27 | double operator()(double x) const { return x; } 28 | }; 29 | 30 | 31 | //==============================================================gamma_power 32 | class gamma_power 33 | { 34 | public: 35 | gamma_power() : m_gamma(1.0) {} 36 | gamma_power(double g) : m_gamma(g) {} 37 | 38 | void gamma(double g) { m_gamma = g; } 39 | double gamma() const { return m_gamma; } 40 | 41 | double operator() (double x) const 42 | { 43 | return pow(x, m_gamma); 44 | } 45 | 46 | private: 47 | double m_gamma; 48 | }; 49 | 50 | 51 | //==========================================================gamma_threshold 52 | class gamma_threshold 53 | { 54 | public: 55 | gamma_threshold() : m_threshold(0.5) {} 56 | gamma_threshold(double t) : m_threshold(t) {} 57 | 58 | void threshold(double t) { m_threshold = t; } 59 | double threshold() const { return m_threshold; } 60 | 61 | double operator() (double x) const 62 | { 63 | return (x < m_threshold) ? 0.0 : 1.0; 64 | } 65 | 66 | private: 67 | double m_threshold; 68 | }; 69 | 70 | 71 | //============================================================gamma_linear 72 | class gamma_linear 73 | { 74 | public: 75 | gamma_linear() : m_start(0.0), m_end(1.0) {} 76 | gamma_linear(double s, double e) : m_start(s), m_end(e) {} 77 | 78 | void set(double s, double e) { m_start = s; m_end = e; } 79 | void start(double s) { m_start = s; } 80 | void end(double e) { m_end = e; } 81 | double start() const { return m_start; } 82 | double end() const { return m_end; } 83 | 84 | double operator() (double x) const 85 | { 86 | if(x < m_start) return 0.0; 87 | if(x > m_end) return 1.0; 88 | return (x - m_start) / (m_end - m_start); 89 | } 90 | 91 | private: 92 | double m_start; 93 | double m_end; 94 | }; 95 | 96 | 97 | //==========================================================gamma_multiply 98 | class gamma_multiply 99 | { 100 | public: 101 | gamma_multiply() : m_mul(1.0) {} 102 | gamma_multiply(double v) : m_mul(v) {} 103 | 104 | void value(double v) { m_mul = v; } 105 | double value() const { return m_mul; } 106 | 107 | double operator() (double x) const 108 | { 109 | double y = x * m_mul; 110 | if(y > 1.0) y = 1.0; 111 | return y; 112 | } 113 | 114 | private: 115 | double m_mul; 116 | }; 117 | 118 | } 119 | 120 | #endif 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /agg2/include/agg_bounding_rect.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // bounding_rect function template 17 | // 18 | //---------------------------------------------------------------------------- 19 | #ifndef AGG_BOUNDING_RECT_INCLUDED 20 | #define AGG_BOUNDING_RECT_INCLUDED 21 | 22 | #include "agg_basics.h" 23 | 24 | namespace agg 25 | { 26 | 27 | //-----------------------------------------------------------bounding_rect 28 | template 29 | bool bounding_rect(VertexSource& vs, GetId& gi, 30 | unsigned start, unsigned num, 31 | CoordT* x1, CoordT* y1, CoordT* x2, CoordT* y2) 32 | { 33 | unsigned i; 34 | double x; 35 | double y; 36 | bool first = true; 37 | 38 | for(i = 0; i < num; i++) 39 | { 40 | vs.rewind(gi[start + i]); 41 | unsigned cmd; 42 | while(!is_stop(cmd = vs.vertex(&x, &y))) 43 | { 44 | if(is_vertex(cmd)) 45 | { 46 | if(first) 47 | { 48 | *x1 = CoordT(x); 49 | *y1 = CoordT(y); 50 | *x2 = CoordT(x); 51 | *y2 = CoordT(y); 52 | first = false; 53 | } 54 | else 55 | { 56 | if(CoordT(x) < *x1) *x1 = CoordT(x); 57 | if(CoordT(y) < *y1) *y1 = CoordT(y); 58 | if(CoordT(x) > *x2) *x2 = CoordT(x); 59 | if(CoordT(y) > *y2) *y2 = CoordT(y); 60 | } 61 | } 62 | } 63 | } 64 | return *x1 <= *x2 && *y1 <= *y2; 65 | } 66 | 67 | 68 | //-----------------------------------------------------bounding_rect_single 69 | template 70 | bool bounding_rect_single(VertexSource& vs, unsigned path_id, 71 | CoordT* x1, CoordT* y1, CoordT* x2, CoordT* y2) 72 | { 73 | double x; 74 | double y; 75 | bool first = true; 76 | 77 | vs.rewind(path_id); 78 | unsigned cmd; 79 | while(!is_stop(cmd = vs.vertex(&x, &y))) 80 | { 81 | if(is_vertex(cmd)) 82 | { 83 | if(first) 84 | { 85 | *x1 = CoordT(x); 86 | *y1 = CoordT(y); 87 | *x2 = CoordT(x); 88 | *y2 = CoordT(y); 89 | first = false; 90 | } 91 | else 92 | { 93 | if(CoordT(x) < *x1) *x1 = CoordT(x); 94 | if(CoordT(y) < *y1) *y1 = CoordT(y); 95 | if(CoordT(x) > *x2) *x2 = CoordT(x); 96 | if(CoordT(y) > *y2) *y2 = CoordT(y); 97 | } 98 | } 99 | } 100 | return *x1 <= *x2 && *y1 <= *y2; 101 | } 102 | 103 | 104 | } 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /agg2/include/platform/win32/agg_win32_bmp.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // class pixel_map 17 | // 18 | //---------------------------------------------------------------------------- 19 | #ifndef AGG_WIN32_BMP_INCLUDED 20 | #define AGG_WIN32_BMP_INCLUDED 21 | 22 | 23 | #include 24 | #include 25 | 26 | 27 | namespace agg 28 | { 29 | enum org_e 30 | { 31 | org_mono8 = 8, 32 | org_color16 = 16, 33 | org_color24 = 24, 34 | org_color32 = 32 35 | }; 36 | 37 | class pixel_map 38 | { 39 | public: 40 | ~pixel_map(); 41 | pixel_map(); 42 | 43 | public: 44 | void destroy(); 45 | void create(unsigned width, 46 | unsigned height, 47 | org_e org, 48 | unsigned clear_val=256); 49 | 50 | void clear(unsigned clear_val=256); 51 | void attach_to_bmp(BITMAPINFO* bmp); 52 | BITMAPINFO* bitmap_info() { return m_bmp; } 53 | bool load_from_bmp(FILE* fd); 54 | bool save_as_bmp(FILE* fd) const; 55 | bool load_from_bmp(const char* filename); 56 | bool save_as_bmp(const char* filename) const; 57 | 58 | void draw(HDC h_dc, 59 | const RECT* device_rect=0, 60 | const RECT* bmp_rect=0) const; 61 | void draw(HDC h_dc, int x, int y, double scale=1.0) const; 62 | 63 | void blend(HDC h_dc, 64 | const RECT* device_rect=0, 65 | const RECT* bmp_rect=0) const; 66 | void blend(HDC h_dc, int x, int y, double scale=1.0) const; 67 | 68 | 69 | unsigned char* buf(); 70 | unsigned width() const; 71 | unsigned height() const; 72 | int stride() const; 73 | unsigned bpp() const { return m_bpp; } 74 | 75 | //Auxiliary static functions 76 | static unsigned calc_full_size(BITMAPINFO *bmp); 77 | static unsigned calc_header_size(BITMAPINFO *bmp); 78 | static unsigned calc_palette_size(unsigned clr_used, 79 | unsigned bits_per_pixel); 80 | static unsigned calc_palette_size(BITMAPINFO *bmp); 81 | static unsigned char* calc_img_ptr(BITMAPINFO *bmp); 82 | static BITMAPINFO* create_bitmap_info(unsigned width, 83 | unsigned height, 84 | unsigned bits_per_pixel); 85 | static void create_gray_scale_palette(BITMAPINFO *bmp); 86 | static unsigned calc_row_len(unsigned width, unsigned bits_per_pixel); 87 | 88 | private: 89 | pixel_map(const pixel_map&); 90 | const pixel_map& operator = (const pixel_map&); 91 | void create_from_bmp(BITMAPINFO *bmp); 92 | 93 | private: 94 | BITMAPINFO* m_bmp; 95 | unsigned char* m_buf; 96 | unsigned m_bpp; 97 | bool m_is_internal; 98 | unsigned m_img_size; 99 | unsigned m_full_size; 100 | }; 101 | 102 | } 103 | 104 | 105 | #endif 106 | -------------------------------------------------------------------------------- /agg2/src/agg_image_filters.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // Filtering class image_filter_base implemantation 17 | // 18 | //---------------------------------------------------------------------------- 19 | 20 | 21 | #include "agg_image_filters.h" 22 | 23 | 24 | namespace agg 25 | { 26 | 27 | //-------------------------------------------------------------------- 28 | image_filter_base::~image_filter_base() 29 | { 30 | delete [] m_weight_array_int; 31 | delete [] m_weight_array_dbl; 32 | } 33 | 34 | 35 | //-------------------------------------------------------------------- 36 | image_filter_base::image_filter_base(unsigned dimension) : 37 | m_dimension(dimension), 38 | m_start(-int(dimension / 2 - 1)), 39 | m_weight_array_dbl(new double [dimension << image_subpixel_shift]), 40 | m_weight_array_int(new int [dimension << image_subpixel_shift]) 41 | { 42 | } 43 | 44 | 45 | //-------------------------------------------------------------------- 46 | void image_filter_base::weight(unsigned idx, double val) 47 | { 48 | m_weight_array_dbl[idx] = val; 49 | m_weight_array_int[idx] = int(val * image_filter_size); 50 | } 51 | 52 | //-------------------------------------------------------------------- 53 | double image_filter_base::calc_x(unsigned idx) const 54 | { 55 | return double(idx) / double(image_subpixel_size) - 56 | double(m_dimension / 2); 57 | } 58 | 59 | //-------------------------------------------------------------------- 60 | // This function normalizes integer values and corrects the rounding 61 | // errors. It doesn't do anything with the source floating point values 62 | // (m_weight_array_dbl), it corrects only integers according to the rule 63 | // of 1.0 which means that any sum of pixel weights must be equal to 1.0. 64 | // So, the filter function must produce a graph of the proper shape. 65 | //-------------------------------------------------------------------- 66 | void image_filter_base::normalize() 67 | { 68 | unsigned i; 69 | int flip = 1; 70 | 71 | for(i = 0; i < image_subpixel_size; i++) 72 | { 73 | for(;;) 74 | { 75 | int sum = 0; 76 | unsigned j; 77 | for(j = 0; j < m_dimension; j++) 78 | { 79 | sum += m_weight_array_int[j * image_subpixel_size + i]; 80 | } 81 | sum -= image_filter_size; 82 | 83 | if(sum == 0) break; 84 | 85 | int inc = (sum > 0) ? -1 : 1; 86 | 87 | for(j = 0; j < m_dimension && sum; j++) 88 | { 89 | flip ^= 1; 90 | unsigned idx = flip ? m_dimension/2 + j/2 : m_dimension/2 - j/2; 91 | int v = m_weight_array_int[idx * image_subpixel_size + i]; 92 | if(v < image_filter_size) 93 | { 94 | m_weight_array_int[idx * image_subpixel_size + i] += inc; 95 | sum += inc; 96 | } 97 | } 98 | } 99 | } 100 | } 101 | 102 | } 103 | 104 | -------------------------------------------------------------------------------- /agg2/include/ctrl/agg_gamma_spline.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // class gamma_spline 17 | // 18 | //---------------------------------------------------------------------------- 19 | 20 | #ifndef AGG_GAMMA_SPLINE_INCLUDED 21 | #define AGG_GAMMA_SPLINE_INCLUDED 22 | 23 | #include "agg_basics.h" 24 | #include "agg_bspline.h" 25 | 26 | namespace agg 27 | { 28 | 29 | //------------------------------------------------------------------------ 30 | // Class-helper for calculation gamma-correction arrays. A gamma-correction 31 | // array is an array of 256 unsigned chars that determine the actual values 32 | // of Anti-Aliasing for each pixel coverage value from 0 to 255. If all the 33 | // values in the array are equal to its index, i.e. 0,1,2,3,... there's 34 | // no gamma-correction. Class agg::polyfill allows you to use custom 35 | // gamma-correction arrays. You can calculate it using any approach, and 36 | // class gamma_spline allows you to calculate almost any reasonable shape 37 | // of the gamma-curve with using only 4 values - kx1, ky1, kx2, ky2. 38 | // 39 | // kx2 40 | // +----------------------------------+ 41 | // | | | . | 42 | // | | | . | ky2 43 | // | | . ------| 44 | // | | . | 45 | // | | . | 46 | // |----------------.|----------------| 47 | // | . | | 48 | // | . | | 49 | // |-------. | | 50 | // ky1 | . | | | 51 | // | . | | | 52 | // +----------------------------------+ 53 | // kx1 54 | // 55 | // Each value can be in range [0...2]. Value 1.0 means one quarter of the 56 | // bounding rectangle. Function values() calculates the curve by these 57 | // 4 values. After calling it one can get the gamma-array with call gamma(). 58 | // Class also supports the vertex source interface, i.e rewind() and 59 | // vertex(). It's made for convinience and used in class gamma_ctrl. 60 | // Before calling rewind/vertex one must set the bounding box 61 | // box() using pixel coordinates. 62 | //------------------------------------------------------------------------ 63 | 64 | class gamma_spline 65 | { 66 | public: 67 | gamma_spline(); 68 | 69 | void values(double kx1, double ky1, double kx2, double ky2); 70 | const unsigned char* gamma() const { return m_gamma; } 71 | double y(double x) const; 72 | void values(double* kx1, double* ky1, double* kx2, double* ky2) const; 73 | void box(double x1, double y1, double x2, double y2); 74 | 75 | void rewind(unsigned); 76 | unsigned vertex(double* x, double* y); 77 | 78 | private: 79 | unsigned char m_gamma[256]; 80 | double m_x[4]; 81 | double m_y[4]; 82 | bspline m_spline; 83 | double m_x1; 84 | double m_y1; 85 | double m_x2; 86 | double m_y2; 87 | double m_cur_x; 88 | }; 89 | 90 | 91 | 92 | 93 | } 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /agg2/src/agg_line_profile_aa.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #include "agg_renderer_outline_aa.h" 17 | 18 | namespace agg 19 | { 20 | 21 | //--------------------------------------------------------------------- 22 | void line_profile_aa::width(double w) 23 | { 24 | if(w < 0.0) w = 0.0; 25 | 26 | if(w < m_smoother_width) w += w; 27 | else w += m_smoother_width; 28 | 29 | w *= 0.5; 30 | 31 | w -= m_smoother_width; 32 | double s = m_smoother_width; 33 | if(w < 0.0) 34 | { 35 | s += w; 36 | w = 0.0; 37 | } 38 | set(w, s); 39 | } 40 | 41 | 42 | //--------------------------------------------------------------------- 43 | line_profile_aa::value_type* line_profile_aa::profile(double w) 44 | { 45 | m_subpixel_width = int(w * subpixel_size); 46 | unsigned size = m_subpixel_width + subpixel_size * 6; 47 | if(size > m_size) 48 | { 49 | delete [] m_profile; 50 | m_profile = new value_type[m_size = size]; 51 | } 52 | return m_profile; 53 | } 54 | 55 | 56 | //--------------------------------------------------------------------- 57 | void line_profile_aa::set(double center_width, double smoother_width) 58 | { 59 | double base_val = 1.0; 60 | if(center_width == 0.0) center_width = 1.0 / subpixel_size; 61 | if(smoother_width == 0.0) smoother_width = 1.0 / subpixel_size; 62 | 63 | double width = center_width + smoother_width; 64 | if(width < m_min_width) 65 | { 66 | double k = width / m_min_width; 67 | base_val *= k; 68 | center_width /= k; 69 | smoother_width /= k; 70 | } 71 | 72 | value_type* ch = profile(center_width + smoother_width); 73 | 74 | unsigned subpixel_center_width = unsigned(center_width * subpixel_size); 75 | unsigned subpixel_smoother_width = unsigned(smoother_width * subpixel_size); 76 | 77 | value_type* ch_center = ch + subpixel_size*2; 78 | value_type* ch_smoother = ch_center + subpixel_center_width; 79 | 80 | unsigned i; 81 | 82 | unsigned val = m_gamma[unsigned(base_val * aa_mask)]; 83 | ch = ch_center; 84 | for(i = 0; i < subpixel_center_width; i++) 85 | { 86 | *ch++ = (value_type)val; 87 | } 88 | 89 | for(i = 0; i < subpixel_smoother_width; i++) 90 | { 91 | *ch_smoother++ = 92 | m_gamma[unsigned((base_val - 93 | base_val * 94 | (double(i) / subpixel_smoother_width)) * aa_mask)]; 95 | } 96 | 97 | unsigned n_smoother = profile_size() - 98 | subpixel_smoother_width - 99 | subpixel_center_width - 100 | subpixel_size*2; 101 | 102 | val = m_gamma[0]; 103 | for(i = 0; i < n_smoother; i++) 104 | { 105 | *ch_smoother++ = (value_type)val; 106 | } 107 | 108 | ch = ch_center; 109 | for(i = 0; i < subpixel_size*2; i++) 110 | { 111 | *--ch = *ch_center++; 112 | } 113 | } 114 | 115 | 116 | } 117 | 118 | -------------------------------------------------------------------------------- /agg2/src/agg_arrowhead.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // Simple arrowhead/arrowtail generator 17 | // 18 | //---------------------------------------------------------------------------- 19 | 20 | #include "agg_arrowhead.h" 21 | 22 | namespace agg 23 | { 24 | 25 | //------------------------------------------------------------------------ 26 | arrowhead::arrowhead() : 27 | m_head_d1(1.0), 28 | m_head_d2(1.0), 29 | m_head_d3(1.0), 30 | m_head_d4(0.0), 31 | m_tail_d1(1.0), 32 | m_tail_d2(1.0), 33 | m_tail_d3(1.0), 34 | m_tail_d4(0.0), 35 | m_head_flag(false), 36 | m_tail_flag(false), 37 | m_curr_id(0), 38 | m_curr_coord(0) 39 | { 40 | } 41 | 42 | 43 | 44 | //------------------------------------------------------------------------ 45 | void arrowhead::rewind(unsigned id) 46 | { 47 | m_curr_id = id; 48 | m_curr_coord = 0; 49 | if(id == 0) 50 | { 51 | if(!m_tail_flag) 52 | { 53 | m_cmd[0] = path_cmd_stop; 54 | return; 55 | } 56 | m_coord[0] = m_tail_d1; m_coord[1] = 0.0; 57 | m_coord[2] = m_tail_d1 - m_tail_d4; m_coord[3] = m_tail_d3; 58 | m_coord[4] = -m_tail_d2 - m_tail_d4; m_coord[5] = m_tail_d3; 59 | m_coord[6] = -m_tail_d2; m_coord[7] = 0.0; 60 | m_coord[8] = -m_tail_d2 - m_tail_d4; m_coord[9] = -m_tail_d3; 61 | m_coord[10] = m_tail_d1 - m_tail_d4; m_coord[11] = -m_tail_d3; 62 | 63 | m_cmd[0] = path_cmd_move_to; 64 | m_cmd[1] = path_cmd_line_to; 65 | m_cmd[2] = path_cmd_line_to; 66 | m_cmd[3] = path_cmd_line_to; 67 | m_cmd[4] = path_cmd_line_to; 68 | m_cmd[5] = path_cmd_line_to; 69 | m_cmd[7] = path_cmd_end_poly | path_flags_close | path_flags_ccw; 70 | m_cmd[6] = path_cmd_stop; 71 | return; 72 | } 73 | 74 | if(id == 1) 75 | { 76 | if(!m_head_flag) 77 | { 78 | m_cmd[0] = path_cmd_stop; 79 | return; 80 | } 81 | m_coord[0] = -m_head_d1; m_coord[1] = 0.0; 82 | m_coord[2] = m_head_d2 + m_head_d4; m_coord[3] = -m_head_d3; 83 | m_coord[4] = m_head_d2; m_coord[5] = 0.0; 84 | m_coord[6] = m_head_d2 + m_head_d4; m_coord[7] = m_head_d3; 85 | 86 | m_cmd[0] = path_cmd_move_to; 87 | m_cmd[1] = path_cmd_line_to; 88 | m_cmd[2] = path_cmd_line_to; 89 | m_cmd[3] = path_cmd_line_to; 90 | m_cmd[4] = path_cmd_end_poly | path_flags_close | path_flags_ccw; 91 | m_cmd[5] = path_cmd_stop; 92 | return; 93 | } 94 | } 95 | 96 | 97 | //------------------------------------------------------------------------ 98 | unsigned arrowhead::vertex(double* x, double* y) 99 | { 100 | if(m_curr_id < 2) 101 | { 102 | unsigned curr_idx = m_curr_coord * 2; 103 | *x = m_coord[curr_idx]; 104 | *y = m_coord[curr_idx + 1]; 105 | return m_cmd[m_curr_coord++]; 106 | } 107 | return path_cmd_stop; 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /agg2/include/ctrl/agg_cbox_ctrl.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // classes cbox_ctrl_impl, cbox_ctrl 17 | // 18 | //---------------------------------------------------------------------------- 19 | 20 | #ifndef AGG_CBOX_CTRL_INCLUDED 21 | #define AGG_CBOX_CTRL_INCLUDED 22 | 23 | #include "agg_basics.h" 24 | #include "agg_conv_stroke.h" 25 | #include "agg_gsv_text.h" 26 | #include "agg_trans_affine.h" 27 | #include "agg_color_rgba.h" 28 | #include "agg_ctrl.h" 29 | 30 | 31 | 32 | namespace agg 33 | { 34 | 35 | //----------------------------------------------------------cbox_ctrl_impl 36 | class cbox_ctrl_impl : public ctrl 37 | { 38 | public: 39 | cbox_ctrl_impl(double x, double y, const char* label, bool flip_y=false); 40 | 41 | void text_thickness(double t) { m_text_thickness = t; } 42 | void text_size(double h, double w=0.0); 43 | 44 | const char* label() { return m_label; } 45 | void label(const char* l); 46 | 47 | bool status() const { return m_status; } 48 | void status(bool st) { m_status = st; } 49 | 50 | virtual bool in_rect(double x, double y) const; 51 | virtual bool on_mouse_button_down(double x, double y); 52 | virtual bool on_mouse_button_up(double x, double y); 53 | virtual bool on_mouse_move(double x, double y, bool button_flag); 54 | virtual bool on_arrow_keys(bool left, bool right, bool down, bool up); 55 | 56 | // Vertex soutce interface 57 | unsigned num_paths() { return 3; }; 58 | void rewind(unsigned id); 59 | unsigned vertex(double* x, double* y); 60 | 61 | private: 62 | double m_text_thickness; 63 | double m_text_height; 64 | double m_text_width; 65 | char m_label[128]; 66 | bool m_status; 67 | double m_vx[32]; 68 | double m_vy[32]; 69 | 70 | gsv_text m_text; 71 | conv_stroke m_text_poly; 72 | 73 | unsigned m_idx; 74 | unsigned m_vertex; 75 | }; 76 | 77 | 78 | //----------------------------------------------------------cbox_ctrl_impl 79 | template class cbox_ctrl : public cbox_ctrl_impl 80 | { 81 | public: 82 | cbox_ctrl(double x, double y, const char* label, bool flip_y=false) : 83 | cbox_ctrl_impl(x, y, label, flip_y), 84 | m_text_color(rgba(0.0, 0.0, 0.0)), 85 | m_inactive_color(rgba(0.0, 0.0, 0.0)), 86 | m_active_color(rgba(0.4, 0.0, 0.0)) 87 | { 88 | m_colors[0] = &m_inactive_color; 89 | m_colors[1] = &m_text_color; 90 | m_colors[2] = &m_active_color; 91 | } 92 | 93 | void text_color(const ColorT& c) { m_text_color = c; } 94 | void inactive_color(const ColorT& c) { m_inactive_color = c; } 95 | void active_color(const ColorT& c) { m_active_color = c; } 96 | 97 | const ColorT& color(unsigned i) const { return *m_colors[i]; } 98 | 99 | private: 100 | cbox_ctrl(const cbox_ctrl&); 101 | const cbox_ctrl& operator = (const cbox_ctrl&); 102 | 103 | ColorT m_text_color; 104 | ColorT m_inactive_color; 105 | ColorT m_active_color; 106 | ColorT* m_colors[3]; 107 | }; 108 | 109 | 110 | } 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /selftest.py: -------------------------------------------------------------------------------- 1 | # $Id$ 2 | # -*- coding: iso-8859-1 -*- 3 | # sanity check 4 | 5 | import Image 6 | 7 | from aggdraw import * 8 | 9 | def testdraw(): 10 | """ 11 | 12 | >>> draw = Draw("RGB") 13 | Traceback (most recent call last): 14 | AttributeError: 'str' object has no attribute 'mode' 15 | 16 | >>> draw = Draw("RGB", (800, 600)) 17 | >>> draw.mode, draw.size 18 | ('RGB', (800, 600)) 19 | 20 | >>> draw = Draw("RGB", (800, 600), "white") 21 | >>> draw.mode, draw.size 22 | ('RGB', (800, 600)) 23 | 24 | >>> im = Image.new("RGB", (600, 800)) 25 | >>> draw = Draw(im) 26 | >>> draw.mode, draw.size 27 | ('RGB', (600, 800)) 28 | 29 | """ 30 | 31 | def testpen(): 32 | """ 33 | 34 | >>> pen = Pen("black") 35 | >>> pen = Pen("black", 1) 36 | >>> pen = Pen("black", 1.5) 37 | >>> pen = Pen("black", 1, opacity=128) 38 | 39 | >>> pen = Pen(0) 40 | >>> pen = Pen((0,0,0)) 41 | >>> pen = Pen("rgb(0,0,0)") 42 | >>> pen = Pen("gold") 43 | 44 | """ 45 | 46 | def testbrush(): 47 | """ 48 | 49 | >>> brush = Brush("black") 50 | >>> brush = Brush("black", opacity=128) 51 | 52 | >>> brush = Brush(0) 53 | >>> brush = Brush((0,0,0)) 54 | >>> brush = Brush("rgb(0,0,0)") 55 | >>> brush = Brush("gold") 56 | 57 | """ 58 | 59 | def testgraphics(): 60 | """ 61 | 62 | >>> draw = Draw("RGB", (500, 500)) 63 | 64 | >>> pen = Pen("black") 65 | >>> brush = Brush("black") 66 | 67 | >>> draw.line((50, 50, 100, 100), pen) 68 | 69 | >>> draw.rectangle((50, 150, 100, 200), pen) 70 | >>> draw.rectangle((50, 220, 100, 270), brush) 71 | >>> draw.rectangle((50, 290, 100, 340), brush, pen) 72 | >>> draw.rectangle((50, 360, 100, 410), pen, brush) 73 | 74 | >>> draw.ellipse((120, 150, 170, 200), pen) 75 | >>> draw.ellipse((120, 220, 170, 270), brush) 76 | >>> draw.ellipse((120, 290, 170, 340), brush, pen) 77 | >>> draw.ellipse((120, 360, 170, 410), pen, brush) 78 | 79 | >>> draw.polygon((190+25, 150, 190, 200, 190+50, 200), pen) 80 | >>> draw.polygon((190+25, 220, 190, 270, 190+50, 270), brush) 81 | >>> draw.polygon((190+25, 290, 190, 340, 190+50, 340), brush, pen) 82 | >>> draw.polygon((190+25, 360, 190, 410, 190+50, 410), pen, brush) 83 | 84 | """ 85 | 86 | def testpath(): 87 | """ 88 | 89 | >>> p = Path() 90 | >>> p = Path([0,0]) 91 | >>> p = Path([0,0,0,0]) 92 | 93 | >>> p.moveto(0, 0) 94 | >>> p.lineto(1, 1) 95 | >>> p.coords() 96 | [0.0, 0.0, 1.0, 1.0] 97 | 98 | >>> p.curveto(0, 0, 0, 0, 0, 0) 99 | >>> p.close() 100 | >>> p.coords() 101 | [0.0, 0.0, 1.0, 1.0, 0.125, 0.125, 0.0, 0.0] 102 | 103 | >>> draw = Draw("RGB", (800, 600)) 104 | >>> draw.line(p) 105 | >>> draw.polygon(p) 106 | >>> draw.symbol((0, 0), p) 107 | 108 | """ 109 | 110 | def testsymbol(): 111 | """ 112 | 113 | >>> s = Symbol("M0,0L0,0L0,0L0,0Z") 114 | >>> s = Symbol("M0,0L0,0,0,0,0,0Z", 10) 115 | >>> s = Symbol("M0,0C0,0,0,0,0,0Z") 116 | >>> s = Symbol("M0,0S0,0,0,0,0,0Z") 117 | 118 | >>> s = Symbol("m0,0l0,0l0,0l0,0z") 119 | >>> s = Symbol("m0,0l0,0,0,0,0,0z", 10) 120 | >>> s = Symbol("m0,0c0,0,0,0,0,0z") 121 | >>> s = Symbol("m0,0s0,0,0,0,0,0z") 122 | 123 | """ 124 | 125 | def testtransform(): 126 | """ 127 | 128 | >>> draw = Draw("RGB", (500, 500)) 129 | 130 | >>> draw.settransform() 131 | >>> draw.settransform((250, 250)) 132 | >>> draw.settransform((1, 0, 250, 0, 1, 250)) 133 | >>> draw.settransform((2.0, 0.5, 250, 0.5, 2.0, 250)) 134 | >>> draw.settransform() 135 | 136 | """ 137 | 138 | 139 | 140 | if __name__ == "__main__": 141 | # use doctest to make sure the test program behaves as documented! 142 | import doctest, selftest 143 | status = doctest.testmod(selftest) 144 | if status[0]: 145 | print "*** %s tests of %d failed." % status 146 | else: 147 | print "%s tests passed." % status[1] 148 | -------------------------------------------------------------------------------- /agg2/include/agg_pattern_filters_rgba8.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_PATTERN_FILTERS_RGBA8_INCLUDED 16 | #define AGG_PATTERN_FILTERS_RGBA8_INCLUDED 17 | 18 | #include "agg_basics.h" 19 | #include "agg_line_aa_basics.h" 20 | #include "agg_color_rgba8.h" 21 | 22 | 23 | namespace agg 24 | { 25 | 26 | //=======================================================pattern_filter_nn 27 | template struct pattern_filter_nn 28 | { 29 | typedef ColorT color_type; 30 | static unsigned dilation() { return 0; } 31 | 32 | static void pixel_low_res(color_type const* const* buf, 33 | color_type* p, int x, int y) 34 | { 35 | *p = buf[y][x]; 36 | } 37 | 38 | static void pixel_high_res(color_type const* const* buf, 39 | color_type* p, int x, int y) 40 | { 41 | *p = buf[y >> line_subpixel_shift] 42 | [x >> line_subpixel_shift]; 43 | } 44 | }; 45 | 46 | typedef pattern_filter_nn pattern_filter_nn_rgba8; 47 | 48 | 49 | 50 | //===========================================pattern_filter_bilinear_rgba8 51 | struct pattern_filter_bilinear_rgba8 52 | { 53 | typedef rgba8 color_type; 54 | static unsigned dilation() { return 1; } 55 | 56 | static void pixel_low_res(color_type const* const* buf, 57 | color_type* p, int x, int y) 58 | { 59 | *p = buf[y][x]; 60 | } 61 | 62 | static void pixel_high_res(color_type const* const* buf, 63 | color_type* p, int x, int y) 64 | { 65 | int r, g, b, a; 66 | r = g = b = a = line_subpixel_size * line_subpixel_size / 2; 67 | 68 | int weight; 69 | int x_lr = x >> line_subpixel_shift; 70 | int y_lr = y >> line_subpixel_shift; 71 | 72 | x &= line_subpixel_mask; 73 | y &= line_subpixel_mask; 74 | const color_type* ptr = buf[y_lr] + x_lr; 75 | 76 | weight = (line_subpixel_size - x) * 77 | (line_subpixel_size - y); 78 | r += weight * ptr->r; 79 | g += weight * ptr->g; 80 | b += weight * ptr->b; 81 | a += weight * ptr->a; 82 | 83 | ++ptr; 84 | 85 | weight = x * (line_subpixel_size - y); 86 | r += weight * ptr->r; 87 | g += weight * ptr->g; 88 | b += weight * ptr->b; 89 | a += weight * ptr->a; 90 | 91 | ptr = buf[y_lr + 1] + x_lr; 92 | 93 | weight = (line_subpixel_size - x) * y; 94 | r += weight * ptr->r; 95 | g += weight * ptr->g; 96 | b += weight * ptr->b; 97 | a += weight * ptr->a; 98 | 99 | ++ptr; 100 | 101 | weight = x * y; 102 | r += weight * ptr->r; 103 | g += weight * ptr->g; 104 | b += weight * ptr->b; 105 | a += weight * ptr->a; 106 | 107 | p->r = (int8u)(r >> line_subpixel_shift * 2); 108 | p->g = (int8u)(g >> line_subpixel_shift * 2); 109 | p->b = (int8u)(b >> line_subpixel_shift * 2); 110 | p->a = (int8u)(a >> line_subpixel_shift * 2); 111 | 112 | } 113 | }; 114 | 115 | } 116 | 117 | #endif 118 | -------------------------------------------------------------------------------- /agg2/src/ctrl/agg_gamma_spline.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // class gamma_spline 17 | // 18 | //---------------------------------------------------------------------------- 19 | 20 | #include "ctrl/agg_gamma_spline.h" 21 | 22 | namespace agg 23 | { 24 | 25 | //------------------------------------------------------------------------ 26 | gamma_spline::gamma_spline() : 27 | m_x1(0), m_y1(0), m_x2(10), m_y2(10), m_cur_x(0.0) 28 | { 29 | values(1.0, 1.0, 1.0, 1.0); 30 | } 31 | 32 | 33 | //------------------------------------------------------------------------ 34 | double gamma_spline::y(double x) const 35 | { 36 | if(x < 0.0) x = 0.0; 37 | if(x > 1.0) x = 1.0; 38 | double val = m_spline.get(x); 39 | if(val < 0.0) val = 0.0; 40 | if(val > 1.0) val = 1.0; 41 | return val; 42 | } 43 | 44 | 45 | 46 | //------------------------------------------------------------------------ 47 | void gamma_spline::values(double kx1, double ky1, double kx2, double ky2) 48 | { 49 | if(kx1 < 0.001) kx1 = 0.001; 50 | if(kx1 > 1.999) kx1 = 1.999; 51 | if(ky1 < 0.001) ky1 = 0.001; 52 | if(ky1 > 1.999) ky1 = 1.999; 53 | if(kx2 < 0.001) kx2 = 0.001; 54 | if(kx2 > 1.999) kx2 = 1.999; 55 | if(ky2 < 0.001) ky2 = 0.001; 56 | if(ky2 > 1.999) ky2 = 1.999; 57 | 58 | m_x[0] = 0.0; 59 | m_y[0] = 0.0; 60 | m_x[1] = kx1 * 0.25; 61 | m_y[1] = ky1 * 0.25; 62 | m_x[2] = 1.0 - kx2 * 0.25; 63 | m_y[2] = 1.0 - ky2 * 0.25; 64 | m_x[3] = 1.0; 65 | m_y[3] = 1.0; 66 | 67 | m_spline.init(4, m_x, m_y); 68 | 69 | int i; 70 | for(i = 0; i < 256; i++) 71 | { 72 | m_gamma[i] = (unsigned char)(y(double(i) / 255.0) * 255.0); 73 | } 74 | } 75 | 76 | 77 | //------------------------------------------------------------------------ 78 | void gamma_spline::values(double* kx1, double* ky1, double* kx2, double* ky2) const 79 | { 80 | *kx1 = m_x[1] * 4.0; 81 | *ky1 = m_y[1] * 4.0; 82 | *kx2 = (1.0 - m_x[2]) * 4.0; 83 | *ky2 = (1.0 - m_y[2]) * 4.0; 84 | } 85 | 86 | 87 | //------------------------------------------------------------------------ 88 | void gamma_spline::box(double x1, double y1, double x2, double y2) 89 | { 90 | m_x1 = x1; 91 | m_y1 = y1; 92 | m_x2 = x2; 93 | m_y2 = y2; 94 | } 95 | 96 | 97 | //------------------------------------------------------------------------ 98 | void gamma_spline::rewind(unsigned) 99 | { 100 | m_cur_x = 0.0; 101 | } 102 | 103 | 104 | //------------------------------------------------------------------------ 105 | unsigned gamma_spline::vertex(double* vx, double* vy) 106 | { 107 | if(m_cur_x == 0.0) 108 | { 109 | *vx = m_x1; 110 | *vy = m_y1; 111 | m_cur_x += 1.0 / (m_x2 - m_x1); 112 | return path_cmd_move_to; 113 | } 114 | 115 | if(m_cur_x > 1.0) 116 | { 117 | return path_cmd_stop; 118 | } 119 | 120 | *vx = m_x1 + m_cur_x * (m_x2 - m_x1); 121 | *vy = m_y1 + y(m_cur_x) * (m_y2 - m_y1); 122 | 123 | m_cur_x += 1.0 / (m_x2 - m_x1); 124 | return path_cmd_line_to; 125 | } 126 | 127 | 128 | 129 | } 130 | 131 | -------------------------------------------------------------------------------- /agg2/src/agg_vpgen_clip_polygon.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #include "agg_vpgen_clip_polygon.h" 17 | #include "agg_clip_liang_barsky.h" 18 | 19 | namespace agg 20 | { 21 | 22 | //------------------------------------------------------------------------ 23 | // Determine the clipping code of the vertex according to the 24 | // Cyrus-Beck line clipping algorithm 25 | // 26 | // | | 27 | // 0110 | 0010 | 0011 28 | // | | 29 | // -------+--------+-------- clip_box.y2 30 | // | | 31 | // 0100 | 0000 | 0001 32 | // | | 33 | // -------+--------+-------- clip_box.y1 34 | // | | 35 | // 1100 | 1000 | 1001 36 | // | | 37 | // clip_box.x1 clip_box.x2 38 | // 39 | // 40 | unsigned vpgen_clip_polygon::clipping_flags(double x, double y) 41 | { 42 | if(x < m_clip_box.x1) 43 | { 44 | if(y > m_clip_box.y2) return 6; 45 | if(y < m_clip_box.y1) return 12; 46 | return 4; 47 | } 48 | 49 | if(x > m_clip_box.x2) 50 | { 51 | if(y > m_clip_box.y2) return 3; 52 | if(y < m_clip_box.y1) return 9; 53 | return 1; 54 | } 55 | 56 | if(y > m_clip_box.y2) return 2; 57 | if(y < m_clip_box.y1) return 8; 58 | 59 | return 0; 60 | } 61 | 62 | //---------------------------------------------------------------------------- 63 | void vpgen_clip_polygon::reset() 64 | { 65 | m_vertex = 0; 66 | m_num_vertices = 0; 67 | } 68 | 69 | //---------------------------------------------------------------------------- 70 | void vpgen_clip_polygon::move_to(double x, double y) 71 | { 72 | m_vertex = 0; 73 | m_num_vertices = 0; 74 | m_clip_flags = clipping_flags(x, y); 75 | if(m_clip_flags == 0) 76 | { 77 | m_x[0] = x; 78 | m_y[0] = y; 79 | m_num_vertices = 1; 80 | } 81 | m_x1 = x; 82 | m_y1 = y; 83 | m_cmd = path_cmd_move_to; 84 | } 85 | 86 | 87 | //---------------------------------------------------------------------------- 88 | void vpgen_clip_polygon::line_to(double x, double y) 89 | { 90 | m_vertex = 0; 91 | m_num_vertices = 0; 92 | unsigned flags = clipping_flags(x, y); 93 | 94 | if(m_clip_flags == flags) 95 | { 96 | if(flags == 0) 97 | { 98 | m_x[0] = x; 99 | m_y[0] = y; 100 | m_num_vertices = 1; 101 | } 102 | } 103 | else 104 | { 105 | m_num_vertices = clip_liang_barsky(m_x1, m_y1, 106 | x, y, 107 | m_clip_box, 108 | m_x, m_y); 109 | } 110 | 111 | m_clip_flags = flags; 112 | m_x1 = x; 113 | m_y1 = y; 114 | } 115 | 116 | 117 | //---------------------------------------------------------------------------- 118 | unsigned vpgen_clip_polygon::vertex(double* x, double* y) 119 | { 120 | if(m_vertex < m_num_vertices) 121 | { 122 | *x = m_x[m_vertex]; 123 | *y = m_y[m_vertex]; 124 | ++m_vertex; 125 | unsigned cmd = m_cmd; 126 | m_cmd = path_cmd_line_to; 127 | return cmd; 128 | } 129 | return path_cmd_stop; 130 | } 131 | 132 | 133 | } 134 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | ================== 2 | The aggdraw module 3 | ================== 4 | 5 | A high-quality graphics engine for PIL, based on Maxim Shemanarev's 6 | Anti-Grain Geometry library (from http://antigrain.com). 7 | 8 | The necessary AGG sources are included in the aggdraw source kit. 9 | 10 | Enjoy /F 11 | 12 | fredrik@pythonware.com 13 | http://www.pythonware.com 14 | 15 | NOTE: This is a patched version of the official package to support 16 | 64 bits systems. To use it on your projects, make sure you specify 17 | the dependency as "aggdraw == 1.1-64bits". You'd also need to make 18 | the distribution available at some place setuptools can reach 19 | with the find-links options, or re-use the branch hosted at Bitbucket: 20 | http://bitbucket.org/2degrees/aggdraw-64bits/ 21 | 22 | -------------------------------------------------------------------- 23 | Build instructions (all platforms) 24 | -------------------------------------------------------------------- 25 | 26 | 1. Check prerequisites. 27 | 28 | You need a C++ compiler to build this extension. 29 | 30 | The library comes with the necessary AGG sources included. 31 | 32 | The following additional libraries can be used: 33 | 34 | OpenType/TrueType freetype2 (2.1.10 or later is recommended) 35 | support 36 | http://www.freetype.org 37 | http://freetype.sourceforge.net 38 | 39 | 2. Configure. 40 | 41 | To enable freetype, you need to build the library somewhere, and 42 | then change the FREETYPE_ROOT variable in aggdraw's setup.py file 43 | so it points to the build location. 44 | 45 | If you don't want or need freetype support, you can leave the 46 | variable as is, or set it to None. 47 | 48 | 3. Build. 49 | 50 | The library uses a standard setup.py file, and you can use all 51 | standard setup.py commands. I recommend the following steps: 52 | 53 | $ python setup.py build_ext -i 54 | $ python selftest.py 55 | 56 | (if you're lazy, you can skip the above and just install the 57 | library; setup.py will make sure the right stuff is built before 58 | it's installed). 59 | 60 | 4. Install. 61 | 62 | If the selftest succeeds, you can install the library: 63 | 64 | $ python setup.py install 65 | 66 | 5. Enjoy! 67 | 68 | -------------------------------------------------------------------- 69 | License 70 | -------------------------------------------------------------------- 71 | 72 | Anti-Grain Geometry - Version 2.0 73 | Copyright (c) 2002 Maxim Shemanarev (McSeem) 74 | 75 | Permission to copy, use, modify, sell and distribute this software 76 | is granted provided this copyright notice appears in all copies. 77 | This software is provided "as is" without express or implied 78 | warranty, and with no claim as to its suitability for any purpose. 79 | 80 | -------------------------------------------------------------------- 81 | 82 | The aggdraw interface, and associated modules and documentation are: 83 | 84 | Copyright (c) 2003-2005 by Secret Labs AB 85 | Copyright (c) 2003-2005 by Fredrik Lundh 86 | 87 | By obtaining, using, and/or copying this software and/or its 88 | associated documentation, you agree that you have read, understood, 89 | and will comply with the following terms and conditions: 90 | 91 | Permission to use, copy, modify, and distribute this software and its 92 | associated documentation for any purpose and without fee is hereby 93 | granted, provided that the above copyright notice appears in all 94 | copies, and that both that copyright notice and this permission notice 95 | appear in supporting documentation, and that the name of Secret Labs 96 | AB or the author not be used in advertising or publicity pertaining to 97 | distribution of the software without specific, written prior 98 | permission. 99 | 100 | SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO 101 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 102 | FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR BE LIABLE FOR 103 | ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 104 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 105 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 106 | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 107 | 108 | -------------------------------------------------------------------- 109 | -------------------------------------------------------------------------------- /agg2/include/agg_conv_adaptor_vpgen.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_CONV_ADAPTOR_VPGEN_INCLUDED 17 | #define AGG_CONV_ADAPTOR_VPGEN_INCLUDED 18 | 19 | #include "agg_basics.h" 20 | #include "agg_vertex_iterator.h" 21 | 22 | namespace agg 23 | { 24 | 25 | //======================================================conv_adaptor_vpgen 26 | template class conv_adaptor_vpgen 27 | { 28 | public: 29 | conv_adaptor_vpgen(VertexSource& source) : m_source(&source) {} 30 | 31 | void set_source(VertexSource& source) { m_source = &source; } 32 | 33 | VPGen& vpgen() { return m_vpgen; } 34 | const VPGen& vpgen() const { return m_vpgen; } 35 | 36 | void rewind(unsigned path_id); 37 | unsigned vertex(double* x, double* y); 38 | 39 | typedef conv_adaptor_vpgen source_type; 40 | typedef vertex_iterator iterator; 41 | iterator begin(unsigned id) { return iterator(*this, id); } 42 | iterator end() { return iterator(path_cmd_stop); } 43 | 44 | private: 45 | conv_adaptor_vpgen(const conv_adaptor_vpgen&); 46 | const conv_adaptor_vpgen& 47 | operator = (const conv_adaptor_vpgen&); 48 | 49 | VertexSource* m_source; 50 | VPGen m_vpgen; 51 | double m_start_x; 52 | double m_start_y; 53 | unsigned m_poly_flags; 54 | }; 55 | 56 | 57 | 58 | //------------------------------------------------------------------------ 59 | template 60 | void conv_adaptor_vpgen::rewind(unsigned path_id) 61 | { 62 | m_source->rewind(path_id); 63 | m_vpgen.reset(); 64 | m_start_x = 0; 65 | m_start_y = 0; 66 | m_poly_flags = 0; 67 | } 68 | 69 | 70 | //------------------------------------------------------------------------ 71 | template 72 | unsigned conv_adaptor_vpgen::vertex(double* x, double* y) 73 | { 74 | unsigned cmd = path_cmd_stop; 75 | for(;;) 76 | { 77 | cmd = m_vpgen.vertex(x, y); 78 | if(!is_stop(cmd)) break; 79 | 80 | if(m_poly_flags) 81 | { 82 | cmd = m_poly_flags; 83 | m_poly_flags = 0; 84 | break; 85 | } 86 | 87 | double tx, ty; 88 | cmd = m_source->vertex(&tx, &ty); 89 | if(is_vertex(cmd)) 90 | { 91 | if(is_move_to(cmd)) 92 | { 93 | m_vpgen.move_to(tx, ty); 94 | m_start_x = tx; 95 | m_start_y = ty; 96 | } 97 | else 98 | { 99 | m_vpgen.line_to(tx, ty); 100 | } 101 | } 102 | else 103 | { 104 | if(is_end_poly(cmd)) 105 | { 106 | m_poly_flags = cmd; 107 | if(is_closed(cmd)) 108 | { 109 | m_vpgen.line_to(m_start_x, m_start_y); 110 | } 111 | } 112 | else 113 | { 114 | // The adaptor should be transparent to all unknown commands 115 | break; 116 | } 117 | } 118 | } 119 | return cmd; 120 | } 121 | 122 | 123 | } 124 | 125 | 126 | #endif 127 | 128 | -------------------------------------------------------------------------------- /agg2/include/agg_vcgen_vertex_sequence.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_VCGEN_VERTEX_SEQUENCE_INCLUDED 17 | #define AGG_VCGEN_VERTEX_SEQUENCE_INCLUDED 18 | 19 | #include "agg_basics.h" 20 | #include "agg_vertex_sequence.h" 21 | #include "agg_shorten_path.h" 22 | 23 | namespace agg 24 | { 25 | 26 | //===================================================vcgen_vertex_sequence 27 | class vcgen_vertex_sequence 28 | { 29 | public: 30 | typedef vertex_dist_cmd vertex_type; 31 | typedef vertex_sequence vertex_storage; 32 | 33 | vcgen_vertex_sequence() : 34 | m_flags(0), 35 | m_cur_vertex(0), 36 | m_shorten(0.0), 37 | m_ready(false) 38 | { 39 | } 40 | 41 | // Vertex Generator Interface 42 | void remove_all(); 43 | void add_vertex(double x, double y, unsigned cmd); 44 | 45 | // Vertex Source Interface 46 | void rewind(unsigned id); 47 | unsigned vertex(double* x, double* y); 48 | 49 | void shorten(double s) { m_shorten = s; } 50 | double shorten() const { return m_shorten; } 51 | 52 | private: 53 | vcgen_vertex_sequence(const vcgen_vertex_sequence&); 54 | const vcgen_vertex_sequence& operator = (const vcgen_vertex_sequence&); 55 | 56 | vertex_storage m_src_vertices; 57 | unsigned m_flags; 58 | unsigned m_cur_vertex; 59 | double m_shorten; 60 | bool m_ready; 61 | }; 62 | 63 | 64 | //------------------------------------------------------------------------ 65 | inline void vcgen_vertex_sequence::remove_all() 66 | { 67 | m_ready = false; 68 | m_src_vertices.remove_all(); 69 | m_cur_vertex = 0; 70 | m_flags = 0; 71 | } 72 | 73 | //------------------------------------------------------------------------ 74 | inline void vcgen_vertex_sequence::add_vertex(double x, double y, unsigned cmd) 75 | { 76 | m_ready = false; 77 | if(is_move_to(cmd)) 78 | { 79 | m_src_vertices.modify_last(vertex_dist_cmd(x, y, cmd)); 80 | } 81 | else 82 | { 83 | if(is_vertex(cmd)) 84 | { 85 | m_src_vertices.add(vertex_dist_cmd(x, y, cmd)); 86 | } 87 | else 88 | { 89 | m_flags = cmd & path_flags_mask; 90 | } 91 | } 92 | } 93 | 94 | 95 | //------------------------------------------------------------------------ 96 | inline void vcgen_vertex_sequence::rewind(unsigned) 97 | { 98 | if(!m_ready) 99 | { 100 | m_src_vertices.close(is_closed(m_flags)); 101 | shorten_path(m_src_vertices, m_shorten, get_close_flag(m_flags)); 102 | } 103 | m_ready = true; 104 | m_cur_vertex = 0; 105 | } 106 | 107 | //------------------------------------------------------------------------ 108 | inline unsigned vcgen_vertex_sequence::vertex(double* x, double* y) 109 | { 110 | if(!m_ready) 111 | { 112 | rewind(0); 113 | } 114 | 115 | if(m_cur_vertex == m_src_vertices.size()) 116 | { 117 | ++m_cur_vertex; 118 | return path_cmd_end_poly | m_flags; 119 | } 120 | 121 | if(m_cur_vertex > m_src_vertices.size()) 122 | { 123 | return path_cmd_stop; 124 | } 125 | 126 | vertex_type& v = m_src_vertices[m_cur_vertex++]; 127 | *x = v.x; 128 | *y = v.y; 129 | return v.cmd; 130 | } 131 | 132 | 133 | } 134 | 135 | #endif 136 | -------------------------------------------------------------------------------- /agg2/include/agg_conv_close_polygon.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_CONV_CLOSE_POLYGON_INCLUDED 17 | #define AGG_CONV_CLOSE_POLYGON_INCLUDED 18 | 19 | #include "agg_basics.h" 20 | #include "agg_vertex_iterator.h" 21 | 22 | namespace agg 23 | { 24 | 25 | //======================================================conv_close_polygon 26 | template class conv_close_polygon 27 | { 28 | public: 29 | conv_close_polygon(VertexSource& vs) : m_source(&vs) {} 30 | 31 | void set_source(VertexSource& source) { m_source = &source; } 32 | 33 | void rewind(unsigned path_id); 34 | unsigned vertex(double* x, double* y); 35 | 36 | typedef conv_close_polygon source_type; 37 | typedef vertex_iterator iterator; 38 | iterator begin(unsigned id) { return iterator(*this, id); } 39 | iterator end() { return iterator(path_cmd_stop); } 40 | 41 | private: 42 | conv_close_polygon(const conv_close_polygon&); 43 | const conv_close_polygon& 44 | operator = (const conv_close_polygon&); 45 | 46 | VertexSource* m_source; 47 | unsigned m_cmd[2]; 48 | double m_x[2]; 49 | double m_y[2]; 50 | unsigned m_vertex; 51 | bool m_line_to; 52 | }; 53 | 54 | 55 | 56 | //------------------------------------------------------------------------ 57 | template 58 | void conv_close_polygon::rewind(unsigned path_id) 59 | { 60 | m_source->rewind(path_id); 61 | m_vertex = 2; 62 | m_line_to = false; 63 | } 64 | 65 | 66 | 67 | //------------------------------------------------------------------------ 68 | template 69 | unsigned conv_close_polygon::vertex(double* x, double* y) 70 | { 71 | unsigned cmd = path_cmd_stop; 72 | for(;;) 73 | { 74 | if(m_vertex < 2) 75 | { 76 | *x = m_x[m_vertex]; 77 | *y = m_y[m_vertex]; 78 | cmd = m_cmd[m_vertex]; 79 | ++m_vertex; 80 | break; 81 | } 82 | 83 | cmd = m_source->vertex(x, y); 84 | 85 | if(is_end_poly(cmd)) 86 | { 87 | cmd |= path_flags_close; 88 | break; 89 | } 90 | 91 | if(is_stop(cmd)) 92 | { 93 | if(m_line_to) 94 | { 95 | m_cmd[0] = path_cmd_end_poly | path_flags_close; 96 | m_cmd[1] = path_cmd_stop; 97 | m_vertex = 0; 98 | m_line_to = false; 99 | continue; 100 | } 101 | break; 102 | } 103 | 104 | if(is_move_to(cmd)) 105 | { 106 | if(m_line_to) 107 | { 108 | m_x[0] = 0.0; 109 | m_y[0] = 0.0; 110 | m_cmd[0] = path_cmd_end_poly | path_flags_close; 111 | m_x[1] = *x; 112 | m_y[1] = *y; 113 | m_cmd[1] = cmd; 114 | m_vertex = 0; 115 | m_line_to = false; 116 | continue; 117 | } 118 | break; 119 | } 120 | 121 | if(is_vertex(cmd)) 122 | { 123 | m_line_to = true; 124 | break; 125 | } 126 | } 127 | return cmd; 128 | } 129 | 130 | } 131 | 132 | #endif 133 | -------------------------------------------------------------------------------- /agg2/include/agg_rasterizer_outline.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | #ifndef AGG_RASTERIZER_OUTLINE_INCLUDED 16 | #define AGG_RASTERIZER_OUTLINE_INCLUDED 17 | 18 | #include "agg_basics.h" 19 | 20 | namespace agg 21 | { 22 | //======================================================rasterizer_outline 23 | template class rasterizer_outline 24 | { 25 | public: 26 | rasterizer_outline(Renderer& ren) : m_ren(&ren), m_start_x(0), m_start_y(0) 27 | { 28 | } 29 | 30 | //-------------------------------------------------------------------- 31 | void move_to(int x, int y) 32 | { 33 | m_ren->move_to(m_start_x = x, m_start_y = y); 34 | } 35 | 36 | //-------------------------------------------------------------------- 37 | void line_to(int x, int y) 38 | { 39 | m_ren->line_to(x, y); 40 | } 41 | 42 | //-------------------------------------------------------------------- 43 | void move_to_d(double x, double y) 44 | { 45 | move_to(m_ren->coord(x), m_ren->coord(y)); 46 | } 47 | 48 | //-------------------------------------------------------------------- 49 | void line_to_d(double x, double y) 50 | { 51 | line_to(m_ren->coord(x), m_ren->coord(y)); 52 | } 53 | 54 | //-------------------------------------------------------------------- 55 | void close() 56 | { 57 | line_to(m_start_x, m_start_y); 58 | } 59 | 60 | //-------------------------------------------------------------------- 61 | void add_vertex(double x, double y, unsigned cmd) 62 | { 63 | if(is_move_to(cmd)) 64 | { 65 | move_to_d(x, y); 66 | } 67 | else 68 | { 69 | if(is_end_poly(cmd)) 70 | { 71 | if(is_closed(cmd)) close(); 72 | } 73 | else 74 | { 75 | line_to_d(x, y); 76 | } 77 | } 78 | } 79 | 80 | 81 | //-------------------------------------------------------------------- 82 | template 83 | void add_path(VertexSource& vs, unsigned id=0) 84 | { 85 | double x; 86 | double y; 87 | 88 | unsigned cmd; 89 | vs.rewind(id); 90 | while(!is_stop(cmd = vs.vertex(&x, &y))) 91 | { 92 | add_vertex(x, y, cmd); 93 | } 94 | } 95 | 96 | 97 | //-------------------------------------------------------------------- 98 | template 99 | void render_all_paths(VertexSource& vs, 100 | const ColorStorage& colors, 101 | const PathId& id, 102 | unsigned num_paths) 103 | { 104 | for(unsigned i = 0; i < num_paths; i++) 105 | { 106 | m_ren->line_color(colors[i]); 107 | add_path(vs, id[i]); 108 | } 109 | } 110 | 111 | 112 | //-------------------------------------------------------------------- 113 | template void render_ctrl(Ctrl& c) 114 | { 115 | unsigned i; 116 | for(i = 0; i < c.num_paths(); i++) 117 | { 118 | m_ren->line_color(c.color(i)); 119 | add_path(c, i); 120 | } 121 | } 122 | 123 | 124 | private: 125 | Renderer* m_ren; 126 | int m_start_x; 127 | int m_start_y; 128 | }; 129 | 130 | 131 | } 132 | 133 | 134 | #endif 135 | 136 | -------------------------------------------------------------------------------- /agg2/include/agg_vertex_iterator.h: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------- 2 | // Anti-Grain Geometry - Version 2.2 3 | // Copyright (C) 2002-2004 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 | // classes: vertex_iterator 17 | // vertex_source_adaptor 18 | // vertex_source_adaptor_with_id 19 | // 20 | //---------------------------------------------------------------------------- 21 | #ifndef AGG_VERTEX_ITERATOR_INCLUDED 22 | #define AGG_VERTEX_ITERATOR_INCLUDED 23 | 24 | #include "agg_basics.h" 25 | 26 | 27 | namespace agg 28 | { 29 | 30 | //---------------------------------------------------------vertex_iterator 31 | template class vertex_iterator 32 | { 33 | public: 34 | vertex_iterator() {} 35 | vertex_iterator(unsigned cmd) { m_vertex.cmd = cmd; } 36 | vertex_iterator(const vertex_iterator& i) : m_vs(i.m_vs), m_vertex(i.m_vertex) {} 37 | vertex_iterator(VertexSource& vs, unsigned id) : m_vs(&vs) 38 | { 39 | m_vs->rewind(id); 40 | m_vertex.cmd = m_vs->vertex(&m_vertex.x, &m_vertex.y); 41 | } 42 | vertex_iterator& operator++() 43 | { 44 | m_vertex.cmd = m_vs->vertex(&m_vertex.x, &m_vertex.y); 45 | return *this; 46 | } 47 | 48 | const vertex_type& operator*() const { return m_vertex; } 49 | const vertex_type* operator->() const { return &m_vertex; } 50 | 51 | bool operator != (const vertex_iterator& i) 52 | { 53 | return m_vertex.cmd != i.m_vertex.cmd; 54 | } 55 | 56 | private: 57 | VertexSource* m_vs; 58 | vertex_type m_vertex; 59 | }; 60 | 61 | 62 | //---------------------------------------------------vertex_source_adaptor 63 | template class vertex_source_adaptor 64 | { 65 | public: 66 | vertex_source_adaptor(const VertexContainer& container) : 67 | m_container(&container) {} 68 | 69 | void rewind(unsigned) 70 | { 71 | m_iterator = m_container->begin(); 72 | m_end = m_container->end(); 73 | } 74 | 75 | unsigned vertex(double* x, double* y) 76 | { 77 | unsigned cmd = path_cmd_stop; 78 | if(m_iterator != m_end) 79 | { 80 | *x = m_iterator->x; 81 | *y = m_iterator->y; 82 | cmd = m_iterator->cmd; 83 | ++m_iterator; 84 | } 85 | return cmd; 86 | } 87 | 88 | private: 89 | const VertexContainer* m_container; 90 | typename VertexContainer::const_iterator m_iterator; 91 | typename VertexContainer::const_iterator m_end; 92 | }; 93 | 94 | 95 | 96 | //-------------------------------------------vertex_source_adaptor_with_id 97 | template class vertex_source_adaptor_with_id 98 | { 99 | public: 100 | vertex_source_adaptor_with_id(const VertexContainer& container) : 101 | m_container(&container) {} 102 | 103 | void rewind(unsigned id) 104 | { 105 | m_iterator = m_container->begin(id); 106 | m_end = m_container->end(); 107 | } 108 | 109 | unsigned vertex(double* x, double* y) 110 | { 111 | unsigned cmd = path_cmd_stop; 112 | if(m_iterator != m_end) 113 | { 114 | *x = m_iterator->x; 115 | *y = m_iterator->y; 116 | cmd = m_iterator->cmd; 117 | ++m_iterator; 118 | } 119 | return cmd; 120 | } 121 | 122 | private: 123 | const VertexContainer* m_container; 124 | typename VertexContainer::const_iterator m_iterator; 125 | typename VertexContainer::const_iterator m_end; 126 | }; 127 | 128 | 129 | 130 | } 131 | 132 | 133 | #endif 134 | --------------------------------------------------------------------------------