Skip to content

Commit

Permalink
Cleanup CMakeLists.txt and Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ram-mohan committed Oct 22, 2023
1 parent d4a3e15 commit 67c7ff0
Show file tree
Hide file tree
Showing 2 changed files with 203 additions and 119 deletions.
221 changes: 132 additions & 89 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,133 +16,176 @@

cmake_minimum_required(VERSION 3.5)

project(ULTRAHDR VERSION 1.0.0)
project(ULTRAHDR)

option(ENABLE_FUZZERS "Enables fuzzers" OFF)
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, defaulting to release")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
endif()

set(ULTRAHDR_VERSION_MAJOR 1)
set(ULTRAHDR_VERSION_MINOR 0)
set(ULTRAHDR_VERSION_PATCH 0)
set(ULTRAHDR_VERSION ${ULTRAHDR_VERSION_MAJOR}.${ULTRAHDR_VERSION_MINOR}.${ULTRAHDR_VERSION_PATCH})

option(ENABLE_FUZZERS "Enable building fuzzer apps" OFF)
# Add -fuzzer-no-link to sanitize argument if fuzzer build is enabled
if (${ENABLE_FUZZERS})
if(DEFINED SANITIZE)
if(${ENABLE_FUZZERS})
message(STATUS "Building fuzzer applications enabled")
if(DEFINED SANITIZE)
set(SANITIZE "${SANITIZE},fuzzer-no-link")
else()
else()
set(SANITIZE "fuzzer-no-link")
endif()
else()
message(STATUS "Building fuzzer applications disabled")
endif()

option(ENABLE_TESTS "Enable unit tests" OFF)
if(${ENABLE_TESTS})
message(STATUS "Building unit tests enabled")
include(CTest)
else()
message(STATUS "Building unit tests disabled")
endif()
set(CMAKE_CXX_STANDARD 17)

include(ExternalProject)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_THREAD_PREFER_PTHREAD ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

set(SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}")

include("${SRC_DIR}/utils.cmake")

libultrahdr_add_compile_options()

ADD_SUBDIRECTORY("${SRC_DIR}/third_party/cmake/image_io")

ExternalProject_Add(libjpeg-turbo
GIT_REPOSITORY https://github.com/libjpeg-turbo/libjpeg-turbo.git
GIT_TAG main
PREFIX ${SRC_DIR}/third_party/build/libjpeg-turbo
SOURCE_DIR ${SRC_DIR}/third_party/libjpeg-turbo
TMP_DIR ${SRC_DIR}/third_party/build/libjpeg-turbo/tmp
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config $<CONFIG> --target jpeg-static
INSTALL_COMMAND ""
)

set(JPEG_INCLUDE_DIR
${SRC_DIR}/third_party/libjpeg-turbo/
${SRC_DIR}/third_party/build/libjpeg-turbo/src/libjpeg-turbo-build)

set(JPEG_LIBRARIES ${SRC_DIR}/third_party/build/libjpeg-turbo/src/libjpeg-turbo-build/libjpeg.a)

ExternalProject_Add(googletest
GIT_REPOSITORY https://android.googlesource.com/platform/external/googletest
GIT_TAG main
PREFIX ${SRC_DIR}/third_party/build/googletest
SOURCE_DIR ${SRC_DIR}/third_party/googletest
TMP_DIR ${SRC_DIR}/third_party/build/googletest/tmp
INSTALL_COMMAND ""
)

set(GTEST_INCLUDE_DIRS
${SRC_DIR}/third_party/googletest/googletest/include
${SRC_DIR}/third_party/googletest/googlemock/include)
include(ExternalProject)

set(GTEST_LIBRARIES
${SRC_DIR}/third_party/build/googletest/src/googletest-build/lib/libgtest.a
${SRC_DIR}/third_party/build/googletest/src/googletest-build/lib/libgtest_main.a)
function(fetch_libjpegturbo)
ExternalProject_Add(libjpeg-turbo
GIT_REPOSITORY https://github.com/libjpeg-turbo/libjpeg-turbo.git
GIT_TAG main
PREFIX ${SRC_DIR}/third_party/build/libjpeg-turbo
SOURCE_DIR ${SRC_DIR}/third_party/libjpeg-turbo
TMP_DIR ${SRC_DIR}/third_party/build/libjpeg-turbo/tmp
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config $<CONFIG> --target jpeg-static
CMAKE_ARGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
INSTALL_COMMAND ""
)
set(JPEG_INCLUDE_DIRS
${SRC_DIR}/third_party/libjpeg-turbo/
${SRC_DIR}/third_party/build/libjpeg-turbo/src/libjpeg-turbo-build PARENT_SCOPE)
set(JPEG_LIBRARIES
${SRC_DIR}/third_party/build/libjpeg-turbo/src/libjpeg-turbo-build/libjpeg.a PARENT_SCOPE)
endfunction()

