diff --git a/.gitignore b/.gitignore index 93524df8..82608382 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -build/ + +CMakeUserPresets.json # VS project and working files *.vcxproj.user diff --git a/.reuse/dep5 b/.reuse/dep5 deleted file mode 100644 index cdba7ccf..00000000 --- a/.reuse/dep5 +++ /dev/null @@ -1,30 +0,0 @@ -Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ -Upstream-Name: basis_universal -Source: https://github.com/BinomialLLC/basis_universal - -# We have asked Binomial about REUSE compliance for their repo, see https://github.com/BinomialLLC/basis_universal/issues/165 -Files: * -Copyright: 2019-2024 Binomial LLC - 2016 The Android Open Source Project -License: Apache-2.0 - -Files: OpenCL/* -Copyright: 2008-2020 The Khronos Group Inc. -License: Apache-2.0 - -Files: zstd/* -Copyright: 2016-present Facebook, Inc. -License: BSD-3-Clause - -Files: encoder/3rdparty/tinyexr.h -Copyright: 2014 - 2021, Syoyo Fujita and many contributors. - 2002 Industrial Light & Magic, a division of Lucas -License: BSD-3-Clause - -Files: encoder/3rdparty/qoi.h -Copyright: 2021 Dominic Szablewski - https://phoboslab.org -License: MIT - -Files: encoder/3rdparty/tinydds.h -Copyright: 2019 DeanoC -License: MIT diff --git a/CMakeLists.txt b/CMakeLists.txt index 97a6e3ec..06f3d39b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,39 +1,61 @@ # Important: The Basis Universal encoder and transcoder libraries must be compiled with -fno-strict-aliasing (MSVC's default, and also the Linux kernel). # It should also work without this option, but we do not test with it. -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.16) + +if (NOT CMAKE_OSX_DEPLOYMENT_TARGET) + # Needed otherwise Xcode builds with the default installed SDK which can often be + # more recent than the macOS version being used. + set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0" CACHE STRING "macOS Deployment Target") +endif() project(basisu C CXX) -set(CMAKE_CXX_STANDARD 17) -option(STATIC "static linking" FALSE) -option(SAN "sanitize" FALSE) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) +option(BASISU_TOOL "Include basisu tool in build" TRUE) +option(BASISU_EXAMPLES "Include examples in build" TRUE) + +option(BASISU_STATIC "static linking" TRUE) +option(BASISU_SAN "sanitize" FALSE) + +# Using a generator expression here prevents multi-config generators (VS, Xcode, Ninja Multi-Config) +# from appending a per-configuration subdirectory. NOTE: This means the output could be overwritten +# by a subsequent build for a different configuration. +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY $<1:${CMAKE_SOURCE_DIR}/bin>) # For MSVC builds default to SSE enabled, and determine if it's a 64-bit (-A x64) vs. 32-bit (-A Win32) build. if (MSVC) - option(SSE "SSE 4.1 support" TRUE) - if ( CMAKE_GENERATOR_PLATFORM STREQUAL Win32 ) - set(BUILD_X64 0) + # TODO: Fix me for Windows ARM + option(BASISU_SSE "SSE 4.1 support" TRUE) + if ( CMAKE_GENERATOR_PLATFORM STREQUAL Win32 ) + set(BASISU_BUILD_X64 0) else() - set(BUILD_X64 1) + set(BASISU_BUILD_X64 1) endif() add_compile_options(/W4) else() - option(SSE "SSE 4.1 support" FALSE) - option(BUILD_X64 "build 64-bit" TRUE) + option(BASISU_SSE "SSE 4.1 support" FALSE) + option(BASISU_BUILD_X64 "build 64-bit" TRUE) endif() -option(ZSTD "ZSTD support for KTX2 transcoding/encoding" TRUE) -option(OPENCL "OpenCL support in encoder" FALSE) +option(BASISU_ZSTD "ZSTD support for KTX2 transcoding/encoding" TRUE) +option(BASISU_OPENCL "OpenCL support in encoder" FALSE) -message("Initial BUILD_X64=${BUILD_X64}") +message("Initial BASISU_BUILD_X64=${BASISU_BUILD_X64}") message("Initial CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") -message("Initial SSE=${SSE}") -message("Initial ZSTD=${ZSTD}") -message("Initial OPENCL=${OPENCL}") -message("Initial SAN=${SAN}") +message("Initial BASISU_SSE=${BASISU_SSE}") +message("Initial BASISU_ZSTD=${BASISU_ZSTD}") +message("Initial BASISU_OPENCL=${BASISU_OPENCL}") +message("Initial BASISU_SAN=${BASISU_SAN}") +message("initial BASISU_TOOL=${BASISU_TOOL}") +message("initial BASISU_EXAMPLES=${BASISU_EXAMPLES}") -if ((NOT MSVC) AND OPENCL) +if(WIN32 AND MINGW) + # Check if the Threads package is provided; if using Mingw it MIGHT be + find_package(Threads) +elseif(LINUX) + find_package(Threads REQUIRED) +endif() + +if ((NOT MSVC) AND BASISU_OPENCL) # With MSVC builds we use the Khronos lib/include files in the project's "OpenCL" directory, to completely avoid requiring fiddly to install vendor SDK's. # Otherwise we use the system's (if any). find_package(OpenCL) @@ -48,92 +70,54 @@ endif() message(${PROJECT_NAME} " build type: " ${CMAKE_BUILD_TYPE}) -if (BUILD_X64) +if (BASISU_BUILD_X64) message("Building 64-bit") else() message("Building 32-bit") endif() -if (SSE) +if (BASISU_SSE) message("SSE enabled") else() message("SSE disabled") endif() -if (ZSTD) +if (BASISU_ZSTD) message("Zstandard enabled") else() message("Zstandard disabled") endif() if (NOT MSVC) - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g") - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g") - - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") + add_compile_options(-g) - if (SAN) + if (BASISU_SAN) message("Enabling SAN") - set(SANITIZE_FLAGS "-fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize=alignment") - - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${SANITIZE_FLAGS}") - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${SANITIZE_FLAGS}") - - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${SANITIZE_FLAGS}") - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${SANITIZE_FLAGS}") + add_compile_options(-fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize=alignment) endif() - set(CMAKE_CXX_FLAGS -std=c++17) - set(GCC_COMPILE_FLAGS "-fvisibility=hidden -fPIC -fno-strict-aliasing -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 -Wall -Wextra -Wno-unused-local-typedefs -Wno-unused-value -Wno-unused-parameter -Wno-unused-variable -Wno-reorder -Wno-misleading-indentation -Wno-class-memaccess -Wno-deprecated-copy -Wno-maybe-uninitialized -Wno-unused-function -Wno-stringop-overflow -Wno-unknown-warning-option") - - if (NOT BUILD_X64) - set(GCC_COMPILE_FLAGS "${GCC_COMPILE_FLAGS} -m32") - endif() - if (EMSCRIPTEN) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -DBASISU_SUPPORT_SSE=0") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -DBASISU_SUPPORT_SSE=0") - - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_LINK_FLAGS}") - elseif (STATIC) - if (SSE) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBASISU_SUPPORT_SSE=1 -msse4.1") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBASISU_SUPPORT_SSE=1 -msse4.1") - else() - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBASISU_SUPPORT_SSE=0") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBASISU_SUPPORT_SSE=0") - endif() - - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_LINK_FLAGS} -static-libgcc -static-libstdc++ -static") - else() - if (SSE) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBASISU_SUPPORT_SSE=1 -msse4.1") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBASISU_SUPPORT_SSE=1 -msse4.1") - else() - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBASISU_SUPPORT_SSE=0") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBASISU_SUPPORT_SSE=0") - endif() - - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_LINK_FLAGS} -Wl,-rpath .") - endif() - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GCC_COMPILE_FLAGS}") - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${GCC_COMPILE_FLAGS}") - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${GCC_COMPILE_FLAGS} -D_DEBUG") + add_compile_options(-fvisibility=hidden -fPIC -fno-strict-aliasing -D_LARGEFILE64_SOURCE=1 + -D_FILE_OFFSET_BITS=64 -Wall -Wextra -Wno-unused-local-typedefs + -Wno-unused-value -Wno-unused-parameter -Wno-unused-variable + -Wno-misleading-indentation + -Wno-maybe-uninitialized -Wno-unused-function + -Wno-stringop-overflow -Wno-unknown-warning-option) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COMPILE_FLAGS}") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${GCC_COMPILE_FLAGS}") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${GCC_COMPILE_FLAGS} -D_DEBUG") -else() - if (SSE) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBASISU_SUPPORT_SSE=1") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBASISU_SUPPORT_SSE=1") - else() - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBASISU_SUPPORT_SSE=0") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBASISU_SUPPORT_SSE=0") + # AppleClang 14 raises this warning in zstd.cpp. + add_compile_options("$<$,$,17>>:-Wno-bitwise-instead-of-logical>") + + add_compile_options("$<$:-Wno-reorder;-Wno-class-memaccess;-Wno-deprecated-copy>") + + add_compile_options($<$>:-m32>) + add_compile_definitions($<$:_DEBUG>) + if (EMSCRIPTEN) + add_link_options("SHELL:-s ALLOW_MEMORY_GROWTH=1") endif() +else() + add_compile_options("$<$:-Wno-unused-variable;-Wno-unused-function>") endif() # Define the source files for the static library @@ -163,66 +147,126 @@ set(ENCODER_LIB_SRC_LIST transcoder/basisu_transcoder.cpp ) -if (ZSTD) +set(ENCODER_LIB_HDR_LIST + encoder/basisu_astc_hdr_6x6_enc.h + encoder/basisu_astc_hdr_common.h + encoder/basisu_backend.h + encoder/basisu_basis_file.h + encoder/basisu_bc7enc.h + encoder/basisu_comp.h + encoder/basisu_enc.h + encoder/basisu_etc.h + encoder/basisu_frontend.h + encoder/basisu_gpu_texture.h + encoder/basisu_kernels_declares.h + encoder/basisu_kernels_imp.h + encoder/basisu_math.h + encoder/basisu_miniz.h + encoder/basisu_ocl_kernels.h + encoder/basisu_opencl.h + encoder/basisu_pvrtc1_4.h + encoder/basisu_resampler_filters.h + encoder/basisu_resampler.h + encoder/basisu_ssim.h + encoder/basisu_uastc_enc.h + encoder/basisu_uastc_hdr_4x4_enc.h + encoder/cppspmd_flow.h + encoder/cppspmd_math_declares.h + encoder/cppspmd_math.h + encoder/cppspmd_sse.h + encoder/cppspmd_type_aliases.h + encoder/jpgd.h + encoder/pvpngreader.h + encoder/3rdparty/android_astc_decomp.h + encoder/3rdparty/qoi.h + encoder/3rdparty/tinyexr.h + transcoder/basisu_astc_hdr_core.h + transcoder/basisu_astc_helpers.h + transcoder/basisu_containers_impl.h + transcoder/basisu_containers.h + transcoder/basisu_file_headers.h + transcoder/basisu_transcoder_internal.h + transcoder/basisu_transcoder_uastc.h + transcoder/basisu_transcoder.h + transcoder/basisu.h +) + +if (BASISU_ZSTD) set(ENCODER_LIB_SRC_LIST ${ENCODER_LIB_SRC_LIST} zstd/zstd.c) + set(ENCODER_LIB_HDR_LIST ${ENCODER_LIB_HDR_LIST} zstd/zstd.h) endif() # Create the static library -add_library(basisu_encoder STATIC ${ENCODER_LIB_SRC_LIST}) +add_library(basisu_encoder STATIC ${ENCODER_LIB_SRC_LIST} ${ENCODER_LIB_HDR_LIST}) -# Create the basisu executable and link against the static library -add_executable(basisu basisu_tool.cpp) -target_link_libraries(basisu PRIVATE basisu_encoder) - -# Create the new example executable and link against the static library -add_executable(examples example/example.cpp) -target_link_libraries(examples PRIVATE basisu_encoder) +target_include_directories(basisu_encoder +INTERFACE + $ + $ # So KTX-Software can use it. +) +# PUBLIC so it will be exported to dependent programs. +target_compile_features(basisu_encoder PUBLIC cxx_std_17) -if (ZSTD) - target_compile_definitions(basisu PRIVATE BASISD_SUPPORT_KTX2_ZSTD=1) - target_compile_definitions(examples PRIVATE BASISD_SUPPORT_KTX2_ZSTD=1) +if (EMSCRIPTEN) + target_compile_definitions(basisu_encoder PRIVATE BASISU_SUPPORT_SSE=0) else() - target_compile_definitions(basisu PRIVATE BASISD_SUPPORT_KTX2_ZSTD=0) - target_compile_definitions(examples PRIVATE BASISD_SUPPORT_KTX2_ZSTD=0) + target_compile_options(basisu_encoder PRIVATE + "$,-DBASISU_SUPPORT_SSE=1;$<$:-msse4.1>,-DBASISU_SUPPORT_SSE=0>" + ) endif() if (NOT MSVC) # For Non-Windows builds, let cmake try and find the system OpenCL headers/libs for us. - if (OPENCL AND OPENCL_FOUND) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBASISU_SUPPORT_OPENCL=1") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBASISU_SUPPORT_OPENCL=1") - - target_include_directories(basisu PRIVATE ${OpenCL_INCLUDE_DIRS}) - target_include_directories(examples PRIVATE ${OpenCL_INCLUDE_DIRS}) - target_include_directories(basisu_encoder PRIVATE ${OpenCL_INCLUDE_DIRS}) - set(BASISU_EXTRA_LIBS ${OpenCL_LIBRARIES}) + if (BASISU_OPENCL AND OPENCL_FOUND) + target_compile_definitions(basisu_encoder PRIVATE BASISU_SUPPORT_OPENCL=1) + + target_include_directories(basisu_encoder INTERFACE ${OpenCL_INCLUDE_DIRS}) + target_link_libraries(basisu_encoder INTERFACE ${OpenCL_LIBRARIES}) + endif() + target_link_libraries(basisu_encoder INTERFACE m) + if(Threads_FOUND AND CMAKE_USE_PTHREADS_INIT) + target_link_libraries(basisu_encoder INTERFACE Threads::Threads) + elseif(LINUX) + target_link_libraries(basisu_encoder INTERFACE dl Threads::Threads) + endif() + if (BASISU_STATIC AND MINGW) + target_link_options(basisu_encoder INTERFACE -static-libgcc -static-libstdc++ -static) endif() else() # For Windows builds, we use our local copies of the OpenCL import lib and Khronos headers. - if (OPENCL) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBASISU_SUPPORT_OPENCL=1") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBASISU_SUPPORT_OPENCL=1") - - target_include_directories(basisu PRIVATE "OpenCL") - target_include_directories(examples PRIVATE "OpenCL") - target_include_directories(basisu_encoder PRIVATE "OpenCL") - - if (BUILD_X64) - target_link_libraries(basisu PRIVATE "${CMAKE_SOURCE_DIR}/OpenCL/lib/OpenCL64.lib") - target_link_libraries(examples PRIVATE "${CMAKE_SOURCE_DIR}/OpenCL/lib/OpenCL64.lib") + if (BASISU_OPENCL) + target_compile_definitions(basisu_encoder PRIVATE BASISU_SUPPORT_OPENCL=1) + target_include_directories(basisu_encoder INTERFACE "OpenCL") + + if (BASISU_BUILD_X64) + target_link_libraries(basisu_encoder INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/OpenCL/lib/OpenCL64.lib") else() - target_link_libraries(basisu PRIVATE "${CMAKE_SOURCE_DIR}/OpenCL/lib/OpenCL.lib") - target_link_libraries(examples PRIVATE "${CMAKE_SOURCE_DIR}/OpenCL/lib/OpenCL.lib") + target_link_libraries(basisu_encoder INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/OpenCL/lib/OpenCL.lib") endif() endif() endif() -if (NOT MSVC) - target_link_libraries(basisu PRIVATE m pthread ${BASISU_EXTRA_LIBS}) - target_link_libraries(examples PRIVATE m pthread ${BASISU_EXTRA_LIBS}) +macro(set_common_executable_properties target) + target_compile_definitions(${target} PRIVATE BASISD_SUPPORT_KTX2_ZSTD=$,1,0>) + target_link_libraries(${target} PRIVATE basisu_encoder) + if (NOT BASISU_STATIC AND NOT EMSCRIPTEN AND NOT WIN32) + target_link_options(${target} PUBLIC -Wl,-rpath .) + endif() +endmacro() + +if (BASISU_TOOL) + # Create the basisu executable and link against the static library + add_executable(basisu basisu_tool.cpp) + set_common_executable_properties(basisu) endif() -if (NOT EMSCRIPTEN) +if (BASISU_EXAMPLES) + # Create the new example executable and link against the static library + add_executable(examples example/example.cpp) + set_common_executable_properties(examples) +endif() + +if (BASISU_TOOL AND NOT EMSCRIPTEN) if (UNIX) if (CMAKE_BUILD_TYPE STREQUAL Release) if (APPLE) @@ -236,20 +280,3 @@ if (NOT EMSCRIPTEN) endif() endif() -if (MSVC) - set_target_properties(basisu PROPERTIES - RUNTIME_OUTPUT_NAME "basisu" - RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - ) - - set_target_properties(examples PROPERTIES - RUNTIME_OUTPUT_NAME "examples" - RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - ) -endif() diff --git a/LICENSES/BSD-3-clause.txt b/LICENSES/BSD-3-Clause.txt similarity index 100% rename from LICENSES/BSD-3-clause.txt rename to LICENSES/BSD-3-Clause.txt diff --git a/LICENSES/Zlib.txt b/LICENSES/Zlib.txt deleted file mode 100644 index 508a9b5b..00000000 --- a/LICENSES/Zlib.txt +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. diff --git a/REUSE.toml b/REUSE.toml new file mode 100644 index 00000000..a63c36ac --- /dev/null +++ b/REUSE.toml @@ -0,0 +1,39 @@ +version = 1 +SPDX-PackageName = "basis_universal" +SPDX-PackageDownloadLocation = "https://github.com/BinomialLLC/basis_universal" + +[[annotations]] +path = "**" +precedence = "aggregate" +SPDX-FileCopyrightText = ["2019-2024 Binomial LLC", "2016 The Android Open Source Project"] +SPDX-License-Identifier = "Apache-2.0" + +[[annotations]] +path = "OpenCL/**" +precedence = "aggregate" +SPDX-FileCopyrightText = "2008-2020 The Khronos Group Inc." +SPDX-License-Identifier = "Apache-2.0" + +[[annotations]] +path = "zstd/**" +precedence = "aggregate" +SPDX-FileCopyrightText = "2016-present Facebook, Inc." +SPDX-License-Identifier = "BSD-3-Clause" + +[[annotations]] +path = "encoder/3rdparty/tinyexr.h" +precedence = "aggregate" +SPDX-FileCopyrightText = ["2014 - 2021, Syoyo Fujita and many contributors.", "2002 Industrial Light & Magic, a division of Lucas"] +SPDX-License-Identifier = "BSD-3-Clause" + +[[annotations]] +path = "encoder/3rdparty/qoi.h" +precedence = "aggregate" +SPDX-FileCopyrightText = "2021 Dominic Szablewski - https://phoboslab.org" +SPDX-License-Identifier = "MIT" + +[[annotations]] +path = "encoder/3rdparty/tinydds.h" +precedence = "aggregate" +SPDX-FileCopyrightText = "2019 DeanoC" +SPDX-License-Identifier = "MIT" diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 00000000..ecb3b59e --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1,7 @@ + +* + +!.gitignore +!ocl_kernels.cl +!clean.bat +!readme.txt diff --git a/build/.gitignore b/build/.gitignore new file mode 100644 index 00000000..3467e412 --- /dev/null +++ b/build/.gitignore @@ -0,0 +1,5 @@ + +* + +!.gitignore +!readme.txt diff --git a/encoder/3rdparty/android_astc_decomp.cpp b/encoder/3rdparty/android_astc_decomp.cpp index a667d0d6..af6090ef 100644 --- a/encoder/3rdparty/android_astc_decomp.cpp +++ b/encoder/3rdparty/android_astc_decomp.cpp @@ -1880,7 +1880,7 @@ half_float float_to_half(float val, bool toward_zero) if (toward_zero) m = (int)truncf((1 << 24) * fabsf(fi.f)); else - m = lrintf((1 << 24) * fabsf(fi.f)); + m = (int)lrintf((1 << 24) * fabsf(fi.f)); } else { @@ -1888,7 +1888,7 @@ half_float float_to_half(float val, bool toward_zero) if (toward_zero) m = (int)truncf((float)flt_m * (1.0f / (float)(1 << 13))); else - m = lrintf((float)flt_m * (1.0f / (float)(1 << 13))); + m = (int)lrintf((float)flt_m * (1.0f / (float)(1 << 13))); } } diff --git a/encoder/3rdparty/qoi.h b/encoder/3rdparty/qoi.h index be8a2d53..5c6de086 100644 --- a/encoder/3rdparty/qoi.h +++ b/encoder/3rdparty/qoi.h @@ -345,7 +345,7 @@ static void qoi_write_32(unsigned char *bytes, int *p, unsigned int v) { bytes[(*p)++] = (uint8_t)((0x000000ff & v)); } -static unsigned int qoi_read_32(const unsigned char *bytes, int *p) { +static unsigned int qoi_read_32(const unsigned char *bytes, size_t *p) { unsigned int a = bytes[(*p)++]; unsigned int b = bytes[(*p)++]; unsigned int c = bytes[(*p)++]; @@ -485,14 +485,15 @@ void *qoi_encode(const void *data, const qoi_desc *desc, int *out_len) { return bytes; } -void *qoi_decode(const void *data, int size, qoi_desc *desc, int channels) { +void *qoi_decode(const void *data, size_t size, qoi_desc *desc, int channels) { const unsigned char *bytes; unsigned int header_magic; unsigned char *pixels; qoi_rgba_t index[64]; qoi_rgba_t px; - int px_len, chunks_len, px_pos; - int p = 0, run = 0; + int px_len, px_pos; + size_t chunks_len, p = 0; + int run = 0; if ( data == NULL || desc == NULL || @@ -628,7 +629,7 @@ void *qoi_read(const char *filename, qoi_desc *desc, int channels) { #else FILE *f = fopen(filename, "rb"); #endif - int size, bytes_read; + size_t size, bytes_read; void *pixels, *data; if (!f) { diff --git a/encoder/3rdparty/tinyexr.h b/encoder/3rdparty/tinyexr.h index a2a065a0..405827ed 100644 --- a/encoder/3rdparty/tinyexr.h +++ b/encoder/3rdparty/tinyexr.h @@ -4928,7 +4928,7 @@ static int DecodeTiledLevel(EXRImage* exr_image, const EXRHeader* exr_header, } #endif exr_image->tiles = static_cast( - calloc(sizeof(EXRTile), static_cast(num_tiles))); + calloc(static_cast(num_tiles), sizeof(EXRTile))); #if TINYEXR_HAS_CXX11 && (TINYEXR_USE_THREAD > 0) std::vector workers; diff --git a/encoder/basisu_enc.h b/encoder/basisu_enc.h index a565803e..5bdb7830 100644 --- a/encoder/basisu_enc.h +++ b/encoder/basisu_enc.h @@ -2164,7 +2164,7 @@ namespace basisu uint32_t max_threads, job_pool *pJob_pool, bool even_odd_input_pairs_equal) { - typedef bit_hasher training_vec_bit_hasher; + //typedef bit_hasher training_vec_bit_hasher; // rg 6/24/2025 - Cross platform determinism #if 0 @@ -4216,11 +4216,11 @@ namespace basisu if (new_exp > 15) e = 31; else if (new_exp < -14) - m = lrintf((1 << 24) * fabsf(fi.f)); + m = (int)lrintf((1 << 24) * fabsf(fi.f)); else { e = new_exp + 15; - m = lrintf(flt_m * (1.0f / ((float)(1 << 13)))); + m = (int)lrintf(flt_m * (1.0f / ((float)(1 << 13)))); } } diff --git a/encoder/basisu_pvrtc1_4.h b/encoder/basisu_pvrtc1_4.h index a9fe6b27..136715e3 100644 --- a/encoder/basisu_pvrtc1_4.h +++ b/encoder/basisu_pvrtc1_4.h @@ -231,18 +231,14 @@ namespace basisu inline void set_to_black() { -#ifndef __EMSCRIPTEN__ -#ifdef __GNUC__ +#if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wclass-memaccess" -#endif #endif memset(m_blocks.get_ptr(), 0, m_blocks.size_in_bytes()); -#ifndef __EMSCRIPTEN__ -#ifdef __GNUC__ +#if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic pop #endif -#endif } inline bool get_block_uses_transparent_modulation(uint32_t bx, uint32_t by) const diff --git a/encoder/pvpngreader.cpp b/encoder/pvpngreader.cpp index 6b32f66c..720884a8 100644 --- a/encoder/pvpngreader.cpp +++ b/encoder/pvpngreader.cpp @@ -609,7 +609,7 @@ int png_decoder::fetch_next_chunk_data(uint8_t* buf, int bytes) #endif if (check_crc32) - m_chunk_crc32 = buminiz::mz_crc32(m_chunk_crc32, buf, bytes); + m_chunk_crc32 = static_cast(buminiz::mz_crc32(m_chunk_crc32, buf, bytes)); if ((m_chunk_left -= bytes) == 0) { diff --git a/transcoder/basisu.h b/transcoder/basisu.h index e1f71611..091882e5 100644 --- a/transcoder/basisu.h +++ b/transcoder/basisu.h @@ -107,20 +107,16 @@ namespace basisu debug_puts(res.c_str()); } -#ifndef __EMSCRIPTEN__ -#ifdef __GNUC__ +#if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wclass-memaccess" -#endif #endif template inline void clear_obj(T& obj) { memset((void *)&obj, 0, sizeof(obj)); } -#ifndef __EMSCRIPTEN__ -#ifdef __GNUC__ +#if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic pop #endif -#endif constexpr double cPiD = 3.14159265358979323846264338327950288; constexpr float REALLY_SMALL_FLOAT_VAL = .000000125f; diff --git a/transcoder/basisu_astc_helpers.h b/transcoder/basisu_astc_helpers.h index 428a964b..4451e1f3 100644 --- a/transcoder/basisu_astc_helpers.h +++ b/transcoder/basisu_astc_helpers.h @@ -1194,7 +1194,7 @@ namespace astc_helpers for (uint32_t i = 0; i < total_levels; i++) { const int qv = dequant_bise_endpoint(i, ise_range); - int e = labs(v - qv); + int e = (int)labs(v - qv); if (e < best_e) { best_e = e; @@ -1217,7 +1217,7 @@ namespace astc_helpers for (uint32_t i = 0; i < total_levels; i++) { const int qv = dequant_bise_weight(i, ise_range); - int e = labs(v - qv); + int e = (int)labs(v - qv); if (e < best_e) { best_e = e; @@ -2183,7 +2183,7 @@ namespace astc_helpers if (toward_zero) m = (int)truncf((1 << 24) * fabsf(fi.f)); else - m = lrintf((1 << 24) * fabsf(fi.f)); + m = (int)lrintf((1 << 24) * fabsf(fi.f)); } else { @@ -2191,7 +2191,7 @@ namespace astc_helpers if (toward_zero) m = (int)truncf((float)flt_m * (1.0f / (float)(1 << 13))); else - m = lrintf((float)flt_m * (1.0f / (float)(1 << 13))); + m = (int)lrintf((float)flt_m * (1.0f / (float)(1 << 13))); } } diff --git a/transcoder/basisu_containers.h b/transcoder/basisu_containers.h index 82b78cba..68b35583 100644 --- a/transcoder/basisu_containers.h +++ b/transcoder/basisu_containers.h @@ -1504,20 +1504,16 @@ namespace basisu if (BASISU_IS_BITWISE_COPYABLE(T)) { -#ifndef __EMSCRIPTEN__ -#ifdef __GNUC__ +#if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wclass-memaccess" -#endif #endif if ((m_p) && (other.m_p)) { memcpy(m_p, other.m_p, m_size * sizeof(T)); } -#ifndef __EMSCRIPTEN__ -#ifdef __GNUC__ +#if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic pop -#endif #endif } else @@ -1649,18 +1645,14 @@ namespace basisu if (BASISU_IS_BITWISE_COPYABLE(T)) { -#ifndef __EMSCRIPTEN__ -#ifdef __GNUC__ +#if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wclass-memaccess" -#endif #endif if ((m_p) && (other.m_p)) memcpy((void *)m_p, other.m_p, other.m_size * sizeof(T)); -#ifndef __EMSCRIPTEN__ -#ifdef __GNUC__ +#if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic pop -#endif #endif } else @@ -2234,19 +2226,15 @@ namespace basisu // Copy "down" the objects to preserve, filling in the empty slots. -#ifndef __EMSCRIPTEN__ -#ifdef __GNUC__ +#if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wclass-memaccess" -#endif #endif memmove((void *)pDst, pSrc, num_to_move * sizeof(T)); -#ifndef __EMSCRIPTEN__ -#ifdef __GNUC__ +#if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic pop -#endif #endif } else @@ -2492,18 +2480,14 @@ namespace basisu { if ((sizeof(T) == 1) && (scalar_type::cFlag)) { -#ifndef __EMSCRIPTEN__ -#ifdef __GNUC__ +#if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wclass-memaccess" -#endif #endif memset(m_p, *reinterpret_cast(&o), m_size); -#ifndef __EMSCRIPTEN__ -#ifdef __GNUC__ +#if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic pop -#endif #endif } else diff --git a/transcoder/basisu_transcoder.cpp b/transcoder/basisu_transcoder.cpp index da8cd43c..7d16bb40 100644 --- a/transcoder/basisu_transcoder.cpp +++ b/transcoder/basisu_transcoder.cpp @@ -19973,11 +19973,11 @@ namespace basist if (new_exp > 15) e = 31; else if (new_exp < -14) - m = lrintf((1 << 24) * fabsf(fi.f)); + m = (int)lrintf((1 << 24) * fabsf(fi.f)); else { e = new_exp + 15; - m = lrintf(flt_m * (1.0f / ((float)(1 << 13)))); + m = (int)lrintf(flt_m * (1.0f / ((float)(1 << 13)))); } } @@ -22344,7 +22344,7 @@ namespace basist if (d >= mid_dots[mid]) low = mid + 1; best_idx = low; - assert((best_idx >= 0) && (best_idx <= 15)); + assert((best_idx <= 15)); pWeights[i] = (uint8_t)best_idx; @@ -22376,7 +22376,7 @@ namespace basist if (d >= mid_dots[mid]) low = mid + 1; best_idx = low; - assert((best_idx >= 0) && (best_idx <= 15)); + assert((best_idx <= 15)); float err = basisu::squaref(qr - cr[best_idx]) + basisu::squaref(qg - cg[best_idx]) + basisu::squaref(qb - cb[best_idx]);