@@ -66,78 +66,84 @@ typedef agg::renderer_scanline_aa_solid<renderer_base_alpha_mask_type> renderer_
6666
6767// a helper class to pass agg::buffer objects around. agg::buffer is
6868// a class in the swig wrapper
69- class BufferRegion : public Py ::PythonExtension<BufferRegion> {
69+ class BufferRegion : public Py ::PythonExtension<BufferRegion>
70+ {
7071public:
71- BufferRegion (const agg::rect_i &r, bool freemem=true ) :
72- rect (r), freemem(freemem) {
73- width = r.x2 - r.x1 ;
74- height = r.y2 - r.y1 ;
75- stride = width * 4 ;
76- data = new agg::int8u[stride * height];
77- }
78- agg::int8u* data;
79- agg::rect_i rect;
80- int width;
81- int height;
82- int stride;
83-
84- bool freemem;
85-
86- // set the x and y corners of the rectangle
87- Py::Object set_x (const Py::Tuple &args);
88- Py::Object set_y (const Py::Tuple &args);
89-
90- Py::Object get_extents (const Py::Tuple &args);
91-
92- Py::Object to_string (const Py::Tuple &args);
93- Py::Object to_string_argb (const Py::Tuple &args);
94- static void init_type (void );
95-
96- virtual ~BufferRegion () {
97- if (freemem) {
98- delete [] data;
99- data = NULL ;
72+ BufferRegion (const agg::rect_i &r, bool freemem = true ) :
73+ rect (r), freemem(freemem)
74+ {
75+ width = r.x2 - r.x1 ;
76+ height = r.y2 - r.y1 ;
77+ stride = width * 4 ;
78+ data = new agg::int8u[stride * height];
10079 }
101- };
80+
81+ agg::int8u* data;
82+ agg::rect_i rect;
83+ int width;
84+ int height;
85+ int stride;
86+
87+ bool freemem;
88+
89+ // set the x and y corners of the rectangle
90+ Py::Object set_x (const Py::Tuple &args);
91+ Py::Object set_y (const Py::Tuple &args);
92+
93+ Py::Object get_extents (const Py::Tuple &args);
94+
95+ Py::Object to_string (const Py::Tuple &args);
96+ Py::Object to_string_argb (const Py::Tuple &args);
97+ static void init_type (void );
98+
99+ virtual ~BufferRegion ()
100+ {
101+ if (freemem)
102+ {
103+ delete [] data;
104+ data = NULL ;
105+ }
106+ };
102107};
103108
104- class GCAgg {
109+ class GCAgg
110+ {
105111public:
106- GCAgg (const Py::Object& gc, double dpi);
112+ GCAgg (const Py::Object& gc, double dpi);
107113
108- double dpi;
109- bool isaa;
114+ double dpi;
115+ bool isaa;
110116
111- agg::line_cap_e cap;
112- agg::line_join_e join;
117+ agg::line_cap_e cap;
118+ agg::line_join_e join;
113119
114- double linewidth;
115- double alpha;
116- agg::rgba color;
120+ double linewidth;
121+ double alpha;
122+ agg::rgba color;
117123
118- Py::Object cliprect;
119- Py::Object clippath;
120- agg::trans_affine clippath_trans;
124+ Py::Object cliprect;
125+ Py::Object clippath;
126+ agg::trans_affine clippath_trans;
121127
122- // dashes
123- typedef std::vector<std::pair<double , double > > dash_t ;
124- double dashOffset;
125- dash_t dashes;
126- e_snap_mode snap_mode;
128+ // dashes
129+ typedef std::vector<std::pair<double , double > > dash_t ;
130+ double dashOffset;
131+ dash_t dashes;
132+ e_snap_mode snap_mode;
127133
128- Py::Object hatchpath;
134+ Py::Object hatchpath;
129135
130136protected:
131- agg::rgba get_color (const Py::Object& gc);
132- double points_to_pixels ( const Py::Object& points);
133- void _set_linecap (const Py::Object& gc) ;
134- void _set_joinstyle (const Py::Object& gc) ;
135- void _set_dashes (const Py::Object& gc) ;
136- void _set_clip_rectangle ( const Py::Object& gc);
137- void _set_clip_path ( const Py::Object& gc);
138- void _set_antialiased ( const Py::Object& gc);
139- void _set_snap ( const Py::Object& gc);
140- void _set_hatch_path ( const Py::Object& gc);
137+ agg::rgba get_color (const Py::Object& gc);
138+ double points_to_pixels (const Py::Object& points);
139+ void _set_linecap (const Py::Object& gc) ;
140+ void _set_joinstyle (const Py::Object& gc) ;
141+ void _set_dashes (const Py::Object& gc) ;
142+ void _set_clip_rectangle (const Py::Object& gc);
143+ void _set_clip_path (const Py::Object& gc);
144+ void _set_antialiased (const Py::Object& gc);
145+ void _set_snap (const Py::Object& gc);
146+ void _set_hatch_path (const Py::Object& gc);
141147};
142148
143149
@@ -146,87 +152,100 @@ class GCAgg {
146152// }
147153
148154// the renderer
149- class RendererAgg : public Py ::PythonExtension<RendererAgg> {
150- typedef std::pair<bool , agg::rgba> facepair_t ;
155+ class RendererAgg : public Py ::PythonExtension<RendererAgg>
156+ {
157+ typedef std::pair<bool , agg::rgba> facepair_t ;
151158public:
152- RendererAgg (unsigned int width, unsigned int height, double dpi, int debug);
153- static void init_type (void );
154-
155- unsigned int get_width () { return width;}
156- unsigned int get_height () { return height;}
157- // the drawing methods
158- // Py::Object _draw_markers_nocache(const Py::Tuple & args);
159- // Py::Object _draw_markers_cache(const Py::Tuple & args);
160- Py::Object draw_markers (const Py::Tuple & args);
161- Py::Object draw_text_image (const Py::Tuple & args);
162- Py::Object draw_image (const Py::Tuple & args);
163- Py::Object draw_path (const Py::Tuple & args);
164- Py::Object draw_path_collection (const Py::Tuple & args);
165- Py::Object draw_quad_mesh (const Py::Tuple& args);
166- Py::Object draw_gouraud_triangle (const Py::Tuple& args);
167- Py::Object draw_gouraud_triangles (const Py::Tuple& args);
168-
169- Py::Object write_rgba (const Py::Tuple & args);
170- Py::Object tostring_rgb (const Py::Tuple & args);
171- Py::Object tostring_argb (const Py::Tuple & args);
172- Py::Object tostring_bgra (const Py::Tuple & args);
173- Py::Object tostring_rgba_minimized (const Py::Tuple & args);
174- Py::Object buffer_rgba (const Py::Tuple & args);
175- Py::Object clear (const Py::Tuple & args);
176-
177- Py::Object copy_from_bbox (const Py::Tuple & args);
178- Py::Object restore_region (const Py::Tuple & args);
179- Py::Object restore_region2 (const Py::Tuple & args);
180-
181- virtual ~RendererAgg ();
182-
183- static const size_t PIXELS_PER_INCH;
184- unsigned int width, height;
185- double dpi;
186- size_t NUMBYTES; // the number of bytes in buffer
187-
188- agg::int8u *pixBuffer;
189- agg::rendering_buffer renderingBuffer;
190-
191- agg::int8u *alphaBuffer;
192- agg::rendering_buffer alphaMaskRenderingBuffer;
193- alpha_mask_type alphaMask;
194- agg::pixfmt_gray8 pixfmtAlphaMask;
195- renderer_base_alpha_mask_type rendererBaseAlphaMask;
196- renderer_alpha_mask_type rendererAlphaMask;
197- agg::scanline_p8 scanlineAlphaMask;
198-
199- scanline_p8 slineP8;
200- scanline_bin slineBin;
201- pixfmt pixFmt;
202- renderer_base rendererBase;
203- renderer_aa rendererAA;
204- renderer_bin rendererBin;
205- rasterizer theRasterizer;
206-
207- Py::Object lastclippath;
208- agg::trans_affine lastclippath_transform;
209-
210- static const size_t HATCH_SIZE = 72 ;
211- agg::int8u hatchBuffer[HATCH_SIZE * HATCH_SIZE * 4 ];
212- agg::rendering_buffer hatchRenderingBuffer;
213-
214- const int debug;
159+ RendererAgg (unsigned int width, unsigned int height, double dpi, int debug);
160+ static void init_type (void );
161+
162+ unsigned int get_width ()
163+ {
164+ return width;
165+ }
166+
167+ unsigned int get_height ()
168+ {
169+ return height;
170+ }
171+
172+ // the drawing methods
173+ // Py::Object _draw_markers_nocache(const Py::Tuple & args);
174+ // Py::Object _draw_markers_cache(const Py::Tuple & args);
175+ Py::Object draw_markers (const Py::Tuple & args);
176+ Py::Object draw_text_image (const Py::Tuple & args);
177+ Py::Object draw_image (const Py::Tuple & args);
178+ Py::Object draw_path (const Py::Tuple & args);
179+ Py::Object draw_path_collection (const Py::Tuple & args);
180+ Py::Object draw_quad_mesh (const Py::Tuple& args);
181+ Py::Object draw_gouraud_triangle (const Py::Tuple& args);
182+ Py::Object draw_gouraud_triangles (const Py::Tuple& args);
183+
184+ Py::Object write_rgba (const Py::Tuple & args);
185+ Py::Object tostring_rgb (const Py::Tuple & args);
186+ Py::Object tostring_argb (const Py::Tuple & args);
187+ Py::Object tostring_bgra (const Py::Tuple & args);
188+ Py::Object tostring_rgba_minimized (const Py::Tuple & args);
189+ Py::Object buffer_rgba (const Py::Tuple & args);
190+ Py::Object clear (const Py::Tuple & args);
191+
192+ Py::Object copy_from_bbox (const Py::Tuple & args);
193+ Py::Object restore_region (const Py::Tuple & args);
194+ Py::Object restore_region2 (const Py::Tuple & args);
195+
196+ virtual ~RendererAgg ();
197+
198+ static const size_t PIXELS_PER_INCH;
199+ unsigned int width, height;
200+ double dpi;
201+ size_t NUMBYTES; // the number of bytes in buffer
202+
203+ agg::int8u *pixBuffer;
204+ agg::rendering_buffer renderingBuffer;
205+
206+ agg::int8u *alphaBuffer;
207+ agg::rendering_buffer alphaMaskRenderingBuffer;
208+ alpha_mask_type alphaMask;
209+ agg::pixfmt_gray8 pixfmtAlphaMask;
210+ renderer_base_alpha_mask_type rendererBaseAlphaMask;
211+ renderer_alpha_mask_type rendererAlphaMask;
212+ agg::scanline_p8 scanlineAlphaMask;
213+
214+ scanline_p8 slineP8;
215+ scanline_bin slineBin;
216+ pixfmt pixFmt;
217+ renderer_base rendererBase;
218+ renderer_aa rendererAA;
219+ renderer_bin rendererBin;
220+ rasterizer theRasterizer;
221+
222+ Py::Object lastclippath;
223+ agg::trans_affine lastclippath_transform;
224+
225+ static const size_t HATCH_SIZE = 72 ;
226+ agg::int8u hatchBuffer[HATCH_SIZE * HATCH_SIZE * 4 ];
227+ agg::rendering_buffer hatchRenderingBuffer;
228+
229+ const int debug;
215230
216231protected:
217- double points_to_pixels ( const Py::Object& points);
218- double points_to_pixels_snapto ( const Py::Object& points);
219- agg::rgba rgb_to_color (const Py::SeqBase<Py::Object>& rgb, double alpha);
220- facepair_t _get_rgba_face (const Py::Object& rgbFace, double alpha);
221- template <class R >
222- void set_clipbox (const Py::Object& cliprect, R& rasterizer);
223- bool render_clippath (const Py::Object& clippath, const agg::trans_affine& clippath_trans);
224- template <class PathIteratorType >
225- void _draw_path (PathIteratorType& path, bool has_clippath,
226- const facepair_t & face, const GCAgg& gc);
227- template <class PathGenerator , int check_snap, int has_curves>
228- Py::Object
229- _draw_path_collection_generic
232+ double points_to_pixels (const Py::Object& points);
233+ double points_to_pixels_snapto (const Py::Object& points);
234+ agg::rgba rgb_to_color (const Py::SeqBase<Py::Object>& rgb, double alpha);
235+ facepair_t _get_rgba_face (const Py::Object& rgbFace, double alpha);
236+
237+ template <class R >
238+ void set_clipbox (const Py::Object& cliprect, R& rasterizer);
239+
240+ bool render_clippath (const Py::Object& clippath, const agg::trans_affine& clippath_trans);
241+
242+ template <class PathIteratorType >
243+ void _draw_path (PathIteratorType& path, bool has_clippath,
244+ const facepair_t & face, const GCAgg& gc);
245+
246+ template <class PathGenerator , int check_snap, int has_curves>
247+ Py::Object
248+ _draw_path_collection_generic
230249 (GCAgg& gc,
231250 agg::trans_affine master_transform,
232251 const Py::Object& cliprect,
@@ -242,35 +261,35 @@ class RendererAgg: public Py::PythonExtension<RendererAgg> {
242261 const Py::SeqBase<Py::Object>& linestyles_obj,
243262 const Py::SeqBase<Py::Int>& antialiaseds);
244263
245- void
246- _draw_gouraud_triangle (
247- const GCAgg& gc,
248- const double * points, const double * colors, agg::trans_affine trans);
264+ void
265+ _draw_gouraud_triangle (
266+ const GCAgg& gc,
267+ const double * points, const double * colors, agg::trans_affine trans);
249268
250269private:
251- void create_alpha_buffers ();
270+ void create_alpha_buffers ();
252271};
253272
254273// the extension module
255274class _backend_agg_module : public Py ::ExtensionModule<_backend_agg_module>
256275{
257276public:
258- _backend_agg_module ()
259- : Py::ExtensionModule<_backend_agg_module>( " _backend_agg" )
260- {
261- RendererAgg::init_type ();
262- BufferRegion::init_type ();
263-
264- add_keyword_method (" RendererAgg" , &_backend_agg_module::new_renderer,
265- " RendererAgg(width, height, dpi)" );
266- initialize ( " The agg rendering backend" );
267- }
277+ _backend_agg_module ()
278+ : Py::ExtensionModule<_backend_agg_module>(" _backend_agg" )
279+ {
280+ RendererAgg::init_type ();
281+ BufferRegion::init_type ();
282+
283+ add_keyword_method (" RendererAgg" , &_backend_agg_module::new_renderer,
284+ " RendererAgg(width, height, dpi)" );
285+ initialize (" The agg rendering backend" );
286+ }
268287
269- virtual ~_backend_agg_module () {}
288+ virtual ~_backend_agg_module () {}
270289
271290private:
272291
273- Py::Object new_renderer (const Py::Tuple &args, const Py::Dict &kws);
292+ Py::Object new_renderer (const Py::Tuple &args, const Py::Dict &kws);
274293};
275294
276295
0 commit comments