function(fetch_googletest)
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest
GIT_TAG v1.13.0
PREFIX ${SRC_DIR}/third_party/build/googletest
SOURCE_DIR ${SRC_DIR}/third_party/googletest
TMP_DIR ${SRC_DIR}/third_party/build/googletest/tmp
CMAKE_ARGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
INSTALL_COMMAND ""
)
set(GTEST_INCLUDE_DIRS
${SRC_DIR}/third_party/googletest/googletest/include
${SRC_DIR}/third_party/googletest/googlemock/include PARENT_SCOPE)
set(GTEST_BOTH_LIBRARIES
${SRC_DIR}/third_party/build/googletest/src/googletest-build/lib/libgtest.a
${SRC_DIR}/third_party/build/googletest/src/googletest-build/lib/libgtest_main.a PARENT_SCOPE)
endfunction()

fetch_libjpegturbo()

if(${ENABLE_TESTS})
find_package(GTest)
if(NOT GTest_FOUND)
fetch_googletest()
endif()
endif()

add_library(ultrahdr STATIC
"${SRC_DIR}/gainmapmath.cpp"
"${SRC_DIR}/icc.cpp"
"${SRC_DIR}/jpegr.cpp"
"${SRC_DIR}/jpegrutils.cpp"
"${SRC_DIR}/jpegencoderhelper.cpp"
"${SRC_DIR}/jpegdecoderhelper.cpp"
"${SRC_DIR}/multipictureformat.cpp"
"${SRC_DIR}/gainmapmath.cpp"
"${SRC_DIR}/icc.cpp"
"${SRC_DIR}/jpegr.cpp"
"${SRC_DIR}/jpegrutils.cpp"
"${SRC_DIR}/jpegencoderhelper.cpp"
"${SRC_DIR}/jpegdecoderhelper.cpp"
"${SRC_DIR}/multipictureformat.cpp"
)

target_include_directories(ultrahdr PRIVATE
"${SRC_DIR}/include"
${JPEG_INCLUDE_DIR}
"${SRC_DIR}/third_party/image_io/includes/"
${JPEG_INCLUDE_DIRS}
"${SRC_DIR}/include"
"${SRC_DIR}/third_party/image_io/includes/"
)

target_link_libraries(ultrahdr PRIVATE
${JPEG_LIBRARIES}
image_io
Threads::Threads
${JPEG_LIBRARIES}
image_io
Threads::Threads
)
add_dependencies(ultrahdr libjpeg-turbo)

libultrahdr_add_executable(ultrahdr_unit_test
ultrahdr
SOURCES
"${SRC_DIR}/tests/jpegr_test.cpp"
"${SRC_DIR}/tests/gainmapmath_test.cpp"
"${SRC_DIR}/tests/icchelper_test.cpp"
"${SRC_DIR}/tests/jpegencoderhelper_test.cpp"
"${SRC_DIR}/tests/jpegdecoderhelper_test.cpp"
"${SRC_DIR}/tests/icchelper_test.cpp"
INCLUDES
"${SRC_DIR}/include"
${GTEST_INCLUDE_DIRS}
${JPEG_INCLUDE_DIR}
)
add_dependencies(ultrahdr_unit_test googletest libjpeg-turbo)

libultrahdr_add_executable(ultrahdr_app
ultrahdr
SOURCES
"${SRC_DIR}/tests/ultrahdr_app.cpp"
INCLUDES
"${SRC_DIR}/include"
${JPEG_INCLUDE_DIR}
ultrahdr
SOURCES
"${SRC_DIR}/tests/ultrahdr_app.cpp"
INCLUDES
${JPEG_INCLUDE_DIRS}
"${SRC_DIR}/include"
)
add_dependencies(ultrahdr_app googletest libjpeg-turbo)

target_link_libraries(ultrahdr_unit_test ${GTEST_LIBRARIES})

if (${ENABLE_FUZZERS})
libultrahdr_add_fuzzer(ultrahdr_enc_fuzzer ultrahdr
libultrahdr_add_fuzzer(ultrahdr_enc_fuzzer ultrahdr
SOURCES
${SRC_DIR}/fuzzer/ultrahdr_enc_fuzzer.cpp
${SRC_DIR}/fuzzer/ultrahdr_enc_fuzzer.cpp
INCLUDES
${SRC_DIR}/include
${JPEG_INCLUDE_DIR}
)
add_dependencies(ultrahdr_enc_fuzzer libjpeg-turbo)
${JPEG_INCLUDE_DIRS}
"${SRC_DIR}/include"
)

