From 36f8f73b0fc8b433cd6a8117e2cd279261a74a45 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Fri, 5 Jan 2024 14:48:41 -0600 Subject: [PATCH] Use common data level functions when generating color table lut --- .../scwx/qt/view/level3_product_view.cpp | 43 ++++++------------- .../wsr88d/rpg/product_description_block.hpp | 1 + .../wsr88d/rpg/product_description_block.cpp | 5 +++ 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/scwx-qt/source/scwx/qt/view/level3_product_view.cpp b/scwx-qt/source/scwx/qt/view/level3_product_view.cpp index c965ab3d..779e6084 100644 --- a/scwx-qt/source/scwx/qt/view/level3_product_view.cpp +++ b/scwx-qt/source/scwx/qt/view/level3_product_view.cpp @@ -247,10 +247,9 @@ void Level3ProductView::UpdateColorTableLut() return; } - std::int16_t productCode = descriptionBlock->product_code(); - float offset = descriptionBlock->offset(); - float scale = descriptionBlock->scale(); - std::uint8_t threshold = static_cast( + float offset = descriptionBlock->offset(); + float scale = descriptionBlock->scale(); + std::uint8_t threshold = static_cast( std::clamp(descriptionBlock->threshold(), std::numeric_limits::min(), std::numeric_limits::max())); @@ -292,7 +291,7 @@ void Level3ProductView::UpdateColorTableLut() std::optional f = descriptionBlock->data_value(i); // Different products use different scale/offset formulas - if (numberOfLevels > 16 || productCode == 34) + if (numberOfLevels > 16 || !descriptionBlock->IsDataLevelCoded()) { if (i == RANGE_FOLDED && threshold > RANGE_FOLDED) { @@ -312,34 +311,20 @@ void Level3ProductView::UpdateColorTableLut() } else { - uint16_t th = descriptionBlock->data_level_threshold(i); - if ((th & 0x8000u) == 0) + std::optional dataLevelCode = + descriptionBlock->data_level_code(i); + + if (dataLevelCode == wsr88d::DataLevelCode::RangeFolded) { - // If bit 0 is zero, then the LSB is numeric - if (f.has_value()) - { - lut[lutIndex] = p->colorTable_->Color(f.value()); - } - else - { - lut[lutIndex] = boost::gil::rgba8_pixel_t {0, 0, 0, 0}; - } + lut[lutIndex] = p->colorTable_->rf_color(); + } + else if (f.has_value()) + { + lut[lutIndex] = p->colorTable_->Color(f.value()); } else { - // If bit 0 is one, then the LSB is coded - uint16_t lsb = th & 0x00ffu; - - switch (lsb) - { - case 3: // RF - lut[lutIndex] = p->colorTable_->rf_color(); - break; - - default: // Ignore other values - lut[lutIndex] = boost::gil::rgba8_pixel_t {0, 0, 0, 0}; - break; - } + lut[lutIndex] = boost::gil::rgba8_pixel_t {0, 0, 0, 0}; } } }); diff --git a/wxdata/include/scwx/wsr88d/rpg/product_description_block.hpp b/wxdata/include/scwx/wsr88d/rpg/product_description_block.hpp index 0e51807f..c67ccbf2 100644 --- a/wxdata/include/scwx/wsr88d/rpg/product_description_block.hpp +++ b/wxdata/include/scwx/wsr88d/rpg/product_description_block.hpp @@ -72,6 +72,7 @@ public: units::angle::degrees elevation() const; bool IsCompressionEnabled() const; + bool IsDataLevelCoded() const; size_t data_size() const override; diff --git a/wxdata/source/scwx/wsr88d/rpg/product_description_block.cpp b/wxdata/source/scwx/wsr88d/rpg/product_description_block.cpp index c44e45d5..cba00da9 100644 --- a/wxdata/source/scwx/wsr88d/rpg/product_description_block.cpp +++ b/wxdata/source/scwx/wsr88d/rpg/product_description_block.cpp @@ -633,6 +633,11 @@ bool ProductDescriptionBlock::IsCompressionEnabled() const return isCompressed; } +bool ProductDescriptionBlock::IsDataLevelCoded() const +{ + return !uncodedDataLevelProducts_.contains(p->productCode_); +} + size_t ProductDescriptionBlock::data_size() const { return SIZE;