Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDR tone mapping for flatbuffers #215

Merged
merged 10 commits into from
Feb 27, 2022
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
4 changes: 3 additions & 1 deletion assets/webconfig/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1144,5 +1144,7 @@
"perf_no" : "No",
"perf_decoding_time": "time",
"perf_frames" : "frames",
"perf_invalid_frames" : "invalid frames"
"perf_invalid_frames" : "invalid frames",
"edt_conf_fbs_tonemapping_expl": "If enabled, HyperHDR will try to correct colors of the HDR10 content that was received by flatbuffers as SDR format. Default 3D LUT file <span class='fw-bold'>'lut_lin_tables.3d'</span> is already included.<span class='fw-bold'> You can generate one and preview the effect using link in the 'Advanced menu'.</span><br/>Your typical hidden configuration folder to upload that file in is (check 'Logs' page to confirm):<br/> Rpi→&#47;home&#47;pi&#47;.hyperhdr<br/>Windows→c:&#47;Users&#47;NAME&#47;.hyperhdr",
"edt_conf_fbs_tonemapping_title": "HDR to SDR tone mapping"
}
5 changes: 5 additions & 0 deletions include/flatbufserver/FlatBufferConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class FlatBufferConnection : public QObject
///
void sendMessage(const uint8_t* buffer, uint32_t size);

bool isFree();

public slots:
///
/// @brief Set the leds according to the given image
Expand All @@ -100,6 +102,8 @@ private slots:
///
///void setVideoModeHdr(int hdr);

void onImage(const Image<ColorRgb>& image);

private:

///
Expand Down Expand Up @@ -132,4 +136,5 @@ private slots:
flatbuffers::FlatBufferBuilder _builder;

bool _registered;
bool _free;
};
27 changes: 26 additions & 1 deletion include/flatbufserver/FlatBufferServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ class FlatBufferServer : public QObject
{
Q_OBJECT
public:
FlatBufferServer(const QJsonDocument& config, QObject* parent = nullptr);
FlatBufferServer(const QJsonDocument& config, const QString& configurationPath, QObject* parent = nullptr);
~FlatBufferServer() override;

static FlatBufferServer* instance;
static FlatBufferServer* getInstance() { return instance; }

signals:
void hdrToneMappingChanged(bool enabled, uint8_t* lutBuffer);

public slots:
///
/// @brief Handle settings update
Expand All @@ -34,6 +40,8 @@ public slots:

void initServer();

void setHdrToneMappingEnabled(bool enabled);

private slots:
///
/// @brief Is called whenever a new socket wants to connect
Expand All @@ -57,6 +65,17 @@ private slots:
void stopServer();


///
/// @brief Get shared LUT file folder
///
QString GetSharedLut();

///
/// @brief Load LUT file
///
void loadLutFile();


private:
QTcpServer* _server;
NetOrigin* _netOrigin;
Expand All @@ -67,4 +86,10 @@ private slots:
BonjourServiceRegister* _serviceRegister = nullptr;

QVector<FlatBufferClient*> _openConnections;

// tone mapping
bool _hdrToneMappingEnabled;
uint8_t* _lutBuffer;
bool _lutBufferInit;
QString _configurationPath;
};
9 changes: 7 additions & 2 deletions sources/api/API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <HyperhdrConfig.h>
#include <utils/SysInfo.h>
#include <utils/ColorSys.h>
#include <flatbufserver/FlatBufferServer.h>

