diff --git a/CMakeLists.txt b/CMakeLists.txt index 49c9c95a3f..f02f4c7b4b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -218,6 +218,7 @@ if (NOT ANDROID) add_subdirectory(${LIBRARIES}/bluegl) add_subdirectory(${LIBRARIES}/filagui) add_subdirectory(${LIBRARIES}/image) + add_subdirectory(${LIBRARIES}/imageio) add_subdirectory(${FILAMENT}/java) diff --git a/libs/image/CMakeLists.txt b/libs/image/CMakeLists.txt index f1437d70b3..3a80f46445 100644 --- a/libs/image/CMakeLists.txt +++ b/libs/image/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.1) -project(images) +project(image) set(TARGET image) set(PUBLIC_HDR_DIR include) @@ -7,13 +7,13 @@ set(PUBLIC_HDR_DIR include) # ================================================================================================== # Sources and headers # ================================================================================================== -file(GLOB_RECURSE PUBLIC_HDRS ${PUBLIC_HDR_DIR}/${TARGET}/*.h) +set(PUBLIC_HDRS + include/image/Image.h + include/image/utilities.h +) set(SRCS src/Image.cpp - src/ImageDecoder.cpp - src/ImageEncoder.cpp - src/utilities.h ) # ================================================================================================== @@ -23,10 +23,7 @@ include_directories(${PUBLIC_HDR_DIR}) add_library(${TARGET} STATIC ${PUBLIC_HDRS} ${SRCS}) -target_link_libraries(${TARGET} PUBLIC math png tinyexr utils z) -if (WIN32) - target_link_libraries(${TARGET} PRIVATE wsock32) -endif() +target_link_libraries(${TARGET} PUBLIC math) target_include_directories(${TARGET} PUBLIC ${PUBLIC_HDR_DIR}) diff --git a/libs/image/include/image/Image.h b/libs/image/include/image/Image.h index c22cd41087..07374fc685 100644 --- a/libs/image/include/image/Image.h +++ b/libs/image/include/image/Image.h @@ -20,6 +20,10 @@ #include #include +/** + * This namespace defines types and free functions for both the core "image" library (minimal + * dependencies) as well as the "imageio" library (for loading and saving files). + */ namespace image { class Image { diff --git a/libs/image/src/utilities.h b/libs/image/include/image/utilities.h similarity index 92% rename from libs/image/src/utilities.h rename to libs/image/include/image/utilities.h index da5da98f2c..4fbd323da3 100644 --- a/libs/image/src/utilities.h +++ b/libs/image/include/image/utilities.h @@ -17,15 +17,9 @@ #ifndef IMAGE_UTILITIES_H_ #define IMAGE_UTILITIES_H_ -template -inline T clamp(T v, T min, T max) { - return std::max(T(min), std::min(v, T(max))); -} +#include -template -inline T saturate(T v) { - return clamp(v, T(0), T(1)); -} +namespace image { template inline math::float4 linearToRGBM(const T& linear) { @@ -40,7 +34,7 @@ inline math::float4 linearToRGBM(const T& linear) { float maxComponent = std::max(std::max(RGBM.r, RGBM.g), std::max(RGBM.b, 1e-6f)); // Don't let M go below 1 in the [0..16] range - RGBM.a = clamp(maxComponent, 1.0f / 16.0f, 1.0f); + RGBM.a = math::clamp(maxComponent, 1.0f / 16.0f, 1.0f); RGBM.a = std::ceil(RGBM.a * 255.0f) / 255.0f; RGBM.rgb = saturate(RGBM.rgb / RGBM.a); @@ -124,5 +118,7 @@ inline math::float4 sRGBToLinear(const math::float4& sRGB) { return linear; } +} + #endif // IMAGE_UTILITIES_H_ diff --git a/libs/imageio/CMakeLists.txt b/libs/imageio/CMakeLists.txt new file mode 100644 index 0000000000..496d1d868f --- /dev/null +++ b/libs/imageio/CMakeLists.txt @@ -0,0 +1,40 @@ +cmake_minimum_required(VERSION 3.1) +project(imageio) + +set(TARGET imageio) +set(PUBLIC_HDR_DIR include) + +# ================================================================================================== +# Sources and headers +# ================================================================================================== +set(PUBLIC_HDRS + include/imageio/ImageDecoder.h + include/imageio/ImageEncoder.h +) + +set(SRCS + src/ImageDecoder.cpp + src/ImageEncoder.cpp +) + +# ================================================================================================== +# Include and target definitions +# ================================================================================================== +include_directories(${PUBLIC_HDR_DIR}) + +add_library(${TARGET} STATIC ${PUBLIC_HDRS} ${SRCS}) + +target_include_directories(${TARGET} PUBLIC ${PUBLIC_HDR_DIR}) + +target_link_libraries(${TARGET} PUBLIC image math png tinyexr utils z) +if (WIN32) + target_link_libraries(${TARGET} PRIVATE wsock32) +endif() + +# ================================================================================================== +# Compiler flags +# ================================================================================================== +target_compile_options(${TARGET} PRIVATE + -Wno-deprecated-register + $<$:-ffast-math> +) diff --git a/libs/image/include/image/ImageDecoder.h b/libs/imageio/include/imageio/ImageDecoder.h similarity index 100% rename from libs/image/include/image/ImageDecoder.h rename to libs/imageio/include/imageio/ImageDecoder.h diff --git a/libs/image/include/image/ImageEncoder.h b/libs/imageio/include/imageio/ImageEncoder.h similarity index 100% rename from libs/image/include/image/ImageEncoder.h rename to libs/imageio/include/imageio/ImageEncoder.h diff --git a/libs/image/src/ImageDecoder.cpp b/libs/imageio/src/ImageDecoder.cpp similarity index 99% rename from libs/image/src/ImageDecoder.cpp rename to libs/imageio/src/ImageDecoder.cpp index d90092b628..c8c1393f6e 100644 --- a/libs/image/src/ImageDecoder.cpp +++ b/libs/imageio/src/ImageDecoder.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include #include #include @@ -38,7 +38,7 @@ #include -#include "utilities.h" +#include namespace image { diff --git a/libs/image/src/ImageEncoder.cpp b/libs/imageio/src/ImageEncoder.cpp similarity index 99% rename from libs/image/src/ImageEncoder.cpp rename to libs/imageio/src/ImageEncoder.cpp index 83c2d18945..8262ea3559 100644 --- a/libs/image/src/ImageEncoder.cpp +++ b/libs/imageio/src/ImageEncoder.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include #include #include @@ -38,7 +38,7 @@ #include #include -#include "utilities.h" +#include using namespace math; diff --git a/tools/cmgen/CMakeLists.txt b/tools/cmgen/CMakeLists.txt index 7ced962018..e5111e9a24 100644 --- a/tools/cmgen/CMakeLists.txt +++ b/tools/cmgen/CMakeLists.txt @@ -6,7 +6,15 @@ set(TARGET cmgen) # ================================================================================================== # Sources and headers # ================================================================================================== -file(GLOB_RECURSE HDRS src/*.h) +set(HDRS + src/JobQueue.h + src/Cubemap.h + src/CubemapIBL.h + src/CubemapSH.h + src/CubemapUtils.h + src/ProgressUpdater.h + src/utilities.h +) set(SRCS src/cmgen.cpp @@ -23,7 +31,7 @@ set(SRCS # ================================================================================================== add_executable(${TARGET} ${HDRS} ${SRCS}) -target_link_libraries(${TARGET} PRIVATE math utils z image getopt) +target_link_libraries(${TARGET} PRIVATE math utils z image imageio getopt) # ================================================================================================== # Compile options and optimizations diff --git a/tools/cmgen/src/cmgen.cpp b/tools/cmgen/src/cmgen.cpp index aac951eae8..1d080aacb5 100644 --- a/tools/cmgen/src/cmgen.cpp +++ b/tools/cmgen/src/cmgen.cpp @@ -24,8 +24,8 @@ #include #include -#include -#include +#include +#include #include diff --git a/tools/normal-blending/CMakeLists.txt b/tools/normal-blending/CMakeLists.txt index 06e98a41fc..9dfd94a63c 100644 --- a/tools/normal-blending/CMakeLists.txt +++ b/tools/normal-blending/CMakeLists.txt @@ -15,7 +15,7 @@ set(SRCS src/main.cpp) # ================================================================================================== add_executable(${TARGET} ${HDRS} ${SRCS}) -target_link_libraries(${TARGET} PRIVATE math utils z image getopt) +target_link_libraries(${TARGET} PRIVATE math utils z image imageio getopt) # ================================================================================================== # Compile options and optimizations diff --git a/tools/normal-blending/src/main.cpp b/tools/normal-blending/src/main.cpp index 3dc59f542c..99704a66f0 100644 --- a/tools/normal-blending/src/main.cpp +++ b/tools/normal-blending/src/main.cpp @@ -20,8 +20,8 @@ #include -#include -#include +#include +#include #include diff --git a/tools/roughness-prefilter/CMakeLists.txt b/tools/roughness-prefilter/CMakeLists.txt index 5778bbed94..87e6cf0f06 100644 --- a/tools/roughness-prefilter/CMakeLists.txt +++ b/tools/roughness-prefilter/CMakeLists.txt @@ -15,7 +15,7 @@ set(SRCS src/main.cpp) # ================================================================================================== add_executable(${TARGET} ${HDRS} ${SRCS}) -target_link_libraries(${TARGET} PRIVATE math utils z image getopt) +target_link_libraries(${TARGET} PRIVATE math utils z image imageio getopt) # ================================================================================================== # Compile options and optimizations diff --git a/tools/roughness-prefilter/src/main.cpp b/tools/roughness-prefilter/src/main.cpp index 8a5ced8c9e..3bd3af53a1 100644 --- a/tools/roughness-prefilter/src/main.cpp +++ b/tools/roughness-prefilter/src/main.cpp @@ -22,8 +22,8 @@ #include -#include -#include +#include +#include #include #include diff --git a/tools/skygen/CMakeLists.txt b/tools/skygen/CMakeLists.txt index a31b9913e9..f3458d4c19 100644 --- a/tools/skygen/CMakeLists.txt +++ b/tools/skygen/CMakeLists.txt @@ -6,16 +6,14 @@ set(TARGET skygen) # ================================================================================================== # Sources and headers # ================================================================================================== -file(GLOB_RECURSE HDRS src/*.h) - set(SRCS src/main.cpp) # ================================================================================================== # Target definitions # ================================================================================================== -add_executable(${TARGET} ${HDRS} ${SRCS}) +add_executable(${TARGET} ${SRCS}) -target_link_libraries(${TARGET} PRIVATE math utils z image skylight getopt) +target_link_libraries(${TARGET} PRIVATE math utils z image imageio skylight getopt) # ================================================================================================== # Compile options and optimizations diff --git a/tools/skygen/src/main.cpp b/tools/skygen/src/main.cpp index 85003e17e7..5326a42a7d 100644 --- a/tools/skygen/src/main.cpp +++ b/tools/skygen/src/main.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include