Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Lord-Grey committed Aug 24, 2023
1 parent b2fcea3 commit 77a213d
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 44 deletions.
10 changes: 9 additions & 1 deletion include/hyperion/LedString.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

// QT includes
#include <QString>
#include <QJsonArray>

// Forward class declarations
namespace Json { class Value; }
Expand Down Expand Up @@ -97,6 +98,8 @@ struct Led
double minY_frac;
/// 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
bool isBlacklisted {false};
/// the color order
ColorOrder colorOrder;
};
Expand All @@ -121,7 +124,12 @@ class LedString
///
const std::vector<Led>& leds() const;

bool hasBlackListedLeds {false};

static LedString createLedString(const QJsonArray& ledConfigArray, const ColorOrder deviceOrder);

private:
/// The list with led specifications
std::vector<Led> mLeds;
std::vector<Led> _leds;

};
38 changes: 0 additions & 38 deletions include/utils/hyperion.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,44 +177,6 @@ namespace hyperion {
return adjustment;
}

/**
* Construct the 'led-string' with the integration area definition per led and the color
* ordering of the RGB channels
* @param ledsConfig The configuration of the led areas
* @param deviceOrder The default RGB channel ordering
* @return The constructed ledstring
*/
static LedString createLedString(const QJsonArray& ledConfigArray, const ColorOrder deviceOrder)
{
LedString ledString;
const QString deviceOrderStr = colorOrderToString(deviceOrder);

for (signed i = 0; i < ledConfigArray.size(); ++i)
{
const QJsonObject& ledConfig = ledConfigArray[i].toObject();
Led led;

led.minX_frac = qMax(0.0, qMin(1.0, ledConfig["hmin"].toDouble()));
led.maxX_frac = qMax(0.0, qMin(1.0, ledConfig["hmax"].toDouble()));
led.minY_frac = qMax(0.0, qMin(1.0, ledConfig["vmin"].toDouble()));
led.maxY_frac = qMax(0.0, qMin(1.0, ledConfig["vmax"].toDouble()));
// Fix if the user swapped min and max
if (led.minX_frac > led.maxX_frac)
{
std::swap(led.minX_frac, led.maxX_frac);
}
if (led.minY_frac > led.maxY_frac)
{
std::swap(led.minY_frac, led.maxY_frac);
}

// Get the order of the rgb channels for this led (default is device order)
led.colorOrder = stringToColorOrder(ledConfig["colorOrder"].toString(deviceOrderStr));
ledString.leds().push_back(led);
}
return ledString;
}

