From ae6130d0c890861b547393c72f52ac5cc7d48607 Mon Sep 17 00:00:00 2001 From: ptahmose Date: Fri, 20 Sep 2024 23:28:17 +0200 Subject: [PATCH] improve msys2 compatibility (#114) --- CMakeLists.txt | 13 +++++- Src/CZICmd/BitmapGen.cpp | 2 - Src/CZICmd/BitmapGenFreeType.cpp | 1 - Src/CZICmd/BitmapGenGdiplus.cpp | 9 ++-- Src/CZICmd/BitmapGenNull.cpp | 9 ++-- Src/CZICmd/BitmapGenNull.h | 16 +++++-- Src/CZICmd/CMakeLists.txt | 46 ++++++++++--------- Src/CZICmd/CZIcmd.cpp | 20 +++----- Src/CZICmd/CZIcmd_Config.h.in | 3 ++ Src/CZICmd/SaveBitmap.cpp | 45 +++++++++--------- Src/CZICmd/cmdlineoptions.cpp | 13 +++--- Src/CZICmd/consoleio.cpp | 2 - Src/CZICmd/consoleio.h | 3 ++ Src/CZICmd/execute.cpp | 1 - Src/CZICmd/executeCreateCzi.cpp | 1 - Src/CZICmd/executePlaneScan.cpp | 1 - Src/CZICmd/inc_rapidjson.h | 2 +- Src/CZICmd/platform_defines.h | 13 ------ Src/CZICmd/stdafx.cpp | 11 ----- Src/CZICmd/stdafx.h | 28 ----------- Src/CZICmd/targetver.h | 14 ------ Src/CZICmd/utils.cpp | 6 +-- Src/CZICmd/utils.h | 3 +- Src/libCZI/CMakeLists.txt | 29 ++++++++---- Src/libCZI/CziMetadataBuilder.cpp | 2 +- Src/libCZI/CziUtils.cpp | 8 ++-- Src/libCZI/Doc/version-history.markdown | 3 +- Src/libCZI/StreamImpl.cpp | 4 +- Src/libCZI/StreamImpl.h | 10 ++-- Src/libCZI/StreamsLib/streamsFactory.cpp | 8 ++-- .../StreamsLib/windowsfileinputstream.cpp | 2 +- .../StreamsLib/windowsfileinputstream.h | 2 +- Src/libCZI/decoder_wic.cpp | 17 +++---- Src/libCZI/decoder_wic.h | 4 +- Src/libCZI/libCZI.h | 6 +-- Src/libCZI/libCZI_Config.h.in | 3 ++ Src/libCZI/libCZI_Lib.cpp | 4 +- Src/libCZI/libCZI_Site.cpp | 7 +-- Src/libCZI/utilities.cpp | 11 ++--- Src/libCZI_UnitTests/test_metadatabuilder.cpp | 4 +- 40 files changed, 172 insertions(+), 214 deletions(-) delete mode 100644 Src/CZICmd/platform_defines.h delete mode 100644 Src/CZICmd/stdafx.cpp delete mode 100644 Src/CZICmd/stdafx.h delete mode 100644 Src/CZICmd/targetver.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2532b10c..c51297f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.15) cmake_policy(SET CMP0091 NEW) # enable new "MSVC runtime library selection" (https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html) project(libCZI - VERSION 0.62.0 + VERSION 0.62.1 HOMEPAGE_URL "https://github.com/ZEISS/libczi" DESCRIPTION "libCZI is an Open Source Cross-Platform C++ library to read and write CZI") @@ -75,6 +75,17 @@ check_cxx_symbol_exists(pwrite unistd.h HAVE_UNISTD_H_PWRITE) BoolToFoundNotFound(HAVE_UNISTD_H_PWRITE HAVE_UNISTD_H_PWRITE_TEXT) message("check for open -> ${HAVE_FCNTL_H_OPEN_TEXT} ; check for pread -> ${HAVE_UNISTD_H_PREAD_TEXT} ; check for pwrite -> ${HAVE_UNISTD_H_PWRITE_TEXT}") +# Determine whether the Win32-API can be used (in other words: whether we are on a Windows-platform or targetting the Windows-platform). +# Note that just checking for WIN32 is not sufficient here, as this is not defined with environments such as msys2. In those cases, UNIX is defined. +# The meaning of this switch is: whether Win32-API can be used (and this affects not only compilation but e.g. also linking to the Win32-API, as +# it is not automatically linked to when using MinGW or Cygwin). +# TODO(JBL): check whether cross-compiling to Windows works +if (WIN32 OR CYGWIN OR MSYS OR MINGW OR CMAKE_SYSTEM_NAME STREQUAL "Windows") + set(LIBCZI_HAVE_WIN32_API ON) +else() + set(LIBCZI_HAVE_WIN32_API OFF) +endif() + # This option controls whether to build the curl-based http-/https-stream object. If this option is # "ON", the build will fail if the curl-library is not available (either as an external package or # as a private copy downloaded during the CMake-run). diff --git a/Src/CZICmd/BitmapGen.cpp b/Src/CZICmd/BitmapGen.cpp index 826b3b1e..0d5ff3b6 100644 --- a/Src/CZICmd/BitmapGen.cpp +++ b/Src/CZICmd/BitmapGen.cpp @@ -2,8 +2,6 @@ // // SPDX-License-Identifier: LGPL-3.0-or-later -#include "stdafx.h" - #include "IBitmapGen.h" #include "BitmapGenGdiplus.h" #include "BitmapGenNull.h" diff --git a/Src/CZICmd/BitmapGenFreeType.cpp b/Src/CZICmd/BitmapGenFreeType.cpp index 472a2188..9db68f7b 100644 --- a/Src/CZICmd/BitmapGenFreeType.cpp +++ b/Src/CZICmd/BitmapGenFreeType.cpp @@ -2,7 +2,6 @@ // // SPDX-License-Identifier: LGPL-3.0-or-later -#include "stdafx.h" #include "inc_CZIcmd_Config.h" #if CZICMD_USE_FREETYPE == 1 diff --git a/Src/CZICmd/BitmapGenGdiplus.cpp b/Src/CZICmd/BitmapGenGdiplus.cpp index a172dc6e..d043442e 100644 --- a/Src/CZICmd/BitmapGenGdiplus.cpp +++ b/Src/CZICmd/BitmapGenGdiplus.cpp @@ -2,7 +2,6 @@ // // SPDX-License-Identifier: LGPL-3.0-or-later -#include "stdafx.h" #include "BitmapGenGdiplus.h" #include "BitmapGenNull.h" #include "utils.h" @@ -47,7 +46,7 @@ class CGdiplusBitmapWrapper : public libCZI::IBitmapData { auto gdiplusPxlFmt = this->bitmap->GetPixelFormat(); libCZI::BitmapLockInfo bitmapLockInfo; - Rect rect(0, 0, (INT)this->bitmap->GetWidth(), (INT)this->bitmap->GetHeight()); + Rect rect(0, 0, static_cast(this->bitmap->GetWidth()), static_cast(this->bitmap->GetHeight())); this->bitmap->LockBits(&rect, ImageLockModeRead, gdiplusPxlFmt, &this->bd); bitmapLockInfo.ptrData = this->bd.Scan0; bitmapLockInfo.ptrDataRoi = this->bd.Scan0; @@ -121,7 +120,7 @@ CBitmapGenGdiplus::CBitmapGenGdiplus(const IBitmapGenParameters* params) : fonth Graphics g(bitmap.get()); g.Clear(Color(255, 0, 0)); - Font font(this->fontname.c_str(), (REAL)this->fontheight, FontStyle::FontStyleBold, UnitPoint); + Font font(this->fontname.c_str(), static_cast(this->fontheight), FontStyle::FontStyleBold, UnitPoint); SolidBrush brush(Color(0, 0, 0)); auto text = IBitmapGen::CreateTextW(info); @@ -173,7 +172,7 @@ CBitmapGenGdiplus::CBitmapGenGdiplus(const IBitmapGenParameters* params) : fonth else if (pixeltype == PixelType::Gray8) { auto bw = make_shared(PixelType::Gray8, width, height); - Rect rect(0, 0, width, height); + Rect rect(0, 0, static_cast(width), static_cast(height)); BitmapData bd; bitmap->LockBits(&rect, ImageLockModeRead, PixelFormat24bppRGB, &bd); auto _ = finally([&] { bitmap->UnlockBits(&bd); }); // execute "UnlockBits" when leaving scope @@ -210,7 +209,7 @@ CBitmapGenGdiplus::CBitmapGenGdiplus(const IBitmapGenParameters* params) : fonth else if (pixeltype == PixelType::Bgr48) { auto bw = make_shared(PixelType::Bgr48, width, height); - Rect rect(0, 0, width, height); + Rect rect(0, 0, static_cast(width), static_cast(height)); BitmapData bd; bitmap->LockBits(&rect, ImageLockModeRead, PixelFormat24bppRGB, &bd); auto _ = finally([&] { bitmap->UnlockBits(&bd); }); diff --git a/Src/CZICmd/BitmapGenNull.cpp b/Src/CZICmd/BitmapGenNull.cpp index 0dd0ec60..85f315eb 100644 --- a/Src/CZICmd/BitmapGenNull.cpp +++ b/Src/CZICmd/BitmapGenNull.cpp @@ -2,7 +2,6 @@ // // SPDX-License-Identifier: LGPL-3.0-or-later -#include "stdafx.h" #include "BitmapGenNull.h" #include "utils.h" #include "inc_libCZI.h" @@ -37,14 +36,14 @@ void CNullBitmapWrapper::Clear(const ColorSpecification& color) case libCZI::PixelType::Gray8: for (std::uint32_t y = 0; y < this->height; ++y) { - memset(((std::uint8_t*)this->ptrData) + static_cast(y) * this->stride, color.Gray8.value, this->width); + memset(static_cast(this->ptrData) + static_cast(y) * this->stride, color.Gray8.value, this->width); } break; case libCZI::PixelType::Bgr24: for (std::uint32_t y = 0; y < this->height; ++y) { - std::uint8_t* ptr = ((std::uint8_t*)this->ptrData) + static_cast(y) * this->stride; + std::uint8_t* ptr = static_cast(this->ptrData) + static_cast(y) * this->stride; for (std::uint32_t x = 0; x < this->height; ++x) { *ptr++ = color.Bgr24.b; @@ -57,7 +56,7 @@ void CNullBitmapWrapper::Clear(const ColorSpecification& color) case libCZI::PixelType::Gray16: for (std::uint32_t y = 0; y < this->height; ++y) { - std::uint16_t* ptr = (std::uint16_t*)(((std::uint8_t*)this->ptrData) + static_cast(y) * this->stride); + std::uint16_t* ptr = reinterpret_cast(static_cast(this->ptrData) + static_cast(y) * this->stride); for (std::uint32_t x = 0; x < this->height; ++x) { *ptr++ = color.Gray16.value; @@ -68,7 +67,7 @@ void CNullBitmapWrapper::Clear(const ColorSpecification& color) case libCZI::PixelType::Bgr48: for (std::uint32_t y = 0; y < this->height; ++y) { - std::uint16_t* ptr = ((std::uint16_t*)this->ptrData) + static_cast(y) * this->stride; + std::uint16_t* ptr = static_cast(this->ptrData) + static_cast(y) * this->stride; for (std::uint32_t x = 0; x < this->height; ++x) { *ptr++ = color.Bgr48.b; diff --git a/Src/CZICmd/BitmapGenNull.h b/Src/CZICmd/BitmapGenNull.h index fbf7c806..e31c6371 100644 --- a/Src/CZICmd/BitmapGenNull.h +++ b/Src/CZICmd/BitmapGenNull.h @@ -59,16 +59,22 @@ class CNullBitmapWrapper : public libCZI::IBitmapData // TODO: posX/posY must be positive for this code to work correctly for (int y = posY; y < posY + height; ++y) { - if (y >= (int)this->height) break; + if (y >= static_cast(this->height)) + { + break; + } - const std::uint8_t* ptr = ((const std::uint8_t*)ptrData) + (y - posY) * stride; - std::uint8_t* ptrDst = ((std::uint8_t*)this->ptrData) + y * this->stride + tBytesPerPel * posX; + const std::uint8_t* ptr = static_cast(ptrData) + static_cast(y - posY) * stride; + std::uint8_t* ptrDst = static_cast(this->ptrData) + static_cast(y) * this->stride + tBytesPerPel * static_cast(posX); int v = 0x80; for (int x = posX; x < posX + width; ++x) { - if (x >= (int)this->width) break; + if (x >= static_cast(this->width)) + { + break; + } - bool pixel = (*ptr & v); + const bool pixel = (*ptr & v); if (pixel) { setPixel.setPixel(ptrDst); diff --git a/Src/CZICmd/CMakeLists.txt b/Src/CZICmd/CMakeLists.txt index cd86deb6..5d0057a1 100644 --- a/Src/CZICmd/CMakeLists.txt +++ b/Src/CZICmd/CMakeLists.txt @@ -2,7 +2,7 @@ # # SPDX-License-Identifier: LGPL-3.0-or-later -IF(UNIX) +IF(NOT LIBCZI_HAVE_WIN32_API) find_package(ZLIB QUIET) if (NOT ZLIB_FOUND) message(FATAL_ERROR [=[ @@ -24,7 +24,7 @@ IF(UNIX) message("** FreeType was not found, CZICmd with the option \"CreateCZI\" will create only empty images.") message(" (consider installing FreeType with e.g. 'sudo apt-get install libfreetype6-dev')") ENDIF() -ENDIF(UNIX) +ENDIF() include(FetchContent) @@ -39,36 +39,39 @@ if (LIBCZI_BUILD_PREFER_EXTERNALPACKAGE_RAPIDJSON) ]=]) endif() else() - # since "RapidJSON" is a header-only library, we just have to download it and point to the include directory - FetchContent_Declare( + # Since "RapidJSON" is a header-only library, we just have to download it and point to the include directory. + # Note: when using v1.1.0 of RapidJSON (the latest release) there we problems (with GCC14.2 with msys2), so + # we use a later version from the master branch. + FetchContent_Declare( RapidJSON GIT_REPOSITORY https://github.com/Tencent/rapidjson.git - GIT_TAG "v1.1.0" + GIT_TAG 7c73dd7de7c4f14379b781418c6e947ad464c818 # master as of 2024-08-16 GIT_SHALLOW TRUE PREFIX "${CMAKE_BINARY_DIR}/vendor/rapidjson" ) - if (NOT rapidjson_POPULATED) - FetchContent_Populate(RapidJSON) - set(RAPIDJSON_INCLUDE_DIRS ${rapidjson_SOURCE_DIR}/include) - endif() + set(RAPIDJSON_BUILD_DOC OFF CACHE BOOL "" FORCE) + set(RAPIDJSON_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) + set(RAPIDJSON_BUILD_TESTS OFF CACHE BOOL "" FORCE) + FetchContent_MakeAvailable(RapidJSON) + + set(RAPIDJSON_INCLUDE_DIRS ${rapidjson_SOURCE_DIR}/include) endif() # make "CLI11" available FetchContent_Declare( cli11 GIT_REPOSITORY https://github.com/CLIUtils/CLI11 - GIT_TAG v2.3.2 + GIT_TAG v2.4.2 ) -if (NOT cli11_POPULATED) - FetchContent_MakeAvailable(cli11) -endif() +set(CLI11_BUILD_TESTS OFF CACHE BOOL "" FORCE) +set(CLI11_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(cli11) set (CZICMDSRCFILES BitmapGen.cpp DisplaySettingsHelper.h - targetver.h BitmapGenFreeType.cpp cmdlineoptions.cpp execute.cpp @@ -84,17 +87,14 @@ set (CZICMDSRCFILES consoleio.cpp executeCreateCzi.h inc_CZIcmd_Config.h - stdafx.cpp BitmapGenGdiplus.h consoleio.h execute.h inc_libCZI.h - stdafx.h BitmapGenNull.cpp inc_rapidjson.h BitmapGenNull.h CZIcmd.cpp - platform_defines.h executePlaneScan.h executePlaneScan.cpp executeBase.h @@ -108,8 +108,8 @@ target_compile_definitions(CZIcmd PRIVATE _LIBCZISTATICLIB) target_link_libraries(CZIcmd PRIVATE ${ZLIB_LIBRARIES} ${PNG_LIBRARIES} CLI11::CLI11 libCZIStatic) target_include_directories(CZIcmd PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${RAPIDJSON_INCLUDE_DIRS}) -IF(WIN32) - target_link_libraries(CZIcmd PRIVATE gdiplus Windowscodecs) +IF(LIBCZI_HAVE_WIN32_API) + target_link_libraries(CZIcmd PRIVATE gdiplus Windowscodecs ole32) ENDIF() IF (FREETYPE_FOUND) @@ -118,16 +118,17 @@ IF (FREETYPE_FOUND) target_link_libraries(CZIcmd PRIVATE ${FREETYPE_LIBRARIES}) ENDIF() -IF(UNIX) +IF(NOT LIBCZI_HAVE_WIN32_API) target_include_directories(CZIcmd PRIVATE ${ZLIB_INCLUDE_DIR} ${PNG_INCLUDE_DIR}) # seems to be problem with glibc I'd reckon -> https://stackoverflow.com/questions/51584960/stdcall-once-throws-stdsystem-error-unknown-error-1 target_link_libraries(CZIcmd PUBLIC pthread) -ENDIF(UNIX) +ENDIF() set(CZICMD_USE_FREETYPE 0) set(CZICMD_USE_WIC 0) set(CZICMD_USE_GDIPLUS 0) set(CZICMD_USE_LIBPNG 0) +set(CZICMD_WINDOWSAPIAVAILABLE 0) IF (FREETYPE_FOUND) set(CZICMD_USE_FREETYPE 1) @@ -139,7 +140,8 @@ IF(PNG_FOUND) set(CZICMD_LIBPNG_VERSION_STRING "${PNG_VERSION_STRING}") ENDIF() -IF(WIN32) +IF(LIBCZI_HAVE_WIN32_API) + set(CZICMD_WINDOWSAPIAVAILABLE 1) set(CZICMD_USE_WIC 1) set(CZICMD_USE_GDIPLUS 1) ENDIF() diff --git a/Src/CZICmd/CZIcmd.cpp b/Src/CZICmd/CZIcmd.cpp index 93845396..91c18483 100644 --- a/Src/CZICmd/CZIcmd.cpp +++ b/Src/CZICmd/CZIcmd.cpp @@ -2,18 +2,13 @@ // // SPDX-License-Identifier: LGPL-3.0-or-later -#include "stdafx.h" +#include "inc_CZIcmd_Config.h" #include "consoleio.h" #include "cmdlineoptions.h" #include "execute.h" #include "inc_libCZI.h" - -#if defined(LINUXENV) #include -#endif - -#if defined(WIN32ENV) -#define NOMINMAX +#if CZICMD_WINDOWSAPI_AVAILABLE #include #endif @@ -24,7 +19,7 @@ class CLibCZISite : public libCZI::ISite public: explicit CLibCZISite(const CCmdLineOptions& opts) : options(opts) { -#if defined(WIN32ENV) +#if CZICMD_WINDOWSAPI_AVAILABLE if (options.GetUseWICJxrDecoder()) { this->pSite = libCZI::GetDefaultSiteObject(libCZI::SiteObjectType::WithWICDecoder); @@ -61,11 +56,10 @@ class CLibCZISite : public libCZI::ISite int main(int argc, char** _argv) { -#if defined(WIN32ENV) +#if CZICMD_WINDOWSAPI_AVAILABLE CoInitialize(NULL); CommandlineArgsWindowsHelper args_helper; -#endif -#if defined(LINUXENV) +#else setlocale(LC_CTYPE, ""); #endif @@ -74,7 +68,7 @@ int main(int argc, char** _argv) try { CCmdLineOptions options(log); -#if defined(WIN32ENV) +#if CZICMD_WINDOWSAPI_AVAILABLE auto cmdLineParseResult = options.Parse(args_helper.GetArgc(), args_helper.GetArgv()); #else auto cmdLineParseResult = options.Parse(argc, _argv); @@ -110,7 +104,7 @@ int main(int argc, char** _argv) retVal = 1; } -#if defined(WIN32ENV) +#if CZICMD_WINDOWSAPI_AVAILABLE CoUninitialize(); #endif diff --git a/Src/CZICmd/CZIcmd_Config.h.in b/Src/CZICmd/CZIcmd_Config.h.in index 7d74489c..cf0145cc 100644 --- a/Src/CZICmd/CZIcmd_Config.h.in +++ b/Src/CZICmd/CZIcmd_Config.h.in @@ -4,6 +4,9 @@ #pragma once +// whether Win32-API can be used +#define CZICMD_WINDOWSAPI_AVAILABLE @CZICMD_WINDOWSAPIAVAILABLE@ + #define CZICMD_USE_WIC @CZICMD_USE_WIC@ #define CZICMD_USE_LIBPNG @CZICMD_USE_LIBPNG@ diff --git a/Src/CZICmd/SaveBitmap.cpp b/Src/CZICmd/SaveBitmap.cpp index a3911f0c..f63e3ddc 100644 --- a/Src/CZICmd/SaveBitmap.cpp +++ b/Src/CZICmd/SaveBitmap.cpp @@ -2,7 +2,6 @@ // // SPDX-License-Identifier: LGPL-3.0-or-later -#include "stdafx.h" #include "SaveBitmap.h" #include #include @@ -14,6 +13,8 @@ #if CZICMD_USE_WIC == 1 #include #include +#include +#include using namespace std; @@ -150,9 +151,9 @@ class CWicSaveBitmap :public ISaveBitmap { if (!checkFunc(hr)) { - char errorMsg[255]; - _snprintf_s(errorMsg, _TRUNCATE, "COM-ERROR hr=0x%08X (%s)", hr, function); - throw std::runtime_error(errorMsg); + ostringstream string_stream; + string_stream << "COM-ERROR hr=0x" << std::hex << std::uppercase << std::setw(8) << std::setfill('0') << hr << " (" << function << ")"; + throw std::runtime_error(string_stream.str()); } } }; @@ -212,11 +213,11 @@ class CLibPngSaveBitmap :public ISaveBitmap [](std::uint32_t width, void* ptrData)->void { char* p = (char*)ptrData; - for (std::uint32_t x = 0; x < width; ++x) - { - std::swap(*p, *(p + 2)); - p += 3; - } + for (std::uint32_t x = 0; x < width; ++x) + { + std::swap(*p, *(p + 2)); + p += 3; + } }); } @@ -226,11 +227,11 @@ class CLibPngSaveBitmap :public ISaveBitmap [](std::uint32_t width, void* ptrData)->void { char* p = (char*)ptrData; - for (std::uint32_t x = 0; x < width; ++x) - { - std::swap(*p, *(p + 2)); - p += 4; - } + for (std::uint32_t x = 0; x < width; ++x) + { + std::swap(*p, *(p + 2)); + p += 4; + } }); } @@ -240,11 +241,11 @@ class CLibPngSaveBitmap :public ISaveBitmap [](std::uint32_t width, void* ptrData)->void { unsigned short* p = (unsigned short*)ptrData; - for (std::uint32_t x = 0; x < width; ++x) - { - std::swap(*p, *(p + 2)); - p += 3; - } + for (std::uint32_t x = 0; x < width; ++x) + { + std::swap(*p, *(p + 2)); + p += 3; + } }); } @@ -277,7 +278,8 @@ class CLibPngSaveBitmap :public ISaveBitmap { libCZI::ScopedBitmapLockerP lckScoped{ bitmap }; - for (std::uint32_t h = 0; h < bitmap->GetHeight(); ++h) { + for (std::uint32_t h = 0; h < bitmap->GetHeight(); ++h) + { png_bytep ptr = (png_bytep)(((char*)lckScoped.ptrDataRoi) + h * lckScoped.stride); png_write_row(pngStructInfo.png_ptr, ptr); } @@ -306,7 +308,8 @@ class CLibPngSaveBitmap :public ISaveBitmap { libCZI::ScopedBitmapLockerP lckScoped{ bitmap }; std::unique_ptr lineToTweak(malloc(lckScoped.stride), &free); - for (std::uint32_t h = 0; h < bitmap->GetHeight(); ++h) { + for (std::uint32_t h = 0; h < bitmap->GetHeight(); ++h) + { void* ptr = (((char*)lckScoped.ptrDataRoi) + h * lckScoped.stride); memcpy(lineToTweak.get(), ptr, lckScoped.stride); tweakLine(bitmap->GetWidth(), lineToTweak.get()); diff --git a/Src/CZICmd/cmdlineoptions.cpp b/Src/CZICmd/cmdlineoptions.cpp index fa83cf0d..310e4b00 100644 --- a/Src/CZICmd/cmdlineoptions.cpp +++ b/Src/CZICmd/cmdlineoptions.cpp @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: LGPL-3.0-or-later -#include "stdafx.h" +#include "inc_CZIcmd_Config.h" #include "cmdlineoptions.h" #include "inc_libCZI.h" #include @@ -12,7 +12,7 @@ #include #include #include -#if defined(LINUXENV) +#if !_WIN32 #include #endif #include "inc_rapidjson.h" @@ -727,7 +727,7 @@ CCmdLineOptions::ParseResult CCmdLineOptions::Parse(int argc, char** argv) ->check(createtileinfo_validator); cli_app.add_option("--font", argument_truetypefontname, "Only used for 'CreateCZI': (on Linux) specify the filename of a TrueType-font (.ttf) to be used for generating text in the subblocks; (on Windows) name of the font.") -#if defined(LINUXENV) +#if CZICMD_USE_FREETYPE ->check(CLI::ExistingFile) #endif ->option_text("NAME/FILENAME"); @@ -1134,7 +1134,7 @@ bool CCmdLineOptions::IsLogLevelEnabled(int level) const void CCmdLineOptions::SetOutputFilename(const std::wstring& s) { -#if defined(WIN32ENV) +#if _WIN32 wchar_t drive[_MAX_DRIVE]; wchar_t dir[_MAX_DIR]; wchar_t fname[_MAX_FNAME]; @@ -1147,8 +1147,7 @@ void CCmdLineOptions::SetOutputFilename(const std::wstring& s) this->outputPath = path; this->outputFilename = fname; this->outputFilename += ext; -#endif -#if defined(LINUXENV) +#else std::string sutf8 = convertToUtf8(s); char* dirName = strdup(sutf8.c_str()); char* fname = strdup(sutf8.c_str()); @@ -1453,7 +1452,7 @@ bool CCmdLineOptions::TryParseDisplaySettings(const std::string& s, std::map 0) + if (!tktr.empty()) { bool token_found = false; for (size_t i = 0; i < sizeof(info_levels) / sizeof(info_levels[0]); ++i) diff --git a/Src/CZICmd/consoleio.cpp b/Src/CZICmd/consoleio.cpp index 6614f958..4bab1908 100644 --- a/Src/CZICmd/consoleio.cpp +++ b/Src/CZICmd/consoleio.cpp @@ -2,8 +2,6 @@ // // SPDX-License-Identifier: LGPL-3.0-or-later -#include "stdafx.h" -#include #include "consoleio.h" #include diff --git a/Src/CZICmd/consoleio.h b/Src/CZICmd/consoleio.h index 18b78df6..67404650 100644 --- a/Src/CZICmd/consoleio.h +++ b/Src/CZICmd/consoleio.h @@ -4,6 +4,9 @@ #pragma once +#include +#include + class ILog { public: diff --git a/Src/CZICmd/execute.cpp b/Src/CZICmd/execute.cpp index 4aadd4c7..27592515 100644 --- a/Src/CZICmd/execute.cpp +++ b/Src/CZICmd/execute.cpp @@ -2,7 +2,6 @@ // // SPDX-License-Identifier: LGPL-3.0-or-later -#include "stdafx.h" #include "execute.h" #include "executeBase.h" #include "executeCreateCzi.h" diff --git a/Src/CZICmd/executeCreateCzi.cpp b/Src/CZICmd/executeCreateCzi.cpp index 95357244..921a334a 100644 --- a/Src/CZICmd/executeCreateCzi.cpp +++ b/Src/CZICmd/executeCreateCzi.cpp @@ -2,7 +2,6 @@ // // SPDX-License-Identifier: LGPL-3.0-or-later -#include "stdafx.h" #include "executeCreateCzi.h" #include "IBitmapGen.h" #include "inc_libCZI.h" diff --git a/Src/CZICmd/executePlaneScan.cpp b/Src/CZICmd/executePlaneScan.cpp index aa227b12..e1d5cfc6 100644 --- a/Src/CZICmd/executePlaneScan.cpp +++ b/Src/CZICmd/executePlaneScan.cpp @@ -2,7 +2,6 @@ // // SPDX-License-Identifier: LGPL-3.0-or-later -#include "stdafx.h" #include "executePlaneScan.h" #include "executeBase.h" #include "SaveBitmap.h" diff --git a/Src/CZICmd/inc_rapidjson.h b/Src/CZICmd/inc_rapidjson.h index 6b43a1c6..e9afdad5 100644 --- a/Src/CZICmd/inc_rapidjson.h +++ b/Src/CZICmd/inc_rapidjson.h @@ -4,7 +4,7 @@ #pragma once -#define RAPIDJSON_HAS_STDSTRING (1) +#define RAPIDJSON_HAS_STDSTRING 1 #include #include diff --git a/Src/CZICmd/platform_defines.h b/Src/CZICmd/platform_defines.h deleted file mode 100644 index e1d350b2..00000000 --- a/Src/CZICmd/platform_defines.h +++ /dev/null @@ -1,13 +0,0 @@ -// SPDX-FileCopyrightText: 2017-2022 Carl Zeiss Microscopy GmbH -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#pragma once - -#if defined(_WIN32) - // this means that the Win32-API is available, and the Windows-SDK is available - #define WIN32ENV (1) -#else - // otherwise, we assume that we are on Linux - #define LINUXENV (1) -#endif diff --git a/Src/CZICmd/stdafx.cpp b/Src/CZICmd/stdafx.cpp deleted file mode 100644 index bea8d18d..00000000 --- a/Src/CZICmd/stdafx.cpp +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-FileCopyrightText: 2017-2022 Carl Zeiss Microscopy GmbH -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -// stdafx.cpp : source file that includes just the standard includes -// stdafx.obj will contain the pre-compiled type information - -#include "stdafx.h" - -// TODO: reference any additional headers you need in STDAFX.H -// and not in this file diff --git a/Src/CZICmd/stdafx.h b/Src/CZICmd/stdafx.h deleted file mode 100644 index 1efaa62e..00000000 --- a/Src/CZICmd/stdafx.h +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-FileCopyrightText: 2017-2022 Carl Zeiss Microscopy GmbH -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -// stdafx.h : include file for standard system include files, -// or project specific include files that are used frequently, but -// are changed infrequently -// - -#pragma once - -#define __STDC_WANT_LIB_EXT1__ 1 - -#include "platform_defines.h" - -#if defined(LINUXENV) -#define _LARGEFILE64_SOURCE -#endif - -#include "targetver.h" - -#include - -#include -#include -#include - -// TODO: reference additional headers your program requires here diff --git a/Src/CZICmd/targetver.h b/Src/CZICmd/targetver.h deleted file mode 100644 index a2ffe0ae..00000000 --- a/Src/CZICmd/targetver.h +++ /dev/null @@ -1,14 +0,0 @@ -// SPDX-FileCopyrightText: 2017-2022 Carl Zeiss Microscopy GmbH -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#pragma once - -// Including SDKDDKVer.h defines the highest available Windows platform. - -// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and -// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. - -#if defined(WIN32ENV) -#include -#endif diff --git a/Src/CZICmd/utils.cpp b/Src/CZICmd/utils.cpp index 08e1e71c..dae2b7ed 100644 --- a/Src/CZICmd/utils.cpp +++ b/Src/CZICmd/utils.cpp @@ -2,13 +2,13 @@ // // SPDX-License-Identifier: LGPL-3.0-or-later -#include "stdafx.h" +#include "inc_CZIcmd_Config.h" #include "utils.h" #include #include #include -#if defined(WIN32ENV) +#if CZICMD_WINDOWSAPI_AVAILABLE #define HAS_CODECVT #include #endif @@ -434,7 +434,7 @@ bool TryParseGuid(const std::wstring& str, libCZI::GUID* outGuid) return false; } -#if defined(WIN32ENV) +#if CZICMD_WINDOWSAPI_AVAILABLE CommandlineArgsWindowsHelper::CommandlineArgsWindowsHelper() { int number_arguments; diff --git a/Src/CZICmd/utils.h b/Src/CZICmd/utils.h index 55caad7e..37d21e28 100644 --- a/Src/CZICmd/utils.h +++ b/Src/CZICmd/utils.h @@ -4,6 +4,7 @@ #pragma once +#include "inc_CZIcmd_Config.h" #include #include #include "inc_libCZI.h" @@ -78,7 +79,7 @@ inline final_act finally(F&& f) noexcept return final_act(std::forward(f)); } -#if defined(WIN32ENV) +#if CZICMD_WINDOWSAPI_AVAILABLE /// A utility which is providing the command-line arguments (on Windows) as UTF8-encoded strings. class CommandlineArgsWindowsHelper { diff --git a/Src/libCZI/CMakeLists.txt b/Src/libCZI/CMakeLists.txt index 46c33ab0..9bfd2bfa 100644 --- a/Src/libCZI/CMakeLists.txt +++ b/Src/libCZI/CMakeLists.txt @@ -246,17 +246,21 @@ else() GIT_TAG "v1.5.6" ) - if(NOT zstd_POPULATED) - message(STATUS "Fetching zstd...") - set(ZSTD_BUILD_PROGRAMS OFF CACHE BOOL "" FORCE) - set(ZSTD_BUILD_SHARED OFF CACHE BOOL "" FORCE) - set(ZSTD_BUILD_TESTS OFF CACHE BOOL "" FORCE) - set(ZSTD_BUILD_CONTRIB OFF CACHE BOOL "" FORCE) + message(STATUS "Fetching zstd...") + set(ZSTD_BUILD_PROGRAMS OFF CACHE BOOL "" FORCE) + set(ZSTD_BUILD_SHARED OFF CACHE BOOL "" FORCE) + set(ZSTD_BUILD_TESTS OFF CACHE BOOL "" FORCE) + set(ZSTD_BUILD_CONTRIB OFF CACHE BOOL "" FORCE) - FetchContent_Populate(zstd) + FetchContent_MakeAvailable(zstd) - add_subdirectory(${zstd_SOURCE_DIR}/build/cmake ${zstd_BINARY_DIR}) - endif() + add_subdirectory(${zstd_SOURCE_DIR}/build/cmake ${zstd_BINARY_DIR}) +endif() + +if (LIBCZI_HAVE_WIN32_API) + set(libCZI_WINDOWSAPIAVAILABLE 1) +else() + set(libCZI_WINDOWSAPIAVAILABLE 0) endif() configure_file ( @@ -304,6 +308,9 @@ if (LIBCZI_BUILD_DYNLIB) IF(UNIX) target_compile_options(libCZI PRIVATE -D_FILE_OFFSET_BITS=64) ENDIF(UNIX) + if(LIBCZI_HAVE_WIN32_API) + target_link_libraries(libCZI PRIVATE ole32 Windowscodecs) + endif() endif(LIBCZI_BUILD_DYNLIB) # @@ -342,7 +349,9 @@ IF(UNIX) target_compile_options(libCZIStatic PRIVATE -D_FILE_OFFSET_BITS=64) set_property(TARGET libCZIStatic PROPERTY POSITION_INDEPENDENT_CODE ON) ENDIF(UNIX) - +if(LIBCZI_HAVE_WIN32_API) + target_link_libraries(libCZIStatic PUBLIC ole32 Windowscodecs) +endif() # # Notes: - the variables CMAKE_INSTALL_<...> have been defined in the module "GNUInstallDirs" diff --git a/Src/libCZI/CziMetadataBuilder.cpp b/Src/libCZI/CziMetadataBuilder.cpp index 9045af01..e3e249f0 100644 --- a/Src/libCZI/CziMetadataBuilder.cpp +++ b/Src/libCZI/CziMetadataBuilder.cpp @@ -1104,7 +1104,7 @@ static bool TryRetrieveIdAndNameAttributeFromChannels(IXmlNodeRw* root, int chan /*static*/void libCZI::MetadataUtils::SetOrAddCustomKeyValuePair(libCZI::ICziMetadataBuilder* builder, const string& key, const libCZI::CustomValueVariant& value) { auto root = builder->GetRootNode(); - const regex isValidNodename(R"(^([_a-z][\w]?|[a-w_yz][\w]{2,}|[_a-z][a-l_n-z\d][\w]+|[_a-z][\w][a-k_m-z\d][\w]*)$)", regex_constants::icase); + const regex isValidNodename(R"(^([_a-zA-Z][\w]?|[a-wA-W_yzYZ][\w]{2,}|[_a-zA-Z][a-lA-L_n-zN-Z\d][\w]+|[_a-zA-Z][\w][a-kA-K_m-zM-Z\d][\w]*)$)"); if (!regex_match(key, isValidNodename)) { diff --git a/Src/libCZI/CziUtils.cpp b/Src/libCZI/CziUtils.cpp index 7f3638db..e4f0ddc8 100644 --- a/Src/libCZI/CziUtils.cpp +++ b/Src/libCZI/CziUtils.cpp @@ -43,12 +43,10 @@ using namespace libCZI; { switch (pyramid_type) { - case SubBlockPyramidType::None: return 0; - case SubBlockPyramidType::SingleSubBlock: return 1; - case SubBlockPyramidType::MultiSubBlock: return 2; + case SubBlockPyramidType::SingleSubBlock: return 1; + case SubBlockPyramidType::MultiSubBlock: return 2; + default: return 0; } - - return 0; } /*static*/int CziUtils::IntFromPixelType(libCZI::PixelType p) diff --git a/Src/libCZI/Doc/version-history.markdown b/Src/libCZI/Doc/version-history.markdown index 5c4c9e8f..3b5f38ce 100644 --- a/Src/libCZI/Doc/version-history.markdown +++ b/Src/libCZI/Doc/version-history.markdown @@ -26,4 +26,5 @@ version history {#version_history} 0.61.0 | [109](https://github.com/ZEISS/libczi/pull/109) | fix behaviour of `IXmlNodeRead::GetChildNodeReadonly` (for non-existing nodes), new method `ICziWriter::GetStatistics` added 0.61.1 | [110](https://github.com/ZEISS/libczi/pull/110) | some code cleanup 0.61.2 | [111](https://github.com/ZEISS/libczi/pull/111) | update libcurl to 8.9.1 (for build with `LIBCZI_BUILD_PREFER_EXTERNALPACKAGE_LIBCURL=OFF`), enable SChannel (on Windows) by default - 0.62.0 | [112](https://github.com/ZEISS/libczi/pull/112) | add Azure-SDK based reader for reading from Azure Blob Storage, raise requirement to C++14 for building libCZI (previously C++11 was sufficient) because Azure-SDK requires C++14 \ No newline at end of file + 0.62.0 | [112](https://github.com/ZEISS/libczi/pull/112) | add Azure-SDK based reader for reading from Azure Blob Storage, raise requirement to C++14 for building libCZI (previously C++11 was sufficient) because Azure-SDK requires C++14 + 0.62.1 | [114](https://github.com/ZEISS/libczi/pull/114) | improve build system fixing issues with msys2 and mingw-w64, cosmetic changes \ No newline at end of file diff --git a/Src/libCZI/StreamImpl.cpp b/Src/libCZI/StreamImpl.cpp index f99e4d92..df2ae07e 100644 --- a/Src/libCZI/StreamImpl.cpp +++ b/Src/libCZI/StreamImpl.cpp @@ -72,7 +72,7 @@ COutputStreamImplPwrite::~COutputStreamImplPwrite() //---------------------------------------------------------------------------- -#if defined(_WIN32) +#if LIBCZI_WINDOWSAPI_AVAILABLE CSimpleOutputStreamImplWindows::CSimpleOutputStreamImplWindows(const wchar_t* filename, bool overwriteExisting) : handle(INVALID_HANDLE_VALUE) @@ -316,7 +316,7 @@ CInputOutputStreamImplPreadPwrite::~CInputOutputStreamImplPreadPwrite() //----------------------------------------------------------------------------- -#if defined(_WIN32) +#if LIBCZI_WINDOWSAPI_AVAILABLE CSimpleInputOutputStreamImplWindows::CSimpleInputOutputStreamImplWindows(const wchar_t* filename) : handle(INVALID_HANDLE_VALUE) { diff --git a/Src/libCZI/StreamImpl.h b/Src/libCZI/StreamImpl.h index 6bce2b82..1ce6edff 100644 --- a/Src/libCZI/StreamImpl.h +++ b/Src/libCZI/StreamImpl.h @@ -4,11 +4,11 @@ #pragma once -#include #include "libCZI.h" #include "inc_libCZI_Config.h" -#if defined(_WIN32) - #include +#include +#if LIBCZI_WINDOWSAPI_AVAILABLE +#include #endif /// A simplistic output-stream implementation (based on C-runtime fopen). Note that this implementation is NOT thread-safe. @@ -40,7 +40,7 @@ class COutputStreamImplPwrite : public libCZI::IOutputStream }; #endif -#if defined(_WIN32) +#if LIBCZI_WINDOWSAPI_AVAILABLE class CSimpleOutputStreamImplWindows : public libCZI::IOutputStream { @@ -84,7 +84,7 @@ class CInputOutputStreamImplPreadPwrite : public libCZI::IInputOutputStream }; #endif -#if defined(_WIN32) +#if LIBCZI_WINDOWSAPI_AVAILABLE class CSimpleInputOutputStreamImplWindows : public libCZI::IInputOutputStream { private: diff --git a/Src/libCZI/StreamsLib/streamsFactory.cpp b/Src/libCZI/StreamsLib/streamsFactory.cpp index 9a471794..b1cea7f5 100644 --- a/Src/libCZI/StreamsLib/streamsFactory.cpp +++ b/Src/libCZI/StreamsLib/streamsFactory.cpp @@ -54,7 +54,7 @@ static const struct nullptr }, #endif // LIBCZI_AZURESDK_BASED_STREAM_AVAILABLE -#if _WIN32 +#if LIBCZI_WINDOWSAPI_AVAILABLE { { "windows_file_inputstream", "stream implementation based on Windows-API", nullptr, nullptr }, [](const StreamsFactory::CreateStreamInfo& stream_info, const std::string& file_name) -> std::shared_ptr @@ -66,7 +66,7 @@ static const struct return std::make_shared(file_name.c_str()); } }, -#endif // _WIN32 +#endif // LIBCZI_WINDOWSAPI_AVAILABLE #if LIBCZI_USE_PREADPWRITEBASED_STREAMIMPL { { "pread_file_inputstream", "stream implementation based on pread-API", nullptr, nullptr }, @@ -200,8 +200,8 @@ std::shared_ptr libCZI::StreamsFactory::CreateStream(const Crea template std::shared_ptr CreateDefaultStreamForFileGeneric(const t_charactertype* filename) { -#if _WIN32 - // if we are on Windows, then "WindowsFileInputStream" should give best performance/features +#if LIBCZI_WINDOWSAPI_AVAILABLE + // if we are on Windows, then "WindowsFileInputStream" should give the best performance/features return std::make_shared(filename); #elif LIBCZI_USE_PREADPWRITEBASED_STREAMIMPL // otherwise (and if pread is available), then "PreadFileInputStream" is the best choice diff --git a/Src/libCZI/StreamsLib/windowsfileinputstream.cpp b/Src/libCZI/StreamsLib/windowsfileinputstream.cpp index 167c7ba3..059af9e8 100644 --- a/Src/libCZI/StreamsLib/windowsfileinputstream.cpp +++ b/Src/libCZI/StreamsLib/windowsfileinputstream.cpp @@ -4,7 +4,7 @@ #include "windowsfileinputstream.h" -#if defined(_WIN32) +#if LIBCZI_WINDOWSAPI_AVAILABLE #include #include #include "../utilities.h" diff --git a/Src/libCZI/StreamsLib/windowsfileinputstream.h b/Src/libCZI/StreamsLib/windowsfileinputstream.h index c01022b3..dc0da30f 100644 --- a/Src/libCZI/StreamsLib/windowsfileinputstream.h +++ b/Src/libCZI/StreamsLib/windowsfileinputstream.h @@ -5,7 +5,7 @@ #pragma once #include -#if defined(_WIN32) +#if LIBCZI_WINDOWSAPI_AVAILABLE #include #include "../libCZI.h" #include diff --git a/Src/libCZI/decoder_wic.cpp b/Src/libCZI/decoder_wic.cpp index 720343de..4a9418d6 100644 --- a/Src/libCZI/decoder_wic.cpp +++ b/Src/libCZI/decoder_wic.cpp @@ -2,15 +2,16 @@ // // SPDX-License-Identifier: LGPL-3.0-or-later -#if defined(_WIN32) #include "decoder_wic.h" + +#if LIBCZI_WINDOWSAPI_AVAILABLE #include "BitmapOperations.h" #include +#include +#include #include "Site.h" -#pragma comment(lib, "Windowscodecs.lib") - using namespace std; using namespace libCZI; @@ -30,9 +31,9 @@ static void ThrowIfFailed(const char* function, HRESULT hr) { if (FAILED(hr)) { - char errorMsg[255]; - _snprintf_s(errorMsg, _TRUNCATE, "COM-ERROR hr=0x%08X (%s)", hr, function); - throw std::runtime_error(errorMsg); + ostringstream string_stream; + string_stream << "COM-ERROR hr=0x" << std::hex << std::uppercase << std::setw(8) << std::setfill('0') << hr << " (" << function << ")"; + throw std::runtime_error(string_stream.str()); } } @@ -293,7 +294,7 @@ static bool DeterminePixelType(const WICPixelFormatGUID& wicPxlFmt, GUID* destPi if (wicPxlFmt == wicDestPxlFmt) { // in this case we do not need to create a converter - hr = up_wicBitmapFrameDecode->CopyPixels(NULL, bmLckInfo.stride, bmLckInfo.stride * sizeBitmap.h, (BYTE*)bmLckInfo.ptrDataRoi); + hr = up_wicBitmapFrameDecode->CopyPixels(NULL, bmLckInfo.stride, bmLckInfo.stride * sizeBitmap.h, static_cast(bmLckInfo.ptrDataRoi)); ThrowIfFailed("wicBitmapFrameDecode->CopyPixels", hr); } else @@ -317,7 +318,7 @@ static bool DeterminePixelType(const WICPixelFormatGUID& wicPxlFmt, GUID* destPi // WIC-codec does not directly support "BGR48", so we need to convert (#36) if (px_type == PixelType::Bgr48) { - CBitmapOperations::RGB48ToBGR48(sizeBitmap.w, sizeBitmap.h, (uint16_t*)bmLckInfo.ptrDataRoi, bmLckInfo.stride); + CBitmapOperations::RGB48ToBGR48(sizeBitmap.w, sizeBitmap.h, static_cast(bmLckInfo.ptrDataRoi), bmLckInfo.stride); } if (GetSite()->IsEnabled(LOGLEVEL_CHATTYINFORMATION)) diff --git a/Src/libCZI/decoder_wic.h b/Src/libCZI/decoder_wic.h index 11b0c62f..b18cd811 100644 --- a/Src/libCZI/decoder_wic.h +++ b/Src/libCZI/decoder_wic.h @@ -4,7 +4,9 @@ #pragma once -#if defined(_WIN32) +#include + +#if LIBCZI_WINDOWSAPI_AVAILABLE #include #include "libCZI_Pixels.h" diff --git a/Src/libCZI/libCZI.h b/Src/libCZI/libCZI.h index aa474830..2249d777 100644 --- a/Src/libCZI/libCZI.h +++ b/Src/libCZI/libCZI.h @@ -35,10 +35,8 @@ namespace libCZI enum class SiteObjectType { Default, ///< An enum constant representing the default option (which is JXRLib) - WithJxrDecoder ///< An enum constant representing a Site-object using the internal JXRLib. -#if defined(_WIN32) - , WithWICDecoder///< An enum constant representing a Site-object using the Windows WIC-codec. -#endif + WithJxrDecoder, ///< An enum constant representing a Site-object using the internal JXRLib. + WithWICDecoder, ///< An enum constant representing a Site-object using the Windows WIC-codec. Note that this option is only available on Windows. }; class ISite; diff --git a/Src/libCZI/libCZI_Config.h.in b/Src/libCZI/libCZI_Config.h.in index dcc52aa2..e490e60a 100644 --- a/Src/libCZI/libCZI_Config.h.in +++ b/Src/libCZI/libCZI_Config.h.in @@ -10,6 +10,9 @@ #define LIBCZI_VERSION_PATCH "@libCZI_VERSION_PATCH@" #define LIBCZI_VERSION_TWEAK "@libCZI_VERSION_TWEAK@" +// whether the libCZI library is built with support for the Windows-API, i.e. whether it is being built for a Windows-environment +#define LIBCZI_WINDOWSAPI_AVAILABLE @libCZI_WINDOWSAPIAVAILABLE@ + // if the host system is a big-endian system, this is "1", otherwise 0 #define LIBCZI_ISBIGENDIANHOST @libCZI_ISBIGENDIANHOST@ diff --git a/Src/libCZI/libCZI_Lib.cpp b/Src/libCZI/libCZI_Lib.cpp index 2105f3e4..aa03d31b 100644 --- a/Src/libCZI/libCZI_Lib.cpp +++ b/Src/libCZI/libCZI_Lib.cpp @@ -105,7 +105,7 @@ std::shared_ptr libCZI::CreateStreamFromMemory(libCZI::IAttachm std::shared_ptr libCZI::CreateOutputStreamForFile(const wchar_t* szFilename, bool overwriteExisting) { -#ifdef _WIN32 +#if LIBCZI_WINDOWSAPI_AVAILABLE return make_shared(szFilename, overwriteExisting); #else #if LIBCZI_USE_PREADPWRITEBASED_STREAMIMPL @@ -118,7 +118,7 @@ std::shared_ptr libCZI::CreateOutputStreamForFile(const wchar_t* std::shared_ptr libCZI::CreateInputOutputStreamForFile(const wchar_t* szFilename) { -#ifdef _WIN32 +#if LIBCZI_WINDOWSAPI_AVAILABLE return make_shared(szFilename); #else #if LIBCZI_USE_PREADPWRITEBASED_STREAMIMPL diff --git a/Src/libCZI/libCZI_Site.cpp b/Src/libCZI/libCZI_Site.cpp index 5aa84264..de77a4c4 100644 --- a/Src/libCZI/libCZI_Site.cpp +++ b/Src/libCZI/libCZI_Site.cpp @@ -3,6 +3,7 @@ // SPDX-License-Identifier: LGPL-3.0-or-later #include "libCZI.h" +#include "inc_libCZI_Config.h" #include "decoder.h" #include "decoder_zstd.h" #include @@ -37,7 +38,7 @@ class CSiteImpBase : public ISite } }; -#if defined(_WIN32) +#if LIBCZI_WINDOWSAPI_AVAILABLE class CSiteImpWic : public CSiteImpBase { private: @@ -139,7 +140,7 @@ class CSiteImpJxrLib : public CSiteImpBase } }; -#if defined(_WIN32) +#if LIBCZI_WINDOWSAPI_AVAILABLE static CSiteImpWic theWicSite; #endif static CSiteImpJxrLib theJxrLibSite; @@ -168,7 +169,7 @@ libCZI::ISite* libCZI::GetDefaultSiteObject(SiteObjectType type) { switch (type) { -#if defined(_WIN32) +#if LIBCZI_WINDOWSAPI_AVAILABLE case SiteObjectType::WithWICDecoder: return &theWicSite; #endif diff --git a/Src/libCZI/utilities.cpp b/Src/libCZI/utilities.cpp index fbb7c3e2..28d9538a 100644 --- a/Src/libCZI/utilities.cpp +++ b/Src/libCZI/utilities.cpp @@ -3,18 +3,17 @@ // SPDX-License-Identifier: LGPL-3.0-or-later #include "utilities.h" +#include "inc_libCZI_Config.h" #include #include #include #include #include -#if !defined(_WIN32) -#include -#endif -#if defined(_WIN32) +#if LIBCZI_WINDOWSAPI_AVAILABLE #include +#else +#include #endif -#include "inc_libCZI_Config.h" #if LIBCZI_HAVE_ENDIAN_H #include "endian.h" #endif @@ -124,7 +123,7 @@ tString trimImpl(const tString& str, const tString& whitespace) /*static*/libCZI::GUID Utilities::GenerateNewGuid() { -#if defined(_WIN32) +#if LIBCZI_WINDOWSAPI_AVAILABLE ::GUID guid; CoCreateGuid(&guid); libCZI::GUID guid_value diff --git a/Src/libCZI_UnitTests/test_metadatabuilder.cpp b/Src/libCZI_UnitTests/test_metadatabuilder.cpp index 8c8e0436..57fc3bae 100644 --- a/Src/libCZI_UnitTests/test_metadatabuilder.cpp +++ b/Src/libCZI_UnitTests/test_metadatabuilder.cpp @@ -523,8 +523,8 @@ TEST(MetadataBuilder, MetadataUtils11) for (auto valid_it = ValidCA.begin(); valid_it != ValidCA.end(); ++valid_it) { - auto key = valid_it->first; - auto value = valid_it->second; + const auto& key = valid_it->first; + const auto& value = valid_it->second; MetadataUtils::SetOrAddCustomKeyValuePair(mdBldr.get(), key, value); }