Skip to content

Commit

Permalink
Merge pull request #473 from zomfg/hotfix/allow-skipping-color-modifi…
Browse files Browse the repository at this point in the history
…cation

udp led devices: allow bypassing color modifications
  • Loading branch information
psieg authored Jun 19, 2021
2 parents 7a03e1b + f7e5b84 commit 9521c1b
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 16 deletions.
9 changes: 7 additions & 2 deletions Software/src/AbstractLedDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void AbstractLedDevice::updateDeviceSettings()
All modifications are made over extended 12bit RGB, so \code outColors \endcode will contain 12bit
RGB instead of 8bit.
*/
void AbstractLedDevice::applyColorModifications(const QList<QRgb> &inColors, QList<StructRgb> &outColors) {
void AbstractLedDevice::applyColorModifications(const QList<QRgb> &inColors, QList<StructRgb> &outColors, const bool rawColors) {

const bool isApplyWBAdjustments = m_wbAdjustments.count() == inColors.count();

Expand All @@ -124,9 +124,14 @@ void AbstractLedDevice::applyColorModifications(const QList<QRgb> &inColors, QLi
outColors[i].g = qGreen(inColors[i]) * k;
outColors[i].b = qBlue(inColors[i]) * k;

PrismatikMath::gammaCorrection(m_gamma, outColors[i]);
if (!rawColors)
PrismatikMath::gammaCorrection(m_gamma, outColors[i]);
}

// we can't completely bypass this function because of the Qrgb / StructRgb conversion above
if (rawColors)
return;

const StructLab avgColor = PrismatikMath::toLab(PrismatikMath::avgColor(outColors));

const double ampCoef = m_ledMilliAmps / (4095.0 * 3.0) / 1000.0;
Expand Down
2 changes: 1 addition & 1 deletion Software/src/AbstractLedDevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public slots:
virtual void setUsbPowerLedDisabled(bool isDisabled);

protected:
virtual void applyColorModifications(const QList<QRgb> & inColors, QList<StructRgb> & outColors);
virtual void applyColorModifications(const QList<QRgb> & inColors, QList<StructRgb> & outColors, const bool rawColors = false);
virtual void applyDithering(QList<StructRgb>& colors, int colorDepth);

protected:
Expand Down
2 changes: 1 addition & 1 deletion Software/src/AbstractLedDeviceUdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void AbstractLedDeviceUdp::switchOffLeds()
blackFrame.reserve(count);
for (int i = 0; i < count; i++)
blackFrame << 0;
setColors(blackFrame);
setColors(blackFrame, true);
}

void AbstractLedDeviceUdp::resizeColorsBuffer(int buffSize)
Expand Down
2 changes: 2 additions & 0 deletions Software/src/AbstractLedDeviceUdp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public slots:
virtual void setColorDepth(int value);
virtual void requestFirmwareVersion();
void switchOffLeds();
virtual void setColors(const QList<QRgb> & colors, const bool rawColors) = 0;
void setColors(const QList<QRgb> & colors) {setColors(colors, false);};

protected:
QByteArray m_writeBufferHeader;
Expand Down
7 changes: 4 additions & 3 deletions Software/src/LedDeviceDnrgb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@ int LedDeviceDnrgb::maxLedsCount()
return MaximumNumberOfLeds::Dnrgb;
}

void LedDeviceDnrgb::setColors(const QList<QRgb> & colors)
void LedDeviceDnrgb::setColors(const QList<QRgb> & colors, const bool rawColors)
{
bool ok = true;
bool sentPackets = false;

resizeColorsBuffer(colors.count());

applyColorModifications(colors, m_colorsBuffer);
applyDithering(m_colorsBuffer, 8);
applyColorModifications(colors, m_colorsBuffer, rawColors);
if (!rawColors)
applyDithering(m_colorsBuffer, 8);

// Send multiple buffers
const int totalColorsSaved = m_processedColorsSaved.count();
Expand Down
2 changes: 1 addition & 1 deletion Software/src/LedDeviceDnrgb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class LedDeviceDnrgb : public AbstractLedDeviceUdp
int maxLedsCount();

public slots:
void setColors(const QList<QRgb> & colors);
void setColors(const QList<QRgb> & colors, const bool rawColors);

protected:
virtual void reinitBufferHeader();
Expand Down
7 changes: 4 additions & 3 deletions Software/src/LedDeviceDrgb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ int LedDeviceDrgb::maxLedsCount()
return MaximumNumberOfLeds::Drgb;
}

void LedDeviceDrgb::setColors(const QList<QRgb> & colors)
void LedDeviceDrgb::setColors(const QList<QRgb> & colors, const bool rawColors)
{
m_colorsSaved = colors;

resizeColorsBuffer(colors.count());

applyColorModifications(colors, m_colorsBuffer);
applyDithering(m_colorsBuffer, 8);
applyColorModifications(colors, m_colorsBuffer, rawColors);
if (!rawColors)
applyDithering(m_colorsBuffer, 8);

m_writeBuffer.clear();
m_writeBuffer.reserve(m_writeBuffer.count() + m_colorsBuffer.count() * sizeof(char));
Expand Down
2 changes: 1 addition & 1 deletion Software/src/LedDeviceDrgb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class LedDeviceDrgb : public AbstractLedDeviceUdp
int maxLedsCount();

public slots:
void setColors(const QList<QRgb> & colors);
void setColors(const QList<QRgb> & colors, const bool rawColors);

protected:
virtual void reinitBufferHeader();
Expand Down
7 changes: 4 additions & 3 deletions Software/src/LedDeviceWarls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ int LedDeviceWarls::maxLedsCount()
return MaximumNumberOfLeds::Warls;
}

void LedDeviceWarls::setColors(const QList<QRgb> & colors)
void LedDeviceWarls::setColors(const QList<QRgb> & colors, const bool rawColors)
{
resizeColorsBuffer(colors.count());

applyColorModifications(colors, m_colorsBuffer);
applyDithering(m_colorsBuffer, 8);
applyColorModifications(colors, m_colorsBuffer, rawColors);
if (!rawColors)
applyDithering(m_colorsBuffer, 8);

const int totalColorsSaved = m_processedColorsSaved.count();
m_writeBuffer.clear();
Expand Down
2 changes: 1 addition & 1 deletion Software/src/LedDeviceWarls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class LedDeviceWarls : public AbstractLedDeviceUdp
int maxLedsCount();

public slots:
void setColors(const QList<QRgb> & colors);
void setColors(const QList<QRgb> & colors, const bool rawColors);

protected:
virtual void reinitBufferHeader();
Expand Down

0 comments on commit 9521c1b

Please sign in to comment.