Skip to content

Commit

Permalink
Pause grabber/flatbuffers while calibrating LUT
Browse files Browse the repository at this point in the history
  • Loading branch information
awawa-dev committed Oct 17, 2024
1 parent d4e5682 commit 838663d
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 11 deletions.
2 changes: 2 additions & 0 deletions include/base/HyperHdrManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class HyperHdrManager : public QObject
bool areInstancesReady();

public slots:
void handleRequestComponent(hyperhdr::Components component, int hyperHdrInd, bool listen);

void setSmoothing(int time);

void setSignalStateByCEC(bool enable);
Expand Down
2 changes: 2 additions & 0 deletions include/flatbuffers/server/FlatBuffersServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class FlatBuffersServer : public QObject, protected LutLoader
void SignalImportFromProto(int priority, int duration, const Image<ColorRgb>& image, QString clientDescription);

public slots:
void handleRequestComponent(hyperhdr::Components component, int hyperHdrInd, bool listen);
void signalSetLutHandler(MemoryBuffer<uint8_t>* lut);
void handleSettingsUpdate(settings::type type, const QJsonDocument& config);
void initServer();
Expand Down Expand Up @@ -72,4 +73,5 @@ private slots:
PixelFormat _currentLutPixelFormat;
int _flatbufferToneMappingMode;
bool _quarterOfFrameMode;
bool _active;
};
4 changes: 2 additions & 2 deletions include/lut-calibrator/CalibrationWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ class CalibrationWorker : public QObject, public QRunnable
const double NITS;
const double3x3& bt2020_to_sRgb;
std::list<std::pair<CapturedColor*, double3>> vertex;
std::atomic<long long int>& weakBestScore;
std::atomic<int>& weakBestScore;
const bool lchCorrection;
std::atomic<bool>& forcedExit;
std::atomic<int>& progress;
public:
CalibrationWorker(BestResult* _bestResult, std::atomic<long long int>& _weakBestScore, YuvConverter* _yuvConverter, const int _id, const int _krIndexStart, const int _krIndexEnd, const int _halfKDelta, const bool _precise, const int _coef,
CalibrationWorker(BestResult* _bestResult, std::atomic<int>& _weakBestScore, YuvConverter* _yuvConverter, const int _id, const int _krIndexStart, const int _krIndexEnd, const int _halfKDelta, const bool _precise, const int _coef,
const std::vector<std::pair<double3, byte2>>& _sampleColors, const int _gamma, const double _gammaHLG, const double _NITS, const double3x3& _bt2020_to_sRgb,
const std::list<CapturedColor*>& _vertex, const bool _lchCorrection, std::atomic<bool>& _forcedExit, std::atomic<int>& _progress) :
yuvConverter(_yuvConverter),
Expand Down
11 changes: 11 additions & 0 deletions sources/base/HyperHdrManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ HyperHdrManager::HyperHdrManager(const QString& rootPath)

connect(&_videoBenchmark, &VideoBenchmark::SignalBenchmarkUpdate, this, &HyperHdrManager::SignalBenchmarkUpdate);
connect(this, &HyperHdrManager::SignalBenchmarkCapture, &_videoBenchmark, &VideoBenchmark::benchmarkCapture);

connect(GlobalSignals::getInstance(), &GlobalSignals::SignalRequestComponent, this, &HyperHdrManager::handleRequestComponent);
}

void HyperHdrManager::handleRequestComponent(hyperhdr::Components component, int hyperHdrInd, bool listen)
{
if (component == hyperhdr::Components::COMP_VIDEOGRABBER && hyperHdrInd == -1)
{
Warning(_log, "Global request to %s USB grabber", (listen) ? "resume" : "pause");
toggleGrabbersAllInstances(listen);
}
}

