Skip to content

Commit

Permalink
Breaking change: remove LUT from installer and create it dynamically (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
awawa-dev authored Nov 24, 2024
1 parent 83f5efb commit cfefbc5
Show file tree
Hide file tree
Showing 24 changed files with 268 additions and 108 deletions.
20 changes: 0 additions & 20 deletions cmake/installers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@ macro(DeployApple TARGET)
if(EXISTS ${TARGET_FILE})
install ( TARGETS hyperhdr DESTINATION "share/.." COMPONENT "HyperHDR" )

execute_process(
COMMAND bash -c "cd ${CMAKE_CURRENT_BINARY_DIR} && tar -xzf ${PROJECT_SOURCE_DIR}/resources/lut/lut_lin_tables.tar.xz"
RESULT_VARIABLE STATUS
OUTPUT_VARIABLE OUTPUT1
)
if(STATUS AND NOT STATUS EQUAL 0)
message( FATAL_ERROR "LUT tar.xz Bad exit status (xz-tools installed?)")
else()
message( STATUS "LUT tar.xz tar extracted")
endif()

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/lut_lin_tables.3d" DESTINATION "hyperhdr.app/Contents/lut" COMPONENT "HyperHDR")
install(FILES "${PROJECT_SOURCE_DIR}/cmake/osx/Hyperhdr.icns" DESTINATION "hyperhdr.app/Contents/Resources" COMPONENT "HyperHDR")
install(FILES "${PROJECT_SOURCE_DIR}/LICENSE" DESTINATION "hyperhdr.app/Contents/Resources" COMPONENT "HyperHDR")
install(FILES "${PROJECT_SOURCE_DIR}/3RD_PARTY_LICENSES" DESTINATION "hyperhdr.app/Contents/Resources" COMPONENT "HyperHDR")
Expand Down Expand Up @@ -214,8 +202,6 @@ macro(DeployUnix TARGET)
if (EXISTS ${TARGET_FILE})
include(GetPrerequisites)

# Install LUT
install(FILES "${PROJECT_SOURCE_DIR}/resources/lut/lut_lin_tables.tar.xz" DESTINATION "share/hyperhdr/lut" COMPONENT "HyperHDR")
install(FILES "${PROJECT_SOURCE_DIR}/LICENSE" DESTINATION "share/hyperhdr" COMPONENT "HyperHDR")
install(FILES "${PROJECT_SOURCE_DIR}/3RD_PARTY_LICENSES" DESTINATION "share/hyperhdr" COMPONENT "HyperHDR")

Expand Down Expand Up @@ -622,12 +608,6 @@ macro(DeployWindows TARGET)
COMPONENT "HyperHDR"
)

install(
FILES ${PROJECT_SOURCE_DIR}/resources/lut/lut_lin_tables.tar.xz
DESTINATION "bin"
COMPONENT "HyperHDR"
)

INSTALL(FILES ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} DESTINATION bin COMPONENT "HyperHDR")

