Skip to content

Commit

Permalink
Fix disabled LEDs
Browse files Browse the repository at this point in the history
  • Loading branch information
awawa-dev committed Nov 19, 2022
1 parent 18e9ce0 commit d7fa77e
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 55 deletions.
8 changes: 7 additions & 1 deletion assets/webconfig/js/light_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,10 @@ $(document).ready(function()
"group": {
"type": "integer",
"minimum": 0
},
"disabled": {
"type": "boolean",
"default": false
}
},
"type": "object"
Expand Down Expand Up @@ -950,7 +954,9 @@ $(document).ready(function()
// validate textfield and update preview
$("#leds_custom_updsim").off().on("click", function()
{
createLedPreview(aceEdt.get(), 'text');
const backup = aceEdt.get();
createLedPreview(backup, 'text');
aceEdt.set(backup);
});

// save led config and saveValues - passing textfield
Expand Down
2 changes: 0 additions & 2 deletions include/base/ImageToLedsMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,10 @@ namespace hyperhdr

/// The absolute indices into the image for each led
std::vector<std::vector<int32_t>> _colorsMap;
std::vector<bool> _colorsDisabled;
std::vector<int> _colorsGroups;

int _groupMin;
int _groupMax;
bool _haveDisabled;

ColorRgb calcMeanColor(const Image<ColorRgb>& image, const std::vector<int32_t>& colors) const;

Expand Down
2 changes: 2 additions & 0 deletions include/base/LedString.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ class LedString
/// the color order
ColorOrder colorOrder = ColorOrder::ORDER_RGB;

bool hasDisabled = false;

static ColorOrder createColorOrder(const QJsonObject& deviceConfig);
static LedString createLedString(const QJsonArray& ledConfigArray, const ColorOrder deviceOrder);
static QSize getLedLayoutGridSize(const QJsonArray& ledConfigArray);
Expand Down
91 changes: 53 additions & 38 deletions sources/base/HyperHdrInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,27 +444,26 @@ bool HyperHdrInstance::setInputInactive(quint8 priority)

void HyperHdrInstance::setColor(int priority, const std::vector<ColorRgb>& ledColors, int timeout_ms, const QString& origin, bool clearEffects)
{
if (ledColors.size() == 0)
return;

// clear effect if this call does not come from an effect
if (clearEffects)
{
_effectEngine->channelCleared(priority);
}

// create full led vector from single/multiple colors
size_t size = _ledString.leds().size();
std::vector<ColorRgb> newLedColors;
while (true)
auto currentCol = ledColors.begin();

for (const Led& led : _ledString.leds())
{
for (const auto& entry : ledColors)
{
newLedColors.emplace_back(entry);
if (newLedColors.size() == size)
{
goto end;
}
}
newLedColors.emplace_back(*currentCol);

if (++currentCol == ledColors.end())
currentCol = ledColors.begin();
}
end:

if (getPriorityInfo(priority).componentId != hyperhdr::COMP_COLOR)
{
Expand Down Expand Up @@ -672,37 +671,53 @@ void HyperHdrInstance::updateResult(std::vector<ColorRgb> _ledBuffer)

_globalLedBuffer = _ledBuffer;

// emit rawLedColors before transform
emit rawLedColors(_ledBuffer);
for (int disabledProcessing = 0; disabledProcessing < 2; disabledProcessing++)
{
if (disabledProcessing == 1)
_raw2ledAdjustment->applyAdjustment(_ledBuffer);

_raw2ledAdjustment->applyAdjustment(_ledBuffer);
if (_ledString.hasDisabled)
{
auto ledIter = _ledString.leds().begin();
for (ColorRgb& color : _ledBuffer)
if (ledIter != _ledString.leds().end())
{
if ((*ledIter).disabled)
color = ColorRgb::BLACK;
++ledIter;
}
}

for (ColorRgb& color : _ledBuffer)
if (disabledProcessing == 0)
emit rawLedColors(_ledBuffer);
}

if (_ledString.colorOrder != ColorOrder::ORDER_RGB)
{
// correct the color byte order
switch (_ledString.colorOrder)
for (ColorRgb& color : _ledBuffer)
{
case ColorOrder::ORDER_RGB:
// leave as it is
break;
case ColorOrder::ORDER_BGR:
std::swap(color.red, color.blue);
break;
case ColorOrder::ORDER_RBG:
std::swap(color.green, color.blue);
break;
case ColorOrder::ORDER_GRB:
std::swap(color.red, color.green);
break;
case ColorOrder::ORDER_GBR:
std::swap(color.red, color.green);
std::swap(color.green, color.blue);
break;

case ColorOrder::ORDER_BRG:
std::swap(color.red, color.blue);
std::swap(color.green, color.blue);
break;
// correct the color byte order
switch (_ledString.colorOrder)
{
case ColorOrder::ORDER_BGR:
std::swap(color.red, color.blue);
break;
case ColorOrder::ORDER_RBG:
std::swap(color.green, color.blue);
break;
case ColorOrder::ORDER_GRB:
std::swap(color.red, color.green);
break;
case ColorOrder::ORDER_GBR:
std::swap(color.red, color.green);
std::swap(color.green, color.blue);
break;

case ColorOrder::ORDER_BRG:
std::swap(color.red, color.blue);
std::swap(color.green, color.blue);
break;
}
}
}

Expand Down
14 changes: 1 addition & 13 deletions sources/base/ImageToLedsMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ ImageToLedsMap::ImageToLedsMap(
, _horizontalBorder(horizontalBorder)
, _verticalBorder(verticalBorder)
, _colorsMap()
, _colorsDisabled()
, _colorsGroups()
, _groupMin(-1)
, _groupMax(-1)
, _haveDisabled(false)
{
// Sanity check of the size of the borders (and width and height)
Q_ASSERT(_width > 2 * _verticalBorder);
Expand Down Expand Up @@ -174,9 +172,7 @@ ImageToLedsMap::ImageToLedsMap(
}

// Add the constructed vector to the map
_haveDisabled |= led.disabled;
_colorsMap.push_back(ledColor);
_colorsDisabled.push_back(led.disabled);
_colorsGroups.push_back(led.group);
if (_groupMin == -1 || led.group < _groupMin)
_groupMin = led.group;
Expand Down Expand Up @@ -254,15 +250,7 @@ std::vector<ColorRgb> ImageToLedsMap::Process(const Image<ColorRgb>& image, uint
}
}
}

for (size_t i = 0; _haveDisabled && i < qMin(_colorsDisabled.size(), colors.size()); i++)
if (_colorsDisabled[i])
{
colors[i].red = 0;
colors[i].green = 0;
colors[i].blue = 0;
}


return colors;
}

Expand Down
2 changes: 2 additions & 0 deletions sources/base/LedString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ LedString LedString::createLedString(const QJsonArray& ledConfigArray, const Col
LedString ledString;
const QString deviceOrderStr = colorOrderToString(deviceOrder);

ledString.hasDisabled = false;
for (signed i = 0; i < ledConfigArray.size(); ++i)
{
const QJsonObject& ledConfig = ledConfigArray[i].toObject();
Expand All @@ -36,6 +37,7 @@ LedString LedString::createLedString(const QJsonArray& ledConfigArray, const Col
led.maxY_frac = qMax(0.0, qMin(1.0, ledConfig["vmax"].toDouble()));
led.group = ledConfig["group"].toInt(0);
led.disabled = ledConfig["disabled"].toBool(false);
ledString.hasDisabled |= led.disabled;

// Fix if the user swapped min and max
if (led.minX_frac > led.maxX_frac)
Expand Down
2 changes: 1 addition & 1 deletion sources/base/LinearSmoothing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ void LinearSmoothing::updateLedValues(const std::vector<ColorRgb>& ledValues)
if (_pause || ledValues.size() == 0)
return;

emit _hyperhdr->ledDeviceData(ledValues);
queueColors(ledValues);

return;
}
Expand Down

0 comments on commit d7fa77e

Please sign in to comment.