hc99 commited on
Commit
f9eec05
·
verified ·
1 Parent(s): ca271ed

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_basics.h +560 -0
  2. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_image_accessors.h +481 -0
  3. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_image_filters.h +448 -0
  4. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_pixfmt_gray.h +737 -0
  5. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_pixfmt_rgb.h +994 -0
  6. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_pixfmt_rgba.h +0 -0
  7. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_rasterizer_cells_aa.h +743 -0
  8. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_scanline_boolean_algebra.h +1567 -0
  9. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_span_gouraud_gray.h +241 -0
  10. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_span_gradient_image.h +188 -0
  11. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_span_image_filter.h +246 -0
  12. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_span_image_filter_gray.h +723 -0
  13. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_span_interpolator_linear.h +232 -0
  14. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_span_pattern_rgb.h +96 -0
  15. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_span_solid.h +53 -0
  16. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_span_subdiv_adaptor.h +141 -0
  17. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_trans_affine.h +518 -0
  18. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_trans_double_path.h +131 -0
  19. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_trans_perspective.h +731 -0
  20. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_trans_single_path.h +97 -0
  21. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_trans_viewport.h +303 -0
  22. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_trans_warp_magnifier.h +56 -0
  23. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_vcgen_bspline.h +74 -0
  24. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_vcgen_contour.h +94 -0
  25. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_vcgen_dash.h +93 -0
  26. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_vcgen_markers_term.h +66 -0
  27. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_vcgen_smooth_poly1.h +87 -0
  28. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_vcgen_stroke.h +102 -0
  29. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_vcgen_vertex_sequence.h +135 -0
  30. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_vertex_sequence.h +172 -0
  31. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_vpgen_clip_polygon.h +83 -0
  32. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_vpgen_clip_polyline.h +78 -0
  33. testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_vpgen_segmentator.h +61 -0
  34. testbed/matplotlib__matplotlib/extern/agg24-svn/src/ChangeLog +0 -0
  35. testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_arc.cpp +106 -0
  36. testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_arrowhead.cpp +110 -0
  37. testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_bezier_arc.cpp +258 -0
  38. testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_bspline.cpp +284 -0
  39. testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_color_rgba.cpp +17 -0
  40. testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_curves.cpp +613 -0
  41. testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_embedded_raster_fonts.cpp +0 -0
  42. testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_gsv_text.cpp +675 -0
  43. testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_image_filters.cpp +103 -0
  44. testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_line_aa_basics.cpp +82 -0
  45. testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_line_profile_aa.cpp +116 -0
  46. testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_rounded_rect.cpp +164 -0
  47. testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_sqrt_tables.cpp +115 -0
  48. testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_trans_affine.cpp +194 -0
  49. testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_trans_double_path.cpp +273 -0
  50. testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_trans_single_path.cpp +202 -0
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_basics.h ADDED
@@ -0,0 +1,560 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+
16
+ #ifndef AGG_BASICS_INCLUDED
17
+ #define AGG_BASICS_INCLUDED
18
+
19
+ #include <math.h>
20
+ #include "agg_config.h"
21
+
22
+ //---------------------------------------------------------AGG_CUSTOM_ALLOCATOR
23
+ #ifdef AGG_CUSTOM_ALLOCATOR
24
+ #include "agg_allocator.h"
25
+ #else
26
+ namespace agg
27
+ {
28
+ // The policy of all AGG containers and memory allocation strategy
29
+ // in general is that no allocated data requires explicit construction.
30
+ // It means that the allocator can be really simple; you can even
31
+ // replace new/delete to malloc/free. The constructors and destructors
32
+ // won't be called in this case, however everything will remain working.
33
+ // The second argument of deallocate() is the size of the allocated
34
+ // block. You can use this information if you wish.
35
+ //------------------------------------------------------------pod_allocator
36
+ template<class T> struct pod_allocator
37
+ {
38
+ static T* allocate(unsigned num) { return new T [num]; }
39
+ static void deallocate(T* ptr, unsigned) { delete [] ptr; }
40
+ };
41
+
42
+ // Single object allocator. It's also can be replaced with your custom
43
+ // allocator. The difference is that it can only allocate a single
44
+ // object and the constructor and destructor must be called.
45
+ // In AGG there is no need to allocate an array of objects with
46
+ // calling their constructors (only single ones). So that, if you
47
+ // replace these new/delete to malloc/free make sure that the in-place
48
+ // new is called and take care of calling the destructor too.
49
+ //------------------------------------------------------------obj_allocator
50
+ template<class T> struct obj_allocator
51
+ {
52
+ static T* allocate() { return new T; }
53
+ static void deallocate(T* ptr) { delete ptr; }
54
+ };
55
+ }
56
+ #endif
57
+
58
+
59
+ //-------------------------------------------------------- Default basic types
60
+ //
61
+ // If the compiler has different capacity of the basic types you can redefine
62
+ // them via the compiler command line or by generating agg_config.h that is
63
+ // empty by default.
64
+ //
65
+ #ifndef AGG_INT8
66
+ #define AGG_INT8 signed char
67
+ #endif
68
+
69
+ #ifndef AGG_INT8U
70
+ #define AGG_INT8U unsigned char
71
+ #endif
72
+
73
+ #ifndef AGG_INT16
74
+ #define AGG_INT16 short
75
+ #endif
76
+
77
+ #ifndef AGG_INT16U
78
+ #define AGG_INT16U unsigned short
79
+ #endif
80
+
81
+ #ifndef AGG_INT32
82
+ #define AGG_INT32 int
83
+ #endif
84
+
85
+ #ifndef AGG_INT32U
86
+ #define AGG_INT32U unsigned
87
+ #endif
88
+
89
+ #ifndef AGG_INT64
90
+ #if defined(_MSC_VER) || defined(__BORLANDC__)
91
+ #define AGG_INT64 signed __int64
92
+ #else
93
+ #define AGG_INT64 signed long long
94
+ #endif
95
+ #endif
96
+
97
+ #ifndef AGG_INT64U
98
+ #if defined(_MSC_VER) || defined(__BORLANDC__)
99
+ #define AGG_INT64U unsigned __int64
100
+ #else
101
+ #define AGG_INT64U unsigned long long
102
+ #endif
103
+ #endif
104
+
105
+ //------------------------------------------------ Some fixes for MS Visual C++
106
+ #if defined(_MSC_VER)
107
+ #pragma warning(disable:4786) // Identifier was truncated...
108
+ #endif
109
+
110
+ #if defined(_MSC_VER)
111
+ #define AGG_INLINE __forceinline
112
+ #else
113
+ #define AGG_INLINE inline
114
+ #endif
115
+
116
+ namespace agg
117
+ {
118
+ //-------------------------------------------------------------------------
119
+ typedef AGG_INT8 int8; //----int8
120
+ typedef AGG_INT8U int8u; //----int8u
121
+ typedef AGG_INT16 int16; //----int16
122
+ typedef AGG_INT16U int16u; //----int16u
123
+ typedef AGG_INT32 int32; //----int32
124
+ typedef AGG_INT32U int32u; //----int32u
125
+ typedef AGG_INT64 int64; //----int64
126
+ typedef AGG_INT64U int64u; //----int64u
127
+
128
+ #if defined(AGG_FISTP)
129
+ #pragma warning(push)
130
+ #pragma warning(disable : 4035) //Disable warning "no return value"
131
+ AGG_INLINE int iround(double v) //-------iround
132
+ {
133
+ int t;
134
+ __asm fld qword ptr [v]
135
+ __asm fistp dword ptr [t]
136
+ __asm mov eax, dword ptr [t]
137
+ }
138
+ AGG_INLINE unsigned uround(double v) //-------uround
139
+ {
140
+ unsigned t;
141
+ __asm fld qword ptr [v]
142
+ __asm fistp dword ptr [t]
143
+ __asm mov eax, dword ptr [t]
144
+ }
145
+ #pragma warning(pop)
146
+ AGG_INLINE int ifloor(double v)
147
+ {
148
+ return int(floor(v));
149
+ }
150
+ AGG_INLINE unsigned ufloor(double v) //-------ufloor
151
+ {
152
+ return unsigned(floor(v));
153
+ }
154
+ AGG_INLINE int iceil(double v)
155
+ {
156
+ return int(ceil(v));
157
+ }
158
+ AGG_INLINE unsigned uceil(double v) //--------uceil
159
+ {
160
+ return unsigned(ceil(v));
161
+ }
162
+ #elif defined(AGG_QIFIST)
163
+ AGG_INLINE int iround(double v)
164
+ {
165
+ return int(v);
166
+ }
167
+ AGG_INLINE int uround(double v)
168
+ {
169
+ return unsigned(v);
170
+ }
171
+ AGG_INLINE int ifloor(double v)
172
+ {
173
+ return int(floor(v));
174
+ }
175
+ AGG_INLINE unsigned ufloor(double v)
176
+ {
177
+ return unsigned(floor(v));
178
+ }
179
+ AGG_INLINE int iceil(double v)
180
+ {
181
+ return int(ceil(v));
182
+ }
183
+ AGG_INLINE unsigned uceil(double v)
184
+ {
185
+ return unsigned(ceil(v));
186
+ }
187
+ #else
188
+ AGG_INLINE int iround(double v)
189
+ {
190
+ return int((v < 0.0) ? v - 0.5 : v + 0.5);
191
+ }
192
+ AGG_INLINE int uround(double v)
193
+ {
194
+ return unsigned(v + 0.5);
195
+ }
196
+ AGG_INLINE int ifloor(double v)
197
+ {
198
+ int i = int(v);
199
+ return i - (i > v);
200
+ }
201
+ AGG_INLINE unsigned ufloor(double v)
202
+ {
203
+ return unsigned(v);
204
+ }
205
+ AGG_INLINE int iceil(double v)
206
+ {
207
+ return int(ceil(v));
208
+ }
209
+ AGG_INLINE unsigned uceil(double v)
210
+ {
211
+ return unsigned(ceil(v));
212
+ }
213
+ #endif
214
+
215
+ //---------------------------------------------------------------saturation
216
+ template<int Limit> struct saturation
217
+ {
218
+ AGG_INLINE static int iround(double v)
219
+ {
220
+ if(v < double(-Limit)) return -Limit;
221
+ if(v > double( Limit)) return Limit;
222
+ return agg::iround(v);
223
+ }
224
+ };
225
+
226
+ //------------------------------------------------------------------mul_one
227
+ template<unsigned Shift> struct mul_one
228
+ {
229
+ AGG_INLINE static unsigned mul(unsigned a, unsigned b)
230
+ {
231
+ unsigned q = a * b + (1 << (Shift-1));
232
+ return (q + (q >> Shift)) >> Shift;
233
+ }
234
+ };
235
+
236
+ //-------------------------------------------------------------------------
237
+ typedef unsigned char cover_type; //----cover_type
238
+ enum cover_scale_e
239
+ {
240
+ cover_shift = 8, //----cover_shift
241
+ cover_size = 1 << cover_shift, //----cover_size
242
+ cover_mask = cover_size - 1, //----cover_mask
243
+ cover_none = 0, //----cover_none
244
+ cover_full = cover_mask //----cover_full
245
+ };
246
+
247
+ //----------------------------------------------------poly_subpixel_scale_e
248
+ // These constants determine the subpixel accuracy, to be more precise,
249
+ // the number of bits of the fractional part of the coordinates.
250
+ // The possible coordinate capacity in bits can be calculated by formula:
251
+ // sizeof(int) * 8 - poly_subpixel_shift, i.e, for 32-bit integers and
252
+ // 8-bits fractional part the capacity is 24 bits.
253
+ enum poly_subpixel_scale_e
254
+ {
255
+ poly_subpixel_shift = 8, //----poly_subpixel_shift
256
+ poly_subpixel_scale = 1<<poly_subpixel_shift, //----poly_subpixel_scale
257
+ poly_subpixel_mask = poly_subpixel_scale-1 //----poly_subpixel_mask
258
+ };
259
+
260
+ //----------------------------------------------------------filling_rule_e
261
+ enum filling_rule_e
262
+ {
263
+ fill_non_zero,
264
+ fill_even_odd
265
+ };
266
+
267
+ //-----------------------------------------------------------------------pi
268
+ const double pi = 3.14159265358979323846;
269
+
270
+ //------------------------------------------------------------------deg2rad
271
+ inline double deg2rad(double deg)
272
+ {
273
+ return deg * pi / 180.0;
274
+ }
275
+
276
+ //------------------------------------------------------------------rad2deg
277
+ inline double rad2deg(double rad)
278
+ {
279
+ return rad * 180.0 / pi;
280
+ }
281
+
282
+ //----------------------------------------------------------------rect_base
283
+ template<class T> struct rect_base
284
+ {
285
+ typedef T value_type;
286
+ typedef rect_base<T> self_type;
287
+ T x1, y1, x2, y2;
288
+
289
+ rect_base() {}
290
+ rect_base(T x1_, T y1_, T x2_, T y2_) :
291
+ x1(x1_), y1(y1_), x2(x2_), y2(y2_) {}
292
+
293
+ void init(T x1_, T y1_, T x2_, T y2_)
294
+ {
295
+ x1 = x1_; y1 = y1_; x2 = x2_; y2 = y2_;
296
+ }
297
+
298
+ const self_type& normalize()
299
+ {
300
+ T t;
301
+ if(x1 > x2) { t = x1; x1 = x2; x2 = t; }
302
+ if(y1 > y2) { t = y1; y1 = y2; y2 = t; }
303
+ return *this;
304
+ }
305
+
306
+ bool clip(const self_type& r)
307
+ {
308
+ if(x2 > r.x2) x2 = r.x2;
309
+ if(y2 > r.y2) y2 = r.y2;
310
+ if(x1 < r.x1) x1 = r.x1;
311
+ if(y1 < r.y1) y1 = r.y1;
312
+ return x1 <= x2 && y1 <= y2;
313
+ }
314
+
315
+ bool is_valid() const
316
+ {
317
+ return x1 <= x2 && y1 <= y2;
318
+ }
319
+
320
+ bool hit_test(T x, T y) const
321
+ {
322
+ return (x >= x1 && x <= x2 && y >= y1 && y <= y2);
323
+ }
324
+
325
+ bool overlaps(const self_type& r) const
326
+ {
327
+ return !(r.x1 > x2 || r.x2 < x1
328
+ || r.y1 > y2 || r.y2 < y1);
329
+ }
330
+ };
331
+
332
+ //-----------------------------------------------------intersect_rectangles
333
+ template<class Rect>
334
+ inline Rect intersect_rectangles(const Rect& r1, const Rect& r2)
335
+ {
336
+ Rect r = r1;
337
+
338
+ // First process x2,y2 because the other order
339
+ // results in Internal Compiler Error under
340
+ // Microsoft Visual C++ .NET 2003 69462-335-0000007-18038 in
341
+ // case of "Maximize Speed" optimization option.
342
+ //-----------------
343
+ if(r.x2 > r2.x2) r.x2 = r2.x2;
344
+ if(r.y2 > r2.y2) r.y2 = r2.y2;
345
+ if(r.x1 < r2.x1) r.x1 = r2.x1;
346
+ if(r.y1 < r2.y1) r.y1 = r2.y1;
347
+ return r;
348
+ }
349
+
350
+
351
+ //---------------------------------------------------------unite_rectangles
352
+ template<class Rect>
353
+ inline Rect unite_rectangles(const Rect& r1, const Rect& r2)
354
+ {
355
+ Rect r = r1;
356
+ if(r.x2 < r2.x2) r.x2 = r2.x2;
357
+ if(r.y2 < r2.y2) r.y2 = r2.y2;
358
+ if(r.x1 > r2.x1) r.x1 = r2.x1;
359
+ if(r.y1 > r2.y1) r.y1 = r2.y1;
360
+ return r;
361
+ }
362
+
363
+ typedef rect_base<int> rect_i; //----rect_i
364
+ typedef rect_base<float> rect_f; //----rect_f
365
+ typedef rect_base<double> rect_d; //----rect_d
366
+
367
+ //---------------------------------------------------------path_commands_e
368
+ enum path_commands_e
369
+ {
370
+ path_cmd_stop = 0, //----path_cmd_stop
371
+ path_cmd_move_to = 1, //----path_cmd_move_to
372
+ path_cmd_line_to = 2, //----path_cmd_line_to
373
+ path_cmd_curve3 = 3, //----path_cmd_curve3
374
+ path_cmd_curve4 = 4, //----path_cmd_curve4
375
+ path_cmd_curveN = 5, //----path_cmd_curveN
376
+ path_cmd_catrom = 6, //----path_cmd_catrom
377
+ path_cmd_ubspline = 7, //----path_cmd_ubspline
378
+ path_cmd_end_poly = 0x0F, //----path_cmd_end_poly
379
+ path_cmd_mask = 0x0F //----path_cmd_mask
380
+ };
381
+
382
+ //------------------------------------------------------------path_flags_e
383
+ enum path_flags_e
384
+ {
385
+ path_flags_none = 0, //----path_flags_none
386
+ path_flags_ccw = 0x10, //----path_flags_ccw
387
+ path_flags_cw = 0x20, //----path_flags_cw
388
+ path_flags_close = 0x40, //----path_flags_close
389
+ path_flags_mask = 0xF0 //----path_flags_mask
390
+ };
391
+
392
+ //---------------------------------------------------------------is_vertex
393
+ inline bool is_vertex(unsigned c)
394
+ {
395
+ return c >= path_cmd_move_to && c < path_cmd_end_poly;
396
+ }
397
+
398
+ //--------------------------------------------------------------is_drawing
399
+ inline bool is_drawing(unsigned c)
400
+ {
401
+ return c >= path_cmd_line_to && c < path_cmd_end_poly;
402
+ }
403
+
404
+ //-----------------------------------------------------------------is_stop
405
+ inline bool is_stop(unsigned c)
406
+ {
407
+ return c == path_cmd_stop;
408
+ }
409
+
410
+ //--------------------------------------------------------------is_move_to
411
+ inline bool is_move_to(unsigned c)
412
+ {
413
+ return c == path_cmd_move_to;
414
+ }
415
+
416
+ //--------------------------------------------------------------is_line_to
417
+ inline bool is_line_to(unsigned c)
418
+ {
419
+ return c == path_cmd_line_to;
420
+ }
421
+
422
+ //----------------------------------------------------------------is_curve
423
+ inline bool is_curve(unsigned c)
424
+ {
425
+ return c == path_cmd_curve3 || c == path_cmd_curve4;
426
+ }
427
+
428
+ //---------------------------------------------------------------is_curve3
429
+ inline bool is_curve3(unsigned c)
430
+ {
431
+ return c == path_cmd_curve3;
432
+ }
433
+
434
+ //---------------------------------------------------------------is_curve4
435
+ inline bool is_curve4(unsigned c)
436
+ {
437
+ return c == path_cmd_curve4;
438
+ }
439
+
440
+ //-------------------------------------------------------------is_end_poly
441
+ inline bool is_end_poly(unsigned c)
442
+ {
443
+ return (c & path_cmd_mask) == path_cmd_end_poly;
444
+ }
445
+
446
+ //----------------------------------------------------------------is_close
447
+ inline bool is_close(unsigned c)
448
+ {
449
+ return (c & ~(path_flags_cw | path_flags_ccw)) ==
450
+ (path_cmd_end_poly | path_flags_close);
451
+ }
452
+
453
+ //------------------------------------------------------------is_next_poly
454
+ inline bool is_next_poly(unsigned c)
455
+ {
456
+ return is_stop(c) || is_move_to(c) || is_end_poly(c);
457
+ }
458
+
459
+ //-------------------------------------------------------------------is_cw
460
+ inline bool is_cw(unsigned c)
461
+ {
462
+ return (c & path_flags_cw) != 0;
463
+ }
464
+
465
+ //------------------------------------------------------------------is_ccw
466
+ inline bool is_ccw(unsigned c)
467
+ {
468
+ return (c & path_flags_ccw) != 0;
469
+ }
470
+
471
+ //-------------------------------------------------------------is_oriented
472
+ inline bool is_oriented(unsigned c)
473
+ {
474
+ return (c & (path_flags_cw | path_flags_ccw)) != 0;
475
+ }
476
+
477
+ //---------------------------------------------------------------is_closed
478
+ inline bool is_closed(unsigned c)
479
+ {
480
+ return (c & path_flags_close) != 0;
481
+ }
482
+
483
+ //----------------------------------------------------------get_close_flag
484
+ inline unsigned get_close_flag(unsigned c)
485
+ {
486
+ return c & path_flags_close;
487
+ }
488
+
489
+ //-------------------------------------------------------clear_orientation
490
+ inline unsigned clear_orientation(unsigned c)
491
+ {
492
+ return c & ~(path_flags_cw | path_flags_ccw);
493
+ }
494
+
495
+ //---------------------------------------------------------get_orientation
496
+ inline unsigned get_orientation(unsigned c)
497
+ {
498
+ return c & (path_flags_cw | path_flags_ccw);
499
+ }
500
+
501
+ //---------------------------------------------------------set_orientation
502
+ inline unsigned set_orientation(unsigned c, unsigned o)
503
+ {
504
+ return clear_orientation(c) | o;
505
+ }
506
+
507
+ //--------------------------------------------------------------point_base
508
+ template<class T> struct point_base
509
+ {
510
+ typedef T value_type;
511
+ T x,y;
512
+ point_base() {}
513
+ point_base(T x_, T y_) : x(x_), y(y_) {}
514
+ };
515
+ typedef point_base<int> point_i; //-----point_i
516
+ typedef point_base<float> point_f; //-----point_f
517
+ typedef point_base<double> point_d; //-----point_d
518
+
519
+ //-------------------------------------------------------------vertex_base
520
+ template<class T> struct vertex_base
521
+ {
522
+ typedef T value_type;
523
+ T x,y;
524
+ unsigned cmd;
525
+ vertex_base() {}
526
+ vertex_base(T x_, T y_, unsigned cmd_) : x(x_), y(y_), cmd(cmd_) {}
527
+ };
528
+ typedef vertex_base<int> vertex_i; //-----vertex_i
529
+ typedef vertex_base<float> vertex_f; //-----vertex_f
530
+ typedef vertex_base<double> vertex_d; //-----vertex_d
531
+
532
+ //----------------------------------------------------------------row_info
533
+ template<class T> struct row_info
534
+ {
535
+ int x1, x2;
536
+ T* ptr;
537
+ row_info() {}
538
+ row_info(int x1_, int x2_, T* ptr_) : x1(x1_), x2(x2_), ptr(ptr_) {}
539
+ };
540
+
541
+ //----------------------------------------------------------const_row_info
542
+ template<class T> struct const_row_info
543
+ {
544
+ int x1, x2;
545
+ const T* ptr;
546
+ const_row_info() {}
547
+ const_row_info(int x1_, int x2_, const T* ptr_) :
548
+ x1(x1_), x2(x2_), ptr(ptr_) {}
549
+ };
550
+
551
+ //------------------------------------------------------------is_equal_eps
552
+ template<class T> inline bool is_equal_eps(T v1, T v2, T epsilon)
553
+ {
554
+ return fabs(v1 - v2) <= double(epsilon);
555
+ }
556
+ }
557
+
558
+
559
+ #endif
560
+
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_image_accessors.h ADDED
@@ -0,0 +1,481 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+
16
+ #ifndef AGG_IMAGE_ACCESSORS_INCLUDED
17
+ #define AGG_IMAGE_ACCESSORS_INCLUDED
18
+
19
+ #include "agg_basics.h"
20
+
21
+ namespace agg
22
+ {
23
+
24
+ //-----------------------------------------------------image_accessor_clip
25
+ template<class PixFmt> class image_accessor_clip
26
+ {
27
+ public:
28
+ typedef PixFmt pixfmt_type;
29
+ typedef typename pixfmt_type::color_type color_type;
30
+ typedef typename pixfmt_type::order_type order_type;
31
+ typedef typename pixfmt_type::value_type value_type;
32
+ enum pix_width_e { pix_width = pixfmt_type::pix_width };
33
+
34
+ image_accessor_clip() {}
35
+ explicit image_accessor_clip(pixfmt_type& pixf,
36
+ const color_type& bk) :
37
+ m_pixf(&pixf)
38
+ {
39
+ pixfmt_type::make_pix(m_bk_buf, bk);
40
+ }
41
+
42
+ void attach(pixfmt_type& pixf)
43
+ {
44
+ m_pixf = &pixf;
45
+ }
46
+
47
+ void background_color(const color_type& bk)
48
+ {
49
+ pixfmt_type::make_pix(m_bk_buf, bk);
50
+ }
51
+
52
+ private:
53
+ AGG_INLINE const int8u* pixel() const
54
+ {
55
+ if(m_y >= 0 && m_y < (int)m_pixf->height() &&
56
+ m_x >= 0 && m_x < (int)m_pixf->width())
57
+ {
58
+ return m_pixf->pix_ptr(m_x, m_y);
59
+ }
60
+ return m_bk_buf;
61
+ }
62
+
63
+ public:
64
+ AGG_INLINE const int8u* span(int x, int y, unsigned len)
65
+ {
66
+ m_x = m_x0 = x;
67
+ m_y = y;
68
+ if(y >= 0 && y < (int)m_pixf->height() &&
69
+ x >= 0 && x+(int)len <= (int)m_pixf->width())
70
+ {
71
+ return m_pix_ptr = m_pixf->pix_ptr(x, y);
72
+ }
73
+ m_pix_ptr = 0;
74
+ return pixel();
75
+ }
76
+
77
+ AGG_INLINE const int8u* next_x()
78
+ {
79
+ if(m_pix_ptr) return m_pix_ptr += pix_width;
80
+ ++m_x;
81
+ return pixel();
82
+ }
83
+
84
+ AGG_INLINE const int8u* next_y()
85
+ {
86
+ ++m_y;
87
+ m_x = m_x0;
88
+ if(m_pix_ptr &&
89
+ m_y >= 0 && m_y < (int)m_pixf->height())
90
+ {
91
+ return m_pix_ptr = m_pixf->pix_ptr(m_x, m_y);
92
+ }
93
+ m_pix_ptr = 0;
94
+ return pixel();
95
+ }
96
+
97
+ private:
98
+ const pixfmt_type* m_pixf;
99
+ int8u m_bk_buf[pix_width];
100
+ int m_x, m_x0, m_y;
101
+ const int8u* m_pix_ptr;
102
+ };
103
+
104
+
105
+
106
+
107
+ //--------------------------------------------------image_accessor_no_clip
108
+ template<class PixFmt> class image_accessor_no_clip
109
+ {
110
+ public:
111
+ typedef PixFmt pixfmt_type;
112
+ typedef typename pixfmt_type::color_type color_type;
113
+ typedef typename pixfmt_type::order_type order_type;
114
+ typedef typename pixfmt_type::value_type value_type;
115
+ enum pix_width_e { pix_width = pixfmt_type::pix_width };
116
+
117
+ image_accessor_no_clip() {}
118
+ explicit image_accessor_no_clip(pixfmt_type& pixf) :
119
+ m_pixf(&pixf)
120
+ {}
121
+
122
+ void attach(pixfmt_type& pixf)
123
+ {
124
+ m_pixf = &pixf;
125
+ }
126
+
127
+ AGG_INLINE const int8u* span(int x, int y, unsigned)
128
+ {
129
+ m_x = x;
130
+ m_y = y;
131
+ return m_pix_ptr = m_pixf->pix_ptr(x, y);
132
+ }
133
+
134
+ AGG_INLINE const int8u* next_x()
135
+ {
136
+ return m_pix_ptr += pix_width;
137
+ }
138
+
139
+ AGG_INLINE const int8u* next_y()
140
+ {
141
+ ++m_y;
142
+ return m_pix_ptr = m_pixf->pix_ptr(m_x, m_y);
143
+ }
144
+
145
+ private:
146
+ const pixfmt_type* m_pixf;
147
+ int m_x, m_y;
148
+ const int8u* m_pix_ptr;
149
+ };
150
+
151
+
152
+
153
+
154
+ //----------------------------------------------------image_accessor_clone
155
+ template<class PixFmt> class image_accessor_clone
156
+ {
157
+ public:
158
+ typedef PixFmt pixfmt_type;
159
+ typedef typename pixfmt_type::color_type color_type;
160
+ typedef typename pixfmt_type::order_type order_type;
161
+ typedef typename pixfmt_type::value_type value_type;
162
+ enum pix_width_e { pix_width = pixfmt_type::pix_width };
163
+
164
+ image_accessor_clone() {}
165
+ explicit image_accessor_clone(pixfmt_type& pixf) :
166
+ m_pixf(&pixf)
167
+ {}
168
+
169
+ void attach(pixfmt_type& pixf)
170
+ {
171
+ m_pixf = &pixf;
172
+ }
173
+
174
+ private:
175
+ AGG_INLINE const int8u* pixel() const
176
+ {
177
+ int x = m_x;
178
+ int y = m_y;
179
+ if(x < 0) x = 0;
180
+ if(y < 0) y = 0;
181
+ if(x >= (int)m_pixf->width()) x = m_pixf->width() - 1;
182
+ if(y >= (int)m_pixf->height()) y = m_pixf->height() - 1;
183
+ return m_pixf->pix_ptr(x, y);
184
+ }
185
+
186
+ public:
187
+ AGG_INLINE const int8u* span(int x, int y, unsigned len)
188
+ {
189
+ m_x = m_x0 = x;
190
+ m_y = y;
191
+ if(y >= 0 && y < (int)m_pixf->height() &&
192
+ x >= 0 && x+len <= (int)m_pixf->width())
193
+ {
194
+ return m_pix_ptr = m_pixf->pix_ptr(x, y);
195
+ }
196
+ m_pix_ptr = 0;
197
+ return pixel();
198
+ }
199
+
200
+ AGG_INLINE const int8u* next_x()
201
+ {
202
+ if(m_pix_ptr) return m_pix_ptr += pix_width;
203
+ ++m_x;
204
+ return pixel();
205
+ }
206
+
207
+ AGG_INLINE const int8u* next_y()
208
+ {
209
+ ++m_y;
210
+ m_x = m_x0;
211
+ if(m_pix_ptr &&
212
+ m_y >= 0 && m_y < (int)m_pixf->height())
213
+ {
214
+ return m_pix_ptr = m_pixf->pix_ptr(m_x, m_y);
215
+ }
216
+ m_pix_ptr = 0;
217
+ return pixel();
218
+ }
219
+
220
+ private:
221
+ const pixfmt_type* m_pixf;
222
+ int m_x, m_x0, m_y;
223
+ const int8u* m_pix_ptr;
224
+ };
225
+
226
+
227
+
228
+
229
+
230
+ //-----------------------------------------------------image_accessor_wrap
231
+ template<class PixFmt, class WrapX, class WrapY> class image_accessor_wrap
232
+ {
233
+ public:
234
+ typedef PixFmt pixfmt_type;
235
+ typedef typename pixfmt_type::color_type color_type;
236
+ typedef typename pixfmt_type::order_type order_type;
237
+ typedef typename pixfmt_type::value_type value_type;
238
+ enum pix_width_e { pix_width = pixfmt_type::pix_width };
239
+
240
+ image_accessor_wrap() {}
241
+ explicit image_accessor_wrap(pixfmt_type& pixf) :
242
+ m_pixf(&pixf),
243
+ m_wrap_x(pixf.width()),
244
+ m_wrap_y(pixf.height())
245
+ {}
246
+
247
+ void attach(pixfmt_type& pixf)
248
+ {
249
+ m_pixf = &pixf;
250
+ }
251
+
252
+ AGG_INLINE const int8u* span(int x, int y, unsigned)
253
+ {
254
+ m_x = x;
255
+ m_row_ptr = m_pixf->pix_ptr(0, m_wrap_y(y));
256
+ return m_row_ptr + m_wrap_x(x) * pix_width;
257
+ }
258
+
259
+ AGG_INLINE const int8u* next_x()
260
+ {
261
+ int x = ++m_wrap_x;
262
+ return m_row_ptr + x * pix_width;
263
+ }
264
+
265
+ AGG_INLINE const int8u* next_y()
266
+ {
267
+ m_row_ptr = m_pixf->pix_ptr(0, ++m_wrap_y);
268
+ return m_row_ptr + m_wrap_x(m_x) * pix_width;
269
+ }
270
+
271
+ private:
272
+ const pixfmt_type* m_pixf;
273
+ const int8u* m_row_ptr;
274
+ int m_x;
275
+ WrapX m_wrap_x;
276
+ WrapY m_wrap_y;
277
+ };
278
+
279
+
280
+
281
+
282
+ //--------------------------------------------------------wrap_mode_repeat
283
+ class wrap_mode_repeat
284
+ {
285
+ public:
286
+ wrap_mode_repeat() {}
287
+ wrap_mode_repeat(unsigned size) :
288
+ m_size(size),
289
+ m_add(size * (0x3FFFFFFF / size)),
290
+ m_value(0)
291
+ {}
292
+
293
+ AGG_INLINE unsigned operator() (int v)
294
+ {
295
+ return m_value = (unsigned(v) + m_add) % m_size;
296
+ }
297
+
298
+ AGG_INLINE unsigned operator++ ()
299
+ {
300
+ ++m_value;
301
+ if(m_value >= m_size) m_value = 0;
302
+ return m_value;
303
+ }
304
+ private:
305
+ unsigned m_size;
306
+ unsigned m_add;
307
+ unsigned m_value;
308
+ };
309
+
310
+
311
+ //---------------------------------------------------wrap_mode_repeat_pow2
312
+ class wrap_mode_repeat_pow2
313
+ {
314
+ public:
315
+ wrap_mode_repeat_pow2() {}
316
+ wrap_mode_repeat_pow2(unsigned size) : m_value(0)
317
+ {
318
+ m_mask = 1;
319
+ while(m_mask < size) m_mask = (m_mask << 1) | 1;
320
+ m_mask >>= 1;
321
+ }
322
+ AGG_INLINE unsigned operator() (int v)
323
+ {
324
+ return m_value = unsigned(v) & m_mask;
325
+ }
326
+ AGG_INLINE unsigned operator++ ()
327
+ {
328
+ ++m_value;
329
+ if(m_value > m_mask) m_value = 0;
330
+ return m_value;
331
+ }
332
+ private:
333
+ unsigned m_mask;
334
+ unsigned m_value;
335
+ };
336
+
337
+
338
+ //----------------------------------------------wrap_mode_repeat_auto_pow2
339
+ class wrap_mode_repeat_auto_pow2
340
+ {
341
+ public:
342
+ wrap_mode_repeat_auto_pow2() {}
343
+ wrap_mode_repeat_auto_pow2(unsigned size) :
344
+ m_size(size),
345
+ m_add(size * (0x3FFFFFFF / size)),
346
+ m_mask((m_size & (m_size-1)) ? 0 : m_size-1),
347
+ m_value(0)
348
+ {}
349
+
350
+ AGG_INLINE unsigned operator() (int v)
351
+ {
352
+ if(m_mask) return m_value = unsigned(v) & m_mask;
353
+ return m_value = (unsigned(v) + m_add) % m_size;
354
+ }
355
+ AGG_INLINE unsigned operator++ ()
356
+ {
357
+ ++m_value;
358
+ if(m_value >= m_size) m_value = 0;
359
+ return m_value;
360
+ }
361
+
362
+ private:
363
+ unsigned m_size;
364
+ unsigned m_add;
365
+ unsigned m_mask;
366
+ unsigned m_value;
367
+ };
368
+
369
+
370
+ //-------------------------------------------------------wrap_mode_reflect
371
+ class wrap_mode_reflect
372
+ {
373
+ public:
374
+ wrap_mode_reflect() {}
375
+ wrap_mode_reflect(unsigned size) :
376
+ m_size(size),
377
+ m_size2(size * 2),
378
+ m_add(m_size2 * (0x3FFFFFFF / m_size2)),
379
+ m_value(0)
380
+ {}
381
+
382
+ AGG_INLINE unsigned operator() (int v)
383
+ {
384
+ m_value = (unsigned(v) + m_add) % m_size2;
385
+ if(m_value >= m_size) return m_size2 - m_value - 1;
386
+ return m_value;
387
+ }
388
+
389
+ AGG_INLINE unsigned operator++ ()
390
+ {
391
+ ++m_value;
392
+ if(m_value >= m_size2) m_value = 0;
393
+ if(m_value >= m_size) return m_size2 - m_value - 1;
394
+ return m_value;
395
+ }
396
+ private:
397
+ unsigned m_size;
398
+ unsigned m_size2;
399
+ unsigned m_add;
400
+ unsigned m_value;
401
+ };
402
+
403
+
404
+
405
+ //--------------------------------------------------wrap_mode_reflect_pow2
406
+ class wrap_mode_reflect_pow2
407
+ {
408
+ public:
409
+ wrap_mode_reflect_pow2() {}
410
+ wrap_mode_reflect_pow2(unsigned size) : m_value(0)
411
+ {
412
+ m_mask = 1;
413
+ m_size = 1;
414
+ while(m_mask < size)
415
+ {
416
+ m_mask = (m_mask << 1) | 1;
417
+ m_size <<= 1;
418
+ }
419
+ }
420
+ AGG_INLINE unsigned operator() (int v)
421
+ {
422
+ m_value = unsigned(v) & m_mask;
423
+ if(m_value >= m_size) return m_mask - m_value;
424
+ return m_value;
425
+ }
426
+ AGG_INLINE unsigned operator++ ()
427
+ {
428
+ ++m_value;
429
+ m_value &= m_mask;
430
+ if(m_value >= m_size) return m_mask - m_value;
431
+ return m_value;
432
+ }
433
+ private:
434
+ unsigned m_size;
435
+ unsigned m_mask;
436
+ unsigned m_value;
437
+ };
438
+
439
+
440
+
441
+ //---------------------------------------------wrap_mode_reflect_auto_pow2
442
+ class wrap_mode_reflect_auto_pow2
443
+ {
444
+ public:
445
+ wrap_mode_reflect_auto_pow2() {}
446
+ wrap_mode_reflect_auto_pow2(unsigned size) :
447
+ m_size(size),
448
+ m_size2(size * 2),
449
+ m_add(m_size2 * (0x3FFFFFFF / m_size2)),
450
+ m_mask((m_size2 & (m_size2-1)) ? 0 : m_size2-1),
451
+ m_value(0)
452
+ {}
453
+
454
+ AGG_INLINE unsigned operator() (int v)
455
+ {
456
+ m_value = m_mask ? unsigned(v) & m_mask :
457
+ (unsigned(v) + m_add) % m_size2;
458
+ if(m_value >= m_size) return m_size2 - m_value - 1;
459
+ return m_value;
460
+ }
461
+ AGG_INLINE unsigned operator++ ()
462
+ {
463
+ ++m_value;
464
+ if(m_value >= m_size2) m_value = 0;
465
+ if(m_value >= m_size) return m_size2 - m_value - 1;
466
+ return m_value;
467
+ }
468
+
469
+ private:
470
+ unsigned m_size;
471
+ unsigned m_size2;
472
+ unsigned m_add;
473
+ unsigned m_mask;
474
+ unsigned m_value;
475
+ };
476
+
477
+
478
+ }
479
+
480
+
481
+ #endif
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_image_filters.h ADDED
@@ -0,0 +1,448 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+ //
16
+ // Image transformation filters,
17
+ // Filtering classes (image_filter_lut, image_filter),
18
+ // Basic filter shape classes
19
+ //----------------------------------------------------------------------------
20
+ #ifndef AGG_IMAGE_FILTERS_INCLUDED
21
+ #define AGG_IMAGE_FILTERS_INCLUDED
22
+
23
+ #include "agg_array.h"
24
+ #include "agg_math.h"
25
+
26
+ namespace agg
27
+ {
28
+
29
+ // See Implementation agg_image_filters.cpp
30
+
31
+ enum image_filter_scale_e
32
+ {
33
+ image_filter_shift = 14, //----image_filter_shift
34
+ image_filter_scale = 1 << image_filter_shift, //----image_filter_scale
35
+ image_filter_mask = image_filter_scale - 1 //----image_filter_mask
36
+ };
37
+
38
+ enum image_subpixel_scale_e
39
+ {
40
+ image_subpixel_shift = 8, //----image_subpixel_shift
41
+ image_subpixel_scale = 1 << image_subpixel_shift, //----image_subpixel_scale
42
+ image_subpixel_mask = image_subpixel_scale - 1 //----image_subpixel_mask
43
+ };
44
+
45
+
46
+ //-----------------------------------------------------image_filter_lut
47
+ class image_filter_lut
48
+ {
49
+ public:
50
+ template<class FilterF> void calculate(const FilterF& filter,
51
+ bool normalization=true)
52
+ {
53
+ double r = filter.radius();
54
+ realloc_lut(r);
55
+ unsigned i;
56
+ unsigned pivot = diameter() << (image_subpixel_shift - 1);
57
+ for(i = 0; i < pivot; i++)
58
+ {
59
+ double x = double(i) / double(image_subpixel_scale);
60
+ double y = filter.calc_weight(x);
61
+ m_weight_array[pivot + i] =
62
+ m_weight_array[pivot - i] = (int16)iround(y * image_filter_scale);
63
+ }
64
+ unsigned end = (diameter() << image_subpixel_shift) - 1;
65
+ m_weight_array[0] = m_weight_array[end];
66
+ if(normalization)
67
+ {
68
+ normalize();
69
+ }
70
+ }
71
+
72
+ image_filter_lut() : m_radius(0), m_diameter(0), m_start(0) {}
73
+
74
+ template<class FilterF> image_filter_lut(const FilterF& filter,
75
+ bool normalization=true)
76
+ {
77
+ calculate(filter, normalization);
78
+ }
79
+
80
+ double radius() const { return m_radius; }
81
+ unsigned diameter() const { return m_diameter; }
82
+ int start() const { return m_start; }
83
+ const int16* weight_array() const { return &m_weight_array[0]; }
84
+ void normalize();
85
+
86
+ private:
87
+ void realloc_lut(double radius);
88
+ image_filter_lut(const image_filter_lut&);
89
+ const image_filter_lut& operator = (const image_filter_lut&);
90
+
91
+ double m_radius;
92
+ unsigned m_diameter;
93
+ int m_start;
94
+ pod_array<int16> m_weight_array;
95
+ };
96
+
97
+
98
+
99
+ //--------------------------------------------------------image_filter
100
+ template<class FilterF> class image_filter : public image_filter_lut
101
+ {
102
+ public:
103
+ image_filter()
104
+ {
105
+ calculate(m_filter_function);
106
+ }
107
+ private:
108
+ FilterF m_filter_function;
109
+ };
110
+
111
+
112
+ //-----------------------------------------------image_filter_bilinear
113
+ struct image_filter_bilinear
114
+ {
115
+ static double radius() { return 1.0; }
116
+ static double calc_weight(double x)
117
+ {
118
+ return 1.0 - x;
119
+ }
120
+ };
121
+
122
+
123
+ //-----------------------------------------------image_filter_hanning
124
+ struct image_filter_hanning
125
+ {
126
+ static double radius() { return 1.0; }
127
+ static double calc_weight(double x)
128
+ {
129
+ return 0.5 + 0.5 * cos(pi * x);
130
+ }
131
+ };
132
+
133
+
134
+ //-----------------------------------------------image_filter_hamming
135
+ struct image_filter_hamming
136
+ {
137
+ static double radius() { return 1.0; }
138
+ static double calc_weight(double x)
139
+ {
140
+ return 0.54 + 0.46 * cos(pi * x);
141
+ }
142
+ };
143
+
144
+ //-----------------------------------------------image_filter_hermite
145
+ struct image_filter_hermite
146
+ {
147
+ static double radius() { return 1.0; }
148
+ static double calc_weight(double x)
149
+ {
150
+ return (2.0 * x - 3.0) * x * x + 1.0;
151
+ }
152
+ };
153
+
154
+ //------------------------------------------------image_filter_quadric
155
+ struct image_filter_quadric
156
+ {
157
+ static double radius() { return 1.5; }
158
+ static double calc_weight(double x)
159
+ {
160
+ double t;
161
+ if(x < 0.5) return 0.75 - x * x;
162
+ if(x < 1.5) {t = x - 1.5; return 0.5 * t * t;}
163
+ return 0.0;
164
+ }
165
+ };
166
+
167
+ //------------------------------------------------image_filter_bicubic
168
+ class image_filter_bicubic
169
+ {
170
+ static double pow3(double x)
171
+ {
172
+ return (x <= 0.0) ? 0.0 : x * x * x;
173
+ }
174
+
175
+ public:
176
+ static double radius() { return 2.0; }
177
+ static double calc_weight(double x)
178
+ {
179
+ return
180
+ (1.0/6.0) *
181
+ (pow3(x + 2) - 4 * pow3(x + 1) + 6 * pow3(x) - 4 * pow3(x - 1));
182
+ }
183
+ };
184
+
185
+ //-------------------------------------------------image_filter_kaiser
186
+ class image_filter_kaiser
187
+ {
188
+ double a;
189
+ double i0a;
190
+ double epsilon;
191
+
192
+ public:
193
+ image_filter_kaiser(double b = 6.33) :
194
+ a(b), epsilon(1e-12)
195
+ {
196
+ i0a = 1.0 / bessel_i0(b);
197
+ }
198
+
199
+ static double radius() { return 1.0; }
200
+ double calc_weight(double x) const
201
+ {
202
+ return bessel_i0(a * sqrt(1. - x * x)) * i0a;
203
+ }
204
+
205
+ private:
206
+ double bessel_i0(double x) const
207
+ {
208
+ int i;
209
+ double sum, y, t;
210
+
211
+ sum = 1.;
212
+ y = x * x / 4.;
213
+ t = y;
214
+
215
+ for(i = 2; t > epsilon; i++)
216
+ {
217
+ sum += t;
218
+ t *= (double)y / (i * i);
219
+ }
220
+ return sum;
221
+ }
222
+ };
223
+
224
+ //----------------------------------------------image_filter_catrom
225
+ struct image_filter_catrom
226
+ {
227
+ static double radius() { return 2.0; }
228
+ static double calc_weight(double x)
229
+ {
230
+ if(x < 1.0) return 0.5 * (2.0 + x * x * (-5.0 + x * 3.0));
231
+ if(x < 2.0) return 0.5 * (4.0 + x * (-8.0 + x * (5.0 - x)));
232
+ return 0.;
233
+ }
234
+ };
235
+
236
+ //---------------------------------------------image_filter_mitchell
237
+ class image_filter_mitchell
238
+ {
239
+ double p0, p2, p3;
240
+ double q0, q1, q2, q3;
241
+
242
+ public:
243
+ image_filter_mitchell(double b = 1.0/3.0, double c = 1.0/3.0) :
244
+ p0((6.0 - 2.0 * b) / 6.0),
245
+ p2((-18.0 + 12.0 * b + 6.0 * c) / 6.0),
246
+ p3((12.0 - 9.0 * b - 6.0 * c) / 6.0),
247
+ q0((8.0 * b + 24.0 * c) / 6.0),
248
+ q1((-12.0 * b - 48.0 * c) / 6.0),
249
+ q2((6.0 * b + 30.0 * c) / 6.0),
250
+ q3((-b - 6.0 * c) / 6.0)
251
+ {}
252
+
253
+ static double radius() { return 2.0; }
254
+ double calc_weight(double x) const
255
+ {
256
+ if(x < 1.0) return p0 + x * x * (p2 + x * p3);
257
+ if(x < 2.0) return q0 + x * (q1 + x * (q2 + x * q3));
258
+ return 0.0;
259
+ }
260
+ };
261
+
262
+
263
+ //----------------------------------------------image_filter_spline16
264
+ struct image_filter_spline16
265
+ {
266
+ static double radius() { return 2.0; }
267
+ static double calc_weight(double x)
268
+ {
269
+ if(x < 1.0)
270
+ {
271
+ return ((x - 9.0/5.0 ) * x - 1.0/5.0 ) * x + 1.0;
272
+ }
273
+ return ((-1.0/3.0 * (x-1) + 4.0/5.0) * (x-1) - 7.0/15.0 ) * (x-1);
274
+ }
275
+ };
276
+
277
+
278
+ //---------------------------------------------image_filter_spline36
279
+ struct image_filter_spline36
280
+ {
281
+ static double radius() { return 3.0; }
282
+ static double calc_weight(double x)
283
+ {
284
+ if(x < 1.0)
285
+ {
286
+ return ((13.0/11.0 * x - 453.0/209.0) * x - 3.0/209.0) * x + 1.0;
287
+ }
288
+ if(x < 2.0)
289
+ {
290
+ return ((-6.0/11.0 * (x-1) + 270.0/209.0) * (x-1) - 156.0/ 209.0) * (x-1);
291
+ }
292
+ return ((1.0/11.0 * (x-2) - 45.0/209.0) * (x-2) + 26.0/209.0) * (x-2);
293
+ }
294
+ };
295
+
296
+
297
+ //----------------------------------------------image_filter_gaussian
298
+ struct image_filter_gaussian
299
+ {
300
+ static double radius() { return 2.0; }
301
+ static double calc_weight(double x)
302
+ {
303
+ return exp(-2.0 * x * x) * sqrt(2.0 / pi);
304
+ }
305
+ };
306
+
307
+
308
+ //------------------------------------------------image_filter_bessel
309
+ struct image_filter_bessel
310
+ {
311
+ static double radius() { return 3.2383; }
312
+ static double calc_weight(double x)
313
+ {
314
+ return (x == 0.0) ? pi / 4.0 : besj(pi * x, 1) / (2.0 * x);
315
+ }
316
+ };
317
+
318
+
319
+ //-------------------------------------------------image_filter_sinc
320
+ class image_filter_sinc
321
+ {
322
+ public:
323
+ image_filter_sinc(double r) : m_radius(r < 2.0 ? 2.0 : r) {}
324
+ double radius() const { return m_radius; }
325
+ double calc_weight(double x) const
326
+ {
327
+ if(x == 0.0) return 1.0;
328
+ x *= pi;
329
+ return sin(x) / x;
330
+ }
331
+ private:
332
+ double m_radius;
333
+ };
334
+
335
+
336
+ //-----------------------------------------------image_filter_lanczos
337
+ class image_filter_lanczos
338
+ {
339
+ public:
340
+ image_filter_lanczos(double r) : m_radius(r < 2.0 ? 2.0 : r) {}
341
+ double radius() const { return m_radius; }
342
+ double calc_weight(double x) const
343
+ {
344
+ if(x == 0.0) return 1.0;
345
+ if(x > m_radius) return 0.0;
346
+ x *= pi;
347
+ double xr = x / m_radius;
348
+ return (sin(x) / x) * (sin(xr) / xr);
349
+ }
350
+ private:
351
+ double m_radius;
352
+ };
353
+
354
+
355
+ //----------------------------------------------image_filter_blackman
356
+ class image_filter_blackman
357
+ {
358
+ public:
359
+ image_filter_blackman(double r) : m_radius(r < 2.0 ? 2.0 : r) {}
360
+ double radius() const { return m_radius; }
361
+ double calc_weight(double x) const
362
+ {
363
+ if(x == 0.0) return 1.0;
364
+ if(x > m_radius) return 0.0;
365
+ x *= pi;
366
+ double xr = x / m_radius;
367
+ return (sin(x) / x) * (0.42 + 0.5*cos(xr) + 0.08*cos(2*xr));
368
+ }
369
+ private:
370
+ double m_radius;
371
+ };
372
+
373
+ //------------------------------------------------image_filter_sinc36
374
+ class image_filter_sinc36 : public image_filter_sinc
375
+ { public: image_filter_sinc36() : image_filter_sinc(3.0){} };
376
+
377
+ //------------------------------------------------image_filter_sinc64
378
+ class image_filter_sinc64 : public image_filter_sinc
379
+ { public: image_filter_sinc64() : image_filter_sinc(4.0){} };
380
+
381
+ //-----------------------------------------------image_filter_sinc100
382
+ class image_filter_sinc100 : public image_filter_sinc
383
+ { public: image_filter_sinc100() : image_filter_sinc(5.0){} };
384
+
385
+ //-----------------------------------------------image_filter_sinc144
386
+ class image_filter_sinc144 : public image_filter_sinc
387
+ { public: image_filter_sinc144() : image_filter_sinc(6.0){} };
388
+
389
+ //-----------------------------------------------image_filter_sinc196
390
+ class image_filter_sinc196 : public image_filter_sinc
391
+ { public: image_filter_sinc196() : image_filter_sinc(7.0){} };
392
+
393
+ //-----------------------------------------------image_filter_sinc256
394
+ class image_filter_sinc256 : public image_filter_sinc
395
+ { public: image_filter_sinc256() : image_filter_sinc(8.0){} };
396
+
397
+ //---------------------------------------------image_filter_lanczos36
398
+ class image_filter_lanczos36 : public image_filter_lanczos
399
+ { public: image_filter_lanczos36() : image_filter_lanczos(3.0){} };
400
+
401
+ //---------------------------------------------image_filter_lanczos64
402
+ class image_filter_lanczos64 : public image_filter_lanczos
403
+ { public: image_filter_lanczos64() : image_filter_lanczos(4.0){} };
404
+
405
+ //--------------------------------------------image_filter_lanczos100
406
+ class image_filter_lanczos100 : public image_filter_lanczos
407
+ { public: image_filter_lanczos100() : image_filter_lanczos(5.0){} };
408
+
409
+ //--------------------------------------------image_filter_lanczos144
410
+ class image_filter_lanczos144 : public image_filter_lanczos
411
+ { public: image_filter_lanczos144() : image_filter_lanczos(6.0){} };
412
+
413
+ //--------------------------------------------image_filter_lanczos196
414
+ class image_filter_lanczos196 : public image_filter_lanczos
415
+ { public: image_filter_lanczos196() : image_filter_lanczos(7.0){} };
416
+
417
+ //--------------------------------------------image_filter_lanczos256
418
+ class image_filter_lanczos256 : public image_filter_lanczos
419
+ { public: image_filter_lanczos256() : image_filter_lanczos(8.0){} };
420
+
421
+ //--------------------------------------------image_filter_blackman36
422
+ class image_filter_blackman36 : public image_filter_blackman
423
+ { public: image_filter_blackman36() : image_filter_blackman(3.0){} };
424
+
425
+ //--------------------------------------------image_filter_blackman64
426
+ class image_filter_blackman64 : public image_filter_blackman
427
+ { public: image_filter_blackman64() : image_filter_blackman(4.0){} };
428
+
429
+ //-------------------------------------------image_filter_blackman100
430
+ class image_filter_blackman100 : public image_filter_blackman
431
+ { public: image_filter_blackman100() : image_filter_blackman(5.0){} };
432
+
433
+ //-------------------------------------------image_filter_blackman144
434
+ class image_filter_blackman144 : public image_filter_blackman
435
+ { public: image_filter_blackman144() : image_filter_blackman(6.0){} };
436
+
437
+ //-------------------------------------------image_filter_blackman196
438
+ class image_filter_blackman196 : public image_filter_blackman
439
+ { public: image_filter_blackman196() : image_filter_blackman(7.0){} };
440
+
441
+ //-------------------------------------------image_filter_blackman256
442
+ class image_filter_blackman256 : public image_filter_blackman
443
+ { public: image_filter_blackman256() : image_filter_blackman(8.0){} };
444
+
445
+
446
+ }
447
+
448
+ #endif
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_pixfmt_gray.h ADDED
@@ -0,0 +1,737 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+ //
16
+ // Adaptation for high precision colors has been sponsored by
17
+ // Liberty Technology Systems, Inc., visit http://lib-sys.com
18
+ //
19
+ // Liberty Technology Systems, Inc. is the provider of
20
+ // PostScript and PDF technology for software developers.
21
+ //
22
+ //----------------------------------------------------------------------------
23
+
24
+ #ifndef AGG_PIXFMT_GRAY_INCLUDED
25
+ #define AGG_PIXFMT_GRAY_INCLUDED
26
+
27
+ #include <string.h>
28
+ #include "agg_pixfmt_base.h"
29
+ #include "agg_rendering_buffer.h"
30
+
31
+ namespace agg
32
+ {
33
+
34
+ //============================================================blender_gray
35
+ template<class ColorT> struct blender_gray
36
+ {
37
+ typedef ColorT color_type;
38
+ typedef typename color_type::value_type value_type;
39
+ typedef typename color_type::calc_type calc_type;
40
+ typedef typename color_type::long_type long_type;
41
+
42
+ // Blend pixels using the non-premultiplied form of Alvy-Ray Smith's
43
+ // compositing function. Since the render buffer is opaque we skip the
44
+ // initial premultiply and final demultiply.
45
+
46
+ static AGG_INLINE void blend_pix(value_type* p,
47
+ value_type cv, value_type alpha, cover_type cover)
48
+ {
49
+ blend_pix(p, cv, color_type::mult_cover(alpha, cover));
50
+ }
51
+
52
+ static AGG_INLINE void blend_pix(value_type* p,
53
+ value_type cv, value_type alpha)
54
+ {
55
+ *p = color_type::lerp(*p, cv, alpha);
56
+ }
57
+ };
58
+
59
+
60
+ //======================================================blender_gray_pre
61
+ template<class ColorT> struct blender_gray_pre
62
+ {
63
+ typedef ColorT color_type;
64
+ typedef typename color_type::value_type value_type;
65
+ typedef typename color_type::calc_type calc_type;
66
+ typedef typename color_type::long_type long_type;
67
+
68
+ // Blend pixels using the premultiplied form of Alvy-Ray Smith's
69
+ // compositing function.
70
+
71
+ static AGG_INLINE void blend_pix(value_type* p,
72
+ value_type cv, value_type alpha, cover_type cover)
73
+ {
74
+ blend_pix(p, color_type::mult_cover(cv, cover), color_type::mult_cover(alpha, cover));
75
+ }
76
+
77
+ static AGG_INLINE void blend_pix(value_type* p,
78
+ value_type cv, value_type alpha)
79
+ {
80
+ *p = color_type::prelerp(*p, cv, alpha);
81
+ }
82
+ };
83
+
84
+
85
+
86
+ //=====================================================apply_gamma_dir_gray
87
+ template<class ColorT, class GammaLut> class apply_gamma_dir_gray
88
+ {
89
+ public:
90
+ typedef typename ColorT::value_type value_type;
91
+
92
+ apply_gamma_dir_gray(const GammaLut& gamma) : m_gamma(gamma) {}
93
+
94
+ AGG_INLINE void operator () (value_type* p)
95
+ {
96
+ *p = m_gamma.dir(*p);
97
+ }
98
+
99
+ private:
100
+ const GammaLut& m_gamma;
101
+ };
102
+
103
+
104
+
105
+ //=====================================================apply_gamma_inv_gray
106
+ template<class ColorT, class GammaLut> class apply_gamma_inv_gray
107
+ {
108
+ public:
109
+ typedef typename ColorT::value_type value_type;
110
+
111
+ apply_gamma_inv_gray(const GammaLut& gamma) : m_gamma(gamma) {}
112
+
113
+ AGG_INLINE void operator () (value_type* p)
114
+ {
115
+ *p = m_gamma.inv(*p);
116
+ }
117
+
118
+ private:
119
+ const GammaLut& m_gamma;
120
+ };
121
+
122
+
123
+
124
+ //=================================================pixfmt_alpha_blend_gray
125
+ template<class Blender, class RenBuf, unsigned Step = 1, unsigned Offset = 0>
126
+ class pixfmt_alpha_blend_gray
127
+ {
128
+ public:
129
+ typedef pixfmt_gray_tag pixfmt_category;
130
+ typedef RenBuf rbuf_type;
131
+ typedef typename rbuf_type::row_data row_data;
132
+ typedef Blender blender_type;
133
+ typedef typename blender_type::color_type color_type;
134
+ typedef int order_type; // A fake one
135
+ typedef typename color_type::value_type value_type;
136
+ typedef typename color_type::calc_type calc_type;
137
+ enum
138
+ {
139
+ pix_width = sizeof(value_type) * Step,
140
+ pix_step = Step,
141
+ pix_offset = Offset,
142
+ };
143
+ struct pixel_type
144
+ {
145
+ value_type c[pix_step];
146
+
147
+ void set(value_type v)
148
+ {
149
+ c[0] = v;
150
+ }
151
+
152
+ void set(const color_type& color)
153
+ {
154
+ set(color.v);
155
+ }
156
+
157
+ void get(value_type& v) const
158
+ {
159
+ v = c[0];
160
+ }
161
+
162
+ color_type get() const
163
+ {
164
+ return color_type(c[0]);
165
+ }
166
+
167
+ pixel_type* next()
168
+ {
169
+ return this + 1;
170
+ }
171
+
172
+ const pixel_type* next() const
173
+ {
174
+ return this + 1;
175
+ }
176
+
177
+ pixel_type* advance(int n)
178
+ {
179
+ return this + n;
180
+ }
181
+
182
+ const pixel_type* advance(int n) const
183
+ {
184
+ return this + n;
185
+ }
186
+ };
187
+
188
+ private:
189
+ //--------------------------------------------------------------------
190
+ AGG_INLINE void blend_pix(pixel_type* p,
191
+ value_type v, value_type a,
192
+ unsigned cover)
193
+ {
194
+ blender_type::blend_pix(p->c, v, a, cover);
195
+ }
196
+
197
+ //--------------------------------------------------------------------
198
+ AGG_INLINE void blend_pix(pixel_type* p, value_type v, value_type a)
199
+ {
200
+ blender_type::blend_pix(p->c, v, a);
201
+ }
202
+
203
+ //--------------------------------------------------------------------
204
+ AGG_INLINE void blend_pix(pixel_type* p, const color_type& c, unsigned cover)
205
+ {
206
+ blender_type::blend_pix(p->c, c.v, c.a, cover);
207
+ }
208
+
209
+ //--------------------------------------------------------------------
210
+ AGG_INLINE void blend_pix(pixel_type* p, const color_type& c)
211
+ {
212
+ blender_type::blend_pix(p->c, c.v, c.a);
213
+ }
214
+
215
+ //--------------------------------------------------------------------
216
+ AGG_INLINE void copy_or_blend_pix(pixel_type* p, const color_type& c, unsigned cover)
217
+ {
218
+ if (!c.is_transparent())
219
+ {
220
+ if (c.is_opaque() && cover == cover_mask)
221
+ {
222
+ p->set(c);
223
+ }
224
+ else
225
+ {
226
+ blend_pix(p, c, cover);
227
+ }
228
+ }
229
+ }
230
+
231
+ //--------------------------------------------------------------------
232
+ AGG_INLINE void copy_or_blend_pix(pixel_type* p, const color_type& c)
233
+ {
234
+ if (!c.is_transparent())
235
+ {
236
+ if (c.is_opaque())
237
+ {
238
+ p->set(c);
239
+ }
240
+ else
241
+ {
242
+ blend_pix(p, c);
243
+ }
244
+ }
245
+ }
246
+
247
+ public:
248
+ //--------------------------------------------------------------------
249
+ explicit pixfmt_alpha_blend_gray(rbuf_type& rb) :
250
+ m_rbuf(&rb)
251
+ {}
252
+ void attach(rbuf_type& rb) { m_rbuf = &rb; }
253
+ //--------------------------------------------------------------------
254
+
255
+ template<class PixFmt>
256
+ bool attach(PixFmt& pixf, int x1, int y1, int x2, int y2)
257
+ {
258
+ rect_i r(x1, y1, x2, y2);
259
+ if (r.clip(rect_i(0, 0, pixf.width()-1, pixf.height()-1)))
260
+ {
261
+ int stride = pixf.stride();
262
+ m_rbuf->attach(pixf.pix_ptr(r.x1, stride < 0 ? r.y2 : r.y1),
263
+ (r.x2 - r.x1) + 1,
264
+ (r.y2 - r.y1) + 1,
265
+ stride);
266
+ return true;
267
+ }
268
+ return false;
269
+ }
270
+
271
+ //--------------------------------------------------------------------
272
+ AGG_INLINE unsigned width() const { return m_rbuf->width(); }
273
+ AGG_INLINE unsigned height() const { return m_rbuf->height(); }
274
+ AGG_INLINE int stride() const { return m_rbuf->stride(); }
275
+
276
+ //--------------------------------------------------------------------
277
+ int8u* row_ptr(int y) { return m_rbuf->row_ptr(y); }
278
+ const int8u* row_ptr(int y) const { return m_rbuf->row_ptr(y); }
279
+ row_data row(int y) const { return m_rbuf->row(y); }
280
+
281
+ //--------------------------------------------------------------------
282
+ AGG_INLINE int8u* pix_ptr(int x, int y)
283
+ {
284
+ return m_rbuf->row_ptr(y) + sizeof(value_type) * (x * pix_step + pix_offset);
285
+ }
286
+
287
+ AGG_INLINE const int8u* pix_ptr(int x, int y) const
288
+ {
289
+ return m_rbuf->row_ptr(y) + sizeof(value_type) * (x * pix_step + pix_offset);
290
+ }
291
+
292
+ // Return pointer to pixel value, forcing row to be allocated.
293
+ AGG_INLINE pixel_type* pix_value_ptr(int x, int y, unsigned len)
294
+ {
295
+ return (pixel_type*)(m_rbuf->row_ptr(x, y, len) + sizeof(value_type) * (x * pix_step + pix_offset));
296
+ }
297
+
298
+ // Return pointer to pixel value, or null if row not allocated.
299
+ AGG_INLINE const pixel_type* pix_value_ptr(int x, int y) const
300
+ {
301
+ int8u* p = m_rbuf->row_ptr(y);
302
+ return p ? (pixel_type*)(p + sizeof(value_type) * (x * pix_step + pix_offset)) : 0;
303
+ }
304
+
305
+ // Get pixel pointer from raw buffer pointer.
306
+ AGG_INLINE static pixel_type* pix_value_ptr(void* p)
307
+ {
308
+ return (pixel_type*)((value_type*)p + pix_offset);
309
+ }
310
+
311
+ // Get pixel pointer from raw buffer pointer.
312
+ AGG_INLINE static const pixel_type* pix_value_ptr(const void* p)
313
+ {
314
+ return (const pixel_type*)((const value_type*)p + pix_offset);
315
+ }
316
+
317
+ //--------------------------------------------------------------------
318
+ AGG_INLINE static void write_plain_color(void* p, color_type c)
319
+ {
320
+ // Grayscale formats are implicitly premultiplied.
321
+ c.premultiply();
322
+ pix_value_ptr(p)->set(c);
323
+ }
324
+
325
+ //--------------------------------------------------------------------
326
+ AGG_INLINE static color_type read_plain_color(const void* p)
327
+ {
328
+ return pix_value_ptr(p)->get();
329
+ }
330
+
331
+ //--------------------------------------------------------------------
332
+ AGG_INLINE static void make_pix(int8u* p, const color_type& c)
333
+ {
334
+ ((pixel_type*)p)->set(c);
335
+ }
336
+
337
+ //--------------------------------------------------------------------
338
+ AGG_INLINE color_type pixel(int x, int y) const
339
+ {
340
+ if (const pixel_type* p = pix_value_ptr(x, y))
341
+ {
342
+ return p->get();
343
+ }
344
+ return color_type::no_color();
345
+ }
346
+
347
+ //--------------------------------------------------------------------
348
+ AGG_INLINE void copy_pixel(int x, int y, const color_type& c)
349
+ {
350
+ pix_value_ptr(x, y, 1)->set(c);
351
+ }
352
+
353
+ //--------------------------------------------------------------------
354
+ AGG_INLINE void blend_pixel(int x, int y, const color_type& c, int8u cover)
355
+ {
356
+ copy_or_blend_pix(pix_value_ptr(x, y, 1), c, cover);
357
+ }
358
+
359
+ //--------------------------------------------------------------------
360
+ AGG_INLINE void copy_hline(int x, int y,
361
+ unsigned len,
362
+ const color_type& c)
363
+ {
364
+ pixel_type* p = pix_value_ptr(x, y, len);
365
+ do
366
+ {
367
+ p->set(c);
368
+ p = p->next();
369
+ }
370
+ while(--len);
371
+ }
372
+
373
+
374
+ //--------------------------------------------------------------------
375
+ AGG_INLINE void copy_vline(int x, int y,
376
+ unsigned len,
377
+ const color_type& c)
378
+ {
379
+ do
380
+ {
381
+ pix_value_ptr(x, y++, 1)->set(c);
382
+ }
383
+ while (--len);
384
+ }
385
+
386
+
387
+ //--------------------------------------------------------------------
388
+ void blend_hline(int x, int y,
389
+ unsigned len,
390
+ const color_type& c,
391
+ int8u cover)
392
+ {
393
+ if (!c.is_transparent())
394
+ {
395
+ pixel_type* p = pix_value_ptr(x, y, len);
396
+
397
+ if (c.is_opaque() && cover == cover_mask)
398
+ {
399
+ do
400
+ {
401
+ p->set(c);
402
+ p = p->next();
403
+ }
404
+ while (--len);
405
+ }
406
+ else
407
+ {
408
+ do
409
+ {
410
+ blend_pix(p, c, cover);
411
+ p = p->next();
412
+ }
413
+ while (--len);
414
+ }
415
+ }
416
+ }
417
+
418
+
419
+ //--------------------------------------------------------------------
420
+ void blend_vline(int x, int y,
421
+ unsigned len,
422
+ const color_type& c,
423
+ int8u cover)
424
+ {
425
+ if (!c.is_transparent())
426
+ {
427
+ if (c.is_opaque() && cover == cover_mask)
428
+ {
429
+ do
430
+ {
431
+ pix_value_ptr(x, y++, 1)->set(c);
432
+ }
433
+ while (--len);
434
+ }
435
+ else
436
+ {
437
+ do
438
+ {
439
+ blend_pix(pix_value_ptr(x, y++, 1), c, cover);
440
+ }
441
+ while (--len);
442
+ }
443
+ }
444
+ }
445
+
446
+
447
+ //--------------------------------------------------------------------
448
+ void blend_solid_hspan(int x, int y,
449
+ unsigned len,
450
+ const color_type& c,
451
+ const int8u* covers)
452
+ {
453
+ if (!c.is_transparent())
454
+ {
455
+ pixel_type* p = pix_value_ptr(x, y, len);
456
+
457
+ do
458
+ {
459
+ if (c.is_opaque() && *covers == cover_mask)
460
+ {
461
+ p->set(c);
462
+ }
463
+ else
464
+ {
465
+ blend_pix(p, c, *covers);
466
+ }
467
+ p = p->next();
468
+ ++covers;
469
+ }
470
+ while (--len);
471
+ }
472
+ }
473
+
474
+
475
+ //--------------------------------------------------------------------
476
+ void blend_solid_vspan(int x, int y,
477
+ unsigned len,
478
+ const color_type& c,
479
+ const int8u* covers)
480
+ {
481
+ if (!c.is_transparent())
482
+ {
483
+ do
484
+ {
485
+ pixel_type* p = pix_value_ptr(x, y++, 1);
486
+
487
+ if (c.is_opaque() && *covers == cover_mask)
488
+ {
489
+ p->set(c);
490
+ }
491
+ else
492
+ {
493
+ blend_pix(p, c, *covers);
494
+ }
495
+ ++covers;
496
+ }
497
+ while (--len);
498
+ }
499
+ }
500
+
501
+
502
+ //--------------------------------------------------------------------
503
+ void copy_color_hspan(int x, int y,
504
+ unsigned len,
505
+ const color_type* colors)
506
+ {
507
+ pixel_type* p = pix_value_ptr(x, y, len);
508
+
509
+ do
510
+ {
511
+ p->set(*colors++);
512
+ p = p->next();
513
+ }
514
+ while (--len);
515
+ }
516
+
517
+
518
+ //--------------------------------------------------------------------
519
+ void copy_color_vspan(int x, int y,
520
+ unsigned len,
521
+ const color_type* colors)
522
+ {
523
+ do
524
+ {
525
+ pix_value_ptr(x, y++, 1)->set(*colors++);
526
+ }
527
+ while (--len);
528
+ }
529
+
530
+
531
+ //--------------------------------------------------------------------
532
+ void blend_color_hspan(int x, int y,
533
+ unsigned len,
534
+ const color_type* colors,
535
+ const int8u* covers,
536
+ int8u cover)
537
+ {
538
+ pixel_type* p = pix_value_ptr(x, y, len);
539
+
540
+ if (covers)
541
+ {
542
+ do
543
+ {
544
+ copy_or_blend_pix(p, *colors++, *covers++);
545
+ p = p->next();
546
+ }
547
+ while (--len);
548
+ }
549
+ else
550
+ {
551
+ if (cover == cover_mask)
552
+ {
553
+ do
554
+ {
555
+ copy_or_blend_pix(p, *colors++);
556
+ p = p->next();
557
+ }
558
+ while (--len);
559
+ }
560
+ else
561
+ {
562
+ do
563
+ {
564
+ copy_or_blend_pix(p, *colors++, cover);
565
+ p = p->next();
566
+ }
567
+ while (--len);
568
+ }
569
+ }
570
+ }
571
+
572
+
573
+ //--------------------------------------------------------------------
574
+ void blend_color_vspan(int x, int y,
575
+ unsigned len,
576
+ const color_type* colors,
577
+ const int8u* covers,
578
+ int8u cover)
579
+ {
580
+ if (covers)
581
+ {
582
+ do
583
+ {
584
+ copy_or_blend_pix(pix_value_ptr(x, y++, 1), *colors++, *covers++);
585
+ }
586
+ while (--len);
587
+ }
588
+ else
589
+ {
590
+ if (cover == cover_mask)
591
+ {
592
+ do
593
+ {
594
+ copy_or_blend_pix(pix_value_ptr(x, y++, 1), *colors++);
595
+ }
596
+ while (--len);
597
+ }
598
+ else
599
+ {
600
+ do
601
+ {
602
+ copy_or_blend_pix(pix_value_ptr(x, y++, 1), *colors++, cover);
603
+ }
604
+ while (--len);
605
+ }
606
+ }
607
+ }
608
+
609
+ //--------------------------------------------------------------------
610
+ template<class Function> void for_each_pixel(Function f)
611
+ {
612
+ unsigned y;
613
+ for (y = 0; y < height(); ++y)
614
+ {
615
+ row_data r = m_rbuf->row(y);
616
+ if (r.ptr)
617
+ {
618
+ unsigned len = r.x2 - r.x1 + 1;
619
+ pixel_type* p = pix_value_ptr(r.x1, y, len);
620
+ do
621
+ {
622
+ f(p->c);
623
+ p = p->next();
624
+ }
625
+ while (--len);
626
+ }
627
+ }
628
+ }
629
+
630
+ //--------------------------------------------------------------------
631
+ template<class GammaLut> void apply_gamma_dir(const GammaLut& g)
632
+ {
633
+ for_each_pixel(apply_gamma_dir_gray<color_type, GammaLut>(g));
634
+ }
635
+
636
+ //--------------------------------------------------------------------
637
+ template<class GammaLut> void apply_gamma_inv(const GammaLut& g)
638
+ {
639
+ for_each_pixel(apply_gamma_inv_gray<color_type, GammaLut>(g));
640
+ }
641
+
642
+ //--------------------------------------------------------------------
643
+ template<class RenBuf2>
644
+ void copy_from(const RenBuf2& from,
645
+ int xdst, int ydst,
646
+ int xsrc, int ysrc,
647
+ unsigned len)
648
+ {
649
+ if (const int8u* p = from.row_ptr(ysrc))
650
+ {
651
+ memmove(m_rbuf->row_ptr(xdst, ydst, len) + xdst * pix_width,
652
+ p + xsrc * pix_width,
653
+ len * pix_width);
654
+ }
655
+ }
656
+
657
+ //--------------------------------------------------------------------
658
+ // Blend from single color, using grayscale surface as alpha channel.
659
+ template<class SrcPixelFormatRenderer>
660
+ void blend_from_color(const SrcPixelFormatRenderer& from,
661
+ const color_type& color,
662
+ int xdst, int ydst,
663
+ int xsrc, int ysrc,
664
+ unsigned len,
665
+ int8u cover)
666
+ {
667
+ typedef typename SrcPixelFormatRenderer::pixel_type src_pixel_type;
668
+ typedef typename SrcPixelFormatRenderer::color_type src_color_type;
669
+
670
+ if (const src_pixel_type* psrc = from.pix_value_ptr(xsrc, ysrc))
671
+ {
672
+ pixel_type* pdst = pix_value_ptr(xdst, ydst, len);
673
+
674
+ do
675
+ {
676
+ copy_or_blend_pix(pdst, color, src_color_type::scale_cover(cover, psrc->c[0]));
677
+ psrc = psrc->next();
678
+ pdst = pdst->next();
679
+ }
680
+ while (--len);
681
+ }
682
+ }
683
+
684
+ //--------------------------------------------------------------------
685
+ // Blend from color table, using grayscale surface as indexes into table.
686
+ // Obviously, this only works for integer value types.
687
+ template<class SrcPixelFormatRenderer>
688
+ void blend_from_lut(const SrcPixelFormatRenderer& from,
689
+ const color_type* color_lut,
690
+ int xdst, int ydst,
691
+ int xsrc, int ysrc,
692
+ unsigned len,
693
+ int8u cover)
694
+ {
695
+ typedef typename SrcPixelFormatRenderer::pixel_type src_pixel_type;
696
+
697
+ if (const src_pixel_type* psrc = from.pix_value_ptr(xsrc, ysrc))
698
+ {
699
+ pixel_type* pdst = pix_value_ptr(xdst, ydst, len);
700
+
701
+ do
702
+ {
703
+ copy_or_blend_pix(pdst, color_lut[psrc->c[0]], cover);
704
+ psrc = psrc->next();
705
+ pdst = pdst->next();
706
+ }
707
+ while (--len);
708
+ }
709
+ }
710
+
711
+ private:
712
+ rbuf_type* m_rbuf;
713
+ };
714
+
715
+ typedef blender_gray<gray8> blender_gray8;
716
+ typedef blender_gray<sgray8> blender_sgray8;
717
+ typedef blender_gray<gray16> blender_gray16;
718
+ typedef blender_gray<gray32> blender_gray32;
719
+
720
+ typedef blender_gray_pre<gray8> blender_gray8_pre;
721
+ typedef blender_gray_pre<sgray8> blender_sgray8_pre;
722
+ typedef blender_gray_pre<gray16> blender_gray16_pre;
723
+ typedef blender_gray_pre<gray32> blender_gray32_pre;
724
+
725
+ typedef pixfmt_alpha_blend_gray<blender_gray8, rendering_buffer> pixfmt_gray8;
726
+ typedef pixfmt_alpha_blend_gray<blender_sgray8, rendering_buffer> pixfmt_sgray8;
727
+ typedef pixfmt_alpha_blend_gray<blender_gray16, rendering_buffer> pixfmt_gray16;
728
+ typedef pixfmt_alpha_blend_gray<blender_gray32, rendering_buffer> pixfmt_gray32;
729
+
730
+ typedef pixfmt_alpha_blend_gray<blender_gray8_pre, rendering_buffer> pixfmt_gray8_pre;
731
+ typedef pixfmt_alpha_blend_gray<blender_sgray8_pre, rendering_buffer> pixfmt_sgray8_pre;
732
+ typedef pixfmt_alpha_blend_gray<blender_gray16_pre, rendering_buffer> pixfmt_gray16_pre;
733
+ typedef pixfmt_alpha_blend_gray<blender_gray32_pre, rendering_buffer> pixfmt_gray32_pre;
734
+ }
735
+
736
+ #endif
737
+
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_pixfmt_rgb.h ADDED
@@ -0,0 +1,994 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+ //
16
+ // Adaptation for high precision colors has been sponsored by
17
+ // Liberty Technology Systems, Inc., visit http://lib-sys.com
18
+ //
19
+ // Liberty Technology Systems, Inc. is the provider of
20
+ // PostScript and PDF technology for software developers.
21
+ //
22
+ //----------------------------------------------------------------------------
23
+
24
+ #ifndef AGG_PIXFMT_RGB_INCLUDED
25
+ #define AGG_PIXFMT_RGB_INCLUDED
26
+
27
+ #include <string.h>
28
+ #include "agg_pixfmt_base.h"
29
+ #include "agg_rendering_buffer.h"
30
+
31
+ namespace agg
32
+ {
33
+
34
+ //=====================================================apply_gamma_dir_rgb
35
+ template<class ColorT, class Order, class GammaLut> class apply_gamma_dir_rgb
36
+ {
37
+ public:
38
+ typedef typename ColorT::value_type value_type;
39
+
40
+ apply_gamma_dir_rgb(const GammaLut& gamma) : m_gamma(gamma) {}
41
+
42
+ AGG_INLINE void operator () (value_type* p)
43
+ {
44
+ p[Order::R] = m_gamma.dir(p[Order::R]);
45
+ p[Order::G] = m_gamma.dir(p[Order::G]);
46
+ p[Order::B] = m_gamma.dir(p[Order::B]);
47
+ }
48
+
49
+ private:
50
+ const GammaLut& m_gamma;
51
+ };
52
+
53
+
54
+
55
+ //=====================================================apply_gamma_inv_rgb
56
+ template<class ColorT, class Order, class GammaLut> class apply_gamma_inv_rgb
57
+ {
58
+ public:
59
+ typedef typename ColorT::value_type value_type;
60
+
61
+ apply_gamma_inv_rgb(const GammaLut& gamma) : m_gamma(gamma) {}
62
+
63
+ AGG_INLINE void operator () (value_type* p)
64
+ {
65
+ p[Order::R] = m_gamma.inv(p[Order::R]);
66
+ p[Order::G] = m_gamma.inv(p[Order::G]);
67
+ p[Order::B] = m_gamma.inv(p[Order::B]);
68
+ }
69
+
70
+ private:
71
+ const GammaLut& m_gamma;
72
+ };
73
+
74
+
75
+ //=========================================================blender_rgb
76
+ template<class ColorT, class Order>
77
+ struct blender_rgb
78
+ {
79
+ typedef ColorT color_type;
80
+ typedef Order order_type;
81
+ typedef typename color_type::value_type value_type;
82
+ typedef typename color_type::calc_type calc_type;
83
+ typedef typename color_type::long_type long_type;
84
+
85
+ // Blend pixels using the non-premultiplied form of Alvy-Ray Smith's
86
+ // compositing function. Since the render buffer is opaque we skip the
87
+ // initial premultiply and final demultiply.
88
+
89
+ //--------------------------------------------------------------------
90
+ static AGG_INLINE void blend_pix(value_type* p,
91
+ value_type cr, value_type cg, value_type cb, value_type alpha, cover_type cover)
92
+ {
93
+ blend_pix(p, cr, cg, cb, color_type::mult_cover(alpha, cover));
94
+ }
95
+
96
+ //--------------------------------------------------------------------
97
+ static AGG_INLINE void blend_pix(value_type* p,
98
+ value_type cr, value_type cg, value_type cb, value_type alpha)
99
+ {
100
+ p[Order::R] = color_type::lerp(p[Order::R], cr, alpha);
101
+ p[Order::G] = color_type::lerp(p[Order::G], cg, alpha);
102
+ p[Order::B] = color_type::lerp(p[Order::B], cb, alpha);
103
+ }
104
+ };
105
+
106
+ //======================================================blender_rgb_pre
107
+ template<class ColorT, class Order>
108
+ struct blender_rgb_pre
109
+ {
110
+ typedef ColorT color_type;
111
+ typedef Order order_type;
112
+ typedef typename color_type::value_type value_type;
113
+ typedef typename color_type::calc_type calc_type;
114
+ typedef typename color_type::long_type long_type;
115
+
116
+ // Blend pixels using the premultiplied form of Alvy-Ray Smith's
117
+ // compositing function.
118
+
119
+ //--------------------------------------------------------------------
120
+ static AGG_INLINE void blend_pix(value_type* p,
121
+ value_type cr, value_type cg, value_type cb, value_type alpha, cover_type cover)
122
+ {
123
+ blend_pix(p,
124
+ color_type::mult_cover(cr, cover),
125
+ color_type::mult_cover(cg, cover),
126
+ color_type::mult_cover(cb, cover),
127
+ color_type::mult_cover(alpha, cover));
128
+ }
129
+
130
+ //--------------------------------------------------------------------
131
+ static AGG_INLINE void blend_pix(value_type* p,
132
+ value_type cr, value_type cg, value_type cb, value_type alpha)
133
+ {
134
+ p[Order::R] = color_type::prelerp(p[Order::R], cr, alpha);
135
+ p[Order::G] = color_type::prelerp(p[Order::G], cg, alpha);
136
+ p[Order::B] = color_type::prelerp(p[Order::B], cb, alpha);
137
+ }
138
+ };
139
+
140
+ //===================================================blender_rgb_gamma
141
+ template<class ColorT, class Order, class Gamma>
142
+ class blender_rgb_gamma : public blender_base<ColorT, Order>
143
+ {
144
+ public:
145
+ typedef ColorT color_type;
146
+ typedef Order order_type;
147
+ typedef Gamma gamma_type;
148
+ typedef typename color_type::value_type value_type;
149
+ typedef typename color_type::calc_type calc_type;
150
+ typedef typename color_type::long_type long_type;
151
+
152
+ //--------------------------------------------------------------------
153
+ blender_rgb_gamma() : m_gamma(0) {}
154
+ void gamma(const gamma_type& g) { m_gamma = &g; }
155
+
156
+ //--------------------------------------------------------------------
157
+ AGG_INLINE void blend_pix(value_type* p,
158
+ value_type cr, value_type cg, value_type cb, value_type alpha, cover_type cover)
159
+ {
160
+ blend_pix(p, cr, cg, cb, color_type::mult_cover(alpha, cover));
161
+ }
162
+
163
+ //--------------------------------------------------------------------
164
+ AGG_INLINE void blend_pix(value_type* p,
165
+ value_type cr, value_type cg, value_type cb, value_type alpha)
166
+ {
167
+ calc_type r = m_gamma->dir(p[Order::R]);
168
+ calc_type g = m_gamma->dir(p[Order::G]);
169
+ calc_type b = m_gamma->dir(p[Order::B]);
170
+ p[Order::R] = m_gamma->inv(color_type::downscale((m_gamma->dir(cr) - r) * alpha) + r);
171
+ p[Order::G] = m_gamma->inv(color_type::downscale((m_gamma->dir(cg) - g) * alpha) + g);
172
+ p[Order::B] = m_gamma->inv(color_type::downscale((m_gamma->dir(cb) - b) * alpha) + b);
173
+ }
174
+
175
+ private:
176
+ const gamma_type* m_gamma;
177
+ };
178
+
179
+
180
+ //==================================================pixfmt_alpha_blend_rgb
181
+ template<class Blender, class RenBuf, unsigned Step, unsigned Offset = 0>
182
+ class pixfmt_alpha_blend_rgb
183
+ {
184
+ public:
185
+ typedef pixfmt_rgb_tag pixfmt_category;
186
+ typedef RenBuf rbuf_type;
187
+ typedef Blender blender_type;
188
+ typedef typename rbuf_type::row_data row_data;
189
+ typedef typename blender_type::color_type color_type;
190
+ typedef typename blender_type::order_type order_type;
191
+ typedef typename color_type::value_type value_type;
192
+ typedef typename color_type::calc_type calc_type;
193
+ enum
194
+ {
195
+ pix_step = Step,
196
+ pix_offset = Offset,
197
+ pix_width = sizeof(value_type) * pix_step
198
+ };
199
+ struct pixel_type
200
+ {
201
+ value_type c[pix_step];
202
+
203
+ void set(value_type r, value_type g, value_type b)
204
+ {
205
+ c[order_type::R] = r;
206
+ c[order_type::G] = g;
207
+ c[order_type::B] = b;
208
+ }
209
+
210
+ void set(const color_type& color)
211
+ {
212
+ set(color.r, color.g, color.b);
213
+ }
214
+
215
+ void get(value_type& r, value_type& g, value_type& b) const
216
+ {
217
+ r = c[order_type::R];
218
+ g = c[order_type::G];
219
+ b = c[order_type::B];
220
+ }
221
+
222
+ color_type get() const
223
+ {
224
+ return color_type(
225
+ c[order_type::R],
226
+ c[order_type::G],
227
+ c[order_type::B]);
228
+ }
229
+
230
+ pixel_type* next()
231
+ {
232
+ return this + 1;
233
+ }
234
+
235
+ const pixel_type* next() const
236
+ {
237
+ return this + 1;
238
+ }
239
+
240
+ pixel_type* advance(int n)
241
+ {
242
+ return this + n;
243
+ }
244
+
245
+ const pixel_type* advance(int n) const
246
+ {
247
+ return this + n;
248
+ }
249
+ };
250
+
251
+ private:
252
+ //--------------------------------------------------------------------
253
+ AGG_INLINE void blend_pix(pixel_type* p,
254
+ value_type r, value_type g, value_type b, value_type a,
255
+ unsigned cover)
256
+ {
257
+ m_blender.blend_pix(p->c, r, g, b, a, cover);
258
+ }
259
+
260
+ //--------------------------------------------------------------------
261
+ AGG_INLINE void blend_pix(pixel_type* p,
262
+ value_type r, value_type g, value_type b, value_type a)
263
+ {
264
+ m_blender.blend_pix(p->c, r, g, b, a);
265
+ }
266
+
267
+ //--------------------------------------------------------------------
268
+ AGG_INLINE void blend_pix(pixel_type* p, const color_type& c, unsigned cover)
269
+ {
270
+ m_blender.blend_pix(p->c, c.r, c.g, c.b, c.a, cover);
271
+ }
272
+
273
+ //--------------------------------------------------------------------
274
+ AGG_INLINE void blend_pix(pixel_type* p, const color_type& c)
275
+ {
276
+ m_blender.blend_pix(p->c, c.r, c.g, c.b, c.a);
277
+ }
278
+
279
+ //--------------------------------------------------------------------
280
+ AGG_INLINE void copy_or_blend_pix(pixel_type* p, const color_type& c, unsigned cover)
281
+ {
282
+ if (!c.is_transparent())
283
+ {
284
+ if (c.is_opaque() && cover == cover_mask)
285
+ {
286
+ p->set(c);
287
+ }
288
+ else
289
+ {
290
+ blend_pix(p, c, cover);
291
+ }
292
+ }
293
+ }
294
+
295
+ //--------------------------------------------------------------------
296
+ AGG_INLINE void copy_or_blend_pix(pixel_type* p, const color_type& c)
297
+ {
298
+ if (!c.is_transparent())
299
+ {
300
+ if (c.is_opaque())
301
+ {
302
+ p->set(c);
303
+ }
304
+ else
305
+ {
306
+ blend_pix(p, c);
307
+ }
308
+ }
309
+ }
310
+
311
+ public:
312
+ //--------------------------------------------------------------------
313
+ explicit pixfmt_alpha_blend_rgb(rbuf_type& rb) :
314
+ m_rbuf(&rb)
315
+ {}
316
+ void attach(rbuf_type& rb) { m_rbuf = &rb; }
317
+
318
+ //--------------------------------------------------------------------
319
+ template<class PixFmt>
320
+ bool attach(PixFmt& pixf, int x1, int y1, int x2, int y2)
321
+ {
322
+ rect_i r(x1, y1, x2, y2);
323
+ if (r.clip(rect_i(0, 0, pixf.width()-1, pixf.height()-1)))
324
+ {
325
+ int stride = pixf.stride();
326
+ m_rbuf->attach(pixf.pix_ptr(r.x1, stride < 0 ? r.y2 : r.y1),
327
+ (r.x2 - r.x1) + 1,
328
+ (r.y2 - r.y1) + 1,
329
+ stride);
330
+ return true;
331
+ }
332
+ return false;
333
+ }
334
+
335
+ //--------------------------------------------------------------------
336
+ Blender& blender() { return m_blender; }
337
+
338
+ //--------------------------------------------------------------------
339
+ AGG_INLINE unsigned width() const { return m_rbuf->width(); }
340
+ AGG_INLINE unsigned height() const { return m_rbuf->height(); }
341
+ AGG_INLINE int stride() const { return m_rbuf->stride(); }
342
+
343
+ //--------------------------------------------------------------------
344
+ AGG_INLINE int8u* row_ptr(int y) { return m_rbuf->row_ptr(y); }
345
+ AGG_INLINE const int8u* row_ptr(int y) const { return m_rbuf->row_ptr(y); }
346
+ AGG_INLINE row_data row(int y) const { return m_rbuf->row(y); }
347
+
348
+ //--------------------------------------------------------------------
349
+ AGG_INLINE int8u* pix_ptr(int x, int y)
350
+ {
351
+ return m_rbuf->row_ptr(y) + sizeof(value_type) * (x * pix_step + pix_offset);
352
+ }
353
+
354
+ AGG_INLINE const int8u* pix_ptr(int x, int y) const
355
+ {
356
+ return m_rbuf->row_ptr(y) + sizeof(value_type) * (x * pix_step + pix_offset);
357
+ }
358
+
359
+ // Return pointer to pixel value, forcing row to be allocated.
360
+ AGG_INLINE pixel_type* pix_value_ptr(int x, int y, unsigned len)
361
+ {
362
+ return (pixel_type*)(m_rbuf->row_ptr(x, y, len) + sizeof(value_type) * (x * pix_step + pix_offset));
363
+ }
364
+
365
+ // Return pointer to pixel value, or null if row not allocated.
366
+ AGG_INLINE const pixel_type* pix_value_ptr(int x, int y) const
367
+ {
368
+ int8u* p = m_rbuf->row_ptr(y);
369
+ return p ? (pixel_type*)(p + sizeof(value_type) * (x * pix_step + pix_offset)) : 0;
370
+ }
371
+
372
+ // Get pixel pointer from raw buffer pointer.
373
+ AGG_INLINE static pixel_type* pix_value_ptr(void* p)
374
+ {
375
+ return (pixel_type*)((value_type*)p + pix_offset);
376
+ }
377
+
378
+ // Get pixel pointer from raw buffer pointer.
379
+ AGG_INLINE static const pixel_type* pix_value_ptr(const void* p)
380
+ {
381
+ return (const pixel_type*)((const value_type*)p + pix_offset);
382
+ }
383
+
384
+ //--------------------------------------------------------------------
385
+ AGG_INLINE static void write_plain_color(void* p, color_type c)
386
+ {
387
+ // RGB formats are implicitly premultiplied.
388
+ c.premultiply();
389
+ pix_value_ptr(p)->set(c);
390
+ }
391
+
392
+ //--------------------------------------------------------------------
393
+ AGG_INLINE static color_type read_plain_color(const void* p)
394
+ {
395
+ return pix_value_ptr(p)->get();
396
+ }
397
+
398
+ //--------------------------------------------------------------------
399
+ AGG_INLINE static void make_pix(int8u* p, const color_type& c)
400
+ {
401
+ ((pixel_type*)p)->set(c);
402
+ }
403
+
404
+ //--------------------------------------------------------------------
405
+ AGG_INLINE color_type pixel(int x, int y) const
406
+ {
407
+ if (const pixel_type* p = pix_value_ptr(x, y))
408
+ {
409
+ return p->get();
410
+ }
411
+ return color_type::no_color();
412
+ }
413
+
414
+ //--------------------------------------------------------------------
415
+ AGG_INLINE void copy_pixel(int x, int y, const color_type& c)
416
+ {
417
+ pix_value_ptr(x, y, 1)->set(c);
418
+ }
419
+
420
+ //--------------------------------------------------------------------
421
+ AGG_INLINE void blend_pixel(int x, int y, const color_type& c, int8u cover)
422
+ {
423
+ copy_or_blend_pix(pix_value_ptr(x, y, 1), c, cover);
424
+ }
425
+
426
+ //--------------------------------------------------------------------
427
+ AGG_INLINE void copy_hline(int x, int y,
428
+ unsigned len,
429
+ const color_type& c)
430
+ {
431
+ pixel_type* p = pix_value_ptr(x, y, len);
432
+ do
433
+ {
434
+ p->set(c);
435
+ p = p->next();
436
+ }
437
+ while(--len);
438
+ }
439
+
440
+
441
+ //--------------------------------------------------------------------
442
+ AGG_INLINE void copy_vline(int x, int y,
443
+ unsigned len,
444
+ const color_type& c)
445
+ {
446
+ do
447
+ {
448
+ pix_value_ptr(x, y++, 1)->set(c);
449
+ }
450
+ while (--len);
451
+ }
452
+
453
+ //--------------------------------------------------------------------
454
+ void blend_hline(int x, int y,
455
+ unsigned len,
456
+ const color_type& c,
457
+ int8u cover)
458
+ {
459
+ if (!c.is_transparent())
460
+ {
461
+ pixel_type* p = pix_value_ptr(x, y, len);
462
+
463
+ if (c.is_opaque() && cover == cover_mask)
464
+ {
465
+ do
466
+ {
467
+ p->set(c);
468
+ p = p->next();
469
+ }
470
+ while (--len);
471
+ }
472
+ else
473
+ {
474
+ do
475
+ {
476
+ blend_pix(p, c, cover);
477
+ p = p->next();
478
+ }
479
+ while (--len);
480
+ }
481
+ }
482
+ }
483
+
484
+
485
+ //--------------------------------------------------------------------
486
+ void blend_vline(int x, int y,
487
+ unsigned len,
488
+ const color_type& c,
489
+ int8u cover)
490
+ {
491
+ if (!c.is_transparent())
492
+ {
493
+ if (c.is_opaque() && cover == cover_mask)
494
+ {
495
+ do
496
+ {
497
+ pix_value_ptr(x, y++, 1)->set(c);
498
+ }
499
+ while (--len);
500
+ }
501
+ else
502
+ {
503
+ do
504
+ {
505
+ blend_pix(pix_value_ptr(x, y++, 1), c, cover);
506
+ }
507
+ while (--len);
508
+ }
509
+ }
510
+ }
511
+
512
+ //--------------------------------------------------------------------
513
+ void blend_solid_hspan(int x, int y,
514
+ unsigned len,
515
+ const color_type& c,
516
+ const int8u* covers)
517
+ {
518
+ if (!c.is_transparent())
519
+ {
520
+ pixel_type* p = pix_value_ptr(x, y, len);
521
+
522
+ do
523
+ {
524
+ if (c.is_opaque() && *covers == cover_mask)
525
+ {
526
+ p->set(c);
527
+ }
528
+ else
529
+ {
530
+ blend_pix(p, c, *covers);
531
+ }
532
+ p = p->next();
533
+ ++covers;
534
+ }
535
+ while (--len);
536
+ }
537
+ }
538
+
539
+
540
+ //--------------------------------------------------------------------
541
+ void blend_solid_vspan(int x, int y,
542
+ unsigned len,
543
+ const color_type& c,
544
+ const int8u* covers)
545
+ {
546
+ if (!c.is_transparent())
547
+ {
548
+ do
549
+ {
550
+ pixel_type* p = pix_value_ptr(x, y++, 1);
551
+
552
+ if (c.is_opaque() && *covers == cover_mask)
553
+ {
554
+ p->set(c);
555
+ }
556
+ else
557
+ {
558
+ blend_pix(p, c, *covers);
559
+ }
560
+ ++covers;
561
+ }
562
+ while (--len);
563
+ }
564
+ }
565
+
566
+ //--------------------------------------------------------------------
567
+ void copy_color_hspan(int x, int y,
568
+ unsigned len,
569
+ const color_type* colors)
570
+ {
571
+ pixel_type* p = pix_value_ptr(x, y, len);
572
+
573
+ do
574
+ {
575
+ p->set(*colors++);
576
+ p = p->next();
577
+ }
578
+ while (--len);
579
+ }
580
+
581
+
582
+ //--------------------------------------------------------------------
583
+ void copy_color_vspan(int x, int y,
584
+ unsigned len,
585
+ const color_type* colors)
586
+ {
587
+ do
588
+ {
589
+ pix_value_ptr(x, y++, 1)->set(*colors++);
590
+ }
591
+ while (--len);
592
+ }
593
+
594
+ //--------------------------------------------------------------------
595
+ void blend_color_hspan(int x, int y,
596
+ unsigned len,
597
+ const color_type* colors,
598
+ const int8u* covers,
599
+ int8u cover)
600
+ {
601
+ pixel_type* p = pix_value_ptr(x, y, len);
602
+
603
+ if (covers)
604
+ {
605
+ do
606
+ {
607
+ copy_or_blend_pix(p, *colors++, *covers++);
608
+ p = p->next();
609
+ }
610
+ while (--len);
611
+ }
612
+ else
613
+ {
614
+ if (cover == cover_mask)
615
+ {
616
+ do
617
+ {
618
+ copy_or_blend_pix(p, *colors++);
619
+ p = p->next();
620
+ }
621
+ while (--len);
622
+ }
623
+ else
624
+ {
625
+ do
626
+ {
627
+ copy_or_blend_pix(p, *colors++, cover);
628
+ p = p->next();
629
+ }
630
+ while (--len);
631
+ }
632
+ }
633
+ }
634
+
635
+ //--------------------------------------------------------------------
636
+ void blend_color_vspan(int x, int y,
637
+ unsigned len,
638
+ const color_type* colors,
639
+ const int8u* covers,
640
+ int8u cover)
641
+ {
642
+ if (covers)
643
+ {
644
+ do
645
+ {
646
+ copy_or_blend_pix(pix_value_ptr(x, y++, 1), *colors++, *covers++);
647
+ }
648
+ while (--len);
649
+ }
650
+ else
651
+ {
652
+ if (cover == cover_mask)
653
+ {
654
+ do
655
+ {
656
+ copy_or_blend_pix(pix_value_ptr(x, y++, 1), *colors++);
657
+ }
658
+ while (--len);
659
+ }
660
+ else
661
+ {
662
+ do
663
+ {
664
+ copy_or_blend_pix(pix_value_ptr(x, y++, 1), *colors++, cover);
665
+ }
666
+ while (--len);
667
+ }
668
+ }
669
+ }
670
+
671
+ //--------------------------------------------------------------------
672
+ template<class Function> void for_each_pixel(Function f)
673
+ {
674
+ for (unsigned y = 0; y < height(); ++y)
675
+ {
676
+ row_data r = m_rbuf->row(y);
677
+ if (r.ptr)
678
+ {
679
+ unsigned len = r.x2 - r.x1 + 1;
680
+ pixel_type* p = pix_value_ptr(r.x1, y, len);
681
+ do
682
+ {
683
+ f(p->c);
684
+ p = p->next();
685
+ }
686
+ while (--len);
687
+ }
688
+ }
689
+ }
690
+
691
+ //--------------------------------------------------------------------
692
+ template<class GammaLut> void apply_gamma_dir(const GammaLut& g)
693
+ {
694
+ for_each_pixel(apply_gamma_dir_rgb<color_type, order_type, GammaLut>(g));
695
+ }
696
+
697
+ //--------------------------------------------------------------------
698
+ template<class GammaLut> void apply_gamma_inv(const GammaLut& g)
699
+ {
700
+ for_each_pixel(apply_gamma_inv_rgb<color_type, order_type, GammaLut>(g));
701
+ }
702
+
703
+ //--------------------------------------------------------------------
704
+ template<class RenBuf2>
705
+ void copy_from(const RenBuf2& from,
706
+ int xdst, int ydst,
707
+ int xsrc, int ysrc,
708
+ unsigned len)
709
+ {
710
+ if (const int8u* p = from.row_ptr(ysrc))
711
+ {
712
+ memmove(m_rbuf->row_ptr(xdst, ydst, len) + xdst * pix_width,
713
+ p + xsrc * pix_width,
714
+ len * pix_width);
715
+ }
716
+ }
717
+
718
+ //--------------------------------------------------------------------
719
+ // Blend from an RGBA surface.
720
+ template<class SrcPixelFormatRenderer>
721
+ void blend_from(const SrcPixelFormatRenderer& from,
722
+ int xdst, int ydst,
723
+ int xsrc, int ysrc,
724
+ unsigned len,
725
+ int8u cover)
726
+ {
727
+ typedef typename SrcPixelFormatRenderer::pixel_type src_pixel_type;
728
+ typedef typename SrcPixelFormatRenderer::order_type src_order;
729
+
730
+ if (const src_pixel_type* psrc = from.pix_value_ptr(xsrc, ysrc))
731
+ {
732
+ pixel_type* pdst = pix_value_ptr(xdst, ydst, len);
733
+
734
+ if (cover == cover_mask)
735
+ {
736
+ do
737
+ {
738
+ value_type alpha = psrc->c[src_order::A];
739
+ if (alpha <= color_type::empty_value())
740
+ {
741
+ if (alpha >= color_type::full_value())
742
+ {
743
+ pdst->c[order_type::R] = psrc->c[src_order::R];
744
+ pdst->c[order_type::G] = psrc->c[src_order::G];
745
+ pdst->c[order_type::B] = psrc->c[src_order::B];
746
+ }
747
+ else
748
+ {
749
+ blend_pix(pdst,
750
+ psrc->c[src_order::R],
751
+ psrc->c[src_order::G],
752
+ psrc->c[src_order::B],
753
+ alpha);
754
+ }
755
+ }
756
+ psrc = psrc->next();
757
+ pdst = pdst->next();
758
+ }
759
+ while(--len);
760
+ }
761
+ else
762
+ {
763
+ do
764
+ {
765
+ copy_or_blend_pix(pdst, psrc->get(), cover);
766
+ psrc = psrc->next();
767
+ pdst = pdst->next();
768
+ }
769
+ while (--len);
770
+ }
771
+ }
772
+ }
773
+
774
+ //--------------------------------------------------------------------
775
+ // Blend from single color, using grayscale surface as alpha channel.
776
+ template<class SrcPixelFormatRenderer>
777
+ void blend_from_color(const SrcPixelFormatRenderer& from,
778
+ const color_type& color,
779
+ int xdst, int ydst,
780
+ int xsrc, int ysrc,
781
+ unsigned len,
782
+ int8u cover)
783
+ {
784
+ typedef typename SrcPixelFormatRenderer::pixel_type src_pixel_type;
785
+ typedef typename SrcPixelFormatRenderer::color_type src_color_type;
786
+
787
+ if (const src_pixel_type* psrc = from.pix_value_ptr(xsrc, ysrc))
788
+ {
789
+ pixel_type* pdst = pix_value_ptr(xdst, ydst, len);
790
+
791
+ do
792
+ {
793
+ copy_or_blend_pix(pdst, color, src_color_type::scale_cover(cover, psrc->c[0]));
794
+ psrc = psrc->next();
795
+ pdst = pdst->next();
796
+ }
797
+ while (--len);
798
+ }
799
+ }
800
+
801
+ //--------------------------------------------------------------------
802
+ // Blend from color table, using grayscale surface as indexes into table.
803
+ // Obviously, this only works for integer value types.
804
+ template<class SrcPixelFormatRenderer>
805
+ void blend_from_lut(const SrcPixelFormatRenderer& from,
806
+ const color_type* color_lut,
807
+ int xdst, int ydst,
808
+ int xsrc, int ysrc,
809
+ unsigned len,
810
+ int8u cover)
811
+ {
812
+ typedef typename SrcPixelFormatRenderer::pixel_type src_pixel_type;
813
+
814
+ if (const src_pixel_type* psrc = from.pix_value_ptr(xsrc, ysrc))
815
+ {
816
+ pixel_type* pdst = pix_value_ptr(xdst, ydst, len);
817
+
818
+ if (cover == cover_mask)
819
+ {
820
+ do
821
+ {
822
+ const color_type& color = color_lut[psrc->c[0]];
823
+ blend_pix(pdst, color);
824
+ psrc = psrc->next();
825
+ pdst = pdst->next();
826
+ }
827
+ while(--len);
828
+ }
829
+ else
830
+ {
831
+ do
832
+ {
833
+ copy_or_blend_pix(pdst, color_lut[psrc->c[0]], cover);
834
+ psrc = psrc->next();
835
+ pdst = pdst->next();
836
+ }
837
+ while(--len);
838
+ }
839
+ }
840
+ }
841
+
842
+ private:
843
+ rbuf_type* m_rbuf;
844
+ Blender m_blender;
845
+ };
846
+
847
+ //-----------------------------------------------------------------------
848
+ typedef blender_rgb<rgba8, order_rgb> blender_rgb24;
849
+ typedef blender_rgb<rgba8, order_bgr> blender_bgr24;
850
+ typedef blender_rgb<srgba8, order_rgb> blender_srgb24;
851
+ typedef blender_rgb<srgba8, order_bgr> blender_sbgr24;
852
+ typedef blender_rgb<rgba16, order_rgb> blender_rgb48;
853
+ typedef blender_rgb<rgba16, order_bgr> blender_bgr48;
854
+ typedef blender_rgb<rgba32, order_rgb> blender_rgb96;
855
+ typedef blender_rgb<rgba32, order_bgr> blender_bgr96;
856
+
857
+ typedef blender_rgb_pre<rgba8, order_rgb> blender_rgb24_pre;
858
+ typedef blender_rgb_pre<rgba8, order_bgr> blender_bgr24_pre;
859
+ typedef blender_rgb_pre<srgba8, order_rgb> blender_srgb24_pre;
860
+ typedef blender_rgb_pre<srgba8, order_bgr> blender_sbgr24_pre;
861
+ typedef blender_rgb_pre<rgba16, order_rgb> blender_rgb48_pre;
862
+ typedef blender_rgb_pre<rgba16, order_bgr> blender_bgr48_pre;
863
+ typedef blender_rgb_pre<rgba32, order_rgb> blender_rgb96_pre;
864
+ typedef blender_rgb_pre<rgba32, order_bgr> blender_bgr96_pre;
865
+
866
+ typedef pixfmt_alpha_blend_rgb<blender_rgb24, rendering_buffer, 3> pixfmt_rgb24;
867
+ typedef pixfmt_alpha_blend_rgb<blender_bgr24, rendering_buffer, 3> pixfmt_bgr24;
868
+ typedef pixfmt_alpha_blend_rgb<blender_srgb24, rendering_buffer, 3> pixfmt_srgb24;
869
+ typedef pixfmt_alpha_blend_rgb<blender_sbgr24, rendering_buffer, 3> pixfmt_sbgr24;
870
+ typedef pixfmt_alpha_blend_rgb<blender_rgb48, rendering_buffer, 3> pixfmt_rgb48;
871
+ typedef pixfmt_alpha_blend_rgb<blender_bgr48, rendering_buffer, 3> pixfmt_bgr48;
872
+ typedef pixfmt_alpha_blend_rgb<blender_rgb96, rendering_buffer, 3> pixfmt_rgb96;
873
+ typedef pixfmt_alpha_blend_rgb<blender_bgr96, rendering_buffer, 3> pixfmt_bgr96;
874
+
875
+ typedef pixfmt_alpha_blend_rgb<blender_rgb24_pre, rendering_buffer, 3> pixfmt_rgb24_pre;
876
+ typedef pixfmt_alpha_blend_rgb<blender_bgr24_pre, rendering_buffer, 3> pixfmt_bgr24_pre;
877
+ typedef pixfmt_alpha_blend_rgb<blender_srgb24_pre, rendering_buffer, 3> pixfmt_srgb24_pre;
878
+ typedef pixfmt_alpha_blend_rgb<blender_sbgr24_pre, rendering_buffer, 3> pixfmt_sbgr24_pre;
879
+ typedef pixfmt_alpha_blend_rgb<blender_rgb48_pre, rendering_buffer, 3> pixfmt_rgb48_pre;
880
+ typedef pixfmt_alpha_blend_rgb<blender_bgr48_pre, rendering_buffer, 3> pixfmt_bgr48_pre;
881
+ typedef pixfmt_alpha_blend_rgb<blender_rgb96_pre, rendering_buffer, 3> pixfmt_rgb96_pre;
882
+ typedef pixfmt_alpha_blend_rgb<blender_bgr96_pre, rendering_buffer, 3> pixfmt_bgr96_pre;
883
+
884
+ typedef pixfmt_alpha_blend_rgb<blender_rgb24, rendering_buffer, 4, 0> pixfmt_rgbx32;
885
+ typedef pixfmt_alpha_blend_rgb<blender_rgb24, rendering_buffer, 4, 1> pixfmt_xrgb32;
886
+ typedef pixfmt_alpha_blend_rgb<blender_bgr24, rendering_buffer, 4, 1> pixfmt_xbgr32;
887
+ typedef pixfmt_alpha_blend_rgb<blender_bgr24, rendering_buffer, 4, 0> pixfmt_bgrx32;
888
+ typedef pixfmt_alpha_blend_rgb<blender_srgb24, rendering_buffer, 4, 0> pixfmt_srgbx32;
889
+ typedef pixfmt_alpha_blend_rgb<blender_srgb24, rendering_buffer, 4, 1> pixfmt_sxrgb32;
890
+ typedef pixfmt_alpha_blend_rgb<blender_sbgr24, rendering_buffer, 4, 1> pixfmt_sxbgr32;
891
+ typedef pixfmt_alpha_blend_rgb<blender_sbgr24, rendering_buffer, 4, 0> pixfmt_sbgrx32;
892
+ typedef pixfmt_alpha_blend_rgb<blender_rgb48, rendering_buffer, 4, 0> pixfmt_rgbx64;
893
+ typedef pixfmt_alpha_blend_rgb<blender_rgb48, rendering_buffer, 4, 1> pixfmt_xrgb64;
894
+ typedef pixfmt_alpha_blend_rgb<blender_bgr48, rendering_buffer, 4, 1> pixfmt_xbgr64;
895
+ typedef pixfmt_alpha_blend_rgb<blender_bgr48, rendering_buffer, 4, 0> pixfmt_bgrx64;
896
+ typedef pixfmt_alpha_blend_rgb<blender_rgb96, rendering_buffer, 4, 0> pixfmt_rgbx128;
897
+ typedef pixfmt_alpha_blend_rgb<blender_rgb96, rendering_buffer, 4, 1> pixfmt_xrgb128;
898
+ typedef pixfmt_alpha_blend_rgb<blender_bgr96, rendering_buffer, 4, 1> pixfmt_xbgr128;
899
+ typedef pixfmt_alpha_blend_rgb<blender_bgr96, rendering_buffer, 4, 0> pixfmt_bgrx128;
900
+
901
+ typedef pixfmt_alpha_blend_rgb<blender_rgb24_pre, rendering_buffer, 4, 0> pixfmt_rgbx32_pre;
902
+ typedef pixfmt_alpha_blend_rgb<blender_rgb24_pre, rendering_buffer, 4, 1> pixfmt_xrgb32_pre;
903
+ typedef pixfmt_alpha_blend_rgb<blender_bgr24_pre, rendering_buffer, 4, 1> pixfmt_xbgr32_pre;
904
+ typedef pixfmt_alpha_blend_rgb<blender_bgr24_pre, rendering_buffer, 4, 0> pixfmt_bgrx32_pre;
905
+ typedef pixfmt_alpha_blend_rgb<blender_srgb24_pre, rendering_buffer, 4, 0> pixfmt_srgbx32_pre;
906
+ typedef pixfmt_alpha_blend_rgb<blender_srgb24_pre, rendering_buffer, 4, 1> pixfmt_sxrgb32_pre;
907
+ typedef pixfmt_alpha_blend_rgb<blender_sbgr24_pre, rendering_buffer, 4, 1> pixfmt_sxbgr32_pre;
908
+ typedef pixfmt_alpha_blend_rgb<blender_sbgr24_pre, rendering_buffer, 4, 0> pixfmt_sbgrx32_pre;
909
+ typedef pixfmt_alpha_blend_rgb<blender_rgb48_pre, rendering_buffer, 4, 0> pixfmt_rgbx64_pre;
910
+ typedef pixfmt_alpha_blend_rgb<blender_rgb48_pre, rendering_buffer, 4, 1> pixfmt_xrgb64_pre;
911
+ typedef pixfmt_alpha_blend_rgb<blender_bgr48_pre, rendering_buffer, 4, 1> pixfmt_xbgr64_pre;
912
+ typedef pixfmt_alpha_blend_rgb<blender_bgr48_pre, rendering_buffer, 4, 0> pixfmt_bgrx64_pre;
913
+ typedef pixfmt_alpha_blend_rgb<blender_rgb96_pre, rendering_buffer, 4, 0> pixfmt_rgbx128_pre;
914
+ typedef pixfmt_alpha_blend_rgb<blender_rgb96_pre, rendering_buffer, 4, 1> pixfmt_xrgb128_pre;
915
+ typedef pixfmt_alpha_blend_rgb<blender_bgr96_pre, rendering_buffer, 4, 1> pixfmt_xbgr128_pre;
916
+ typedef pixfmt_alpha_blend_rgb<blender_bgr96_pre, rendering_buffer, 4, 0> pixfmt_bgrx128_pre;
917
+
918
+
919
+ //-----------------------------------------------------pixfmt_rgb24_gamma
920
+ template<class Gamma> class pixfmt_rgb24_gamma :
921
+ public pixfmt_alpha_blend_rgb<blender_rgb_gamma<rgba8, order_rgb, Gamma>, rendering_buffer, 3>
922
+ {
923
+ public:
924
+ pixfmt_rgb24_gamma(rendering_buffer& rb, const Gamma& g) :
925
+ pixfmt_alpha_blend_rgb<blender_rgb_gamma<rgba8, order_rgb, Gamma>, rendering_buffer, 3>(rb)
926
+ {
927
+ this->blender().gamma(g);
928
+ }
929
+ };
930
+
931
+ //-----------------------------------------------------pixfmt_srgb24_gamma
932
+ template<class Gamma> class pixfmt_srgb24_gamma :
933
+ public pixfmt_alpha_blend_rgb<blender_rgb_gamma<srgba8, order_rgb, Gamma>, rendering_buffer, 3>
934
+ {
935
+ public:
936
+ pixfmt_srgb24_gamma(rendering_buffer& rb, const Gamma& g) :
937
+ pixfmt_alpha_blend_rgb<blender_rgb_gamma<srgba8, order_rgb, Gamma>, rendering_buffer, 3>(rb)
938
+ {
939
+ this->blender().gamma(g);
940
+ }
941
+ };
942
+
943
+ //-----------------------------------------------------pixfmt_bgr24_gamma
944
+ template<class Gamma> class pixfmt_bgr24_gamma :
945
+ public pixfmt_alpha_blend_rgb<blender_rgb_gamma<rgba8, order_bgr, Gamma>, rendering_buffer, 3>
946
+ {
947
+ public:
948
+ pixfmt_bgr24_gamma(rendering_buffer& rb, const Gamma& g) :
949
+ pixfmt_alpha_blend_rgb<blender_rgb_gamma<rgba8, order_bgr, Gamma>, rendering_buffer, 3>(rb)
950
+ {
951
+ this->blender().gamma(g);
952
+ }
953
+ };
954
+
955
+ //-----------------------------------------------------pixfmt_sbgr24_gamma
956
+ template<class Gamma> class pixfmt_sbgr24_gamma :
957
+ public pixfmt_alpha_blend_rgb<blender_rgb_gamma<srgba8, order_bgr, Gamma>, rendering_buffer, 3>
958
+ {
959
+ public:
960
+ pixfmt_sbgr24_gamma(rendering_buffer& rb, const Gamma& g) :
961
+ pixfmt_alpha_blend_rgb<blender_rgb_gamma<srgba8, order_bgr, Gamma>, rendering_buffer, 3>(rb)
962
+ {
963
+ this->blender().gamma(g);
964
+ }
965
+ };
966
+
967
+ //-----------------------------------------------------pixfmt_rgb48_gamma
968
+ template<class Gamma> class pixfmt_rgb48_gamma :
969
+ public pixfmt_alpha_blend_rgb<blender_rgb_gamma<rgba16, order_rgb, Gamma>, rendering_buffer, 3>
970
+ {
971
+ public:
972
+ pixfmt_rgb48_gamma(rendering_buffer& rb, const Gamma& g) :
973
+ pixfmt_alpha_blend_rgb<blender_rgb_gamma<rgba16, order_rgb, Gamma>, rendering_buffer, 3>(rb)
974
+ {
975
+ this->blender().gamma(g);
976
+ }
977
+ };
978
+
979
+ //-----------------------------------------------------pixfmt_bgr48_gamma
980
+ template<class Gamma> class pixfmt_bgr48_gamma :
981
+ public pixfmt_alpha_blend_rgb<blender_rgb_gamma<rgba16, order_bgr, Gamma>, rendering_buffer, 3>
982
+ {
983
+ public:
984
+ pixfmt_bgr48_gamma(rendering_buffer& rb, const Gamma& g) :
985
+ pixfmt_alpha_blend_rgb<blender_rgb_gamma<rgba16, order_bgr, Gamma>, rendering_buffer, 3>(rb)
986
+ {
987
+ this->blender().gamma(g);
988
+ }
989
+ };
990
+
991
+ }
992
+
993
+ #endif
994
+
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_pixfmt_rgba.h ADDED
The diff for this file is too large to render. See raw diff
 
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_rasterizer_cells_aa.h ADDED
@@ -0,0 +1,743 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ //
12
+ // The author gratefully acknowleges the support of David Turner,
13
+ // Robert Wilhelm, and Werner Lemberg - the authors of the FreeType
14
+ // libray - in producing this work. See http://www.freetype.org for details.
15
+ //
16
+ //----------------------------------------------------------------------------
17
+ // Contact: mcseem@antigrain.com
18
+ // mcseemagg@yahoo.com
19
+ // http://www.antigrain.com
20
+ //----------------------------------------------------------------------------
21
+ //
22
+ // Adaptation for 32-bit screen coordinates has been sponsored by
23
+ // Liberty Technology Systems, Inc., visit http://lib-sys.com
24
+ //
25
+ // Liberty Technology Systems, Inc. is the provider of
26
+ // PostScript and PDF technology for software developers.
27
+ //
28
+ //----------------------------------------------------------------------------
29
+ #ifndef AGG_RASTERIZER_CELLS_AA_INCLUDED
30
+ #define AGG_RASTERIZER_CELLS_AA_INCLUDED
31
+
32
+ #include <stdexcept>
33
+ #include <string.h>
34
+ #include <math.h>
35
+ #include "agg_math.h"
36
+ #include "agg_array.h"
37
+
38
+
39
+ namespace agg
40
+ {
41
+
42
+ //-----------------------------------------------------rasterizer_cells_aa
43
+ // An internal class that implements the main rasterization algorithm.
44
+ // Used in the rasterizer. Should not be used direcly.
45
+ template<class Cell> class rasterizer_cells_aa
46
+ {
47
+ enum cell_block_scale_e
48
+ {
49
+ cell_block_shift = 12,
50
+ cell_block_size = 1 << cell_block_shift,
51
+ cell_block_mask = cell_block_size - 1,
52
+ cell_block_pool = 256
53
+ };
54
+
55
+ struct sorted_y
56
+ {
57
+ unsigned start;
58
+ unsigned num;
59
+ };
60
+
61
+ public:
62
+ typedef Cell cell_type;
63
+ typedef rasterizer_cells_aa<Cell> self_type;
64
+
65
+ ~rasterizer_cells_aa();
66
+ rasterizer_cells_aa(unsigned cell_block_limit=1024);
67
+
68
+ void reset();
69
+ void style(const cell_type& style_cell);
70
+ void line(int x1, int y1, int x2, int y2);
71
+
72
+ int min_x() const { return m_min_x; }
73
+ int min_y() const { return m_min_y; }
74
+ int max_x() const { return m_max_x; }
75
+ int max_y() const { return m_max_y; }
76
+
77
+ void sort_cells();
78
+
79
+ unsigned total_cells() const
80
+ {
81
+ return m_num_cells;
82
+ }
83
+
84
+ unsigned scanline_num_cells(unsigned y) const
85
+ {
86
+ return m_sorted_y[y - m_min_y].num;
87
+ }
88
+
89
+ const cell_type* const* scanline_cells(unsigned y) const
90
+ {
91
+ return m_sorted_cells.data() + m_sorted_y[y - m_min_y].start;
92
+ }
93
+
94
+ bool sorted() const { return m_sorted; }
95
+
96
+ private:
97
+ rasterizer_cells_aa(const self_type&);
98
+ const self_type& operator = (const self_type&);
99
+
100
+ void set_curr_cell(int x, int y);
101
+ void add_curr_cell();
102
+ void render_hline(int ey, int x1, int y1, int x2, int y2);
103
+ void allocate_block();
104
+
105
+ private:
106
+ unsigned m_num_blocks;
107
+ unsigned m_max_blocks;
108
+ unsigned m_curr_block;
109
+ unsigned m_num_cells;
110
+ unsigned m_cell_block_limit;
111
+ cell_type** m_cells;
112
+ cell_type* m_curr_cell_ptr;
113
+ pod_vector<cell_type*> m_sorted_cells;
114
+ pod_vector<sorted_y> m_sorted_y;
115
+ cell_type m_curr_cell;
116
+ cell_type m_style_cell;
117
+ int m_min_x;
118
+ int m_min_y;
119
+ int m_max_x;
120
+ int m_max_y;
121
+ bool m_sorted;
122
+ };
123
+
124
+
125
+
126
+
127
+ //------------------------------------------------------------------------
128
+ template<class Cell>
129
+ rasterizer_cells_aa<Cell>::~rasterizer_cells_aa()
130
+ {
131
+ if(m_num_blocks)
132
+ {
133
+ cell_type** ptr = m_cells + m_num_blocks - 1;
134
+ while(m_num_blocks--)
135
+ {
136
+ pod_allocator<cell_type>::deallocate(*ptr, cell_block_size);
137
+ ptr--;
138
+ }
139
+ pod_allocator<cell_type*>::deallocate(m_cells, m_max_blocks);
140
+ }
141
+ }
142
+
143
+ //------------------------------------------------------------------------
144
+ template<class Cell>
145
+ rasterizer_cells_aa<Cell>::rasterizer_cells_aa(unsigned cell_block_limit) :
146
+ m_num_blocks(0),
147
+ m_max_blocks(0),
148
+ m_curr_block(0),
149
+ m_num_cells(0),
150
+ m_cell_block_limit(cell_block_limit),
151
+ m_cells(0),
152
+ m_curr_cell_ptr(0),
153
+ m_sorted_cells(),
154
+ m_sorted_y(),
155
+ m_min_x(0x7FFFFFFF),
156
+ m_min_y(0x7FFFFFFF),
157
+ m_max_x(-0x7FFFFFFF),
158
+ m_max_y(-0x7FFFFFFF),
159
+ m_sorted(false)
160
+ {
161
+ m_style_cell.initial();
162
+ m_curr_cell.initial();
163
+ }
164
+
165
+ //------------------------------------------------------------------------
166
+ template<class Cell>
167
+ void rasterizer_cells_aa<Cell>::reset()
168
+ {
169
+ m_num_cells = 0;
170
+ m_curr_block = 0;
171
+ m_curr_cell.initial();
172
+ m_style_cell.initial();
173
+ m_sorted = false;
174
+ m_min_x = 0x7FFFFFFF;
175
+ m_min_y = 0x7FFFFFFF;
176
+ m_max_x = -0x7FFFFFFF;
177
+ m_max_y = -0x7FFFFFFF;
178
+ }
179
+
180
+ //------------------------------------------------------------------------
181
+ template<class Cell>
182
+ AGG_INLINE void rasterizer_cells_aa<Cell>::add_curr_cell()
183
+ {
184
+ if(m_curr_cell.area | m_curr_cell.cover)
185
+ {
186
+ if((m_num_cells & cell_block_mask) == 0)
187
+ {
188
+ if(m_num_blocks >= m_cell_block_limit) {
189
+ throw std::overflow_error("Exceeded cell block limit");
190
+ }
191
+ allocate_block();
192
+ }
193
+ *m_curr_cell_ptr++ = m_curr_cell;
194
+ ++m_num_cells;
195
+ }
196
+ }
197
+
198
+ //------------------------------------------------------------------------
199
+ template<class Cell>
200
+ AGG_INLINE void rasterizer_cells_aa<Cell>::set_curr_cell(int x, int y)
201
+ {
202
+ if(m_curr_cell.not_equal(x, y, m_style_cell))
203
+ {
204
+ add_curr_cell();
205
+ m_curr_cell.style(m_style_cell);
206
+ m_curr_cell.x = x;
207
+ m_curr_cell.y = y;
208
+ m_curr_cell.cover = 0;
209
+ m_curr_cell.area = 0;
210
+ }
211
+ }
212
+
213
+ //------------------------------------------------------------------------
214
+ template<class Cell>
215
+ AGG_INLINE void rasterizer_cells_aa<Cell>::render_hline(int ey,
216
+ int x1, int y1,
217
+ int x2, int y2)
218
+ {
219
+ int ex1 = x1 >> poly_subpixel_shift;
220
+ int ex2 = x2 >> poly_subpixel_shift;
221
+ int fx1 = x1 & poly_subpixel_mask;
222
+ int fx2 = x2 & poly_subpixel_mask;
223
+
224
+ int delta, p, first, dx;
225
+ int incr, lift, mod, rem;
226
+
227
+ //trivial case. Happens often
228
+ if(y1 == y2)
229
+ {
230
+ set_curr_cell(ex2, ey);
231
+ return;
232
+ }
233
+
234
+ //everything is located in a single cell. That is easy!
235
+ if(ex1 == ex2)
236
+ {
237
+ delta = y2 - y1;
238
+ m_curr_cell.cover += delta;
239
+ m_curr_cell.area += (fx1 + fx2) * delta;
240
+ return;
241
+ }
242
+
243
+ //ok, we'll have to render a run of adjacent cells on the same
244
+ //hline...
245
+ p = (poly_subpixel_scale - fx1) * (y2 - y1);
246
+ first = poly_subpixel_scale;
247
+ incr = 1;
248
+
249
+ dx = x2 - x1;
250
+
251
+ if(dx < 0)
252
+ {
253
+ p = fx1 * (y2 - y1);
254
+ first = 0;
255
+ incr = -1;
256
+ dx = -dx;
257
+ }
258
+
259
+ delta = p / dx;
260
+ mod = p % dx;
261
+
262
+ if(mod < 0)
263
+ {
264
+ delta--;
265
+ mod += dx;
266
+ }
267
+
268
+ m_curr_cell.cover += delta;
269
+ m_curr_cell.area += (fx1 + first) * delta;
270
+
271
+ ex1 += incr;
272
+ set_curr_cell(ex1, ey);
273
+ y1 += delta;
274
+
275
+ if(ex1 != ex2)
276
+ {
277
+ p = poly_subpixel_scale * (y2 - y1 + delta);
278
+ lift = p / dx;
279
+ rem = p % dx;
280
+
281
+ if (rem < 0)
282
+ {
283
+ lift--;
284
+ rem += dx;
285
+ }
286
+
287
+ mod -= dx;
288
+
289
+ while (ex1 != ex2)
290
+ {
291
+ delta = lift;
292
+ mod += rem;
293
+ if(mod >= 0)
294
+ {
295
+ mod -= dx;
296
+ delta++;
297
+ }
298
+
299
+ m_curr_cell.cover += delta;
300
+ m_curr_cell.area += poly_subpixel_scale * delta;
301
+ y1 += delta;
302
+ ex1 += incr;
303
+ set_curr_cell(ex1, ey);
304
+ }
305
+ }
306
+ delta = y2 - y1;
307
+ m_curr_cell.cover += delta;
308
+ m_curr_cell.area += (fx2 + poly_subpixel_scale - first) * delta;
309
+ }
310
+
311
+ //------------------------------------------------------------------------
312
+ template<class Cell>
313
+ AGG_INLINE void rasterizer_cells_aa<Cell>::style(const cell_type& style_cell)
314
+ {
315
+ m_style_cell.style(style_cell);
316
+ }
317
+
318
+ //------------------------------------------------------------------------
319
+ template<class Cell>
320
+ void rasterizer_cells_aa<Cell>::line(int x1, int y1, int x2, int y2)
321
+ {
322
+ enum dx_limit_e { dx_limit = 16384 << poly_subpixel_shift };
323
+
324
+ int dx = x2 - x1;
325
+
326
+ if(dx >= dx_limit || dx <= -dx_limit)
327
+ {
328
+ int cx = (x1 + x2) >> 1;
329
+ int cy = (y1 + y2) >> 1;
330
+ line(x1, y1, cx, cy);
331
+ line(cx, cy, x2, y2);
332
+ return;
333
+ }
334
+
335
+ int dy = y2 - y1;
336
+ int ex1 = x1 >> poly_subpixel_shift;
337
+ int ex2 = x2 >> poly_subpixel_shift;
338
+ int ey1 = y1 >> poly_subpixel_shift;
339
+ int ey2 = y2 >> poly_subpixel_shift;
340
+ int fy1 = y1 & poly_subpixel_mask;
341
+ int fy2 = y2 & poly_subpixel_mask;
342
+
343
+ int x_from, x_to;
344
+ int p, rem, mod, lift, delta, first, incr;
345
+
346
+ if(ex1 < m_min_x) m_min_x = ex1;
347
+ if(ex1 > m_max_x) m_max_x = ex1;
348
+ if(ey1 < m_min_y) m_min_y = ey1;
349
+ if(ey1 > m_max_y) m_max_y = ey1;
350
+ if(ex2 < m_min_x) m_min_x = ex2;
351
+ if(ex2 > m_max_x) m_max_x = ex2;
352
+ if(ey2 < m_min_y) m_min_y = ey2;
353
+ if(ey2 > m_max_y) m_max_y = ey2;
354
+
355
+ set_curr_cell(ex1, ey1);
356
+
357
+ //everything is on a single hline
358
+ if(ey1 == ey2)
359
+ {
360
+ render_hline(ey1, x1, fy1, x2, fy2);
361
+ return;
362
+ }
363
+
364
+ //Vertical line - we have to calculate start and end cells,
365
+ //and then - the common values of the area and coverage for
366
+ //all cells of the line. We know exactly there's only one
367
+ //cell, so, we don't have to call render_hline().
368
+ incr = 1;
369
+ if(dx == 0)
370
+ {
371
+ int ex = x1 >> poly_subpixel_shift;
372
+ int two_fx = (x1 - (ex << poly_subpixel_shift)) << 1;
373
+ int area;
374
+
375
+ first = poly_subpixel_scale;
376
+ if(dy < 0)
377
+ {
378
+ first = 0;
379
+ incr = -1;
380
+ }
381
+
382
+ x_from = x1;
383
+
384
+ //render_hline(ey1, x_from, fy1, x_from, first);
385
+ delta = first - fy1;
386
+ m_curr_cell.cover += delta;
387
+ m_curr_cell.area += two_fx * delta;
388
+
389
+ ey1 += incr;
390
+ set_curr_cell(ex, ey1);
391
+
392
+ delta = first + first - poly_subpixel_scale;
393
+ area = two_fx * delta;
394
+ while(ey1 != ey2)
395
+ {
396
+ //render_hline(ey1, x_from, poly_subpixel_scale - first, x_from, first);
397
+ m_curr_cell.cover = delta;
398
+ m_curr_cell.area = area;
399
+ ey1 += incr;
400
+ set_curr_cell(ex, ey1);
401
+ }
402
+ //render_hline(ey1, x_from, poly_subpixel_scale - first, x_from, fy2);
403
+ delta = fy2 - poly_subpixel_scale + first;
404
+ m_curr_cell.cover += delta;
405
+ m_curr_cell.area += two_fx * delta;
406
+ return;
407
+ }
408
+
409
+ //ok, we have to render several hlines
410
+ p = (poly_subpixel_scale - fy1) * dx;
411
+ first = poly_subpixel_scale;
412
+
413
+ if(dy < 0)
414
+ {
415
+ p = fy1 * dx;
416
+ first = 0;
417
+ incr = -1;
418
+ dy = -dy;
419
+ }
420
+
421
+ delta = p / dy;
422
+ mod = p % dy;
423
+
424
+ if(mod < 0)
425
+ {
426
+ delta--;
427
+ mod += dy;
428
+ }
429
+
430
+ x_from = x1 + delta;
431
+ render_hline(ey1, x1, fy1, x_from, first);
432
+
433
+ ey1 += incr;
434
+ set_curr_cell(x_from >> poly_subpixel_shift, ey1);
435
+
436
+ if(ey1 != ey2)
437
+ {
438
+ p = poly_subpixel_scale * dx;
439
+ lift = p / dy;
440
+ rem = p % dy;
441
+
442
+ if(rem < 0)
443
+ {
444
+ lift--;
445
+ rem += dy;
446
+ }
447
+ mod -= dy;
448
+
449
+ while(ey1 != ey2)
450
+ {
451
+ delta = lift;
452
+ mod += rem;
453
+ if (mod >= 0)
454
+ {
455
+ mod -= dy;
456
+ delta++;
457
+ }
458
+
459
+ x_to = x_from + delta;
460
+ render_hline(ey1, x_from, poly_subpixel_scale - first, x_to, first);
461
+ x_from = x_to;
462
+
463
+ ey1 += incr;
464
+ set_curr_cell(x_from >> poly_subpixel_shift, ey1);
465
+ }
466
+ }
467
+ render_hline(ey1, x_from, poly_subpixel_scale - first, x2, fy2);
468
+ }
469
+
470
+ //------------------------------------------------------------------------
471
+ template<class Cell>
472
+ void rasterizer_cells_aa<Cell>::allocate_block()
473
+ {
474
+ if(m_curr_block >= m_num_blocks)
475
+ {
476
+ if(m_num_blocks >= m_max_blocks)
477
+ {
478
+ cell_type** new_cells =
479
+ pod_allocator<cell_type*>::allocate(m_max_blocks +
480
+ cell_block_pool);
481
+
482
+ if(m_cells)
483
+ {
484
+ memcpy(new_cells, m_cells, m_max_blocks * sizeof(cell_type*));
485
+ pod_allocator<cell_type*>::deallocate(m_cells, m_max_blocks);
486
+ }
487
+ m_cells = new_cells;
488
+ m_max_blocks += cell_block_pool;
489
+ }
490
+
491
+ m_cells[m_num_blocks++] =
492
+ pod_allocator<cell_type>::allocate(cell_block_size);
493
+
494
+ }
495
+ m_curr_cell_ptr = m_cells[m_curr_block++];
496
+ }
497
+
498
+
499
+
500
+ //------------------------------------------------------------------------
501
+ template <class T> static AGG_INLINE void swap_cells(T* a, T* b)
502
+ {
503
+ T temp = *a;
504
+ *a = *b;
505
+ *b = temp;
506
+ }
507
+
508
+
509
+ //------------------------------------------------------------------------
510
+ enum
511
+ {
512
+ qsort_threshold = 9
513
+ };
514
+
515
+
516
+ //------------------------------------------------------------------------
517
+ template<class Cell>
518
+ void qsort_cells(Cell** start, unsigned num)
519
+ {
520
+ Cell** stack[80];
521
+ Cell*** top;
522
+ Cell** limit;
523
+ Cell** base;
524
+
525
+ limit = start + num;
526
+ base = start;
527
+ top = stack;
528
+
529
+ for (;;)
530
+ {
531
+ int len = int(limit - base);
532
+
533
+ Cell** i;
534
+ Cell** j;
535
+ Cell** pivot;
536
+
537
+ if(len > qsort_threshold)
538
+ {
539
+ // we use base + len/2 as the pivot
540
+ pivot = base + len / 2;
541
+ swap_cells(base, pivot);
542
+
543
+ i = base + 1;
544
+ j = limit - 1;
545
+
546
+ // now ensure that *i <= *base <= *j
547
+ if((*j)->x < (*i)->x)
548
+ {
549
+ swap_cells(i, j);
550
+ }
551
+
552
+ if((*base)->x < (*i)->x)
553
+ {
554
+ swap_cells(base, i);
555
+ }
556
+
557
+ if((*j)->x < (*base)->x)
558
+ {
559
+ swap_cells(base, j);
560
+ }
561
+
562
+ for(;;)
563
+ {
564
+ int x = (*base)->x;
565
+ do i++; while( (*i)->x < x );
566
+ do j--; while( x < (*j)->x );
567
+
568
+ if(i > j)
569
+ {
570
+ break;
571
+ }
572
+
573
+ swap_cells(i, j);
574
+ }
575
+
576
+ swap_cells(base, j);
577
+
578
+ // now, push the largest sub-array
579
+ if(j - base > limit - i)
580
+ {
581
+ top[0] = base;
582
+ top[1] = j;
583
+ base = i;
584
+ }
585
+ else
586
+ {
587
+ top[0] = i;
588
+ top[1] = limit;
589
+ limit = j;
590
+ }
591
+ top += 2;
592
+ }
593
+ else
594
+ {
595
+ // the sub-array is small, perform insertion sort
596
+ j = base;
597
+ i = j + 1;
598
+
599
+ for(; i < limit; j = i, i++)
600
+ {
601
+ for(; j[1]->x < (*j)->x; j--)
602
+ {
603
+ swap_cells(j + 1, j);
604
+ if (j == base)
605
+ {
606
+ break;
607
+ }
608
+ }
609
+ }
610
+
611
+ if(top > stack)
612
+ {
613
+ top -= 2;
614
+ base = top[0];
615
+ limit = top[1];
616
+ }
617
+ else
618
+ {
619
+ break;
620
+ }
621
+ }
622
+ }
623
+ }
624
+
625
+
626
+ //------------------------------------------------------------------------
627
+ template<class Cell>
628
+ void rasterizer_cells_aa<Cell>::sort_cells()
629
+ {
630
+ if(m_sorted) return; //Perform sort only the first time.
631
+
632
+ add_curr_cell();
633
+ m_curr_cell.x = 0x7FFFFFFF;
634
+ m_curr_cell.y = 0x7FFFFFFF;
635
+ m_curr_cell.cover = 0;
636
+ m_curr_cell.area = 0;
637
+
638
+ if(m_num_cells == 0) return;
639
+
640
+ // DBG: Check to see if min/max works well.
641
+ //for(unsigned nc = 0; nc < m_num_cells; nc++)
642
+ //{
643
+ // cell_type* cell = m_cells[nc >> cell_block_shift] + (nc & cell_block_mask);
644
+ // if(cell->x < m_min_x ||
645
+ // cell->y < m_min_y ||
646
+ // cell->x > m_max_x ||
647
+ // cell->y > m_max_y)
648
+ // {
649
+ // cell = cell; // Breakpoint here
650
+ // }
651
+ //}
652
+ // Allocate the array of cell pointers
653
+ m_sorted_cells.allocate(m_num_cells, 16);
654
+
655
+ // Allocate and zero the Y array
656
+ m_sorted_y.allocate(m_max_y - m_min_y + 1, 16);
657
+ m_sorted_y.zero();
658
+
659
+ // Create the Y-histogram (count the numbers of cells for each Y)
660
+ cell_type** block_ptr = m_cells;
661
+ cell_type* cell_ptr;
662
+ unsigned nb = m_num_cells;
663
+ unsigned i;
664
+ while(nb)
665
+ {
666
+ cell_ptr = *block_ptr++;
667
+ i = (nb > cell_block_size) ? cell_block_size : nb;
668
+ nb -= i;
669
+ while(i--)
670
+ {
671
+ m_sorted_y[cell_ptr->y - m_min_y].start++;
672
+ ++cell_ptr;
673
+ }
674
+ }
675
+
676
+ // Convert the Y-histogram into the array of starting indexes
677
+ unsigned start = 0;
678
+ for(i = 0; i < m_sorted_y.size(); i++)
679
+ {
680
+ unsigned v = m_sorted_y[i].start;
681
+ m_sorted_y[i].start = start;
682
+ start += v;
683
+ }
684
+
685
+ // Fill the cell pointer array sorted by Y
686
+ block_ptr = m_cells;
687
+ nb = m_num_cells;
688
+ while(nb)
689
+ {
690
+ cell_ptr = *block_ptr++;
691
+ i = (nb > cell_block_size) ? cell_block_size : nb;
692
+ nb -= i;
693
+ while(i--)
694
+ {
695
+ sorted_y& curr_y = m_sorted_y[cell_ptr->y - m_min_y];
696
+ m_sorted_cells[curr_y.start + curr_y.num] = cell_ptr;
697
+ ++curr_y.num;
698
+ ++cell_ptr;
699
+ }
700
+ }
701
+
702
+ // Finally arrange the X-arrays
703
+ for(i = 0; i < m_sorted_y.size(); i++)
704
+ {
705
+ const sorted_y& curr_y = m_sorted_y[i];
706
+ if(curr_y.num)
707
+ {
708
+ qsort_cells(m_sorted_cells.data() + curr_y.start, curr_y.num);
709
+ }
710
+ }
711
+ m_sorted = true;
712
+ }
713
+
714
+
715
+
716
+ //------------------------------------------------------scanline_hit_test
717
+ class scanline_hit_test
718
+ {
719
+ public:
720
+ scanline_hit_test(int x) : m_x(x), m_hit(false) {}
721
+
722
+ void reset_spans() {}
723
+ void finalize(int) {}
724
+ void add_cell(int x, int)
725
+ {
726
+ if(m_x == x) m_hit = true;
727
+ }
728
+ void add_span(int x, int len, int)
729
+ {
730
+ if(m_x >= x && m_x < x+len) m_hit = true;
731
+ }
732
+ unsigned num_spans() const { return 1; }
733
+ bool hit() const { return m_hit; }
734
+
735
+ private:
736
+ int m_x;
737
+ bool m_hit;
738
+ };
739
+
740
+
741
+ }
742
+
743
+ #endif
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_scanline_boolean_algebra.h ADDED
@@ -0,0 +1,1567 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+
16
+ #ifndef AGG_SCANLINE_BOOLEAN_ALGEBRA_INCLUDED
17
+ #define AGG_SCANLINE_BOOLEAN_ALGEBRA_INCLUDED
18
+
19
+ #include <stdlib.h>
20
+ #include <math.h>
21
+ #include "agg_basics.h"
22
+
23
+
24
+ namespace agg
25
+ {
26
+
27
+ //-----------------------------------------------sbool_combine_spans_bin
28
+ // Functor.
29
+ // Combine two binary encoded spans, i.e., when we don't have any
30
+ // anti-aliasing information, but only X and Length. The function
31
+ // is compatible with any type of scanlines.
32
+ //----------------
33
+ template<class Scanline1,
34
+ class Scanline2,
35
+ class Scanline>
36
+ struct sbool_combine_spans_bin
37
+ {
38
+ void operator () (const typename Scanline1::const_iterator&,
39
+ const typename Scanline2::const_iterator&,
40
+ int x, unsigned len,
41
+ Scanline& sl) const
42
+ {
43
+ sl.add_span(x, len, cover_full);
44
+ }
45
+ };
46
+
47
+
48
+
49
+ //---------------------------------------------sbool_combine_spans_empty
50
+ // Functor.
51
+ // Combine two spans as empty ones. The functor does nothing
52
+ // and is used to XOR binary spans.
53
+ //----------------
54
+ template<class Scanline1,
55
+ class Scanline2,
56
+ class Scanline>
57
+ struct sbool_combine_spans_empty
58
+ {
59
+ void operator () (const typename Scanline1::const_iterator&,
60
+ const typename Scanline2::const_iterator&,
61
+ int, unsigned,
62
+ Scanline&) const
63
+ {}
64
+ };
65
+
66
+
67
+
68
+ //--------------------------------------------------sbool_add_span_empty
69
+ // Functor.
70
+ // Add nothing. Used in conbine_shapes_sub
71
+ //----------------
72
+ template<class Scanline1,
73
+ class Scanline>
74
+ struct sbool_add_span_empty
75
+ {
76
+ void operator () (const typename Scanline1::const_iterator&,
77
+ int, unsigned,
78
+ Scanline&) const
79
+ {}
80
+ };
81
+
82
+
83
+ //----------------------------------------------------sbool_add_span_bin
84
+ // Functor.
85
+ // Add a binary span
86
+ //----------------
87
+ template<class Scanline1,
88
+ class Scanline>
89
+ struct sbool_add_span_bin
90
+ {
91
+ void operator () (const typename Scanline1::const_iterator&,
92
+ int x, unsigned len,
93
+ Scanline& sl) const
94
+ {
95
+ sl.add_span(x, len, cover_full);
96
+ }
97
+ };
98
+
99
+
100
+
101
+
102
+ //-----------------------------------------------------sbool_add_span_aa
103
+ // Functor.
104
+ // Add an anti-aliased span
105
+ // anti-aliasing information, but only X and Length. The function
106
+ // is compatible with any type of scanlines.
107
+ //----------------
108
+ template<class Scanline1,
109
+ class Scanline>
110
+ struct sbool_add_span_aa
111
+ {
112
+ void operator () (const typename Scanline1::const_iterator& span,
113
+ int x, unsigned len,
114
+ Scanline& sl) const
115
+ {
116
+ if(span->len < 0)
117
+ {
118
+ sl.add_span(x, len, *span->covers);
119
+ }
120
+ else
121
+ if(span->len > 0)
122
+ {
123
+ const typename Scanline1::cover_type* covers = span->covers;
124
+ if(span->x < x) covers += x - span->x;
125
+ sl.add_cells(x, len, covers);
126
+ }
127
+ }
128
+ };
129
+
130
+
131
+
132
+
133
+ //----------------------------------------------sbool_intersect_spans_aa
134
+ // Functor.
135
+ // Intersect two spans preserving the anti-aliasing information.
136
+ // The result is added to the "sl" scanline.
137
+ //------------------
138
+ template<class Scanline1,
139
+ class Scanline2,
140
+ class Scanline,
141
+ unsigned CoverShift = cover_shift>
142
+ struct sbool_intersect_spans_aa
143
+ {
144
+ enum cover_scale_e
145
+ {
146
+ cover_shift = CoverShift,
147
+ cover_size = 1 << cover_shift,
148
+ cover_mask = cover_size - 1,
149
+ cover_full = cover_mask
150
+ };
151
+
152
+
153
+ void operator () (const typename Scanline1::const_iterator& span1,
154
+ const typename Scanline2::const_iterator& span2,
155
+ int x, unsigned len,
156
+ Scanline& sl) const
157
+ {
158
+ unsigned cover;
159
+ const typename Scanline1::cover_type* covers1;
160
+ const typename Scanline2::cover_type* covers2;
161
+
162
+ // Calculate the operation code and choose the
163
+ // proper combination algorithm.
164
+ // 0 = Both spans are of AA type
165
+ // 1 = span1 is solid, span2 is AA
166
+ // 2 = span1 is AA, span2 is solid
167
+ // 3 = Both spans are of solid type
168
+ //-----------------
169
+ switch((span1->len < 0) | ((span2->len < 0) << 1))
170
+ {
171
+ case 0: // Both are AA spans
172
+ covers1 = span1->covers;
173
+ covers2 = span2->covers;
174
+ if(span1->x < x) covers1 += x - span1->x;
175
+ if(span2->x < x) covers2 += x - span2->x;
176
+ do
177
+ {
178
+ cover = *covers1++ * *covers2++;
179
+ sl.add_cell(x++,
180
+ (cover == cover_full * cover_full) ?
181
+ cover_full :
182
+ (cover >> cover_shift));
183
+ }
184
+ while(--len);
185
+ break;
186
+
187
+ case 1: // span1 is solid, span2 is AA
188
+ covers2 = span2->covers;
189
+ if(span2->x < x) covers2 += x - span2->x;
190
+ if(*(span1->covers) == cover_full)
191
+ {
192
+ sl.add_cells(x, len, covers2);
193
+ }
194
+ else
195
+ {
196
+ do
197
+ {
198
+ cover = *(span1->covers) * *covers2++;
199
+ sl.add_cell(x++,
200
+ (cover == cover_full * cover_full) ?
201
+ cover_full :
202
+ (cover >> cover_shift));
203
+ }
204
+ while(--len);
205
+ }
206
+ break;
207
+
208
+ case 2: // span1 is AA, span2 is solid
209
+ covers1 = span1->covers;
210
+ if(span1->x < x) covers1 += x - span1->x;
211
+ if(*(span2->covers) == cover_full)
212
+ {
213
+ sl.add_cells(x, len, covers1);
214
+ }
215
+ else
216
+ {
217
+ do
218
+ {
219
+ cover = *covers1++ * *(span2->covers);
220
+ sl.add_cell(x++,
221
+ (cover == cover_full * cover_full) ?
222
+ cover_full :
223
+ (cover >> cover_shift));
224
+ }
225
+ while(--len);
226
+ }
227
+ break;
228
+
229
+ case 3: // Both are solid spans
230
+ cover = *(span1->covers) * *(span2->covers);
231
+ sl.add_span(x, len,
232
+ (cover == cover_full * cover_full) ?
233
+ cover_full :
234
+ (cover >> cover_shift));
235
+ break;
236
+ }
237
+ }
238
+ };
239
+
240
+
241
+
242
+
243
+
244
+
245
+ //--------------------------------------------------sbool_unite_spans_aa
246
+ // Functor.
247
+ // Unite two spans preserving the anti-aliasing information.
248
+ // The result is added to the "sl" scanline.
249
+ //------------------
250
+ template<class Scanline1,
251
+ class Scanline2,
252
+ class Scanline,
253
+ unsigned CoverShift = cover_shift>
254
+ struct sbool_unite_spans_aa
255
+ {
256
+ enum cover_scale_e
257
+ {
258
+ cover_shift = CoverShift,
259
+ cover_size = 1 << cover_shift,
260
+ cover_mask = cover_size - 1,
261
+ cover_full = cover_mask
262
+ };
263
+
264
+
265
+ void operator () (const typename Scanline1::const_iterator& span1,
266
+ const typename Scanline2::const_iterator& span2,
267
+ int x, unsigned len,
268
+ Scanline& sl) const
269
+ {
270
+ unsigned cover;
271
+ const typename Scanline1::cover_type* covers1;
272
+ const typename Scanline2::cover_type* covers2;
273
+
274
+ // Calculate the operation code and choose the
275
+ // proper combination algorithm.
276
+ // 0 = Both spans are of AA type
277
+ // 1 = span1 is solid, span2 is AA
278
+ // 2 = span1 is AA, span2 is solid
279
+ // 3 = Both spans are of solid type
280
+ //-----------------
281
+ switch((span1->len < 0) | ((span2->len < 0) << 1))
282
+ {
283
+ case 0: // Both are AA spans
284
+ covers1 = span1->covers;
285
+ covers2 = span2->covers;
286
+ if(span1->x < x) covers1 += x - span1->x;
287
+ if(span2->x < x) covers2 += x - span2->x;
288
+ do
289
+ {
290
+ cover = cover_mask * cover_mask -
291
+ (cover_mask - *covers1++) *
292
+ (cover_mask - *covers2++);
293
+ sl.add_cell(x++,
294
+ (cover == cover_full * cover_full) ?
295
+ cover_full :
296
+ (cover >> cover_shift));
297
+ }
298
+ while(--len);
299
+ break;
300
+
301
+ case 1: // span1 is solid, span2 is AA
302
+ covers2 = span2->covers;
303
+ if(span2->x < x) covers2 += x - span2->x;
304
+ if(*(span1->covers) == cover_full)
305
+ {
306
+ sl.add_span(x, len, cover_full);
307
+ }
308
+ else
309
+ {
310
+ do
311
+ {
312
+ cover = cover_mask * cover_mask -
313
+ (cover_mask - *(span1->covers)) *
314
+ (cover_mask - *covers2++);
315
+ sl.add_cell(x++,
316
+ (cover == cover_full * cover_full) ?
317
+ cover_full :
318
+ (cover >> cover_shift));
319
+ }
320
+ while(--len);
321
+ }
322
+ break;
323
+
324
+ case 2: // span1 is AA, span2 is solid
325
+ covers1 = span1->covers;
326
+ if(span1->x < x) covers1 += x - span1->x;
327
+ if(*(span2->covers) == cover_full)
328
+ {
329
+ sl.add_span(x, len, cover_full);
330
+ }
331
+ else
332
+ {
333
+ do
334
+ {
335
+ cover = cover_mask * cover_mask -
336
+ (cover_mask - *covers1++) *
337
+ (cover_mask - *(span2->covers));
338
+ sl.add_cell(x++,
339
+ (cover == cover_full * cover_full) ?
340
+ cover_full :
341
+ (cover >> cover_shift));
342
+ }
343
+ while(--len);
344
+ }
345
+ break;
346
+
347
+ case 3: // Both are solid spans
348
+ cover = cover_mask * cover_mask -
349
+ (cover_mask - *(span1->covers)) *
350
+ (cover_mask - *(span2->covers));
351
+ sl.add_span(x, len,
352
+ (cover == cover_full * cover_full) ?
353
+ cover_full :
354
+ (cover >> cover_shift));
355
+ break;
356
+ }
357
+ }
358
+ };
359
+
360
+
361
+ //---------------------------------------------sbool_xor_formula_linear
362
+ template<unsigned CoverShift = cover_shift>
363
+ struct sbool_xor_formula_linear
364
+ {
365
+ enum cover_scale_e
366
+ {
367
+ cover_shift = CoverShift,
368
+ cover_size = 1 << cover_shift,
369
+ cover_mask = cover_size - 1
370
+ };
371
+
372
+ static AGG_INLINE unsigned calculate(unsigned a, unsigned b)
373
+ {
374
+ unsigned cover = a + b;
375
+ if(cover > cover_mask) cover = cover_mask + cover_mask - cover;
376
+ return cover;
377
+ }
378
+ };
379
+
380
+
381
+ //---------------------------------------------sbool_xor_formula_saddle
382
+ template<unsigned CoverShift = cover_shift>
383
+ struct sbool_xor_formula_saddle
384
+ {
385
+ enum cover_scale_e
386
+ {
387
+ cover_shift = CoverShift,
388
+ cover_size = 1 << cover_shift,
389
+ cover_mask = cover_size - 1
390
+ };
391
+
392
+ static AGG_INLINE unsigned calculate(unsigned a, unsigned b)
393
+ {
394
+ unsigned k = a * b;
395
+ if(k == cover_mask * cover_mask) return 0;
396
+
397
+ a = (cover_mask * cover_mask - (a << cover_shift) + k) >> cover_shift;
398
+ b = (cover_mask * cover_mask - (b << cover_shift) + k) >> cover_shift;
399
+ return cover_mask - ((a * b) >> cover_shift);
400
+ }
401
+ };
402
+
403
+
404
+ //-------------------------------------------sbool_xor_formula_abs_diff
405
+ struct sbool_xor_formula_abs_diff
406
+ {
407
+ static AGG_INLINE unsigned calculate(unsigned a, unsigned b)
408
+ {
409
+ return unsigned(abs(int(a) - int(b)));
410
+ }
411
+ };
412
+
413
+
414
+
415
+ //----------------------------------------------------sbool_xor_spans_aa
416
+ // Functor.
417
+ // XOR two spans preserving the anti-aliasing information.
418
+ // The result is added to the "sl" scanline.
419
+ //------------------
420
+ template<class Scanline1,
421
+ class Scanline2,
422
+ class Scanline,
423
+ class XorFormula,
424
+ unsigned CoverShift = cover_shift>
425
+ struct sbool_xor_spans_aa
426
+ {
427
+ enum cover_scale_e
428
+ {
429
+ cover_shift = CoverShift,
430
+ cover_size = 1 << cover_shift,
431
+ cover_mask = cover_size - 1,
432
+ cover_full = cover_mask
433
+ };
434
+
435
+
436
+ void operator () (const typename Scanline1::const_iterator& span1,
437
+ const typename Scanline2::const_iterator& span2,
438
+ int x, unsigned len,
439
+ Scanline& sl) const
440
+ {
441
+ unsigned cover;
442
+ const typename Scanline1::cover_type* covers1;
443
+ const typename Scanline2::cover_type* covers2;
444
+
445
+ // Calculate the operation code and choose the
446
+ // proper combination algorithm.
447
+ // 0 = Both spans are of AA type
448
+ // 1 = span1 is solid, span2 is AA
449
+ // 2 = span1 is AA, span2 is solid
450
+ // 3 = Both spans are of solid type
451
+ //-----------------
452
+ switch((span1->len < 0) | ((span2->len < 0) << 1))
453
+ {
454
+ case 0: // Both are AA spans
455
+ covers1 = span1->covers;
456
+ covers2 = span2->covers;
457
+ if(span1->x < x) covers1 += x - span1->x;
458
+ if(span2->x < x) covers2 += x - span2->x;
459
+ do
460
+ {
461
+ cover = XorFormula::calculate(*covers1++, *covers2++);
462
+ if(cover) sl.add_cell(x, cover);
463
+ ++x;
464
+ }
465
+ while(--len);
466
+ break;
467
+
468
+ case 1: // span1 is solid, span2 is AA
469
+ covers2 = span2->covers;
470
+ if(span2->x < x) covers2 += x - span2->x;
471
+ do
472
+ {
473
+ cover = XorFormula::calculate(*(span1->covers), *covers2++);
474
+ if(cover) sl.add_cell(x, cover);
475
+ ++x;
476
+ }
477
+ while(--len);
478
+ break;
479
+
480
+ case 2: // span1 is AA, span2 is solid
481
+ covers1 = span1->covers;
482
+ if(span1->x < x) covers1 += x - span1->x;
483
+ do
484
+ {
485
+ cover = XorFormula::calculate(*covers1++, *(span2->covers));
486
+ if(cover) sl.add_cell(x, cover);
487
+ ++x;
488
+ }
489
+ while(--len);
490
+ break;
491
+
492
+ case 3: // Both are solid spans
493
+ cover = XorFormula::calculate(*(span1->covers), *(span2->covers));
494
+ if(cover) sl.add_span(x, len, cover);
495
+ break;
496
+
497
+ }
498
+ }
499
+ };
500
+
501
+
502
+
503
+
504
+
505
+ //-----------------------------------------------sbool_subtract_spans_aa
506
+ // Functor.
507
+ // Unite two spans preserving the anti-aliasing information.
508
+ // The result is added to the "sl" scanline.
509
+ //------------------
510
+ template<class Scanline1,
511
+ class Scanline2,
512
+ class Scanline,
513
+ unsigned CoverShift = cover_shift>
514
+ struct sbool_subtract_spans_aa
515
+ {
516
+ enum cover_scale_e
517
+ {
518
+ cover_shift = CoverShift,
519
+ cover_size = 1 << cover_shift,
520
+ cover_mask = cover_size - 1,
521
+ cover_full = cover_mask
522
+ };
523
+
524
+
525
+ void operator () (const typename Scanline1::const_iterator& span1,
526
+ const typename Scanline2::const_iterator& span2,
527
+ int x, unsigned len,
528
+ Scanline& sl) const
529
+ {
530
+ unsigned cover;
531
+ const typename Scanline1::cover_type* covers1;
532
+ const typename Scanline2::cover_type* covers2;
533
+
534
+ // Calculate the operation code and choose the
535
+ // proper combination algorithm.
536
+ // 0 = Both spans are of AA type
537
+ // 1 = span1 is solid, span2 is AA
538
+ // 2 = span1 is AA, span2 is solid
539
+ // 3 = Both spans are of solid type
540
+ //-----------------
541
+ switch((span1->len < 0) | ((span2->len < 0) << 1))
542
+ {
543
+ case 0: // Both are AA spans
544
+ covers1 = span1->covers;
545
+ covers2 = span2->covers;
546
+ if(span1->x < x) covers1 += x - span1->x;
547
+ if(span2->x < x) covers2 += x - span2->x;
548
+ do
549
+ {
550
+ cover = *covers1++ * (cover_mask - *covers2++);
551
+ if(cover)
552
+ {
553
+ sl.add_cell(x,
554
+ (cover == cover_full * cover_full) ?
555
+ cover_full :
556
+ (cover >> cover_shift));
557
+ }
558
+ ++x;
559
+ }
560
+ while(--len);
561
+ break;
562
+
563
+ case 1: // span1 is solid, span2 is AA
564
+ covers2 = span2->covers;
565
+ if(span2->x < x) covers2 += x - span2->x;
566
+ do
567
+ {
568
+ cover = *(span1->covers) * (cover_mask - *covers2++);
569
+ if(cover)
570
+ {
571
+ sl.add_cell(x,
572
+ (cover == cover_full * cover_full) ?
573
+ cover_full :
574
+ (cover >> cover_shift));
575
+ }
576
+ ++x;
577
+ }
578
+ while(--len);
579
+ break;
580
+
581
+ case 2: // span1 is AA, span2 is solid
582
+ covers1 = span1->covers;
583
+ if(span1->x < x) covers1 += x - span1->x;
584
+ if(*(span2->covers) != cover_full)
585
+ {
586
+ do
587
+ {
588
+ cover = *covers1++ * (cover_mask - *(span2->covers));
589
+ if(cover)
590
+ {
591
+ sl.add_cell(x,
592
+ (cover == cover_full * cover_full) ?
593
+ cover_full :
594
+ (cover >> cover_shift));
595
+ }
596
+ ++x;
597
+ }
598
+ while(--len);
599
+ }
600
+ break;
601
+
602
+ case 3: // Both are solid spans
603
+ cover = *(span1->covers) * (cover_mask - *(span2->covers));
604
+ if(cover)
605
+ {
606
+ sl.add_span(x, len,
607
+ (cover == cover_full * cover_full) ?
608
+ cover_full :
609
+ (cover >> cover_shift));
610
+ }
611
+ break;
612
+ }
613
+ }
614
+ };
615
+
616
+
617
+
618
+
619
+
620
+
621
+ //--------------------------------------------sbool_add_spans_and_render
622
+ template<class Scanline1,
623
+ class Scanline,
624
+ class Renderer,
625
+ class AddSpanFunctor>
626
+ void sbool_add_spans_and_render(const Scanline1& sl1,
627
+ Scanline& sl,
628
+ Renderer& ren,
629
+ AddSpanFunctor add_span)
630
+ {
631
+ sl.reset_spans();
632
+ typename Scanline1::const_iterator span = sl1.begin();
633
+ unsigned num_spans = sl1.num_spans();
634
+ for(;;)
635
+ {
636
+ add_span(span, span->x, abs((int)span->len), sl);
637
+ if(--num_spans == 0) break;
638
+ ++span;
639
+ }
640
+ sl.finalize(sl1.y());
641
+ ren.render(sl);
642
+ }
643
+
644
+
645
+
646
+
647
+
648
+
649
+
650
+ //---------------------------------------------sbool_intersect_scanlines
651
+ // Intersect two scanlines, "sl1" and "sl2" and generate a new "sl" one.
652
+ // The combine_spans functor can be of type sbool_combine_spans_bin or
653
+ // sbool_intersect_spans_aa. First is a general functor to combine
654
+ // two spans without Anti-Aliasing, the second preserves the AA
655
+ // information, but works slower
656
+ //
657
+ template<class Scanline1,
658
+ class Scanline2,
659
+ class Scanline,
660
+ class CombineSpansFunctor>
661
+ void sbool_intersect_scanlines(const Scanline1& sl1,
662
+ const Scanline2& sl2,
663
+ Scanline& sl,
664
+ CombineSpansFunctor combine_spans)
665
+ {
666
+ sl.reset_spans();
667
+
668
+ unsigned num1 = sl1.num_spans();
669
+ if(num1 == 0) return;
670
+
671
+ unsigned num2 = sl2.num_spans();
672
+ if(num2 == 0) return;
673
+
674
+ typename Scanline1::const_iterator span1 = sl1.begin();
675
+ typename Scanline2::const_iterator span2 = sl2.begin();
676
+
677
+ while(num1 && num2)
678
+ {
679
+ int xb1 = span1->x;
680
+ int xb2 = span2->x;
681
+ int xe1 = xb1 + abs((int)span1->len) - 1;
682
+ int xe2 = xb2 + abs((int)span2->len) - 1;
683
+
684
+ // Determine what spans we should advance in the next step
685
+ // The span with the least ending X should be advanced
686
+ // advance_both is just an optimization when we ending
687
+ // coordinates are the same and we can advance both
688
+ //--------------
689
+ bool advance_span1 = xe1 < xe2;
690
+ bool advance_both = xe1 == xe2;
691
+
692
+ // Find the intersection of the spans
693
+ // and check if they intersect
694
+ //--------------
695
+ if(xb1 < xb2) xb1 = xb2;
696
+ if(xe1 > xe2) xe1 = xe2;
697
+ if(xb1 <= xe1)
698
+ {
699
+ combine_spans(span1, span2, xb1, xe1 - xb1 + 1, sl);
700
+ }
701
+
702
+ // Advance the spans
703
+ //--------------
704
+ if(advance_both)
705
+ {
706
+ --num1;
707
+ --num2;
708
+ if(num1) ++span1;
709
+ if(num2) ++span2;
710
+ }
711
+ else
712
+ {
713
+ if(advance_span1)
714
+ {
715
+ --num1;
716
+ if(num1) ++span1;
717
+ }
718
+ else
719
+ {
720
+ --num2;
721
+ if(num2) ++span2;
722
+ }
723
+ }
724
+ }
725
+ }
726
+
727
+
728
+
729
+
730
+
731
+
732
+
733
+
734
+ //------------------------------------------------sbool_intersect_shapes
735
+ // Intersect the scanline shapes. Here the "Scanline Generator"
736
+ // abstraction is used. ScanlineGen1 and ScanlineGen2 are
737
+ // the generators, and can be of type rasterizer_scanline_aa<>.
738
+ // There function requires three scanline containers that can be of
739
+ // different types.
740
+ // "sl1" and "sl2" are used to retrieve scanlines from the generators,
741
+ // "sl" is ised as the resulting scanline to render it.
742
+ // The external "sl1" and "sl2" are used only for the sake of
743
+ // optimization and reusing of the scanline objects.
744
+ // the function calls sbool_intersect_scanlines with CombineSpansFunctor
745
+ // as the last argument. See sbool_intersect_scanlines for details.
746
+ //----------
747
+ template<class ScanlineGen1,
748
+ class ScanlineGen2,
749
+ class Scanline1,
750
+ class Scanline2,
751
+ class Scanline,
752
+ class Renderer,
753
+ class CombineSpansFunctor>
754
+ void sbool_intersect_shapes(ScanlineGen1& sg1, ScanlineGen2& sg2,
755
+ Scanline1& sl1, Scanline2& sl2,
756
+ Scanline& sl, Renderer& ren,
757
+ CombineSpansFunctor combine_spans)
758
+ {
759
+ // Prepare the scanline generators.
760
+ // If anyone of them doesn't contain
761
+ // any scanlines, then return.
762
+ //-----------------
763
+ if(!sg1.rewind_scanlines()) return;
764
+ if(!sg2.rewind_scanlines()) return;
765
+
766
+ // Get the bounding boxes
767
+ //----------------
768
+ rect_i r1(sg1.min_x(), sg1.min_y(), sg1.max_x(), sg1.max_y());
769
+ rect_i r2(sg2.min_x(), sg2.min_y(), sg2.max_x(), sg2.max_y());
770
+
771
+ // Calculate the intersection of the bounding
772
+ // boxes and return if they don't intersect.
773
+ //-----------------
774
+ rect_i ir = intersect_rectangles(r1, r2);
775
+ if(!ir.is_valid()) return;
776
+
777
+ // Reset the scanlines and get two first ones
778
+ //-----------------
779
+ sl.reset(ir.x1, ir.x2);
780
+ sl1.reset(sg1.min_x(), sg1.max_x());
781
+ sl2.reset(sg2.min_x(), sg2.max_x());
782
+ if(!sg1.sweep_scanline(sl1)) return;
783
+ if(!sg2.sweep_scanline(sl2)) return;
784
+
785
+ ren.prepare();
786
+
787
+ // The main loop
788
+ // Here we synchronize the scanlines with
789
+ // the same Y coordinate, ignoring all other ones.
790
+ // Only scanlines having the same Y-coordinate
791
+ // are to be combined.
792
+ //-----------------
793
+ for(;;)
794
+ {
795
+ while(sl1.y() < sl2.y())
796
+ {
797
+ if(!sg1.sweep_scanline(sl1)) return;
798
+ }
799
+ while(sl2.y() < sl1.y())
800
+ {
801
+ if(!sg2.sweep_scanline(sl2)) return;
802
+ }
803
+
804
+ if(sl1.y() == sl2.y())
805
+ {
806
+ // The Y coordinates are the same.
807
+ // Combine the scanlines, render if they contain any spans,
808
+ // and advance both generators to the next scanlines
809
+ //----------------------
810
+ sbool_intersect_scanlines(sl1, sl2, sl, combine_spans);
811
+ if(sl.num_spans())
812
+ {
813
+ sl.finalize(sl1.y());
814
+ ren.render(sl);
815
+ }
816
+ if(!sg1.sweep_scanline(sl1)) return;
817
+ if(!sg2.sweep_scanline(sl2)) return;
818
+ }
819
+ }
820
+ }
821
+
822
+
823
+
824
+
825
+
826
+
827
+
828
+ //-------------------------------------------------sbool_unite_scanlines
829
+ // Unite two scanlines, "sl1" and "sl2" and generate a new "sl" one.
830
+ // The combine_spans functor can be of type sbool_combine_spans_bin or
831
+ // sbool_intersect_spans_aa. First is a general functor to combine
832
+ // two spans without Anti-Aliasing, the second preserves the AA
833
+ // information, but works slower
834
+ //
835
+ template<class Scanline1,
836
+ class Scanline2,
837
+ class Scanline,
838
+ class AddSpanFunctor1,
839
+ class AddSpanFunctor2,
840
+ class CombineSpansFunctor>
841
+ void sbool_unite_scanlines(const Scanline1& sl1,
842
+ const Scanline2& sl2,
843
+ Scanline& sl,
844
+ AddSpanFunctor1 add_span1,
845
+ AddSpanFunctor2 add_span2,
846
+ CombineSpansFunctor combine_spans)
847
+ {
848
+ sl.reset_spans();
849
+
850
+ unsigned num1 = sl1.num_spans();
851
+ unsigned num2 = sl2.num_spans();
852
+
853
+ typename Scanline1::const_iterator span1;// = sl1.begin();
854
+ typename Scanline2::const_iterator span2;// = sl2.begin();
855
+
856
+ enum invalidation_e
857
+ {
858
+ invalid_b = 0xFFFFFFF,
859
+ invalid_e = invalid_b - 1
860
+ };
861
+
862
+ // Initialize the spans as invalid
863
+ //---------------
864
+ int xb1 = invalid_b;
865
+ int xb2 = invalid_b;
866
+ int xe1 = invalid_e;
867
+ int xe2 = invalid_e;
868
+
869
+ // Initialize span1 if there are spans
870
+ //---------------
871
+ if(num1)
872
+ {
873
+ span1 = sl1.begin();
874
+ xb1 = span1->x;
875
+ xe1 = xb1 + abs((int)span1->len) - 1;
876
+ --num1;
877
+ }
878
+
879
+ // Initialize span2 if there are spans
880
+ //---------------
881
+ if(num2)
882
+ {
883
+ span2 = sl2.begin();
884
+ xb2 = span2->x;
885
+ xe2 = xb2 + abs((int)span2->len) - 1;
886
+ --num2;
887
+ }
888
+
889
+
890
+ for(;;)
891
+ {
892
+ // Retrieve a new span1 if it's invalid
893
+ //----------------
894
+ if(num1 && xb1 > xe1)
895
+ {
896
+ --num1;
897
+ ++span1;
898
+ xb1 = span1->x;
899
+ xe1 = xb1 + abs((int)span1->len) - 1;
900
+ }
901
+
902
+ // Retrieve a new span2 if it's invalid
903
+ //----------------
904
+ if(num2 && xb2 > xe2)
905
+ {
906
+ --num2;
907
+ ++span2;
908
+ xb2 = span2->x;
909
+ xe2 = xb2 + abs((int)span2->len) - 1;
910
+ }
911
+
912
+ if(xb1 > xe1 && xb2 > xe2) break;
913
+
914
+ // Calculate the intersection
915
+ //----------------
916
+ int xb = xb1;
917
+ int xe = xe1;
918
+ if(xb < xb2) xb = xb2;
919
+ if(xe > xe2) xe = xe2;
920
+ int len = xe - xb + 1; // The length of the intersection
921
+ if(len > 0)
922
+ {
923
+ // The spans intersect,
924
+ // add the beginning of the span
925
+ //----------------
926
+ if(xb1 < xb2)
927
+ {
928
+ add_span1(span1, xb1, xb2 - xb1, sl);
929
+ xb1 = xb2;
930
+ }
931
+ else
932
+ if(xb2 < xb1)
933
+ {
934
+ add_span2(span2, xb2, xb1 - xb2, sl);
935
+ xb2 = xb1;
936
+ }
937
+
938
+ // Add the combination part of the spans
939
+ //----------------
940
+ combine_spans(span1, span2, xb, len, sl);
941
+
942
+
943
+ // Invalidate the fully processed span or both
944
+ //----------------
945
+ if(xe1 < xe2)
946
+ {
947
+ // Invalidate span1 and eat
948
+ // the processed part of span2
949
+ //--------------
950
+ xb1 = invalid_b;
951
+ xe1 = invalid_e;
952
+ xb2 += len;
953
+ }
954
+ else
955
+ if(xe2 < xe1)
956
+ {
957
+ // Invalidate span2 and eat
958
+ // the processed part of span1
959
+ //--------------
960
+ xb2 = invalid_b;
961
+ xe2 = invalid_e;
962
+ xb1 += len;
963
+ }
964
+ else
965
+ {
966
+ xb1 = invalid_b; // Invalidate both
967
+ xb2 = invalid_b;
968
+ xe1 = invalid_e;
969
+ xe2 = invalid_e;
970
+ }
971
+ }
972
+ else
973
+ {
974
+ // The spans do not intersect
975
+ //--------------
976
+ if(xb1 < xb2)
977
+ {
978
+ // Advance span1
979
+ //---------------
980
+ if(xb1 <= xe1)
981
+ {
982
+ add_span1(span1, xb1, xe1 - xb1 + 1, sl);
983
+ }
984
+ xb1 = invalid_b; // Invalidate
985
+ xe1 = invalid_e;
986
+ }
987
+ else
988
+ {
989
+ // Advance span2
990
+ //---------------
991
+ if(xb2 <= xe2)
992
+ {
993
+ add_span2(span2, xb2, xe2 - xb2 + 1, sl);
994
+ }
995
+ xb2 = invalid_b; // Invalidate
996
+ xe2 = invalid_e;
997
+ }
998
+ }
999
+ }
1000
+ }
1001
+
1002
+
1003
+
1004
+
1005
+ //----------------------------------------------------sbool_unite_shapes
1006
+ // Unite the scanline shapes. Here the "Scanline Generator"
1007
+ // abstraction is used. ScanlineGen1 and ScanlineGen2 are
1008
+ // the generators, and can be of type rasterizer_scanline_aa<>.
1009
+ // There function requires three scanline containers that can be
1010
+ // of different type.
1011
+ // "sl1" and "sl2" are used to retrieve scanlines from the generators,
1012
+ // "sl" is ised as the resulting scanline to render it.
1013
+ // The external "sl1" and "sl2" are used only for the sake of
1014
+ // optimization and reusing of the scanline objects.
1015
+ // the function calls sbool_unite_scanlines with CombineSpansFunctor
1016
+ // as the last argument. See sbool_unite_scanlines for details.
1017
+ //----------
1018
+ template<class ScanlineGen1,
1019
+ class ScanlineGen2,
1020
+ class Scanline1,
1021
+ class Scanline2,
1022
+ class Scanline,
1023
+ class Renderer,
1024
+ class AddSpanFunctor1,
1025
+ class AddSpanFunctor2,
1026
+ class CombineSpansFunctor>
1027
+ void sbool_unite_shapes(ScanlineGen1& sg1, ScanlineGen2& sg2,
1028
+ Scanline1& sl1, Scanline2& sl2,
1029
+ Scanline& sl, Renderer& ren,
1030
+ AddSpanFunctor1 add_span1,
1031
+ AddSpanFunctor2 add_span2,
1032
+ CombineSpansFunctor combine_spans)
1033
+ {
1034
+ // Prepare the scanline generators.
1035
+ // If anyone of them doesn't contain
1036
+ // any scanlines, then return.
1037
+ //-----------------
1038
+ bool flag1 = sg1.rewind_scanlines();
1039
+ bool flag2 = sg2.rewind_scanlines();
1040
+ if(!flag1 && !flag2) return;
1041
+
1042
+ // Get the bounding boxes
1043
+ //----------------
1044
+ rect_i r1(sg1.min_x(), sg1.min_y(), sg1.max_x(), sg1.max_y());
1045
+ rect_i r2(sg2.min_x(), sg2.min_y(), sg2.max_x(), sg2.max_y());
1046
+
1047
+ // Calculate the union of the bounding boxes
1048
+ //-----------------
1049
+ rect_i ur(1,1,0,0);
1050
+ if(flag1 && flag2) ur = unite_rectangles(r1, r2);
1051
+ else if(flag1) ur = r1;
1052
+ else if(flag2) ur = r2;
1053
+
1054
+ if(!ur.is_valid()) return;
1055
+
1056
+ ren.prepare();
1057
+
1058
+ // Reset the scanlines and get two first ones
1059
+ //-----------------
1060
+ sl.reset(ur.x1, ur.x2);
1061
+ if(flag1)
1062
+ {
1063
+ sl1.reset(sg1.min_x(), sg1.max_x());
1064
+ flag1 = sg1.sweep_scanline(sl1);
1065
+ }
1066
+
1067
+ if(flag2)
1068
+ {
1069
+ sl2.reset(sg2.min_x(), sg2.max_x());
1070
+ flag2 = sg2.sweep_scanline(sl2);
1071
+ }
1072
+
1073
+ // The main loop
1074
+ // Here we synchronize the scanlines with
1075
+ // the same Y coordinate.
1076
+ //-----------------
1077
+ while(flag1 || flag2)
1078
+ {
1079
+ if(flag1 && flag2)
1080
+ {
1081
+ if(sl1.y() == sl2.y())
1082
+ {
1083
+ // The Y coordinates are the same.
1084
+ // Combine the scanlines, render if they contain any spans,
1085
+ // and advance both generators to the next scanlines
1086
+ //----------------------
1087
+ sbool_unite_scanlines(sl1, sl2, sl,
1088
+ add_span1, add_span2, combine_spans);
1089
+ if(sl.num_spans())
1090
+ {
1091
+ sl.finalize(sl1.y());
1092
+ ren.render(sl);
1093
+ }
1094
+ flag1 = sg1.sweep_scanline(sl1);
1095
+ flag2 = sg2.sweep_scanline(sl2);
1096
+ }
1097
+ else
1098
+ {
1099
+ if(sl1.y() < sl2.y())
1100
+ {
1101
+ sbool_add_spans_and_render(sl1, sl, ren, add_span1);
1102
+ flag1 = sg1.sweep_scanline(sl1);
1103
+ }
1104
+ else
1105
+ {
1106
+ sbool_add_spans_and_render(sl2, sl, ren, add_span2);
1107
+ flag2 = sg2.sweep_scanline(sl2);
1108
+ }
1109
+ }
1110
+ }
1111
+ else
1112
+ {
1113
+ if(flag1)
1114
+ {
1115
+ sbool_add_spans_and_render(sl1, sl, ren, add_span1);
1116
+ flag1 = sg1.sweep_scanline(sl1);
1117
+ }
1118
+ if(flag2)
1119
+ {
1120
+ sbool_add_spans_and_render(sl2, sl, ren, add_span2);
1121
+ flag2 = sg2.sweep_scanline(sl2);
1122
+ }
1123
+ }
1124
+ }
1125
+ }
1126
+
1127
+
1128
+
1129
+
1130
+
1131
+
1132
+
1133
+
1134
+ //-------------------------------------------------sbool_subtract_shapes
1135
+ // Subtract the scanline shapes, "sg1-sg2". Here the "Scanline Generator"
1136
+ // abstraction is used. ScanlineGen1 and ScanlineGen2 are
1137
+ // the generators, and can be of type rasterizer_scanline_aa<>.
1138
+ // There function requires three scanline containers that can be of
1139
+ // different types.
1140
+ // "sl1" and "sl2" are used to retrieve scanlines from the generators,
1141
+ // "sl" is ised as the resulting scanline to render it.
1142
+ // The external "sl1" and "sl2" are used only for the sake of
1143
+ // optimization and reusing of the scanline objects.
1144
+ // the function calls sbool_intersect_scanlines with CombineSpansFunctor
1145
+ // as the last argument. See combine_scanlines_sub for details.
1146
+ //----------
1147
+ template<class ScanlineGen1,
1148
+ class ScanlineGen2,
1149
+ class Scanline1,
1150
+ class Scanline2,
1151
+ class Scanline,
1152
+ class Renderer,
1153
+ class AddSpanFunctor1,
1154
+ class CombineSpansFunctor>
1155
+ void sbool_subtract_shapes(ScanlineGen1& sg1, ScanlineGen2& sg2,
1156
+ Scanline1& sl1, Scanline2& sl2,
1157
+ Scanline& sl, Renderer& ren,
1158
+ AddSpanFunctor1 add_span1,
1159
+ CombineSpansFunctor combine_spans)
1160
+ {
1161
+ // Prepare the scanline generators.
1162
+ // Here "sg1" is master, "sg2" is slave.
1163
+ //-----------------
1164
+ if(!sg1.rewind_scanlines()) return;
1165
+ bool flag2 = sg2.rewind_scanlines();
1166
+
1167
+ // Get the bounding box
1168
+ //----------------
1169
+ rect_i r1(sg1.min_x(), sg1.min_y(), sg1.max_x(), sg1.max_y());
1170
+
1171
+ // Reset the scanlines and get two first ones
1172
+ //-----------------
1173
+ sl.reset(sg1.min_x(), sg1.max_x());
1174
+ sl1.reset(sg1.min_x(), sg1.max_x());
1175
+ sl2.reset(sg2.min_x(), sg2.max_x());
1176
+ if(!sg1.sweep_scanline(sl1)) return;
1177
+
1178
+ if(flag2) flag2 = sg2.sweep_scanline(sl2);
1179
+
1180
+ ren.prepare();
1181
+
1182
+ // A fake span2 processor
1183
+ sbool_add_span_empty<Scanline2, Scanline> add_span2;
1184
+
1185
+ // The main loop
1186
+ // Here we synchronize the scanlines with
1187
+ // the same Y coordinate, ignoring all other ones.
1188
+ // Only scanlines having the same Y-coordinate
1189
+ // are to be combined.
1190
+ //-----------------
1191
+ bool flag1 = true;
1192
+ do
1193
+ {
1194
+ // Synchronize "slave" with "master"
1195
+ //-----------------
1196
+ while(flag2 && sl2.y() < sl1.y())
1197
+ {
1198
+ flag2 = sg2.sweep_scanline(sl2);
1199
+ }
1200
+
1201
+
1202
+ if(flag2 && sl2.y() == sl1.y())
1203
+ {
1204
+ // The Y coordinates are the same.
1205
+ // Combine the scanlines and render if they contain any spans.
1206
+ //----------------------
1207
+ sbool_unite_scanlines(sl1, sl2, sl, add_span1, add_span2, combine_spans);
1208
+ if(sl.num_spans())
1209
+ {
1210
+ sl.finalize(sl1.y());
1211
+ ren.render(sl);
1212
+ }
1213
+ }
1214
+ else
1215
+ {
1216
+ sbool_add_spans_and_render(sl1, sl, ren, add_span1);
1217
+ }
1218
+
1219
+ // Advance the "master"
1220
+ flag1 = sg1.sweep_scanline(sl1);
1221
+ }
1222
+ while(flag1);
1223
+ }
1224
+
1225
+
1226
+
1227
+
1228
+
1229
+
1230
+
1231
+ //---------------------------------------------sbool_intersect_shapes_aa
1232
+ // Intersect two anti-aliased scanline shapes.
1233
+ // Here the "Scanline Generator" abstraction is used.
1234
+ // ScanlineGen1 and ScanlineGen2 are the generators, and can be of
1235
+ // type rasterizer_scanline_aa<>. There function requires three
1236
+ // scanline containers that can be of different types.
1237
+ // "sl1" and "sl2" are used to retrieve scanlines from the generators,
1238
+ // "sl" is ised as the resulting scanline to render it.
1239
+ // The external "sl1" and "sl2" are used only for the sake of
1240
+ // optimization and reusing of the scanline objects.
1241
+ //----------
1242
+ template<class ScanlineGen1,
1243
+ class ScanlineGen2,
1244
+ class Scanline1,
1245
+ class Scanline2,
1246
+ class Scanline,
1247
+ class Renderer>
1248
+ void sbool_intersect_shapes_aa(ScanlineGen1& sg1, ScanlineGen2& sg2,
1249
+ Scanline1& sl1, Scanline2& sl2,
1250
+ Scanline& sl, Renderer& ren)
1251
+ {
1252
+ sbool_intersect_spans_aa<Scanline1, Scanline2, Scanline> combine_functor;
1253
+ sbool_intersect_shapes(sg1, sg2, sl1, sl2, sl, ren, combine_functor);
1254
+ }
1255
+
1256
+
1257
+
1258
+
1259
+
1260
+ //--------------------------------------------sbool_intersect_shapes_bin
1261
+ // Intersect two binary scanline shapes (without anti-aliasing).
1262
+ // See intersect_shapes_aa for more comments
1263
+ //----------
1264
+ template<class ScanlineGen1,
1265
+ class ScanlineGen2,
1266
+ class Scanline1,
1267
+ class Scanline2,
1268
+ class Scanline,
1269
+ class Renderer>
1270
+ void sbool_intersect_shapes_bin(ScanlineGen1& sg1, ScanlineGen2& sg2,
1271
+ Scanline1& sl1, Scanline2& sl2,
1272
+ Scanline& sl, Renderer& ren)
1273
+ {
1274
+ sbool_combine_spans_bin<Scanline1, Scanline2, Scanline> combine_functor;
1275
+ sbool_intersect_shapes(sg1, sg2, sl1, sl2, sl, ren, combine_functor);
1276
+ }
1277
+
1278
+
1279
+
1280
+
1281
+
1282
+ //-------------------------------------------------sbool_unite_shapes_aa
1283
+ // Unite two anti-aliased scanline shapes
1284
+ // See intersect_shapes_aa for more comments
1285
+ //----------
1286
+ template<class ScanlineGen1,
1287
+ class ScanlineGen2,
1288
+ class Scanline1,
1289
+ class Scanline2,
1290
+ class Scanline,
1291
+ class Renderer>
1292
+ void sbool_unite_shapes_aa(ScanlineGen1& sg1, ScanlineGen2& sg2,
1293
+ Scanline1& sl1, Scanline2& sl2,
1294
+ Scanline& sl, Renderer& ren)
1295
+ {
1296
+ sbool_add_span_aa<Scanline1, Scanline> add_functor1;
1297
+ sbool_add_span_aa<Scanline2, Scanline> add_functor2;
1298
+ sbool_unite_spans_aa<Scanline1, Scanline2, Scanline> combine_functor;
1299
+ sbool_unite_shapes(sg1, sg2, sl1, sl2, sl, ren,
1300
+ add_functor1, add_functor2, combine_functor);
1301
+ }
1302
+
1303
+
1304
+
1305
+
1306
+
1307
+ //------------------------------------------------sbool_unite_shapes_bin
1308
+ // Unite two binary scanline shapes (without anti-aliasing).
1309
+ // See intersect_shapes_aa for more comments
1310
+ //----------
1311
+ template<class ScanlineGen1,
1312
+ class ScanlineGen2,
1313
+ class Scanline1,
1314
+ class Scanline2,
1315
+ class Scanline,
1316
+ class Renderer>
1317
+ void sbool_unite_shapes_bin(ScanlineGen1& sg1, ScanlineGen2& sg2,
1318
+ Scanline1& sl1, Scanline2& sl2,
1319
+ Scanline& sl, Renderer& ren)
1320
+ {
1321
+ sbool_add_span_bin<Scanline1, Scanline> add_functor1;
1322
+ sbool_add_span_bin<Scanline2, Scanline> add_functor2;
1323
+ sbool_combine_spans_bin<Scanline1, Scanline2, Scanline> combine_functor;
1324
+ sbool_unite_shapes(sg1, sg2, sl1, sl2, sl, ren,
1325
+ add_functor1, add_functor2, combine_functor);
1326
+ }
1327
+
1328
+
1329
+
1330
+
1331
+
1332
+
1333
+
1334
+
1335
+
1336
+ //---------------------------------------------------sbool_xor_shapes_aa
1337
+ // Apply eXclusive OR to two anti-aliased scanline shapes. There's
1338
+ // a modified "Linear" XOR used instead of classical "Saddle" one.
1339
+ // The reason is to have the result absolutely conststent with what
1340
+ // the scanline rasterizer produces.
1341
+ // See intersect_shapes_aa for more comments
1342
+ //----------
1343
+ template<class ScanlineGen1,
1344
+ class ScanlineGen2,
1345
+ class Scanline1,
1346
+ class Scanline2,
1347
+ class Scanline,
1348
+ class Renderer>
1349
+ void sbool_xor_shapes_aa(ScanlineGen1& sg1, ScanlineGen2& sg2,
1350
+ Scanline1& sl1, Scanline2& sl2,
1351
+ Scanline& sl, Renderer& ren)
1352
+ {
1353
+ sbool_add_span_aa<Scanline1, Scanline> add_functor1;
1354
+ sbool_add_span_aa<Scanline2, Scanline> add_functor2;
1355
+ sbool_xor_spans_aa<Scanline1, Scanline2, Scanline,
1356
+ sbool_xor_formula_linear<> > combine_functor;
1357
+ sbool_unite_shapes(sg1, sg2, sl1, sl2, sl, ren,
1358
+ add_functor1, add_functor2, combine_functor);
1359
+ }
1360
+
1361
+
1362
+
1363
+ //------------------------------------------sbool_xor_shapes_saddle_aa
1364
+ // Apply eXclusive OR to two anti-aliased scanline shapes.
1365
+ // There's the classical "Saddle" used to calculate the
1366
+ // Anti-Aliasing values, that is:
1367
+ // a XOR b : 1-((1-a+a*b)*(1-b+a*b))
1368
+ // See intersect_shapes_aa for more comments
1369
+ //----------
1370
+ template<class ScanlineGen1,
1371
+ class ScanlineGen2,
1372
+ class Scanline1,
1373
+ class Scanline2,
1374
+ class Scanline,
1375
+ class Renderer>
1376
+ void sbool_xor_shapes_saddle_aa(ScanlineGen1& sg1, ScanlineGen2& sg2,
1377
+ Scanline1& sl1, Scanline2& sl2,
1378
+ Scanline& sl, Renderer& ren)
1379
+ {
1380
+ sbool_add_span_aa<Scanline1, Scanline> add_functor1;
1381
+ sbool_add_span_aa<Scanline2, Scanline> add_functor2;
1382
+ sbool_xor_spans_aa<Scanline1,
1383
+ Scanline2,
1384
+ Scanline,
1385
+ sbool_xor_formula_saddle<> > combine_functor;
1386
+ sbool_unite_shapes(sg1, sg2, sl1, sl2, sl, ren,
1387
+ add_functor1, add_functor2, combine_functor);
1388
+ }
1389
+
1390
+
1391
+ //--------------------------------------sbool_xor_shapes_abs_diff_aa
1392
+ // Apply eXclusive OR to two anti-aliased scanline shapes.
1393
+ // There's the absolute difference used to calculate
1394
+ // Anti-Aliasing values, that is:
1395
+ // a XOR b : abs(a-b)
1396
+ // See intersect_shapes_aa for more comments
1397
+ //----------
1398
+ template<class ScanlineGen1,
1399
+ class ScanlineGen2,
1400
+ class Scanline1,
1401
+ class Scanline2,
1402
+ class Scanline,
1403
+ class Renderer>
1404
+ void sbool_xor_shapes_abs_diff_aa(ScanlineGen1& sg1, ScanlineGen2& sg2,
1405
+ Scanline1& sl1, Scanline2& sl2,
1406
+ Scanline& sl, Renderer& ren)
1407
+ {
1408
+ sbool_add_span_aa<Scanline1, Scanline> add_functor1;
1409
+ sbool_add_span_aa<Scanline2, Scanline> add_functor2;
1410
+ sbool_xor_spans_aa<Scanline1,
1411
+ Scanline2,
1412
+ Scanline,
1413
+ sbool_xor_formula_abs_diff> combine_functor;
1414
+ sbool_unite_shapes(sg1, sg2, sl1, sl2, sl, ren,
1415
+ add_functor1, add_functor2, combine_functor);
1416
+ }
1417
+
1418
+
1419
+
1420
+ //--------------------------------------------------sbool_xor_shapes_bin
1421
+ // Apply eXclusive OR to two binary scanline shapes (without anti-aliasing).
1422
+ // See intersect_shapes_aa for more comments
1423
+ //----------
1424
+ template<class ScanlineGen1,
1425
+ class ScanlineGen2,
1426
+ class Scanline1,
1427
+ class Scanline2,
1428
+ class Scanline,
1429
+ class Renderer>
1430
+ void sbool_xor_shapes_bin(ScanlineGen1& sg1, ScanlineGen2& sg2,
1431
+ Scanline1& sl1, Scanline2& sl2,
1432
+ Scanline& sl, Renderer& ren)
1433
+ {
1434
+ sbool_add_span_bin<Scanline1, Scanline> add_functor1;
1435
+ sbool_add_span_bin<Scanline2, Scanline> add_functor2;
1436
+ sbool_combine_spans_empty<Scanline1, Scanline2, Scanline> combine_functor;
1437
+ sbool_unite_shapes(sg1, sg2, sl1, sl2, sl, ren,
1438
+ add_functor1, add_functor2, combine_functor);
1439
+ }
1440
+
1441
+
1442
+
1443
+
1444
+
1445
+
1446
+ //----------------------------------------------sbool_subtract_shapes_aa
1447
+ // Subtract shapes "sg1-sg2" with anti-aliasing
1448
+ // See intersect_shapes_aa for more comments
1449
+ //----------
1450
+ template<class ScanlineGen1,
1451
+ class ScanlineGen2,
1452
+ class Scanline1,
1453
+ class Scanline2,
1454
+ class Scanline,
1455
+ class Renderer>
1456
+ void sbool_subtract_shapes_aa(ScanlineGen1& sg1, ScanlineGen2& sg2,
1457
+ Scanline1& sl1, Scanline2& sl2,
1458
+ Scanline& sl, Renderer& ren)
1459
+ {
1460
+ sbool_add_span_aa<Scanline1, Scanline> add_functor;
1461
+ sbool_subtract_spans_aa<Scanline1, Scanline2, Scanline> combine_functor;
1462
+ sbool_subtract_shapes(sg1, sg2, sl1, sl2, sl, ren,
1463
+ add_functor, combine_functor);
1464
+ }
1465
+
1466
+
1467
+
1468
+
1469
+
1470
+ //---------------------------------------------sbool_subtract_shapes_bin
1471
+ // Subtract binary shapes "sg1-sg2" without anti-aliasing
1472
+ // See intersect_shapes_aa for more comments
1473
+ //----------
1474
+ template<class ScanlineGen1,
1475
+ class ScanlineGen2,
1476
+ class Scanline1,
1477
+ class Scanline2,
1478
+ class Scanline,
1479
+ class Renderer>
1480
+ void sbool_subtract_shapes_bin(ScanlineGen1& sg1, ScanlineGen2& sg2,
1481
+ Scanline1& sl1, Scanline2& sl2,
1482
+ Scanline& sl, Renderer& ren)
1483
+ {
1484
+ sbool_add_span_bin<Scanline1, Scanline> add_functor;
1485
+ sbool_combine_spans_empty<Scanline1, Scanline2, Scanline> combine_functor;
1486
+ sbool_subtract_shapes(sg1, sg2, sl1, sl2, sl, ren,
1487
+ add_functor, combine_functor);
1488
+ }
1489
+
1490
+
1491
+
1492
+
1493
+
1494
+
1495
+ //------------------------------------------------------------sbool_op_e
1496
+ enum sbool_op_e
1497
+ {
1498
+ sbool_or, //----sbool_or
1499
+ sbool_and, //----sbool_and
1500
+ sbool_xor, //----sbool_xor
1501
+ sbool_xor_saddle, //----sbool_xor_saddle
1502
+ sbool_xor_abs_diff, //----sbool_xor_abs_diff
1503
+ sbool_a_minus_b, //----sbool_a_minus_b
1504
+ sbool_b_minus_a //----sbool_b_minus_a
1505
+ };
1506
+
1507
+
1508
+
1509
+
1510
+
1511
+
1512
+ //----------------------------------------------sbool_combine_shapes_bin
1513
+ template<class ScanlineGen1,
1514
+ class ScanlineGen2,
1515
+ class Scanline1,
1516
+ class Scanline2,
1517
+ class Scanline,
1518
+ class Renderer>
1519
+ void sbool_combine_shapes_bin(sbool_op_e op,
1520
+ ScanlineGen1& sg1, ScanlineGen2& sg2,
1521
+ Scanline1& sl1, Scanline2& sl2,
1522
+ Scanline& sl, Renderer& ren)
1523
+ {
1524
+ switch(op)
1525
+ {
1526
+ case sbool_or : sbool_unite_shapes_bin (sg1, sg2, sl1, sl2, sl, ren); break;
1527
+ case sbool_and : sbool_intersect_shapes_bin(sg1, sg2, sl1, sl2, sl, ren); break;
1528
+ case sbool_xor :
1529
+ case sbool_xor_saddle :
1530
+ case sbool_xor_abs_diff: sbool_xor_shapes_bin (sg1, sg2, sl1, sl2, sl, ren); break;
1531
+ case sbool_a_minus_b : sbool_subtract_shapes_bin (sg1, sg2, sl1, sl2, sl, ren); break;
1532
+ case sbool_b_minus_a : sbool_subtract_shapes_bin (sg2, sg1, sl2, sl1, sl, ren); break;
1533
+ }
1534
+ }
1535
+
1536
+
1537
+
1538
+
1539
+ //-----------------------------------------------sbool_combine_shapes_aa
1540
+ template<class ScanlineGen1,
1541
+ class ScanlineGen2,
1542
+ class Scanline1,
1543
+ class Scanline2,
1544
+ class Scanline,
1545
+ class Renderer>
1546
+ void sbool_combine_shapes_aa(sbool_op_e op,
1547
+ ScanlineGen1& sg1, ScanlineGen2& sg2,
1548
+ Scanline1& sl1, Scanline2& sl2,
1549
+ Scanline& sl, Renderer& ren)
1550
+ {
1551
+ switch(op)
1552
+ {
1553
+ case sbool_or : sbool_unite_shapes_aa (sg1, sg2, sl1, sl2, sl, ren); break;
1554
+ case sbool_and : sbool_intersect_shapes_aa (sg1, sg2, sl1, sl2, sl, ren); break;
1555
+ case sbool_xor : sbool_xor_shapes_aa (sg1, sg2, sl1, sl2, sl, ren); break;
1556
+ case sbool_xor_saddle : sbool_xor_shapes_saddle_aa (sg1, sg2, sl1, sl2, sl, ren); break;
1557
+ case sbool_xor_abs_diff: sbool_xor_shapes_abs_diff_aa(sg1, sg2, sl1, sl2, sl, ren); break;
1558
+ case sbool_a_minus_b : sbool_subtract_shapes_aa (sg1, sg2, sl1, sl2, sl, ren); break;
1559
+ case sbool_b_minus_a : sbool_subtract_shapes_aa (sg2, sg1, sl2, sl1, sl, ren); break;
1560
+ }
1561
+ }
1562
+
1563
+ }
1564
+
1565
+
1566
+ #endif
1567
+
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_span_gouraud_gray.h ADDED
@@ -0,0 +1,241 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+ //
16
+ // Adaptation for high precision colors has been sponsored by
17
+ // Liberty Technology Systems, Inc., visit http://lib-sys.com
18
+ //
19
+ // Liberty Technology Systems, Inc. is the provider of
20
+ // PostScript and PDF technology for software developers.
21
+ //
22
+ //----------------------------------------------------------------------------
23
+
24
+ #ifndef AGG_SPAN_GOURAUD_GRAY_INCLUDED
25
+ #define AGG_SPAN_GOURAUD_GRAY_INCLUDED
26
+
27
+ #include "agg_basics.h"
28
+ #include "agg_color_gray.h"
29
+ #include "agg_dda_line.h"
30
+ #include "agg_span_gouraud.h"
31
+
32
+ namespace agg
33
+ {
34
+
35
+ //=======================================================span_gouraud_gray
36
+ template<class ColorT> class span_gouraud_gray : public span_gouraud<ColorT>
37
+ {
38
+ public:
39
+ typedef ColorT color_type;
40
+ typedef typename color_type::value_type value_type;
41
+ typedef span_gouraud<color_type> base_type;
42
+ typedef typename base_type::coord_type coord_type;
43
+ enum subpixel_scale_e
44
+ {
45
+ subpixel_shift = 4,
46
+ subpixel_scale = 1 << subpixel_shift
47
+ };
48
+
49
+ private:
50
+ //--------------------------------------------------------------------
51
+ struct gray_calc
52
+ {
53
+ void init(const coord_type& c1, const coord_type& c2)
54
+ {
55
+ m_x1 = c1.x - 0.5;
56
+ m_y1 = c1.y - 0.5;
57
+ m_dx = c2.x - c1.x;
58
+ double dy = c2.y - c1.y;
59
+ m_1dy = (fabs(dy) < 1e-10) ? 1e10 : 1.0 / dy;
60
+ m_v1 = c1.color.v;
61
+ m_a1 = c1.color.a;
62
+ m_dv = c2.color.v - m_v1;
63
+ m_da = c2.color.a - m_a1;
64
+ }
65
+
66
+ void calc(double y)
67
+ {
68
+ double k = (y - m_y1) * m_1dy;
69
+ if(k < 0.0) k = 0.0;
70
+ if(k > 1.0) k = 1.0;
71
+ m_v = m_v1 + iround(m_dv * k);
72
+ m_a = m_a1 + iround(m_da * k);
73
+ m_x = iround((m_x1 + m_dx * k) * subpixel_scale);
74
+ }
75
+
76
+ double m_x1;
77
+ double m_y1;
78
+ double m_dx;
79
+ double m_1dy;
80
+ int m_v1;
81
+ int m_a1;
82
+ int m_dv;
83
+ int m_da;
84
+ int m_v;
85
+ int m_a;
86
+ int m_x;
87
+ };
88
+
89
+
90
+ public:
91
+ //--------------------------------------------------------------------
92
+ span_gouraud_gray() {}
93
+ span_gouraud_gray(const color_type& c1,
94
+ const color_type& c2,
95
+ const color_type& c3,
96
+ double x1, double y1,
97
+ double x2, double y2,
98
+ double x3, double y3,
99
+ double d = 0) :
100
+ base_type(c1, c2, c3, x1, y1, x2, y2, x3, y3, d)
101
+ {}
102
+
103
+ //--------------------------------------------------------------------
104
+ void prepare()
105
+ {
106
+ coord_type coord[3];
107
+ base_type::arrange_vertices(coord);
108
+
109
+ m_y2 = int(coord[1].y);
110
+
111
+ m_swap = cross_product(coord[0].x, coord[0].y,
112
+ coord[2].x, coord[2].y,
113
+ coord[1].x, coord[1].y) < 0.0;
114
+
115
+ m_c1.init(coord[0], coord[2]);
116
+ m_c2.init(coord[0], coord[1]);
117
+ m_c3.init(coord[1], coord[2]);
118
+ }
119
+
120
+ //--------------------------------------------------------------------
121
+ void generate(color_type* span, int x, int y, unsigned len)
122
+ {
123
+ m_c1.calc(y);
124
+ const gray_calc* pc1 = &m_c1;
125
+ const gray_calc* pc2 = &m_c2;
126
+
127
+ if(y < m_y2)
128
+ {
129
+ // Bottom part of the triangle (first subtriangle)
130
+ //-------------------------
131
+ m_c2.calc(y + m_c2.m_1dy);
132
+ }
133
+ else
134
+ {
135
+ // Upper part (second subtriangle)
136
+ //-------------------------
137
+ m_c3.calc(y - m_c3.m_1dy);
138
+ pc2 = &m_c3;
139
+ }
140
+
141
+ if(m_swap)
142
+ {
143
+ // It means that the triangle is oriented clockwise,
144
+ // so that we need to swap the controlling structures
145
+ //-------------------------
146
+ const gray_calc* t = pc2;
147
+ pc2 = pc1;
148
+ pc1 = t;
149
+ }
150
+
151
+ // Get the horizontal length with subpixel accuracy
152
+ // and protect it from division by zero
153
+ //-------------------------
154
+ int nlen = abs(pc2->m_x - pc1->m_x);
155
+ if(nlen <= 0) nlen = 1;
156
+
157
+ dda_line_interpolator<14> v(pc1->m_v, pc2->m_v, nlen);
158
+ dda_line_interpolator<14> a(pc1->m_a, pc2->m_a, nlen);
159
+
160
+ // Calculate the starting point of the gradient with subpixel
161
+ // accuracy and correct (roll back) the interpolators.
162
+ // This operation will also clip the beginning of the span
163
+ // if necessary.
164
+ //-------------------------
165
+ int start = pc1->m_x - (x << subpixel_shift);
166
+ v -= start;
167
+ a -= start;
168
+ nlen += start;
169
+
170
+ int vv, va;
171
+ enum lim_e { lim = color_type::base_mask };
172
+
173
+ // Beginning part of the span. Since we rolled back the
174
+ // interpolators, the color values may have overflow.
175
+ // So that, we render the beginning part with checking
176
+ // for overflow. It lasts until "start" is positive;
177
+ // typically it's 1-2 pixels, but may be more in some cases.
178
+ //-------------------------
179
+ while(len && start > 0)
180
+ {
181
+ vv = v.y();
182
+ va = a.y();
183
+ if(vv < 0) vv = 0; if(vv > lim) vv = lim;
184
+ if(va < 0) va = 0; if(va > lim) va = lim;
185
+ span->v = (value_type)vv;
186
+ span->a = (value_type)va;
187
+ v += subpixel_scale;
188
+ a += subpixel_scale;
189
+ nlen -= subpixel_scale;
190
+ start -= subpixel_scale;
191
+ ++span;
192
+ --len;
193
+ }
194
+
195
+ // Middle part, no checking for overflow.
196
+ // Actual spans can be longer than the calculated length
197
+ // because of anti-aliasing, thus, the interpolators can
198
+ // overflow. But while "nlen" is positive we are safe.
199
+ //-------------------------
200
+ while(len && nlen > 0)
201
+ {
202
+ span->v = (value_type)v.y();
203
+ span->a = (value_type)a.y();
204
+ v += subpixel_scale;
205
+ a += subpixel_scale;
206
+ nlen -= subpixel_scale;
207
+ ++span;
208
+ --len;
209
+ }
210
+
211
+ // Ending part; checking for overflow.
212
+ // Typically it's 1-2 pixels, but may be more in some cases.
213
+ //-------------------------
214
+ while(len)
215
+ {
216
+ vv = v.y();
217
+ va = a.y();
218
+ if(vv < 0) vv = 0; if(vv > lim) vv = lim;
219
+ if(va < 0) va = 0; if(va > lim) va = lim;
220
+ span->v = (value_type)vv;
221
+ span->a = (value_type)va;
222
+ v += subpixel_scale;
223
+ a += subpixel_scale;
224
+ ++span;
225
+ --len;
226
+ }
227
+ }
228
+
229
+
230
+ private:
231
+ bool m_swap;
232
+ int m_y2;
233
+ gray_calc m_c1;
234
+ gray_calc m_c2;
235
+ gray_calc m_c3;
236
+ };
237
+
238
+
239
+ }
240
+
241
+ #endif
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_span_gradient_image.h ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // AGG Contribution Pack - Gradients 1 (AGG CP - Gradients 1)
3
+ // http://milan.marusinec.sk/aggcp
4
+ //
5
+ // For Anti-Grain Geometry - Version 2.4
6
+ // http://www.antigrain.org
7
+ //
8
+ // Contribution Created By:
9
+ // Milan Marusinec alias Milano
10
+ // milan@marusinec.sk
11
+ // Copyright (c) 2007-2008
12
+ //
13
+ // Permission to copy, use, modify, sell and distribute this software
14
+ // is granted provided this copyright notice appears in all copies.
15
+ // This software is provided "as is" without express or implied
16
+ // warranty, and with no claim as to its suitability for any purpose.
17
+ //
18
+ // [History] -----------------------------------------------------------------
19
+ //
20
+ // 03.02.2008-Milano: Ported from Object Pascal code of AggPas
21
+ //
22
+ #ifndef AGG_SPAN_GRADIENT_IMAGE_INCLUDED
23
+ #define AGG_SPAN_GRADIENT_IMAGE_INCLUDED
24
+
25
+ #include "agg_basics.h"
26
+ #include "agg_span_gradient.h"
27
+ #include "agg_color_rgba.h"
28
+ #include "agg_rendering_buffer.h"
29
+ #include "agg_pixfmt_rgba.h"
30
+
31
+ namespace agg
32
+ {
33
+
34
+ //==========================================================one_color_function
35
+ template<class ColorT> class one_color_function
36
+ {
37
+ public:
38
+ typedef ColorT color_type;
39
+
40
+ color_type m_color;
41
+
42
+ one_color_function() :
43
+ m_color()
44
+ {
45
+ }
46
+
47
+ static unsigned size() { return 1; }
48
+
49
+ const color_type& operator [] (unsigned i) const
50
+ {
51
+ return m_color;
52
+ }
53
+
54
+ color_type* operator [] (unsigned i)
55
+ {
56
+ return &m_color;
57
+ }
58
+ };
59
+
60
+ //==========================================================gradient_image
61
+ template<class ColorT> class gradient_image
62
+ {
63
+ private:
64
+ //------------ fields
65
+ typedef ColorT color_type;
66
+ typedef agg::pixfmt_rgba32 pixfmt_type;
67
+
68
+ agg::rgba8* m_buffer;
69
+
70
+ int m_alocdx;
71
+ int m_alocdy;
72
+ int m_width;
73
+ int m_height;
74
+
75
+ color_type* m_color;
76
+
77
+ one_color_function<color_type> m_color_function;
78
+
79
+ public:
80
+ gradient_image() :
81
+ m_color_function(),
82
+ m_buffer(NULL),
83
+ m_alocdx(0),
84
+ m_alocdy(0),
85
+ m_width(0),
86
+ m_height(0)
87
+ {
88
+ m_color = m_color_function[0 ];
89
+ }
90
+
91
+ ~gradient_image()
92
+ {
93
+ if (m_buffer) { delete [] m_buffer; }
94
+ }
95
+
96
+ void* image_create(int width, int height )
97
+ {
98
+ void* result = NULL;
99
+
100
+ if (width > m_alocdx || height > m_alocdy)
101
+ {
102
+ if (m_buffer) { delete [] m_buffer; }
103
+
104
+ m_buffer = NULL;
105
+ m_buffer = new agg::rgba8[width * height];
106
+
107
+ if (m_buffer)
108
+ {
109
+ m_alocdx = width;
110
+ m_alocdy = height;
111
+ }
112
+ else
113
+ {
114
+ m_alocdx = 0;
115
+ m_alocdy = 0;
116
+ };
117
+ };
118
+
119
+ if (m_buffer)
120
+ {
121
+ m_width = width;
122
+ m_height = height;
123
+
124
+ for (int rows = 0; rows < height; rows++)
125
+ {
126
+ agg::rgba8* row = &m_buffer[rows * m_alocdx ];
127
+ memset(row ,0 ,m_width * 4 );
128
+ };
129
+
130
+ result = m_buffer;
131
+ };
132
+ return result;
133
+ }
134
+
135
+ void* image_buffer() { return m_buffer; }
136
+ int image_width() { return m_width; }
137
+ int image_height() { return m_height; }
138
+ int image_stride() { return m_alocdx * 4; }
139
+
140
+ int calculate(int x, int y, int d) const
141
+ {
142
+ if (m_buffer)
143
+ {
144
+ int px = x >> agg::gradient_subpixel_shift;
145
+ int py = y >> agg::gradient_subpixel_shift;
146
+
147
+ px %= m_width;
148
+
149
+ if (px < 0)
150
+ {
151
+ px += m_width;
152
+ }
153
+
154
+ py %= m_height;
155
+
156
+ if (py < 0 )
157
+ {
158
+ py += m_height;
159
+ }
160
+
161
+ rgba8* pixel = &m_buffer[py * m_alocdx + px ];
162
+
163
+ m_color->r = pixel->r;
164
+ m_color->g = pixel->g;
165
+ m_color->b = pixel->b;
166
+ m_color->a = pixel->a;
167
+
168
+ }
169
+ else
170
+ {
171
+ m_color->r = 0;
172
+ m_color->g = 0;
173
+ m_color->b = 0;
174
+ m_color->a = 0;
175
+ }
176
+ return 0;
177
+ }
178
+
179
+ const one_color_function<color_type>& color_function() const
180
+ {
181
+ return m_color_function;
182
+ }
183
+
184
+ };
185
+
186
+ }
187
+
188
+ #endif
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_span_image_filter.h ADDED
@@ -0,0 +1,246 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+ //
16
+ // 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_span_interpolator_linear.h"
25
+
26
+ namespace agg
27
+ {
28
+
29
+ //-------------------------------------------------------span_image_filter
30
+ template<class Source, class Interpolator> class span_image_filter
31
+ {
32
+ public:
33
+ typedef Source source_type;
34
+ typedef Interpolator interpolator_type;
35
+
36
+ //--------------------------------------------------------------------
37
+ span_image_filter() {}
38
+ span_image_filter(source_type& src,
39
+ interpolator_type& interpolator,
40
+ image_filter_lut* filter) :
41
+ m_src(&src),
42
+ m_interpolator(&interpolator),
43
+ m_filter(filter),
44
+ m_dx_dbl(0.5),
45
+ m_dy_dbl(0.5),
46
+ m_dx_int(image_subpixel_scale / 2),
47
+ m_dy_int(image_subpixel_scale / 2)
48
+ {}
49
+ void attach(source_type& v) { m_src = &v; }
50
+
51
+ //--------------------------------------------------------------------
52
+ source_type& source() { return *m_src; }
53
+ const source_type& source() const { return *m_src; }
54
+ const image_filter_lut& filter() const { return *m_filter; }
55
+ int filter_dx_int() const { return m_dx_int; }
56
+ int filter_dy_int() const { return m_dy_int; }
57
+ double filter_dx_dbl() const { return m_dx_dbl; }
58
+ double filter_dy_dbl() const { return m_dy_dbl; }
59
+
60
+ //--------------------------------------------------------------------
61
+ void interpolator(interpolator_type& v) { m_interpolator = &v; }
62
+ void filter(image_filter_lut& v) { m_filter = &v; }
63
+ void filter_offset(double dx, double dy)
64
+ {
65
+ m_dx_dbl = dx;
66
+ m_dy_dbl = dy;
67
+ m_dx_int = iround(dx * image_subpixel_scale);
68
+ m_dy_int = iround(dy * image_subpixel_scale);
69
+ }
70
+ void filter_offset(double d) { filter_offset(d, d); }
71
+
72
+ //--------------------------------------------------------------------
73
+ interpolator_type& interpolator() { return *m_interpolator; }
74
+
75
+ //--------------------------------------------------------------------
76
+ void prepare() {}
77
+
78
+ //--------------------------------------------------------------------
79
+ private:
80
+ source_type* m_src;
81
+ interpolator_type* m_interpolator;
82
+ image_filter_lut* m_filter;
83
+ double m_dx_dbl;
84
+ double m_dy_dbl;
85
+ unsigned m_dx_int;
86
+ unsigned m_dy_int;
87
+ };
88
+
89
+
90
+
91
+
92
+ //==============================================span_image_resample_affine
93
+ template<class Source>
94
+ class span_image_resample_affine :
95
+ public span_image_filter<Source, span_interpolator_linear<trans_affine> >
96
+ {
97
+ public:
98
+ typedef Source source_type;
99
+ typedef span_interpolator_linear<trans_affine> interpolator_type;
100
+ typedef span_image_filter<source_type, interpolator_type> base_type;
101
+
102
+ //--------------------------------------------------------------------
103
+ span_image_resample_affine() :
104
+ m_scale_limit(200.0),
105
+ m_blur_x(1.0),
106
+ m_blur_y(1.0)
107
+ {}
108
+
109
+ //--------------------------------------------------------------------
110
+ span_image_resample_affine(source_type& src,
111
+ interpolator_type& inter,
112
+ image_filter_lut& filter) :
113
+ base_type(src, inter, &filter),
114
+ m_scale_limit(200.0),
115
+ m_blur_x(1.0),
116
+ m_blur_y(1.0)
117
+ {}
118
+
119
+
120
+ //--------------------------------------------------------------------
121
+ int scale_limit() const { return uround(m_scale_limit); }
122
+ void scale_limit(int v) { m_scale_limit = v; }
123
+
124
+ //--------------------------------------------------------------------
125
+ double blur_x() const { return m_blur_x; }
126
+ double blur_y() const { return m_blur_y; }
127
+ void blur_x(double v) { m_blur_x = v; }
128
+ void blur_y(double v) { m_blur_y = v; }
129
+ void blur(double v) { m_blur_x = m_blur_y = v; }
130
+
131
+ //--------------------------------------------------------------------
132
+ void prepare()
133
+ {
134
+ double scale_x;
135
+ double scale_y;
136
+
137
+ base_type::interpolator().transformer().scaling_abs(&scale_x, &scale_y);
138
+
139
+ if(scale_x * scale_y > m_scale_limit)
140
+ {
141
+ scale_x = scale_x * m_scale_limit / (scale_x * scale_y);
142
+ scale_y = scale_y * m_scale_limit / (scale_x * scale_y);
143
+ }
144
+
145
+ if(scale_x < 1) scale_x = 1;
146
+ if(scale_y < 1) scale_y = 1;
147
+
148
+ if(scale_x > m_scale_limit) scale_x = m_scale_limit;
149
+ if(scale_y > m_scale_limit) scale_y = m_scale_limit;
150
+
151
+ scale_x *= m_blur_x;
152
+ scale_y *= m_blur_y;
153
+
154
+ if(scale_x < 1) scale_x = 1;
155
+ if(scale_y < 1) scale_y = 1;
156
+
157
+ m_rx = uround( scale_x * double(image_subpixel_scale));
158
+ m_rx_inv = uround(1.0/scale_x * double(image_subpixel_scale));
159
+
160
+ m_ry = uround( scale_y * double(image_subpixel_scale));
161
+ m_ry_inv = uround(1.0/scale_y * double(image_subpixel_scale));
162
+ }
163
+
164
+ protected:
165
+ int m_rx;
166
+ int m_ry;
167
+ int m_rx_inv;
168
+ int m_ry_inv;
169
+
170
+ private:
171
+ double m_scale_limit;
172
+ double m_blur_x;
173
+ double m_blur_y;
174
+ };
175
+
176
+
177
+
178
+ //=====================================================span_image_resample
179
+ template<class Source, class Interpolator>
180
+ class span_image_resample :
181
+ public span_image_filter<Source, Interpolator>
182
+ {
183
+ public:
184
+ typedef Source source_type;
185
+ typedef Interpolator interpolator_type;
186
+ typedef span_image_filter<source_type, interpolator_type> base_type;
187
+
188
+ //--------------------------------------------------------------------
189
+ span_image_resample() :
190
+ m_scale_limit(20),
191
+ m_blur_x(image_subpixel_scale),
192
+ m_blur_y(image_subpixel_scale)
193
+ {}
194
+
195
+ //--------------------------------------------------------------------
196
+ span_image_resample(source_type& src,
197
+ interpolator_type& inter,
198
+ image_filter_lut& filter) :
199
+ base_type(src, inter, &filter),
200
+ m_scale_limit(20),
201
+ m_blur_x(image_subpixel_scale),
202
+ m_blur_y(image_subpixel_scale)
203
+ {}
204
+
205
+ //--------------------------------------------------------------------
206
+ int scale_limit() const { return m_scale_limit; }
207
+ void scale_limit(int v) { m_scale_limit = v; }
208
+
209
+ //--------------------------------------------------------------------
210
+ double blur_x() const { return double(m_blur_x) / double(image_subpixel_scale); }
211
+ double blur_y() const { return double(m_blur_y) / double(image_subpixel_scale); }
212
+ void blur_x(double v) { m_blur_x = uround(v * double(image_subpixel_scale)); }
213
+ void blur_y(double v) { m_blur_y = uround(v * double(image_subpixel_scale)); }
214
+ void blur(double v) { m_blur_x =
215
+ m_blur_y = uround(v * double(image_subpixel_scale)); }
216
+
217
+ protected:
218
+ AGG_INLINE void adjust_scale(int* rx, int* ry)
219
+ {
220
+ if(*rx < image_subpixel_scale) *rx = image_subpixel_scale;
221
+ if(*ry < image_subpixel_scale) *ry = image_subpixel_scale;
222
+ if(*rx > image_subpixel_scale * m_scale_limit)
223
+ {
224
+ *rx = image_subpixel_scale * m_scale_limit;
225
+ }
226
+ if(*ry > image_subpixel_scale * m_scale_limit)
227
+ {
228
+ *ry = image_subpixel_scale * m_scale_limit;
229
+ }
230
+ *rx = (*rx * m_blur_x) >> image_subpixel_shift;
231
+ *ry = (*ry * m_blur_y) >> image_subpixel_shift;
232
+ if(*rx < image_subpixel_scale) *rx = image_subpixel_scale;
233
+ if(*ry < image_subpixel_scale) *ry = image_subpixel_scale;
234
+ }
235
+
236
+ int m_scale_limit;
237
+ int m_blur_x;
238
+ int m_blur_y;
239
+ };
240
+
241
+
242
+
243
+
244
+ }
245
+
246
+ #endif
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_span_image_filter_gray.h ADDED
@@ -0,0 +1,723 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+ //
16
+ // Adaptation for high precision colors has been sponsored by
17
+ // Liberty Technology Systems, Inc., visit http://lib-sys.com
18
+ //
19
+ // Liberty Technology Systems, Inc. is the provider of
20
+ // PostScript and PDF technology for software developers.
21
+ //
22
+ //----------------------------------------------------------------------------
23
+ #ifndef AGG_SPAN_IMAGE_FILTER_GRAY_INCLUDED
24
+ #define AGG_SPAN_IMAGE_FILTER_GRAY_INCLUDED
25
+
26
+ #include "agg_basics.h"
27
+ #include "agg_color_gray.h"
28
+ #include "agg_span_image_filter.h"
29
+
30
+
31
+ namespace agg
32
+ {
33
+
34
+ //==============================================span_image_filter_gray_nn
35
+ template<class Source, class Interpolator>
36
+ class span_image_filter_gray_nn :
37
+ public span_image_filter<Source, Interpolator>
38
+ {
39
+ public:
40
+ typedef Source source_type;
41
+ typedef typename source_type::color_type color_type;
42
+ typedef Interpolator interpolator_type;
43
+ typedef span_image_filter<source_type, interpolator_type> base_type;
44
+ typedef typename color_type::value_type value_type;
45
+ typedef typename color_type::calc_type calc_type;
46
+ typedef typename color_type::long_type long_type;
47
+
48
+ //--------------------------------------------------------------------
49
+ span_image_filter_gray_nn() {}
50
+ span_image_filter_gray_nn(source_type& src,
51
+ interpolator_type& inter) :
52
+ base_type(src, inter, 0)
53
+ {}
54
+
55
+ //--------------------------------------------------------------------
56
+ void generate(color_type* span, int x, int y, unsigned len)
57
+ {
58
+ base_type::interpolator().begin(x + base_type::filter_dx_dbl(),
59
+ y + base_type::filter_dy_dbl(), len);
60
+ do
61
+ {
62
+ base_type::interpolator().coordinates(&x, &y);
63
+ span->v = *(const value_type*)
64
+ base_type::source().span(x >> image_subpixel_shift,
65
+ y >> image_subpixel_shift,
66
+ 1);
67
+ span->a = color_type::full_value();
68
+ ++span;
69
+ ++base_type::interpolator();
70
+ } while(--len);
71
+ }
72
+ };
73
+
74
+
75
+
76
+ //=========================================span_image_filter_gray_bilinear
77
+ template<class Source, class Interpolator>
78
+ class span_image_filter_gray_bilinear :
79
+ public span_image_filter<Source, Interpolator>
80
+ {
81
+ public:
82
+ typedef Source source_type;
83
+ typedef typename source_type::color_type color_type;
84
+ typedef Interpolator interpolator_type;
85
+ typedef span_image_filter<source_type, interpolator_type> base_type;
86
+ typedef typename color_type::value_type value_type;
87
+ typedef typename color_type::calc_type calc_type;
88
+ typedef typename color_type::long_type long_type;
89
+
90
+ //--------------------------------------------------------------------
91
+ span_image_filter_gray_bilinear() {}
92
+ span_image_filter_gray_bilinear(source_type& src,
93
+ interpolator_type& inter) :
94
+ base_type(src, inter, 0)
95
+ {}
96
+
97
+
98
+ //--------------------------------------------------------------------
99
+ void generate(color_type* span, int x, int y, unsigned len)
100
+ {
101
+ base_type::interpolator().begin(x + base_type::filter_dx_dbl(),
102
+ y + base_type::filter_dy_dbl(), len);
103
+ long_type fg;
104
+ const value_type *fg_ptr;
105
+ do
106
+ {
107
+ int x_hr;
108
+ int y_hr;
109
+
110
+ base_type::interpolator().coordinates(&x_hr, &y_hr);
111
+
112
+ x_hr -= base_type::filter_dx_int();
113
+ y_hr -= base_type::filter_dy_int();
114
+
115
+ int x_lr = x_hr >> image_subpixel_shift;
116
+ int y_lr = y_hr >> image_subpixel_shift;
117
+
118
+ fg = 0;
119
+
120
+ x_hr &= image_subpixel_mask;
121
+ y_hr &= image_subpixel_mask;
122
+
123
+ fg_ptr = (const value_type*)base_type::source().span(x_lr, y_lr, 2);
124
+ fg += *fg_ptr * (image_subpixel_scale - x_hr) * (image_subpixel_scale - y_hr);
125
+
126
+ fg_ptr = (const value_type*)base_type::source().next_x();
127
+ fg += *fg_ptr * x_hr * (image_subpixel_scale - y_hr);
128
+
129
+ fg_ptr = (const value_type*)base_type::source().next_y();
130
+ fg += *fg_ptr * (image_subpixel_scale - x_hr) * y_hr;
131
+
132
+ fg_ptr = (const value_type*)base_type::source().next_x();
133
+ fg += *fg_ptr * x_hr * y_hr;
134
+
135
+ span->v = color_type::downshift(fg, image_subpixel_shift * 2);
136
+ span->a = color_type::full_value();
137
+ ++span;
138
+ ++base_type::interpolator();
139
+
140
+ } while(--len);
141
+ }
142
+ };
143
+
144
+
145
+ //====================================span_image_filter_gray_bilinear_clip
146
+ template<class Source, class Interpolator>
147
+ class span_image_filter_gray_bilinear_clip :
148
+ public span_image_filter<Source, Interpolator>
149
+ {
150
+ public:
151
+ typedef Source source_type;
152
+ typedef typename source_type::color_type color_type;
153
+ typedef Interpolator interpolator_type;
154
+ typedef span_image_filter<source_type, interpolator_type> base_type;
155
+ typedef typename color_type::value_type value_type;
156
+ typedef typename color_type::calc_type calc_type;
157
+ typedef typename color_type::long_type long_type;
158
+
159
+ //--------------------------------------------------------------------
160
+ span_image_filter_gray_bilinear_clip() {}
161
+ span_image_filter_gray_bilinear_clip(source_type& src,
162
+ const color_type& back_color,
163
+ interpolator_type& inter) :
164
+ base_type(src, inter, 0),
165
+ m_back_color(back_color)
166
+ {}
167
+ const color_type& background_color() const { return m_back_color; }
168
+ void background_color(const color_type& v) { m_back_color = v; }
169
+
170
+ //--------------------------------------------------------------------
171
+ void generate(color_type* span, int x, int y, unsigned len)
172
+ {
173
+ base_type::interpolator().begin(x + base_type::filter_dx_dbl(),
174
+ y + base_type::filter_dy_dbl(), len);
175
+ long_type fg;
176
+ long_type src_alpha;
177
+ value_type back_v = m_back_color.v;
178
+ value_type back_a = m_back_color.a;
179
+
180
+ const value_type *fg_ptr;
181
+
182
+ int maxx = base_type::source().width() - 1;
183
+ int maxy = base_type::source().height() - 1;
184
+
185
+ do
186
+ {
187
+ int x_hr;
188
+ int y_hr;
189
+
190
+ base_type::interpolator().coordinates(&x_hr, &y_hr);
191
+
192
+ x_hr -= base_type::filter_dx_int();
193
+ y_hr -= base_type::filter_dy_int();
194
+
195
+ int x_lr = x_hr >> image_subpixel_shift;
196
+ int y_lr = y_hr >> image_subpixel_shift;
197
+
198
+ if(x_lr >= 0 && y_lr >= 0 &&
199
+ x_lr < maxx && y_lr < maxy)
200
+ {
201
+ fg = 0;
202
+
203
+ x_hr &= image_subpixel_mask;
204
+ y_hr &= image_subpixel_mask;
205
+ fg_ptr = (const value_type*)base_type::source().row_ptr(y_lr) + x_lr;
206
+
207
+ fg += *fg_ptr++ * (image_subpixel_scale - x_hr) * (image_subpixel_scale - y_hr);
208
+ fg += *fg_ptr++ * (image_subpixel_scale - y_hr) * x_hr;
209
+
210
+ ++y_lr;
211
+ fg_ptr = (const value_type*)base_type::source().row_ptr(y_lr) + x_lr;
212
+
213
+ fg += *fg_ptr++ * (image_subpixel_scale - x_hr) * y_hr;
214
+ fg += *fg_ptr++ * x_hr * y_hr;
215
+
216
+ fg = color_type::downshift(fg, image_subpixel_shift * 2);
217
+ src_alpha = color_type::full_value();
218
+ }
219
+ else
220
+ {
221
+ unsigned weight;
222
+ if(x_lr < -1 || y_lr < -1 ||
223
+ x_lr > maxx || y_lr > maxy)
224
+ {
225
+ fg = back_v;
226
+ src_alpha = back_a;
227
+ }
228
+ else
229
+ {
230
+ fg = src_alpha = 0;
231
+
232
+ x_hr &= image_subpixel_mask;
233
+ y_hr &= image_subpixel_mask;
234
+
235
+ weight = (image_subpixel_scale - x_hr) *
236
+ (image_subpixel_scale - y_hr);
237
+ if(x_lr >= 0 && y_lr >= 0 &&
238
+ x_lr <= maxx && y_lr <= maxy)
239
+ {
240
+ fg += weight *
241
+ *((const value_type*)base_type::source().row_ptr(y_lr) + x_lr);
242
+ src_alpha += weight * color_type::full_value();
243
+ }
244
+ else
245
+ {
246
+ fg += back_v * weight;
247
+ src_alpha += back_a * weight;
248
+ }
249
+
250
+ x_lr++;
251
+
252
+ weight = x_hr * (image_subpixel_scale - y_hr);
253
+ if(x_lr >= 0 && y_lr >= 0 &&
254
+ x_lr <= maxx && y_lr <= maxy)
255
+ {
256
+ fg += weight *
257
+ *((const value_type*)base_type::source().row_ptr(y_lr) + x_lr);
258
+ src_alpha += weight * color_type::full_value();
259
+ }
260
+ else
261
+ {
262
+ fg += back_v * weight;
263
+ src_alpha += back_a * weight;
264
+ }
265
+
266
+ x_lr--;
267
+ y_lr++;
268
+
269
+ weight = (image_subpixel_scale - x_hr) * y_hr;
270
+ if(x_lr >= 0 && y_lr >= 0 &&
271
+ x_lr <= maxx && y_lr <= maxy)
272
+ {
273
+ fg += weight *
274
+ *((const value_type*)base_type::source().row_ptr(y_lr) + x_lr);
275
+ src_alpha += weight * color_type::full_value();
276
+ }
277
+ else
278
+ {
279
+ fg += back_v * weight;
280
+ src_alpha += back_a * weight;
281
+ }
282
+
283
+ x_lr++;
284
+
285
+ weight = x_hr * y_hr;
286
+ if(x_lr >= 0 && y_lr >= 0 &&
287
+ x_lr <= maxx && y_lr <= maxy)
288
+ {
289
+ fg += weight *
290
+ *((const value_type*)base_type::source().row_ptr(y_lr) + x_lr);
291
+ src_alpha += weight * color_type::full_value();
292
+ }
293
+ else
294
+ {
295
+ fg += back_v * weight;
296
+ src_alpha += back_a * weight;
297
+ }
298
+
299
+ fg = color_type::downshift(fg, image_subpixel_shift * 2);
300
+ src_alpha = color_type::downshift(src_alpha, image_subpixel_shift * 2);
301
+ }
302
+ }
303
+
304
+ span->v = (value_type)fg;
305
+ span->a = (value_type)src_alpha;
306
+ ++span;
307
+ ++base_type::interpolator();
308
+
309
+ } while(--len);
310
+ }
311
+ private:
312
+ color_type m_back_color;
313
+ };
314
+
315
+
316
+
317
+ //==============================================span_image_filter_gray_2x2
318
+ template<class Source, class Interpolator>
319
+ class span_image_filter_gray_2x2 :
320
+ public span_image_filter<Source, Interpolator>
321
+ {
322
+ public:
323
+ typedef Source source_type;
324
+ typedef typename source_type::color_type color_type;
325
+ typedef Interpolator interpolator_type;
326
+ typedef span_image_filter<source_type, interpolator_type> base_type;
327
+ typedef typename color_type::value_type value_type;
328
+ typedef typename color_type::calc_type calc_type;
329
+ typedef typename color_type::long_type long_type;
330
+
331
+ //--------------------------------------------------------------------
332
+ span_image_filter_gray_2x2() {}
333
+ span_image_filter_gray_2x2(source_type& src,
334
+ interpolator_type& inter,
335
+ image_filter_lut& filter) :
336
+ base_type(src, inter, &filter)
337
+ {}
338
+
339
+
340
+ //--------------------------------------------------------------------
341
+ void generate(color_type* span, int x, int y, unsigned len)
342
+ {
343
+ base_type::interpolator().begin(x + base_type::filter_dx_dbl(),
344
+ y + base_type::filter_dy_dbl(), len);
345
+
346
+ long_type fg;
347
+
348
+ const value_type *fg_ptr;
349
+ const int16* weight_array = base_type::filter().weight_array() +
350
+ ((base_type::filter().diameter()/2 - 1) <<
351
+ image_subpixel_shift);
352
+ do
353
+ {
354
+ int x_hr;
355
+ int y_hr;
356
+
357
+ base_type::interpolator().coordinates(&x_hr, &y_hr);
358
+
359
+ x_hr -= base_type::filter_dx_int();
360
+ y_hr -= base_type::filter_dy_int();
361
+
362
+ int x_lr = x_hr >> image_subpixel_shift;
363
+ int y_lr = y_hr >> image_subpixel_shift;
364
+
365
+ unsigned weight;
366
+ fg = 0;
367
+
368
+ x_hr &= image_subpixel_mask;
369
+ y_hr &= image_subpixel_mask;
370
+
371
+ fg_ptr = (const value_type*)base_type::source().span(x_lr, y_lr, 2);
372
+ weight = (weight_array[x_hr + image_subpixel_scale] *
373
+ weight_array[y_hr + image_subpixel_scale] +
374
+ image_filter_scale / 2) >>
375
+ image_filter_shift;
376
+ fg += weight * *fg_ptr;
377
+
378
+ fg_ptr = (const value_type*)base_type::source().next_x();
379
+ weight = (weight_array[x_hr] *
380
+ weight_array[y_hr + image_subpixel_scale] +
381
+ image_filter_scale / 2) >>
382
+ image_filter_shift;
383
+ fg += weight * *fg_ptr;
384
+
385
+ fg_ptr = (const value_type*)base_type::source().next_y();
386
+ weight = (weight_array[x_hr + image_subpixel_scale] *
387
+ weight_array[y_hr] +
388
+ image_filter_scale / 2) >>
389
+ image_filter_shift;
390
+ fg += weight * *fg_ptr;
391
+
392
+ fg_ptr = (const value_type*)base_type::source().next_x();
393
+ weight = (weight_array[x_hr] *
394
+ weight_array[y_hr] +
395
+ image_filter_scale / 2) >>
396
+ image_filter_shift;
397
+ fg += weight * *fg_ptr;
398
+
399
+ fg >>= image_filter_shift;
400
+ if(fg > color_type::full_value()) fg = color_type::full_value();
401
+
402
+ span->v = (value_type)fg;
403
+ span->a = color_type::full_value();
404
+ ++span;
405
+ ++base_type::interpolator();
406
+ } while(--len);
407
+ }
408
+ };
409
+
410
+
411
+
412
+ //==================================================span_image_filter_gray
413
+ template<class Source, class Interpolator>
414
+ class span_image_filter_gray :
415
+ public span_image_filter<Source, Interpolator>
416
+ {
417
+ public:
418
+ typedef Source source_type;
419
+ typedef typename source_type::color_type color_type;
420
+ typedef Interpolator interpolator_type;
421
+ typedef span_image_filter<source_type, interpolator_type> base_type;
422
+ typedef typename color_type::value_type value_type;
423
+ typedef typename color_type::calc_type calc_type;
424
+ typedef typename color_type::long_type long_type;
425
+
426
+ //--------------------------------------------------------------------
427
+ span_image_filter_gray() {}
428
+ span_image_filter_gray(source_type& src,
429
+ interpolator_type& inter,
430
+ image_filter_lut& filter) :
431
+ base_type(src, inter, &filter)
432
+ {}
433
+
434
+ //--------------------------------------------------------------------
435
+ void generate(color_type* span, int x, int y, unsigned len)
436
+ {
437
+ base_type::interpolator().begin(x + base_type::filter_dx_dbl(),
438
+ y + base_type::filter_dy_dbl(), len);
439
+
440
+ long_type fg;
441
+ const value_type *fg_ptr;
442
+
443
+ unsigned diameter = base_type::filter().diameter();
444
+ int start = base_type::filter().start();
445
+ const int16* weight_array = base_type::filter().weight_array();
446
+
447
+ int x_count;
448
+ int weight_y;
449
+
450
+ do
451
+ {
452
+ base_type::interpolator().coordinates(&x, &y);
453
+
454
+ x -= base_type::filter_dx_int();
455
+ y -= base_type::filter_dy_int();
456
+
457
+ int x_hr = x;
458
+ int y_hr = y;
459
+
460
+ int x_lr = x_hr >> image_subpixel_shift;
461
+ int y_lr = y_hr >> image_subpixel_shift;
462
+
463
+ fg = 0;
464
+
465
+ int x_fract = x_hr & image_subpixel_mask;
466
+ unsigned y_count = diameter;
467
+
468
+ y_hr = image_subpixel_mask - (y_hr & image_subpixel_mask);
469
+ fg_ptr = (const value_type*)base_type::source().span(x_lr + start,
470
+ y_lr + start,
471
+ diameter);
472
+ for(;;)
473
+ {
474
+ x_count = diameter;
475
+ weight_y = weight_array[y_hr];
476
+ x_hr = image_subpixel_mask - x_fract;
477
+ for(;;)
478
+ {
479
+ fg += *fg_ptr *
480
+ ((weight_y * weight_array[x_hr] +
481
+ image_filter_scale / 2) >>
482
+ image_filter_shift);
483
+ if(--x_count == 0) break;
484
+ x_hr += image_subpixel_scale;
485
+ fg_ptr = (const value_type*)base_type::source().next_x();
486
+ }
487
+
488
+ if(--y_count == 0) break;
489
+ y_hr += image_subpixel_scale;
490
+ fg_ptr = (const value_type*)base_type::source().next_y();
491
+ }
492
+
493
+ fg = color_type::downshift(fg, image_filter_shift);
494
+ if(fg < 0) fg = 0;
495
+ if(fg > color_type::full_value()) fg = color_type::full_value();
496
+ span->v = (value_type)fg;
497
+ span->a = color_type::full_value();
498
+
499
+ ++span;
500
+ ++base_type::interpolator();
501
+
502
+ } while(--len);
503
+ }
504
+ };
505
+
506
+
507
+
508
+ //=========================================span_image_resample_gray_affine
509
+ template<class Source>
510
+ class span_image_resample_gray_affine :
511
+ public span_image_resample_affine<Source>
512
+ {
513
+ public:
514
+ typedef Source source_type;
515
+ typedef typename source_type::color_type color_type;
516
+ typedef span_image_resample_affine<source_type> base_type;
517
+ typedef typename base_type::interpolator_type interpolator_type;
518
+ typedef typename color_type::value_type value_type;
519
+ typedef typename color_type::long_type long_type;
520
+ enum base_scale_e
521
+ {
522
+ downscale_shift = image_filter_shift
523
+ };
524
+
525
+ //--------------------------------------------------------------------
526
+ span_image_resample_gray_affine() {}
527
+ span_image_resample_gray_affine(source_type& src,
528
+ interpolator_type& inter,
529
+ image_filter_lut& filter) :
530
+ base_type(src, inter, filter)
531
+ {}
532
+
533
+
534
+ //--------------------------------------------------------------------
535
+ void generate(color_type* span, int x, int y, unsigned len)
536
+ {
537
+ base_type::interpolator().begin(x + base_type::filter_dx_dbl(),
538
+ y + base_type::filter_dy_dbl(), len);
539
+
540
+ long_type fg;
541
+
542
+ int diameter = base_type::filter().diameter();
543
+ int filter_scale = diameter << image_subpixel_shift;
544
+ int radius_x = (diameter * base_type::m_rx) >> 1;
545
+ int radius_y = (diameter * base_type::m_ry) >> 1;
546
+ int len_x_lr =
547
+ (diameter * base_type::m_rx + image_subpixel_mask) >>
548
+ image_subpixel_shift;
549
+
550
+ const int16* weight_array = base_type::filter().weight_array();
551
+
552
+ do
553
+ {
554
+ base_type::interpolator().coordinates(&x, &y);
555
+
556
+ x += base_type::filter_dx_int() - radius_x;
557
+ y += base_type::filter_dy_int() - radius_y;
558
+
559
+ fg = 0;
560
+
561
+ int y_lr = y >> image_subpixel_shift;
562
+ int y_hr = ((image_subpixel_mask - (y & image_subpixel_mask)) *
563
+ base_type::m_ry_inv) >>
564
+ image_subpixel_shift;
565
+ int total_weight = 0;
566
+ int x_lr = x >> image_subpixel_shift;
567
+ int x_hr = ((image_subpixel_mask - (x & image_subpixel_mask)) *
568
+ base_type::m_rx_inv) >>
569
+ image_subpixel_shift;
570
+
571
+ int x_hr2 = x_hr;
572
+ const value_type* fg_ptr =
573
+ (const value_type*)base_type::source().span(x_lr, y_lr, len_x_lr);
574
+ for(;;)
575
+ {
576
+ int weight_y = weight_array[y_hr];
577
+ x_hr = x_hr2;
578
+ for(;;)
579
+ {
580
+ int weight = (weight_y * weight_array[x_hr] +
581
+ image_filter_scale / 2) >>
582
+ downscale_shift;
583
+
584
+ fg += *fg_ptr * weight;
585
+ total_weight += weight;
586
+ x_hr += base_type::m_rx_inv;
587
+ if(x_hr >= filter_scale) break;
588
+ fg_ptr = (const value_type*)base_type::source().next_x();
589
+ }
590
+ y_hr += base_type::m_ry_inv;
591
+ if(y_hr >= filter_scale) break;
592
+ fg_ptr = (const value_type*)base_type::source().next_y();
593
+ }
594
+
595
+ fg /= total_weight;
596
+ if(fg < 0) fg = 0;
597
+ if(fg > color_type::full_value()) fg = color_type::full_value();
598
+
599
+ span->v = (value_type)fg;
600
+ span->a = color_type::full_value();
601
+
602
+ ++span;
603
+ ++base_type::interpolator();
604
+ } while(--len);
605
+ }
606
+ };
607
+
608
+
609
+
610
+ //================================================span_image_resample_gray
611
+ template<class Source, class Interpolator>
612
+ class span_image_resample_gray :
613
+ public span_image_resample<Source, Interpolator>
614
+ {
615
+ public:
616
+ typedef Source source_type;
617
+ typedef typename source_type::color_type color_type;
618
+ typedef Interpolator interpolator_type;
619
+ typedef span_image_resample<source_type, interpolator_type> base_type;
620
+ typedef typename color_type::value_type value_type;
621
+ typedef typename color_type::long_type long_type;
622
+ enum base_scale_e
623
+ {
624
+ downscale_shift = image_filter_shift
625
+ };
626
+
627
+ //--------------------------------------------------------------------
628
+ span_image_resample_gray() {}
629
+ span_image_resample_gray(source_type& src,
630
+ interpolator_type& inter,
631
+ image_filter_lut& filter) :
632
+ base_type(src, inter, filter)
633
+ {}
634
+
635
+ //--------------------------------------------------------------------
636
+ void generate(color_type* span, int x, int y, unsigned len)
637
+ {
638
+ base_type::interpolator().begin(x + base_type::filter_dx_dbl(),
639
+ y + base_type::filter_dy_dbl(), len);
640
+ long_type fg;
641
+
642
+ int diameter = base_type::filter().diameter();
643
+ int filter_scale = diameter << image_subpixel_shift;
644
+
645
+ const int16* weight_array = base_type::filter().weight_array();
646
+ do
647
+ {
648
+ int rx;
649
+ int ry;
650
+ int rx_inv = image_subpixel_scale;
651
+ int ry_inv = image_subpixel_scale;
652
+ base_type::interpolator().coordinates(&x, &y);
653
+ base_type::interpolator().local_scale(&rx, &ry);
654
+ base_type::adjust_scale(&rx, &ry);
655
+
656
+ rx_inv = image_subpixel_scale * image_subpixel_scale / rx;
657
+ ry_inv = image_subpixel_scale * image_subpixel_scale / ry;
658
+
659
+ int radius_x = (diameter * rx) >> 1;
660
+ int radius_y = (diameter * ry) >> 1;
661
+ int len_x_lr =
662
+ (diameter * rx + image_subpixel_mask) >>
663
+ image_subpixel_shift;
664
+
665
+ x += base_type::filter_dx_int() - radius_x;
666
+ y += base_type::filter_dy_int() - radius_y;
667
+
668
+ fg = 0;
669
+
670
+ int y_lr = y >> image_subpixel_shift;
671
+ int y_hr = ((image_subpixel_mask - (y & image_subpixel_mask)) *
672
+ ry_inv) >>
673
+ image_subpixel_shift;
674
+ int total_weight = 0;
675
+ int x_lr = x >> image_subpixel_shift;
676
+ int x_hr = ((image_subpixel_mask - (x & image_subpixel_mask)) *
677
+ rx_inv) >>
678
+ image_subpixel_shift;
679
+ int x_hr2 = x_hr;
680
+ const value_type* fg_ptr =
681
+ (const value_type*)base_type::source().span(x_lr, y_lr, len_x_lr);
682
+
683
+ for(;;)
684
+ {
685
+ int weight_y = weight_array[y_hr];
686
+ x_hr = x_hr2;
687
+ for(;;)
688
+ {
689
+ int weight = (weight_y * weight_array[x_hr] +
690
+ image_filter_scale / 2) >>
691
+ downscale_shift;
692
+ fg += *fg_ptr * weight;
693
+ total_weight += weight;
694
+ x_hr += rx_inv;
695
+ if(x_hr >= filter_scale) break;
696
+ fg_ptr = (const value_type*)base_type::source().next_x();
697
+ }
698
+ y_hr += ry_inv;
699
+ if(y_hr >= filter_scale) break;
700
+ fg_ptr = (const value_type*)base_type::source().next_y();
701
+ }
702
+
703
+ fg /= total_weight;
704
+ if(fg < 0) fg = 0;
705
+ if(fg > color_type::full_value()) fg = color_type::full_value();
706
+
707
+ span->v = (value_type)fg;
708
+ span->a = color_type::full_value();
709
+
710
+ ++span;
711
+ ++base_type::interpolator();
712
+ } while(--len);
713
+ }
714
+ };
715
+
716
+
717
+ }
718
+
719
+
720
+ #endif
721
+
722
+
723
+
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_span_interpolator_linear.h ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+
16
+ #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<class Transformer = trans_affine, unsigned SubpixelShift = 8>
28
+ class span_interpolator_linear
29
+ {
30
+ public:
31
+ typedef Transformer trans_type;
32
+
33
+ enum subpixel_scale_e
34
+ {
35
+ subpixel_shift = SubpixelShift,
36
+ subpixel_scale = 1 << subpixel_shift
37
+ };
38
+
39
+ //--------------------------------------------------------------------
40
+ span_interpolator_linear() {}
41
+ span_interpolator_linear(trans_type& trans) : m_trans(&trans) {}
42
+ span_interpolator_linear(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(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 = iround(tx * subpixel_scale);
63
+ int y1 = iround(ty * subpixel_scale);
64
+
65
+ tx = x + len;
66
+ ty = y;
67
+ m_trans->transform(&tx, &ty);
68
+ int x2 = iround(tx * subpixel_scale);
69
+ int y2 = iround(ty * subpixel_scale);
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 resynchronize(double xe, double ye, unsigned len)
77
+ {
78
+ m_trans->transform(&xe, &ye);
79
+ m_li_x = dda2_line_interpolator(m_li_x.y(), iround(xe * subpixel_scale), len);
80
+ m_li_y = dda2_line_interpolator(m_li_y.y(), iround(ye * subpixel_scale), len);
81
+ }
82
+
83
+ //----------------------------------------------------------------
84
+ void operator++()
85
+ {
86
+ ++m_li_x;
87
+ ++m_li_y;
88
+ }
89
+
90
+ //----------------------------------------------------------------
91
+ void coordinates(int* x, int* y) const
92
+ {
93
+ *x = m_li_x.y();
94
+ *y = m_li_y.y();
95
+ }
96
+
97
+ private:
98
+ trans_type* m_trans;
99
+ dda2_line_interpolator m_li_x;
100
+ dda2_line_interpolator m_li_y;
101
+ };
102
+
103
+
104
+
105
+
106
+
107
+
108
+ //=====================================span_interpolator_linear_subdiv
109
+ template<class Transformer = trans_affine, unsigned SubpixelShift = 8>
110
+ class span_interpolator_linear_subdiv
111
+ {
112
+ public:
113
+ typedef Transformer trans_type;
114
+
115
+ enum subpixel_scale_e
116
+ {
117
+ subpixel_shift = SubpixelShift,
118
+ subpixel_scale = 1 << subpixel_shift
119
+ };
120
+
121
+
122
+ //----------------------------------------------------------------
123
+ span_interpolator_linear_subdiv() :
124
+ m_subdiv_shift(4),
125
+ m_subdiv_size(1 << m_subdiv_shift),
126
+ m_subdiv_mask(m_subdiv_size - 1) {}
127
+
128
+ span_interpolator_linear_subdiv(trans_type& trans,
129
+ unsigned subdiv_shift = 4) :
130
+ m_subdiv_shift(subdiv_shift),
131
+ m_subdiv_size(1 << m_subdiv_shift),
132
+ m_subdiv_mask(m_subdiv_size - 1),
133
+ m_trans(&trans) {}
134
+
135
+ span_interpolator_linear_subdiv(trans_type& trans,
136
+ double x, double y, unsigned len,
137
+ unsigned subdiv_shift = 4) :
138
+ m_subdiv_shift(subdiv_shift),
139
+ m_subdiv_size(1 << m_subdiv_shift),
140
+ m_subdiv_mask(m_subdiv_size - 1),
141
+ m_trans(&trans)
142
+ {
143
+ begin(x, y, len);
144
+ }
145
+
146
+ //----------------------------------------------------------------
147
+ const trans_type& transformer() const { return *m_trans; }
148
+ void transformer(const trans_type& trans) { m_trans = &trans; }
149
+
150
+ //----------------------------------------------------------------
151
+ unsigned subdiv_shift() const { return m_subdiv_shift; }
152
+ void subdiv_shift(unsigned shift)
153
+ {
154
+ m_subdiv_shift = shift;
155
+ m_subdiv_size = 1 << m_subdiv_shift;
156
+ m_subdiv_mask = m_subdiv_size - 1;
157
+ }
158
+
159
+ //----------------------------------------------------------------
160
+ void begin(double x, double y, unsigned len)
161
+ {
162
+ double tx;
163
+ double ty;
164
+ m_pos = 1;
165
+ m_src_x = iround(x * subpixel_scale) + subpixel_scale;
166
+ m_src_y = y;
167
+ m_len = len;
168
+
169
+ if(len > m_subdiv_size) len = m_subdiv_size;
170
+ tx = x;
171
+ ty = y;
172
+ m_trans->transform(&tx, &ty);
173
+ int x1 = iround(tx * subpixel_scale);
174
+ int y1 = iround(ty * subpixel_scale);
175
+
176
+ tx = x + len;
177
+ ty = y;
178
+ m_trans->transform(&tx, &ty);
179
+
180
+ m_li_x = dda2_line_interpolator(x1, iround(tx * subpixel_scale), len);
181
+ m_li_y = dda2_line_interpolator(y1, iround(ty * subpixel_scale), len);
182
+ }
183
+
184
+ //----------------------------------------------------------------
185
+ void operator++()
186
+ {
187
+ ++m_li_x;
188
+ ++m_li_y;
189
+ if(m_pos >= m_subdiv_size)
190
+ {
191
+ unsigned len = m_len;
192
+ if(len > m_subdiv_size) len = m_subdiv_size;
193
+ double tx = double(m_src_x) / double(subpixel_scale) + len;
194
+ double ty = m_src_y;
195
+ m_trans->transform(&tx, &ty);
196
+ m_li_x = dda2_line_interpolator(m_li_x.y(), iround(tx * subpixel_scale), len);
197
+ m_li_y = dda2_line_interpolator(m_li_y.y(), iround(ty * subpixel_scale), len);
198
+ m_pos = 0;
199
+ }
200
+ m_src_x += subpixel_scale;
201
+ ++m_pos;
202
+ --m_len;
203
+ }
204
+
205
+ //----------------------------------------------------------------
206
+ void coordinates(int* x, int* y) const
207
+ {
208
+ *x = m_li_x.y();
209
+ *y = m_li_y.y();
210
+ }
211
+
212
+ private:
213
+ unsigned m_subdiv_shift;
214
+ unsigned m_subdiv_size;
215
+ unsigned m_subdiv_mask;
216
+ trans_type* m_trans;
217
+ dda2_line_interpolator m_li_x;
218
+ dda2_line_interpolator m_li_y;
219
+ int m_src_x;
220
+ double m_src_y;
221
+ unsigned m_pos;
222
+ unsigned m_len;
223
+ };
224
+
225
+
226
+ }
227
+
228
+
229
+
230
+ #endif
231
+
232
+
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_span_pattern_rgb.h ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+ //
16
+ // Adaptation for high precision colors has been sponsored by
17
+ // Liberty Technology Systems, Inc., visit http://lib-sys.com
18
+ //
19
+ // Liberty Technology Systems, Inc. is the provider of
20
+ // PostScript and PDF technology for software developers.
21
+ //
22
+ //----------------------------------------------------------------------------
23
+
24
+
25
+ #ifndef AGG_SPAN_PATTERN_RGB_INCLUDED
26
+ #define AGG_SPAN_PATTERN_RGB_INCLUDED
27
+
28
+ #include "agg_basics.h"
29
+
30
+ namespace agg
31
+ {
32
+
33
+ //========================================================span_pattern_rgb
34
+ template<class Source> class span_pattern_rgb
35
+ {
36
+ public:
37
+ typedef Source source_type;
38
+ typedef typename source_type::color_type color_type;
39
+ typedef typename source_type::order_type order_type;
40
+ typedef typename color_type::value_type value_type;
41
+ typedef typename color_type::calc_type calc_type;
42
+
43
+ //--------------------------------------------------------------------
44
+ span_pattern_rgb() {}
45
+ span_pattern_rgb(source_type& src,
46
+ unsigned offset_x, unsigned offset_y) :
47
+ m_src(&src),
48
+ m_offset_x(offset_x),
49
+ m_offset_y(offset_y),
50
+ m_alpha(color_type::base_mask)
51
+ {}
52
+
53
+ //--------------------------------------------------------------------
54
+ void attach(source_type& v) { m_src = &v; }
55
+ source_type& source() { return *m_src; }
56
+ const source_type& source() const { return *m_src; }
57
+
58
+ //--------------------------------------------------------------------
59
+ void offset_x(unsigned v) { m_offset_x = v; }
60
+ void offset_y(unsigned v) { m_offset_y = v; }
61
+ unsigned offset_x() const { return m_offset_x; }
62
+ unsigned offset_y() const { return m_offset_y; }
63
+ void alpha(value_type v) { m_alpha = v; }
64
+ value_type alpha() const { return m_alpha; }
65
+
66
+ //--------------------------------------------------------------------
67
+ void prepare() {}
68
+ void generate(color_type* span, int x, int y, unsigned len)
69
+ {
70
+ x += m_offset_x;
71
+ y += m_offset_y;
72
+ const value_type* p = (const value_type*)m_src->span(x, y, len);
73
+ do
74
+ {
75
+ span->r = p[order_type::R];
76
+ span->g = p[order_type::G];
77
+ span->b = p[order_type::B];
78
+ span->a = m_alpha;
79
+ p = m_src->next_x();
80
+ ++span;
81
+ }
82
+ while(--len);
83
+ }
84
+
85
+ private:
86
+ source_type* m_src;
87
+ unsigned m_offset_x;
88
+ unsigned m_offset_y;
89
+ value_type m_alpha;
90
+
91
+ };
92
+
93
+ }
94
+
95
+ #endif
96
+
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_span_solid.h ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+ //
16
+ // 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
+
25
+ namespace agg
26
+ {
27
+ //--------------------------------------------------------------span_solid
28
+ template<class ColorT> class span_solid
29
+ {
30
+ public:
31
+ typedef ColorT color_type;
32
+
33
+ //--------------------------------------------------------------------
34
+ void color(const color_type& c) { m_color = c; }
35
+ const color_type& color() const { return m_color; }
36
+
37
+ //--------------------------------------------------------------------
38
+ void prepare() {}
39
+
40
+ //--------------------------------------------------------------------
41
+ void generate(color_type* span, int x, int y, unsigned len)
42
+ {
43
+ do { *span++ = m_color; } while(--len);
44
+ }
45
+
46
+ private:
47
+ color_type m_color;
48
+ };
49
+
50
+
51
+ }
52
+
53
+ #endif
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_span_subdiv_adaptor.h ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+ #ifndef AGG_SPAN_SUBDIV_ADAPTOR_INCLUDED
16
+ #define AGG_SPAN_SUBDIV_ADAPTOR_INCLUDED
17
+
18
+ #include "agg_basics.h"
19
+
20
+ namespace agg
21
+ {
22
+
23
+ //=================================================span_subdiv_adaptor
24
+ template<class Interpolator, unsigned SubpixelShift = 8>
25
+ class span_subdiv_adaptor
26
+ {
27
+ public:
28
+ typedef Interpolator interpolator_type;
29
+ typedef typename interpolator_type::trans_type trans_type;
30
+
31
+ enum sublixel_scale_e
32
+ {
33
+ subpixel_shift = SubpixelShift,
34
+ subpixel_scale = 1 << subpixel_shift
35
+ };
36
+
37
+
38
+ //----------------------------------------------------------------
39
+ span_subdiv_adaptor() :
40
+ m_subdiv_shift(4),
41
+ m_subdiv_size(1 << m_subdiv_shift),
42
+ m_subdiv_mask(m_subdiv_size - 1) {}
43
+
44
+ span_subdiv_adaptor(interpolator_type& interpolator,
45
+ unsigned subdiv_shift = 4) :
46
+ m_subdiv_shift(subdiv_shift),
47
+ m_subdiv_size(1 << m_subdiv_shift),
48
+ m_subdiv_mask(m_subdiv_size - 1),
49
+ m_interpolator(&interpolator) {}
50
+
51
+ span_subdiv_adaptor(interpolator_type& interpolator,
52
+ double x, double y, unsigned len,
53
+ unsigned subdiv_shift = 4) :
54
+ m_subdiv_shift(subdiv_shift),
55
+ m_subdiv_size(1 << m_subdiv_shift),
56
+ m_subdiv_mask(m_subdiv_size - 1),
57
+ m_interpolator(&interpolator)
58
+ {
59
+ begin(x, y, len);
60
+ }
61
+
62
+
63
+ //----------------------------------------------------------------
64
+ const interpolator_type& interpolator() const { return *m_interpolator; }
65
+ void interpolator(interpolator_type& intr) { m_interpolator = &intr; }
66
+
67
+ //----------------------------------------------------------------
68
+ const trans_type& transformer() const
69
+ {
70
+ return *m_interpolator->transformer();
71
+ }
72
+ void transformer(const trans_type& trans)
73
+ {
74
+ m_interpolator->transformer(trans);
75
+ }
76
+
77
+ //----------------------------------------------------------------
78
+ unsigned subdiv_shift() const { return m_subdiv_shift; }
79
+ void subdiv_shift(unsigned shift)
80
+ {
81
+ m_subdiv_shift = shift;
82
+ m_subdiv_size = 1 << m_subdiv_shift;
83
+ m_subdiv_mask = m_subdiv_size - 1;
84
+ }
85
+
86
+ //----------------------------------------------------------------
87
+ void begin(double x, double y, unsigned len)
88
+ {
89
+ m_pos = 1;
90
+ m_src_x = iround(x * subpixel_scale) + subpixel_scale;
91
+ m_src_y = y;
92
+ m_len = len;
93
+ if(len > m_subdiv_size) len = m_subdiv_size;
94
+ m_interpolator->begin(x, y, len);
95
+ }
96
+
97
+ //----------------------------------------------------------------
98
+ void operator++()
99
+ {
100
+ ++(*m_interpolator);
101
+ if(m_pos >= m_subdiv_size)
102
+ {
103
+ unsigned len = m_len;
104
+ if(len > m_subdiv_size) len = m_subdiv_size;
105
+ m_interpolator->resynchronize(double(m_src_x) / double(subpixel_scale) + len,
106
+ m_src_y,
107
+ len);
108
+ m_pos = 0;
109
+ }
110
+ m_src_x += subpixel_scale;
111
+ ++m_pos;
112
+ --m_len;
113
+ }
114
+
115
+ //----------------------------------------------------------------
116
+ void coordinates(int* x, int* y) const
117
+ {
118
+ m_interpolator->coordinates(x, y);
119
+ }
120
+
121
+ //----------------------------------------------------------------
122
+ void local_scale(int* x, int* y) const
123
+ {
124
+ m_interpolator->local_scale(x, y);
125
+ }
126
+
127
+
128
+ private:
129
+ unsigned m_subdiv_shift;
130
+ unsigned m_subdiv_size;
131
+ unsigned m_subdiv_mask;
132
+ interpolator_type* m_interpolator;
133
+ int m_src_x;
134
+ double m_src_y;
135
+ unsigned m_pos;
136
+ unsigned m_len;
137
+ };
138
+
139
+ }
140
+
141
+ #endif
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_trans_affine.h ADDED
@@ -0,0 +1,518 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+ //
16
+ // Affine transformation classes.
17
+ //
18
+ //----------------------------------------------------------------------------
19
+ #ifndef AGG_TRANS_AFFINE_INCLUDED
20
+ #define AGG_TRANS_AFFINE_INCLUDED
21
+
22
+ #include <math.h>
23
+ #include "agg_basics.h"
24
+
25
+ namespace agg
26
+ {
27
+ const double affine_epsilon = 1e-14;
28
+
29
+ //============================================================trans_affine
30
+ //
31
+ // See Implementation agg_trans_affine.cpp
32
+ //
33
+ // Affine transformation are linear transformations in Cartesian coordinates
34
+ // (strictly speaking not only in Cartesian, but for the beginning we will
35
+ // think so). They are rotation, scaling, translation and skewing.
36
+ // After any affine transformation a line segment remains a line segment
37
+ // and it will never become a curve.
38
+ //
39
+ // There will be no math about matrix calculations, since it has been
40
+ // described many times. Ask yourself a very simple question:
41
+ // "why do we need to understand and use some matrix stuff instead of just
42
+ // rotating, scaling and so on". The answers are:
43
+ //
44
+ // 1. Any combination of transformations can be done by only 4 multiplications
45
+ // and 4 additions in floating point.
46
+ // 2. One matrix transformation is equivalent to the number of consecutive
47
+ // discrete transformations, i.e. the matrix "accumulates" all transformations
48
+ // in the order of their settings. Suppose we have 4 transformations:
49
+ // * rotate by 30 degrees,
50
+ // * scale X to 2.0,
51
+ // * scale Y to 1.5,
52
+ // * move to (100, 100).
53
+ // The result will depend on the order of these transformations,
54
+ // and the advantage of matrix is that the sequence of discret calls:
55
+ // rotate(30), scaleX(2.0), scaleY(1.5), move(100,100)
56
+ // will have exactly the same result as the following matrix transformations:
57
+ //
58
+ // affine_matrix m;
59
+ // m *= rotate_matrix(30);
60
+ // m *= scaleX_matrix(2.0);
61
+ // m *= scaleY_matrix(1.5);
62
+ // m *= move_matrix(100,100);
63
+ //
64
+ // m.transform_my_point_at_last(x, y);
65
+ //
66
+ // What is the good of it? In real life we will set-up the matrix only once
67
+ // and then transform many points, let alone the convenience to set any
68
+ // combination of transformations.
69
+ //
70
+ // So, how to use it? Very easy - literally as it's shown above. Not quite,
71
+ // let us write a correct example:
72
+ //
73
+ // agg::trans_affine m;
74
+ // m *= agg::trans_affine_rotation(30.0 * 3.1415926 / 180.0);
75
+ // m *= agg::trans_affine_scaling(2.0, 1.5);
76
+ // m *= agg::trans_affine_translation(100.0, 100.0);
77
+ // m.transform(&x, &y);
78
+ //
79
+ // The affine matrix is all you need to perform any linear transformation,
80
+ // but all transformations have origin point (0,0). It means that we need to
81
+ // use 2 translations if we want to rotate someting around (100,100):
82
+ //
83
+ // m *= agg::trans_affine_translation(-100.0, -100.0); // move to (0,0)
84
+ // m *= agg::trans_affine_rotation(30.0 * 3.1415926 / 180.0); // rotate
85
+ // m *= agg::trans_affine_translation(100.0, 100.0); // move back to (100,100)
86
+ //----------------------------------------------------------------------
87
+ struct trans_affine
88
+ {
89
+ double sx, shy, shx, sy, tx, ty;
90
+
91
+ //------------------------------------------ Construction
92
+ // Identity matrix
93
+ trans_affine() :
94
+ sx(1.0), shy(0.0), shx(0.0), sy(1.0), tx(0.0), ty(0.0)
95
+ {}
96
+
97
+ // Custom matrix. Usually used in derived classes
98
+ trans_affine(double v0, double v1, double v2,
99
+ double v3, double v4, double v5) :
100
+ sx(v0), shy(v1), shx(v2), sy(v3), tx(v4), ty(v5)
101
+ {}
102
+
103
+ // Custom matrix from m[6]
104
+ explicit trans_affine(const double* m) :
105
+ sx(m[0]), shy(m[1]), shx(m[2]), sy(m[3]), tx(m[4]), ty(m[5])
106
+ {}
107
+
108
+ // Rectangle to a parallelogram.
109
+ trans_affine(double x1, double y1, double x2, double y2,
110
+ const double* parl)
111
+ {
112
+ rect_to_parl(x1, y1, x2, y2, parl);
113
+ }
114
+
115
+ // Parallelogram to a rectangle.
116
+ trans_affine(const double* parl,
117
+ double x1, double y1, double x2, double y2)
118
+ {
119
+ parl_to_rect(parl, x1, y1, x2, y2);
120
+ }
121
+
122
+ // Arbitrary parallelogram transformation.
123
+ trans_affine(const double* src, const double* dst)
124
+ {
125
+ parl_to_parl(src, dst);
126
+ }
127
+
128
+ //---------------------------------- Parellelogram transformations
129
+ // transform a parallelogram to another one. Src and dst are
130
+ // pointers to arrays of three points (double[6], x1,y1,...) that
131
+ // identify three corners of the parallelograms assuming implicit
132
+ // fourth point. The arguments are arrays of double[6] mapped
133
+ // to x1,y1, x2,y2, x3,y3 where the coordinates are:
134
+ // *-----------------*
135
+ // / (x3,y3)/
136
+ // / /
137
+ // /(x1,y1) (x2,y2)/
138
+ // *-----------------*
139
+ const trans_affine& parl_to_parl(const double* src,
140
+ const double* dst);
141
+
142
+ const trans_affine& rect_to_parl(double x1, double y1,
143
+ double x2, double y2,
144
+ const double* parl);
145
+
146
+ const trans_affine& parl_to_rect(const double* parl,
147
+ double x1, double y1,
148
+ double x2, double y2);
149
+
150
+
151
+ //------------------------------------------ Operations
152
+ // Reset - load an identity matrix
153
+ const trans_affine& reset();
154
+
155
+ // Direct transformations operations
156
+ const trans_affine& translate(double x, double y);
157
+ const trans_affine& rotate(double a);
158
+ const trans_affine& scale(double s);
159
+ const trans_affine& scale(double x, double y);
160
+
161
+ // Multiply matrix to another one
162
+ const trans_affine& multiply(const trans_affine& m);
163
+
164
+ // Multiply "m" to "this" and assign the result to "this"
165
+ const trans_affine& premultiply(const trans_affine& m);
166
+
167
+ // Multiply matrix to inverse of another one
168
+ const trans_affine& multiply_inv(const trans_affine& m);
169
+
170
+ // Multiply inverse of "m" to "this" and assign the result to "this"
171
+ const trans_affine& premultiply_inv(const trans_affine& m);
172
+
173
+ // Invert matrix. Do not try to invert degenerate matrices,
174
+ // there's no check for validity. If you set scale to 0 and
175
+ // then try to invert matrix, expect unpredictable result.
176
+ const trans_affine& invert();
177
+
178
+ // Mirroring around X
179
+ const trans_affine& flip_x();
180
+
181
+ // Mirroring around Y
182
+ const trans_affine& flip_y();
183
+
184
+ //------------------------------------------- Load/Store
185
+ // Store matrix to an array [6] of double
186
+ void store_to(double* m) const
187
+ {
188
+ *m++ = sx; *m++ = shy; *m++ = shx; *m++ = sy; *m++ = tx; *m++ = ty;
189
+ }
190
+
191
+ // Load matrix from an array [6] of double
192
+ const trans_affine& load_from(const double* m)
193
+ {
194
+ sx = *m++; shy = *m++; shx = *m++; sy = *m++; tx = *m++; ty = *m++;
195
+ return *this;
196
+ }
197
+
198
+ //------------------------------------------- Operators
199
+
200
+ // Multiply the matrix by another one
201
+ const trans_affine& operator *= (const trans_affine& m)
202
+ {
203
+ return multiply(m);
204
+ }
205
+
206
+ // Multiply the matrix by inverse of another one
207
+ const trans_affine& operator /= (const trans_affine& m)
208
+ {
209
+ return multiply_inv(m);
210
+ }
211
+
212
+ // Multiply the matrix by another one and return
213
+ // the result in a separete matrix.
214
+ trans_affine operator * (const trans_affine& m) const
215
+ {
216
+ return trans_affine(*this).multiply(m);
217
+ }
218
+
219
+ // Multiply the matrix by inverse of another one
220
+ // and return the result in a separete matrix.
221
+ trans_affine operator / (const trans_affine& m) const
222
+ {
223
+ return trans_affine(*this).multiply_inv(m);
224
+ }
225
+
226
+ // Calculate and return the inverse matrix
227
+ trans_affine operator ~ () const
228
+ {
229
+ trans_affine ret = *this;
230
+ return ret.invert();
231
+ }
232
+
233
+ // Equal operator with default epsilon
234
+ bool operator == (const trans_affine& m) const
235
+ {
236
+ return is_equal(m, affine_epsilon);
237
+ }
238
+
239
+ // Not Equal operator with default epsilon
240
+ bool operator != (const trans_affine& m) const
241
+ {
242
+ return !is_equal(m, affine_epsilon);
243
+ }
244
+
245
+ //-------------------------------------------- Transformations
246
+ // Direct transformation of x and y
247
+ void transform(double* x, double* y) const;
248
+
249
+ // Direct transformation of x and y, 2x2 matrix only, no translation
250
+ void transform_2x2(double* x, double* y) const;
251
+
252
+ // Inverse transformation of x and y. It works slower than the
253
+ // direct transformation. For massive operations it's better to
254
+ // invert() the matrix and then use direct transformations.
255
+ void inverse_transform(double* x, double* y) const;
256
+
257
+ //-------------------------------------------- Auxiliary
258
+ // Calculate the determinant of matrix
259
+ double determinant() const
260
+ {
261
+ return sx * sy - shy * shx;
262
+ }
263
+
264
+ // Calculate the reciprocal of the determinant
265
+ double determinant_reciprocal() const
266
+ {
267
+ return 1.0 / (sx * sy - shy * shx);
268
+ }
269
+
270
+ // Get the average scale (by X and Y).
271
+ // Basically used to calculate the approximation_scale when
272
+ // decomposinting curves into line segments.
273
+ double scale() const;
274
+
275
+ // Check to see if the matrix is not degenerate
276
+ bool is_valid(double epsilon = affine_epsilon) const;
277
+
278
+ // Check to see if it's an identity matrix
279
+ bool is_identity(double epsilon = affine_epsilon) const;
280
+
281
+ // Check to see if two matrices are equal
282
+ bool is_equal(const trans_affine& m, double epsilon = affine_epsilon) const;
283
+
284
+ // Determine the major parameters. Use with caution considering
285
+ // possible degenerate cases.
286
+ double rotation() const;
287
+ void translation(double* dx, double* dy) const;
288
+ void scaling(double* x, double* y) const;
289
+ void scaling_abs(double* x, double* y) const;
290
+ };
291
+
292
+ //------------------------------------------------------------------------
293
+ inline void trans_affine::transform(double* x, double* y) const
294
+ {
295
+ double tmp = *x;
296
+ *x = tmp * sx + *y * shx + tx;
297
+ *y = tmp * shy + *y * sy + ty;
298
+ }
299
+
300
+ //------------------------------------------------------------------------
301
+ inline void trans_affine::transform_2x2(double* x, double* y) const
302
+ {
303
+ double tmp = *x;
304
+ *x = tmp * sx + *y * shx;
305
+ *y = tmp * shy + *y * sy;
306
+ }
307
+
308
+ //------------------------------------------------------------------------
309
+ inline void trans_affine::inverse_transform(double* x, double* y) const
310
+ {
311
+ double d = determinant_reciprocal();
312
+ double a = (*x - tx) * d;
313
+ double b = (*y - ty) * d;
314
+ *x = a * sy - b * shx;
315
+ *y = b * sx - a * shy;
316
+ }
317
+
318
+ //------------------------------------------------------------------------
319
+ inline double trans_affine::scale() const
320
+ {
321
+ double x = 0.707106781 * sx + 0.707106781 * shx;
322
+ double y = 0.707106781 * shy + 0.707106781 * sy;
323
+ return sqrt(x*x + y*y);
324
+ }
325
+
326
+ //------------------------------------------------------------------------
327
+ inline const trans_affine& trans_affine::translate(double x, double y)
328
+ {
329
+ tx += x;
330
+ ty += y;
331
+ return *this;
332
+ }
333
+
334
+ //------------------------------------------------------------------------
335
+ inline const trans_affine& trans_affine::rotate(double a)
336
+ {
337
+ double ca = cos(a);
338
+ double sa = sin(a);
339
+ double t0 = sx * ca - shy * sa;
340
+ double t2 = shx * ca - sy * sa;
341
+ double t4 = tx * ca - ty * sa;
342
+ shy = sx * sa + shy * ca;
343
+ sy = shx * sa + sy * ca;
344
+ ty = tx * sa + ty * ca;
345
+ sx = t0;
346
+ shx = t2;
347
+ tx = t4;
348
+ return *this;
349
+ }
350
+
351
+ //------------------------------------------------------------------------
352
+ inline const trans_affine& trans_affine::scale(double x, double y)
353
+ {
354
+ double mm0 = x; // Possible hint for the optimizer
355
+ double mm3 = y;
356
+ sx *= mm0;
357
+ shx *= mm0;
358
+ tx *= mm0;
359
+ shy *= mm3;
360
+ sy *= mm3;
361
+ ty *= mm3;
362
+ return *this;
363
+ }
364
+
365
+ //------------------------------------------------------------------------
366
+ inline const trans_affine& trans_affine::scale(double s)
367
+ {
368
+ double m = s; // Possible hint for the optimizer
369
+ sx *= m;
370
+ shx *= m;
371
+ tx *= m;
372
+ shy *= m;
373
+ sy *= m;
374
+ ty *= m;
375
+ return *this;
376
+ }
377
+
378
+ //------------------------------------------------------------------------
379
+ inline const trans_affine& trans_affine::premultiply(const trans_affine& m)
380
+ {
381
+ trans_affine t = m;
382
+ return *this = t.multiply(*this);
383
+ }
384
+
385
+ //------------------------------------------------------------------------
386
+ inline const trans_affine& trans_affine::multiply_inv(const trans_affine& m)
387
+ {
388
+ trans_affine t = m;
389
+ t.invert();
390
+ return multiply(t);
391
+ }
392
+
393
+ //------------------------------------------------------------------------
394
+ inline const trans_affine& trans_affine::premultiply_inv(const trans_affine& m)
395
+ {
396
+ trans_affine t = m;
397
+ t.invert();
398
+ return *this = t.multiply(*this);
399
+ }
400
+
401
+ //------------------------------------------------------------------------
402
+ inline void trans_affine::scaling_abs(double* x, double* y) const
403
+ {
404
+ // Used to calculate scaling coefficients in image resampling.
405
+ // When there is considerable shear this method gives us much
406
+ // better estimation than just sx, sy.
407
+ *x = sqrt(sx * sx + shx * shx);
408
+ *y = sqrt(shy * shy + sy * sy);
409
+ }
410
+
411
+ //====================================================trans_affine_rotation
412
+ // Rotation matrix. sin() and cos() are calculated twice for the same angle.
413
+ // There's no harm because the performance of sin()/cos() is very good on all
414
+ // modern processors. Besides, this operation is not going to be invoked too
415
+ // often.
416
+ class trans_affine_rotation : public trans_affine
417
+ {
418
+ public:
419
+ trans_affine_rotation(double a) :
420
+ trans_affine(cos(a), sin(a), -sin(a), cos(a), 0.0, 0.0)
421
+ {}
422
+ };
423
+
424
+ //====================================================trans_affine_scaling
425
+ // Scaling matrix. x, y - scale coefficients by X and Y respectively
426
+ class trans_affine_scaling : public trans_affine
427
+ {
428
+ public:
429
+ trans_affine_scaling(double x, double y) :
430
+ trans_affine(x, 0.0, 0.0, y, 0.0, 0.0)
431
+ {}
432
+
433
+ trans_affine_scaling(double s) :
434
+ trans_affine(s, 0.0, 0.0, s, 0.0, 0.0)
435
+ {}
436
+ };
437
+
438
+ //================================================trans_affine_translation
439
+ // Translation matrix
440
+ class trans_affine_translation : public trans_affine
441
+ {
442
+ public:
443
+ trans_affine_translation(double x, double y) :
444
+ trans_affine(1.0, 0.0, 0.0, 1.0, x, y)
445
+ {}
446
+ };
447
+
448
+ //====================================================trans_affine_skewing
449
+ // Sckewing (shear) matrix
450
+ class trans_affine_skewing : public trans_affine
451
+ {
452
+ public:
453
+ trans_affine_skewing(double x, double y) :
454
+ trans_affine(1.0, tan(y), tan(x), 1.0, 0.0, 0.0)
455
+ {}
456
+ };
457
+
458
+
459
+ //===============================================trans_affine_line_segment
460
+ // Rotate, Scale and Translate, associating 0...dist with line segment
461
+ // x1,y1,x2,y2
462
+ class trans_affine_line_segment : public trans_affine
463
+ {
464
+ public:
465
+ trans_affine_line_segment(double x1, double y1, double x2, double y2,
466
+ double dist)
467
+ {
468
+ double dx = x2 - x1;
469
+ double dy = y2 - y1;
470
+ if(dist > 0.0)
471
+ {
472
+ multiply(trans_affine_scaling(sqrt(dx * dx + dy * dy) / dist));
473
+ }
474
+ multiply(trans_affine_rotation(atan2(dy, dx)));
475
+ multiply(trans_affine_translation(x1, y1));
476
+ }
477
+ };
478
+
479
+
480
+ //============================================trans_affine_reflection_unit
481
+ // Reflection matrix. Reflect coordinates across the line through
482
+ // the origin containing the unit vector (ux, uy).
483
+ // Contributed by John Horigan
484
+ class trans_affine_reflection_unit : public trans_affine
485
+ {
486
+ public:
487
+ trans_affine_reflection_unit(double ux, double uy) :
488
+ trans_affine(2.0 * ux * ux - 1.0,
489
+ 2.0 * ux * uy,
490
+ 2.0 * ux * uy,
491
+ 2.0 * uy * uy - 1.0,
492
+ 0.0, 0.0)
493
+ {}
494
+ };
495
+
496
+
497
+ //=================================================trans_affine_reflection
498
+ // Reflection matrix. Reflect coordinates across the line through
499
+ // the origin at the angle a or containing the non-unit vector (x, y).
500
+ // Contributed by John Horigan
501
+ class trans_affine_reflection : public trans_affine_reflection_unit
502
+ {
503
+ public:
504
+ trans_affine_reflection(double a) :
505
+ trans_affine_reflection_unit(cos(a), sin(a))
506
+ {}
507
+
508
+
509
+ trans_affine_reflection(double x, double y) :
510
+ trans_affine_reflection_unit(x / sqrt(x * x + y * y), y / sqrt(x * x + y * y))
511
+ {}
512
+ };
513
+
514
+ }
515
+
516
+
517
+ #endif
518
+
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_trans_double_path.h ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+
16
+ #ifndef AGG_TRANS_DOUBLE_PATH_INCLUDED
17
+ #define AGG_TRANS_DOUBLE_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_double_path.cpp
26
+ //
27
+ //-------------------------------------------------------trans_double_path
28
+ class trans_double_path
29
+ {
30
+ enum status_e
31
+ {
32
+ initial,
33
+ making_path,
34
+ ready
35
+ };
36
+
37
+ public:
38
+ typedef vertex_sequence<vertex_dist, 6> vertex_storage;
39
+
40
+ trans_double_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 base_height(double v) { m_base_height = v; }
48
+ double base_height() const { return m_base_height; }
49
+
50
+ //--------------------------------------------------------------------
51
+ void preserve_x_scale(bool f) { m_preserve_x_scale = f; }
52
+ bool preserve_x_scale() const { return m_preserve_x_scale; }
53
+
54
+ //--------------------------------------------------------------------
55
+ void reset();
56
+ void move_to1(double x, double y);
57
+ void line_to1(double x, double y);
58
+ void move_to2(double x, double y);
59
+ void line_to2(double x, double y);
60
+ void finalize_paths();
61
+
62
+ //--------------------------------------------------------------------
63
+ template<class VertexSource1, class VertexSource2>
64
+ void add_paths(VertexSource1& vs1, VertexSource2& vs2,
65
+ unsigned path1_id=0, unsigned path2_id=0)
66
+ {
67
+ double x;
68
+ double y;
69
+
70
+ unsigned cmd;
71
+
72
+ vs1.rewind(path1_id);
73
+ while(!is_stop(cmd = vs1.vertex(&x, &y)))
74
+ {
75
+ if(is_move_to(cmd))
76
+ {
77
+ move_to1(x, y);
78
+ }
79
+ else
80
+ {
81
+ if(is_vertex(cmd))
82
+ {
83
+ line_to1(x, y);
84
+ }
85
+ }
86
+ }
87
+
88
+ vs2.rewind(path2_id);
89
+ while(!is_stop(cmd = vs2.vertex(&x, &y)))
90
+ {
91
+ if(is_move_to(cmd))
92
+ {
93
+ move_to2(x, y);
94
+ }
95
+ else
96
+ {
97
+ if(is_vertex(cmd))
98
+ {
99
+ line_to2(x, y);
100
+ }
101
+ }
102
+ }
103
+ finalize_paths();
104
+ }
105
+
106
+ //--------------------------------------------------------------------
107
+ double total_length1() const;
108
+ double total_length2() const;
109
+ void transform(double *x, double *y) const;
110
+
111
+ private:
112
+ double finalize_path(vertex_storage& vertices);
113
+ void transform1(const vertex_storage& vertices,
114
+ double kindex, double kx,
115
+ double *x, double* y) const;
116
+
117
+ vertex_storage m_src_vertices1;
118
+ vertex_storage m_src_vertices2;
119
+ double m_base_length;
120
+ double m_base_height;
121
+ double m_kindex1;
122
+ double m_kindex2;
123
+ status_e m_status1;
124
+ status_e m_status2;
125
+ bool m_preserve_x_scale;
126
+ };
127
+
128
+ }
129
+
130
+
131
+ #endif
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_trans_perspective.h ADDED
@@ -0,0 +1,731 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+ //
16
+ // Perspective 2D transformations
17
+ //
18
+ //----------------------------------------------------------------------------
19
+ #ifndef AGG_TRANS_PERSPECTIVE_INCLUDED
20
+ #define AGG_TRANS_PERSPECTIVE_INCLUDED
21
+
22
+ #include "agg_trans_affine.h"
23
+
24
+ namespace agg
25
+ {
26
+ //=======================================================trans_perspective
27
+ struct trans_perspective
28
+ {
29
+ double sx, shy, w0, shx, sy, w1, tx, ty, w2;
30
+
31
+ //------------------------------------------------------- Construction
32
+ // Identity matrix
33
+ trans_perspective() :
34
+ sx (1), shy(0), w0(0),
35
+ shx(0), sy (1), w1(0),
36
+ tx (0), ty (0), w2(1) {}
37
+
38
+ // Custom matrix
39
+ trans_perspective(double v0, double v1, double v2,
40
+ double v3, double v4, double v5,
41
+ double v6, double v7, double v8) :
42
+ sx (v0), shy(v1), w0(v2),
43
+ shx(v3), sy (v4), w1(v5),
44
+ tx (v6), ty (v7), w2(v8) {}
45
+
46
+ // Custom matrix from m[9]
47
+ explicit trans_perspective(const double* m) :
48
+ sx (m[0]), shy(m[1]), w0(m[2]),
49
+ shx(m[3]), sy (m[4]), w1(m[5]),
50
+ tx (m[6]), ty (m[7]), w2(m[8]) {}
51
+
52
+ // From affine
53
+ explicit trans_perspective(const trans_affine& a) :
54
+ sx (a.sx ), shy(a.shy), w0(0),
55
+ shx(a.shx), sy (a.sy ), w1(0),
56
+ tx (a.tx ), ty (a.ty ), w2(1) {}
57
+
58
+ // Rectangle to quadrilateral
59
+ trans_perspective(double x1, double y1, double x2, double y2,
60
+ const double* quad);
61
+
62
+ // Quadrilateral to rectangle
63
+ trans_perspective(const double* quad,
64
+ double x1, double y1, double x2, double y2);
65
+
66
+ // Arbitrary quadrilateral transformations
67
+ trans_perspective(const double* src, const double* dst);
68
+
69
+ //-------------------------------------- Quadrilateral transformations
70
+ // The arguments are double[8] that are mapped to quadrilaterals:
71
+ // x1,y1, x2,y2, x3,y3, x4,y4
72
+ bool quad_to_quad(const double* qs, const double* qd);
73
+
74
+ bool rect_to_quad(double x1, double y1,
75
+ double x2, double y2,
76
+ const double* q);
77
+
78
+ bool quad_to_rect(const double* q,
79
+ double x1, double y1,
80
+ double x2, double y2);
81
+
82
+ // Map square (0,0,1,1) to the quadrilateral and vice versa
83
+ bool square_to_quad(const double* q);
84
+ bool quad_to_square(const double* q);
85
+
86
+
87
+ //--------------------------------------------------------- Operations
88
+ // Reset - load an identity matrix
89
+ const trans_perspective& reset();
90
+
91
+ // Invert matrix. Returns false in degenerate case
92
+ bool invert();
93
+
94
+ // Direct transformations operations
95
+ const trans_perspective& translate(double x, double y);
96
+ const trans_perspective& rotate(double a);
97
+ const trans_perspective& scale(double s);
98
+ const trans_perspective& scale(double x, double y);
99
+
100
+ // Multiply the matrix by another one
101
+ const trans_perspective& multiply(const trans_perspective& m);
102
+
103
+ // Multiply "m" by "this" and assign the result to "this"
104
+ const trans_perspective& premultiply(const trans_perspective& m);
105
+
106
+ // Multiply matrix to inverse of another one
107
+ const trans_perspective& multiply_inv(const trans_perspective& m);
108
+
109
+ // Multiply inverse of "m" by "this" and assign the result to "this"
110
+ const trans_perspective& premultiply_inv(const trans_perspective& m);
111
+
112
+ // Multiply the matrix by another one
113
+ const trans_perspective& multiply(const trans_affine& m);
114
+
115
+ // Multiply "m" by "this" and assign the result to "this"
116
+ const trans_perspective& premultiply(const trans_affine& m);
117
+
118
+ // Multiply the matrix by inverse of another one
119
+ const trans_perspective& multiply_inv(const trans_affine& m);
120
+
121
+ // Multiply inverse of "m" by "this" and assign the result to "this"
122
+ const trans_perspective& premultiply_inv(const trans_affine& m);
123
+
124
+ //--------------------------------------------------------- Load/Store
125
+ void store_to(double* m) const;
126
+ const trans_perspective& load_from(const double* m);
127
+
128
+ //---------------------------------------------------------- Operators
129
+ // Multiply the matrix by another one
130
+ const trans_perspective& operator *= (const trans_perspective& m)
131
+ {
132
+ return multiply(m);
133
+ }
134
+ const trans_perspective& operator *= (const trans_affine& m)
135
+ {
136
+ return multiply(m);
137
+ }
138
+
139
+ // Multiply the matrix by inverse of another one
140
+ const trans_perspective& operator /= (const trans_perspective& m)
141
+ {
142
+ return multiply_inv(m);
143
+ }
144
+ const trans_perspective& operator /= (const trans_affine& m)
145
+ {
146
+ return multiply_inv(m);
147
+ }
148
+
149
+ // Multiply the matrix by another one and return
150
+ // the result in a separete matrix.
151
+ trans_perspective operator * (const trans_perspective& m) const
152
+ {
153
+ return trans_perspective(*this).multiply(m);
154
+ }
155
+ trans_perspective operator * (const trans_affine& m) const
156
+ {
157
+ return trans_perspective(*this).multiply(m);
158
+ }
159
+
160
+ // Multiply the matrix by inverse of another one
161
+ // and return the result in a separete matrix.
162
+ trans_perspective operator / (const trans_perspective& m) const
163
+ {
164
+ return trans_perspective(*this).multiply_inv(m);
165
+ }
166
+ trans_perspective operator / (const trans_affine& m) const
167
+ {
168
+ return trans_perspective(*this).multiply_inv(m);
169
+ }
170
+
171
+ // Calculate and return the inverse matrix
172
+ trans_perspective operator ~ () const
173
+ {
174
+ trans_perspective ret = *this;
175
+ ret.invert();
176
+ return ret;
177
+ }
178
+
179
+ // Equal operator with default epsilon
180
+ bool operator == (const trans_perspective& m) const
181
+ {
182
+ return is_equal(m, affine_epsilon);
183
+ }
184
+
185
+ // Not Equal operator with default epsilon
186
+ bool operator != (const trans_perspective& m) const
187
+ {
188
+ return !is_equal(m, affine_epsilon);
189
+ }
190
+
191
+ //---------------------------------------------------- Transformations
192
+ // Direct transformation of x and y
193
+ void transform(double* x, double* y) const;
194
+
195
+ // Direct transformation of x and y, affine part only
196
+ void transform_affine(double* x, double* y) const;
197
+
198
+ // Direct transformation of x and y, 2x2 matrix only, no translation
199
+ void transform_2x2(double* x, double* y) const;
200
+
201
+ // Inverse transformation of x and y. It works slow because
202
+ // it explicitly inverts the matrix on every call. For massive
203
+ // operations it's better to invert() the matrix and then use
204
+ // direct transformations.
205
+ void inverse_transform(double* x, double* y) const;
206
+
207
+
208
+ //---------------------------------------------------------- Auxiliary
209
+ const trans_perspective& from_affine(const trans_affine& a);
210
+ double determinant() const;
211
+ double determinant_reciprocal() const;
212
+
213
+ bool is_valid(double epsilon = affine_epsilon) const;
214
+ bool is_identity(double epsilon = affine_epsilon) const;
215
+ bool is_equal(const trans_perspective& m,
216
+ double epsilon = affine_epsilon) const;
217
+
218
+ // Determine the major affine parameters. Use with caution
219
+ // considering possible degenerate cases.
220
+ double scale() const;
221
+ double rotation() const;
222
+ void translation(double* dx, double* dy) const;
223
+ void scaling(double* x, double* y) const;
224
+ void scaling_abs(double* x, double* y) const;
225
+
226
+
227
+
228
+ //--------------------------------------------------------------------
229
+ class iterator_x
230
+ {
231
+ double den;
232
+ double den_step;
233
+ double nom_x;
234
+ double nom_x_step;
235
+ double nom_y;
236
+ double nom_y_step;
237
+
238
+ public:
239
+ double x;
240
+ double y;
241
+
242
+ iterator_x() {}
243
+ iterator_x(double px, double py, double step, const trans_perspective& m) :
244
+ den(px * m.w0 + py * m.w1 + m.w2),
245
+ den_step(m.w0 * step),
246
+ nom_x(px * m.sx + py * m.shx + m.tx),
247
+ nom_x_step(step * m.sx),
248
+ nom_y(px * m.shy + py * m.sy + m.ty),
249
+ nom_y_step(step * m.shy),
250
+ x(nom_x / den),
251
+ y(nom_y / den)
252
+ {}
253
+
254
+ void operator ++ ()
255
+ {
256
+ den += den_step;
257
+ nom_x += nom_x_step;
258
+ nom_y += nom_y_step;
259
+ double d = 1.0 / den;
260
+ x = nom_x * d;
261
+ y = nom_y * d;
262
+ }
263
+ };
264
+
265
+ //--------------------------------------------------------------------
266
+ iterator_x begin(double x, double y, double step) const
267
+ {
268
+ return iterator_x(x, y, step, *this);
269
+ }
270
+ };
271
+
272
+
273
+
274
+
275
+
276
+
277
+
278
+
279
+
280
+
281
+
282
+
283
+
284
+
285
+ //------------------------------------------------------------------------
286
+ inline bool trans_perspective::square_to_quad(const double* q)
287
+ {
288
+ double dx = q[0] - q[2] + q[4] - q[6];
289
+ double dy = q[1] - q[3] + q[5] - q[7];
290
+ if(dx == 0.0 && dy == 0.0)
291
+ {
292
+ // Affine case (parallelogram)
293
+ //---------------
294
+ sx = q[2] - q[0];
295
+ shy = q[3] - q[1];
296
+ w0 = 0.0;
297
+ shx = q[4] - q[2];
298
+ sy = q[5] - q[3];
299
+ w1 = 0.0;
300
+ tx = q[0];
301
+ ty = q[1];
302
+ w2 = 1.0;
303
+ }
304
+ else
305
+ {
306
+ double dx1 = q[2] - q[4];
307
+ double dy1 = q[3] - q[5];
308
+ double dx2 = q[6] - q[4];
309
+ double dy2 = q[7] - q[5];
310
+ double den = dx1 * dy2 - dx2 * dy1;
311
+ if(den == 0.0)
312
+ {
313
+ // Singular case
314
+ //---------------
315
+ sx = shy = w0 = shx = sy = w1 = tx = ty = w2 = 0.0;
316
+ return false;
317
+ }
318
+ // General case
319
+ //---------------
320
+ double u = (dx * dy2 - dy * dx2) / den;
321
+ double v = (dy * dx1 - dx * dy1) / den;
322
+ sx = q[2] - q[0] + u * q[2];
323
+ shy = q[3] - q[1] + u * q[3];
324
+ w0 = u;
325
+ shx = q[6] - q[0] + v * q[6];
326
+ sy = q[7] - q[1] + v * q[7];
327
+ w1 = v;
328
+ tx = q[0];
329
+ ty = q[1];
330
+ w2 = 1.0;
331
+ }
332
+ return true;
333
+ }
334
+
335
+ //------------------------------------------------------------------------
336
+ inline bool trans_perspective::invert()
337
+ {
338
+ double d0 = sy * w2 - w1 * ty;
339
+ double d1 = w0 * ty - shy * w2;
340
+ double d2 = shy * w1 - w0 * sy;
341
+ double d = sx * d0 + shx * d1 + tx * d2;
342
+ if(d == 0.0)
343
+ {
344
+ sx = shy = w0 = shx = sy = w1 = tx = ty = w2 = 0.0;
345
+ return false;
346
+ }
347
+ d = 1.0 / d;
348
+ trans_perspective a = *this;
349
+ sx = d * d0;
350
+ shy = d * d1;
351
+ w0 = d * d2;
352
+ shx = d * (a.w1 *a.tx - a.shx*a.w2);
353
+ sy = d * (a.sx *a.w2 - a.w0 *a.tx);
354
+ w1 = d * (a.w0 *a.shx - a.sx *a.w1);
355
+ tx = d * (a.shx*a.ty - a.sy *a.tx);
356
+ ty = d * (a.shy*a.tx - a.sx *a.ty);
357
+ w2 = d * (a.sx *a.sy - a.shy*a.shx);
358
+ return true;
359
+ }
360
+
361
+ //------------------------------------------------------------------------
362
+ inline bool trans_perspective::quad_to_square(const double* q)
363
+ {
364
+ if(!square_to_quad(q)) return false;
365
+ invert();
366
+ return true;
367
+ }
368
+
369
+ //------------------------------------------------------------------------
370
+ inline bool trans_perspective::quad_to_quad(const double* qs,
371
+ const double* qd)
372
+ {
373
+ trans_perspective p;
374
+ if(! quad_to_square(qs)) return false;
375
+ if(!p.square_to_quad(qd)) return false;
376
+ multiply(p);
377
+ return true;
378
+ }
379
+
380
+ //------------------------------------------------------------------------
381
+ inline bool trans_perspective::rect_to_quad(double x1, double y1,
382
+ double x2, double y2,
383
+ const double* q)
384
+ {
385
+ double r[8];
386
+ r[0] = r[6] = x1;
387
+ r[2] = r[4] = x2;
388
+ r[1] = r[3] = y1;
389
+ r[5] = r[7] = y2;
390
+ return quad_to_quad(r, q);
391
+ }
392
+
393
+ //------------------------------------------------------------------------
394
+ inline bool trans_perspective::quad_to_rect(const double* q,
395
+ double x1, double y1,
396
+ double x2, double y2)
397
+ {
398
+ double r[8];
399
+ r[0] = r[6] = x1;
400
+ r[2] = r[4] = x2;
401
+ r[1] = r[3] = y1;
402
+ r[5] = r[7] = y2;
403
+ return quad_to_quad(q, r);
404
+ }
405
+
406
+ //------------------------------------------------------------------------
407
+ inline trans_perspective::trans_perspective(double x1, double y1,
408
+ double x2, double y2,
409
+ const double* quad)
410
+ {
411
+ rect_to_quad(x1, y1, x2, y2, quad);
412
+ }
413
+
414
+ //------------------------------------------------------------------------
415
+ inline trans_perspective::trans_perspective(const double* quad,
416
+ double x1, double y1,
417
+ double x2, double y2)
418
+ {
419
+ quad_to_rect(quad, x1, y1, x2, y2);
420
+ }
421
+
422
+ //------------------------------------------------------------------------
423
+ inline trans_perspective::trans_perspective(const double* src,
424
+ const double* dst)
425
+ {
426
+ quad_to_quad(src, dst);
427
+ }
428
+
429
+ //------------------------------------------------------------------------
430
+ inline const trans_perspective& trans_perspective::reset()
431
+ {
432
+ sx = 1; shy = 0; w0 = 0;
433
+ shx = 0; sy = 1; w1 = 0;
434
+ tx = 0; ty = 0; w2 = 1;
435
+ return *this;
436
+ }
437
+
438
+ //------------------------------------------------------------------------
439
+ inline const trans_perspective&
440
+ trans_perspective::multiply(const trans_perspective& a)
441
+ {
442
+ trans_perspective b = *this;
443
+ sx = a.sx *b.sx + a.shx*b.shy + a.tx*b.w0;
444
+ shx = a.sx *b.shx + a.shx*b.sy + a.tx*b.w1;
445
+ tx = a.sx *b.tx + a.shx*b.ty + a.tx*b.w2;
446
+ shy = a.shy*b.sx + a.sy *b.shy + a.ty*b.w0;
447
+ sy = a.shy*b.shx + a.sy *b.sy + a.ty*b.w1;
448
+ ty = a.shy*b.tx + a.sy *b.ty + a.ty*b.w2;
449
+ w0 = a.w0 *b.sx + a.w1 *b.shy + a.w2*b.w0;
450
+ w1 = a.w0 *b.shx + a.w1 *b.sy + a.w2*b.w1;
451
+ w2 = a.w0 *b.tx + a.w1 *b.ty + a.w2*b.w2;
452
+ return *this;
453
+ }
454
+
455
+ //------------------------------------------------------------------------
456
+ inline const trans_perspective&
457
+ trans_perspective::multiply(const trans_affine& a)
458
+ {
459
+ trans_perspective b = *this;
460
+ sx = a.sx *b.sx + a.shx*b.shy + a.tx*b.w0;
461
+ shx = a.sx *b.shx + a.shx*b.sy + a.tx*b.w1;
462
+ tx = a.sx *b.tx + a.shx*b.ty + a.tx*b.w2;
463
+ shy = a.shy*b.sx + a.sy *b.shy + a.ty*b.w0;
464
+ sy = a.shy*b.shx + a.sy *b.sy + a.ty*b.w1;
465
+ ty = a.shy*b.tx + a.sy *b.ty + a.ty*b.w2;
466
+ return *this;
467
+ }
468
+
469
+ //------------------------------------------------------------------------
470
+ inline const trans_perspective&
471
+ trans_perspective::premultiply(const trans_perspective& b)
472
+ {
473
+ trans_perspective a = *this;
474
+ sx = a.sx *b.sx + a.shx*b.shy + a.tx*b.w0;
475
+ shx = a.sx *b.shx + a.shx*b.sy + a.tx*b.w1;
476
+ tx = a.sx *b.tx + a.shx*b.ty + a.tx*b.w2;
477
+ shy = a.shy*b.sx + a.sy *b.shy + a.ty*b.w0;
478
+ sy = a.shy*b.shx + a.sy *b.sy + a.ty*b.w1;
479
+ ty = a.shy*b.tx + a.sy *b.ty + a.ty*b.w2;
480
+ w0 = a.w0 *b.sx + a.w1 *b.shy + a.w2*b.w0;
481
+ w1 = a.w0 *b.shx + a.w1 *b.sy + a.w2*b.w1;
482
+ w2 = a.w0 *b.tx + a.w1 *b.ty + a.w2*b.w2;
483
+ return *this;
484
+ }
485
+
486
+ //------------------------------------------------------------------------
487
+ inline const trans_perspective&
488
+ trans_perspective::premultiply(const trans_affine& b)
489
+ {
490
+ trans_perspective a = *this;
491
+ sx = a.sx *b.sx + a.shx*b.shy;
492
+ shx = a.sx *b.shx + a.shx*b.sy;
493
+ tx = a.sx *b.tx + a.shx*b.ty + a.tx;
494
+ shy = a.shy*b.sx + a.sy *b.shy;
495
+ sy = a.shy*b.shx + a.sy *b.sy;
496
+ ty = a.shy*b.tx + a.sy *b.ty + a.ty;
497
+ w0 = a.w0 *b.sx + a.w1 *b.shy;
498
+ w1 = a.w0 *b.shx + a.w1 *b.sy;
499
+ w2 = a.w0 *b.tx + a.w1 *b.ty + a.w2;
500
+ return *this;
501
+ }
502
+
503
+ //------------------------------------------------------------------------
504
+ const trans_perspective&
505
+ trans_perspective::multiply_inv(const trans_perspective& m)
506
+ {
507
+ trans_perspective t = m;
508
+ t.invert();
509
+ return multiply(t);
510
+ }
511
+
512
+ //------------------------------------------------------------------------
513
+ const trans_perspective&
514
+ trans_perspective::multiply_inv(const trans_affine& m)
515
+ {
516
+ trans_affine t = m;
517
+ t.invert();
518
+ return multiply(t);
519
+ }
520
+
521
+ //------------------------------------------------------------------------
522
+ const trans_perspective&
523
+ trans_perspective::premultiply_inv(const trans_perspective& m)
524
+ {
525
+ trans_perspective t = m;
526
+ t.invert();
527
+ return *this = t.multiply(*this);
528
+ }
529
+
530
+ //------------------------------------------------------------------------
531
+ const trans_perspective&
532
+ trans_perspective::premultiply_inv(const trans_affine& m)
533
+ {
534
+ trans_perspective t(m);
535
+ t.invert();
536
+ return *this = t.multiply(*this);
537
+ }
538
+
539
+ //------------------------------------------------------------------------
540
+ inline const trans_perspective&
541
+ trans_perspective::translate(double x, double y)
542
+ {
543
+ tx += x;
544
+ ty += y;
545
+ return *this;
546
+ }
547
+
548
+ //------------------------------------------------------------------------
549
+ inline const trans_perspective& trans_perspective::rotate(double a)
550
+ {
551
+ multiply(trans_affine_rotation(a));
552
+ return *this;
553
+ }
554
+
555
+ //------------------------------------------------------------------------
556
+ inline const trans_perspective& trans_perspective::scale(double s)
557
+ {
558
+ multiply(trans_affine_scaling(s));
559
+ return *this;
560
+ }
561
+
562
+ //------------------------------------------------------------------------
563
+ inline const trans_perspective& trans_perspective::scale(double x, double y)
564
+ {
565
+ multiply(trans_affine_scaling(x, y));
566
+ return *this;
567
+ }
568
+
569
+ //------------------------------------------------------------------------
570
+ inline void trans_perspective::transform(double* px, double* py) const
571
+ {
572
+ double x = *px;
573
+ double y = *py;
574
+ double m = 1.0 / (x*w0 + y*w1 + w2);
575
+ *px = m * (x*sx + y*shx + tx);
576
+ *py = m * (x*shy + y*sy + ty);
577
+ }
578
+
579
+ //------------------------------------------------------------------------
580
+ inline void trans_perspective::transform_affine(double* x, double* y) const
581
+ {
582
+ double tmp = *x;
583
+ *x = tmp * sx + *y * shx + tx;
584
+ *y = tmp * shy + *y * sy + ty;
585
+ }
586
+
587
+ //------------------------------------------------------------------------
588
+ inline void trans_perspective::transform_2x2(double* x, double* y) const
589
+ {
590
+ double tmp = *x;
591
+ *x = tmp * sx + *y * shx;
592
+ *y = tmp * shy + *y * sy;
593
+ }
594
+
595
+ //------------------------------------------------------------------------
596
+ inline void trans_perspective::inverse_transform(double* x, double* y) const
597
+ {
598
+ trans_perspective t(*this);
599
+ if(t.invert()) t.transform(x, y);
600
+ }
601
+
602
+ //------------------------------------------------------------------------
603
+ inline void trans_perspective::store_to(double* m) const
604
+ {
605
+ *m++ = sx; *m++ = shy; *m++ = w0;
606
+ *m++ = shx; *m++ = sy; *m++ = w1;
607
+ *m++ = tx; *m++ = ty; *m++ = w2;
608
+ }
609
+
610
+ //------------------------------------------------------------------------
611
+ inline const trans_perspective& trans_perspective::load_from(const double* m)
612
+ {
613
+ sx = *m++; shy = *m++; w0 = *m++;
614
+ shx = *m++; sy = *m++; w1 = *m++;
615
+ tx = *m++; ty = *m++; w2 = *m++;
616
+ return *this;
617
+ }
618
+
619
+ //------------------------------------------------------------------------
620
+ inline const trans_perspective&
621
+ trans_perspective::from_affine(const trans_affine& a)
622
+ {
623
+ sx = a.sx; shy = a.shy; w0 = 0;
624
+ shx = a.shx; sy = a.sy; w1 = 0;
625
+ tx = a.tx; ty = a.ty; w2 = 1;
626
+ return *this;
627
+ }
628
+
629
+ //------------------------------------------------------------------------
630
+ inline double trans_perspective::determinant() const
631
+ {
632
+ return sx * (sy * w2 - ty * w1) +
633
+ shx * (ty * w0 - shy * w2) +
634
+ tx * (shy * w1 - sy * w0);
635
+ }
636
+
637
+ //------------------------------------------------------------------------
638
+ inline double trans_perspective::determinant_reciprocal() const
639
+ {
640
+ return 1.0 / determinant();
641
+ }
642
+
643
+ //------------------------------------------------------------------------
644
+ inline bool trans_perspective::is_valid(double epsilon) const
645
+ {
646
+ return fabs(sx) > epsilon && fabs(sy) > epsilon && fabs(w2) > epsilon;
647
+ }
648
+
649
+ //------------------------------------------------------------------------
650
+ inline bool trans_perspective::is_identity(double epsilon) const
651
+ {
652
+ return is_equal_eps(sx, 1.0, epsilon) &&
653
+ is_equal_eps(shy, 0.0, epsilon) &&
654
+ is_equal_eps(w0, 0.0, epsilon) &&
655
+ is_equal_eps(shx, 0.0, epsilon) &&
656
+ is_equal_eps(sy, 1.0, epsilon) &&
657
+ is_equal_eps(w1, 0.0, epsilon) &&
658
+ is_equal_eps(tx, 0.0, epsilon) &&
659
+ is_equal_eps(ty, 0.0, epsilon) &&
660
+ is_equal_eps(w2, 1.0, epsilon);
661
+ }
662
+
663
+ //------------------------------------------------------------------------
664
+ inline bool trans_perspective::is_equal(const trans_perspective& m,
665
+ double epsilon) const
666
+ {
667
+ return is_equal_eps(sx, m.sx, epsilon) &&
668
+ is_equal_eps(shy, m.shy, epsilon) &&
669
+ is_equal_eps(w0, m.w0, epsilon) &&
670
+ is_equal_eps(shx, m.shx, epsilon) &&
671
+ is_equal_eps(sy, m.sy, epsilon) &&
672
+ is_equal_eps(w1, m.w1, epsilon) &&
673
+ is_equal_eps(tx, m.tx, epsilon) &&
674
+ is_equal_eps(ty, m.ty, epsilon) &&
675
+ is_equal_eps(w2, m.w2, epsilon);
676
+ }
677
+
678
+ //------------------------------------------------------------------------
679
+ inline double trans_perspective::scale() const
680
+ {
681
+ double x = 0.707106781 * sx + 0.707106781 * shx;
682
+ double y = 0.707106781 * shy + 0.707106781 * sy;
683
+ return sqrt(x*x + y*y);
684
+ }
685
+
686
+ //------------------------------------------------------------------------
687
+ inline double trans_perspective::rotation() const
688
+ {
689
+ double x1 = 0.0;
690
+ double y1 = 0.0;
691
+ double x2 = 1.0;
692
+ double y2 = 0.0;
693
+ transform(&x1, &y1);
694
+ transform(&x2, &y2);
695
+ return atan2(y2-y1, x2-x1);
696
+ }
697
+
698
+ //------------------------------------------------------------------------
699
+ void trans_perspective::translation(double* dx, double* dy) const
700
+ {
701
+ *dx = tx;
702
+ *dy = ty;
703
+ }
704
+
705
+ //------------------------------------------------------------------------
706
+ void trans_perspective::scaling(double* x, double* y) const
707
+ {
708
+ double x1 = 0.0;
709
+ double y1 = 0.0;
710
+ double x2 = 1.0;
711
+ double y2 = 1.0;
712
+ trans_perspective t(*this);
713
+ t *= trans_affine_rotation(-rotation());
714
+ t.transform(&x1, &y1);
715
+ t.transform(&x2, &y2);
716
+ *x = x2 - x1;
717
+ *y = y2 - y1;
718
+ }
719
+
720
+ //------------------------------------------------------------------------
721
+ void trans_perspective::scaling_abs(double* x, double* y) const
722
+ {
723
+ *x = sqrt(sx * sx + shx * shx);
724
+ *y = sqrt(shy * shy + sy * sy);
725
+ }
726
+
727
+
728
+ }
729
+
730
+ #endif
731
+
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_trans_single_path.h ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+
16
+ #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_dist, 6> 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<class VertexSource>
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
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_trans_viewport.h ADDED
@@ -0,0 +1,303 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+ //
16
+ // Viewport transformer - simple orthogonal conversions from world coordinates
17
+ // to screen (device) ones.
18
+ //
19
+ //----------------------------------------------------------------------------
20
+
21
+ #ifndef AGG_TRANS_VIEWPORT_INCLUDED
22
+ #define AGG_TRANS_VIEWPORT_INCLUDED
23
+
24
+ #include <string.h>
25
+ #include "agg_trans_affine.h"
26
+
27
+
28
+ namespace agg
29
+ {
30
+
31
+ enum aspect_ratio_e
32
+ {
33
+ aspect_ratio_stretch,
34
+ aspect_ratio_meet,
35
+ aspect_ratio_slice
36
+ };
37
+
38
+
39
+ //----------------------------------------------------------trans_viewport
40
+ class trans_viewport
41
+ {
42
+ public:
43
+ //-------------------------------------------------------------------
44
+ trans_viewport() :
45
+ m_world_x1(0.0),
46
+ m_world_y1(0.0),
47
+ m_world_x2(1.0),
48
+ m_world_y2(1.0),
49
+ m_device_x1(0.0),
50
+ m_device_y1(0.0),
51
+ m_device_x2(1.0),
52
+ m_device_y2(1.0),
53
+ m_aspect(aspect_ratio_stretch),
54
+ m_is_valid(true),
55
+ m_align_x(0.5),
56
+ m_align_y(0.5),
57
+ m_wx1(0.0),
58
+ m_wy1(0.0),
59
+ m_wx2(1.0),
60
+ m_wy2(1.0),
61
+ m_dx1(0.0),
62
+ m_dy1(0.0),
63
+ m_kx(1.0),
64
+ m_ky(1.0)
65
+ {}
66
+
67
+ //-------------------------------------------------------------------
68
+ void preserve_aspect_ratio(double alignx,
69
+ double aligny,
70
+ aspect_ratio_e aspect)
71
+ {
72
+ m_align_x = alignx;
73
+ m_align_y = aligny;
74
+ m_aspect = aspect;
75
+ update();
76
+ }
77
+
78
+ //-------------------------------------------------------------------
79
+ void device_viewport(double x1, double y1, double x2, double y2)
80
+ {
81
+ m_device_x1 = x1;
82
+ m_device_y1 = y1;
83
+ m_device_x2 = x2;
84
+ m_device_y2 = y2;
85
+ update();
86
+ }
87
+
88
+ //-------------------------------------------------------------------
89
+ void world_viewport(double x1, double y1, double x2, double y2)
90
+ {
91
+ m_world_x1 = x1;
92
+ m_world_y1 = y1;
93
+ m_world_x2 = x2;
94
+ m_world_y2 = y2;
95
+ update();
96
+ }
97
+
98
+ //-------------------------------------------------------------------
99
+ void device_viewport(double* x1, double* y1, double* x2, double* y2) const
100
+ {
101
+ *x1 = m_device_x1;
102
+ *y1 = m_device_y1;
103
+ *x2 = m_device_x2;
104
+ *y2 = m_device_y2;
105
+ }
106
+
107
+ //-------------------------------------------------------------------
108
+ void world_viewport(double* x1, double* y1, double* x2, double* y2) const
109
+ {
110
+ *x1 = m_world_x1;
111
+ *y1 = m_world_y1;
112
+ *x2 = m_world_x2;
113
+ *y2 = m_world_y2;
114
+ }
115
+
116
+ //-------------------------------------------------------------------
117
+ void world_viewport_actual(double* x1, double* y1,
118
+ double* x2, double* y2) const
119
+ {
120
+ *x1 = m_wx1;
121
+ *y1 = m_wy1;
122
+ *x2 = m_wx2;
123
+ *y2 = m_wy2;
124
+ }
125
+
126
+ //-------------------------------------------------------------------
127
+ bool is_valid() const { return m_is_valid; }
128
+ double align_x() const { return m_align_x; }
129
+ double align_y() const { return m_align_y; }
130
+ aspect_ratio_e aspect_ratio() const { return m_aspect; }
131
+
132
+ //-------------------------------------------------------------------
133
+ void transform(double* x, double* y) const
134
+ {
135
+ *x = (*x - m_wx1) * m_kx + m_dx1;
136
+ *y = (*y - m_wy1) * m_ky + m_dy1;
137
+ }
138
+
139
+ //-------------------------------------------------------------------
140
+ void transform_scale_only(double* x, double* y) const
141
+ {
142
+ *x *= m_kx;
143
+ *y *= m_ky;
144
+ }
145
+
146
+ //-------------------------------------------------------------------
147
+ void inverse_transform(double* x, double* y) const
148
+ {
149
+ *x = (*x - m_dx1) / m_kx + m_wx1;
150
+ *y = (*y - m_dy1) / m_ky + m_wy1;
151
+ }
152
+
153
+ //-------------------------------------------------------------------
154
+ void inverse_transform_scale_only(double* x, double* y) const
155
+ {
156
+ *x /= m_kx;
157
+ *y /= m_ky;
158
+ }
159
+
160
+ //-------------------------------------------------------------------
161
+ double device_dx() const { return m_dx1 - m_wx1 * m_kx; }
162
+ double device_dy() const { return m_dy1 - m_wy1 * m_ky; }
163
+
164
+ //-------------------------------------------------------------------
165
+ double scale_x() const
166
+ {
167
+ return m_kx;
168
+ }
169
+
170
+ //-------------------------------------------------------------------
171
+ double scale_y() const
172
+ {
173
+ return m_ky;
174
+ }
175
+
176
+ //-------------------------------------------------------------------
177
+ double scale() const
178
+ {
179
+ return (m_kx + m_ky) * 0.5;
180
+ }
181
+
182
+ //-------------------------------------------------------------------
183
+ trans_affine to_affine() const
184
+ {
185
+ trans_affine mtx = trans_affine_translation(-m_wx1, -m_wy1);
186
+ mtx *= trans_affine_scaling(m_kx, m_ky);
187
+ mtx *= trans_affine_translation(m_dx1, m_dy1);
188
+ return mtx;
189
+ }
190
+
191
+ //-------------------------------------------------------------------
192
+ trans_affine to_affine_scale_only() const
193
+ {
194
+ return trans_affine_scaling(m_kx, m_ky);
195
+ }
196
+
197
+ //-------------------------------------------------------------------
198
+ unsigned byte_size() const
199
+ {
200
+ return sizeof(*this);
201
+ }
202
+
203
+ void serialize(int8u* ptr) const
204
+ {
205
+ memcpy(ptr, this, sizeof(*this));
206
+ }
207
+
208
+ void deserialize(const int8u* ptr)
209
+ {
210
+ memcpy(this, ptr, sizeof(*this));
211
+ }
212
+
213
+ private:
214
+ void update();
215
+
216
+ double m_world_x1;
217
+ double m_world_y1;
218
+ double m_world_x2;
219
+ double m_world_y2;
220
+ double m_device_x1;
221
+ double m_device_y1;
222
+ double m_device_x2;
223
+ double m_device_y2;
224
+ aspect_ratio_e m_aspect;
225
+ bool m_is_valid;
226
+ double m_align_x;
227
+ double m_align_y;
228
+ double m_wx1;
229
+ double m_wy1;
230
+ double m_wx2;
231
+ double m_wy2;
232
+ double m_dx1;
233
+ double m_dy1;
234
+ double m_kx;
235
+ double m_ky;
236
+ };
237
+
238
+
239
+
240
+ //-----------------------------------------------------------------------
241
+ inline void trans_viewport::update()
242
+ {
243
+ const double epsilon = 1e-30;
244
+ if(fabs(m_world_x1 - m_world_x2) < epsilon ||
245
+ fabs(m_world_y1 - m_world_y2) < epsilon ||
246
+ fabs(m_device_x1 - m_device_x2) < epsilon ||
247
+ fabs(m_device_y1 - m_device_y2) < epsilon)
248
+ {
249
+ m_wx1 = m_world_x1;
250
+ m_wy1 = m_world_y1;
251
+ m_wx2 = m_world_x1 + 1.0;
252
+ m_wy2 = m_world_y2 + 1.0;
253
+ m_dx1 = m_device_x1;
254
+ m_dy1 = m_device_y1;
255
+ m_kx = 1.0;
256
+ m_ky = 1.0;
257
+ m_is_valid = false;
258
+ return;
259
+ }
260
+
261
+ double world_x1 = m_world_x1;
262
+ double world_y1 = m_world_y1;
263
+ double world_x2 = m_world_x2;
264
+ double world_y2 = m_world_y2;
265
+ double device_x1 = m_device_x1;
266
+ double device_y1 = m_device_y1;
267
+ double device_x2 = m_device_x2;
268
+ double device_y2 = m_device_y2;
269
+ if(m_aspect != aspect_ratio_stretch)
270
+ {
271
+ double d;
272
+ m_kx = (device_x2 - device_x1) / (world_x2 - world_x1);
273
+ m_ky = (device_y2 - device_y1) / (world_y2 - world_y1);
274
+
275
+ if((m_aspect == aspect_ratio_meet) == (m_kx < m_ky))
276
+ {
277
+ d = (world_y2 - world_y1) * m_ky / m_kx;
278
+ world_y1 += (world_y2 - world_y1 - d) * m_align_y;
279
+ world_y2 = world_y1 + d;
280
+ }
281
+ else
282
+ {
283
+ d = (world_x2 - world_x1) * m_kx / m_ky;
284
+ world_x1 += (world_x2 - world_x1 - d) * m_align_x;
285
+ world_x2 = world_x1 + d;
286
+ }
287
+ }
288
+ m_wx1 = world_x1;
289
+ m_wy1 = world_y1;
290
+ m_wx2 = world_x2;
291
+ m_wy2 = world_y2;
292
+ m_dx1 = device_x1;
293
+ m_dy1 = device_y1;
294
+ m_kx = (device_x2 - device_x1) / (world_x2 - world_x1);
295
+ m_ky = (device_y2 - device_y1) / (world_y2 - world_y1);
296
+ m_is_valid = true;
297
+ }
298
+
299
+
300
+ }
301
+
302
+
303
+ #endif
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_trans_warp_magnifier.h ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+
16
+ #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
+ double xc() const { return m_xc; }
37
+ double yc() const { return m_yc; }
38
+ double magnification() const { return m_magn; }
39
+ double radius() const { return m_radius; }
40
+
41
+ void transform(double* x, double* y) const;
42
+ void inverse_transform(double* x, double* y) const;
43
+
44
+ private:
45
+ double m_xc;
46
+ double m_yc;
47
+ double m_magn;
48
+ double m_radius;
49
+ };
50
+
51
+
52
+ }
53
+
54
+
55
+ #endif
56
+
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_vcgen_bspline.h ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+
16
+ #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_bvector<point_d, 6> 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 path_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
+
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_vcgen_contour.h ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+
16
+ #ifndef AGG_VCGEN_CONTOUR_INCLUDED
17
+ #define AGG_VCGEN_CONTOUR_INCLUDED
18
+
19
+ #include "agg_math_stroke.h"
20
+
21
+ namespace agg
22
+ {
23
+
24
+ //----------------------------------------------------------vcgen_contour
25
+ //
26
+ // See Implementation agg_vcgen_contour.cpp
27
+ //
28
+ class vcgen_contour
29
+ {
30
+ enum status_e
31
+ {
32
+ initial,
33
+ ready,
34
+ outline,
35
+ out_vertices,
36
+ end_poly,
37
+ stop
38
+ };
39
+
40
+ public:
41
+ typedef vertex_sequence<vertex_dist, 6> vertex_storage;
42
+ typedef pod_bvector<point_d, 6> coord_storage;
43
+
44
+ vcgen_contour();
45
+
46
+ void line_cap(line_cap_e lc) { m_stroker.line_cap(lc); }
47
+ void line_join(line_join_e lj) { m_stroker.line_join(lj); }
48
+ void inner_join(inner_join_e ij) { m_stroker.inner_join(ij); }
49
+
50
+ line_cap_e line_cap() const { return m_stroker.line_cap(); }
51
+ line_join_e line_join() const { return m_stroker.line_join(); }
52
+ inner_join_e inner_join() const { return m_stroker.inner_join(); }
53
+
54
+ void width(double w) { m_stroker.width(m_width = w); }
55
+ void miter_limit(double ml) { m_stroker.miter_limit(ml); }
56
+ void miter_limit_theta(double t) { m_stroker.miter_limit_theta(t); }
57
+ void inner_miter_limit(double ml) { m_stroker.inner_miter_limit(ml); }
58
+ void approximation_scale(double as) { m_stroker.approximation_scale(as); }
59
+
60
+ double width() const { return m_width; }
61
+ double miter_limit() const { return m_stroker.miter_limit(); }
62
+ double inner_miter_limit() const { return m_stroker.inner_miter_limit(); }
63
+ double approximation_scale() const { return m_stroker.approximation_scale(); }
64
+
65
+ void auto_detect_orientation(bool v) { m_auto_detect = v; }
66
+ bool auto_detect_orientation() const { return m_auto_detect; }
67
+
68
+ // Generator interface
69
+ void remove_all();
70
+ void add_vertex(double x, double y, unsigned cmd);
71
+
72
+ // Vertex Source Interface
73
+ void rewind(unsigned path_id);
74
+ unsigned vertex(double* x, double* y);
75
+
76
+ private:
77
+ vcgen_contour(const vcgen_contour&);
78
+ const vcgen_contour& operator = (const vcgen_contour&);
79
+
80
+ math_stroke<coord_storage> m_stroker;
81
+ double m_width;
82
+ vertex_storage m_src_vertices;
83
+ coord_storage m_out_vertices;
84
+ status_e m_status;
85
+ unsigned m_src_vertex;
86
+ unsigned m_out_vertex;
87
+ unsigned m_closed;
88
+ unsigned m_orientation;
89
+ bool m_auto_detect;
90
+ };
91
+
92
+ }
93
+
94
+ #endif
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_vcgen_dash.h ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+ //
16
+ // 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
+
25
+ namespace agg
26
+ {
27
+
28
+ //---------------------------------------------------------------vcgen_dash
29
+ //
30
+ // See Implementation agg_vcgen_dash.cpp
31
+ //
32
+ class vcgen_dash
33
+ {
34
+ enum max_dashes_e
35
+ {
36
+ max_dashes = 32
37
+ };
38
+
39
+ enum status_e
40
+ {
41
+ initial,
42
+ ready,
43
+ polyline,
44
+ stop
45
+ };
46
+
47
+ public:
48
+ typedef vertex_sequence<vertex_dist, 6> vertex_storage;
49
+
50
+ vcgen_dash();
51
+
52
+ void remove_all_dashes();
53
+ void add_dash(double dash_len, double gap_len);
54
+ void dash_start(double ds);
55
+
56
+ void shorten(double s) { m_shorten = s; }
57
+ double shorten() const { return m_shorten; }
58
+
59
+ // Vertex Generator Interface
60
+ void remove_all();
61
+ void add_vertex(double x, double y, unsigned cmd);
62
+
63
+ // Vertex Source Interface
64
+ void rewind(unsigned path_id);
65
+ unsigned vertex(double* x, double* y);
66
+
67
+ private:
68
+ vcgen_dash(const vcgen_dash&);
69
+ const vcgen_dash& operator = (const vcgen_dash&);
70
+
71
+ void calc_dash_start(double ds);
72
+
73
+ double m_dashes[max_dashes];
74
+ double m_total_dash_len;
75
+ unsigned m_num_dashes;
76
+ double m_dash_start;
77
+ double m_shorten;
78
+ double m_curr_dash_start;
79
+ unsigned m_curr_dash;
80
+ double m_curr_rest;
81
+ const vertex_dist* m_v1;
82
+ const vertex_dist* m_v2;
83
+
84
+ vertex_storage m_src_vertices;
85
+ unsigned m_closed;
86
+ status_e m_status;
87
+ unsigned m_src_vertex;
88
+ };
89
+
90
+
91
+ }
92
+
93
+ #endif
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_vcgen_markers_term.h ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+
16
+ #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
+
22
+ namespace agg
23
+ {
24
+
25
+ //======================================================vcgen_markers_term
26
+ //
27
+ // See Implemantation agg_vcgen_markers_term.cpp
28
+ // Terminal markers generator (arrowhead/arrowtail)
29
+ //
30
+ //------------------------------------------------------------------------
31
+ class vcgen_markers_term
32
+ {
33
+ public:
34
+ vcgen_markers_term() : m_curr_id(0), m_curr_idx(0) {}
35
+
36
+ // Vertex Generator Interface
37
+ void remove_all();
38
+ void add_vertex(double x, double y, unsigned cmd);
39
+
40
+ // Vertex Source Interface
41
+ void rewind(unsigned path_id);
42
+ unsigned vertex(double* x, double* y);
43
+
44
+ private:
45
+ vcgen_markers_term(const vcgen_markers_term&);
46
+ const vcgen_markers_term& operator = (const vcgen_markers_term&);
47
+
48
+ struct coord_type
49
+ {
50
+ double x, y;
51
+
52
+ coord_type() {}
53
+ coord_type(double x_, double y_) : x(x_), y(y_) {}
54
+ };
55
+
56
+ typedef pod_bvector<coord_type, 6> coord_storage;
57
+
58
+ coord_storage m_markers;
59
+ unsigned m_curr_id;
60
+ unsigned m_curr_idx;
61
+ };
62
+
63
+
64
+ }
65
+
66
+ #endif
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_vcgen_smooth_poly1.h ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+
16
+ #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_dist, 6> 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 path_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
+
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_vcgen_stroke.h ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+
16
+ #ifndef AGG_VCGEN_STROKE_INCLUDED
17
+ #define AGG_VCGEN_STROKE_INCLUDED
18
+
19
+ #include "agg_math_stroke.h"
20
+
21
+
22
+ namespace agg
23
+ {
24
+
25
+ //============================================================vcgen_stroke
26
+ //
27
+ // See Implementation agg_vcgen_stroke.cpp
28
+ // Stroke generator
29
+ //
30
+ //------------------------------------------------------------------------
31
+ class vcgen_stroke
32
+ {
33
+ enum status_e
34
+ {
35
+ initial,
36
+ ready,
37
+ cap1,
38
+ cap2,
39
+ outline1,
40
+ close_first,
41
+ outline2,
42
+ out_vertices,
43
+ end_poly1,
44
+ end_poly2,
45
+ stop
46
+ };
47
+
48
+ public:
49
+ typedef vertex_sequence<vertex_dist, 6> vertex_storage;
50
+ typedef pod_bvector<point_d, 6> coord_storage;
51
+
52
+ vcgen_stroke();
53
+
54
+ void line_cap(line_cap_e lc) { m_stroker.line_cap(lc); }
55
+ void line_join(line_join_e lj) { m_stroker.line_join(lj); }
56
+ void inner_join(inner_join_e ij) { m_stroker.inner_join(ij); }
57
+
58
+ line_cap_e line_cap() const { return m_stroker.line_cap(); }
59
+ line_join_e line_join() const { return m_stroker.line_join(); }
60
+ inner_join_e inner_join() const { return m_stroker.inner_join(); }
61
+
62
+ void width(double w) { m_stroker.width(w); }
63
+ void miter_limit(double ml) { m_stroker.miter_limit(ml); }
64
+ void miter_limit_theta(double t) { m_stroker.miter_limit_theta(t); }
65
+ void inner_miter_limit(double ml) { m_stroker.inner_miter_limit(ml); }
66
+ void approximation_scale(double as) { m_stroker.approximation_scale(as); }
67
+
68
+ double width() const { return m_stroker.width(); }
69
+ double miter_limit() const { return m_stroker.miter_limit(); }
70
+ double inner_miter_limit() const { return m_stroker.inner_miter_limit(); }
71
+ double approximation_scale() const { return m_stroker.approximation_scale(); }
72
+
73
+ void shorten(double s) { m_shorten = s; }
74
+ double shorten() const { return m_shorten; }
75
+
76
+ // Vertex Generator Interface
77
+ void remove_all();
78
+ void add_vertex(double x, double y, unsigned cmd);
79
+
80
+ // Vertex Source Interface
81
+ void rewind(unsigned path_id);
82
+ unsigned vertex(double* x, double* y);
83
+
84
+ private:
85
+ vcgen_stroke(const vcgen_stroke&);
86
+ const vcgen_stroke& operator = (const vcgen_stroke&);
87
+
88
+ math_stroke<coord_storage> m_stroker;
89
+ vertex_storage m_src_vertices;
90
+ coord_storage m_out_vertices;
91
+ double m_shorten;
92
+ unsigned m_closed;
93
+ status_e m_status;
94
+ status_e m_prev_status;
95
+ unsigned m_src_vertex;
96
+ unsigned m_out_vertex;
97
+ };
98
+
99
+
100
+ }
101
+
102
+ #endif
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_vcgen_vertex_sequence.h ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+
16
+ #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_type, 6> 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 path_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
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_vertex_sequence.h ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+ //
16
+ // vertex_sequence container and vertex_dist struct
17
+ //
18
+ //----------------------------------------------------------------------------
19
+ #ifndef AGG_VERTEX_SEQUENCE_INCLUDED
20
+ #define AGG_VERTEX_SEQUENCE_INCLUDED
21
+
22
+ #include "agg_basics.h"
23
+ #include "agg_array.h"
24
+ #include "agg_math.h"
25
+
26
+ namespace agg
27
+ {
28
+
29
+ //----------------------------------------------------------vertex_sequence
30
+ // Modified agg::pod_bvector. The data is interpreted as a sequence
31
+ // of vertices. It means that the type T must expose:
32
+ //
33
+ // bool T::operator() (const T& val)
34
+ //
35
+ // that is called every time new vertex is being added. The main purpose
36
+ // of this operator is the possibility to calculate some values during
37
+ // adding and to return true if the vertex fits some criteria or false if
38
+ // it doesn't. In the last case the new vertex is not added.
39
+ //
40
+ // The simple example is filtering coinciding vertices with calculation
41
+ // of the distance between the current and previous ones:
42
+ //
43
+ // struct vertex_dist
44
+ // {
45
+ // double x;
46
+ // double y;
47
+ // double dist;
48
+ //
49
+ // vertex_dist() {}
50
+ // vertex_dist(double x_, double y_) :
51
+ // x(x_),
52
+ // y(y_),
53
+ // dist(0.0)
54
+ // {
55
+ // }
56
+ //
57
+ // bool operator () (const vertex_dist& val)
58
+ // {
59
+ // return (dist = calc_distance(x, y, val.x, val.y)) > EPSILON;
60
+ // }
61
+ // };
62
+ //
63
+ // Function close() calls this operator and removes the last vertex if
64
+ // necessary.
65
+ //------------------------------------------------------------------------
66
+ template<class T, unsigned S=6>
67
+ class vertex_sequence : public pod_bvector<T, S>
68
+ {
69
+ public:
70
+ typedef pod_bvector<T, S> base_type;
71
+
72
+ void add(const T& val);
73
+ void modify_last(const T& val);
74
+ void close(bool remove_flag);
75
+ };
76
+
77
+
78
+
79
+ //------------------------------------------------------------------------
80
+ template<class T, unsigned S>
81
+ void vertex_sequence<T, S>::add(const T& val)
82
+ {
83
+ if(base_type::size() > 1)
84
+ {
85
+ if(!(*this)[base_type::size() - 2]((*this)[base_type::size() - 1]))
86
+ {
87
+ base_type::remove_last();
88
+ }
89
+ }
90
+ base_type::add(val);
91
+ }
92
+
93
+
94
+ //------------------------------------------------------------------------
95
+ template<class T, unsigned S>
96
+ void vertex_sequence<T, S>::modify_last(const T& val)
97
+ {
98
+ base_type::remove_last();
99
+ add(val);
100
+ }
101
+
102
+
103
+
104
+ //------------------------------------------------------------------------
105
+ template<class T, unsigned S>
106
+ void vertex_sequence<T, S>::close(bool closed)
107
+ {
108
+ while(base_type::size() > 1)
109
+ {
110
+ if((*this)[base_type::size() - 2]((*this)[base_type::size() - 1])) break;
111
+ T t = (*this)[base_type::size() - 1];
112
+ base_type::remove_last();
113
+ modify_last(t);
114
+ }
115
+
116
+ if(closed)
117
+ {
118
+ while(base_type::size() > 1)
119
+ {
120
+ if((*this)[base_type::size() - 1]((*this)[0])) break;
121
+ base_type::remove_last();
122
+ }
123
+ }
124
+ }
125
+
126
+
127
+ //-------------------------------------------------------------vertex_dist
128
+ // Vertex (x, y) with the distance to the next one. The last vertex has
129
+ // distance between the last and the first points if the polygon is closed
130
+ // and 0.0 if it's a polyline.
131
+ struct vertex_dist
132
+ {
133
+ double x;
134
+ double y;
135
+ double dist;
136
+
137
+ vertex_dist() {}
138
+ vertex_dist(double x_, double y_) :
139
+ x(x_),
140
+ y(y_),
141
+ dist(0.0)
142
+ {
143
+ }
144
+
145
+ bool operator () (const vertex_dist& val)
146
+ {
147
+ bool ret = (dist = calc_distance(x, y, val.x, val.y)) > vertex_dist_epsilon;
148
+ if(!ret) dist = 1.0 / vertex_dist_epsilon;
149
+ return ret;
150
+ }
151
+ };
152
+
153
+
154
+
155
+ //--------------------------------------------------------vertex_dist_cmd
156
+ // Save as the above but with additional "command" value
157
+ struct vertex_dist_cmd : public vertex_dist
158
+ {
159
+ unsigned cmd;
160
+
161
+ vertex_dist_cmd() {}
162
+ vertex_dist_cmd(double x_, double y_, unsigned cmd_) :
163
+ vertex_dist(x_, y_),
164
+ cmd(cmd_)
165
+ {
166
+ }
167
+ };
168
+
169
+
170
+ }
171
+
172
+ #endif
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_vpgen_clip_polygon.h ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+
16
+ #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
+ static bool auto_close() { return true; }
58
+ static bool auto_unclose() { return false; }
59
+
60
+ void reset();
61
+ void move_to(double x, double y);
62
+ void line_to(double x, double y);
63
+ unsigned vertex(double* x, double* y);
64
+
65
+ private:
66
+ unsigned clipping_flags(double x, double y);
67
+
68
+ private:
69
+ rect_d m_clip_box;
70
+ double m_x1;
71
+ double m_y1;
72
+ unsigned m_clip_flags;
73
+ double m_x[4];
74
+ double m_y[4];
75
+ unsigned m_num_vertices;
76
+ unsigned m_vertex;
77
+ unsigned m_cmd;
78
+ };
79
+
80
+ }
81
+
82
+
83
+ #endif
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_vpgen_clip_polyline.h ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+
16
+ #ifndef AGG_VPGEN_CLIP_POLYLINE_INCLUDED
17
+ #define AGG_VPGEN_CLIP_POLYLINE_INCLUDED
18
+
19
+ #include "agg_basics.h"
20
+
21
+ namespace agg
22
+ {
23
+
24
+ //======================================================vpgen_clip_polyline
25
+ //
26
+ // See Implementation agg_vpgen_clip_polyline.cpp
27
+ //
28
+ class vpgen_clip_polyline
29
+ {
30
+ public:
31
+ vpgen_clip_polyline() :
32
+ m_clip_box(0, 0, 1, 1),
33
+ m_x1(0),
34
+ m_y1(0),
35
+ m_num_vertices(0),
36
+ m_vertex(0),
37
+ m_move_to(false)
38
+ {
39
+ }
40
+
41
+ void clip_box(double x1, double y1, double x2, double y2)
42
+ {
43
+ m_clip_box.x1 = x1;
44
+ m_clip_box.y1 = y1;
45
+ m_clip_box.x2 = x2;
46
+ m_clip_box.y2 = y2;
47
+ m_clip_box.normalize();
48
+ }
49
+
50
+ double x1() const { return m_clip_box.x1; }
51
+ double y1() const { return m_clip_box.y1; }
52
+ double x2() const { return m_clip_box.x2; }
53
+ double y2() const { return m_clip_box.y2; }
54
+
55
+ static bool auto_close() { return false; }
56
+ static bool auto_unclose() { return true; }
57
+
58
+ void reset();
59
+ void move_to(double x, double y);
60
+ void line_to(double x, double y);
61
+ unsigned vertex(double* x, double* y);
62
+
63
+ private:
64
+ rect_d m_clip_box;
65
+ double m_x1;
66
+ double m_y1;
67
+ double m_x[2];
68
+ double m_y[2];
69
+ unsigned m_cmd[2];
70
+ unsigned m_num_vertices;
71
+ unsigned m_vertex;
72
+ bool m_move_to;
73
+ };
74
+
75
+ }
76
+
77
+
78
+ #endif
testbed/matplotlib__matplotlib/extern/agg24-svn/include/agg_vpgen_segmentator.h ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+
16
+ #ifndef AGG_VPGEN_SEGMENTATOR_INCLUDED
17
+ #define AGG_VPGEN_SEGMENTATOR_INCLUDED
18
+
19
+ #include <math.h>
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
+ static bool auto_close() { return false; }
38
+ static bool auto_unclose() { return false; }
39
+
40
+ void reset() { m_cmd = path_cmd_stop; }
41
+ void move_to(double x, double y);
42
+ void line_to(double x, double y);
43
+ unsigned vertex(double* x, double* y);
44
+
45
+ private:
46
+ double m_approximation_scale;
47
+ double m_x1;
48
+ double m_y1;
49
+ double m_dx;
50
+ double m_dy;
51
+ double m_dl;
52
+ double m_ddl;
53
+ unsigned m_cmd;
54
+ };
55
+
56
+
57
+
58
+ }
59
+
60
+ #endif
61
+
testbed/matplotlib__matplotlib/extern/agg24-svn/src/ChangeLog ADDED
File without changes
testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_arc.cpp ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+ //
16
+ // Arc vertex generator
17
+ //
18
+ //----------------------------------------------------------------------------
19
+
20
+ #include <math.h>
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_da/4) != 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
+ double ra = (fabs(m_rx) + fabs(m_ry)) / 2;
90
+ m_da = acos(ra / (ra + 0.125 / m_scale)) * 2;
91
+ if(ccw)
92
+ {
93
+ while(a2 < a1) a2 += pi * 2.0;
94
+ }
95
+ else
96
+ {
97
+ while(a1 < a2) a1 += pi * 2.0;
98
+ m_da = -m_da;
99
+ }
100
+ m_ccw = ccw;
101
+ m_start = a1;
102
+ m_end = a2;
103
+ m_initialized = true;
104
+ }
105
+
106
+ }
testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_arrowhead.cpp ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+ //
16
+ // 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 path_id)
46
+ {
47
+ m_curr_id = path_id;
48
+ m_curr_coord = 0;
49
+ if(path_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(path_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
+ }
testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_bezier_arc.cpp ADDED
@@ -0,0 +1,258 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+ //
16
+ // Arc generator. Produces at most 4 consecutive cubic bezier curves, i.e.,
17
+ // 4, 7, 10, or 13 vertices.
18
+ //
19
+ //----------------------------------------------------------------------------
20
+
21
+
22
+ #include <math.h>
23
+ #include "agg_bezier_arc.h"
24
+
25
+
26
+ namespace agg
27
+ {
28
+
29
+ // This epsilon is used to prevent us from adding degenerate curves
30
+ // (converging to a single point).
31
+ // The value isn't very critical. Function arc_to_bezier() has a limit
32
+ // of the sweep_angle. If fabs(sweep_angle) exceeds pi/2 the curve
33
+ // becomes inaccurate. But slight exceeding is quite appropriate.
34
+ //-------------------------------------------------bezier_arc_angle_epsilon
35
+ const double bezier_arc_angle_epsilon = 0.01;
36
+
37
+ //------------------------------------------------------------arc_to_bezier
38
+ void arc_to_bezier(double cx, double cy, double rx, double ry,
39
+ double start_angle, double sweep_angle,
40
+ double* curve)
41
+ {
42
+ double x0 = cos(sweep_angle / 2.0);
43
+ double y0 = sin(sweep_angle / 2.0);
44
+ double tx = (1.0 - x0) * 4.0 / 3.0;
45
+ double ty = y0 - tx * x0 / y0;
46
+ double px[4];
47
+ double py[4];
48
+ px[0] = x0;
49
+ py[0] = -y0;
50
+ px[1] = x0 + tx;
51
+ py[1] = -ty;
52
+ px[2] = x0 + tx;
53
+ py[2] = ty;
54
+ px[3] = x0;
55
+ py[3] = y0;
56
+
57
+ double sn = sin(start_angle + sweep_angle / 2.0);
58
+ double cs = cos(start_angle + sweep_angle / 2.0);
59
+
60
+ unsigned i;
61
+ for(i = 0; i < 4; i++)
62
+ {
63
+ curve[i * 2] = cx + rx * (px[i] * cs - py[i] * sn);
64
+ curve[i * 2 + 1] = cy + ry * (px[i] * sn + py[i] * cs);
65
+ }
66
+ }
67
+
68
+
69
+
70
+ //------------------------------------------------------------------------
71
+ void bezier_arc::init(double x, double y,
72
+ double rx, double ry,
73
+ double start_angle,
74
+ double sweep_angle)
75
+ {
76
+ start_angle = fmod(start_angle, 2.0 * pi);
77
+ if(sweep_angle >= 2.0 * pi) sweep_angle = 2.0 * pi;
78
+ if(sweep_angle <= -2.0 * pi) sweep_angle = -2.0 * pi;
79
+
80
+ if(fabs(sweep_angle) < 1e-10)
81
+ {
82
+ m_num_vertices = 4;
83
+ m_cmd = path_cmd_line_to;
84
+ m_vertices[0] = x + rx * cos(start_angle);
85
+ m_vertices[1] = y + ry * sin(start_angle);
86
+ m_vertices[2] = x + rx * cos(start_angle + sweep_angle);
87
+ m_vertices[3] = y + ry * sin(start_angle + sweep_angle);
88
+ return;
89
+ }
90
+
91
+ double total_sweep = 0.0;
92
+ double local_sweep = 0.0;
93
+ double prev_sweep;
94
+ m_num_vertices = 2;
95
+ m_cmd = path_cmd_curve4;
96
+ bool done = false;
97
+ do
98
+ {
99
+ if(sweep_angle < 0.0)
100
+ {
101
+ prev_sweep = total_sweep;
102
+ local_sweep = -pi * 0.5;
103
+ total_sweep -= pi * 0.5;
104
+ if(total_sweep <= sweep_angle + bezier_arc_angle_epsilon)
105
+ {
106
+ local_sweep = sweep_angle - prev_sweep;
107
+ done = true;
108
+ }
109
+ }
110
+ else
111
+ {
112
+ prev_sweep = total_sweep;
113
+ local_sweep = pi * 0.5;
114
+ total_sweep += pi * 0.5;
115
+ if(total_sweep >= sweep_angle - bezier_arc_angle_epsilon)
116
+ {
117
+ local_sweep = sweep_angle - prev_sweep;
118
+ done = true;
119
+ }
120
+ }
121
+
122
+ arc_to_bezier(x, y, rx, ry,
123
+ start_angle,
124
+ local_sweep,
125
+ m_vertices + m_num_vertices - 2);
126
+
127
+ m_num_vertices += 6;
128
+ start_angle += local_sweep;
129
+ }
130
+ while(!done && m_num_vertices < 26);
131
+ }
132
+
133
+
134
+
135
+
136
+ //--------------------------------------------------------------------
137
+ void bezier_arc_svg::init(double x0, double y0,
138
+ double rx, double ry,
139
+ double angle,
140
+ bool large_arc_flag,
141
+ bool sweep_flag,
142
+ double x2, double y2)
143
+ {
144
+ m_radii_ok = true;
145
+
146
+ if(rx < 0.0) rx = -rx;
147
+ if(ry < 0.0) ry = -rx;
148
+
149
+ // Calculate the middle point between
150
+ // the current and the final points
151
+ //------------------------
152
+ double dx2 = (x0 - x2) / 2.0;
153
+ double dy2 = (y0 - y2) / 2.0;
154
+
155
+ double cos_a = cos(angle);
156
+ double sin_a = sin(angle);
157
+
158
+ // Calculate (x1, y1)
159
+ //------------------------
160
+ double x1 = cos_a * dx2 + sin_a * dy2;
161
+ double y1 = -sin_a * dx2 + cos_a * dy2;
162
+
163
+ // Ensure radii are large enough
164
+ //------------------------
165
+ double prx = rx * rx;
166
+ double pry = ry * ry;
167
+ double px1 = x1 * x1;
168
+ double py1 = y1 * y1;
169
+
170
+ // Check that radii are large enough
171
+ //------------------------
172
+ double radii_check = px1/prx + py1/pry;
173
+ if(radii_check > 1.0)
174
+ {
175
+ rx = sqrt(radii_check) * rx;
176
+ ry = sqrt(radii_check) * ry;
177
+ prx = rx * rx;
178
+ pry = ry * ry;
179
+ if(radii_check > 10.0) m_radii_ok = false;
180
+ }
181
+
182
+ // Calculate (cx1, cy1)
183
+ //------------------------
184
+ double sign = (large_arc_flag == sweep_flag) ? -1.0 : 1.0;
185
+ double sq = (prx*pry - prx*py1 - pry*px1) / (prx*py1 + pry*px1);
186
+ double coef = sign * sqrt((sq < 0) ? 0 : sq);
187
+ double cx1 = coef * ((rx * y1) / ry);
188
+ double cy1 = coef * -((ry * x1) / rx);
189
+
190
+ //
191
+ // Calculate (cx, cy) from (cx1, cy1)
192
+ //------------------------
193
+ double sx2 = (x0 + x2) / 2.0;
194
+ double sy2 = (y0 + y2) / 2.0;
195
+ double cx = sx2 + (cos_a * cx1 - sin_a * cy1);
196
+ double cy = sy2 + (sin_a * cx1 + cos_a * cy1);
197
+
198
+ // Calculate the start_angle (angle1) and the sweep_angle (dangle)
199
+ //------------------------
200
+ double ux = (x1 - cx1) / rx;
201
+ double uy = (y1 - cy1) / ry;
202
+ double vx = (-x1 - cx1) / rx;
203
+ double vy = (-y1 - cy1) / ry;
204
+ double p, n;
205
+
206
+ // Calculate the angle start
207
+ //------------------------
208
+ n = sqrt(ux*ux + uy*uy);
209
+ p = ux; // (1 * ux) + (0 * uy)
210
+ sign = (uy < 0) ? -1.0 : 1.0;
211
+ double v = p / n;
212
+ if(v < -1.0) v = -1.0;
213
+ if(v > 1.0) v = 1.0;
214
+ double start_angle = sign * acos(v);
215
+
216
+ // Calculate the sweep angle
217
+ //------------------------
218
+ n = sqrt((ux*ux + uy*uy) * (vx*vx + vy*vy));
219
+ p = ux * vx + uy * vy;
220
+ sign = (ux * vy - uy * vx < 0) ? -1.0 : 1.0;
221
+ v = p / n;
222
+ if(v < -1.0) v = -1.0;
223
+ if(v > 1.0) v = 1.0;
224
+ double sweep_angle = sign * acos(v);
225
+ if(!sweep_flag && sweep_angle > 0)
226
+ {
227
+ sweep_angle -= pi * 2.0;
228
+ }
229
+ else
230
+ if (sweep_flag && sweep_angle < 0)
231
+ {
232
+ sweep_angle += pi * 2.0;
233
+ }
234
+
235
+ // We can now build and transform the resulting arc
236
+ //------------------------
237
+ m_arc.init(0.0, 0.0, rx, ry, start_angle, sweep_angle);
238
+ trans_affine mtx = trans_affine_rotation(angle);
239
+ mtx *= trans_affine_translation(cx, cy);
240
+
241
+ for(unsigned i = 2; i < m_arc.num_vertices()-2; i += 2)
242
+ {
243
+ mtx.transform(m_arc.vertices() + i, m_arc.vertices() + i + 1);
244
+ }
245
+
246
+ // We must make sure that the starting and ending points
247
+ // exactly coincide with the initial (x0,y0) and (x2,y2)
248
+ m_arc.vertices()[0] = x0;
249
+ m_arc.vertices()[1] = y0;
250
+ if(m_arc.num_vertices() > 2)
251
+ {
252
+ m_arc.vertices()[m_arc.num_vertices() - 2] = x2;
253
+ m_arc.vertices()[m_arc.num_vertices() - 1] = y2;
254
+ }
255
+ }
256
+
257
+
258
+ }
testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_bspline.cpp ADDED
@@ -0,0 +1,284 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+ //
16
+ // class bspline
17
+ //
18
+ //----------------------------------------------------------------------------
19
+
20
+ #include "agg_bspline.h"
21
+
22
+ namespace agg
23
+ {
24
+ //------------------------------------------------------------------------
25
+ bspline::bspline() :
26
+ m_max(0),
27
+ m_num(0),
28
+ m_x(0),
29
+ m_y(0),
30
+ m_last_idx(-1)
31
+ {
32
+ }
33
+
34
+ //------------------------------------------------------------------------
35
+ bspline::bspline(int num) :
36
+ m_max(0),
37
+ m_num(0),
38
+ m_x(0),
39
+ m_y(0),
40
+ m_last_idx(-1)
41
+ {
42
+ init(num);
43
+ }
44
+
45
+ //------------------------------------------------------------------------
46
+ bspline::bspline(int num, const double* x, const double* y) :
47
+ m_max(0),
48
+ m_num(0),
49
+ m_x(0),
50
+ m_y(0),
51
+ m_last_idx(-1)
52
+ {
53
+ init(num, x, y);
54
+ }
55
+
56
+
57
+ //------------------------------------------------------------------------
58
+ void bspline::init(int max)
59
+ {
60
+ if(max > 2 && max > m_max)
61
+ {
62
+ m_am.resize(max * 3);
63
+ m_max = max;
64
+ m_x = &m_am[m_max];
65
+ m_y = &m_am[m_max * 2];
66
+ }
67
+ m_num = 0;
68
+ m_last_idx = -1;
69
+ }
70
+
71
+
72
+ //------------------------------------------------------------------------
73
+ void bspline::add_point(double x, double y)
74
+ {
75
+ if(m_num < m_max)
76
+ {
77
+ m_x[m_num] = x;
78
+ m_y[m_num] = y;
79
+ ++m_num;
80
+ }
81
+ }
82
+
83
+
84
+ //------------------------------------------------------------------------
85
+ void bspline::prepare()
86
+ {
87
+ if(m_num > 2)
88
+ {
89
+ int i, k, n1;
90
+ double* temp;
91
+ double* r;
92
+ double* s;
93
+ double h, p, d, f, e;
94
+
95
+ for(k = 0; k < m_num; k++)
96
+ {
97
+ m_am[k] = 0.0;
98
+ }
99
+
100
+ n1 = 3 * m_num;
101
+
102
+ pod_array<double> al(n1);
103
+ temp = &al[0];
104
+
105
+ for(k = 0; k < n1; k++)
106
+ {
107
+ temp[k] = 0.0;
108
+ }
109
+
110
+ r = temp + m_num;
111
+ s = temp + m_num * 2;
112
+
113
+ n1 = m_num - 1;
114
+ d = m_x[1] - m_x[0];
115
+ e = (m_y[1] - m_y[0]) / d;
116
+
117
+ for(k = 1; k < n1; k++)
118
+ {
119
+ h = d;
120
+ d = m_x[k + 1] - m_x[k];
121
+ f = e;
122
+ e = (m_y[k + 1] - m_y[k]) / d;
123
+ al[k] = d / (d + h);
124
+ r[k] = 1.0 - al[k];
125
+ s[k] = 6.0 * (e - f) / (h + d);
126
+ }
127
+
128
+ for(k = 1; k < n1; k++)
129
+ {
130
+ p = 1.0 / (r[k] * al[k - 1] + 2.0);
131
+ al[k] *= -p;
132
+ s[k] = (s[k] - r[k] * s[k - 1]) * p;
133
+ }
134
+
135
+ m_am[n1] = 0.0;
136
+ al[n1 - 1] = s[n1 - 1];
137
+ m_am[n1 - 1] = al[n1 - 1];
138
+
139
+ for(k = n1 - 2, i = 0; i < m_num - 2; i++, k--)
140
+ {
141
+ al[k] = al[k] * al[k + 1] + s[k];
142
+ m_am[k] = al[k];
143
+ }
144
+ }
145
+ m_last_idx = -1;
146
+ }
147
+
148
+
149
+
150
+ //------------------------------------------------------------------------
151
+ void bspline::init(int num, const double* x, const double* y)
152
+ {
153
+ if(num > 2)
154
+ {
155
+ init(num);
156
+ int i;
157
+ for(i = 0; i < num; i++)
158
+ {
159
+ add_point(*x++, *y++);
160
+ }
161
+ prepare();
162
+ }
163
+ m_last_idx = -1;
164
+ }
165
+
166
+
167
+ //------------------------------------------------------------------------
168
+ void bspline::bsearch(int n, const double *x, double x0, int *i)
169
+ {
170
+ int j = n - 1;
171
+ int k;
172
+
173
+ for(*i = 0; (j - *i) > 1; )
174
+ {
175
+ if(x0 < x[k = (*i + j) >> 1]) j = k;
176
+ else *i = k;
177
+ }
178
+ }
179
+
180
+
181
+
182
+ //------------------------------------------------------------------------
183
+ double bspline::interpolation(double x, int i) const
184
+ {
185
+ int j = i + 1;
186
+ double d = m_x[i] - m_x[j];
187
+ double h = x - m_x[j];
188
+ double r = m_x[i] - x;
189
+ double p = d * d / 6.0;
190
+ return (m_am[j] * r * r * r + m_am[i] * h * h * h) / 6.0 / d +
191
+ ((m_y[j] - m_am[j] * p) * r + (m_y[i] - m_am[i] * p) * h) / d;
192
+ }
193
+
194
+
195
+ //------------------------------------------------------------------------
196
+ double bspline::extrapolation_left(double x) const
197
+ {
198
+ double d = m_x[1] - m_x[0];
199
+ return (-d * m_am[1] / 6 + (m_y[1] - m_y[0]) / d) *
200
+ (x - m_x[0]) +
201
+ m_y[0];
202
+ }
203
+
204
+ //------------------------------------------------------------------------
205
+ double bspline::extrapolation_right(double x) const
206
+ {
207
+ double d = m_x[m_num - 1] - m_x[m_num - 2];
208
+ return (d * m_am[m_num - 2] / 6 + (m_y[m_num - 1] - m_y[m_num - 2]) / d) *
209
+ (x - m_x[m_num - 1]) +
210
+ m_y[m_num - 1];
211
+ }
212
+
213
+ //------------------------------------------------------------------------
214
+ double bspline::get(double x) const
215
+ {
216
+ if(m_num > 2)
217
+ {
218
+ int i;
219
+
220
+ // Extrapolation on the left
221
+ if(x < m_x[0]) return extrapolation_left(x);
222
+
223
+ // Extrapolation on the right
224
+ if(x >= m_x[m_num - 1]) return extrapolation_right(x);
225
+
226
+ // Interpolation
227
+ bsearch(m_num, m_x, x, &i);
228
+ return interpolation(x, i);
229
+ }
230
+ return 0.0;
231
+ }
232
+
233
+
234
+ //------------------------------------------------------------------------
235
+ double bspline::get_stateful(double x) const
236
+ {
237
+ if(m_num > 2)
238
+ {
239
+ // Extrapolation on the left
240
+ if(x < m_x[0]) return extrapolation_left(x);
241
+
242
+ // Extrapolation on the right
243
+ if(x >= m_x[m_num - 1]) return extrapolation_right(x);
244
+
245
+ if(m_last_idx >= 0)
246
+ {
247
+ // Check if x is not in current range
248
+ if(x < m_x[m_last_idx] || x > m_x[m_last_idx + 1])
249
+ {
250
+ // Check if x between next points (most probably)
251
+ if(m_last_idx < m_num - 2 &&
252
+ x >= m_x[m_last_idx + 1] &&
253
+ x <= m_x[m_last_idx + 2])
254
+ {
255
+ ++m_last_idx;
256
+ }
257
+ else
258
+ if(m_last_idx > 0 &&
259
+ x >= m_x[m_last_idx - 1] &&
260
+ x <= m_x[m_last_idx])
261
+ {
262
+ // x is between pevious points
263
+ --m_last_idx;
264
+ }
265
+ else
266
+ {
267
+ // Else perform full search
268
+ bsearch(m_num, m_x, x, &m_last_idx);
269
+ }
270
+ }
271
+ return interpolation(x, m_last_idx);
272
+ }
273
+ else
274
+ {
275
+ // Interpolation
276
+ bsearch(m_num, m_x, x, &m_last_idx);
277
+ return interpolation(x, m_last_idx);
278
+ }
279
+ }
280
+ return 0.0;
281
+ }
282
+
283
+ }
284
+
testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_color_rgba.cpp ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2009 John Horigan (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
+ //
12
+ // Contact: john@glyphic.com.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+
16
+ // rgbaN construction from grayN types is no longer required,
17
+ // as grayN types now define their own conversions to rgbaN.
testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_curves.cpp ADDED
@@ -0,0 +1,613 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+
16
+ #include <math.h>
17
+ #include "agg_curves.h"
18
+ #include "agg_math.h"
19
+
20
+ namespace agg
21
+ {
22
+
23
+ //------------------------------------------------------------------------
24
+ const double curve_distance_epsilon = 1e-30;
25
+ const double curve_collinearity_epsilon = 1e-30;
26
+ const double curve_angle_tolerance_epsilon = 0.01;
27
+ enum curve_recursion_limit_e { curve_recursion_limit = 32 };
28
+
29
+
30
+
31
+ //------------------------------------------------------------------------
32
+ void curve3_inc::approximation_scale(double s)
33
+ {
34
+ m_scale = s;
35
+ }
36
+
37
+ //------------------------------------------------------------------------
38
+ double curve3_inc::approximation_scale() const
39
+ {
40
+ return m_scale;
41
+ }
42
+
43
+ //------------------------------------------------------------------------
44
+ void curve3_inc::init(double x1, double y1,
45
+ double x2, double y2,
46
+ double x3, double y3)
47
+ {
48
+ m_start_x = x1;
49
+ m_start_y = y1;
50
+ m_end_x = x3;
51
+ m_end_y = y3;
52
+
53
+ double dx1 = x2 - x1;
54
+ double dy1 = y2 - y1;
55
+ double dx2 = x3 - x2;
56
+ double dy2 = y3 - y2;
57
+
58
+ double len = sqrt(dx1 * dx1 + dy1 * dy1) + sqrt(dx2 * dx2 + dy2 * dy2);
59
+
60
+ m_num_steps = uround(len * 0.25 * m_scale);
61
+
62
+ if(m_num_steps < 4)
63
+ {
64
+ m_num_steps = 4;
65
+ }
66
+
67
+ double subdivide_step = 1.0 / m_num_steps;
68
+ double subdivide_step2 = subdivide_step * subdivide_step;
69
+
70
+ double tmpx = (x1 - x2 * 2.0 + x3) * subdivide_step2;
71
+ double tmpy = (y1 - y2 * 2.0 + y3) * subdivide_step2;
72
+
73
+ m_saved_fx = m_fx = x1;
74
+ m_saved_fy = m_fy = y1;
75
+
76
+ m_saved_dfx = m_dfx = tmpx + (x2 - x1) * (2.0 * subdivide_step);
77
+ m_saved_dfy = m_dfy = tmpy + (y2 - y1) * (2.0 * subdivide_step);
78
+
79
+ m_ddfx = tmpx * 2.0;
80
+ m_ddfy = tmpy * 2.0;
81
+
82
+ m_step = m_num_steps;
83
+ }
84
+
85
+ //------------------------------------------------------------------------
86
+ void curve3_inc::rewind(unsigned)
87
+ {
88
+ if(m_num_steps == 0)
89
+ {
90
+ m_step = -1;
91
+ return;
92
+ }
93
+ m_step = m_num_steps;
94
+ m_fx = m_saved_fx;
95
+ m_fy = m_saved_fy;
96
+ m_dfx = m_saved_dfx;
97
+ m_dfy = m_saved_dfy;
98
+ }
99
+
100
+ //------------------------------------------------------------------------
101
+ unsigned curve3_inc::vertex(double* x, double* y)
102
+ {
103
+ if(m_step < 0) return path_cmd_stop;
104
+ if(m_step == m_num_steps)
105
+ {
106
+ *x = m_start_x;
107
+ *y = m_start_y;
108
+ --m_step;
109
+ return path_cmd_move_to;
110
+ }
111
+ if(m_step == 0)
112
+ {
113
+ *x = m_end_x;
114
+ *y = m_end_y;
115
+ --m_step;
116
+ return path_cmd_line_to;
117
+ }
118
+ m_fx += m_dfx;
119
+ m_fy += m_dfy;
120
+ m_dfx += m_ddfx;
121
+ m_dfy += m_ddfy;
122
+ *x = m_fx;
123
+ *y = m_fy;
124
+ --m_step;
125
+ return path_cmd_line_to;
126
+ }
127
+
128
+ //------------------------------------------------------------------------
129
+ void curve3_div::init(double x1, double y1,
130
+ double x2, double y2,
131
+ double x3, double y3)
132
+ {
133
+ m_points.remove_all();
134
+ m_distance_tolerance_square = 0.5 / m_approximation_scale;
135
+ m_distance_tolerance_square *= m_distance_tolerance_square;
136
+ bezier(x1, y1, x2, y2, x3, y3);
137
+ m_count = 0;
138
+ }
139
+
140
+ //------------------------------------------------------------------------
141
+ void curve3_div::recursive_bezier(double x1, double y1,
142
+ double x2, double y2,
143
+ double x3, double y3,
144
+ unsigned level)
145
+ {
146
+ if(level > curve_recursion_limit)
147
+ {
148
+ return;
149
+ }
150
+
151
+ // Calculate all the mid-points of the line segments
152
+ //----------------------
153
+ double x12 = (x1 + x2) / 2;
154
+ double y12 = (y1 + y2) / 2;
155
+ double x23 = (x2 + x3) / 2;
156
+ double y23 = (y2 + y3) / 2;
157
+ double x123 = (x12 + x23) / 2;
158
+ double y123 = (y12 + y23) / 2;
159
+
160
+ double dx = x3-x1;
161
+ double dy = y3-y1;
162
+ double d = fabs(((x2 - x3) * dy - (y2 - y3) * dx));
163
+ double da;
164
+
165
+ if(d > curve_collinearity_epsilon)
166
+ {
167
+ // Regular case
168
+ //-----------------
169
+ if(d * d <= m_distance_tolerance_square * (dx*dx + dy*dy))
170
+ {
171
+ // If the curvature doesn't exceed the distance_tolerance value
172
+ // we tend to finish subdivisions.
173
+ //----------------------
174
+ if(m_angle_tolerance < curve_angle_tolerance_epsilon)
175
+ {
176
+ m_points.add(point_d(x123, y123));
177
+ return;
178
+ }
179
+
180
+ // Angle & Cusp Condition
181
+ //----------------------
182
+ da = fabs(atan2(y3 - y2, x3 - x2) - atan2(y2 - y1, x2 - x1));
183
+ if(da >= pi) da = 2*pi - da;
184
+
185
+ if(da < m_angle_tolerance)
186
+ {
187
+ // Finally we can stop the recursion
188
+ //----------------------
189
+ m_points.add(point_d(x123, y123));
190
+ return;
191
+ }
192
+ }
193
+ }
194
+ else
195
+ {
196
+ // Collinear case
197
+ //------------------
198
+ da = dx*dx + dy*dy;
199
+ if(da == 0)
200
+ {
201
+ d = calc_sq_distance(x1, y1, x2, y2);
202
+ }
203
+ else
204
+ {
205
+ d = ((x2 - x1)*dx + (y2 - y1)*dy) / da;
206
+ if(d > 0 && d < 1)
207
+ {
208
+ // Simple collinear case, 1---2---3
209
+ // We can leave just two endpoints
210
+ return;
211
+ }
212
+ if(d <= 0) d = calc_sq_distance(x2, y2, x1, y1);
213
+ else if(d >= 1) d = calc_sq_distance(x2, y2, x3, y3);
214
+ else d = calc_sq_distance(x2, y2, x1 + d*dx, y1 + d*dy);
215
+ }
216
+ if(d < m_distance_tolerance_square)
217
+ {
218
+ m_points.add(point_d(x2, y2));
219
+ return;
220
+ }
221
+ }
222
+
223
+ // Continue subdivision
224
+ //----------------------
225
+ recursive_bezier(x1, y1, x12, y12, x123, y123, level + 1);
226
+ recursive_bezier(x123, y123, x23, y23, x3, y3, level + 1);
227
+ }
228
+
229
+ //------------------------------------------------------------------------
230
+ void curve3_div::bezier(double x1, double y1,
231
+ double x2, double y2,
232
+ double x3, double y3)
233
+ {
234
+ m_points.add(point_d(x1, y1));
235
+ recursive_bezier(x1, y1, x2, y2, x3, y3, 0);
236
+ m_points.add(point_d(x3, y3));
237
+ }
238
+
239
+
240
+
241
+
242
+
243
+ //------------------------------------------------------------------------
244
+ void curve4_inc::approximation_scale(double s)
245
+ {
246
+ m_scale = s;
247
+ }
248
+
249
+ //------------------------------------------------------------------------
250
+ double curve4_inc::approximation_scale() const
251
+ {
252
+ return m_scale;
253
+ }
254
+
255
+ #if defined(_MSC_VER) && _MSC_VER <= 1200
256
+ //------------------------------------------------------------------------
257
+ static double MSC60_fix_ICE(double v) { return v; }
258
+ #endif
259
+
260
+ //------------------------------------------------------------------------
261
+ void curve4_inc::init(double x1, double y1,
262
+ double x2, double y2,
263
+ double x3, double y3,
264
+ double x4, double y4)
265
+ {
266
+ m_start_x = x1;
267
+ m_start_y = y1;
268
+ m_end_x = x4;
269
+ m_end_y = y4;
270
+
271
+ double dx1 = x2 - x1;
272
+ double dy1 = y2 - y1;
273
+ double dx2 = x3 - x2;
274
+ double dy2 = y3 - y2;
275
+ double dx3 = x4 - x3;
276
+ double dy3 = y4 - y3;
277
+
278
+ double len = (sqrt(dx1 * dx1 + dy1 * dy1) +
279
+ sqrt(dx2 * dx2 + dy2 * dy2) +
280
+ sqrt(dx3 * dx3 + dy3 * dy3)) * 0.25 * m_scale;
281
+
282
+ #if defined(_MSC_VER) && _MSC_VER <= 1200
283
+ m_num_steps = uround(MSC60_fix_ICE(len));
284
+ #else
285
+ m_num_steps = uround(len);
286
+ #endif
287
+
288
+ if(m_num_steps < 4)
289
+ {
290
+ m_num_steps = 4;
291
+ }
292
+
293
+ double subdivide_step = 1.0 / m_num_steps;
294
+ double subdivide_step2 = subdivide_step * subdivide_step;
295
+ double subdivide_step3 = subdivide_step * subdivide_step * subdivide_step;
296
+
297
+ double pre1 = 3.0 * subdivide_step;
298
+ double pre2 = 3.0 * subdivide_step2;
299
+ double pre4 = 6.0 * subdivide_step2;
300
+ double pre5 = 6.0 * subdivide_step3;
301
+
302
+ double tmp1x = x1 - x2 * 2.0 + x3;
303
+ double tmp1y = y1 - y2 * 2.0 + y3;
304
+
305
+ double tmp2x = (x2 - x3) * 3.0 - x1 + x4;
306
+ double tmp2y = (y2 - y3) * 3.0 - y1 + y4;
307
+
308
+ m_saved_fx = m_fx = x1;
309
+ m_saved_fy = m_fy = y1;
310
+
311
+ m_saved_dfx = m_dfx = (x2 - x1) * pre1 + tmp1x * pre2 + tmp2x * subdivide_step3;
312
+ m_saved_dfy = m_dfy = (y2 - y1) * pre1 + tmp1y * pre2 + tmp2y * subdivide_step3;
313
+
314
+ m_saved_ddfx = m_ddfx = tmp1x * pre4 + tmp2x * pre5;
315
+ m_saved_ddfy = m_ddfy = tmp1y * pre4 + tmp2y * pre5;
316
+
317
+ m_dddfx = tmp2x * pre5;
318
+ m_dddfy = tmp2y * pre5;
319
+
320
+ m_step = m_num_steps;
321
+ }
322
+
323
+ //------------------------------------------------------------------------
324
+ void curve4_inc::rewind(unsigned)
325
+ {
326
+ if(m_num_steps == 0)
327
+ {
328
+ m_step = -1;
329
+ return;
330
+ }
331
+ m_step = m_num_steps;
332
+ m_fx = m_saved_fx;
333
+ m_fy = m_saved_fy;
334
+ m_dfx = m_saved_dfx;
335
+ m_dfy = m_saved_dfy;
336
+ m_ddfx = m_saved_ddfx;
337
+ m_ddfy = m_saved_ddfy;
338
+ }
339
+
340
+ //------------------------------------------------------------------------
341
+ unsigned curve4_inc::vertex(double* x, double* y)
342
+ {
343
+ if(m_step < 0) return path_cmd_stop;
344
+ if(m_step == m_num_steps)
345
+ {
346
+ *x = m_start_x;
347
+ *y = m_start_y;
348
+ --m_step;
349
+ return path_cmd_move_to;
350
+ }
351
+
352
+ if(m_step == 0)
353
+ {
354
+ *x = m_end_x;
355
+ *y = m_end_y;
356
+ --m_step;
357
+ return path_cmd_line_to;
358
+ }
359
+
360
+ m_fx += m_dfx;
361
+ m_fy += m_dfy;
362
+ m_dfx += m_ddfx;
363
+ m_dfy += m_ddfy;
364
+ m_ddfx += m_dddfx;
365
+ m_ddfy += m_dddfy;
366
+
367
+ *x = m_fx;
368
+ *y = m_fy;
369
+ --m_step;
370
+ return path_cmd_line_to;
371
+ }
372
+
373
+
374
+
375
+
376
+ //------------------------------------------------------------------------
377
+ void curve4_div::init(double x1, double y1,
378
+ double x2, double y2,
379
+ double x3, double y3,
380
+ double x4, double y4)
381
+ {
382
+ m_points.remove_all();
383
+ m_distance_tolerance_square = 0.5 / m_approximation_scale;
384
+ m_distance_tolerance_square *= m_distance_tolerance_square;
385
+ bezier(x1, y1, x2, y2, x3, y3, x4, y4);
386
+ m_count = 0;
387
+ }
388
+
389
+ //------------------------------------------------------------------------
390
+ void curve4_div::recursive_bezier(double x1, double y1,
391
+ double x2, double y2,
392
+ double x3, double y3,
393
+ double x4, double y4,
394
+ unsigned level)
395
+ {
396
+ if(level > curve_recursion_limit)
397
+ {
398
+ return;
399
+ }
400
+
401
+ // Calculate all the mid-points of the line segments
402
+ //----------------------
403
+ double x12 = (x1 + x2) / 2;
404
+ double y12 = (y1 + y2) / 2;
405
+ double x23 = (x2 + x3) / 2;
406
+ double y23 = (y2 + y3) / 2;
407
+ double x34 = (x3 + x4) / 2;
408
+ double y34 = (y3 + y4) / 2;
409
+ double x123 = (x12 + x23) / 2;
410
+ double y123 = (y12 + y23) / 2;
411
+ double x234 = (x23 + x34) / 2;
412
+ double y234 = (y23 + y34) / 2;
413
+ double x1234 = (x123 + x234) / 2;
414
+ double y1234 = (y123 + y234) / 2;
415
+
416
+
417
+ // Try to approximate the full cubic curve by a single straight line
418
+ //------------------
419
+ double dx = x4-x1;
420
+ double dy = y4-y1;
421
+
422
+ double d2 = fabs(((x2 - x4) * dy - (y2 - y4) * dx));
423
+ double d3 = fabs(((x3 - x4) * dy - (y3 - y4) * dx));
424
+ double da1, da2, k;
425
+
426
+ switch((int(d2 > curve_collinearity_epsilon) << 1) +
427
+ int(d3 > curve_collinearity_epsilon))
428
+ {
429
+ case 0:
430
+ // All collinear OR p1==p4
431
+ //----------------------
432
+ k = dx*dx + dy*dy;
433
+ if(k == 0)
434
+ {
435
+ d2 = calc_sq_distance(x1, y1, x2, y2);
436
+ d3 = calc_sq_distance(x4, y4, x3, y3);
437
+ }
438
+ else
439
+ {
440
+ k = 1 / k;
441
+ da1 = x2 - x1;
442
+ da2 = y2 - y1;
443
+ d2 = k * (da1*dx + da2*dy);
444
+ da1 = x3 - x1;
445
+ da2 = y3 - y1;
446
+ d3 = k * (da1*dx + da2*dy);
447
+ if(d2 > 0 && d2 < 1 && d3 > 0 && d3 < 1)
448
+ {
449
+ // Simple collinear case, 1---2---3---4
450
+ // We can leave just two endpoints
451
+ return;
452
+ }
453
+ if(d2 <= 0) d2 = calc_sq_distance(x2, y2, x1, y1);
454
+ else if(d2 >= 1) d2 = calc_sq_distance(x2, y2, x4, y4);
455
+ else d2 = calc_sq_distance(x2, y2, x1 + d2*dx, y1 + d2*dy);
456
+
457
+ if(d3 <= 0) d3 = calc_sq_distance(x3, y3, x1, y1);
458
+ else if(d3 >= 1) d3 = calc_sq_distance(x3, y3, x4, y4);
459
+ else d3 = calc_sq_distance(x3, y3, x1 + d3*dx, y1 + d3*dy);
460
+ }
461
+ if(d2 > d3)
462
+ {
463
+ if(d2 < m_distance_tolerance_square)
464
+ {
465
+ m_points.add(point_d(x2, y2));
466
+ return;
467
+ }
468
+ }
469
+ else
470
+ {
471
+ if(d3 < m_distance_tolerance_square)
472
+ {
473
+ m_points.add(point_d(x3, y3));
474
+ return;
475
+ }
476
+ }
477
+ break;
478
+
479
+ case 1:
480
+ // p1,p2,p4 are collinear, p3 is significant
481
+ //----------------------
482
+ if(d3 * d3 <= m_distance_tolerance_square * (dx*dx + dy*dy))
483
+ {
484
+ if(m_angle_tolerance < curve_angle_tolerance_epsilon)
485
+ {
486
+ m_points.add(point_d(x23, y23));
487
+ return;
488
+ }
489
+
490
+ // Angle Condition
491
+ //----------------------
492
+ da1 = fabs(atan2(y4 - y3, x4 - x3) - atan2(y3 - y2, x3 - x2));
493
+ if(da1 >= pi) da1 = 2*pi - da1;
494
+
495
+ if(da1 < m_angle_tolerance)
496
+ {
497
+ m_points.add(point_d(x2, y2));
498
+ m_points.add(point_d(x3, y3));
499
+ return;
500
+ }
501
+
502
+ if(m_cusp_limit != 0.0)
503
+ {
504
+ if(da1 > m_cusp_limit)
505
+ {
506
+ m_points.add(point_d(x3, y3));
507
+ return;
508
+ }
509
+ }
510
+ }
511
+ break;
512
+
513
+ case 2:
514
+ // p1,p3,p4 are collinear, p2 is significant
515
+ //----------------------
516
+ if(d2 * d2 <= m_distance_tolerance_square * (dx*dx + dy*dy))
517
+ {
518
+ if(m_angle_tolerance < curve_angle_tolerance_epsilon)
519
+ {
520
+ m_points.add(point_d(x23, y23));
521
+ return;
522
+ }
523
+
524
+ // Angle Condition
525
+ //----------------------
526
+ da1 = fabs(atan2(y3 - y2, x3 - x2) - atan2(y2 - y1, x2 - x1));
527
+ if(da1 >= pi) da1 = 2*pi - da1;
528
+
529
+ if(da1 < m_angle_tolerance)
530
+ {
531
+ m_points.add(point_d(x2, y2));
532
+ m_points.add(point_d(x3, y3));
533
+ return;
534
+ }
535
+
536
+ if(m_cusp_limit != 0.0)
537
+ {
538
+ if(da1 > m_cusp_limit)
539
+ {
540
+ m_points.add(point_d(x2, y2));
541
+ return;
542
+ }
543
+ }
544
+ }
545
+ break;
546
+
547
+ case 3:
548
+ // Regular case
549
+ //-----------------
550
+ if((d2 + d3)*(d2 + d3) <= m_distance_tolerance_square * (dx*dx + dy*dy))
551
+ {
552
+ // If the curvature doesn't exceed the distance_tolerance value
553
+ // we tend to finish subdivisions.
554
+ //----------------------
555
+ if(m_angle_tolerance < curve_angle_tolerance_epsilon)
556
+ {
557
+ m_points.add(point_d(x23, y23));
558
+ return;
559
+ }
560
+
561
+ // Angle & Cusp Condition
562
+ //----------------------
563
+ k = atan2(y3 - y2, x3 - x2);
564
+ da1 = fabs(k - atan2(y2 - y1, x2 - x1));
565
+ da2 = fabs(atan2(y4 - y3, x4 - x3) - k);
566
+ if(da1 >= pi) da1 = 2*pi - da1;
567
+ if(da2 >= pi) da2 = 2*pi - da2;
568
+
569
+ if(da1 + da2 < m_angle_tolerance)
570
+ {
571
+ // Finally we can stop the recursion
572
+ //----------------------
573
+ m_points.add(point_d(x23, y23));
574
+ return;
575
+ }
576
+
577
+ if(m_cusp_limit != 0.0)
578
+ {
579
+ if(da1 > m_cusp_limit)
580
+ {
581
+ m_points.add(point_d(x2, y2));
582
+ return;
583
+ }
584
+
585
+ if(da2 > m_cusp_limit)
586
+ {
587
+ m_points.add(point_d(x3, y3));
588
+ return;
589
+ }
590
+ }
591
+ }
592
+ break;
593
+ }
594
+
595
+ // Continue subdivision
596
+ //----------------------
597
+ recursive_bezier(x1, y1, x12, y12, x123, y123, x1234, y1234, level + 1);
598
+ recursive_bezier(x1234, y1234, x234, y234, x34, y34, x4, y4, level + 1);
599
+ }
600
+
601
+ //------------------------------------------------------------------------
602
+ void curve4_div::bezier(double x1, double y1,
603
+ double x2, double y2,
604
+ double x3, double y3,
605
+ double x4, double y4)
606
+ {
607
+ m_points.add(point_d(x1, y1));
608
+ recursive_bezier(x1, y1, x2, y2, x3, y3, x4, y4, 0);
609
+ m_points.add(point_d(x4, y4));
610
+ }
611
+
612
+ }
613
+
testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_embedded_raster_fonts.cpp ADDED
The diff for this file is too large to render. See raw diff
 
testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_gsv_text.cpp ADDED
@@ -0,0 +1,675 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+ //
16
+ // Class gsv_text
17
+ //
18
+ //----------------------------------------------------------------------------
19
+ #include <string.h>
20
+ #include <stdio.h>
21
+ #include "agg_gsv_text.h"
22
+ #include "agg_bounding_rect.h"
23
+
24
+
25
+
26
+ namespace agg
27
+ {
28
+ int8u gsv_default_font[] =
29
+ {
30
+ 0x40,0x00,0x6c,0x0f,0x15,0x00,0x0e,0x00,0xf9,0xff,
31
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
32
+ 0x0d,0x0a,0x0d,0x0a,0x46,0x6f,0x6e,0x74,0x20,0x28,
33
+ 0x63,0x29,0x20,0x4d,0x69,0x63,0x72,0x6f,0x50,0x72,
34
+ 0x6f,0x66,0x20,0x32,0x37,0x20,0x53,0x65,0x70,0x74,
35
+ 0x65,0x6d,0x62,0x2e,0x31,0x39,0x38,0x39,0x00,0x0d,
36
+ 0x0a,0x0d,0x0a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
37
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
38
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
39
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
40
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
41
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
42
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
43
+ 0x02,0x00,0x12,0x00,0x34,0x00,0x46,0x00,0x94,0x00,
44
+ 0xd0,0x00,0x2e,0x01,0x3e,0x01,0x64,0x01,0x8a,0x01,
45
+ 0x98,0x01,0xa2,0x01,0xb4,0x01,0xba,0x01,0xc6,0x01,
46
+ 0xcc,0x01,0xf0,0x01,0xfa,0x01,0x18,0x02,0x38,0x02,
47
+ 0x44,0x02,0x68,0x02,0x98,0x02,0xa2,0x02,0xde,0x02,
48
+ 0x0e,0x03,0x24,0x03,0x40,0x03,0x48,0x03,0x52,0x03,
49
+ 0x5a,0x03,0x82,0x03,0xec,0x03,0xfa,0x03,0x26,0x04,
50
+ 0x4c,0x04,0x6a,0x04,0x7c,0x04,0x8a,0x04,0xb6,0x04,
51
+ 0xc4,0x04,0xca,0x04,0xe0,0x04,0xee,0x04,0xf8,0x04,
52
+ 0x0a,0x05,0x18,0x05,0x44,0x05,0x5e,0x05,0x8e,0x05,
53
+ 0xac,0x05,0xd6,0x05,0xe0,0x05,0xf6,0x05,0x00,0x06,
54
+ 0x12,0x06,0x1c,0x06,0x28,0x06,0x36,0x06,0x48,0x06,
55
+ 0x4e,0x06,0x60,0x06,0x6e,0x06,0x74,0x06,0x84,0x06,
56
+ 0xa6,0x06,0xc8,0x06,0xe6,0x06,0x08,0x07,0x2c,0x07,
57
+ 0x3c,0x07,0x68,0x07,0x7c,0x07,0x8c,0x07,0xa2,0x07,
58
+ 0xb0,0x07,0xb6,0x07,0xd8,0x07,0xec,0x07,0x10,0x08,
59
+ 0x32,0x08,0x54,0x08,0x64,0x08,0x88,0x08,0x98,0x08,
60
+ 0xac,0x08,0xb6,0x08,0xc8,0x08,0xd2,0x08,0xe4,0x08,
61
+ 0xf2,0x08,0x3e,0x09,0x48,0x09,0x94,0x09,0xc2,0x09,
62
+ 0xc4,0x09,0xd0,0x09,0xe2,0x09,0x04,0x0a,0x0e,0x0a,
63
+ 0x26,0x0a,0x34,0x0a,0x4a,0x0a,0x66,0x0a,0x70,0x0a,
64
+ 0x7e,0x0a,0x8e,0x0a,0x9a,0x0a,0xa6,0x0a,0xb4,0x0a,
65
+ 0xd8,0x0a,0xe2,0x0a,0xf6,0x0a,0x18,0x0b,0x22,0x0b,
66
+ 0x32,0x0b,0x56,0x0b,0x60,0x0b,0x6e,0x0b,0x7c,0x0b,
67
+ 0x8a,0x0b,0x9c,0x0b,0x9e,0x0b,0xb2,0x0b,0xc2,0x0b,
68
+ 0xd8,0x0b,0xf4,0x0b,0x08,0x0c,0x30,0x0c,0x56,0x0c,
69
+ 0x72,0x0c,0x90,0x0c,0xb2,0x0c,0xce,0x0c,0xe2,0x0c,
70
+ 0xfe,0x0c,0x10,0x0d,0x26,0x0d,0x36,0x0d,0x42,0x0d,
71
+ 0x4e,0x0d,0x5c,0x0d,0x78,0x0d,0x8c,0x0d,0x8e,0x0d,
72
+ 0x90,0x0d,0x92,0x0d,0x94,0x0d,0x96,0x0d,0x98,0x0d,
73
+ 0x9a,0x0d,0x9c,0x0d,0x9e,0x0d,0xa0,0x0d,0xa2,0x0d,
74
+ 0xa4,0x0d,0xa6,0x0d,0xa8,0x0d,0xaa,0x0d,0xac,0x0d,
75
+ 0xae,0x0d,0xb0,0x0d,0xb2,0x0d,0xb4,0x0d,0xb6,0x0d,
76
+ 0xb8,0x0d,0xba,0x0d,0xbc,0x0d,0xbe,0x0d,0xc0,0x0d,
77
+ 0xc2,0x0d,0xc4,0x0d,0xc6,0x0d,0xc8,0x0d,0xca,0x0d,
78
+ 0xcc,0x0d,0xce,0x0d,0xd0,0x0d,0xd2,0x0d,0xd4,0x0d,
79
+ 0xd6,0x0d,0xd8,0x0d,0xda,0x0d,0xdc,0x0d,0xde,0x0d,
80
+ 0xe0,0x0d,0xe2,0x0d,0xe4,0x0d,0xe6,0x0d,0xe8,0x0d,
81
+ 0xea,0x0d,0xec,0x0d,0x0c,0x0e,0x26,0x0e,0x48,0x0e,
82
+ 0x64,0x0e,0x88,0x0e,0x92,0x0e,0xa6,0x0e,0xb4,0x0e,
83
+ 0xd0,0x0e,0xee,0x0e,0x02,0x0f,0x16,0x0f,0x26,0x0f,
84
+ 0x3c,0x0f,0x58,0x0f,0x6c,0x0f,0x6c,0x0f,0x6c,0x0f,
85
+ 0x6c,0x0f,0x6c,0x0f,0x6c,0x0f,0x6c,0x0f,0x6c,0x0f,
86
+ 0x6c,0x0f,0x6c,0x0f,0x6c,0x0f,0x6c,0x0f,0x6c,0x0f,
87
+ 0x6c,0x0f,0x6c,0x0f,0x6c,0x0f,0x6c,0x0f,0x10,0x80,
88
+ 0x05,0x95,0x00,0x72,0x00,0xfb,0xff,0x7f,0x01,0x7f,
89
+ 0x01,0x01,0xff,0x01,0x05,0xfe,0x05,0x95,0xff,0x7f,
90
+ 0x00,0x7a,0x01,0x86,0xff,0x7a,0x01,0x87,0x01,0x7f,
91
+ 0xfe,0x7a,0x0a,0x87,0xff,0x7f,0x00,0x7a,0x01,0x86,
92
+ 0xff,0x7a,0x01,0x87,0x01,0x7f,0xfe,0x7a,0x05,0xf2,
93
+ 0x0b,0x95,0xf9,0x64,0x0d,0x9c,0xf9,0x64,0xfa,0x91,
94
+ 0x0e,0x00,0xf1,0xfa,0x0e,0x00,0x04,0xfc,0x08,0x99,
95
+ 0x00,0x63,0x04,0x9d,0x00,0x63,0x04,0x96,0xff,0x7f,
96
+ 0x01,0x7f,0x01,0x01,0x00,0x01,0xfe,0x02,0xfd,0x01,
97
+ 0xfc,0x00,0xfd,0x7f,0xfe,0x7e,0x00,0x7e,0x01,0x7e,
98
+ 0x01,0x7f,0x02,0x7f,0x06,0x7e,0x02,0x7f,0x02,0x7e,
99
+ 0xf2,0x89,0x02,0x7e,0x02,0x7f,0x06,0x7e,0x02,0x7f,
100
+ 0x01,0x7f,0x01,0x7e,0x00,0x7c,0xfe,0x7e,0xfd,0x7f,
101
+ 0xfc,0x00,0xfd,0x01,0xfe,0x02,0x00,0x01,0x01,0x01,
102
+ 0x01,0x7f,0xff,0x7f,0x10,0xfd,0x15,0x95,0xee,0x6b,
103
+ 0x05,0x95,0x02,0x7e,0x00,0x7e,0xff,0x7e,0xfe,0x7f,
104
+ 0xfe,0x00,0xfe,0x02,0x00,0x02,0x01,0x02,0x02,0x01,
105
+ 0x02,0x00,0x02,0x7f,0x03,0x7f,0x03,0x00,0x03,0x01,
106
+ 0x02,0x01,0xfc,0xf2,0xfe,0x7f,0xff,0x7e,0x00,0x7e,
107
+ 0x02,0x7e,0x02,0x00,0x02,0x01,0x01,0x02,0x00,0x02,
108
+ 0xfe,0x02,0xfe,0x00,0x07,0xf9,0x15,0x8d,0xff,0x7f,
109
+ 0x01,0x7f,0x01,0x01,0x00,0x01,0xff,0x01,0xff,0x00,
110
+ 0xff,0x7f,0xff,0x7e,0xfe,0x7b,0xfe,0x7d,0xfe,0x7e,
111
+ 0xfe,0x7f,0xfd,0x00,0xfd,0x01,0xff,0x02,0x00,0x03,
112
+ 0x01,0x02,0x06,0x04,0x02,0x02,0x01,0x02,0x00,0x02,
113
+ 0xff,0x02,0xfe,0x01,0xfe,0x7f,0xff,0x7e,0x00,0x7e,
114
+ 0x01,0x7d,0x02,0x7d,0x05,0x79,0x02,0x7e,0x03,0x7f,
115
+ 0x01,0x00,0x01,0x01,0x00,0x01,0xf1,0xfe,0xfe,0x01,
116
+ 0xff,0x02,0x00,0x03,0x01,0x02,0x02,0x02,0x00,0x86,
117
+ 0x01,0x7e,0x08,0x75,0x02,0x7e,0x02,0x7f,0x05,0x80,
118
+ 0x05,0x93,0xff,0x01,0x01,0x01,0x01,0x7f,0x00,0x7e,
119
+ 0xff,0x7e,0xff,0x7f,0x06,0xf1,0x0b,0x99,0xfe,0x7e,
120
+ 0xfe,0x7d,0xfe,0x7c,0xff,0x7b,0x00,0x7c,0x01,0x7b,
121
+ 0x02,0x7c,0x02,0x7d,0x02,0x7e,0xfe,0x9e,0xfe,0x7c,
122
+ 0xff,0x7d,0xff,0x7b,0x00,0x7c,0x01,0x7b,0x01,0x7d,
123
+ 0x02,0x7c,0x05,0x85,0x03,0x99,0x02,0x7e,0x02,0x7d,
124
+ 0x02,0x7c,0x01,0x7b,0x00,0x7c,0xff,0x7b,0xfe,0x7c,
125
+ 0xfe,0x7d,0xfe,0x7e,0x02,0x9e,0x02,0x7c,0x01,0x7d,
126
+ 0x01,0x7b,0x00,0x7c,0xff,0x7b,0xff,0x7d,0xfe,0x7c,
127
+ 0x09,0x85,0x08,0x95,0x00,0x74,0xfb,0x89,0x0a,0x7a,
128
+ 0x00,0x86,0xf6,0x7a,0x0d,0xf4,0x0d,0x92,0x00,0x6e,
129
+ 0xf7,0x89,0x12,0x00,0x04,0xf7,0x06,0x81,0xff,0x7f,
130
+ 0xff,0x01,0x01,0x01,0x01,0x7f,0x00,0x7e,0xff,0x7e,
131
+ 0xff,0x7f,0x06,0x84,0x04,0x89,0x12,0x00,0x04,0xf7,
132
+ 0x05,0x82,0xff,0x7f,0x01,0x7f,0x01,0x01,0xff,0x01,
133
+ 0x05,0xfe,0x00,0xfd,0x0e,0x18,0x00,0xeb,0x09,0x95,
134
+ 0xfd,0x7f,0xfe,0x7d,0xff,0x7b,0x00,0x7d,0x01,0x7b,
135
+ 0x02,0x7d,0x03,0x7f,0x02,0x00,0x03,0x01,0x02,0x03,
136
+ 0x01,0x05,0x00,0x03,0xff,0x05,0xfe,0x03,0xfd,0x01,
137
+ 0xfe,0x00,0x0b,0xeb,0x06,0x91,0x02,0x01,0x03,0x03,
138
+ 0x00,0x6b,0x09,0x80,0x04,0x90,0x00,0x01,0x01,0x02,
139
+ 0x01,0x01,0x02,0x01,0x04,0x00,0x02,0x7f,0x01,0x7f,
140
+ 0x01,0x7e,0x00,0x7e,0xff,0x7e,0xfe,0x7d,0xf6,0x76,
141
+ 0x0e,0x00,0x03,0x80,0x05,0x95,0x0b,0x00,0xfa,0x78,
142
+ 0x03,0x00,0x02,0x7f,0x01,0x7f,0x01,0x7d,0x00,0x7e,
143
+ 0xff,0x7d,0xfe,0x7e,0xfd,0x7f,0xfd,0x00,0xfd,0x01,
144
+ 0xff,0x01,0xff,0x02,0x11,0xfc,0x0d,0x95,0xf6,0x72,
145
+ 0x0f,0x00,0xfb,0x8e,0x00,0x6b,0x07,0x80,0x0f,0x95,
146
+ 0xf6,0x00,0xff,0x77,0x01,0x01,0x03,0x01,0x03,0x00,
147
+ 0x03,0x7f,0x02,0x7e,0x01,0x7d,0x00,0x7e,0xff,0x7d,
148
+ 0xfe,0x7e,0xfd,0x7f,0xfd,0x00,0xfd,0x01,0xff,0x01,
149
+ 0xff,0x02,0x11,0xfc,0x10,0x92,0xff,0x02,0xfd,0x01,
150
+ 0xfe,0x00,0xfd,0x7f,0xfe,0x7d,0xff,0x7b,0x00,0x7b,
151
+ 0x01,0x7c,0x02,0x7e,0x03,0x7f,0x01,0x00,0x03,0x01,
152
+ 0x02,0x02,0x01,0x03,0x00,0x01,0xff,0x03,0xfe,0x02,
153
+ 0xfd,0x01,0xff,0x00,0xfd,0x7f,0xfe,0x7e,0xff,0x7d,
154
+ 0x10,0xf9,0x11,0x95,0xf6,0x6b,0xfc,0x95,0x0e,0x00,
155
+ 0x03,0xeb,0x08,0x95,0xfd,0x7f,0xff,0x7e,0x00,0x7e,
156
+ 0x01,0x7e,0x02,0x7f,0x04,0x7f,0x03,0x7f,0x02,0x7e,
157
+ 0x01,0x7e,0x00,0x7d,0xff,0x7e,0xff,0x7f,0xfd,0x7f,
158
+ 0xfc,0x00,0xfd,0x01,0xff,0x01,0xff,0x02,0x00,0x03,
159
+ 0x01,0x02,0x02,0x02,0x03,0x01,0x04,0x01,0x02,0x01,
160
+ 0x01,0x02,0x00,0x02,0xff,0x02,0xfd,0x01,0xfc,0x00,
161
+ 0x0c,0xeb,0x10,0x8e,0xff,0x7d,0xfe,0x7e,0xfd,0x7f,
162
+ 0xff,0x00,0xfd,0x01,0xfe,0x02,0xff,0x03,0x00,0x01,
163
+ 0x01,0x03,0x02,0x02,0x03,0x01,0x01,0x00,0x03,0x7f,
164
+ 0x02,0x7e,0x01,0x7c,0x00,0x7b,0xff,0x7b,0xfe,0x7d,
165
+ 0xfd,0x7f,0xfe,0x00,0xfd,0x01,0xff,0x02,0x10,0xfd,
166
+ 0x05,0x8e,0xff,0x7f,0x01,0x7f,0x01,0x01,0xff,0x01,
167
+ 0x00,0xf4,0xff,0x7f,0x01,0x7f,0x01,0x01,0xff,0x01,
168
+ 0x05,0xfe,0x05,0x8e,0xff,0x7f,0x01,0x7f,0x01,0x01,
169
+ 0xff,0x01,0x01,0xf3,0xff,0x7f,0xff,0x01,0x01,0x01,
170
+ 0x01,0x7f,0x00,0x7e,0xff,0x7e,0xff,0x7f,0x06,0x84,
171
+ 0x14,0x92,0xf0,0x77,0x10,0x77,0x04,0x80,0x04,0x8c,
172
+ 0x12,0x00,0xee,0xfa,0x12,0x00,0x04,0xfa,0x04,0x92,
173
+ 0x10,0x77,0xf0,0x77,0x14,0x80,0x03,0x90,0x00,0x01,
174
+ 0x01,0x02,0x01,0x01,0x02,0x01,0x04,0x00,0x02,0x7f,
175
+ 0x01,0x7f,0x01,0x7e,0x00,0x7e,0xff,0x7e,0xff,0x7f,
176
+ 0xfc,0x7e,0x00,0x7d,0x00,0xfb,0xff,0x7f,0x01,0x7f,
177
+ 0x01,0x01,0xff,0x01,0x09,0xfe,0x12,0x8d,0xff,0x02,
178
+ 0xfe,0x01,0xfd,0x00,0xfe,0x7f,0xff,0x7f,0xff,0x7d,
179
+ 0x00,0x7d,0x01,0x7e,0x02,0x7f,0x03,0x00,0x02,0x01,
180
+ 0x01,0x02,0xfb,0x88,0xfe,0x7e,0xff,0x7d,0x00,0x7d,
181
+ 0x01,0x7e,0x01,0x7f,0x07,0x8b,0xff,0x78,0x00,0x7e,
182
+ 0x02,0x7f,0x02,0x00,0x02,0x02,0x01,0x03,0x00,0x02,
183
+ 0xff,0x03,0xff,0x02,0xfe,0x02,0xfe,0x01,0xfd,0x01,
184
+ 0xfd,0x00,0xfd,0x7f,0xfe,0x7f,0xfe,0x7e,0xff,0x7e,
185
+ 0xff,0x7d,0x00,0x7d,0x01,0x7d,0x01,0x7e,0x02,0x7e,
186
+ 0x02,0x7f,0x03,0x7f,0x03,0x00,0x03,0x01,0x02,0x01,
187
+ 0x01,0x01,0xfe,0x8d,0xff,0x78,0x00,0x7e,0x01,0x7f,
188
+ 0x08,0xfb,0x09,0x95,0xf8,0x6b,0x08,0x95,0x08,0x6b,
189
+ 0xf3,0x87,0x0a,0x00,0x04,0xf9,0x04,0x95,0x00,0x6b,
190
+ 0x00,0x95,0x09,0x00,0x03,0x7f,0x01,0x7f,0x01,0x7e,
191
+ 0x00,0x7e,0xff,0x7e,0xff,0x7f,0xfd,0x7f,0xf7,0x80,
192
+ 0x09,0x00,0x03,0x7f,0x01,0x7f,0x01,0x7e,0x00,0x7d,
193
+ 0xff,0x7e,0xff,0x7f,0xfd,0x7f,0xf7,0x00,0x11,0x80,
194
+ 0x12,0x90,0xff,0x02,0xfe,0x02,0xfe,0x01,0xfc,0x00,
195
+ 0xfe,0x7f,0xfe,0x7e,0xff,0x7e,0xff,0x7d,0x00,0x7b,
196
+ 0x01,0x7d,0x01,0x7e,0x02,0x7e,0x02,0x7f,0x04,0x00,
197
+ 0x02,0x01,0x02,0x02,0x01,0x02,0x03,0xfb,0x04,0x95,
198
+ 0x00,0x6b,0x00,0x95,0x07,0x00,0x03,0x7f,0x02,0x7e,
199
+ 0x01,0x7e,0x01,0x7d,0x00,0x7b,0xff,0x7d,0xff,0x7e,
200
+ 0xfe,0x7e,0xfd,0x7f,0xf9,0x00,0x11,0x80,0x04,0x95,
201
+ 0x00,0x6b,0x00,0x95,0x0d,0x00,0xf3,0xf6,0x08,0x00,
202
+ 0xf8,0xf5,0x0d,0x00,0x02,0x80,0x04,0x95,0x00,0x6b,
203
+ 0x00,0x95,0x0d,0x00,0xf3,0xf6,0x08,0x00,0x06,0xf5,
204
+ 0x12,0x90,0xff,0x02,0xfe,0x02,0xfe,0x01,0xfc,0x00,
205
+ 0xfe,0x7f,0xfe,0x7e,0xff,0x7e,0xff,0x7d,0x00,0x7b,
206
+ 0x01,0x7d,0x01,0x7e,0x02,0x7e,0x02,0x7f,0x04,0x00,
207
+ 0x02,0x01,0x02,0x02,0x01,0x02,0x00,0x03,0xfb,0x80,
208
+ 0x05,0x00,0x03,0xf8,0x04,0x95,0x00,0x6b,0x0e,0x95,
209
+ 0x00,0x6b,0xf2,0x8b,0x0e,0x00,0x04,0xf5,0x04,0x95,
210
+ 0x00,0x6b,0x04,0x80,0x0c,0x95,0x00,0x70,0xff,0x7d,
211
+ 0xff,0x7f,0xfe,0x7f,0xfe,0x00,0xfe,0x01,0xff,0x01,
212
+ 0xff,0x03,0x00,0x02,0x0e,0xf9,0x04,0x95,0x00,0x6b,
213
+ 0x0e,0x95,0xf2,0x72,0x05,0x85,0x09,0x74,0x03,0x80,
214
+ 0x04,0x95,0x00,0x6b,0x00,0x80,0x0c,0x00,0x01,0x80,
215
+ 0x04,0x95,0x00,0x6b,0x00,0x95,0x08,0x6b,0x08,0x95,
216
+ 0xf8,0x6b,0x08,0x95,0x00,0x6b,0x04,0x80,0x04,0x95,
217
+ 0x00,0x6b,0x00,0x95,0x0e,0x6b,0x00,0x95,0x00,0x6b,
218
+ 0x04,0x80,0x09,0x95,0xfe,0x7f,0xfe,0x7e,0xff,0x7e,
219
+ 0xff,0x7d,0x00,0x7b,0x01,0x7d,0x01,0x7e,0x02,0x7e,
220
+ 0x02,0x7f,0x04,0x00,0x02,0x01,0x02,0x02,0x01,0x02,
221
+ 0x01,0x03,0x00,0x05,0xff,0x03,0xff,0x02,0xfe,0x02,
222
+ 0xfe,0x01,0xfc,0x00,0x0d,0xeb,0x04,0x95,0x00,0x6b,
223
+ 0x00,0x95,0x09,0x00,0x03,0x7f,0x01,0x7f,0x01,0x7e,
224
+ 0x00,0x7d,0xff,0x7e,0xff,0x7f,0xfd,0x7f,0xf7,0x00,
225
+ 0x11,0xf6,0x09,0x95,0xfe,0x7f,0xfe,0x7e,0xff,0x7e,
226
+ 0xff,0x7d,0x00,0x7b,0x01,0x7d,0x01,0x7e,0x02,0x7e,
227
+ 0x02,0x7f,0x04,0x00,0x02,0x01,0x02,0x02,0x01,0x02,
228
+ 0x01,0x03,0x00,0x05,0xff,0x03,0xff,0x02,0xfe,0x02,
229
+ 0xfe,0x01,0xfc,0x00,0x03,0xef,0x06,0x7a,0x04,0x82,
230
+ 0x04,0x95,0x00,0x6b,0x00,0x95,0x09,0x00,0x03,0x7f,
231
+ 0x01,0x7f,0x01,0x7e,0x00,0x7e,0xff,0x7e,0xff,0x7f,
232
+ 0xfd,0x7f,0xf7,0x00,0x07,0x80,0x07,0x75,0x03,0x80,
233
+ 0x11,0x92,0xfe,0x02,0xfd,0x01,0xfc,0x00,0xfd,0x7f,
234
+ 0xfe,0x7e,0x00,0x7e,0x01,0x7e,0x01,0x7f,0x02,0x7f,
235
+ 0x06,0x7e,0x02,0x7f,0x01,0x7f,0x01,0x7e,0x00,0x7d,
236
+ 0xfe,0x7e,0xfd,0x7f,0xfc,0x00,0xfd,0x01,0xfe,0x02,
237
+ 0x11,0xfd,0x08,0x95,0x00,0x6b,0xf9,0x95,0x0e,0x00,
238
+ 0x01,0xeb,0x04,0x95,0x00,0x71,0x01,0x7d,0x02,0x7e,
239
+ 0x03,0x7f,0x02,0x00,0x03,0x01,0x02,0x02,0x01,0x03,
240
+ 0x00,0x0f,0x04,0xeb,0x01,0x95,0x08,0x6b,0x08,0x95,
241
+ 0xf8,0x6b,0x09,0x80,0x02,0x95,0x05,0x6b,0x05,0x95,
242
+ 0xfb,0x6b,0x05,0x95,0x05,0x6b,0x05,0x95,0xfb,0x6b,
243
+ 0x07,0x80,0x03,0x95,0x0e,0x6b,0x00,0x95,0xf2,0x6b,
244
+ 0x11,0x80,0x01,0x95,0x08,0x76,0x00,0x75,0x08,0x95,
245
+ 0xf8,0x76,0x09,0xf5,0x11,0x95,0xf2,0x6b,0x00,0x95,
246
+ 0x0e,0x00,0xf2,0xeb,0x0e,0x00,0x03,0x80,0x03,0x93,
247
+ 0x00,0x6c,0x01,0x94,0x00,0x6c,0xff,0x94,0x05,0x00,
248
+ 0xfb,0xec,0x05,0x00,0x02,0x81,0x00,0x95,0x0e,0x68,
249
+ 0x00,0x83,0x06,0x93,0x00,0x6c,0x01,0x94,0x00,0x6c,
250
+ 0xfb,0x94,0x05,0x00,0xfb,0xec,0x05,0x00,0x03,0x81,
251
+ 0x03,0x87,0x08,0x05,0x08,0x7b,0xf0,0x80,0x08,0x04,
252
+ 0x08,0x7c,0x03,0xf9,0x01,0x80,0x10,0x00,0x01,0x80,
253
+ 0x06,0x95,0xff,0x7f,0xff,0x7e,0x00,0x7e,0x01,0x7f,
254
+ 0x01,0x01,0xff,0x01,0x05,0xef,0x0f,0x8e,0x00,0x72,
255
+ 0x00,0x8b,0xfe,0x02,0xfe,0x01,0xfd,0x00,0xfe,0x7f,
256
+ 0xfe,0x7e,0xff,0x7d,0x00,0x7e,0x01,0x7d,0x02,0x7e,
257
+ 0x02,0x7f,0x03,0x00,0x02,0x01,0x02,0x02,0x04,0xfd,
258
+ 0x04,0x95,0x00,0x6b,0x00,0x8b,0x02,0x02,0x02,0x01,
259
+ 0x03,0x00,0x02,0x7f,0x02,0x7e,0x01,0x7d,0x00,0x7e,
260
+ 0xff,0x7d,0xfe,0x7e,0xfe,0x7f,0xfd,0x00,0xfe,0x01,
261
+ 0xfe,0x02,0x0f,0xfd,0x0f,0x8b,0xfe,0x02,0xfe,0x01,
262
+ 0xfd,0x00,0xfe,0x7f,0xfe,0x7e,0xff,0x7d,0x00,0x7e,
263
+ 0x01,0x7d,0x02,0x7e,0x02,0x7f,0x03,0x00,0x02,0x01,
264
+ 0x02,0x02,0x03,0xfd,0x0f,0x95,0x00,0x6b,0x00,0x8b,
265
+ 0xfe,0x02,0xfe,0x01,0xfd,0x00,0xfe,0x7f,0xfe,0x7e,
266
+ 0xff,0x7d,0x00,0x7e,0x01,0x7d,0x02,0x7e,0x02,0x7f,
267
+ 0x03,0x00,0x02,0x01,0x02,0x02,0x04,0xfd,0x03,0x88,
268
+ 0x0c,0x00,0x00,0x02,0xff,0x02,0xff,0x01,0xfe,0x01,
269
+ 0xfd,0x00,0xfe,0x7f,0xfe,0x7e,0xff,0x7d,0x00,0x7e,
270
+ 0x01,0x7d,0x02,0x7e,0x02,0x7f,0x03,0x00,0x02,0x01,
271
+ 0x02,0x02,0x03,0xfd,0x0a,0x95,0xfe,0x00,0xfe,0x7f,
272
+ 0xff,0x7d,0x00,0x6f,0xfd,0x8e,0x07,0x00,0x03,0xf2,
273
+ 0x0f,0x8e,0x00,0x70,0xff,0x7d,0xff,0x7f,0xfe,0x7f,
274
+ 0xfd,0x00,0xfe,0x01,0x09,0x91,0xfe,0x02,0xfe,0x01,
275
+ 0xfd,0x00,0xfe,0x7f,0xfe,0x7e,0xff,0x7d,0x00,0x7e,
276
+ 0x01,0x7d,0x02,0x7e,0x02,0x7f,0x03,0x00,0x02,0x01,
277
+ 0x02,0x02,0x04,0xfd,0x04,0x95,0x00,0x6b,0x00,0x8a,
278
+ 0x03,0x03,0x02,0x01,0x03,0x00,0x02,0x7f,0x01,0x7d,
279
+ 0x00,0x76,0x04,0x80,0x03,0x95,0x01,0x7f,0x01,0x01,
280
+ 0xff,0x01,0xff,0x7f,0x01,0xf9,0x00,0x72,0x04,0x80,
281
+ 0x05,0x95,0x01,0x7f,0x01,0x01,0xff,0x01,0xff,0x7f,
282
+ 0x01,0xf9,0x00,0x6f,0xff,0x7d,0xfe,0x7f,0xfe,0x00,
283
+ 0x09,0x87,0x04,0x95,0x00,0x6b,0x0a,0x8e,0xf6,0x76,
284
+ 0x04,0x84,0x07,0x78,0x02,0x80,0x04,0x95,0x00,0x6b,
285
+ 0x04,0x80,0x04,0x8e,0x00,0x72,0x00,0x8a,0x03,0x03,
286
+ 0x02,0x01,0x03,0x00,0x02,0x7f,0x01,0x7d,0x00,0x76,
287
+ 0x00,0x8a,0x03,0x03,0x02,0x01,0x03,0x00,0x02,0x7f,
288
+ 0x01,0x7d,0x00,0x76,0x04,0x80,0x04,0x8e,0x00,0x72,
289
+ 0x00,0x8a,0x03,0x03,0x02,0x01,0x03,0x00,0x02,0x7f,
290
+ 0x01,0x7d,0x00,0x76,0x04,0x80,0x08,0x8e,0xfe,0x7f,
291
+ 0xfe,0x7e,0xff,0x7d,0x00,0x7e,0x01,0x7d,0x02,0x7e,
292
+ 0x02,0x7f,0x03,0x00,0x02,0x01,0x02,0x02,0x01,0x03,
293
+ 0x00,0x02,0xff,0x03,0xfe,0x02,0xfe,0x01,0xfd,0x00,
294
+ 0x0b,0xf2,0x04,0x8e,0x00,0x6b,0x00,0x92,0x02,0x02,
295
+ 0x02,0x01,0x03,0x00,0x02,0x7f,0x02,0x7e,0x01,0x7d,
296
+ 0x00,0x7e,0xff,0x7d,0xfe,0x7e,0xfe,0x7f,0xfd,0x00,
297
+ 0xfe,0x01,0xfe,0x02,0x0f,0xfd,0x0f,0x8e,0x00,0x6b,
298
+ 0x00,0x92,0xfe,0x02,0xfe,0x01,0xfd,0x00,0xfe,0x7f,
299
+ 0xfe,0x7e,0xff,0x7d,0x00,0x7e,0x01,0x7d,0x02,0x7e,
300
+ 0x02,0x7f,0x03,0x00,0x02,0x01,0x02,0x02,0x04,0xfd,
301
+ 0x04,0x8e,0x00,0x72,0x00,0x88,0x01,0x03,0x02,0x02,
302
+ 0x02,0x01,0x03,0x00,0x01,0xf2,0x0e,0x8b,0xff,0x02,
303
+ 0xfd,0x01,0xfd,0x00,0xfd,0x7f,0xff,0x7e,0x01,0x7e,
304
+ 0x02,0x7f,0x05,0x7f,0x02,0x7f,0x01,0x7e,0x00,0x7f,
305
+ 0xff,0x7e,0xfd,0x7f,0xfd,0x00,0xfd,0x01,0xff,0x02,
306
+ 0x0e,0xfd,0x05,0x95,0x00,0x6f,0x01,0x7d,0x02,0x7f,
307
+ 0x02,0x00,0xf8,0x8e,0x07,0x00,0x03,0xf2,0x04,0x8e,
308
+ 0x00,0x76,0x01,0x7d,0x02,0x7f,0x03,0x00,0x02,0x01,
309
+ 0x03,0x03,0x00,0x8a,0x00,0x72,0x04,0x80,0x02,0x8e,
310
+ 0x06,0x72,0x06,0x8e,0xfa,0x72,0x08,0x80,0x03,0x8e,
311
+ 0x04,0x72,0x04,0x8e,0xfc,0x72,0x04,0x8e,0x04,0x72,
312
+ 0x04,0x8e,0xfc,0x72,0x07,0x80,0x03,0x8e,0x0b,0x72,
313
+ 0x00,0x8e,0xf5,0x72,0x0e,0x80,0x02,0x8e,0x06,0x72,
314
+ 0x06,0x8e,0xfa,0x72,0xfe,0x7c,0xfe,0x7e,0xfe,0x7f,
315
+ 0xff,0x00,0x0f,0x87,0x0e,0x8e,0xf5,0x72,0x00,0x8e,
316
+ 0x0b,0x00,0xf5,0xf2,0x0b,0x00,0x03,0x80,0x09,0x99,
317
+ 0xfe,0x7f,0xff,0x7f,0xff,0x7e,0x00,0x7e,0x01,0x7e,
318
+ 0x01,0x7f,0x01,0x7e,0x00,0x7e,0xfe,0x7e,0x01,0x8e,
319
+ 0xff,0x7e,0x00,0x7e,0x01,0x7e,0x01,0x7f,0x01,0x7e,
320
+ 0x00,0x7e,0xff,0x7e,0xfc,0x7e,0x04,0x7e,0x01,0x7e,
321
+ 0x00,0x7e,0xff,0x7e,0xff,0x7f,0xff,0x7e,0x00,0x7e,
322
+ 0x01,0x7e,0xff,0x8e,0x02,0x7e,0x00,0x7e,0xff,0x7e,
323
+ 0xff,0x7f,0xff,0x7e,0x00,0x7e,0x01,0x7e,0x01,0x7f,
324
+ 0x02,0x7f,0x05,0x87,0x04,0x95,0x00,0x77,0x00,0xfd,
325
+ 0x00,0x77,0x04,0x80,0x05,0x99,0x02,0x7f,0x01,0x7f,
326
+ 0x01,0x7e,0x00,0x7e,0xff,0x7e,0xff,0x7f,0xff,0x7e,
327
+ 0x00,0x7e,0x02,0x7e,0xff,0x8e,0x01,0x7e,0x00,0x7e,
328
+ 0xff,0x7e,0xff,0x7f,0xff,0x7e,0x00,0x7e,0x01,0x7e,
329
+ 0x04,0x7e,0xfc,0x7e,0xff,0x7e,0x00,0x7e,0x01,0x7e,
330
+ 0x01,0x7f,0x01,0x7e,0x00,0x7e,0xff,0x7e,0x01,0x8e,
331
+ 0xfe,0x7e,0x00,0x7e,0x01,0x7e,0x01,0x7f,0x01,0x7e,
332
+ 0x00,0x7e,0xff,0x7e,0xff,0x7f,0xfe,0x7f,0x09,0x87,
333
+ 0x03,0x86,0x00,0x02,0x01,0x03,0x02,0x01,0x02,0x00,
334
+ 0x02,0x7f,0x04,0x7d,0x02,0x7f,0x02,0x00,0x02,0x01,
335
+ 0x01,0x02,0xee,0xfe,0x01,0x02,0x02,0x01,0x02,0x00,
336
+ 0x02,0x7f,0x04,0x7d,0x02,0x7f,0x02,0x00,0x02,0x01,
337
+ 0x01,0x03,0x00,0x02,0x03,0xf4,0x10,0x80,0x03,0x80,
338
+ 0x07,0x15,0x08,0x6b,0xfe,0x85,0xf5,0x00,0x10,0xfb,
339
+ 0x0d,0x95,0xf6,0x00,0x00,0x6b,0x0a,0x00,0x02,0x02,
340
+ 0x00,0x08,0xfe,0x02,0xf6,0x00,0x0e,0xf4,0x03,0x80,
341
+ 0x00,0x15,0x0a,0x00,0x02,0x7e,0x00,0x7e,0x00,0x7d,
342
+ 0x00,0x7e,0xfe,0x7f,0xf6,0x00,0x0a,0x80,0x02,0x7e,
343
+ 0x01,0x7e,0x00,0x7d,0xff,0x7d,0xfe,0x7f,0xf6,0x00,
344
+ 0x10,0x80,0x03,0x80,0x00,0x15,0x0c,0x00,0xff,0x7e,
345
+ 0x03,0xed,0x03,0xfd,0x00,0x03,0x02,0x00,0x00,0x12,
346
+ 0x02,0x03,0x0a,0x00,0x00,0x6b,0x02,0x00,0x00,0x7d,
347
+ 0xfe,0x83,0xf4,0x00,0x11,0x80,0x0f,0x80,0xf4,0x00,
348
+ 0x00,0x15,0x0c,0x00,0xff,0xf6,0xf5,0x00,0x0f,0xf5,
349
+ 0x04,0x95,0x07,0x76,0x00,0x0a,0x07,0x80,0xf9,0x76,
350
+ 0x00,0x75,0xf8,0x80,0x07,0x0c,0x09,0xf4,0xf9,0x0c,
351
+ 0x09,0xf4,0x03,0x92,0x02,0x03,0x07,0x00,0x03,0x7d,
352
+ 0x00,0x7b,0xfc,0x7e,0x04,0x7d,0x00,0x7a,0xfd,0x7e,
353
+ 0xf9,0x00,0xfe,0x02,0x06,0x89,0x02,0x00,0x06,0xf5,
354
+ 0x03,0x95,0x00,0x6b,0x0c,0x15,0x00,0x6b,0x02,0x80,
355
+ 0x03,0x95,0x00,0x6b,0x0c,0x15,0x00,0x6b,0xf8,0x96,
356
+ 0x03,0x00,0x07,0xea,0x03,0x80,0x00,0x15,0x0c,0x80,
357
+ 0xf7,0x76,0xfd,0x00,0x03,0x80,0x0a,0x75,0x03,0x80,
358
+ 0x03,0x80,0x07,0x13,0x02,0x02,0x03,0x00,0x00,0x6b,
359
+ 0x02,0x80,0x03,0x80,0x00,0x15,0x09,0x6b,0x09,0x15,
360
+ 0x00,0x6b,0x03,0x80,0x03,0x80,0x00,0x15,0x00,0xf6,
361
+ 0x0d,0x00,0x00,0x8a,0x00,0x6b,0x03,0x80,0x07,0x80,
362
+ 0xfd,0x00,0xff,0x03,0x00,0x04,0x00,0x07,0x00,0x04,
363
+ 0x01,0x02,0x03,0x01,0x06,0x00,0x03,0x7f,0x01,0x7e,
364
+ 0x01,0x7c,0x00,0x79,0xff,0x7c,0xff,0x7d,0xfd,0x00,
365
+ 0xfa,0x00,0x0e,0x80,0x03,0x80,0x00,0x15,0x0c,0x00,
366
+ 0x00,0x6b,0x02,0x80,0x03,0x80,0x00,0x15,0x0a,0x00,
367
+ 0x02,0x7f,0x01,0x7d,0x00,0x7b,0xff,0x7e,0xfe,0x7f,
368
+ 0xf6,0x00,0x10,0xf7,0x11,0x8f,0xff,0x03,0xff,0x02,
369
+ 0xfe,0x01,0xfa,0x00,0xfd,0x7f,0xff,0x7e,0x00,0x7c,
370
+ 0x00,0x79,0x00,0x7b,0x01,0x7e,0x03,0x00,0x06,0x00,
371
+ 0x02,0x00,0x01,0x03,0x01,0x02,0x03,0xfb,0x03,0x95,
372
+ 0x0c,0x00,0xfa,0x80,0x00,0x6b,0x09,0x80,0x03,0x95,
373
+ 0x00,0x77,0x06,0x7a,0x06,0x06,0x00,0x09,0xfa,0xf1,
374
+ 0xfa,0x7a,0x0e,0x80,0x03,0x87,0x00,0x0b,0x02,0x02,
375
+ 0x03,0x00,0x02,0x7e,0x01,0x02,0x04,0x00,0x02,0x7e,
376
+ 0x00,0x75,0xfe,0x7e,0xfc,0x00,0xff,0x01,0xfe,0x7f,
377
+ 0xfd,0x00,0xfe,0x02,0x07,0x8e,0x00,0x6b,0x09,0x80,
378
+ 0x03,0x80,0x0e,0x15,0xf2,0x80,0x0e,0x6b,0x03,0x80,
379
+ 0x03,0x95,0x00,0x6b,0x0e,0x00,0x00,0x7d,0xfe,0x98,
380
+ 0x00,0x6b,0x05,0x80,0x03,0x95,0x00,0x75,0x02,0x7d,
381
+ 0x0a,0x00,0x00,0x8e,0x00,0x6b,0x02,0x80,0x03,0x95,
382
+ 0x00,0x6b,0x10,0x00,0x00,0x15,0xf8,0x80,0x00,0x6b,
383
+ 0x0a,0x80,0x03,0x95,0x00,0x6b,0x10,0x00,0x00,0x15,
384
+ 0xf8,0x80,0x00,0x6b,0x0a,0x00,0x00,0x7d,0x02,0x83,
385
+ 0x10,0x80,0x03,0x95,0x00,0x6b,0x09,0x00,0x03,0x02,
386
+ 0x00,0x08,0xfd,0x02,0xf7,0x00,0x0e,0x89,0x00,0x6b,
387
+ 0x03,0x80,0x03,0x95,0x00,0x6b,0x09,0x00,0x03,0x02,
388
+ 0x00,0x08,0xfd,0x02,0xf7,0x00,0x0e,0xf4,0x03,0x92,
389
+ 0x02,0x03,0x07,0x00,0x03,0x7d,0x00,0x70,0xfd,0x7e,
390
+ 0xf9,0x00,0xfe,0x02,0x03,0x89,0x09,0x00,0x02,0xf5,
391
+ 0x03,0x80,0x00,0x15,0x00,0xf5,0x07,0x00,0x00,0x08,
392
+ 0x02,0x03,0x06,0x00,0x02,0x7d,0x00,0x70,0xfe,0x7e,
393
+ 0xfa,0x00,0xfe,0x02,0x00,0x08,0x0c,0xf6,0x0f,0x80,
394
+ 0x00,0x15,0xf6,0x00,0xfe,0x7d,0x00,0x79,0x02,0x7e,
395
+ 0x0a,0x00,0xf4,0xf7,0x07,0x09,0x07,0xf7,0x03,0x8c,
396
+ 0x01,0x02,0x01,0x01,0x05,0x00,0x02,0x7f,0x01,0x7e,
397
+ 0x00,0x74,0x00,0x86,0xff,0x01,0xfe,0x01,0xfb,0x00,
398
+ 0xff,0x7f,0xff,0x7f,0x00,0x7c,0x01,0x7e,0x01,0x00,
399
+ 0x05,0x00,0x02,0x00,0x01,0x02,0x03,0xfe,0x04,0x8e,
400
+ 0x02,0x01,0x04,0x00,0x02,0x7f,0x01,0x7e,0x00,0x77,
401
+ 0xff,0x7e,0xfe,0x7f,0xfc,0x00,0xfe,0x01,0xff,0x02,
402
+ 0x00,0x09,0x01,0x02,0x02,0x02,0x03,0x01,0x02,0x01,
403
+ 0x01,0x01,0x01,0x02,0x02,0xeb,0x03,0x80,0x00,0x15,
404
+ 0x03,0x00,0x02,0x7e,0x00,0x7b,0xfe,0x7e,0xfd,0x00,
405
+ 0x03,0x80,0x04,0x00,0x03,0x7e,0x00,0x78,0xfd,0x7e,
406
+ 0xf9,0x00,0x0c,0x80,0x03,0x8c,0x02,0x02,0x02,0x01,
407
+ 0x03,0x00,0x02,0x7f,0x01,0x7d,0xfe,0x7e,0xf9,0x7d,
408
+ 0xff,0x7e,0x00,0x7d,0x03,0x7f,0x02,0x00,0x03,0x01,
409
+ 0x02,0x01,0x02,0xfe,0x0d,0x8c,0xff,0x02,0xfe,0x01,
410
+ 0xfc,0x00,0xfe,0x7f,0xff,0x7e,0x00,0x77,0x01,0x7e,
411
+ 0x02,0x7f,0x04,0x00,0x02,0x01,0x01,0x02,0x00,0x0f,
412
+ 0xff,0x02,0xfe,0x01,0xf9,0x00,0x0c,0xeb,0x03,0x88,
413
+ 0x0a,0x00,0x00,0x02,0x00,0x03,0xfe,0x02,0xfa,0x00,
414
+ 0xff,0x7e,0xff,0x7d,0x00,0x7b,0x01,0x7c,0x01,0x7f,
415
+ 0x06,0x00,0x02,0x02,0x03,0xfe,0x03,0x8f,0x06,0x77,
416
+ 0x06,0x09,0xfa,0x80,0x00,0x71,0xff,0x87,0xfb,0x79,
417
+ 0x07,0x87,0x05,0x79,0x02,0x80,0x03,0x8d,0x02,0x02,
418
+ 0x06,0x00,0x02,0x7e,0x00,0x7d,0xfc,0x7d,0x04,0x7e,
419
+ 0x00,0x7d,0xfe,0x7e,0xfa,0x00,0xfe,0x02,0x04,0x85,
420
+ 0x02,0x00,0x06,0xf9,0x03,0x8f,0x00,0x73,0x01,0x7e,
421
+ 0x07,0x00,0x02,0x02,0x00,0x0d,0x00,0xf3,0x01,0x7e,
422
+ 0x03,0x80,0x03,0x8f,0x00,0x73,0x01,0x7e,0x07,0x00,
423
+ 0x02,0x02,0x00,0x0d,0x00,0xf3,0x01,0x7e,0xf8,0x90,
424
+ 0x03,0x00,0x08,0xf0,0x03,0x80,0x00,0x15,0x00,0xf3,
425
+ 0x02,0x00,0x06,0x07,0xfa,0xf9,0x07,0x78,0x03,0x80,
426
+ 0x03,0x80,0x04,0x0c,0x02,0x03,0x04,0x00,0x00,0x71,
427
+ 0x02,0x80,0x03,0x80,0x00,0x0f,0x06,0x77,0x06,0x09,
428
+ 0x00,0x71,0x02,0x80,0x03,0x80,0x00,0x0f,0x0a,0xf1,
429
+ 0x00,0x0f,0xf6,0xf8,0x0a,0x00,0x02,0xf9,0x05,0x80,
430
+ 0xff,0x01,0xff,0x04,0x00,0x05,0x01,0x03,0x01,0x02,
431
+ 0x06,0x00,0x02,0x7e,0x00,0x7d,0x00,0x7b,0x00,0x7c,
432
+ 0xfe,0x7f,0xfa,0x00,0x0b,0x80,0x03,0x80,0x00,0x0f,
433
+ 0x00,0xfb,0x01,0x03,0x01,0x02,0x05,0x00,0x02,0x7e,
434
+ 0x01,0x7d,0x00,0x76,0x03,0x80,0x10,0x80,0x10,0x80,
435
+ 0x10,0x80,0x10,0x80,0x10,0x80,0x10,0x80,0x10,0x80,
436
+ 0x10,0x80,0x10,0x80,0x10,0x80,0x10,0x80,0x10,0x80,
437
+ 0x10,0x80,0x10,0x80,0x10,0x80,0x10,0x80,0x10,0x80,
438
+ 0x10,0x80,0x10,0x80,0x10,0x80,0x10,0x80,0x10,0x80,
439
+ 0x10,0x80,0x10,0x80,0x10,0x80,0x10,0x80,0x10,0x80,
440
+ 0x10,0x80,0x10,0x80,0x10,0x80,0x10,0x80,0x10,0x80,
441
+ 0x10,0x80,0x10,0x80,0x10,0x80,0x10,0x80,0x10,0x80,
442
+ 0x10,0x80,0x10,0x80,0x10,0x80,0x10,0x80,0x10,0x80,
443
+ 0x10,0x80,0x10,0x80,0x10,0x80,0x10,0x80,0x10,0x80,
444
+ 0x10,0x80,0x0a,0x8f,0x02,0x7f,0x01,0x7e,0x00,0x76,
445
+ 0xff,0x7f,0xfe,0x7f,0xfb,0x00,0xff,0x01,0xff,0x01,
446
+ 0x00,0x0a,0x01,0x02,0x01,0x01,0x05,0x00,0xf9,0x80,
447
+ 0x00,0x6b,0x0c,0x86,0x0d,0x8a,0xff,0x03,0xfe,0x02,
448
+ 0xfb,0x00,0xff,0x7e,0xff,0x7d,0x00,0x7b,0x01,0x7c,
449
+ 0x01,0x7f,0x05,0x00,0x02,0x01,0x01,0x03,0x03,0xfc,
450
+ 0x03,0x80,0x00,0x0f,0x00,0xfb,0x01,0x03,0x01,0x02,
451
+ 0x04,0x00,0x01,0x7e,0x01,0x7d,0x00,0x76,0x00,0x8a,
452
+ 0x01,0x03,0x02,0x02,0x03,0x00,0x02,0x7e,0x01,0x7d,
453
+ 0x00,0x76,0x03,0x80,0x03,0x8f,0x00,0x74,0x01,0x7e,
454
+ 0x02,0x7f,0x04,0x00,0x02,0x01,0x01,0x01,0x00,0x8d,
455
+ 0x00,0x6e,0xff,0x7e,0xfe,0x7f,0xfb,0x00,0xfe,0x01,
456
+ 0x0c,0x85,0x03,0x8d,0x01,0x02,0x03,0x00,0x02,0x7e,
457
+ 0x01,0x02,0x03,0x00,0x02,0x7e,0x00,0x74,0xfe,0x7f,
458
+ 0xfd,0x00,0xff,0x01,0xfe,0x7f,0xfd,0x00,0xff,0x01,
459
+ 0x00,0x0c,0x06,0x82,0x00,0x6b,0x08,0x86,0x03,0x80,
460
+ 0x0a,0x0f,0xf6,0x80,0x0a,0x71,0x03,0x80,0x03,0x8f,
461
+ 0x00,0x73,0x01,0x7e,0x07,0x00,0x02,0x02,0x00,0x0d,
462
+ 0x00,0xf3,0x01,0x7e,0x00,0x7e,0x03,0x82,0x03,0x8f,
463
+ 0x00,0x79,0x02,0x7e,0x08,0x00,0x00,0x89,0x00,0x71,
464
+ 0x02,0x80,0x03,0x8f,0x00,0x73,0x01,0x7e,0x03,0x00,
465
+ 0x02,0x02,0x00,0x0d,0x00,0xf3,0x01,0x7e,0x03,0x00,
466
+ 0x02,0x02,0x00,0x0d,0x00,0xf3,0x01,0x7e,0x03,0x80,
467
+ 0x03,0x8f,0x00,0x73,0x01,0x7e,0x03,0x00,0x02,0x02,
468
+ 0x00,0x0d,0x00,0xf3,0x01,0x7e,0x03,0x00,0x02,0x02,
469
+ 0x00,0x0d,0x00,0xf3,0x01,0x7e,0x00,0x7e,0x03,0x82,
470
+ 0x03,0x8d,0x00,0x02,0x02,0x00,0x00,0x71,0x08,0x00,
471
+ 0x02,0x02,0x00,0x06,0xfe,0x02,0xf8,0x00,0x0c,0xf6,
472
+ 0x03,0x8f,0x00,0x71,0x07,0x00,0x02,0x02,0x00,0x06,
473
+ 0xfe,0x02,0xf9,0x00,0x0c,0x85,0x00,0x71,0x02,0x80,
474
+ 0x03,0x8f,0x00,0x71,0x07,0x00,0x03,0x02,0x00,0x06,
475
+ 0xfd,0x02,0xf9,0x00,0x0c,0xf6,0x03,0x8d,0x02,0x02,
476
+ 0x06,0x00,0x02,0x7e,0x00,0x75,0xfe,0x7e,0xfa,0x00,
477
+ 0xfe,0x02,0x04,0x85,0x06,0x00,0x02,0xf9,0x03,0x80,
478
+ 0x00,0x0f,0x00,0xf8,0x04,0x00,0x00,0x06,0x02,0x02,
479
+ 0x04,0x00,0x02,0x7e,0x00,0x75,0xfe,0x7e,0xfc,0x00,
480
+ 0xfe,0x02,0x00,0x05,0x0a,0xf9,0x0d,0x80,0x00,0x0f,
481
+ 0xf7,0x00,0xff,0x7e,0x00,0x7b,0x01,0x7e,0x09,0x00,
482
+ 0xf6,0xfa,0x04,0x06,0x08,0xfa
483
+ };
484
+
485
+ //-------------------------------------------------------------------------
486
+ gsv_text::gsv_text() :
487
+ m_x(0.0),
488
+ m_y(0.0),
489
+ m_start_x(0.0),
490
+ m_width(10.0),
491
+ m_height(0.0),
492
+ m_space(0.0),
493
+ m_line_space(0.0),
494
+ m_text(m_chr),
495
+ m_text_buf(),
496
+ m_cur_chr(m_chr),
497
+ m_font(gsv_default_font),
498
+ m_loaded_font(),
499
+ m_status(initial),
500
+ m_big_endian(false),
501
+ m_flip(false)
502
+ {
503
+ m_chr[0] = m_chr[1] = 0;
504
+
505
+ int t = 1;
506
+ if(*(char*)&t == 0) m_big_endian = true;
507
+ }
508
+
509
+ //-------------------------------------------------------------------------
510
+ void gsv_text::font(const void* font)
511
+ {
512
+ m_font = font;
513
+ if(m_font == 0) m_font = &m_loaded_font[0];
514
+ }
515
+
516
+ //-------------------------------------------------------------------------
517
+ void gsv_text::size(double height, double width)
518
+ {
519
+ m_height = height;
520
+ m_width = width;
521
+ }
522
+
523
+ //-------------------------------------------------------------------------
524
+ void gsv_text::space(double space)
525
+ {
526
+ m_space = space;
527
+ }
528
+
529
+ //-------------------------------------------------------------------------
530
+ void gsv_text::line_space(double line_space)
531
+ {
532
+ m_line_space = line_space;
533
+ }
534
+
535
+ //-------------------------------------------------------------------------
536
+ void gsv_text::start_point(double x, double y)
537
+ {
538
+ m_x = m_start_x = x;
539
+ m_y = y;
540
+ //if(m_flip) m_y += m_height;
541
+ }
542
+
543
+ //-------------------------------------------------------------------------
544
+ void gsv_text::load_font(const char* file)
545
+ {
546
+ m_loaded_font.resize(0);
547
+ FILE* fd = fopen(file, "rb");
548
+ if(fd)
549
+ {
550
+ unsigned len;
551
+
552
+ fseek(fd, 0l, SEEK_END);
553
+ len = ftell(fd);
554
+ fseek(fd, 0l, SEEK_SET);
555
+ if(len > 0)
556
+ {
557
+ m_loaded_font.resize(len);
558
+ fread(&m_loaded_font[0], 1, len, fd);
559
+ m_font = &m_loaded_font[0];
560
+ }
561
+ fclose(fd);
562
+ }
563
+ }
564
+
565
+ //-------------------------------------------------------------------------
566
+ void gsv_text::text(const char* text)
567
+ {
568
+ if(text == 0)
569
+ {
570
+ m_chr[0] = 0;
571
+ m_text = m_chr;
572
+ return;
573
+ }
574
+ unsigned new_size = strlen(text) + 1;
575
+ if(new_size > m_text_buf.size())
576
+ {
577
+ m_text_buf.resize(new_size);
578
+ }
579
+ memcpy(&m_text_buf[0], text, new_size);
580
+ m_text = &m_text_buf[0];
581
+ }
582
+
583
+ //-------------------------------------------------------------------------
584
+ void gsv_text::rewind(unsigned)
585
+ {
586
+ m_status = initial;
587
+ if(m_font == 0) return;
588
+
589
+ m_indices = (int8u*)m_font;
590
+ double base_height = value(m_indices + 4);
591
+ m_indices += value(m_indices);
592
+ m_glyphs = (int8*)(m_indices + 257*2);
593
+ m_h = m_height / base_height;
594
+ m_w = (m_width == 0.0) ? m_h : m_width / base_height;
595
+ if(m_flip) m_h = -m_h;
596
+ m_cur_chr = m_text;
597
+ }
598
+
599
+ //-------------------------------------------------------------------------
600
+ unsigned gsv_text::vertex(double* x, double* y)
601
+ {
602
+ unsigned idx;
603
+ int8 yc, yf;
604
+ int dx, dy;
605
+ bool quit = false;
606
+
607
+ while(!quit)
608
+ {
609
+ switch(m_status)
610
+ {
611
+ case initial:
612
+ if(m_font == 0)
613
+ {
614
+ quit = true;
615
+ break;
616
+ }
617
+ m_status = next_char;
618
+
619
+ case next_char:
620
+ if(*m_cur_chr == 0)
621
+ {
622
+ quit = true;
623
+ break;
624
+ }
625
+ idx = (*m_cur_chr++) & 0xFF;
626
+ if(idx == '\n')
627
+ {
628
+ m_x = m_start_x;
629
+ m_y -= m_flip ? -m_height - m_line_space : m_height + m_line_space;
630
+ break;
631
+ }
632
+ idx <<= 1;
633
+ m_bglyph = m_glyphs + value(m_indices + idx);
634
+ m_eglyph = m_glyphs + value(m_indices + idx + 2);
635
+ m_status = start_glyph;
636
+
637
+ case start_glyph:
638
+ *x = m_x;
639
+ *y = m_y;
640
+ m_status = glyph;
641
+ return path_cmd_move_to;
642
+
643
+ case glyph:
644
+ if(m_bglyph >= m_eglyph)
645
+ {
646
+ m_status = next_char;
647
+ m_x += m_space;
648
+ break;
649
+ }
650
+ dx = int(*m_bglyph++);
651
+ yf = (yc = *m_bglyph++) & 0x80;
652
+ yc <<= 1;
653
+ yc >>= 1;
654
+ dy = int(yc);
655
+ m_x += double(dx) * m_w;
656
+ m_y += double(dy) * m_h;
657
+ *x = m_x;
658
+ *y = m_y;
659
+ return yf ? path_cmd_move_to : path_cmd_line_to;
660
+ }
661
+
662
+ }
663
+ return path_cmd_stop;
664
+ }
665
+
666
+ //-------------------------------------------------------------------------
667
+ double gsv_text::text_width()
668
+ {
669
+ double x1, y1, x2, y2;
670
+ bounding_rect_single(*this, 0, &x1, &y1, &x2, &y2);
671
+ return x2 - x1;
672
+ }
673
+
674
+
675
+ }
testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_image_filters.cpp ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+ //
16
+ // Filtering class image_filter_lut implemantation
17
+ //
18
+ //----------------------------------------------------------------------------
19
+
20
+
21
+ #include "agg_image_filters.h"
22
+
23
+
24
+ namespace agg
25
+ {
26
+ //--------------------------------------------------------------------
27
+ void image_filter_lut::realloc_lut(double radius)
28
+ {
29
+ m_radius = radius;
30
+ m_diameter = uceil(radius) * 2;
31
+ m_start = -int(m_diameter / 2 - 1);
32
+ unsigned size = m_diameter << image_subpixel_shift;
33
+ if(size > m_weight_array.size())
34
+ {
35
+ m_weight_array.resize(size);
36
+ }
37
+ }
38
+
39
+
40
+
41
+ //--------------------------------------------------------------------
42
+ // This function normalizes integer values and corrects the rounding
43
+ // errors. It doesn't do anything with the source floating point values
44
+ // (m_weight_array_dbl), it corrects only integers according to the rule
45
+ // of 1.0 which means that any sum of pixel weights must be equal to 1.0.
46
+ // So, the filter function must produce a graph of the proper shape.
47
+ //--------------------------------------------------------------------
48
+ void image_filter_lut::normalize()
49
+ {
50
+ unsigned i;
51
+ int flip = 1;
52
+
53
+ for(i = 0; i < image_subpixel_scale; i++)
54
+ {
55
+ for(;;)
56
+ {
57
+ int sum = 0;
58
+ unsigned j;
59
+ for(j = 0; j < m_diameter; j++)
60
+ {
61
+ sum += m_weight_array[j * image_subpixel_scale + i];
62
+ }
63
+
64
+ if(sum == image_filter_scale) break;
65
+
66
+ double k = double(image_filter_scale) / double(sum);
67
+ sum = 0;
68
+ for(j = 0; j < m_diameter; j++)
69
+ {
70
+ sum += m_weight_array[j * image_subpixel_scale + i] =
71
+ iround(m_weight_array[j * image_subpixel_scale + i] * k);
72
+ }
73
+
74
+ sum -= image_filter_scale;
75
+ int inc = (sum > 0) ? -1 : 1;
76
+
77
+ for(j = 0; j < m_diameter && sum; j++)
78
+ {
79
+ flip ^= 1;
80
+ unsigned idx = flip ? m_diameter/2 + j/2 : m_diameter/2 - j/2;
81
+ int v = m_weight_array[idx * image_subpixel_scale + i];
82
+ if(v < image_filter_scale)
83
+ {
84
+ m_weight_array[idx * image_subpixel_scale + i] += inc;
85
+ sum += inc;
86
+ }
87
+ }
88
+ }
89
+ }
90
+
91
+ unsigned pivot = m_diameter << (image_subpixel_shift - 1);
92
+
93
+ for(i = 0; i < pivot; i++)
94
+ {
95
+ m_weight_array[pivot + i] = m_weight_array[pivot - i];
96
+ }
97
+ unsigned end = (diameter() << image_subpixel_shift) - 1;
98
+ m_weight_array[0] = m_weight_array[end];
99
+ }
100
+
101
+
102
+ }
103
+
testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_line_aa_basics.cpp ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+
16
+ #include <math.h>
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
+ // <M> 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
+ const int8u line_parameters::s_orthogonal_quadrant[8] = { 0,0,1,1,3,3,2,2 };
46
+ const 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_scale)
73
+ {
74
+ *x = (l2.x1 + l2.x1 + (l2.y1 - l1.y1) + (l2.y2 - l2.y1)) >> 1;
75
+ *y = (l2.y1 + l2.y1 - (l2.x1 - l1.x1) - (l2.x2 - l2.x1)) >> 1;
76
+ return;
77
+ }
78
+ *x = iround(tx);
79
+ *y = iround(ty);
80
+ }
81
+
82
+ }
testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_line_profile_aa.cpp ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+
16
+ #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 = uround(w * subpixel_scale);
46
+ unsigned size = m_subpixel_width + subpixel_scale * 6;
47
+ if(size > m_profile.size())
48
+ {
49
+ m_profile.resize(size);
50
+ }
51
+ return &m_profile[0];
52
+ }
53
+
54
+
55
+ //---------------------------------------------------------------------
56
+ void line_profile_aa::set(double center_width, double smoother_width)
57
+ {
58
+ double base_val = 1.0;
59
+ if(center_width == 0.0) center_width = 1.0 / subpixel_scale;
60
+ if(smoother_width == 0.0) smoother_width = 1.0 / subpixel_scale;
61
+
62
+ double width = center_width + smoother_width;
63
+ if(width < m_min_width)
64
+ {
65
+ double k = width / m_min_width;
66
+ base_val *= k;
67
+ center_width /= k;
68
+ smoother_width /= k;
69
+ }
70
+
71
+ value_type* ch = profile(center_width + smoother_width);
72
+
73
+ unsigned subpixel_center_width = unsigned(center_width * subpixel_scale);
74
+ unsigned subpixel_smoother_width = unsigned(smoother_width * subpixel_scale);
75
+
76
+ value_type* ch_center = ch + subpixel_scale*2;
77
+ value_type* ch_smoother = ch_center + subpixel_center_width;
78
+
79
+ unsigned i;
80
+
81
+ unsigned val = m_gamma[unsigned(base_val * aa_mask)];
82
+ ch = ch_center;
83
+ for(i = 0; i < subpixel_center_width; i++)
84
+ {
85
+ *ch++ = (value_type)val;
86
+ }
87
+
88
+ for(i = 0; i < subpixel_smoother_width; i++)
89
+ {
90
+ *ch_smoother++ =
91
+ m_gamma[unsigned((base_val -
92
+ base_val *
93
+ (double(i) / subpixel_smoother_width)) * aa_mask)];
94
+ }
95
+
96
+ unsigned n_smoother = profile_size() -
97
+ subpixel_smoother_width -
98
+ subpixel_center_width -
99
+ subpixel_scale*2;
100
+
101
+ val = m_gamma[0];
102
+ for(i = 0; i < n_smoother; i++)
103
+ {
104
+ *ch_smoother++ = (value_type)val;
105
+ }
106
+
107
+ ch = ch_center;
108
+ for(i = 0; i < subpixel_scale*2; i++)
109
+ {
110
+ *--ch = *ch_center++;
111
+ }
112
+ }
113
+
114
+
115
+ }
116
+
testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_rounded_rect.cpp ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+ //
16
+ // Rounded rectangle vertex generator
17
+ //
18
+ //----------------------------------------------------------------------------
19
+
20
+ #include <math.h>
21
+ #include "agg_rounded_rect.h"
22
+
23
+
24
+ namespace agg
25
+ {
26
+ //------------------------------------------------------------------------
27
+ rounded_rect::rounded_rect(double x1, double y1, double x2, double y2, double r) :
28
+ m_x1(x1), m_y1(y1), m_x2(x2), m_y2(y2),
29
+ m_rx1(r), m_ry1(r), m_rx2(r), m_ry2(r),
30
+ m_rx3(r), m_ry3(r), m_rx4(r), m_ry4(r)
31
+ {
32
+ if(x1 > x2) { m_x1 = x2; m_x2 = x1; }
33
+ if(y1 > y2) { m_y1 = y2; m_y2 = y1; }
34
+ }
35
+
36
+ //--------------------------------------------------------------------
37
+ void rounded_rect::rect(double x1, double y1, double x2, double y2)
38
+ {
39
+ m_x1 = x1;
40
+ m_y1 = y1;
41
+ m_x2 = x2;
42
+ m_y2 = y2;
43
+ if(x1 > x2) { m_x1 = x2; m_x2 = x1; }
44
+ if(y1 > y2) { m_y1 = y2; m_y2 = y1; }
45
+ }
46
+
47
+ //--------------------------------------------------------------------
48
+ void rounded_rect::radius(double r)
49
+ {
50
+ m_rx1 = m_ry1 = m_rx2 = m_ry2 = m_rx3 = m_ry3 = m_rx4 = m_ry4 = r;
51
+ }
52
+
53
+ //--------------------------------------------------------------------
54
+ void rounded_rect::radius(double rx, double ry)
55
+ {
56
+ m_rx1 = m_rx2 = m_rx3 = m_rx4 = rx;
57
+ m_ry1 = m_ry2 = m_ry3 = m_ry4 = ry;
58
+ }
59
+
60
+ //--------------------------------------------------------------------
61
+ void rounded_rect::radius(double rx_bottom, double ry_bottom,
62
+ double rx_top, double ry_top)
63
+ {
64
+ m_rx1 = m_rx2 = rx_bottom;
65
+ m_rx3 = m_rx4 = rx_top;
66
+ m_ry1 = m_ry2 = ry_bottom;
67
+ m_ry3 = m_ry4 = ry_top;
68
+ }
69
+
70
+ //--------------------------------------------------------------------
71
+ void rounded_rect::radius(double rx1, double ry1, double rx2, double ry2,
72
+ double rx3, double ry3, double rx4, double ry4)
73
+ {
74
+ m_rx1 = rx1; m_ry1 = ry1; m_rx2 = rx2; m_ry2 = ry2;
75
+ m_rx3 = rx3; m_ry3 = ry3; m_rx4 = rx4; m_ry4 = ry4;
76
+ }
77
+
78
+ //--------------------------------------------------------------------
79
+ void rounded_rect::normalize_radius()
80
+ {
81
+ double dx = fabs(m_y2 - m_y1);
82
+ double dy = fabs(m_x2 - m_x1);
83
+
84
+ double k = 1.0;
85
+ double t;
86
+ t = dx / (m_rx1 + m_rx2); if(t < k) k = t;
87
+ t = dx / (m_rx3 + m_rx4); if(t < k) k = t;
88
+ t = dy / (m_ry1 + m_ry2); if(t < k) k = t;
89
+ t = dy / (m_ry3 + m_ry4); if(t < k) k = t;
90
+
91
+ if(k < 1.0)
92
+ {
93
+ m_rx1 *= k; m_ry1 *= k; m_rx2 *= k; m_ry2 *= k;
94
+ m_rx3 *= k; m_ry3 *= k; m_rx4 *= k; m_ry4 *= k;
95
+ }
96
+ }
97
+
98
+ //--------------------------------------------------------------------
99
+ void rounded_rect::rewind(unsigned)
100
+ {
101
+ m_status = 0;
102
+ }
103
+
104
+ //--------------------------------------------------------------------
105
+ unsigned rounded_rect::vertex(double* x, double* y)
106
+ {
107
+ unsigned cmd = path_cmd_stop;
108
+ switch(m_status)
109
+ {
110
+ case 0:
111
+ m_arc.init(m_x1 + m_rx1, m_y1 + m_ry1, m_rx1, m_ry1,
112
+ pi, pi+pi*0.5);
113
+ m_arc.rewind(0);
114
+ m_status++;
115
+
116
+ case 1:
117
+ cmd = m_arc.vertex(x, y);
118
+ if(is_stop(cmd)) m_status++;
119
+ else return cmd;
120
+
121
+ case 2:
122
+ m_arc.init(m_x2 - m_rx2, m_y1 + m_ry2, m_rx2, m_ry2,
123
+ pi+pi*0.5, 0.0);
124
+ m_arc.rewind(0);
125
+ m_status++;
126
+
127
+ case 3:
128
+ cmd = m_arc.vertex(x, y);
129
+ if(is_stop(cmd)) m_status++;
130
+ else return path_cmd_line_to;
131
+
132
+ case 4:
133
+ m_arc.init(m_x2 - m_rx3, m_y2 - m_ry3, m_rx3, m_ry3,
134
+ 0.0, pi*0.5);
135
+ m_arc.rewind(0);
136
+ m_status++;
137
+
138
+ case 5:
139
+ cmd = m_arc.vertex(x, y);
140
+ if(is_stop(cmd)) m_status++;
141
+ else return path_cmd_line_to;
142
+
143
+ case 6:
144
+ m_arc.init(m_x1 + m_rx4, m_y2 - m_ry4, m_rx4, m_ry4,
145
+ pi*0.5, pi);
146
+ m_arc.rewind(0);
147
+ m_status++;
148
+
149
+ case 7:
150
+ cmd = m_arc.vertex(x, y);
151
+ if(is_stop(cmd)) m_status++;
152
+ else return path_cmd_line_to;
153
+
154
+ case 8:
155
+ cmd = path_cmd_end_poly | path_flags_close | path_flags_ccw;
156
+ m_status++;
157
+ break;
158
+ }
159
+ return cmd;
160
+ }
161
+
162
+
163
+ }
164
+
testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_sqrt_tables.cpp ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+ //
16
+ // static tables for fast integer sqrt
17
+ //
18
+ //----------------------------------------------------------------------------
19
+
20
+ #include "agg_basics.h"
21
+
22
+ namespace agg
23
+ {
24
+ int16u g_sqrt_table[1024] = //----------g_sqrt_table
25
+ {
26
+ 0,
27
+ 2048,2896,3547,4096,4579,5017,5418,5793,6144,6476,6792,7094,7384,7663,7932,8192,8444,
28
+ 8689,8927,9159,9385,9606,9822,10033,10240,10443,10642,10837,11029,11217,11403,11585,
29
+ 11765,11942,12116,12288,12457,12625,12790,12953,13114,13273,13430,13585,13738,13890,
30
+ 14040,14189,14336,14482,14626,14768,14910,15050,15188,15326,15462,15597,15731,15864,
31
+ 15995,16126,16255,16384,16512,16638,16764,16888,17012,17135,17257,17378,17498,17618,
32
+ 17736,17854,17971,18087,18203,18318,18432,18545,18658,18770,18882,18992,19102,19212,
33
+ 19321,19429,19537,19644,19750,19856,19961,20066,20170,20274,20377,20480,20582,20684,
34
+ 20785,20886,20986,21085,21185,21283,21382,21480,21577,21674,21771,21867,21962,22058,
35
+ 22153,22247,22341,22435,22528,22621,22713,22806,22897,22989,23080,23170,23261,23351,
36
+ 23440,23530,23619,23707,23796,23884,23971,24059,24146,24232,24319,24405,24491,24576,
37
+ 24661,24746,24831,24915,24999,25083,25166,25249,25332,25415,25497,25580,25661,25743,
38
+ 25824,25905,25986,26067,26147,26227,26307,26387,26466,26545,26624,26703,26781,26859,
39
+ 26937,27015,27092,27170,27247,27324,27400,27477,27553,27629,27705,27780,27856,27931,
40
+ 28006,28081,28155,28230,28304,28378,28452,28525,28599,28672,28745,28818,28891,28963,
41
+ 29035,29108,29180,29251,29323,29394,29466,29537,29608,29678,29749,29819,29890,29960,
42
+ 30030,30099,30169,30238,30308,30377,30446,30515,30583,30652,30720,30788,30856,30924,
43
+ 30992,31059,31127,31194,31261,31328,31395,31462,31529,31595,31661,31727,31794,31859,
44
+ 31925,31991,32056,32122,32187,32252,32317,32382,32446,32511,32575,32640,32704,32768,
45
+ 32832,32896,32959,33023,33086,33150,33213,33276,33339,33402,33465,33527,33590,33652,
46
+ 33714,33776,33839,33900,33962,34024,34086,34147,34208,34270,34331,34392,34453,34514,
47
+ 34574,34635,34695,34756,34816,34876,34936,34996,35056,35116,35176,35235,35295,35354,
48
+ 35413,35472,35531,35590,35649,35708,35767,35825,35884,35942,36001,36059,36117,36175,
49
+ 36233,36291,36348,36406,36464,36521,36578,36636,36693,36750,36807,36864,36921,36978,
50
+ 37034,37091,37147,37204,37260,37316,37372,37429,37485,37540,37596,37652,37708,37763,
51
+ 37819,37874,37929,37985,38040,38095,38150,38205,38260,38315,38369,38424,38478,38533,
52
+ 38587,38642,38696,38750,38804,38858,38912,38966,39020,39073,39127,39181,39234,39287,
53
+ 39341,39394,39447,39500,39553,39606,39659,39712,39765,39818,39870,39923,39975,40028,
54
+ 40080,40132,40185,40237,40289,40341,40393,40445,40497,40548,40600,40652,40703,40755,
55
+ 40806,40857,40909,40960,41011,41062,41113,41164,41215,41266,41317,41368,41418,41469,
56
+ 41519,41570,41620,41671,41721,41771,41821,41871,41922,41972,42021,42071,42121,42171,
57
+ 42221,42270,42320,42369,42419,42468,42518,42567,42616,42665,42714,42763,42813,42861,
58
+ 42910,42959,43008,43057,43105,43154,43203,43251,43300,43348,43396,43445,43493,43541,
59
+ 43589,43637,43685,43733,43781,43829,43877,43925,43972,44020,44068,44115,44163,44210,
60
+ 44258,44305,44352,44400,44447,44494,44541,44588,44635,44682,44729,44776,44823,44869,
61
+ 44916,44963,45009,45056,45103,45149,45195,45242,45288,45334,45381,45427,45473,45519,
62
+ 45565,45611,45657,45703,45749,45795,45840,45886,45932,45977,46023,46069,46114,46160,
63
+ 46205,46250,46296,46341,46386,46431,46477,46522,46567,46612,46657,46702,46746,46791,
64
+ 46836,46881,46926,46970,47015,47059,47104,47149,47193,47237,47282,47326,47370,47415,
65
+ 47459,47503,47547,47591,47635,47679,47723,47767,47811,47855,47899,47942,47986,48030,
66
+ 48074,48117,48161,48204,48248,48291,48335,48378,48421,48465,48508,48551,48594,48637,
67
+ 48680,48723,48766,48809,48852,48895,48938,48981,49024,49067,49109,49152,49195,49237,
68
+ 49280,49322,49365,49407,49450,49492,49535,49577,49619,49661,49704,49746,49788,49830,
69
+ 49872,49914,49956,49998,50040,50082,50124,50166,50207,50249,50291,50332,50374,50416,
70
+ 50457,50499,50540,50582,50623,50665,50706,50747,50789,50830,50871,50912,50954,50995,
71
+ 51036,51077,51118,51159,51200,51241,51282,51323,51364,51404,51445,51486,51527,51567,
72
+ 51608,51649,51689,51730,51770,51811,51851,51892,51932,51972,52013,52053,52093,52134,
73
+ 52174,52214,52254,52294,52334,52374,52414,52454,52494,52534,52574,52614,52654,52694,
74
+ 52734,52773,52813,52853,52892,52932,52972,53011,53051,53090,53130,53169,53209,53248,
75
+ 53287,53327,53366,53405,53445,53484,53523,53562,53601,53640,53679,53719,53758,53797,
76
+ 53836,53874,53913,53952,53991,54030,54069,54108,54146,54185,54224,54262,54301,54340,
77
+ 54378,54417,54455,54494,54532,54571,54609,54647,54686,54724,54762,54801,54839,54877,
78
+ 54915,54954,54992,55030,55068,55106,55144,55182,55220,55258,55296,55334,55372,55410,
79
+ 55447,55485,55523,55561,55599,55636,55674,55712,55749,55787,55824,55862,55900,55937,
80
+ 55975,56012,56049,56087,56124,56162,56199,56236,56273,56311,56348,56385,56422,56459,
81
+ 56497,56534,56571,56608,56645,56682,56719,56756,56793,56830,56867,56903,56940,56977,
82
+ 57014,57051,57087,57124,57161,57198,57234,57271,57307,57344,57381,57417,57454,57490,
83
+ 57527,57563,57599,57636,57672,57709,57745,57781,57817,57854,57890,57926,57962,57999,
84
+ 58035,58071,58107,58143,58179,58215,58251,58287,58323,58359,58395,58431,58467,58503,
85
+ 58538,58574,58610,58646,58682,58717,58753,58789,58824,58860,58896,58931,58967,59002,
86
+ 59038,59073,59109,59144,59180,59215,59251,59286,59321,59357,59392,59427,59463,59498,
87
+ 59533,59568,59603,59639,59674,59709,59744,59779,59814,59849,59884,59919,59954,59989,
88
+ 60024,60059,60094,60129,60164,60199,60233,60268,60303,60338,60373,60407,60442,60477,
89
+ 60511,60546,60581,60615,60650,60684,60719,60753,60788,60822,60857,60891,60926,60960,
90
+ 60995,61029,61063,61098,61132,61166,61201,61235,61269,61303,61338,61372,61406,61440,
91
+ 61474,61508,61542,61576,61610,61644,61678,61712,61746,61780,61814,61848,61882,61916,
92
+ 61950,61984,62018,62051,62085,62119,62153,62186,62220,62254,62287,62321,62355,62388,
93
+ 62422,62456,62489,62523,62556,62590,62623,62657,62690,62724,62757,62790,62824,62857,
94
+ 62891,62924,62957,62991,63024,63057,63090,63124,63157,63190,63223,63256,63289,63323,
95
+ 63356,63389,63422,63455,63488,63521,63554,63587,63620,63653,63686,63719,63752,63785,
96
+ 63817,63850,63883,63916,63949,63982,64014,64047,64080,64113,64145,64178,64211,64243,
97
+ 64276,64309,64341,64374,64406,64439,64471,64504,64536,64569,64601,64634,64666,64699,
98
+ 64731,64763,64796,64828,64861,64893,64925,64957,64990,65022,65054,65086,65119,65151,
99
+ 65183,65215,65247,65279,65312,65344,65376,65408,65440,65472,65504
100
+ };
101
+
102
+
103
+ int8 g_elder_bit_table[256] = //---------g_elder_bit_table
104
+ {
105
+ 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
106
+ 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
107
+ 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
108
+ 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
109
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
110
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
111
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
112
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
113
+ };
114
+
115
+ }
testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_trans_affine.cpp ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+ //
16
+ // Affine transformations
17
+ //
18
+ //----------------------------------------------------------------------------
19
+ #include "agg_trans_affine.h"
20
+
21
+
22
+
23
+ namespace agg
24
+ {
25
+
26
+ //------------------------------------------------------------------------
27
+ const trans_affine& trans_affine::parl_to_parl(const double* src,
28
+ const double* dst)
29
+ {
30
+ sx = src[2] - src[0];
31
+ shy = src[3] - src[1];
32
+ shx = src[4] - src[0];
33
+ sy = src[5] - src[1];
34
+ tx = src[0];
35
+ ty = src[1];
36
+ invert();
37
+ multiply(trans_affine(dst[2] - dst[0], dst[3] - dst[1],
38
+ dst[4] - dst[0], dst[5] - dst[1],
39
+ dst[0], dst[1]));
40
+ return *this;
41
+ }
42
+
43
+ //------------------------------------------------------------------------
44
+ const trans_affine& trans_affine::rect_to_parl(double x1, double y1,
45
+ double x2, double y2,
46
+ const double* parl)
47
+ {
48
+ double src[6];
49
+ src[0] = x1; src[1] = y1;
50
+ src[2] = x2; src[3] = y1;
51
+ src[4] = x2; src[5] = y2;
52
+ parl_to_parl(src, parl);
53
+ return *this;
54
+ }
55
+
56
+ //------------------------------------------------------------------------
57
+ const trans_affine& trans_affine::parl_to_rect(const double* parl,
58
+ double x1, double y1,
59
+ double x2, double y2)
60
+ {
61
+ double dst[6];
62
+ dst[0] = x1; dst[1] = y1;
63
+ dst[2] = x2; dst[3] = y1;
64
+ dst[4] = x2; dst[5] = y2;
65
+ parl_to_parl(parl, dst);
66
+ return *this;
67
+ }
68
+
69
+ //------------------------------------------------------------------------
70
+ const trans_affine& trans_affine::multiply(const trans_affine& m)
71
+ {
72
+ double t0 = sx * m.sx + shy * m.shx;
73
+ double t2 = shx * m.sx + sy * m.shx;
74
+ double t4 = tx * m.sx + ty * m.shx + m.tx;
75
+ shy = sx * m.shy + shy * m.sy;
76
+ sy = shx * m.shy + sy * m.sy;
77
+ ty = tx * m.shy + ty * m.sy + m.ty;
78
+ sx = t0;
79
+ shx = t2;
80
+ tx = t4;
81
+ return *this;
82
+ }
83
+
84
+
85
+ //------------------------------------------------------------------------
86
+ const trans_affine& trans_affine::invert()
87
+ {
88
+ double d = determinant_reciprocal();
89
+
90
+ double t0 = sy * d;
91
+ sy = sx * d;
92
+ shy = -shy * d;
93
+ shx = -shx * d;
94
+
95
+ double t4 = -tx * t0 - ty * shx;
96
+ ty = -tx * shy - ty * sy;
97
+
98
+ sx = t0;
99
+ tx = t4;
100
+ return *this;
101
+ }
102
+
103
+
104
+ //------------------------------------------------------------------------
105
+ const trans_affine& trans_affine::flip_x()
106
+ {
107
+ sx = -sx;
108
+ shy = -shy;
109
+ tx = -tx;
110
+ return *this;
111
+ }
112
+
113
+ //------------------------------------------------------------------------
114
+ const trans_affine& trans_affine::flip_y()
115
+ {
116
+ shx = -shx;
117
+ sy = -sy;
118
+ ty = -ty;
119
+ return *this;
120
+ }
121
+
122
+ //------------------------------------------------------------------------
123
+ const trans_affine& trans_affine::reset()
124
+ {
125
+ sx = sy = 1.0;
126
+ shy = shx = tx = ty = 0.0;
127
+ return *this;
128
+ }
129
+
130
+ //------------------------------------------------------------------------
131
+ bool trans_affine::is_identity(double epsilon) const
132
+ {
133
+ return is_equal_eps(sx, 1.0, epsilon) &&
134
+ is_equal_eps(shy, 0.0, epsilon) &&
135
+ is_equal_eps(shx, 0.0, epsilon) &&
136
+ is_equal_eps(sy, 1.0, epsilon) &&
137
+ is_equal_eps(tx, 0.0, epsilon) &&
138
+ is_equal_eps(ty, 0.0, epsilon);
139
+ }
140
+
141
+ //------------------------------------------------------------------------
142
+ bool trans_affine::is_valid(double epsilon) const
143
+ {
144
+ return fabs(sx) > epsilon && fabs(sy) > epsilon;
145
+ }
146
+
147
+ //------------------------------------------------------------------------
148
+ bool trans_affine::is_equal(const trans_affine& m, double epsilon) const
149
+ {
150
+ return is_equal_eps(sx, m.sx, epsilon) &&
151
+ is_equal_eps(shy, m.shy, epsilon) &&
152
+ is_equal_eps(shx, m.shx, epsilon) &&
153
+ is_equal_eps(sy, m.sy, epsilon) &&
154
+ is_equal_eps(tx, m.tx, epsilon) &&
155
+ is_equal_eps(ty, m.ty, epsilon);
156
+ }
157
+
158
+ //------------------------------------------------------------------------
159
+ double trans_affine::rotation() const
160
+ {
161
+ double x1 = 0.0;
162
+ double y1 = 0.0;
163
+ double x2 = 1.0;
164
+ double y2 = 0.0;
165
+ transform(&x1, &y1);
166
+ transform(&x2, &y2);
167
+ return atan2(y2-y1, x2-x1);
168
+ }
169
+
170
+ //------------------------------------------------------------------------
171
+ void trans_affine::translation(double* dx, double* dy) const
172
+ {
173
+ *dx = tx;
174
+ *dy = ty;
175
+ }
176
+
177
+ //------------------------------------------------------------------------
178
+ void trans_affine::scaling(double* x, double* y) const
179
+ {
180
+ double x1 = 0.0;
181
+ double y1 = 0.0;
182
+ double x2 = 1.0;
183
+ double y2 = 1.0;
184
+ trans_affine t(*this);
185
+ t *= trans_affine_rotation(-rotation());
186
+ t.transform(&x1, &y1);
187
+ t.transform(&x2, &y2);
188
+ *x = x2 - x1;
189
+ *y = y2 - y1;
190
+ }
191
+
192
+
193
+ }
194
+
testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_trans_double_path.cpp ADDED
@@ -0,0 +1,273 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+
16
+ #include "agg_math.h"
17
+ #include "agg_trans_double_path.h"
18
+
19
+ namespace agg
20
+ {
21
+
22
+ //------------------------------------------------------------------------
23
+ trans_double_path::trans_double_path() :
24
+ m_kindex1(0.0),
25
+ m_kindex2(0.0),
26
+ m_base_length(0.0),
27
+ m_base_height(1.0),
28
+ m_status1(initial),
29
+ m_status2(initial),
30
+ m_preserve_x_scale(true)
31
+ {
32
+ }
33
+
34
+
35
+ //------------------------------------------------------------------------
36
+ void trans_double_path::reset()
37
+ {
38
+ m_src_vertices1.remove_all();
39
+ m_src_vertices2.remove_all();
40
+ m_kindex1 = 0.0;
41
+ m_kindex1 = 0.0;
42
+ m_status1 = initial;
43
+ m_status2 = initial;
44
+ }
45
+
46
+
47
+ //------------------------------------------------------------------------
48
+ void trans_double_path::move_to1(double x, double y)
49
+ {
50
+ if(m_status1 == initial)
51
+ {
52
+ m_src_vertices1.modify_last(vertex_dist(x, y));
53
+ m_status1 = making_path;
54
+ }
55
+ else
56
+ {
57
+ line_to1(x, y);
58
+ }
59
+ }
60
+
61
+
62
+ //------------------------------------------------------------------------
63
+ void trans_double_path::line_to1(double x, double y)
64
+ {
65
+ if(m_status1 == making_path)
66
+ {
67
+ m_src_vertices1.add(vertex_dist(x, y));
68
+ }
69
+ }
70
+
71
+
72
+ //------------------------------------------------------------------------
73
+ void trans_double_path::move_to2(double x, double y)
74
+ {
75
+ if(m_status2 == initial)
76
+ {
77
+ m_src_vertices2.modify_last(vertex_dist(x, y));
78
+ m_status2 = making_path;
79
+ }
80
+ else
81
+ {
82
+ line_to2(x, y);
83
+ }
84
+ }
85
+
86
+
87
+ //------------------------------------------------------------------------
88
+ void trans_double_path::line_to2(double x, double y)
89
+ {
90
+ if(m_status2 == making_path)
91
+ {
92
+ m_src_vertices2.add(vertex_dist(x, y));
93
+ }
94
+ }
95
+
96
+
97
+ //------------------------------------------------------------------------
98
+ double trans_double_path::finalize_path(vertex_storage& vertices)
99
+ {
100
+ unsigned i;
101
+ double dist;
102
+ double d;
103
+
104
+ vertices.close(false);
105
+ if(vertices.size() > 2)
106
+ {
107
+ if(vertices[vertices.size() - 2].dist * 10.0 <
108
+ vertices[vertices.size() - 3].dist)
109
+ {
110
+ d = vertices[vertices.size() - 3].dist +
111
+ vertices[vertices.size() - 2].dist;
112
+
113
+ vertices[vertices.size() - 2] =
114
+ vertices[vertices.size() - 1];
115
+
116
+ vertices.remove_last();
117
+ vertices[vertices.size() - 2].dist = d;
118
+ }
119
+ }
120
+
121
+ dist = 0;
122
+ for(i = 0; i < vertices.size(); i++)
123
+ {
124
+ vertex_dist& v = vertices[i];
125
+ d = v.dist;
126
+ v.dist = dist;
127
+ dist += d;
128
+ }
129
+
130
+ return (vertices.size() - 1) / dist;
131
+ }
132
+
133
+
134
+ //------------------------------------------------------------------------
135
+ void trans_double_path::finalize_paths()
136
+ {
137
+ if(m_status1 == making_path && m_src_vertices1.size() > 1 &&
138
+ m_status2 == making_path && m_src_vertices2.size() > 1)
139
+ {
140
+ m_kindex1 = finalize_path(m_src_vertices1);
141
+ m_kindex2 = finalize_path(m_src_vertices2);
142
+ m_status1 = ready;
143
+ m_status2 = ready;
144
+ }
145
+ }
146
+
147
+
148
+ //------------------------------------------------------------------------
149
+ double trans_double_path::total_length1() const
150
+ {
151
+ if(m_base_length >= 1e-10) return m_base_length;
152
+ return (m_status1 == ready) ?
153
+ m_src_vertices1[m_src_vertices1.size() - 1].dist :
154
+ 0.0;
155
+ }
156
+
157
+
158
+ //------------------------------------------------------------------------
159
+ double trans_double_path::total_length2() const
160
+ {
161
+ if(m_base_length >= 1e-10) return m_base_length;
162
+ return (m_status2 == ready) ?
163
+ m_src_vertices2[m_src_vertices2.size() - 1].dist :
164
+ 0.0;
165
+ }
166
+
167
+
168
+ //------------------------------------------------------------------------
169
+ void trans_double_path::transform1(const vertex_storage& vertices,
170
+ double kindex, double kx,
171
+ double *x, double* y) const
172
+ {
173
+ double x1 = 0.0;
174
+ double y1 = 0.0;
175
+ double dx = 1.0;
176
+ double dy = 1.0;
177
+ double d = 0.0;
178
+ double dd = 1.0;
179
+ *x *= kx;
180
+ if(*x < 0.0)
181
+ {
182
+ // Extrapolation on the left
183
+ //--------------------------
184
+ x1 = vertices[0].x;
185
+ y1 = vertices[0].y;
186
+ dx = vertices[1].x - x1;
187
+ dy = vertices[1].y - y1;
188
+ dd = vertices[1].dist - vertices[0].dist;
189
+ d = *x;
190
+ }
191
+ else
192
+ if(*x > vertices[vertices.size() - 1].dist)
193
+ {
194
+ // Extrapolation on the right
195
+ //--------------------------
196
+ unsigned i = vertices.size() - 2;
197
+ unsigned j = vertices.size() - 1;
198
+ x1 = vertices[j].x;
199
+ y1 = vertices[j].y;
200
+ dx = x1 - vertices[i].x;
201
+ dy = y1 - vertices[i].y;
202
+ dd = vertices[j].dist - vertices[i].dist;
203
+ d = *x - vertices[j].dist;
204
+ }
205
+ else
206
+ {
207
+ // Interpolation
208
+ //--------------------------
209
+ unsigned i = 0;
210
+ unsigned j = vertices.size() - 1;
211
+ if(m_preserve_x_scale)
212
+ {
213
+ unsigned k;
214
+ for(i = 0; (j - i) > 1; )
215
+ {
216
+ if(*x < vertices[k = (i + j) >> 1].dist)
217
+ {
218
+ j = k;
219
+ }
220
+ else
221
+ {
222
+ i = k;
223
+ }
224
+ }
225
+ d = vertices[i].dist;
226
+ dd = vertices[j].dist - d;
227
+ d = *x - d;
228
+ }
229
+ else
230
+ {
231
+ i = unsigned(*x * kindex);
232
+ j = i + 1;
233
+ dd = vertices[j].dist - vertices[i].dist;
234
+ d = ((*x * kindex) - i) * dd;
235
+ }
236
+ x1 = vertices[i].x;
237
+ y1 = vertices[i].y;
238
+ dx = vertices[j].x - x1;
239
+ dy = vertices[j].y - y1;
240
+ }
241
+ *x = x1 + dx * d / dd;
242
+ *y = y1 + dy * d / dd;
243
+ }
244
+
245
+
246
+ //------------------------------------------------------------------------
247
+ void trans_double_path::transform(double *x, double *y) const
248
+ {
249
+ if(m_status1 == ready && m_status2 == ready)
250
+ {
251
+ if(m_base_length > 1e-10)
252
+ {
253
+ *x *= m_src_vertices1[m_src_vertices1.size() - 1].dist /
254
+ m_base_length;
255
+ }
256
+
257
+ double x1 = *x;
258
+ double y1 = *y;
259
+ double x2 = *x;
260
+ double y2 = *y;
261
+ double dd = m_src_vertices2[m_src_vertices2.size() - 1].dist /
262
+ m_src_vertices1[m_src_vertices1.size() - 1].dist;
263
+
264
+ transform1(m_src_vertices1, m_kindex1, 1.0, &x1, &y1);
265
+ transform1(m_src_vertices2, m_kindex2, dd, &x2, &y2);
266
+
267
+ *x = x1 + *y * (x2 - x1) / m_base_height;
268
+ *y = y1 + *y * (y2 - y1) / m_base_height;
269
+ }
270
+ }
271
+
272
+ }
273
+
testbed/matplotlib__matplotlib/extern/agg24-svn/src/agg_trans_single_path.cpp ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //----------------------------------------------------------------------------
2
+ // Anti-Grain Geometry - Version 2.4
3
+ // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
+ //
5
+ // Permission to copy, use, modify, sell and distribute this software
6
+ // is granted provided this copyright notice appears in all copies.
7
+ // This software is provided "as is" without express or implied
8
+ // warranty, and with no claim as to its suitability for any purpose.
9
+ //
10
+ //----------------------------------------------------------------------------
11
+ // Contact: mcseem@antigrain.com
12
+ // mcseemagg@yahoo.com
13
+ // http://www.antigrain.com
14
+ //----------------------------------------------------------------------------
15
+
16
+ #include "agg_math.h"
17
+ #include "agg_vertex_sequence.h"
18
+ #include "agg_trans_single_path.h"
19
+
20
+ namespace agg
21
+ {
22
+
23
+ //------------------------------------------------------------------------
24
+ trans_single_path::trans_single_path() :
25
+ m_base_length(0.0),
26
+ m_kindex(0.0),
27
+ m_status(initial),
28
+ m_preserve_x_scale(true)
29
+ {
30
+ }
31
+
32
+ //------------------------------------------------------------------------
33
+ void trans_single_path::reset()
34
+ {
35
+ m_src_vertices.remove_all();
36
+ m_kindex = 0.0;
37
+ m_status = initial;
38
+ }
39
+
40
+ //------------------------------------------------------------------------
41
+ void trans_single_path::move_to(double x, double y)
42
+ {
43
+ if(m_status == initial)
44
+ {
45
+ m_src_vertices.modify_last(vertex_dist(x, y));
46
+ m_status = making_path;
47
+ }
48
+ else
49
+ {
50
+ line_to(x, y);
51
+ }
52
+ }
53
+
54
+ //------------------------------------------------------------------------
55
+ void trans_single_path::line_to(double x, double y)
56
+ {
57
+ if(m_status == making_path)
58
+ {
59
+ m_src_vertices.add(vertex_dist(x, y));
60
+ }
61
+ }
62
+
63
+
64
+ //------------------------------------------------------------------------
65
+ void trans_single_path::finalize_path()
66
+ {
67
+ if(m_status == making_path && m_src_vertices.size() > 1)
68
+ {
69
+ unsigned i;
70
+ double dist;
71
+ double d;
72
+
73
+ m_src_vertices.close(false);
74
+ if(m_src_vertices.size() > 2)
75
+ {
76
+ if(m_src_vertices[m_src_vertices.size() - 2].dist * 10.0 <
77
+ m_src_vertices[m_src_vertices.size() - 3].dist)
78
+ {
79
+ d = m_src_vertices[m_src_vertices.size() - 3].dist +
80
+ m_src_vertices[m_src_vertices.size() - 2].dist;
81
+
82
+ m_src_vertices[m_src_vertices.size() - 2] =
83
+ m_src_vertices[m_src_vertices.size() - 1];
84
+
85
+ m_src_vertices.remove_last();
86
+ m_src_vertices[m_src_vertices.size() - 2].dist = d;
87
+ }
88
+ }
89
+
90
+ dist = 0.0;
91
+ for(i = 0; i < m_src_vertices.size(); i++)
92
+ {
93
+ vertex_dist& v = m_src_vertices[i];
94
+ double d = v.dist;
95
+ v.dist = dist;
96
+ dist += d;
97
+ }
98
+ m_kindex = (m_src_vertices.size() - 1) / dist;
99
+ m_status = ready;
100
+ }
101
+ }
102
+
103
+
104
+
105
+ //------------------------------------------------------------------------
106
+ double trans_single_path::total_length() const
107
+ {
108
+ if(m_base_length >= 1e-10) return m_base_length;
109
+ return (m_status == ready) ?
110
+ m_src_vertices[m_src_vertices.size() - 1].dist :
111
+ 0.0;
112
+ }
113
+
114
+
115
+ //------------------------------------------------------------------------
116
+ void trans_single_path::transform(double *x, double *y) const
117
+ {
118
+ if(m_status == ready)
119
+ {
120
+ if(m_base_length > 1e-10)
121
+ {
122
+ *x *= m_src_vertices[m_src_vertices.size() - 1].dist /
123
+ m_base_length;
124
+ }
125
+
126
+ double x1 = 0.0;
127
+ double y1 = 0.0;
128
+ double dx = 1.0;
129
+ double dy = 1.0;
130
+ double d = 0.0;
131
+ double dd = 1.0;
132
+ if(*x < 0.0)
133
+ {
134
+ // Extrapolation on the left
135
+ //--------------------------
136
+ x1 = m_src_vertices[0].x;
137
+ y1 = m_src_vertices[0].y;
138
+ dx = m_src_vertices[1].x - x1;
139
+ dy = m_src_vertices[1].y - y1;
140
+ dd = m_src_vertices[1].dist - m_src_vertices[0].dist;
141
+ d = *x;
142
+ }
143
+ else
144
+ if(*x > m_src_vertices[m_src_vertices.size() - 1].dist)
145
+ {
146
+ // Extrapolation on the right
147
+ //--------------------------
148
+ unsigned i = m_src_vertices.size() - 2;
149
+ unsigned j = m_src_vertices.size() - 1;
150
+ x1 = m_src_vertices[j].x;
151
+ y1 = m_src_vertices[j].y;
152
+ dx = x1 - m_src_vertices[i].x;
153
+ dy = y1 - m_src_vertices[i].y;
154
+ dd = m_src_vertices[j].dist - m_src_vertices[i].dist;
155
+ d = *x - m_src_vertices[j].dist;
156
+ }
157
+ else
158
+ {
159
+ // Interpolation
160
+ //--------------------------
161
+ unsigned i = 0;
162
+ unsigned j = m_src_vertices.size() - 1;
163
+ if(m_preserve_x_scale)
164
+ {
165
+ unsigned k;
166
+ for(i = 0; (j - i) > 1; )
167
+ {
168
+ if(*x < m_src_vertices[k = (i + j) >> 1].dist)
169
+ {
170
+ j = k;
171
+ }
172
+ else
173
+ {
174
+ i = k;
175
+ }
176
+ }
177
+ d = m_src_vertices[i].dist;
178
+ dd = m_src_vertices[j].dist - d;
179
+ d = *x - d;
180
+ }
181
+ else
182
+ {
183
+ i = unsigned(*x * m_kindex);
184
+ j = i + 1;
185
+ dd = m_src_vertices[j].dist - m_src_vertices[i].dist;
186
+ d = ((*x * m_kindex) - i) * dd;
187
+ }
188
+ x1 = m_src_vertices[i].x;
189
+ y1 = m_src_vertices[i].y;
190
+ dx = m_src_vertices[j].x - x1;
191
+ dy = m_src_vertices[j].y - y1;
192
+ }
193
+ double x2 = x1 + dx * d / dd;
194
+ double y2 = y1 + dy * d / dd;
195
+ *x = x2 - *y * dy / dd;
196
+ *y = y2 + *y * dx / dd;
197
+ }
198
+ }
199
+
200
+
201
+ }
202
+