static QSize getLedLayoutGridSize(const QJsonArray& ledConfigArray)
{
std::vector<int> midPointsX;
Expand Down
20 changes: 17 additions & 3 deletions libsrc/hyperion/Hyperion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Hyperion::Hyperion(quint8 instance, bool readonlyMode)
, _instIndex(instance)
, _settingsManager(new SettingsManager(instance, this, readonlyMode))
, _componentRegister(nullptr)
, _ledString(hyperion::createLedString(getSetting(settings::LEDS).array(), hyperion::createColorOrder(getSetting(settings::DEVICE).object())))
, _ledString(LedString::createLedString(getSetting(settings::LEDS).array(), hyperion::createColorOrder(getSetting(settings::DEVICE).object())))
, _imageProcessor(nullptr)
, _muxer(nullptr)
, _raw2ledAdjustment(hyperion::createLedColorsAdjustment(static_cast<int>(_ledString.leds().size()), getSetting(settings::COLOR).object()))
Expand Down Expand Up @@ -255,7 +255,7 @@ void Hyperion::handleSettingsUpdate(settings::type type, const QJsonDocument& co
#endif

// ledstring, img processor, muxer, ledGridSize (effect-engine image based effects), _ledBuffer and ByteOrder of ledstring
_ledString = hyperion::createLedString(leds, hyperion::createColorOrder(getSetting(settings::DEVICE).object()));
_ledString = LedString::createLedString(leds, hyperion::createColorOrder(getSetting(settings::DEVICE).object()));
_imageProcessor->setLedString(_ledString);
_muxer->updateLedColorsLength(static_cast<int>(_ledString.leds().size()));
_ledGridSize = hyperion::getLedLayoutGridSize(leds);
Expand Down Expand Up @@ -291,7 +291,7 @@ void Hyperion::handleSettingsUpdate(settings::type type, const QJsonDocument& co
// force ledString update, if device ByteOrder changed
if(_ledDeviceWrapper->getColorOrder() != dev["colorOrder"].toString("rgb"))
{
_ledString = hyperion::createLedString(getSetting(settings::LEDS).array(), hyperion::createColorOrder(dev));
_ledString = LedString::createLedString(getSetting(settings::LEDS).array(), hyperion::createColorOrder(dev));
_imageProcessor->setLedString(_ledString);

_ledStringColorOrder.clear();
Expand Down Expand Up @@ -673,6 +673,20 @@ void Hyperion::update()
_ledBuffer = priorityInfo.ledColors;
}

if (_ledString.hasBlackListedLeds)
{
auto ledIter = _ledString.leds().begin();
for (ColorRgb& color : _ledBuffer)
if (ledIter != _ledString.leds().end())
{
if ((*ledIter).isBlacklisted)
{
color = ColorRgb::BLACK;
}
++ledIter;
}
}

// emit rawLedColors before transform
emit rawLedColors(_ledBuffer);

Expand Down
59 changes: 57 additions & 2 deletions libsrc/hyperion/LedString.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,71 @@
// STL includes

#include <cstring>
#include <iostream>

// hyperion includes
#include <hyperion/LedString.h>

// QT includes
#include <QJsonObject>

std::vector<Led>& LedString::leds()
{
return mLeds;
return _leds;
}

const std::vector<Led>& LedString::leds() const
{
return mLeds;
return _leds;
}

/**
* Construct the 'led-string' with the integration area definition per led and the color
* ordering of the RGB channels
* @param ledsConfig The configuration of the led areas
* @param deviceOrder The default RGB channel ordering
* @return The constructed ledstring
*/
LedString LedString::createLedString(const QJsonArray& ledConfigArray, const ColorOrder deviceOrder)
{
LedString ledString;
const QString deviceOrderStr = colorOrderToString(deviceOrder);

ledString.hasBlackListedLeds = false;

for (signed i = 0; i < ledConfigArray.size(); ++i)
{
const QJsonObject& ledConfig = ledConfigArray[i].toObject();
Led led;

led.minX_frac = qMax(0.0, qMin(1.0, ledConfig["hmin"].toDouble()));
led.maxX_frac = qMax(0.0, qMin(1.0, ledConfig["hmax"].toDouble()));
led.minY_frac = qMax(0.0, qMin(1.0, ledConfig["vmin"].toDouble()));
led.maxY_frac = qMax(0.0, qMin(1.0, ledConfig["vmax"].toDouble()));
// Fix if the user swapped min and max
if (led.minX_frac > led.maxX_frac)
{
std::swap(led.minX_frac, led.maxX_frac);
}
if (led.minY_frac > led.maxY_frac)
{
std::swap(led.minY_frac, led.maxY_frac);
}

// Get the order of the rgb channels for this led (default is device order)
led.colorOrder = stringToColorOrder(ledConfig["colorOrder"].toString(deviceOrderStr));

led.isBlacklisted = false;
if (led.minX_frac < std::numeric_limits<double>::epsilon() &&
led.maxX_frac < std::numeric_limits<double>::epsilon() &&
led.minY_frac < std::numeric_limits<double>::epsilon() &&
led.maxY_frac < std::numeric_limits<double>::epsilon()
)
{
led.isBlacklisted = true;
ledString.hasBlackListedLeds |= led.isBlacklisted;
}
ledString.leds().push_back(led);
}
return ledString;
}

0 comments on commit 77a213d

Please sign in to comment.