libultrahdr_add_fuzzer(ultrahdr_dec_fuzzer ultrahdr
SOURCES
${SRC_DIR}/fuzzer/ultrahdr_dec_fuzzer.cpp
INCLUDES
${JPEG_INCLUDE_DIRS}
"${SRC_DIR}/include"
)
endif()

libultrahdr_add_fuzzer(ultrahdr_dec_fuzzer ultrahdr
if(${ENABLE_TESTS})
libultrahdr_add_executable(ultrahdr_unit_test
ultrahdr
SOURCES
${SRC_DIR}/fuzzer/ultrahdr_dec_fuzzer.cpp
"${SRC_DIR}/tests/jpegr_test.cpp"
"${SRC_DIR}/tests/gainmapmath_test.cpp"
"${SRC_DIR}/tests/icchelper_test.cpp"
"${SRC_DIR}/tests/jpegencoderhelper_test.cpp"
"${SRC_DIR}/tests/jpegdecoderhelper_test.cpp"
"${SRC_DIR}/tests/icchelper_test.cpp"
INCLUDES
${SRC_DIR}/include
${JPEG_INCLUDE_DIR}
)
add_dependencies(ultrahdr_dec_fuzzer libjpeg-turbo)
${JPEG_INCLUDE_DIRS}
${GTEST_INCLUDE_DIRS}
"${SRC_DIR}/include"
)

target_link_libraries(ultrahdr_unit_test ${GTEST_BOTH_LIBRARIES})

execute_process(COMMAND cmake -E create_symlink
"${SRC_DIR}/third_party/data/"
"${CMAKE_CURRENT_BINARY_DIR}/data"
)

add_test(NAME UltraHdrUnitTests, COMMAND ultrahdr_unit_test)
endif()
101 changes: 71 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,71 @@
## Format Introduction
https://developer.android.com/guide/topics/media/platform/hdr-image-format

## Getting Started

Supports:
- x86_32/x86_64 on Linux
- macOS

Preferred Compiler: Clang
Tested with:
- C compiler: Clang 15.0.7
- CXX compiler: Clang 15.0.7

## Building Commands

### For x86_32 on a x86_64 Linux machine
```
$ mkdir build
$ cd build
$ cmake ..
$ make
```
### For macOS
```
$ mkdir build
$ cd build
$ cmake ..
$ make
```
Background
==========

libultrahdr is an image compression library that uses gain map technology
to store and distribute HDR images. Conceptually on the encoding side, the
library accepts SDR and HDR rendition of an image and from these a Gain Map
(quotient between the two renditions) is computed. The library then uses
backward compatible means to store the base image (SDR), gain map image and
some associated metadata. Legacy readers that dont support parsing the
gain map image and/or metadata, will display the base image. Readers that
support the format combine the base image with the gain map and render a
high dynamic range image on compatible displays.

More information about libultrahdr can be found at
<https://developer.android.com/guide/topics/media/platform/hdr-image-format>.


Building libultrahdr
======================

libultrahdr compresses base image and gain map image in to jpeg format.
For this libjpeg is used. This is cloned from
<https://github.com/libjpeg-turbo/libjpeg-turbo.git> and included in the
build process.

### Requirements

- [CMake](http://www.cmake.org) v3.5 or later

- [NASM](http://www.nasm.us) or [Yasm](http://yasm.tortall.net)
(If libjpeg-turbo is building on x86 or x86-64 with SIMD extensions)
* If using NASM, 2.13 or later is required.
* If using Yasm, 1.2.0 or later is required.
* If building on macOS, NASM or Yasm can be obtained from
[MacPorts](http://www.macports.org/) or [Homebrew](http://brew.sh/).

Tested with GCC v11.4 and Clang 14.0.0 on Linux and Mac Platforms.

### Building Commands

To build libultrahdr and sample application:

mkdir {build_directory}
cd {build_directory}
cmake ../ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
make

To build unit tests:

mkdir {build_directory}
cd {build_directory}
cmake ../ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DENABLE_TESTS=1
make
ctest

This will generate the following files under *{build_directory}*:

**libultrahdr.a**<br> Static link library for the ultrahdr API

**ultrahdr_app**<br> Sample application demonstrating ultrahdr API

**ultrahdr_unit_test**<br> Unit tests

Using libultrahdr
===================

libultrahdr includes two classes of APIs, one to compress and the other to
decompress HDR images:

- Refer to [jpegr.h](include/ultrahdr/jpegr.h) for detailed description of various encode and decode api.
- Refer to [ultrahdr_app.cpp](tests/ultrahdr_app.cpp) for examples of its usage.

0 comments on commit 67c7ff0

Please sign in to comment.