Skip to content

Commit

Permalink
Save and apply recommended: brightness, contrast, saturation
Browse files Browse the repository at this point in the history
  • Loading branch information
awawa-dev committed May 18, 2023
1 parent a6c383d commit b9ce4b3
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 31 deletions.
2 changes: 2 additions & 0 deletions include/base/HyperHdrInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public slots:

void saveCalibration(QString saveData);

void saveGrabberParams(int hardware_brightness, int hardware_contrast, int hardware_saturation);

///
/// Updates the priority muxer with the current time and (re)writes the led color with applied
/// transforms.
Expand Down
3 changes: 2 additions & 1 deletion sources/api/JsonAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ void JsonAPI::lutDownloaded(QNetworkReply* reply, int hardware_brightness, int h
Info(_log, "Reloading LUT...");
API::setVideoModeHdr(0);
API::setVideoModeHdr(1);
QTimer::singleShot(0, _hyperhdr, [=]() { _hyperhdr->saveGrabberParams(hardware_brightness, hardware_contrast, hardware_saturation); });
Info(_log, "New LUT has been installed as: %s (from: %s)", QSTRING_CSTR(fileName), QSTRING_CSTR(reply->url().toString()));
}
else
Expand All @@ -885,7 +886,7 @@ void JsonAPI::handleLutInstallCommand(const QJsonObject& message, const QString&
int hardware_brightness = message["hardware_brightness"].toInt(0);
int hardware_contrast = message["hardware_contrast"].toInt(0);
int hardware_saturation = message["hardware_saturation"].toInt(0);
qint64 time = message["now"].toInteger(0);
qint64 time = message["now"].toInt(0);

Debug(_log, "Request to install LUT from: %s (params => [%i, %i, %i])", QSTRING_CSTR(address),
hardware_brightness, hardware_contrast, hardware_saturation);
Expand Down
2 changes: 1 addition & 1 deletion sources/base/Grabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ QJsonObject Grabber::getJsonInfo()
for (int i = 0; i < 256; i += 2)
for (int j = 32; j <= 160; j+= 64)
{
checkSum ^= *(reinterpret_cast<uint32_t*>(&(_lutBuffer[LUT_INDEX(j, i, 255 - i)])));
checkSum ^= *(reinterpret_cast<uint32_t*>(&(_lutBuffer[LUT_INDEX(j, i, (255 - i))])));
}
grabbers["lutFastCRC"] = "0x" + QString("%1").arg(checkSum, 4, 16).toUpper();
}
Expand Down
10 changes: 10 additions & 0 deletions sources/base/HyperHdrInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,16 @@ bool HyperHdrInstance::setInput(int priority, const std::vector<ColorRgb>& ledCo
return false;
}

void HyperHdrInstance::saveGrabberParams(int hardware_brightness, int hardware_contrast, int hardware_saturation)
{
QJsonDocument newSet = _settingsManager->getSetting(settings::type::VIDEOGRABBER);
QJsonObject grabber = QJsonObject(newSet.object());
grabber["hardware_brightness"] = hardware_brightness;
grabber["hardware_contrast"] = hardware_contrast;
grabber["hardware_saturation"] = hardware_saturation;
_settingsManager->saveSetting(settings::type::VIDEOGRABBER, QJsonDocument(grabber).toJson(QJsonDocument::Compact));
}

bool HyperHdrInstance::setInputImage(int priority, const Image<ColorRgb>& image, int64_t timeout_ms, bool clearEffect)
{
if (!_muxer.hasPriority(priority))
Expand Down
70 changes: 43 additions & 27 deletions sources/db/DBManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,43 +201,59 @@ bool DBManager::updateRecord(const VectorPair& conditions, const QVariantMap& co
}

QSqlDatabase idb = getDB();
QSqlQuery query(idb);
query.setForwardOnly(true);
if (idb.transaction())
{

QVariantList values;
QStringList prep;
QSqlQuery query(idb);
query.setForwardOnly(true);

// prepare columns valus
QVariantMap::const_iterator i = columns.constBegin();
while (i != columns.constEnd()) {
prep += i.key() + "=?";
values += i.value();
QVariantList values;
QStringList prep;

++i;
}
// prepare columns valus
QVariantMap::const_iterator i = columns.constBegin();
while (i != columns.constEnd()) {
prep += i.key() + "=?";
values += i.value();

// prepare condition values
QStringList prepCond;
QVariantList prepBindVal;
if (!conditions.isEmpty())
prepCond << "WHERE";
++i;
}

for (const auto& pair : conditions)
// prepare condition values
QStringList prepCond;
QVariantList prepBindVal;
if (!conditions.isEmpty())
prepCond << "WHERE";

for (const auto& pair : conditions)
{
prepCond << pair.first + "=?";
prepBindVal << pair.second;
}

query.prepare(QString("UPDATE %1 SET %2 %3").arg(_table, prep.join(", ")).arg(prepCond.join(" ")));
// add column values
doAddBindValue(query, values);
// add condition values
doAddBindValue(query, prepBindVal);
if (!query.exec())
{
Error(_log, "Failed to update record: '%s' in table: '%s' Error: %s", QSTRING_CSTR(prepCond.join(" ")), QSTRING_CSTR(_table), QSTRING_CSTR(idb.lastError().text()));
idb.rollback();
return false;
}
}
else
{
prepCond << pair.first + "=?";
prepBindVal << pair.second;
Error(_log, "Could not create a DB transaction. Error: %s", QSTRING_CSTR(idb.lastError().text()));
return false;
}

query.prepare(QString("UPDATE %1 SET %2 %3").arg(_table, prep.join(", ")).arg(prepCond.join(" ")));
// add column values
doAddBindValue(query, values);
// add condition values
doAddBindValue(query, prepBindVal);
if (!query.exec())
if (!idb.commit())
{
Error(_log, "Failed to update record: '%s' in table: '%s' Error: %s", QSTRING_CSTR(prepCond.join(" ")), QSTRING_CSTR(_table), QSTRING_CSTR(idb.lastError().text()));
return false;
Error(_log, "Could not commit the DB transaction. Error: %s", QSTRING_CSTR(idb.lastError().text()));
}

return true;
}

Expand Down
5 changes: 4 additions & 1 deletion sources/grabber/MF/MFGrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,10 @@ bool MFGrabber::init()
bool strict = false;
const auto& val = dev.valid[i];

if (bestGuess == -1 || (val.x <= bestGuessMinX && val.x >= 640 && val.fps <= bestGuessMinFPS && val.fps >= 10))
if (bestGuess == -1 ||
(val.x <= bestGuessMinX && val.x >= 640 &&
((val.x > 800 && val.fps <= bestGuessMinFPS && val.fps >= 10) ||
(val.x <= 800 && val.fps > bestGuessMinFPS))))
{
bestGuess = i;
bestGuessMinFPS = val.fps;
Expand Down
5 changes: 4 additions & 1 deletion sources/grabber/v4l2/V4L2Grabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ bool V4L2Grabber::init()
bool strict = false;
const auto& val = dev.valid[i];

if (bestGuess == -1 || (val.x <= bestGuessMinX && val.x >= 640 && (val.fps <= bestGuessMinFPS || val.fps <= 60) && val.fps >= 10))
if (bestGuess == -1 ||
(val.x <= bestGuessMinX && val.x >= 640 &&
((val.x > 800 && val.fps <= bestGuessMinFPS && val.fps >= 10) ||
(val.x <= 800 && val.fps > bestGuessMinFPS))))
{
bestGuess = i;
bestGuessMinFPS = val.fps;
Expand Down

0 comments on commit b9ce4b3

Please sign in to comment.