Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 32 additions & 23 deletions Software/src/AbstractLedDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ void AbstractLedDevice::setBrightnessCap(int value, bool updateColors) {
setColors(m_colorsSaved);
}

void AbstractLedDevice::setDitheringEnabled(bool value, bool updateColors) {
m_isDitheringEnabled = value;
if (updateColors)
setColors(m_colorsSaved);
}

void AbstractLedDevice::setLedMilliAmps(const int value, const bool updateColors) {
m_ledMilliAmps = value;
if (updateColors)
Expand Down Expand Up @@ -90,6 +96,7 @@ void AbstractLedDevice::updateDeviceSettings()
setBrightnessCap(Settings::getDeviceBrightnessCap(), false);
setLuminosityThreshold(Settings::getLuminosityThreshold(), false);
setMinimumLuminosityThresholdEnabled(Settings::isMinimumLuminosityEnabled(), false);
setDitheringEnabled(Settings::isDeviceDitheringEnabled(), false);
updateWBAdjustments(Settings::getLedCoefs(), false);

setColors(m_colorsSaved);
Expand Down Expand Up @@ -195,31 +202,33 @@ void AbstractLedDevice::applyDithering(QList<StructRgb>& colors, int colorDepth)
colors[i].g = (double)colors[i].g / k;
colors[i].b = (double)colors[i].b / k;

carryR += tempR - (double)colors[i].r * k;
carryG += tempG - (double)colors[i].g * k;
carryB += tempB - (double)colors[i].b * k;
if (m_isDitheringEnabled) {
carryR += tempR - (double)colors[i].r * k;
carryG += tempG - (double)colors[i].g * k;
carryB += tempB - (double)colors[i].b * k;

meanIndR += (tempR - (double)colors[i].r * k) * i;
meanIndG += (tempG - (double)colors[i].g * k) * i;
meanIndB += (tempB - (double)colors[i].b * k) * i;
meanIndR += (tempR - (double)colors[i].r * k) * i;
meanIndG += (tempG - (double)colors[i].g * k) * i;
meanIndB += (tempB - (double)colors[i].b * k) * i;

if (carryR >= k) {
int ind = (meanIndR - (carryR - k) * i) / k;
colors[ind].r++;
carryR -= k;
meanIndR = carryR * i;
}
if (carryG >= k) {
int ind = (meanIndG - (carryG - k) * i) / k;
colors[ind].g++;
carryG -= k;
meanIndG = carryG * i;
}
if (carryB >= k) {
int ind = (meanIndB - (carryB - k) * i) / k;
colors[ind].b++;
carryB -= k;
meanIndB = carryB * i;
if (carryR >= k) {
int ind = (meanIndR - (carryR - k) * i) / k;
colors[ind].r++;
carryR -= k;
meanIndR = carryR * i;
}
if (carryG >= k) {
int ind = (meanIndG - (carryG - k) * i) / k;
colors[ind].g++;
carryG -= k;
meanIndG = carryG * i;
}
if (carryB >= k) {
int ind = (meanIndB - (carryB - k) * i) / k;
colors[ind].b++;
carryB -= k;
meanIndB = carryB * i;
}
}
}
}
2 changes: 2 additions & 0 deletions Software/src/AbstractLedDevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public slots:
virtual void setGamma(double value, bool updateColors = true);
virtual void setBrightness(int value, bool updateColors = true);
virtual void setBrightnessCap(int value, bool updateColors = true);
virtual void setDitheringEnabled(bool value, bool updateColors = true);
virtual void setLedMilliAmps(const int value, const bool updateColors = true);
virtual void setPowerSupplyAmps(const double value, const bool updateColors = true);
virtual void setColorSequence(QString value) = 0;
Expand Down Expand Up @@ -107,6 +108,7 @@ public slots:
double m_powerSupplyAmps{0.0};
int m_luminosityThreshold;
bool m_isMinimumLuminosityEnabled;
bool m_isDitheringEnabled;

QList<WBAdjustment> m_wbAdjustments;

Expand Down
23 changes: 22 additions & 1 deletion Software/src/LedDeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,21 @@ void LedDeviceManager::setMinimumLuminosityEnabled(bool value)
}
}

