From 4b9517a148bcd6f47cc2f20a83355093811cc04b Mon Sep 17 00:00:00 2001 From: Vasile Vilvoiu Date: Thu, 21 Oct 2021 23:12:06 +0300 Subject: Renderer does not cache colromap and valuemap. * Renderer build colormap from configuration. * Renderer builds (temporary) valuemap from configuration. * LiveOutput no longer needs cmap/vmap parameters. --- src/renderer.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/renderer.cpp') diff --git a/src/renderer.cpp b/src/renderer.cpp index 00dedfe..b4f5a1e 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -48,11 +48,14 @@ Renderer::ValueToShortString(double value, int scale, const std::string& unit) return ss.str(); } -Renderer::Renderer(const Configuration& conf, const ColorMap& cmap, const ValueMap& vmap, std::size_t fft_count) - : configuration_(conf), fft_count_(fft_count), color_map_(cmap.Copy()) +Renderer::Renderer(const Configuration& conf, std::size_t fft_count) + : configuration_(conf) + , fft_count_(fft_count) + , color_map_(ColorMap::Build(conf.GetColorMap(), conf.GetBackgroundColor(), + conf.GetColorMapCustomColor())) { if (color_map_ == nullptr) { - throw std::runtime_error("failed to copy color map"); + throw std::runtime_error("failed to build colormap"); } if (fft_count == 0) { throw std::runtime_error("positive number of FFT windows required by renderer"); @@ -71,10 +74,14 @@ Renderer::Renderer(const Configuration& conf, const ColorMap& cmap, const ValueM Renderer::GetNiceTicks(0.0f, (double)fft_count * this->configuration_.GetAverageCount() * this->configuration_.GetFFTStride() / this->configuration_.GetRate(), "s", fft_count, 30, !this->configuration_.IsHorizontal()); - auto legend_ticks = Renderer::GetNiceTicks(vmap.GetLowerBound(), vmap.GetUpperBound(), - vmap.GetUnit(), this->configuration_.GetWidth(), 50, + auto vmap = ValueMap::Build(conf.GetScaleType(), + conf.GetScaleLowerBound(), + conf.GetScaleUpperBound(), + conf.GetScaleUnit()); + auto legend_ticks = Renderer::GetNiceTicks(vmap->GetLowerBound(), vmap->GetUpperBound(), + vmap->GetUnit(), this->configuration_.GetWidth(), 50, this->configuration_.IsHorizontal()); - this->live_ticks_ = Renderer::GetNiceTicks(vmap.GetLowerBound(), vmap.GetUpperBound(), + this->live_ticks_ = Renderer::GetNiceTicks(vmap->GetLowerBound(), vmap->GetUpperBound(), "", this->configuration_.GetLiveFFTHeight(), 20, !this->configuration_.IsHorizontal()); /* no unit, keep it short */ @@ -233,7 +240,7 @@ Renderer::Renderer(const Configuration& conf, const ColorMap& cmap, const ValueM this->canvas_.draw(legend_box, this->legend_transform_); /* legend gradient */ - auto memory = cmap.Gradient(this->configuration_.GetWidth()); + auto memory = color_map_->Gradient(this->configuration_.GetWidth()); sf::Texture tex; tex.create(this->configuration_.GetWidth(), 1); tex.update(reinterpret_cast(memory.data())); -- cgit v1.2.3