install(FILES "${PROJECT_SOURCE_DIR}/LICENSE" DESTINATION bin COMPONENT "HyperHDR")
Expand Down
6 changes: 0 additions & 6 deletions cmake/linux/arch/INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ post_install() {
start_msg=""
restart_msg=""

echo "Extracting LUT table..."
tar -xf /usr/share/hyperhdr/lut/lut_lin_tables.tar.xz -C /usr/share/hyperhdr/lut/
rm -f -v /usr/share/hyperhdr/lut/lut_lin_tables.tar.xz

if grep -m1 systemd /proc/1/comm > /dev/null
then
# systemd
Expand Down Expand Up @@ -255,8 +251,6 @@ pre_remove() {
rm -v /usr/share/applications/hyperhdr* 2>/dev/null
rm -rv /usr/share/pixmaps/hyperhdr 2>/dev/null

echo "Removing LUT table"
rm -f -v /usr/share/hyperhdr/lut/lut_lin_tables.3d
exit 0
}

Expand Down
4 changes: 0 additions & 4 deletions cmake/linux/debian/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ fi
start_msg=""
restart_msg=""

echo "Extracting LUT table..."
tar -xf /usr/share/hyperhdr/lut/lut_lin_tables.tar.xz -C /usr/share/hyperhdr/lut/
rm -f -v /usr/share/hyperhdr/lut/lut_lin_tables.tar.xz

if grep -m1 systemd /proc/1/comm > /dev/null
then
# systemd
Expand Down
2 changes: 0 additions & 2 deletions cmake/linux/debian/prerm
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,4 @@ desktop-file-edit --set-key=NoDisplay --set-value=true /usr/share/applications/h
rm -v /usr/share/applications/hyperhdr* 2>/dev/null
rm -rv /usr/share/pixmaps/hyperhdr 2>/dev/null

echo "Removing LUT table"
rm -f -v /usr/share/hyperhdr/lut/lut_lin_tables.3d
exit 0
4 changes: 0 additions & 4 deletions cmake/linux/rpm/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ fi
start_msg=""
restart_msg=""

echo "Extracting LUT table..."
tar -xf /usr/share/hyperhdr/lut/lut_lin_tables.tar.xz -C /usr/share/hyperhdr/lut/
rm -f -v /usr/share/hyperhdr/lut/lut_lin_tables.tar.xz

if grep -m1 systemd /proc/1/comm > /dev/null
then
# systemd
Expand Down
2 changes: 0 additions & 2 deletions cmake/linux/rpm/prerm
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,4 @@ then
firewall-cmd --remove-port=8090/tcp
fi

echo "Removing LUT table"
rm -f -v /usr/share/hyperhdr/lut/lut_lin_tables.3d
exit 0
Binary file removed cmake/windows/plugins/ExtractLut.dll
Binary file not shown.
12 changes: 1 addition & 11 deletions cmake/windows/template/NSIS.template.in
Original file line number Diff line number Diff line change
Expand Up @@ -793,16 +793,6 @@ Section "-Core installation"
; Install Visual c++ Redistributable
ExecWait '"$INSTDIR\bin\vc_redist.x64.exe" /install /quiet /norestart'

Push "$INSTDIR\bin\lut_lin_tables.tar.xz"
Push "$INSTDIR\bin\lut_lin_tables.3d"

ExtractLut::extract
Pop $0
StrCmp $0 success SUCCESS
MessageBox MB_OK|MB_ICONSTOP "$0"
MessageBox MB_OK|MB_ICONSTOP "Please extract $INSTDIR\bin\lut_lin_tables.tar.xz manually using 7-zip"
SUCCESS:

SectionEnd

Section "-Add to path"
Expand Down Expand Up @@ -925,7 +915,7 @@ Section "Uninstall"
;Remove files we installed.
;Keep the list of directories here in sync with the File commands above.
@CPACK_NSIS_DELETE_FILES@
Delete "$INSTDIR\bin\lut_lin_tables.3d"

@CPACK_NSIS_DELETE_DIRECTORIES@

!ifdef CPACK_NSIS_ADD_REMOVE
Expand Down
2 changes: 2 additions & 0 deletions include/base/Grabber.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ class Grabber : public DetectionAutomatic, public DetectionManual, protected Lut

int getActualFps() override;

void pleaseWaitForLut(bool videoGrabber = true);

void setEncoding(QString enc);

void setBrightnessContrastSaturationHue(int brightness, int contrast, int saturation, int hue);
Expand Down
2 changes: 2 additions & 0 deletions include/base/HyperHdrManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public slots:
void clearInstancePriority(int instance, int priority);
std::list<EffectDefinition> getEffects();

void handleLutRequestSignal();

signals:
void SignalInstanceStateChanged(InstanceState state, quint8 instance, const QString& name = QString());

Expand Down
2 changes: 1 addition & 1 deletion include/grabber/linux/v4l2/V4L2Grabber.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private slots:

void enumerateV4L2devices(bool silent);

void loadLutFile(PixelFormat color = PixelFormat::NO_CHANGE);
void loadLutFile(PixelFormat color = PixelFormat::NO_CHANGE, bool silent = false);

void getV4L2devices();

Expand Down
2 changes: 1 addition & 1 deletion include/grabber/osx/AVF/AVFGrabber.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public slots:

void enumerateAVFdevices(bool silent);

void loadLutFile(PixelFormat color = PixelFormat::NO_CHANGE);
void loadLutFile(PixelFormat color = PixelFormat::NO_CHANGE, bool silent = false);

void enumerateAVFdevices();

Expand Down
2 changes: 1 addition & 1 deletion include/grabber/windows/DX/DxGrabber.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public slots:

void enumerateDevices(bool silent);

void loadLutFile(PixelFormat color = PixelFormat::NO_CHANGE);
void loadLutFile(PixelFormat color = PixelFormat::NO_CHANGE, bool silent = false);

void getDevices();

Expand Down
2 changes: 1 addition & 1 deletion include/grabber/windows/MF/MFGrabber.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public slots:

void enumerateMFdevices(bool silent);

void loadLutFile(PixelFormat color = PixelFormat::NO_CHANGE);
void loadLutFile(PixelFormat color = PixelFormat::NO_CHANGE, bool silent = false);

void getMFdevices();

Expand Down
1 change: 1 addition & 0 deletions include/lut-calibrator/LutCalibrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class LutCalibrator : public QObject
~LutCalibrator();
static void sendReport(Logger* _log, QString report);
static QString CreateLutFile(Logger* _log, QString _rootPath, BestResult* bestResult, std::vector<std::vector<std::vector<CapturedColor>>>* all);
static void CreateDefaultLut(QString filepath);

signals:
void SignalLutCalibrationUpdated(const QJsonObject& data);
Expand Down
2 changes: 2 additions & 0 deletions include/utils/GlobalSignals.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,6 @@ class GlobalSignals : public QObject
void SignalDiscoveryEvent(DiscoveryRecord message);

void SignalSetLut(MemoryBuffer<uint8_t>* lut);

void SignalLutRequest();
};
63 changes: 63 additions & 0 deletions sources/base/Grabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ const QString Grabber::AUTO_SETTING = QString("auto");
const int Grabber::AUTO_INPUT = -1;
const int Grabber::AUTO_FPS = 0;