void LedDeviceManager::setDitheringEnabled(bool isEnabled) {
DEBUG_MID_LEVEL << Q_FUNC_INFO << isEnabled
<< "Is last command completed:" << m_isLastCommandCompleted;

if (m_isLastCommandCompleted) {
m_cmdTimeoutTimer->start();
m_isLastCommandCompleted = false;
emit ledDeviceSetDitheringEnabled(isEnabled);
}
else {
m_savedDitheringEnabled = isEnabled;
cmdQueueAppend(LedDeviceCommands::SetDitheringEnabled);
}
}

void LedDeviceManager::setColorSequence(QString value)
{
DEBUG_MID_LEVEL << Q_FUNC_INFO << value << "Is last command completed:" << m_isLastCommandCompleted;
Expand Down Expand Up @@ -542,7 +557,8 @@ void LedDeviceManager::connectSignalSlotsLedDevice()
connect(this, SIGNAL(ledDeviceSetBrightnessCap(int, bool)), m_ledDevice, SLOT(setBrightnessCap(int, bool)), Qt::QueuedConnection);
connect(this, SIGNAL(ledDeviceSetColorSequence(QString)), m_ledDevice, SLOT(setColorSequence(QString)), Qt::QueuedConnection);
connect(this, SIGNAL(ledDeviceSetLuminosityThreshold(int, bool)), m_ledDevice, SLOT(setLuminosityThreshold(int, bool)), Qt::QueuedConnection);
connect(this, SIGNAL(ledDeviceSetMinimumLuminosityEnabled(bool, bool)), m_ledDevice, SLOT(setMinimumLuminosityThresholdEnabled(bool, bool)), Qt::QueuedConnection);
connect(this, SIGNAL(ledDeviceSetMinimumLuminosityEnabled(bool, bool)), m_ledDevice,SLOT(setMinimumLuminosityThresholdEnabled(bool, bool)), Qt::QueuedConnection);
connect(this, SIGNAL(ledDeviceSetDitheringEnabled(bool)), m_ledDevice, SLOT(setDitheringEnabled(bool)), Qt::QueuedConnection);
connect(this, SIGNAL(ledDeviceRequestFirmwareVersion()), m_ledDevice, SLOT(requestFirmwareVersion()), Qt::QueuedConnection);
connect(this, SIGNAL(ledDeviceUpdateWBAdjustments()), m_ledDevice, SLOT(updateWBAdjustments()), Qt::QueuedConnection);
connect(this, SIGNAL(ledDeviceUpdateDeviceSettings()), m_ledDevice, SLOT(updateDeviceSettings()), Qt::QueuedConnection);
Expand Down Expand Up @@ -666,6 +682,11 @@ void LedDeviceManager::cmdQueueProcessNext()
emit ledDeviceSetMinimumLuminosityEnabled(m_savedIsMinimumLuminosityEnabled, m_backlightStatus != Backlight::StatusOff);
break;

case LedDeviceCommands::SetDitheringEnabled:
m_cmdTimeoutTimer->start();
emit ledDeviceSetDitheringEnabled(m_savedDitheringEnabled);
break;

case LedDeviceCommands::RequestFirmwareVersion:
m_cmdTimeoutTimer->start();
emit ledDeviceRequestFirmwareVersion();
Expand Down
3 changes: 3 additions & 0 deletions Software/src/LedDeviceManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class LedDeviceManager : public QObject
void ledDeviceSetBrightnessCap(int value, bool);
void ledDeviceSetLuminosityThreshold(int value, bool);
void ledDeviceSetMinimumLuminosityEnabled(bool, bool);
void ledDeviceSetDitheringEnabled(bool isEnabled);
void ledDeviceSetColorSequence(QString value);
void ledDeviceRequestFirmwareVersion();
void ledDeviceUpdateWBAdjustments();
Expand All @@ -86,6 +87,7 @@ public slots:
void setBrightnessCap(int value);
void setLuminosityThreshold(int value);
void setMinimumLuminosityEnabled(bool value);
void setDitheringEnabled(bool isEnabled);
void setColorSequence(QString value);
void requestFirmwareVersion();
void updateWBAdjustments();
Expand Down Expand Up @@ -124,6 +126,7 @@ private slots:
int m_savedBrightnessCap;
int m_savedLuminosityThreshold;
bool m_savedIsMinimumLuminosityEnabled;
bool m_savedDitheringEnabled;
QString m_savedColorSequence;

QList<AbstractLedDevice *> m_ledDevices;
Expand Down
1 change: 1 addition & 0 deletions Software/src/LightpackApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ void LightpackApplication::startLedDeviceManager()
connect(settings(), SIGNAL(deviceRefreshDelayChanged(int)), m_ledDeviceManager, SLOT(setRefreshDelay(int)), Qt::QueuedConnection);
connect(settings(), SIGNAL(deviceUsbPowerLedDisabledChanged(bool)), m_ledDeviceManager, SLOT(setUsbPowerLedDisabled(bool)), Qt::QueuedConnection);
connect(settings(), SIGNAL(deviceGammaChanged(double)), m_ledDeviceManager, SLOT(setGamma(double)), Qt::QueuedConnection);
connect(settings(), SIGNAL(deviceDitheringEnabledChanged(bool)), m_ledDeviceManager, SLOT(setDitheringEnabled(bool)), Qt::QueuedConnection);
connect(settings(), SIGNAL(deviceBrightnessChanged(int)), m_ledDeviceManager, SLOT(setBrightness(int)), Qt::QueuedConnection);
connect(settings(), SIGNAL(deviceBrightnessCapChanged(int)), m_ledDeviceManager, SLOT(setBrightnessCap(int)), Qt::QueuedConnection);
connect(settings(), SIGNAL(luminosityThresholdChanged(int)), m_ledDeviceManager, SLOT(setLuminosityThreshold(int)), Qt::QueuedConnection);
Expand Down
17 changes: 15 additions & 2 deletions Software/src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ static const QString Brightness = "Device/Brightness";
static const QString BrightnessCap = "Device/BrightnessCap";
static const QString ColorDepth = "Device/ColorDepth";
static const QString Gamma = "Device/Gamma";
static const QString IsDitheringEnabled = "Device/IsDitheringEnabled";
}
// [LED_i]
namespace Led
Expand Down Expand Up @@ -289,7 +290,6 @@ Settings::Settings() : QObject(NULL) {
qRegisterMetaType<QColor>("QColor");
qRegisterMetaType<SupportedDevices::DeviceType>("SupportedDevices::DeviceType");
qRegisterMetaType<Lightpack::Mode>("Lightpack::Mode");

}