// bonjour wrapper
#include <bonjour/bonjourbrowserwrapper.h>
Expand Down Expand Up @@ -211,7 +212,7 @@ bool API::setComponentState(const QString& comp, bool& compState, QString& reply
input = "VIDEOGRABBER";
Components component = stringToComponent(input);
if (component == COMP_ALL)
{
{
QMetaObject::invokeMethod(HyperHdrIManager::getInstance(), "toggleStateAllInstances", Qt::QueuedConnection, Q_ARG(bool, compState));

return true;
Expand All @@ -237,7 +238,11 @@ void API::setLedMappingType(int type, hyperhdr::Components callerComp)

void API::setVideoModeHdr(int hdr, hyperhdr::Components callerComp)
{
QMetaObject::invokeMethod(GrabberWrapper::getInstance(), "setHdrToneMappingEnabled", Qt::QueuedConnection, Q_ARG(int, hdr));
if (GrabberWrapper::getInstance() != nullptr)
QMetaObject::invokeMethod(GrabberWrapper::getInstance(), "setHdrToneMappingEnabled", Qt::QueuedConnection, Q_ARG(int, hdr));

if (FlatBufferServer::getInstance() != nullptr)
QMetaObject::invokeMethod(FlatBufferServer::getInstance(), "setHdrToneMappingEnabled", Qt::QueuedConnection, Q_ARG(bool, hdr));
}

bool API::setEffect(const EffectCmdData& dat, hyperhdr::Components callerComp)
Expand Down
17 changes: 16 additions & 1 deletion sources/flatbufserver/FlatBufferClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
#include <QTimer>
#include <QRgb>

FlatBufferClient::FlatBufferClient(QTcpSocket* socket, int timeout, QObject* parent)
// util includes
#include <utils/FrameDecoder.h>

FlatBufferClient::FlatBufferClient(QTcpSocket* socket, int timeout, bool hdrToneMappingEnabled, uint8_t* lutBuffer, QObject* parent)
: QObject(parent)
, _log(Logger::getInstance("FLATBUFSERVER"))
, _socket(socket)
, _clientAddress("@" + socket->peerAddress().toString())
, _timeoutTimer(new QTimer(this))
, _timeout(timeout * 1000)
, _priority()
, _hdrToneMappingEnabled(hdrToneMappingEnabled)
, _lutBuffer(lutBuffer)
{
// timer setup
_timeoutTimer->setSingleShot(true);
Expand Down Expand Up @@ -65,6 +70,12 @@ void FlatBufferClient::forceClose()
_socket->close();
}

void FlatBufferClient::setHdrToneMappingEnabled(bool enabled, uint8_t* lutBuffer)
{
_hdrToneMappingEnabled = enabled;
_lutBuffer = lutBuffer;
}

void FlatBufferClient::disconnected()
{
Debug(_log, "Socket Closed");
Expand Down Expand Up @@ -164,6 +175,10 @@ void FlatBufferClient::handleImageCommand(const hyperhdrnet::Image* image)

Image<ColorRgb> imageDest(width, height);
memmove(imageDest.memptr(), imageData->data(), imageData->size());

// tone mapping
FrameDecoder::applyLUT((uint8_t*)imageDest.memptr(), imageDest.width(), imageDest.height(), _lutBuffer, _hdrToneMappingEnabled);

emit setGlobalInputImage(_priority, imageDest, duration);
}

Expand Down
11 changes: 10 additions & 1 deletion sources/flatbufserver/FlatBufferClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class FlatBufferClient : public QObject
/// @param timeout The timeout when a client is automatically disconnected and the priority unregistered
/// @param parent The parent
///
explicit FlatBufferClient(QTcpSocket* socket, int timeout, QObject* parent = nullptr);
explicit FlatBufferClient(QTcpSocket* socket, int timeout, bool hdrToneMappingEnabled, uint8_t* lutBuffer, QObject* parent = nullptr);

signals:
///
Expand Down Expand Up @@ -65,6 +65,11 @@ public slots:
///
void forceClose();

///
/// @brief Change HDR tone mapping
///
void setHdrToneMappingEnabled(bool enabled, uint8_t* lutBuffer);

private slots:
///
/// @brief Is called whenever the socket got new data to read
Expand Down Expand Up @@ -140,4 +145,8 @@ private slots:

// Flatbuffers builder
flatbuffers::FlatBufferBuilder _builder;

// tone mapping
bool _hdrToneMappingEnabled;
uint8_t* _lutBuffer;
};
13 changes: 13 additions & 0 deletions sources/flatbufserver/FlatBufferConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ FlatBufferConnection::FlatBufferConnection(const QString& origin, const QString&
, _prevSocketState(QAbstractSocket::UnconnectedState)
, _log(Logger::getInstance("FLATBUFCONN"))
, _registered(false)
, _free(true)
{
QStringList parts = address.split(":");
if (parts.size() != 2)
Expand Down Expand Up @@ -45,6 +46,8 @@ FlatBufferConnection::FlatBufferConnection(const QString& origin, const QString&

connect(&_timer, &QTimer::timeout, this, &FlatBufferConnection::connectToHost);
_timer.start();

connect(this, &FlatBufferConnection::onImage, this, &FlatBufferConnection::setImage);
}

FlatBufferConnection::~FlatBufferConnection()
Expand Down Expand Up @@ -126,6 +129,8 @@ void FlatBufferConnection::setColor(const ColorRgb& color, int priority, int dur

void FlatBufferConnection::setImage(const Image<ColorRgb>& image)
{
_free = false;

auto imgData = _builder.CreateVector(reinterpret_cast<const uint8_t*>(image.memptr()), image.size());
auto rawImg = hyperhdrnet::CreateRawImage(_builder, imgData, image.width(), image.height());
auto imageReq = hyperhdrnet::CreateImage(_builder, hyperhdrnet::ImageType_RawImage, rawImg.Union(), -1);
Expand All @@ -134,6 +139,14 @@ void FlatBufferConnection::setImage(const Image<ColorRgb>& image)
_builder.Finish(req);
sendMessage(_builder.GetBufferPointer(), _builder.GetSize());
_builder.Clear();

_free = true;
}


bool FlatBufferConnection::isFree()
{
return _free;
}

void FlatBufferConnection::clear(int priority)
Expand Down
Loading