Refactor to process blacklisted LEDs with less resources

This commit is contained in:
LordGrey 2023-08-25 19:52:00 +02:00
parent 77a213dfc7
commit 8f3a1cc2af
4 changed files with 64 additions and 25 deletions

View File

@ -74,7 +74,7 @@ inline ColorOrder stringToColorOrder(const QString & order)
}
///
/// The Led structure contains the definition of the image portion used to determine a single led's
/// The Led structure contains the definition of the image portion used to determine a single LED's
/// color.
/// @verbatim
/// |--------------------image--|
@ -90,46 +90,66 @@ inline ColorOrder stringToColorOrder(const QString & order)
///
struct Led
{
/// The minimum vertical scan line included for this leds color
/// The minimum vertical scan line included for this LEDs color
double minX_frac;
/// The maximum vertical scan line included for this leds color
/// The maximum vertical scan line included for this LEDs color
double maxX_frac;
/// The minimum horizontal scan line included for this leds color
/// The minimum horizontal scan line included for this LEDs color
double minY_frac;
/// The maximum horizontal scan line included for this leds color
/// The maximum horizontal scan line included for this LEDs color
double maxY_frac;
/// A Led at {0,0,0,0} is not visible and therefore treated as blacklisted
/// A LEDs at {0,0,0,0} is not visible and therefore treated as blacklisted
bool isBlacklisted {false};
/// the color order
ColorOrder colorOrder;
};
///
/// The LedString contains the image integration information of the leds
/// The LedString contains the image integration information of the LEDs
///
class LedString
{
public:
///
/// Returns the led specifications
/// Returns the LED specifications
///
/// @return The list with led specifications
///
std::vector<Led>& leds();
///
/// Returns the led specifications
/// Returns the LED specifications
///
/// @return The list with led specifications
///
const std::vector<Led>& leds() const;
bool hasBlackListedLeds {false};
///
/// Returns the IDs of blacklisted LEDs
///
/// @return ID List of blacklisted LEDs
///
std::vector<int>& blacklistedLedIds();
///
/// Returns the IDs of blacklisted LEDs
///
/// @return ID List of blacklisted LEDs
///
const std::vector<int>& blacklistedLedIds() const;
///
/// Check, if teh layout has blacklisted LEDs configured
///
/// @return True, if blacklisted LEDs are configured
///
bool hasBlackListedLeds ();
static LedString createLedString(const QJsonArray& ledConfigArray, const ColorOrder deviceOrder);
private:
/// The list with led specifications
/// The list with LED specifications
std::vector<Led> _leds;
/// The list containing IDs of blacklisted LED
std::vector<int> _blacklistedLedIds;
};

View File

@ -671,20 +671,18 @@ void Hyperion::update()
else
{
_ledBuffer = priorityInfo.ledColors;
}
if (_ledString.hasBlackListedLeds)
{
auto ledIter = _ledString.leds().begin();
for (ColorRgb& color : _ledBuffer)
if (ledIter != _ledString.leds().end())
if (_ledString.hasBlackListedLeds())
{
for (int id : _ledString.blacklistedLedIds())
{
if ((*ledIter).isBlacklisted)
if (id > _ledBuffer.size()-1)
{
color = ColorRgb::BLACK;
break;
}
++ledIter;
_ledBuffer.at(id) = ColorRgb::BLACK;
}
}
}
// emit rawLedColors before transform

View File

@ -19,6 +19,29 @@ const std::vector<Led>& LedString::leds() const
return _leds;
}
std::vector<int>& LedString::blacklistedLedIds()
{
return _blacklistedLedIds;
}
const std::vector<int>& LedString::blacklistedLedIds() const
{
return _blacklistedLedIds;
}
bool LedString::hasBlackListedLeds()
{
if (_blacklistedLedIds.size() > 0)
{
return true;
}
else
{
return false;
}
}
/**
* Construct the 'led-string' with the integration area definition per led and the color
* ordering of the RGB channels
@ -31,8 +54,6 @@ LedString LedString::createLedString(const QJsonArray& ledConfigArray, const Col
LedString ledString;
const QString deviceOrderStr = colorOrderToString(deviceOrder);
ledString.hasBlackListedLeds = false;
for (signed i = 0; i < ledConfigArray.size(); ++i)
{
const QJsonObject& ledConfig = ledConfigArray[i].toObject();
@ -63,7 +84,7 @@ LedString LedString::createLedString(const QJsonArray& ledConfigArray, const Col
)
{
led.isBlacklisted = true;
ledString.hasBlackListedLeds |= led.isBlacklisted;
ledString.blacklistedLedIds().push_back(i);
}
ledString.leds().push_back(led);
}

View File

@ -24,7 +24,7 @@ int main()
return -1;
}
const LedString ledString = hyperion::createLedString(config["leds"].toArray(), hyperion::createColorOrder(config["device"].toObject()));
const LedString ledString = LedString::createLedString(config["leds"].toArray(), hyperion::createColorOrder(config["device"].toObject()));
const ColorRgb testColor = {64, 123, 12};