From 9a5a5bfd18f5befb7d0b5c2b4e4f54e7699aa1ae Mon Sep 17 00:00:00 2001
From: Awawa <69086569+awawa-dev@users.noreply.github.com>
Date: Thu, 28 Nov 2024 00:46:13 +0100
Subject: [PATCH] More structures
---
include/lut-calibrator/BestResult.h | 2 ++
include/lut-calibrator/BoardUtils.h | 3 +-
include/utils/settings.h | 3 ++
sources/base/hyperhdr.schema.json | 4 +++
sources/base/resource.qrc | 1 +
.../schema/schema-automaticToneMapping.json | 35 +++++++++++++++----
sources/db/SettingsTable.cpp | 2 +-
sources/lut-calibrator/BoardUtils.cpp | 10 +++++-
sources/lut-calibrator/LutCalibrator.cpp | 12 ++++++-
www/i18n/en.json | 10 ++++--
10 files changed, 69 insertions(+), 13 deletions(-)
diff --git a/include/lut-calibrator/BestResult.h b/include/lut-calibrator/BestResult.h
index b615944f..c67c5a62 100644
--- a/include/lut-calibrator/BestResult.h
+++ b/include/lut-calibrator/BestResult.h
@@ -80,6 +80,7 @@ struct BestResult
double upYLimit = 0;
double downYLimit = 0;
double yShift = 0;
+ byte3 yuvRange = {};
bool isSourceP010 = false;
} signal;
@@ -124,6 +125,7 @@ struct BestResult
out << "bestResult.signal.yShift = " << std::to_string(signal.yShift) << ";" << std::endl;
out << "bestResult.signal.isSourceP010 = " << std::to_string(signal.isSourceP010) << ";" << std::endl;
out << "bestResult.minError = " << std::to_string(std::round(minError * 100.0) / 30000.0) << ";" << std::endl;
+ out << "bestResult.signal.yuvRange = byte3{ " << std::to_string(signal.yuvRange[0]) << ", " << std::to_string(signal.yuvRange[1]) << ", " << std::to_string(signal.yuvRange[2]) << "};" << std::endl;
out << "*/" << std::endl;
}
};
diff --git a/include/lut-calibrator/BoardUtils.h b/include/lut-calibrator/BoardUtils.h
index 9a36427d..b3ab7ec1 100644
--- a/include/lut-calibrator/BoardUtils.h
+++ b/include/lut-calibrator/BoardUtils.h
@@ -84,6 +84,7 @@ namespace BoardUtils
double _yShift = 0;
double _downYLimit = 0;
double _upYLimit = 0;
+ byte3 _rangeYUV = {};
public:
CapturedColors() = default;
@@ -96,7 +97,7 @@ namespace BoardUtils
bool areAllCaptured();
void finilizeBoard();
static void correctYRange(double3& yuv, double yRange, double upYLimit, double downYLimit, double yShift);
- void getSignalParams(double& yRange, double& upYLimit, double& downYLimit, double& yShift);
+ void getSignalParams(double& yRange, double& upYLimit, double& downYLimit, double& yShift, byte3& rangeYUV);
void setCaptured(int index);
void setRange(YuvConverter::COLOR_RANGE range);
YuvConverter::COLOR_RANGE getRange() const;
diff --git a/include/utils/settings.h b/include/utils/settings.h
index 6858ab3b..904a9daf 100644
--- a/include/utils/settings.h
+++ b/include/utils/settings.h
@@ -33,6 +33,7 @@ namespace settings {
RAWUDPSERVER,
PROTOSERVER,
MQTT,
+ AUTOTONEMAPPING,
INVALID
};
@@ -65,6 +66,7 @@ namespace settings {
case type::RAWUDPSERVER: return "rawUdpServer";
case type::PROTOSERVER: return "protoServer";
case type::MQTT: return "mqtt";
+ case type::AUTOTONEMAPPING: return "automaticToneMapping";
default: return "invalid";
}
}
@@ -96,6 +98,7 @@ namespace settings {
else if (type == "rawUdpServer") return type::RAWUDPSERVER;
else if (type == "protoServer") return type::PROTOSERVER;
else if (type == "mqtt") return type::MQTT;
+ else if (type == "automaticToneMapping") return type::AUTOTONEMAPPING;
else return type::INVALID;
}
}
diff --git a/sources/base/hyperhdr.schema.json b/sources/base/hyperhdr.schema.json
index 09e45539..eb48d61d 100644
--- a/sources/base/hyperhdr.schema.json
+++ b/sources/base/hyperhdr.schema.json
@@ -102,6 +102,10 @@
"mqtt":
{
"$ref": "schema-mqtt.json"
+ },
+ "automaticToneMapping" :
+ {
+ "$ref": "schema-automaticToneMapping.json"
}
},
"additionalProperties" : false
diff --git a/sources/base/resource.qrc b/sources/base/resource.qrc
index 71197887..0d4d028f 100644
--- a/sources/base/resource.qrc
+++ b/sources/base/resource.qrc
@@ -26,5 +26,6 @@
schema/schema-videoDetection.json
schema/schema-network.json
schema/schema-mqtt.json
+ schema/schema-automaticToneMapping.json
diff --git a/sources/base/schema/schema-automaticToneMapping.json b/sources/base/schema/schema-automaticToneMapping.json
index a8c94fd6..f492a61a 100644
--- a/sources/base/schema/schema-automaticToneMapping.json
+++ b/sources/base/schema/schema-automaticToneMapping.json
@@ -12,19 +12,42 @@
"required" : true,
"propertyOrder" : 1
},
- "tone_mapping_threshold" :
+ "tone_mapping_y_threshold" :
{
"type" : "integer",
"format": "stepper",
"step" : 1,
- "title" : "edt_automatic_tone_mapping_threshold_title",
- "minimum" : 155,
+ "title" : "edt_automatic_tone_mapping_y_threshold_title",
+ "minimum" : 150,
"maximum" : 255,
- "default" : 165,
- "append" : "edt_append_percent",
+ "default" : 155,
"required" : true,
"propertyOrder" : 2
},
+ "tone_mapping_u_threshold" :
+ {
+ "type" : "integer",
+ "format": "stepper",
+ "step" : 1,
+ "title" : "edt_automatic_tone_mapping_u_threshold_title",
+ "minimum" : 165,
+ "maximum" : 255,
+ "default" : 175,
+ "required" : true,
+ "propertyOrder" : 3
+ },
+ "tone_mapping_v_threshold" :
+ {
+ "type" : "integer",
+ "format": "stepper",
+ "step" : 1,
+ "title" : "edt_automatic_tone_mapping_v_threshold_title",
+ "minimum" : 155,
+ "maximum" : 255,
+ "default" : 160,
+ "required" : true,
+ "propertyOrder" : 4
+ },
"time_to_tone_mapping" :
{
"type" : "integer",
@@ -36,7 +59,7 @@
"default" : 30,
"append" : "edt_append_s",
"required" : true,
- "propertyOrder" : 3
+ "propertyOrder" : 5
}
},
"additionalProperties" : false
diff --git a/sources/db/SettingsTable.cpp b/sources/db/SettingsTable.cpp
index f54d2254..1c772cf4 100644
--- a/sources/db/SettingsTable.cpp
+++ b/sources/db/SettingsTable.cpp
@@ -122,7 +122,7 @@ bool SettingsTable::isSettingGlobal(const QString& type) const
<< settings::typeToString(settings::type::VIDEOGRABBER) << settings::typeToString(settings::type::SYSTEMGRABBER)
<< settings::typeToString(settings::type::LOGGER) << settings::typeToString(settings::type::GENERAL)
<< settings::typeToString(settings::type::SNDEFFECT) << settings::typeToString(settings::type::VIDEODETECTION)
- << settings::typeToString(settings::type::MQTT)
+ << settings::typeToString(settings::type::MQTT) << settings::typeToString(settings::type::AUTOTONEMAPPING)
// legacy
<< "grabberV4L2";
diff --git a/sources/lut-calibrator/BoardUtils.cpp b/sources/lut-calibrator/BoardUtils.cpp
index 31a8a89e..28b9dd7c 100644
--- a/sources/lut-calibrator/BoardUtils.cpp
+++ b/sources/lut-calibrator/BoardUtils.cpp
@@ -443,6 +443,13 @@ namespace BoardUtils
for (int b = 0; b < SCREEN_COLOR_DIMENSION; b++)
{
all[r][g][b].setCoords(byte3(r, g, b));
+
+ if (all[r][g][b].Y() > _rangeYUV.x)
+ _rangeYUV.x = all[r][g][b].Y();
+ if (all[r][g][b].U() > _rangeYUV.y)
+ _rangeYUV.y = all[r][g][b].U();
+ if (all[r][g][b].V() > _rangeYUV.z)
+ _rangeYUV.z = all[r][g][b].V();
}
}
@@ -451,12 +458,13 @@ namespace BoardUtils
yuv.x = ((yuv.x - downYLimit) / (upYLimit - downYLimit)) * yRange + yShift;
}
- void CapturedColors::getSignalParams(double& yRange, double& upYLimit, double& downYLimit, double& yShift)
+ void CapturedColors::getSignalParams(double& yRange, double& upYLimit, double& downYLimit, double& yShift, byte3& rangeYUV)
{
yRange = _yRange;
upYLimit = _upYLimit;
downYLimit = _downYLimit;
yShift = _yShift;
+ rangeYUV = _rangeYUV;
}
void CapturedColors::setCaptured(int index)
diff --git a/sources/lut-calibrator/LutCalibrator.cpp b/sources/lut-calibrator/LutCalibrator.cpp
index e56057fb..2d6b3c5b 100644
--- a/sources/lut-calibrator/LutCalibrator.cpp
+++ b/sources/lut-calibrator/LutCalibrator.cpp
@@ -1125,7 +1125,7 @@ void LutCalibrator::fineTune(bool precise)
// set startup parameters (signal)
bestResult->signal.range = _capturedColors->getRange();
- _capturedColors->getSignalParams(bestResult->signal.yRange, bestResult->signal.upYLimit, bestResult->signal.downYLimit, bestResult->signal.yShift);
+ _capturedColors->getSignalParams(bestResult->signal.yRange, bestResult->signal.upYLimit, bestResult->signal.downYLimit, bestResult->signal.yShift, bestResult->signal.yuvRange);
if (bestResult->signal.isSourceP010)
{
@@ -1136,6 +1136,16 @@ void LutCalibrator::fineTune(bool precise)
double down = bestResult->signal.downYLimit;
unpackP010(&down, nullptr, nullptr);
bestResult->signal.downYLimit = down;
+
+ double3 yuvrange = static_cast(bestResult->signal.yuvRange);
+ yuvrange.x /= 255.0;
+ yuvrange.y = (yuvrange.y - 128.0) / 128.0;
+ yuvrange.z = (yuvrange.z - 128.0) / 128.0;
+ unpackP010(yuvrange);
+ yuvrange.x *= 255.0;
+ yuvrange.y = yuvrange.y * 128.0 + 128.0;
+ yuvrange.z = yuvrange.z * 128.0 + 128.0;
+ bestResult->signal.yuvRange = static_cast(yuvrange);
}
if (bestResult->signal.range == YuvConverter::COLOR_RANGE::LIMITED)
diff --git a/www/i18n/en.json b/www/i18n/en.json
index d41d3ca2..8d41e787 100644
--- a/www/i18n/en.json
+++ b/www/i18n/en.json
@@ -1255,8 +1255,12 @@
"edt_automatic_tone_mapping_title" : "Automatic tone mapping",
"edt_automatic_tone_mapping_enable_title" : "Enable automatic tone mapping",
"edt_automatic_tone_mapping_enable_expl" : "Automatic tone mapping is only available for YUV/NV12/P010 formats with 'Quarter of frame' mode enabled",
- "edt_automatic_tone_mapping_threshold_title" : "Brightness threshold",
- "edt_automatic_tone_mapping_threshold_expl" : "The brightness level that separates raw dark HDR material from the SDR signal",
+ "edt_automatic_tone_mapping_y_threshold_title" : "Brightness threshold (Y)",
+ "edt_automatic_tone_mapping_y_threshold_expl" : "The brightness level that separates raw dark HDR material from the SDR signal",
+ "edt_automatic_tone_mapping_u_threshold_title" : "Blue chroma threshold (U)",
+ "edt_automatic_tone_mapping_u_threshold_expl" : "Blue chroma level that separates raw pale HDR material from the SDR signal",
+ "edt_automatic_tone_mapping_v_threshold_title" : "Red chroma threshold (V)",
+ "edt_automatic_tone_mapping_v_threshold_expl" : "Red chroma level that separates raw pale HDR material from the SDR signal",
"edt_automatic_tone_mapping_time_title" : "Time to turn on tone mapping",
- "edt_automatic_tone_mapping_time_title_expl" : "Time to turn on tone mapping if the signal does not exceed the set brightness level"
+ "edt_automatic_tone_mapping_time_title_expl" : "Time to turn on tone mapping if the signal does not exceed the configured threshold levels"
}