// Desktop should be initialized before call Settings::Initialize()
Expand Down Expand Up @@ -1488,6 +1488,18 @@ void Settings::setDeviceGamma(double gamma)
m_this->deviceGammaChanged(gamma);
}

bool Settings::isDeviceDitheringEnabled()
{
return value(Profile::Key::Device::IsDitheringEnabled).toBool();
}

void Settings::setDeviceDitheringEnabled(bool isEnabled)
{
DEBUG_LOW_LEVEL << Q_FUNC_INFO;
setValue(Profile::Key::Device::IsDitheringEnabled, isEnabled);
m_this->deviceDitheringEnabledChanged(isEnabled);
}

Grab::GrabberType Settings::getGrabberType()
{
DEBUG_LOW_LEVEL << Q_FUNC_INFO;
Expand Down Expand Up @@ -2105,12 +2117,13 @@ void Settings::initCurrentProfile(bool isResetDefault)
#endif
// [Device]
setNewOption(Profile::Key::Device::RefreshDelay, Profile::Device::RefreshDelayDefault, isResetDefault);
setNewOption(Profile::Key::Device::IsUsbPowerLedDisabled, Profile::Device::IsUsbPowerLedDisabled, isResetDefault);
setNewOption(Profile::Key::Device::IsUsbPowerLedDisabled, Profile::Device::IsUsbPowerLedDisabledDefault, isResetDefault);
setNewOption(Profile::Key::Device::Brightness, Profile::Device::BrightnessDefault, isResetDefault);
setNewOption(Profile::Key::Device::BrightnessCap, Profile::Device::BrightnessCapDefault, isResetDefault);
setNewOption(Profile::Key::Device::Smooth, Profile::Device::SmoothDefault, isResetDefault);
setNewOption(Profile::Key::Device::Gamma, Profile::Device::GammaDefault, isResetDefault);
setNewOption(Profile::Key::Device::ColorDepth, Profile::Device::ColorDepthDefault, isResetDefault);
setNewOption(Profile::Key::Device::IsDitheringEnabled, Profile::Device::IsDitheringEnabledDefault, isResetDefault);


QPoint ledPosition;
Expand Down
3 changes: 3 additions & 0 deletions Software/src/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ class Settings : public QObject
static void setDeviceColorDepth(int value);
static double getDeviceGamma();
static void setDeviceGamma(double gamma);
static bool isDeviceDitheringEnabled();
static void setDeviceDitheringEnabled(bool isEnabled);

static Grab::GrabberType getGrabberType();
static void setGrabberType(Grab::GrabberType grabMode);
Expand Down Expand Up @@ -363,6 +365,7 @@ class Settings : public QObject
void deviceSmoothChanged(int value);
void deviceColorDepthChanged(int value);
void deviceGammaChanged(double gamma);
void deviceDitheringEnabledChanged(bool isEnabled);
void deviceColorSequenceChanged(QString value);
void grabberTypeChanged(const Grab::GrabberType grabMode);
#ifdef D3D10_GRAB_SUPPORT
Expand Down
4 changes: 3 additions & 1 deletion Software/src/SettingsDefaults.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ static const int RefreshDelayMin = 64;
static const int RefreshDelayDefault = 100;
static const int RefreshDelayMax = 1023;

static const bool IsUsbPowerLedDisabled = false;
static const bool IsUsbPowerLedDisabledDefault = false;

static const int BrightnessMin = 0;
static const int BrightnessDefault = 100;
Expand All @@ -241,6 +241,8 @@ static const int ColorDepthMax = 255;
static const double GammaMin = 0.01;
static const double GammaDefault = 2.0;
static const double GammaMax = 10.0;

static const bool IsDitheringEnabledDefault = false;
}
// [LED_i]
namespace Led
Expand Down
33 changes: 23 additions & 10 deletions Software/src/SettingsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ SettingsWindow::SettingsWindow(QWidget *parent) :

