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

Add P010 HDR10 video format support #968

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@
[submodule "external/stb"]
path = external/stb
url = https://github.com/nothings/stb.git
[submodule "external/linalg"]
path = external/linalg
url = https://github.com/sgorsten/linalg.git
13 changes: 5 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -550,14 +550,11 @@ if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-psabi")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-psabi")
endif()
if(COMPILER_SUPPORTS_CXX17 AND Qt_VERSION EQUAL 6)
message(STATUS "Enabling support for C++17 for QT6")
if(COMPILER_SUPPORTS_CXX17)
message(STATUS "Enabling support for C++17")
set(CMAKE_CXX_STANDARD 17)
elseif(COMPILER_SUPPORTS_CXX11)
message(STATUS "Enabling support for C++11")
set(CMAKE_CXX_STANDARD 11)
else()
message(STATUS "No support for C++11 detected. Compilation will most likely fail on your compiler")
message(STATUS "No support for C++17 detected. Compilation will most likely fail on your compiler")
endif()
else()
include(CheckCXXCompilerFlag)
Expand Down Expand Up @@ -691,8 +688,8 @@ add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_D
include (${CMAKE_CURRENT_SOURCE_DIR}/cmake/packages.cmake)

# external targets
if (WIN32 AND TARGET stb AND TARGET flatbuffers AND TARGET protobuf-nanopb AND TARGET lunasvg AND TARGET flatc AND TARGET qmqtt AND TARGET liblzma AND TARGET sqlite3)
set_target_properties(stb qmqtt flatbuffers protobuf-nanopb lunasvg flatc resources uninstall liblzma sqlite3 PROPERTIES FOLDER ExternalLibsTargets)
if (WIN32 AND TARGET stb AND TARGET flatbuffers AND TARGET protobuf-nanopb AND TARGET lunasvg AND TARGET flatc AND TARGET qmqtt AND TARGET liblzma AND TARGET sqlite3 AND TARGET precompiled_hyperhdr_headers)
set_target_properties(stb qmqtt flatbuffers protobuf-nanopb lunasvg flatc resources uninstall liblzma sqlite3 precompiled_hyperhdr_headers PROPERTIES FOLDER ExternalLibsTargets)
else()
set_target_properties(resources uninstall PROPERTIES FOLDER ExternalLibsTargets)
endif()
Expand Down
8 changes: 8 additions & 0 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ if(ENABLE_WS281XPWM)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/rpi_ws281x)
endif()

#=============================================================================
# LINALG
#=============================================================================

