From d55a6aa4ba83472a094c9cf57101413eb7cf7862 Mon Sep 17 00:00:00 2001 From: Erik Garrison Date: Tue, 16 Jan 2024 11:39:03 +0100 Subject: [PATCH] try to write highlights over the rasterized image --- src/algorithms/atomic_image.cpp | 4 ++++ src/algorithms/atomic_image.hpp | 1 + src/algorithms/draw.cpp | 20 ++++++++++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/algorithms/atomic_image.cpp b/src/algorithms/atomic_image.cpp index 870e2759..7238bf82 100644 --- a/src/algorithms/atomic_image.cpp +++ b/src/algorithms/atomic_image.cpp @@ -39,6 +39,10 @@ std::ostream& operator<<(std::ostream& out, const color_t& c) { return out; } +bool operator==(const color_t& a, const color_t& b) { + return a.c.r == b.c.r && a.c.g == b.c.g && a.c.b == b.c.b && a.c.a == b.c.a; +} + color_t lighten(const color_t& c, const double& f) { return layer(c, COLOR_WHITE, f); } diff --git a/src/algorithms/atomic_image.hpp b/src/algorithms/atomic_image.hpp index 05472902..c67a2b6a 100644 --- a/src/algorithms/atomic_image.hpp +++ b/src/algorithms/atomic_image.hpp @@ -85,6 +85,7 @@ typedef union rgb_t { } color_t; std::ostream& operator<<(std::ostream& out, const color_t& c); +bool operator==(const color_t& a, const color_t& b); color_t hash_color(const std::string& s); color_t lighten(const color_t& c, const double& f); diff --git a/src/algorithms/draw.cpp b/src/algorithms/draw.cpp index 7d606c8f..f483460b 100644 --- a/src/algorithms/draw.cpp +++ b/src/algorithms/draw.cpp @@ -208,11 +208,18 @@ std::vector rasterize(const std::vector &X, source_min_x, source_min_y); auto range_itr = component_ranges.begin(); + struct draw_target_t { + xy_d_t xy0; + xy_d_t xy1; + algorithms::color_t color; + }; + for (auto& component : weak_components) { auto& range = *range_itr++; auto& x_off = range.x_offset; auto& y_off = range.y_offset; -#pragma omp parallel for + std::vector highlights; +//#pragma omp parallel for for (uint64_t i = 0; i < component.size(); ++i) { const handle_t& handle = component[i]; uint64_t a = 2 * number_bool_packing::unpack_number(handle); @@ -252,9 +259,18 @@ std::vector rasterize(const std::vector &X, */ const algorithms::color_t node_color = !node_id_to_color.empty() ? node_id_to_color[graph.get_id(handle)] : COLOR_BLACK; - wu_calc_wide_line(xy0, xy1, node_color, image, line_width); + // if gray or black color, otherwise save for later + if (node_color == COLOR_BLACK || node_color == COLOR_LIGHTGRAY) { + wu_calc_wide_line(xy0, xy1, node_color, image, line_width); + } else { + highlights.push_back({xy0, xy1, node_color}); + } } } + // color highlights + for (auto& highlight : highlights) { + wu_calc_wide_line(highlight.xy0, highlight.xy1, highlight.color, image, line_width); + } } // todo, edges, paths, coverage, bins