initGrabbersRadioButtonsVisibility();
initLanguages();
initVirtualLeds(Settings::getNumberOfLeds(SupportedDevices::DeviceTypeVirtual));

loadTranslation(Settings::getLanguage());

Expand Down Expand Up @@ -265,6 +264,7 @@ void SettingsWindow::connectSignalsSlots()
connect(ui->spinBox_DeviceBrightnessCap, SIGNAL(valueChanged(int)), this, SLOT(onDeviceBrightnessCap_valueChanged(int)));
connect(ui->spinBox_DeviceColorDepth, SIGNAL(valueChanged(int)), this, SLOT(onDeviceColorDepth_valueChanged(int)));
connect(ui->doubleSpinBox_DeviceGamma, SIGNAL(valueChanged(double)), this, SLOT(onDeviceGammaCorrection_valueChanged(double)));
connect(ui->checkBox_EnableDithering, SIGNAL(toggled(bool)), this, SLOT(onDeviceDitheringEnabled_toggled(bool)));
connect(ui->horizontalSlider_GammaCorrection, SIGNAL(valueChanged(int)), this, SLOT(onSliderDeviceGammaCorrection_valueChanged(int)));
connect(ui->checkBox_SendDataOnlyIfColorsChanges, SIGNAL(toggled(bool)), this, SLOT(onDeviceSendDataOnlyIfColorsChanged_toggled(bool)));

Expand Down Expand Up @@ -1393,6 +1393,13 @@ void SettingsWindow::onSliderDeviceGammaCorrection_valueChanged(int value)
emit updateGamma(Settings::getDeviceGamma());
}

void SettingsWindow::onDeviceDitheringEnabled_toggled(bool state) {
DEBUG_LOW_LEVEL << Q_FUNC_INFO << state;

Settings::setDeviceDitheringEnabled(state);
}


