Skip to content

Commit 1ce4c3a

Browse files
authored
Add support for ZSTD compression for all LUT files (#1062)
* Add support for XZ compression for all LUTs file * Replace XZ with ZSTD * Update 3RD_PARTY_LICENSES
1 parent 97b138d commit 1ce4c3a

21 files changed

+348
-211
lines changed

Diff for: .gitmodules

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
path = external/qmqtt
1414
url = https://github.com/emqx/qmqtt.git
1515
ignore = dirty
16-
[submodule "external/xz"]
17-
path = external/xz
18-
url = https://github.com/tukaani-project/xz.git
1916
[submodule "external/mdns"]
2017
path = external/mdns
2118
url = https://github.com/mjansson/mdns.git
@@ -34,3 +31,6 @@
3431
[submodule "external/linalg"]
3532
path = external/linalg
3633
url = https://github.com/sgorsten/linalg.git
34+
[submodule "external/zstd"]
35+
path = external/zstd
36+
url = https://github.com/facebook/zstd.git

Diff for: 3RD_PARTY_LICENSES

+35
Original file line numberDiff line numberDiff line change
@@ -3009,3 +3009,38 @@ INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHA
30093009
FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
30103010
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
30113011
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3012+
3013+
==============================
3014+
zstd
3015+
==============================
3016+
3017+
BSD License
3018+
3019+
For Zstandard software
3020+
3021+
Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved.
3022+
3023+
Redistribution and use in source and binary forms, with or without modification,
3024+
are permitted provided that the following conditions are met:
3025+
3026+
* Redistributions of source code must retain the above copyright notice, this
3027+
list of conditions and the following disclaimer.
3028+
3029+
* Redistributions in binary form must reproduce the above copyright notice,
3030+
this list of conditions and the following disclaimer in the documentation
3031+
and/or other materials provided with the distribution.
3032+
3033+
* Neither the name Facebook, nor Meta, nor the names of its contributors may
3034+
be used to endorse or promote products derived from this software without
3035+
specific prior written permission.
3036+
3037+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
3038+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
3039+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
3040+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
3041+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
3042+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
3043+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
3044+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3045+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3046+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Diff for: CMakeLists.txt

+14-34
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ SET ( DEFAULT_BONJOUR ON )
4747
SET ( DEFAULT_MQTT ON )
4848
SET ( DEFAULT_STATIC_QT_PLUGINS OFF )
4949
SET ( DEFAULT_PRECOMPILED_HEADERS ON )
50-
SET ( DEFAULT_XZ ON )
50+
SET ( DEFAULT_ZSTD ON )
5151
SET ( DEFAULT_POWER_MANAGEMENT ON )
5252
SET ( DEFAULT_SYSTRAY ON )
5353
SET ( DEFAULT_SHARED_LIBS ON )
@@ -382,26 +382,6 @@ if(DEFAULT_CEC)
382382
endif()
383383
endif()
384384

385-
# 7-zip as support
386-
if (WIN32)
387-
# 7zip
388-
cmake_policy(SET CMP0053 NEW)
389-
set(MYENV "PROGRAMFILES(X86)")
390-
391-
find_program(SEVENZIP_BIN
392-
NAMES 7z 7za
393-
HINTS "${MINGWDIR}" "${MINGWLIBS}/bin" "$MYENV/7-zip" "$ENV{ProgramFiles}/7-zip" "$ENV{ProgramW6432}/7-zip"
394-
PATH_SUFFIXES bin
395-
DOC "7zip executable"
396-
)
397-
398-
if (SEVENZIP_BIN)
399-
message( STATUS "7-zip found: ${SEVENZIP_BIN}")
400-
else()
401-
message( FATAL_ERROR "Please install 7-zip")
402-
endif (SEVENZIP_BIN)
403-
endif()
404-
405385
if (CMAKE_CROSSCOMPILING)
406386
set ( DEFAULT_USE_SYSTEM_FLATBUFFERS_LIBS OFF )
407387
SET ( DEFAULT_SHARED_LIBS OFF )
@@ -504,8 +484,8 @@ colorMe("ENABLE_PROTOBUF = " ${ENABLE_PROTOBUF})
504484
option(ENABLE_SYSTRAY "Enable SYSTRAY" ${DEFAULT_SYSTRAY})
505485
colorMe("ENABLE_SYSTRAY = " ${ENABLE_SYSTRAY})
506486

507-
option(ENABLE_XZ "Enable XZ support" ${DEFAULT_XZ})
508-
colorMe("ENABLE_XZ = " ${ENABLE_XZ})
487+
option(ENABLE_ZSTD "Enable ZSTD support" ${DEFAULT_ZSTD})
488+
colorMe("ENABLE_ZSTD = " ${ENABLE_ZSTD})
509489

510490
message( STATUS "\n${CyanColor}BUILD FEATURES${ColorReset}")
511491

@@ -547,8 +527,8 @@ SET ( FLATBUFFERS_INSTALL_LIB_DIR ${CMAKE_BINARY_DIR}/flatbuf )
547527

548528
find_package(GitVersion)
549529

550-
if(ENABLE_XZ)
551-
find_package(LibLZMA)
530+
if(ENABLE_ZSTD)
531+
find_package(zstd)
552532
endif()
553533

554534
# configure a header file to pass some of the CMake settings
@@ -694,13 +674,6 @@ if (WIN32)
694674
endif()
695675
endif()
696676

697-
# Add the source/lib directories
698-
add_subdirectory(external)
699-
add_subdirectory(sources)
700-
701-
# Add resources directory
702-
add_subdirectory(resources)
703-
704677
# remove generated files on make cleaan too
705678
LIST( APPEND GENERATED_QRC
706679
${CMAKE_BINARY_DIR}/WebConfig.qrc
@@ -712,12 +685,19 @@ set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${GENERATED_QRC
712685
configure_file( "${OUR_CMAKE_MODULES}/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)
713686
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
714687

688+
# Add the source/lib directories
689+
add_subdirectory(external)
690+
add_subdirectory(sources)
691+
692+
# Add resources directory
693+
add_subdirectory(resources)
694+
715695
# enable make package - no code after this line !
716696
include (${CMAKE_CURRENT_SOURCE_DIR}/cmake/packages.cmake)
717697

718698
# external targets
719-
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)
720-
set_target_properties(stb qmqtt flatbuffers protobuf-nanopb lunasvg flatc resources uninstall liblzma sqlite3 precompiled_hyperhdr_headers PROPERTIES FOLDER ExternalLibsTargets)
699+
if (WIN32 AND TARGET stb AND TARGET flatbuffers AND TARGET protobuf-nanopb AND TARGET lunasvg AND TARGET flatc AND TARGET qmqtt AND TARGET libzstd_static AND TARGET libzstd_shared AND TARGET zstd AND TARGET clean-all AND TARGET sqlite3 AND TARGET precompiled_hyperhdr_headers)
700+
set_target_properties(stb qmqtt flatbuffers protobuf-nanopb lunasvg flatc resources uninstall libzstd_static libzstd_shared zstd clean-all sqlite3 precompiled_hyperhdr_headers PROPERTIES FOLDER ExternalLibsTargets)
721701
else()
722702
set_target_properties(resources uninstall PROPERTIES FOLDER ExternalLibsTargets)
723703
endif()

Diff for: HyperhdrConfig.h.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
// Define to enable system qmqtt
6767
#cmakedefine USE_SYSTEM_MQTT_LIBS
6868

69-
// Define to enable protobuf
70-
#cmakedefine ENABLE_XZ
69+
// Define to enable zstd
70+
#cmakedefine ENABLE_ZSTD
7171

7272
// Define to enable protobuf
7373
#cmakedefine ENABLE_PROTOBUF

Diff for: cmake/cmake_modules/Findzstd.cmake

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# - Find zstd
2+
# Find the zstd compression library and includes
3+
#
4+
# ZSTD_INCLUDE_DIRS - where to find zstd.h, etc.
5+
# ZSTD_LIBRARIES - List of libraries when using zstd.
6+
# ZSTD_FOUND - True if zstd found.
7+
8+
find_path(ZSTD_INCLUDE_DIRS
9+
NAMES zstd.h
10+
HINTS ${zstd_ROOT_DIR}/include)
11+
12+
find_library(ZSTD_LIBRARIES
13+
NAMES zstd
14+
HINTS ${zstd_ROOT_DIR}/lib)
15+
16+
include(FindPackageHandleStandardArgs)
17+
find_package_handle_standard_args(zstd DEFAULT_MSG ZSTD_LIBRARIES ZSTD_INCLUDE_DIRS)
18+
19+
mark_as_advanced(
20+
ZSTD_LIBRARIES
21+
ZSTD_INCLUDE_DIRS)
22+
23+
if(ZSTD_FOUND AND NOT (TARGET zstd::zstd))
24+
add_library (zstd::zstd UNKNOWN IMPORTED)
25+
set_target_properties(zstd::zstd
26+
PROPERTIES
27+
IMPORTED_LOCATION ${ZSTD_LIBRARIES}
28+
INTERFACE_INCLUDE_DIRECTORIES ${ZSTD_INCLUDE_DIRS})
29+
endif()

Diff for: cmake/installers.cmake

+10-10
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ macro(DeployApple TARGET)
2020
install(CODE [[ file(INSTALL FILES $<TARGET_FILE:sqlite3> DESTINATION "${CMAKE_INSTALL_PREFIX}/hyperhdr.app/Contents/lib" TYPE SHARED_LIBRARY) ]] COMPONENT "HyperHDR")
2121
endif()
2222

23-
# Copy utils-xz
24-
if (USE_SHARED_LIBS AND TARGET utils-xz)
25-
install(CODE [[ file(INSTALL FILES $<TARGET_FILE:utils-xz> DESTINATION "${CMAKE_INSTALL_PREFIX}/hyperhdr.app/Contents/lib" TYPE SHARED_LIBRARY) ]] COMPONENT "HyperHDR")
23+
# Copy utils-zstd
24+
if (USE_SHARED_LIBS AND TARGET utils-zstd)
25+
install(CODE [[ file(INSTALL FILES $<TARGET_FILE:utils-zstd> DESTINATION "${CMAKE_INSTALL_PREFIX}/hyperhdr.app/Contents/lib" TYPE SHARED_LIBRARY) ]] COMPONENT "HyperHDR")
2626
endif()
2727

2828
# Copy utils-image
@@ -243,9 +243,9 @@ macro(DeployUnix TARGET)
243243
install(CODE [[ file(INSTALL FILES $<TARGET_FILE:utils-image> DESTINATION "${CMAKE_INSTALL_PREFIX}/share/hyperhdr/lib" TYPE SHARED_LIBRARY) ]] COMPONENT "HyperHDR")
244244
endif()
245245

246-
# Copy UTILS-XZ lib
247-
if (TARGET utils-image)
248-
install(CODE [[ file(INSTALL FILES $<TARGET_FILE:utils-xz> DESTINATION "${CMAKE_INSTALL_PREFIX}/share/hyperhdr/lib" TYPE SHARED_LIBRARY) ]] COMPONENT "HyperHDR")
246+
# Copy UTILS-ZSTD lib
247+
if (TARGET utils-zstd)
248+
install(CODE [[ file(INSTALL FILES $<TARGET_FILE:utils-zstd> DESTINATION "${CMAKE_INSTALL_PREFIX}/share/hyperhdr/lib" TYPE SHARED_LIBRARY) ]] COMPONENT "HyperHDR")
249249
endif()
250250

251251

@@ -354,7 +354,7 @@ macro(DeployUnix TARGET)
354354
"librt"
355355
"libstdc++"
356356
"libudev"
357-
"libz"
357+
"libz.so"
358358
"libxrender1"
359359
"libxi6"
360360
"libxext6"
@@ -593,9 +593,9 @@ macro(DeployWindows TARGET)
593593
install(CODE [[ file(INSTALL FILES $<TARGET_FILE:sqlite3> DESTINATION "${CMAKE_INSTALL_PREFIX}/bin" TYPE SHARED_LIBRARY) ]] COMPONENT "HyperHDR")
594594
endif()
595595

596-
# Copy utils-xz
597-
if (USE_SHARED_LIBS AND TARGET utils-xz)
598-
install(CODE [[ file(INSTALL FILES $<TARGET_FILE:utils-xz> DESTINATION "${CMAKE_INSTALL_PREFIX}/bin" TYPE SHARED_LIBRARY) ]] COMPONENT "HyperHDR")
596+
# Copy utils-zstd
597+
if (USE_SHARED_LIBS AND TARGET utils-zstd)
598+
install(CODE [[ file(INSTALL FILES $<TARGET_FILE:utils-zstd> DESTINATION "${CMAKE_INSTALL_PREFIX}/bin" TYPE SHARED_LIBRARY) ]] COMPONENT "HyperHDR")
599599
endif()
600600

601601
# Copy utils-image

Diff for: external/CMakeLists.txt

+14-9
Original file line numberDiff line numberDiff line change
@@ -237,17 +237,22 @@ if ( ENABLE_MQTT )
237237
endif()
238238

239239
#=============================================================================
240-
# XZ
240+
# ZSTD
241241
#=============================================================================
242242

243-
if ( ENABLE_XZ )
244-
if (NOT LIBLZMA_FOUND)
245-
message( STATUS "System library xz could not be found. Using embedded xz library.")
246-
option(BUILD_TESTING "" OFF)
247-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/xz)
248-
set_target_properties(liblzma PROPERTIES INTERFACE_INCLUDE_DIRECTORIES $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/external/xz/src/liblzma/api>)
249-
set_property(TARGET liblzma PROPERTY POSITION_INDEPENDENT_CODE ON)
250-
add_library(LibLZMA::LibLZMA ALIAS liblzma)
243+
if ( ENABLE_ZSTD )
244+
if (NOT zstd_FOUND)
245+
message( STATUS "System library zstd could not be found. Using embedded zstd library.")
246+
if(WIN32)
247+
set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -I${CMAKE_SOURCE_DIR}/external/zstd/lib")
248+
endif()
249+
set(ZSTD_BUILD_TESTS OFF)
250+
set(ZSTD_LEGACY_SUPPORT OFF)
251+
set(ZSTD_BUILD_PROGRAMS OFF)
252+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/zstd/build/cmake)
253+
set_target_properties(libzstd PROPERTIES INTERFACE_INCLUDE_DIRECTORIES $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/external/zstd/lib>)
254+
set_property(TARGET libzstd PROPERTY POSITION_INDEPENDENT_CODE ON)
255+
add_library(zstd::zstd ALIAS libzstd)
251256
endif()
252257
ENDIF()
253258

Diff for: external/xz

-1
This file was deleted.

Diff for: external/zstd

Submodule zstd added at 794ea1b

Diff for: include/utils-xz/utils-xz.h

-7
This file was deleted.

Diff for: include/utils-zstd/utils-zstd.h

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
3+
#ifndef _ZSTD_SHARED_API
4+
#define _ZSTD_SHARED_API
5+
#endif
6+
7+
#include <image/MemoryBuffer.h>
8+
9+
_ZSTD_SHARED_API const char* DecompressZSTD(size_t downloadedDataSize, const uint8_t* downloadedData, const char* fileName);
10+
_ZSTD_SHARED_API const char* DecompressZSTD(size_t downloadedDataSize, const uint8_t* downloadedData, uint8_t* dest, int destSeek, int destSize);

Diff for: include/utils/LutLoader.h

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#ifndef PCH_ENABLED
44
#include <QString>
55
#include <QList>
6+
#include <QFile>
67
#endif
78

89
#include <utils/PixelFormat.h>
@@ -17,4 +18,7 @@ class LutLoader {
1718
MemoryBuffer<uint8_t> _lut;
1819

1920
void loadLutFile(Logger* _log, PixelFormat color, const QList<QString>& files);
21+
private:
22+
bool decompressLut(Logger* _log, QFile& file, int index);
23+
void hasher(int index, Logger* _log);
2024
};

Diff for: sources/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ add_subdirectory(utils)
3333
add_subdirectory(utils-image)
3434
add_subdirectory(webserver)
3535

36-
if(ENABLE_XZ)
37-
add_subdirectory(utils-xz)
36+
if(ENABLE_ZSTD)
37+
add_subdirectory(utils-zstd)
3838
endif()
3939

4040

Diff for: sources/api/BaseAPI.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
#include <base/GrabberHelper.h>
3232
#include <utils-image/utils-image.h>
3333

34-
#ifdef ENABLE_XZ
35-
#include <utils-xz/utils-xz.h>
34+
#ifdef ENABLE_ZSTD
35+
#include <utils-zstd/utils-zstd.h>
3636
#endif
3737

3838
#ifdef _WIN32
@@ -410,21 +410,21 @@ bool BaseAPI::saveSettings(const QJsonObject& data)
410410

411411
QString BaseAPI::installLut(QNetworkReply* reply, QString fileName, int hardware_brightness, int hardware_contrast, int hardware_saturation, qint64 time)
412412
{
413-
#ifdef ENABLE_XZ
413+
#ifdef ENABLE_ZSTD
414414
QString error = nullptr;
415415

416416
if (reply->error() == QNetworkReply::NetworkError::NoError)
417417
{
418418
QByteArray downloadedData = reply->readAll();
419419

420-
error = DecompressXZ(downloadedData.size(), reinterpret_cast<uint8_t*>(downloadedData.data()), QSTRING_CSTR(fileName));
420+
error = DecompressZSTD(downloadedData.size(), reinterpret_cast<uint8_t*>(downloadedData.data()), QSTRING_CSTR(fileName));
421421
}
422422
else
423423
error = "Could not download LUT file";
424424

425425
return error;
426426
#else
427-
return "XZ support was disabled in the build configuration";
427+
return "ZSTD support was disabled in the build configuration";
428428
#endif
429429
}
430430

Diff for: sources/api/HyperAPI.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ void HyperAPI::lutDownloaded(QNetworkReply* reply, int hardware_brightness, int
568568

569569
void HyperAPI::handleLutInstallCommand(const QJsonObject& message, const QString& command, int tan)
570570
{
571-
const QString& address = QString("%1/lut_lin_tables.3d.xz").arg(message["subcommand"].toString().trimmed());
571+
const QString& address = QString("%1/lut_lin_tables.3d.zst").arg(message["subcommand"].toString().trimmed());
572572
int hardware_brightness = message["hardware_brightness"].toInt(0);
573573
int hardware_contrast = message["hardware_contrast"].toInt(0);
574574
int hardware_saturation = message["hardware_saturation"].toInt(0);

Diff for: sources/hyperhdr/CMakeLists.txt

+2-6
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,8 @@ else()
5454
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
5555
endif()
5656

57-
if(ENABLE_XZ)
58-
if (LIBLZMA_FOUND)
59-
target_link_libraries(hyperhdr LibLZMA::LibLZMA utils-xz)
60-
else()
61-
target_link_libraries(hyperhdr liblzma utils-xz)
62-
endif()
57+
if(ENABLE_ZSTD)
58+
target_link_libraries(hyperhdr zstd::zstd utils-zstd)
6359
endif()
6460

6561
if (USE_STATIC_QT_PLUGINS)

0 commit comments

Comments
 (0)