namespace
{
const unsigned char pleasewait[] = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x3f,0xff,0xff,0xff,0xff,0xff,0xff,0xfd,0xdf,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x1f,0xff,0xff,0xff,0x31,0x88,0x25,0xb5,0xfe,0x21,0x9f,0xfe,0xdb,0x7b,0x6d,0xb6,0x7f,0x6d,0xbf,0xfe,0xfb,0xc,0x6d,0xb5,0xbf,0x6d,0xbf,0xfe,0xdb,0x6f,0x6d,0xb5,0xbf,0x6d,0xbf,0xff,0x30,0x98,0xc5,0x6,0x3f,0x6d,0x1f,0xff,0xff,0xff,0xef,0xff,0xff,0x7f,0xbf,0xff,0xff,0xff,0xef,0xff,0xff,0x7f,0xbf,0xff,0xff,0xff,0xfd,0xff,0xfe,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0x3c,0x44,0x13,0x9f,0xdb,0x84,0x4f,0xff,0x7e,0xbd,0xbd,0x7f,0xdb,0xb6,0xdf,0xff,0x7e,0x86,0x3b,0xf,0xa5,0xc6,0xdf,0xff,0xe,0xb7,0xb7,0x6f,0xb6,0xf6,0xdf,0xff,0x76,0xcc,0x79,0x9f,0x24,0x8c,0x8f,0xff,0x76,0xff,0xff,0xff,0xff,0xff,0xdf,0xff,0x76,0xff,0xff,0xff,0xff,0xff,0xdf,0xfe,0xc,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff };
};