void SettingsWindow::onLightpackModes_currentIndexChanged(int index)
{
if (updatingFromSettings) return;
Expand Down Expand Up @@ -1926,25 +1933,26 @@ void SettingsWindow::updateUiFromSettings()

ui->pushButton_SelectColorSoundVizMin->setColor (Settings::getSoundVisualizerMinColor());
ui->pushButton_SelectColorSoundVizMax->setColor (Settings::getSoundVisualizerMaxColor());
ui->radioButton_SoundVizConstantMode->setChecked (!Settings::isSoundVisualizerLiquidMode());
ui->radioButton_SoundVizConstantMode->setChecked (!Settings::isSoundVisualizerLiquidMode());
ui->radioButton_SoundVizLiquidMode->setChecked (Settings::isSoundVisualizerLiquidMode());
ui->horizontalSlider_SoundVizLiquidSpeed->setValue (Settings::getSoundVisualizerLiquidSpeed());
#endif

ui->checkBox_DisableUsbPowerLed->setChecked (Settings::isDeviceUsbPowerLedDisabled());
ui->horizontalSlider_DeviceRefreshDelay->setValue (Settings::getDeviceRefreshDelay());
ui->horizontalSlider_DeviceBrightness->setValue (Settings::getDeviceBrightness());
ui->horizontalSlider_DeviceBrightnessCap->setValue (Settings::getDeviceBrightnessCap());
ui->horizontalSlider_DeviceBrightnessCap->setValue (Settings::getDeviceBrightnessCap());
ui->horizontalSlider_DeviceSmooth->setValue (Settings::getDeviceSmooth());
ui->horizontalSlider_DeviceColorDepth->setValue (Settings::getDeviceColorDepth());
ui->doubleSpinBox_DeviceGamma->setValue (Settings::getDeviceGamma());
ui->horizontalSlider_GammaCorrection->setValue (floor((Settings::getDeviceGamma() * 100 + 0.5)));

ui->groupBox_Api->setChecked (Settings::isApiEnabled());
ui->checkBox_listenOnlyOnLoInterface->setChecked (Settings::isListenOnlyOnLoInterface());
ui->lineEdit_ApiPort->setText (QString::number(Settings::getApiPort()));
ui->lineEdit_ApiPort->setValidator(new QIntValidator(1, 49151));
ui->lineEdit_ApiKey->setText (Settings::getApiAuthKey());
ui->horizontalSlider_GammaCorrection->setValue (floor((Settings::getDeviceGamma() * 100 + 0.5)));
ui->checkBox_EnableDithering->setChecked (Settings::isDeviceDitheringEnabled());

ui->groupBox_Api->setChecked (Settings::isApiEnabled());
ui->checkBox_listenOnlyOnLoInterface->setChecked (Settings::isListenOnlyOnLoInterface());
ui->lineEdit_ApiPort->setText (QString::number(Settings::getApiPort()));
ui->lineEdit_ApiPort->setValidator (new QIntValidator(1, 49151));
ui->lineEdit_ApiKey->setText (Settings::getApiAuthKey());
ui->spinBox_LoggingLevel->setValue (g_debugLevel);

if (g_debugLevel == Debug::DebugLevels::ZeroLevel) {
Expand Down Expand Up @@ -2125,6 +2133,11 @@ void SettingsWindow::on_pushButton_GammaCorrectionHelp_clicked()
showHelpOf(ui->horizontalSlider_GammaCorrection);
}

void SettingsWindow::on_pushButton_DitheringHelp_clicked()
{
showHelpOf(ui->checkBox_EnableDithering);
}

void SettingsWindow::on_pushButton_BrightnessCapHelp_clicked()
{
showHelpOf(ui->horizontalSlider_DeviceBrightnessCap);
Expand Down
2 changes: 2 additions & 0 deletions Software/src/SettingsWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ private slots:
void onDeviceColorDepth_valueChanged(int value);
void onDeviceGammaCorrection_valueChanged(double value);
void onSliderDeviceGammaCorrection_valueChanged(int value);
void onDeviceDitheringEnabled_toggled(bool state);
void onDeviceSendDataOnlyIfColorsChanged_toggled(bool state);
void onDx1011CaptureEnabledChanged(bool isEnabled);
void onDx9CaptureEnabledChanged(bool isEnabled);
Expand Down Expand Up @@ -215,6 +216,7 @@ private slots:
void on_pushButton_LightpackRefreshDelayHelp_clicked();

void on_pushButton_GammaCorrectionHelp_clicked();
void on_pushButton_DitheringHelp_clicked();
void on_pushButton_BrightnessCapHelp_clicked();

void on_pushButton_lumosityThresholdHelp_clicked();
Expand Down
Loading