add_library(linalg INTERFACE)
target_compile_definitions(linalg INTERFACE LINALG_FORWARD_COMPATIBLE )
target_include_directories(linalg INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/linalg")

#=============================================================================
# LUNASVG
#=============================================================================
Expand Down
1 change: 1 addition & 0 deletions external/linalg
Submodule linalg added at 4460f1
16 changes: 11 additions & 5 deletions include/api/BaseAPI.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#pragma once

#ifndef PCH_ENABLED
#include <QThread>
#include <memory>
#endif

#include <base/HyperHdrInstance.h>
#include <base/HyperHdrManager.h>
#include <base/AccessManager.h>
Expand All @@ -18,12 +23,12 @@ class BaseAPI : public QObject

struct ImageCmdData
{
int priority;
int priority = 0;
QString origin;
int64_t duration;
int width;
int height;
int scale;
int64_t duration = 0;
int width = 0;
int height = 0;
int scale = 0;
QString format;
QString imgName;
QString imagedata;
Expand Down Expand Up @@ -122,6 +127,7 @@ class BaseAPI : public QObject
std::shared_ptr<GrabberHelper> _systemGrabber;
std::shared_ptr<PerformanceCounters> _performanceCounters;
std::shared_ptr<DiscoveryWrapper> _discoveryWrapper;
std::unique_ptr<QThread, std::function<void(QThread*)>> _lutCalibratorThread;

struct {
bool init = false;
Expand Down
4 changes: 2 additions & 2 deletions include/api/CallbackAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class CallbackAPI : public BaseAPI
void subscribe(QJsonArray subsArr);

protected:
std::unique_ptr<LutCalibrator> _lutCalibrator;
Image<ColorRgb> _liveImage;

void stopDataConnections() override = 0;
Expand All @@ -59,11 +58,12 @@ private slots:
void instancesListChangedHandler();
void tokenChangeHandler(const QVector<AccessManager::AuthDefinition>& def);
void signalBenchmarkUpdateHandler(int status, QString message);
void lutCalibrationUpdateHandler(const QJsonObject& data);
void performanceUpdateHandler(const QJsonObject& data);
#ifdef ENABLE_BONJOUR
void signalDiscoveryFoundServiceHandler(DiscoveryRecord::Service type, QList<DiscoveryRecord> records);
#endif
public slots:
void lutCalibrationUpdateHandler(const QJsonObject& data);

private:
QStringList _availableCommands;
Expand Down
11 changes: 5 additions & 6 deletions include/base/Grabber.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ class Grabber : public DetectionAutomatic, public DetectionManual, protected Lut

void setSignalDetectionEnable(bool enable);

void setAutoSignalDetectionEnable(bool enable);

void benchmarkCapture(int status, QString message);
void setAutoSignalDetectionEnable(bool enable);

QList<Grabber::DevicePropertiesItem> getVideoDeviceModesFullInfo(const QString& devicePath);

Expand Down Expand Up @@ -163,6 +161,8 @@ public slots:

QStringList getVideoDevices() const;

void signalSetLutHandler(MemoryBuffer<uint8_t>* lut);

signals:
void SignalNewCapturedFrame(const Image<ColorRgb>& image);

Expand All @@ -176,6 +176,8 @@ public slots:

int getTargetSystemFrameDimension(int& targetSizeX, int& targetSizeY);

int getTargetSystemFrameDimension(int actualWidth, int actualHeight, int& targetSizeX, int& targetSizeY);

void processSystemFrameBGRA(uint8_t* source, int lineSize = 0, bool useLut = true);

void processSystemFrameBGR(uint8_t* source, int lineSize = 0);
Expand Down Expand Up @@ -268,9 +270,6 @@ public slots:
bool _signalDetectionEnabled;
bool _signalAutoDetectionEnabled;
QSemaphore _synchro;

int _benchmarkStatus;
QString _benchmarkMessage;
};

bool sortDevicePropertiesItem(const Grabber::DevicePropertiesItem& v1, const Grabber::DevicePropertiesItem& v2);
3 changes: 0 additions & 3 deletions include/base/GrabberWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public slots:
void stop();
void revive();

void benchmarkCapture(int status, QString message);

QJsonObject getJsonInfo();

QJsonDocument startCalibration();
Expand All @@ -57,7 +55,6 @@ private slots:
void SignalNewVideoImage(const QString& name, const Image<ColorRgb>& image);
void SignalVideoStreamChanged(QString device, QString videoMode);
void SignalCecKeyPressed(int key);
void SignalBenchmarkUpdate(int status, QString message);
void SignalInstancePauseChanged(int instance, bool isEnabled);
void SignalSetNewComponentStateToAllInstances(hyperhdr::Components component, bool enable);
void SignalSaveCalibration(QString saveData);
Expand Down
7 changes: 7 additions & 0 deletions include/base/HyperHdrManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#endif

#include <image/ColorRgb.h>
#include <utils/VideoBenchmark.h>
#include <utils/Logger.h>
#include <utils/settings.h>
#include <utils/Components.h>
Expand Down Expand Up @@ -43,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 Expand Up @@ -101,6 +104,9 @@ public slots:

void SignalInstancePauseChanged(int instance, bool isEnabled);

void SignalBenchmarkUpdate(int status, QString message);
void SignalBenchmarkCapture(int status, QString message);

private slots:
void handleInstanceJustStarted();

Expand All @@ -126,4 +132,5 @@ private slots:
int _fireStarter;

QMap<quint8, PendingRequests> _pendingRequests;
VideoBenchmark _videoBenchmark;
};
4 changes: 4 additions & 0 deletions include/flatbuffers/server/FlatBuffersServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ 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();
int getHdrToneMappingEnabled();
Expand Down Expand Up @@ -70,4 +72,6 @@ private slots:
QString _userLutFile;
PixelFormat _currentLutPixelFormat;
int _flatbufferToneMappingMode;
bool _quarterOfFrameMode;
bool _active;
};
75 changes: 59 additions & 16 deletions include/grabber/windows/DX/DxGrabber.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,61 @@
#include <vector>
#include <map>
#include <chrono>
#include <list>
#include <algorithm>
#endif

// util includes
#include <utils/PixelFormat.h>
#include <base/Grabber.h>
#include <utils/Components.h>

template <class T> void SafeRelease(T** ppT)
{
if (*ppT)
{
(*ppT)->Release();
*ppT = NULL;
}
}

