11
11
#include < cmath>
12
12
#include < algorithm>
13
13
#include < functional>
14
+ #include < optional>
14
15
#include < vector>
15
16
16
17
#include " agg_alpha_mask_u8.h"
@@ -123,9 +124,6 @@ class RendererAgg
123
124
typedef agg::renderer_base<agg::pixfmt_gray8> renderer_base_alpha_mask_type;
124
125
typedef agg::renderer_scanline_aa_solid<renderer_base_alpha_mask_type> renderer_alpha_mask_type;
125
126
126
- /* TODO: Remove facepair_t */
127
- typedef std::pair<bool , agg::rgba> facepair_t ;
128
-
129
127
RendererAgg (unsigned int width, unsigned int height, double dpi);
130
128
131
129
virtual ~RendererAgg ();
@@ -248,7 +246,7 @@ class RendererAgg
248
246
bool render_clippath (mpl::PathIterator &clippath, const agg::trans_affine &clippath_trans, e_snap_mode snap_mode);
249
247
250
248
template <class PathIteratorType >
251
- void _draw_path (PathIteratorType &path, bool has_clippath, const facepair_t &face, GCAgg &gc);
249
+ void _draw_path (PathIteratorType &path, bool has_clippath, const std::optional<agg::rgba> &face, GCAgg &gc);
252
250
253
251
template <class PathIterator ,
254
252
class PathGenerator ,
@@ -295,7 +293,7 @@ class RendererAgg
295
293
296
294
template <class path_t >
297
295
inline void
298
- RendererAgg::_draw_path (path_t &path, bool has_clippath, const facepair_t &face, GCAgg &gc)
296
+ RendererAgg::_draw_path (path_t &path, bool has_clippath, const std::optional<agg::rgba> &face, GCAgg &gc)
299
297
{
300
298
typedef agg::conv_stroke<path_t > stroke_t ;
301
299
typedef agg::conv_dash<path_t > dash_t ;
@@ -306,29 +304,29 @@ RendererAgg::_draw_path(path_t &path, bool has_clippath, const facepair_t &face,
306
304
typedef agg::renderer_scanline_bin_solid<amask_ren_type> amask_bin_renderer_type;
307
305
308
306
// Render face
309
- if (face. first ) {
307
+ if (face) {
310
308
theRasterizer.add_path (path);
311
309
312
310
if (gc.isaa ) {
313
311
if (has_clippath) {
314
312
pixfmt_amask_type pfa (pixFmt, alphaMask);
315
313
amask_ren_type r (pfa);
316
314
amask_aa_renderer_type ren (r);
317
- ren.color (face. second );
315
+ ren.color (* face);
318
316
agg::render_scanlines (theRasterizer, scanlineAlphaMask, ren);
319
317
} else {
320
- rendererAA.color (face. second );
318
+ rendererAA.color (* face);
321
319
agg::render_scanlines (theRasterizer, slineP8, rendererAA);
322
320
}
323
321
} else {
324
322
if (has_clippath) {
325
323
pixfmt_amask_type pfa (pixFmt, alphaMask);
326
324
amask_ren_type r (pfa);
327
325
amask_bin_renderer_type ren (r);
328
- ren.color (face. second );
326
+ ren.color (* face);
329
327
agg::render_scanlines (theRasterizer, scanlineAlphaMask, ren);
330
328
} else {
331
- rendererBin.color (face. second );
329
+ rendererBin.color (* face);
332
330
agg::render_scanlines (theRasterizer, slineP8, rendererBin);
333
331
}
334
332
}
@@ -458,7 +456,10 @@ RendererAgg::draw_path(GCAgg &gc, PathIterator &path, agg::trans_affine &trans,
458
456
typedef agg::conv_curve<simplify_t > curve_t ;
459
457
typedef Sketch<curve_t > sketch_t ;
460
458
461
- facepair_t face (color.a != 0.0 , color);
459
+ std::optional<agg::rgba> face;
460
+ if (color.a != 0.0 ) {
461
+ face = color;
462
+ }
462
463
463
464
theRasterizer.reset_clipping ();
464
465
rendererBase.reset_clipping (true );
@@ -467,7 +468,7 @@ RendererAgg::draw_path(GCAgg &gc, PathIterator &path, agg::trans_affine &trans,
467
468
468
469
trans *= agg::trans_affine_scaling (1.0 , -1.0 );
469
470
trans *= agg::trans_affine_translation (0.0 , (double )height);
470
- bool clip = !face. first && !gc.has_hatchpath ();
471
+ bool clip = !face && !gc.has_hatchpath ();
471
472
bool simplify = path.should_simplify () && clip;
472
473
double snapping_linewidth = points_to_pixels (gc.linewidth );
473
474
if (gc.color .a == 0.0 ) {
@@ -529,7 +530,10 @@ inline void RendererAgg::draw_markers(GCAgg &gc,
529
530
curve_t path_curve (path_snapped);
530
531
path_curve.rewind (0 );
531
532
532
- facepair_t face (color.a != 0.0 , color);
533
+ std::optional<agg::rgba> face;
534
+ if (color.a != 0.0 ) {
535
+ face = color;
536
+ }
533
537
534
538
// maxim's suggestions for cached scanlines
535
539
agg::scanline_storage_aa8 scanlines;
@@ -541,7 +545,7 @@ inline void RendererAgg::draw_markers(GCAgg &gc,
541
545
try
542
546
{
543
547
std::vector<agg::int8u> fillBuffer;
544
- if (face. first ) {
548
+ if (face) {
545
549
theRasterizer.add_path (marker_path_curve);
546
550
agg::render_scanlines (theRasterizer, slineP8, scanlines);
547
551
fillBuffer.resize (scanlines.byte_size ());
@@ -605,8 +609,8 @@ inline void RendererAgg::draw_markers(GCAgg &gc,
605
609
amask_ren_type r (pfa);
606
610
amask_aa_renderer_type ren (r);
607
611
608
- if (face. first ) {
609
- ren.color (face. second );
612
+ if (face) {
613
+ ren.color (* face);
610
614
sa.init (fillBuffer.data (), fillBuffer.size (), x, y);
611
615
agg::render_scanlines (sa, sl, ren);
612
616
}
@@ -633,8 +637,8 @@ inline void RendererAgg::draw_markers(GCAgg &gc,
633
637
continue ;
634
638
}
635
639
636
- if (face. first ) {
637
- rendererAA.color (face. second );
640
+ if (face) {
641
+ rendererAA.color (* face);
638
642
sa.init (fillBuffer.data (), fillBuffer.size (), x, y);
639
643
agg::render_scanlines (sa, sl, rendererAA);
640
644
}
@@ -936,10 +940,9 @@ inline void RendererAgg::_draw_path_collection_generic(GCAgg &gc,
936
940
937
941
// Set some defaults, assuming no face or edge
938
942
gc.linewidth = 0.0 ;
939
- facepair_t face;
940
- face.first = Nfacecolors != 0 ;
943
+ std::optional<agg::rgba> face;
941
944
agg::trans_affine trans;
942
- bool do_clip = !face. first && !gc.has_hatchpath ();
945
+ bool do_clip = Nfacecolors == 0 && !gc.has_hatchpath ();
943
946
944
947
for (int i = 0 ; i < (int )N; ++i) {
945
948
typename PathGenerator::path_iterator path = path_generator (i);
@@ -970,7 +973,7 @@ inline void RendererAgg::_draw_path_collection_generic(GCAgg &gc,
970
973
971
974
if (Nfacecolors) {
972
975
int ic = i % Nfacecolors;
973
- face.second = agg::rgba (facecolors (ic, 0 ), facecolors (ic, 1 ), facecolors (ic, 2 ), facecolors (ic, 3 ));
976
+ face.emplace (facecolors (ic, 0 ), facecolors (ic, 1 ), facecolors (ic, 2 ), facecolors (ic, 3 ));
974
977
}
975
978
976
979
if (Nedgecolors) {
0 commit comments