Grabber::Grabber(const QString& configurationPath, const QString& grabberName)
: _configurationPath(configurationPath)
Expand Down Expand Up @@ -83,6 +88,64 @@ Grabber::~Grabber()
disconnect(GlobalSignals::getInstance(), &GlobalSignals::SignalSetLut, this, &Grabber::signalSetLutHandler);
}

void Grabber::pleaseWaitForLut(bool videoGrabber)
{
Image<ColorRgb> image(_actualWidth, _actualHeight);
double sizeX = _actualWidth / 64.0;
double sizeY = _actualHeight / 32.0;

auto timer = InternalClock::now() / 1200;

ColorRgb fgColor, bgColor;

if (timer % 8 < 2)
{
bgColor = ColorRgb::WHITE;
fgColor = ColorRgb::BLACK;
}
else if (timer % 8 < 4)
{
bgColor = ColorRgb::RED;
fgColor = ColorRgb::BLACK;
}
else if (timer % 8 < 6)
{
bgColor = ColorRgb::GREEN;
fgColor = ColorRgb::BLACK;
}
else
{
bgColor = ColorRgb::BLUE;
fgColor = ColorRgb::WHITE;
}

image.fastBox(0, 0, image.width(), image.height(), bgColor.red, bgColor.green, bgColor.blue);

for (int y = 0; y < 32; y++)
for (int x = 0; x < 64; x++)
{
int index = (31 - y) * 8 + (x / 8);
uint8_t bit = 1 << (7 - (x % 8));
if (index < static_cast<int>(sizeof(pleasewait)) && !(pleasewait[index] & bit))
{
int fromX = sizeX * x;
int fromY = sizeY * y;
image.fastBox(fromX, fromY, fromX + sizeX, fromY + sizeY, fgColor.red, fgColor.green, fgColor.blue);
}
}

if (videoGrabber)
{
emit GlobalSignals::getInstance()->SignalNewVideoImage(_deviceName, image);
}
else
{
emit GlobalSignals::getInstance()->SignalNewSystemImage(_deviceName, image);
}

emit GlobalSignals::getInstance()->SignalLutRequest();
}

bool sortDevicePropertiesItem(const Grabber::DevicePropertiesItem& v1, const Grabber::DevicePropertiesItem& v2)
{
if (v1.x != v2.x)
Expand Down
14 changes: 14 additions & 0 deletions sources/base/HyperHdrManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <base/AccessManager.h>
#include <base/Muxer.h>
#include <utils/GlobalSignals.h>
#include <lut-calibrator/LutCalibrator.h>

QString HyperHdrManager::getRootPath()
{
Expand All @@ -58,6 +59,7 @@ HyperHdrManager::HyperHdrManager(const QString& rootPath)
connect(this, &HyperHdrManager::SignalBenchmarkCapture, &_videoBenchmark, &VideoBenchmark::benchmarkCapture);

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

void HyperHdrManager::handleRequestComponent(hyperhdr::Components component, int hyperHdrInd, bool listen)
Expand All @@ -74,6 +76,18 @@ HyperHdrManager::~HyperHdrManager()
Debug(_log, "HyperHdrManager has been removed");
}

void HyperHdrManager::handleLutRequestSignal()
{
static bool requested = false;

if (!requested)
{
requested = true;

LutCalibrator::CreateDefaultLut(_rootPath);
}
}

void HyperHdrManager::startAll(bool disableOnStartup)
{
auto instanceList = _instanceTable->getAllInstances(true);
Expand Down
22 changes: 18 additions & 4 deletions sources/grabber/linux/v4l2/V4L2Grabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ QString V4L2Grabber::GetSharedLut()
return ret;
}

void V4L2Grabber::loadLutFile(PixelFormat color)
void V4L2Grabber::loadLutFile(PixelFormat color, bool silent)
{
// load lut table
QString fileName1 = QString("%1%2").arg(_configurationPath).arg("/lut_lin_tables.3d");
QString fileName2 = QString("%1%2").arg(GetSharedLut()).arg("/lut_lin_tables.3d");
QString fileName3 = QString("/usr/share/hyperhdr/lut/lut_lin_tables.3d");

Grabber::loadLutFile(_log, color, QList<QString>{fileName1, fileName2, fileName3});
Grabber::loadLutFile((!silent) ? _log : nullptr, color, QList<QString>{fileName1, fileName2, fileName3});
}

void V4L2Grabber::setHdrToneMappingEnabled(int mode)
Expand Down Expand Up @@ -1210,9 +1210,23 @@ bool V4L2Grabber::process_image(v4l2_buffer* buf, const void* frameImageBuffer,
V4L2Worker* _workerThread = _V4L2WorkerManager.workers[i];

if ((_actualVideoFormat == PixelFormat::YUYV || _actualVideoFormat == PixelFormat::I420 ||
_actualVideoFormat == PixelFormat::NV12) && !_lutBufferInit)
_actualVideoFormat == PixelFormat::NV12 || _hdrToneMappingEnabled) && !_lutBufferInit)
{
loadLutFile();
if ((_actualVideoFormat == PixelFormat::YUYV) || (_actualVideoFormat == PixelFormat::I420) || (_actualVideoFormat == PixelFormat::NV12) || (_actualVideoFormat == PixelFormat::MJPEG))
{
loadLutFile(PixelFormat::YUYV, true);
}
else
{
loadLutFile(PixelFormat::RGB24, true);
}

if (!_lutBufferInit)
{
pleaseWaitForLut();
_V4L2WorkerManager.workers[i]->noBusy();
return true;
}
}