HyperHdrManager::~HyperHdrManager()
Expand Down
28 changes: 27 additions & 1 deletion sources/flatbuffers/server/FlatBuffersServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,26 @@ FlatBuffersServer::FlatBuffersServer(std::shared_ptr<NetOrigin> netOrigin, const
, _currentLutPixelFormat(PixelFormat::RGB24)
, _flatbufferToneMappingMode(0)
, _quarterOfFrameMode(false)
, _active(false)
{
connect(GlobalSignals::getInstance(), &GlobalSignals::SignalSetLut, this, &FlatBuffersServer::signalSetLutHandler, Qt::BlockingQueuedConnection);
connect(GlobalSignals::getInstance(), &GlobalSignals::SignalRequestComponent, this, &FlatBuffersServer::handleRequestComponent);
}

void FlatBuffersServer::handleRequestComponent(hyperhdr::Components component, int hyperHdrInd, bool listen)
{
if (component == hyperhdr::Components::COMP_FLATBUFSERVER && hyperHdrInd == -1 && _active)
{
Warning(_log, "Global request to %s FlatBuffersServer", (listen) ? "resume" : "pause");
if (listen)
{
startServer();
}
else
{
stopServer();
}
}
}

FlatBuffersServer::~FlatBuffersServer()
Expand Down Expand Up @@ -123,7 +141,15 @@ void FlatBuffersServer::handleSettingsUpdate(settings::type type, const QJsonDoc
// new timeout just for new connections
_timeout = obj["timeout"].toInt(5000);
// enable check
obj["enable"].toBool(true) ? startServer() : stopServer();
_active = obj["enable"].toBool(true);
if (_active)
{
startServer();
}
else
{
stopServer();
}

_quarterOfFrameMode = obj["quarterOfFrameMode"].toBool(false);

Expand Down
35 changes: 33 additions & 2 deletions sources/lut-calibrator/LutCalibrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,17 @@ void LutCalibrator::startHandler()
Debug(_log, message);
connect(GlobalSignals::getInstance(), &GlobalSignals::SignalNewSystemImage, this, &LutCalibrator::setSystemImage, Qt::ConnectionType::UniqueConnection);
}
else
else if (_defaultComp == hyperhdr::COMP_FLATBUFSERVER)
{
auto message = "Using flatbuffers/protobuffers as a source<br/>Waiting for first captured test board..";
notifyCalibrationMessage(message);
Debug(_log, message);
connect(GlobalSignals::getInstance(), &GlobalSignals::SignalSetGlobalImage, this, &LutCalibrator::signalSetGlobalImageHandler, Qt::ConnectionType::UniqueConnection);
}
else
{
error(QString("Cannot use '%1' as a video source for calibration").arg(hyperhdr::componentToString(_defaultComp)));
}
}

void LutCalibrator::stopHandler()
Expand All @@ -355,6 +359,15 @@ void LutCalibrator::stopHandler()
{
emit GlobalSignals::getInstance()->SignalRequestComponent(hyperhdr::Components::COMP_HDR, -1, false);
emit GlobalSignals::getInstance()->SignalRequestComponent(hyperhdr::Components::COMP_HDR, -1, true);

if (_defaultComp == hyperhdr::COMP_VIDEOGRABBER)
{
emit GlobalSignals::getInstance()->SignalRequestComponent(hyperhdr::Components::COMP_VIDEOGRABBER, -1, true);
}
if (_defaultComp == hyperhdr::COMP_FLATBUFSERVER)
{
emit GlobalSignals::getInstance()->SignalRequestComponent(hyperhdr::Components::COMP_FLATBUFSERVER, -1, true);
}
}
}

Expand Down Expand Up @@ -946,7 +959,7 @@ void LutCalibrator::fineTune(bool precise)
const auto white = _capturedColors->all[MAX_IND][MAX_IND][MAX_IND].Y();
double NITS = 0.0;
double maxLevel = 0.0;
std::atomic<long long int> weakBestScore = MAX_CALIBRATION_ERROR;
std::atomic<int> weakBestScore = MAX_CALIBRATION_ERROR;

// prepare vertexes
std::list<CapturedColor*> vertex, masterVertex;
Expand Down Expand Up @@ -1228,6 +1241,15 @@ void LutCalibrator::calibration()
// reload LUT
emit GlobalSignals::getInstance()->SignalRequestComponent(hyperhdr::Components::COMP_HDR, -1, false);
emit GlobalSignals::getInstance()->SignalRequestComponent(hyperhdr::Components::COMP_HDR, -1, true);

if (_defaultComp == hyperhdr::COMP_VIDEOGRABBER)
{
emit GlobalSignals::getInstance()->SignalRequestComponent(hyperhdr::Components::COMP_VIDEOGRABBER, -1, true);
}
if (_defaultComp == hyperhdr::COMP_FLATBUFSERVER)
{
emit GlobalSignals::getInstance()->SignalRequestComponent(hyperhdr::Components::COMP_FLATBUFSERVER, -1, true);
}
}


Expand Down Expand Up @@ -1447,6 +1469,15 @@ void LutCalibrator::calibrate()
sendReport(_log, _yuvConverter->toString());
#endif