struct DisplayHandle
{
QString name;
int warningCounter = 6;
bool wideGamut = false;
int actualDivide = -1, actualWidth = 0, actualHeight = 0;
uint targetMonitorNits = 0;
ID3D11Texture2D* d3dConvertTexture = nullptr;
ID3D11RenderTargetView* d3dRenderTargetView = nullptr;
ID3D11ShaderResourceView* d3dConvertTextureView = nullptr;
ID3D11VertexShader* d3dVertexShader = nullptr;
ID3D11PixelShader* d3dPixelShader = nullptr;
ID3D11Buffer* d3dBuffer = nullptr;
ID3D11SamplerState* d3dSampler = nullptr;
ID3D11InputLayout* d3dVertexLayout = nullptr;
IDXGIOutputDuplication* d3dDuplicate = nullptr;
ID3D11Texture2D* d3dSourceTexture = nullptr;
DXGI_OUTDUPL_DESC surfaceProperties{};

DisplayHandle() = default;
DisplayHandle(const DisplayHandle&) = delete;
~DisplayHandle()
{
SafeRelease(&d3dRenderTargetView);
SafeRelease(&d3dSourceTexture);
SafeRelease(&d3dConvertTextureView);
SafeRelease(&d3dConvertTexture);
SafeRelease(&d3dVertexShader);
SafeRelease(&d3dVertexLayout);
SafeRelease(&d3dPixelShader);
SafeRelease(&d3dSampler);
SafeRelease(&d3dBuffer);
SafeRelease(&d3dDuplicate);
printf("SmartPointer is removing: DisplayHandle for %s\n", QSTRING_CSTR(name));
};
};

class DxGrabber : public Grabber
{
Q_OBJECT
Expand Down Expand Up @@ -56,6 +104,13 @@ public slots:
void restart();

private:

const QString MULTI_MONITOR = "MULTI-MONITOR";

void captureFrame(DisplayHandle& display);

int captureFrame(DisplayHandle& display, Image<ColorRgb>& image);

QString GetSharedLut();

void enumerateDevices(bool silent);
Expand All @@ -70,29 +125,17 @@ public slots:

bool initDirectX(QString selectedDeviceName);

bool initShaders();
HRESULT deepScaledCopy(ID3D11Texture2D* source);
bool initShaders(DisplayHandle& display);
HRESULT deepScaledCopy(DisplayHandle& display, ID3D11Texture2D* source);

QString _configurationPath;
QTimer* _timer;
QTimer* _retryTimer;
int _warningCounter;
int _actualDivide;
bool _wideGamut;
bool _multiMonitor;

bool _dxRestartNow;
std::list<std::unique_ptr<DisplayHandle>> _handles;
ID3D11Device* _d3dDevice;
ID3D11DeviceContext* _d3dContext;
ID3D11Buffer* _d3dBuffer;
ID3D11SamplerState* _d3dSampler;
ID3D11InputLayout* _d3dVertexLayout;
ID3D11VertexShader* _d3dVertexShader;
ID3D11PixelShader* _d3dPixelShader;
ID3D11Texture2D* _d3dSourceTexture;
ID3D11Texture2D* _d3dConvertTexture;
ID3D11ShaderResourceView* _d3dConvertTextureView;
ID3D11RenderTargetView* _d3dRenderTargetView;
IDXGIOutputDuplication* _d3dDuplicate;
DXGI_OUTDUPL_DESC _surfaceProperties;
Image<ColorRgb> _cacheImage;
};
8 changes: 8 additions & 0 deletions include/image/ColorRgb.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
#include <sstream>
#include <cstdint>
#include <iostream>
#include <cmath>
#endif



struct ColorRgb
{
uint8_t red = 0;
Expand Down Expand Up @@ -100,6 +103,11 @@ struct ColorRgb
return (x < 0) ? 0 : ((x > 255) ? 255 : uint8_t(x));
}

inline static uint8_t round(double x)
{
return (x < 0) ? 0 : ((x > 255) ? 255 : static_cast<uint8_t>(std::lround(x)));
}

static void rgb2hsv(uint8_t red, uint8_t green, uint8_t blue, uint16_t& _hue, uint8_t& _saturation, uint8_t& _value);
static void hsv2rgb(uint16_t hue, uint8_t saturation, uint8_t value, uint8_t& red, uint8_t& green, uint8_t& blue);
static void rgb2hsl(uint8_t red, uint8_t green, uint8_t blue, uint16_t& hue, float& saturation, float& luminance);
Expand Down
11 changes: 11 additions & 0 deletions include/image/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <image/ImageData.h>

enum class PixelFormat;

template <typename ColorSpace>
class Image
{
Expand All @@ -28,6 +30,8 @@ class Image

void gradientVBox(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint8_t r, uint8_t g, uint8_t b);

void insertHorizontal(int x, Image<ColorSpace>& source);

unsigned width() const;

unsigned height() const;
Expand All @@ -36,6 +40,10 @@ class Image

ColorSpace& operator()(unsigned x, unsigned y);

void setOriginFormat(PixelFormat pf);

PixelFormat getOriginFormat() const;

void resize(unsigned width, unsigned height);

uint8_t* rawMem();
Expand All @@ -46,6 +54,9 @@ class Image

void clear();

bool save(const char* filename) const;

private:
std::shared_ptr<ImageData<ColorSpace>> _sharedData;
PixelFormat _pixelFormat;
};
Loading