bool directAccess = !(_signalAutoDetectionEnabled || _signalDetectionEnabled || isCalibrating() );
Expand Down
22 changes: 18 additions & 4 deletions sources/grabber/osx/AVF/AVFGrabber.mm
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ - (void)captureOutput:(AVCaptureOutput *)output didOutputSampleBuffer:(CMSampleB
return ret;
}

void AVFGrabber::loadLutFile(PixelFormat color)
void AVFGrabber::loadLutFile(PixelFormat color, bool silent)
{
// load lut table
QString fileName1 = QString("%1%2").arg(_configurationPath).arg("/lut_lin_tables.3d");
QString fileName2 = QString("%1%2").arg(GetSharedLut()).arg("/lut_lin_tables.3d");

Grabber::loadLutFile(_log, color, QList<QString>{fileName1, fileName2});
Grabber::loadLutFile((!silent) ? _log : nullptr, color, QList<QString>{fileName1, fileName2});
}

void AVFGrabber::setHdrToneMappingEnabled(int mode)
Expand Down Expand Up @@ -813,9 +813,23 @@ - (void)captureOutput:(AVCaptureOutput *)output didOutputSampleBuffer:(CMSampleB
AVFWorker* _workerThread = _AVFWorkerManager.workers[i];

if ((_actualVideoFormat == PixelFormat::YUYV || _actualVideoFormat == PixelFormat::I420 ||
_actualVideoFormat == PixelFormat::NV12) && !_lutBufferInit)
_actualVideoFormat == PixelFormat::NV12 || _hdrToneMappingEnabled) && !_lutBufferInit)
{
loadLutFile();
if ((_actualVideoFormat == PixelFormat::YUYV) || (_actualVideoFormat == PixelFormat::I420) || (_actualVideoFormat == PixelFormat::NV12) || (_actualVideoFormat == PixelFormat::MJPEG))
{
loadLutFile(PixelFormat::YUYV, true);
}
else
{
loadLutFile(PixelFormat::RGB24, true);
}

if (!_lutBufferInit)
{
pleaseWaitForLut();
_AVFWorkerManager.workers[i]->noBusy();
return true;
}
}

bool directAccess = !(_signalAutoDetectionEnabled || _signalDetectionEnabled || isCalibrating());
Expand Down
Loading

0 comments on commit cfefbc5

Please sign in to comment.