if (_defaultComp == hyperhdr::COMP_VIDEOGRABBER)
{
emit GlobalSignals::getInstance()->SignalRequestComponent(hyperhdr::Components::COMP_VIDEOGRABBER, -1, false);
}
if (_defaultComp == hyperhdr::COMP_FLATBUFSERVER)
{
emit GlobalSignals::getInstance()->SignalRequestComponent(hyperhdr::Components::COMP_FLATBUFSERVER, -1, false);
}

bestResult = std::make_shared<BestResult>();
_capturedColors->finilizeBoard();

Expand Down
8 changes: 4 additions & 4 deletions www/content/grabber_calibration.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ <h3 class="page-header text-start"><svg data-src="svg/lut_calibration.svg" width
<div class="callout callout-info text-start ms-3 me-3">
<h4 id="grabber_calibration_intro" style="font-size:16px"></h4>
</div>
<div class="d-flex justify-content-center pt-2 mb-4">
<canvas width="1280px" height="720px" id="canvas">
</canvas>
</div>
<div class="w-100 mb-2 text-center d-inline-block">
<div class="form-check d-inline-block">
<input class="form-check-input ms-2 float-none" type="checkbox" id="chk_debug2" />
Expand All @@ -80,6 +76,10 @@ <h4 id="grabber_calibration_intro" style="font-size:16px"></h4>
<div style="text-align:center;" class="w-100 h-100">
<button id="startCalibration" type="button" style="width: 320px;" class="btn btn-success"><svg data-src="svg/button_play.svg" fill="currentColor" class="svg4hyperhdr"></svg><span data-i18n="general_btn_start">Start</span></button>
</div>
<div class="d-flex justify-content-center pt-2 mb-4 mt-2">
<canvas width="1280px" height="720px" id="canvas">
</canvas>
</div>
<div>
<script>
$.getScript("/js/grabber_calibration.js");
Expand Down
4 changes: 2 additions & 2 deletions www/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1246,10 +1246,10 @@
"option_calibration_intro" : "Please select calibration type",
"option_calibration_video" : "Calibration using a test video played by your favorite video player.<br/>We calibrate LUT taking into account the grabber, player and your TV.",
"option_calibration_classic" : "Calibration using Windows with HDR mode enabled and a web browser.<br/>We calibrate LUT taking into account the grabber and your TV.",
"video_calibration_overview" : "<b>1</b> You need to set the video format of your grabber to MJPEG/YUYV/NV12. Other formats are not supported.<br/><br/><b>2</b> If you calibrate using Flatbuffers, you need to enable tone mapping in its settings. Only the NV12 video format is supported.</br><br/><b>3</b> You can download test files here: <a href='https://github.com/awawa-dev/awawa-dev.github.io/tree/master/calibration'>link</a>. In your player, start playing the test file. You should see it in the HyperHDR video preview. The test screen must take up the entire screen and no extraneous elements, such as the player menu, can be visible.</br><br/><b>4</b> For calibration, you should choose a file with 'hdr' in the name unless your system or player automatically uses SDR to HDR tone mapping. In that case, to adapt to such a scenario, choose a file with 'sdr' in the name.</br><br/><b>5</b> The YUV420 format provides the greatest compatibility with average quality and is the most common. The YUV444 format provides the best quality but it is rare to find materials encoded in this form.</br><br/><b>6</b> <b>If you are calibrating using Windows 11 (using a web browser or video player as the video source), turn off features such as 'Night light', 'Automatic manage color for apps' and 'Auto-HDR'. Do not change the color balance in the graphics driver. The GFX output should support e.g. 10 or 12 bit RGB in full PC range.</b>",
"video_calibration_overview" : "<b>1</b> You need to set the video format of your grabber to MJPEG/YUYV/NV12. Other formats are not supported.<br/><br/><b>2</b> If you calibrate using Flatbuffers, you need to enable tone mapping in its settings. Only the NV12 video format is supported.</br><br/><b>3</b> You can download test files here: <a href='https://github.com/awawa-dev/awawa-dev.github.io/tree/master/calibration'>link</a>. In your player, start playing the test file. You should see it in the HyperHDR video preview. The test screen must take up the entire screen and no extraneous elements, such as the player menu, can be visible.</br><br/><b>4</b> For calibration, you should choose a file with 'hdr' in the name unless your system or player automatically uses SDR to HDR tone mapping or if you plan to calibrate the SDR signal. In that case, to adapt to such a scenario, choose a file with 'sdr' in the name.</br><br/><b>5</b> The limited range YUV420 format provides the greatest compatibility with average to very good quality and is the most popular.. The YUV444 format provides the best quality but it is rare to find materials encoded in this form.</br><br/><b>6</b> <b>If you are calibrating using Windows 11 (using a web browser or video player as the video source), turn off features such as 'Night light', 'Automatic manage color for apps' and 'Auto-HDR'. Do not change the color balance in the graphics driver. The GFX output should support e.g. 10 or 12 bit RGB in full PC range.</b></br><br/><b>7</b> <b>The calculations are very intensive and put a strain on your equipment! <svg data-src='svg/performance_undervoltage.svg' class='svg4hyperhdr ms-1'></svg></b>",
"chk_calibration_debug" : "Debug",
"flatbuffers_nv12_quarter_of_frame_title": "Quarter of frame for NV12",
"flatbuffers_nv12_quarter_of_frame_expl": "The NV12 codec contains four times more information about brightness than about color. This option allows you to reduce CPU load by reducing the height and width of the video frame by 2 without losing color information.",
"chk_lchCorrection" : "LCH color correction",
"grabber_calibration_expl": "This tool allows you to create a new calibrated HDR LUT for your grabber (or external flatbuffers source) as close to the actual input colors as possible.<br/>You need an HDR10 video source that can display this web page, for example: Windows 10 with HDR enabled in the properties of the graphics driver.<br/>The screen may flicker during calibration. The process typically takes about few minutes on a Intel 7 Windows PC (depending on the host CPU resources and the video capturing framerate).<br/><b>The calculations are intensive and put a strain on your equipment.</b><br/>You can monitor the progress in HyperHDR logs using the browser from other device.<br/><br/><br/><b>1</b> If everything is properly connected, this page should be displayed on the TV screen (as HDR content) and live preview in HyperHDR (captured by the grabber).</br><b>2</b> Absolute minimum capturing resolution is 1280x720 (we will verify this). Recommended is 1920x1080 YUV/NV12. Aspect 1920/1080 must be preserved.<br/><b>3</b> You must disable 'Quarter of frame mode' in your grabber properties if it's enabled.<br/><b>4</b> You must set the grabber's video format to MJPEG/NV12/YUV.<br/><b>5</b> Before you run the process please put your WWW browser in the full-screen mode (F11 key, we will verify this).</br><b>6</b> <b>If you are calibrating using Windows 11, turn off features such as 'Night light', 'Automatic manage color for apps' and 'Auto-HDR'. Do not change the color balance in the graphics driver. The GFX output should support e.g. 10 or 12 bit RGB in full PC range.</b><br/><br/>After completing the calibration, your new LUT table file (lut_lin_tables.3d) will be created in the user's HyperHDR home directory and is immediately ready to use when you just enable HDR tone mapping. Please verify HyperHDR logs for details."
"grabber_calibration_expl": "This tool allows you to create a new calibrated HDR LUT for your grabber (or external flatbuffers source) as close to the actual input colors as possible.<br/>You need an HDR10 video source that can display this web page, for example: Windows 10 with HDR enabled in the properties of the graphics driver.<br/>The screen may flicker during calibration. The process typically takes about few minutes on a Intel 7 Windows PC (depending on the host CPU resources and the video capturing framerate).<br/><b>The calculations are very intensive and put a strain on your equipment <svg data-src='svg/performance_undervoltage.svg' class='svg4hyperhdr ms-1'></svg></b><br/>You can monitor the progress in HyperHDR logs using the browser from other device.<br/><br/><br/><b>1</b> If everything is properly connected, this page should be displayed on the TV screen (as HDR content) and live preview in HyperHDR (captured by the grabber).</br><b>2</b> Absolute minimum capturing resolution is 1280x720 (we will verify this). Recommended is 1920x1080 YUV/NV12. Aspect 1920/1080 must be preserved.<br/><b>3</b> You must disable 'Quarter of frame mode' in your grabber properties if it's enabled.<br/><b>4</b> You must set the grabber's video format to MJPEG/NV12/YUV.<br/><b>5</b> Before you run the process please put your WWW browser in the full-screen mode (F11 key, we will verify this).</br><b>6</b> <b>If you are calibrating using Windows 11, turn off features such as 'Night light', 'Automatic manage color for apps' and 'Auto-HDR'. Do not change the color balance in the graphics driver. The GFX output should support e.g. 10 or 12 bit RGB in full PC range.</b><br/><br/>After completing the calibration, your new LUT table file (lut_lin_tables.3d) will be created in the user's HyperHDR home directory and is immediately ready to use when you just enable HDR tone mapping. Please verify HyperHDR logs for details."
}

0 comments on commit 838663d

Please sign in to comment.