| 1 |
diff --git a/CMakeLists.txt b/CMakeLists.txt |
| 2 |
index ec6d70e..b8d3cec 100644 |
| 3 |
--- a/CMakeLists.txt |
| 4 |
+++ b/CMakeLists.txt |
| 5 |
@@ -1,17 +1,18 @@ |
| 6 |
# |
| 7 |
-# Copyright (c) 2020, Gilles Caulier, <caulier dot gilles at gmail dot com> |
| 8 |
+# Copyright (c) 2020-2023, Gilles Caulier, <caulier dot gilles at gmail dot com> |
| 9 |
# |
| 10 |
# Redistribution and use is allowed according to the terms of the BSD license. |
| 11 |
# For details see the accompanying COPYING-CMAKE-SCRIPTS file. |
| 12 |
|
| 13 |
-project(ImageMosaicWall) |
| 14 |
+cmake_minimum_required(VERSION "3.16") |
| 15 |
|
| 16 |
-cmake_minimum_required(VERSION "3.1.0") |
| 17 |
+project(ImageMosaicWall) |
| 18 |
|
| 19 |
-option(ENABLE_DPLUGIN "Build digiKam plugin version of Image Mosaic Wall tool (default=OFF)" OFF) |
| 20 |
-option(BUILD_WITH_QT6 "Build with Qt6, else Qt5" OFF) |
| 21 |
+option(ENABLE_DPLUGIN "Build digiKam plugin only of Image Mosaic Wall tool (default=OFF)" OFF) |
| 22 |
+option(BUILD_WITH_QT6 "Build with Qt6, else Qt5" OFF) |
| 23 |
|
| 24 |
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH}) |
| 25 |
+ |
| 26 |
if (ENABLE_DPLUGIN) |
| 27 |
include(MacroInstall) |
| 28 |
endif() |
| 29 |
@@ -24,6 +25,12 @@ endif() |
| 30 |
|
| 31 |
include(FeatureSummary) |
| 32 |
|
| 33 |
+if(MSVC) |
| 34 |
+ add_compile_options(/utf-8) |
| 35 |
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus") |
| 36 |
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive-") |
| 37 |
+endif() |
| 38 |
+ |
| 39 |
set(CMAKE_CXX_STANDARD 17) |
| 40 |
|
| 41 |
if(CMAKE_VERSION VERSION_LESS "3.7.0") |
| 42 |
@@ -34,7 +41,6 @@ set(CMAKE_AUTOMOC ON) |
| 43 |
set(CMAKE_AUTORCC ON) |
| 44 |
set(CMAKE_AUTOUIC ON) |
| 45 |
|
| 46 |
- |
| 47 |
if(BUILD_WITH_QT6) |
| 48 |
|
| 49 |
find_package(Qt6 "6.5.0" REQUIRED |
| 50 |
@@ -63,10 +69,29 @@ endif() |
| 51 |
|
| 52 |
find_package(Threads) |
| 53 |
|
| 54 |
-find_package(exiv2 REQUIRED) |
| 55 |
+find_package(exiv2lib REQUIRED CONFIG NAMES exiv2) |
| 56 |
+ |
| 57 |
+if(exiv2lib_FOUND) |
| 58 |
+ |
| 59 |
+ message(STATUS "Found Exiv2 version ${exiv2lib_VERSION}") |
| 60 |
+ |
| 61 |
+ # Work around the cmake export rules from Exiv2 since 0.28 |
| 62 |
+ |
| 63 |
+ if("${exiv2lib_VERSION}" VERSION_GREATER "0.27.99") |
| 64 |
+ |
| 65 |
+ set(exiv2lib_LIBRARIES Exiv2::exiv2lib) |
| 66 |
+ |
| 67 |
+ else() |
| 68 |
+ |
| 69 |
+ set(exiv2lib_LIBRARIES exiv2lib) |
| 70 |
+ |
| 71 |
+ endif() |
| 72 |
+ |
| 73 |
+ message(STATUS "Exiv2 libraries: ${exiv2lib_LIBRARIES}") |
| 74 |
|
| 75 |
-set_package_properties("exiv2" PROPERTIES |
| 76 |
- DESCRIPTION "Required to build digiKam" |
| 77 |
+endif() |
| 78 |
+ |
| 79 |
+set_package_properties(exiv2lib PROPERTIES |
| 80 |
URL "https://www.exiv2.org" |
| 81 |
TYPE RECOMMENDED |
| 82 |
PURPOSE "Library to manage image metadata" |
| 83 |
@@ -74,8 +99,7 @@ set_package_properties("exiv2" PROPERTIES |
| 84 |
|
| 85 |
include(i18nUtils) |
| 86 |
|
| 87 |
-include_directories($<TARGET_PROPERTY:exiv2lib,INTERFACE_INCLUDE_DIRECTORIES> |
| 88 |
- $<TARGET_PROPERTY:Qt${QT_VERSION_MAJOR}::Widgets,INTERFACE_INCLUDE_DIRECTORIES> |
| 89 |
+include_directories($<TARGET_PROPERTY:Qt${QT_VERSION_MAJOR}::Widgets,INTERFACE_INCLUDE_DIRECTORIES> |
| 90 |
$<TARGET_PROPERTY:Qt${QT_VERSION_MAJOR}::Core,INTERFACE_INCLUDE_DIRECTORIES> |
| 91 |
$<TARGET_PROPERTY:Qt${QT_VERSION_MAJOR}::Gui,INTERFACE_INCLUDE_DIRECTORIES> |
| 92 |
$<TARGET_PROPERTY:Qt${QT_VERSION_MAJOR}::Concurrent,INTERFACE_INCLUDE_DIRECTORIES> |
| 93 |
@@ -93,7 +117,6 @@ set(imagemosaicwall_core_SRCS ${CMAKE_SOURCE_DIR}/mainwindow.cpp |
| 94 |
${i18n_QM} |
| 95 |
) |
| 96 |
|
| 97 |
- |
| 98 |
if(Qt6_FOUND) |
| 99 |
|
| 100 |
qt6_wrap_ui(imagemosaicwall_core_SRCS ${CMAKE_SOURCE_DIR}/mainwindow.ui |
| 101 |
@@ -119,47 +142,54 @@ set(libimagemosaicwall_core_SRCS |
| 102 |
|
| 103 |
add_library(imagemosaicwallcore STATIC ${libimagemosaicwall_core_SRCS}) |
| 104 |
|
| 105 |
+target_link_libraries(imagemosaicwallcore |
| 106 |
+ PUBLIC |
| 107 |
+ ${exiv2lib_LIBRARIES} |
| 108 |
+) |
| 109 |
+ |
| 110 |
if(NOT MSVC) |
| 111 |
target_compile_options(imagemosaicwallcore PRIVATE -fPIC) |
| 112 |
endif() |
| 113 |
|
| 114 |
-if(APPLE) |
| 115 |
- add_executable(ImageMosaicWall MACOSX_BUNDLE ${OSX_APP_ICON} ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp) |
| 116 |
-else() |
| 117 |
- add_executable(ImageMosaicWall ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp) |
| 118 |
-endif() |
| 119 |
+if(NOT ENABLE_DPLUGIN) |
| 120 |
|
| 121 |
-target_link_libraries(ImageMosaicWall |
| 122 |
+ if(APPLE) |
| 123 |
+ add_executable(ImageMosaicWall MACOSX_BUNDLE ${OSX_APP_ICON} ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp) |
| 124 |
+ else() |
| 125 |
+ add_executable(ImageMosaicWall ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp) |
| 126 |
+ endif() |
| 127 |
|
| 128 |
- imagemosaicwallcore |
| 129 |
+ target_link_libraries(ImageMosaicWall |
| 130 |
|
| 131 |
- Qt${QT_VERSION_MAJOR}::Core |
| 132 |
- Qt${QT_VERSION_MAJOR}::Widgets |
| 133 |
- Qt${QT_VERSION_MAJOR}::Gui |
| 134 |
- Qt${QT_VERSION_MAJOR}::Concurrent |
| 135 |
+ imagemosaicwallcore |
| 136 |
|
| 137 |
- exiv2lib |
| 138 |
- ${CMAKE_THREAD_LIBS_INIT} |
| 139 |
-) |
| 140 |
+ Qt${QT_VERSION_MAJOR}::Core |
| 141 |
+ Qt${QT_VERSION_MAJOR}::Widgets |
| 142 |
+ Qt${QT_VERSION_MAJOR}::Gui |
| 143 |
+ Qt${QT_VERSION_MAJOR}::Concurrent |
| 144 |
+ |
| 145 |
+ ${CMAKE_THREAD_LIBS_INIT} |
| 146 |
+ ) |
| 147 |
+ |
| 148 |
+ if(APPLE) |
| 149 |
+ set(APPS "\${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}.app") |
| 150 |
+ set(DIRS "\${CMAKE_INSTALL_PREFIX}/share") |
| 151 |
|
| 152 |
-if(APPLE) |
| 153 |
- set(APPS "\${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}.app") |
| 154 |
- set(DIRS "\${CMAKE_INSTALL_PREFIX}/share") |
| 155 |
+ install(TARGETS ${PROJECT_NAME} |
| 156 |
+ BUNDLE DESTINATION . COMPONENT Runtime |
| 157 |
+ RUNTIME DESTINATION bin COMPONENT Runtime) |
| 158 |
|
| 159 |
- install(TARGETS ${PROJECT_NAME} |
| 160 |
- BUNDLE DESTINATION . COMPONENT Runtime |
| 161 |
- RUNTIME DESTINATION bin COMPONENT Runtime |
| 162 |
- ) |
| 163 |
+ install(CODE " |
| 164 |
+ include(BundleUtilities) |
| 165 |
+ fixup_bundle(\"${APPS}\" \"\" \"${DIRS}\") |
| 166 |
+ " COMPONENT Runtime) |
| 167 |
+ else() |
| 168 |
+ install(TARGETS ImageMosaicWall RUNTIME DESTINATION bin) |
| 169 |
+ endif() |
| 170 |
|
| 171 |
- install(CODE " |
| 172 |
- include(BundleUtilities) |
| 173 |
- fixup_bundle(\"${APPS}\" \"\" \"${DIRS}\") |
| 174 |
- " COMPONENT Runtime) |
| 175 |
else() |
| 176 |
- install(TARGETS ImageMosaicWall RUNTIME DESTINATION bin) |
| 177 |
-endif() |
| 178 |
|
| 179 |
-if (ENABLE_DPLUGIN) |
| 180 |
add_subdirectory(dplugin) |
| 181 |
MACRO_ADD_UNINSTALL_TARGET() |
| 182 |
+ |
| 183 |
endif() |
| 184 |
diff --git a/dplugin/CMakeLists.txt b/dplugin/CMakeLists.txt |
| 185 |
index 2842f45..f882de8 100644 |
| 186 |
--- a/dplugin/CMakeLists.txt |
| 187 |
+++ b/dplugin/CMakeLists.txt |
| 188 |
@@ -35,8 +35,6 @@ target_link_libraries(Generic_ImageMosaicWall_Plugin |
| 189 |
Qt${QT_VERSION_MAJOR}::Widgets |
| 190 |
Qt${QT_VERSION_MAJOR}::Gui |
| 191 |
Qt${QT_VERSION_MAJOR}::Concurrent |
| 192 |
- |
| 193 |
- exiv2lib |
| 194 |
) |
| 195 |
|
| 196 |
MACRO_ADD_PLUGIN_INSTALL_TARGET(Generic_ImageMosaicWall_Plugin generic) |
| 197 |
diff --git a/imageprocessing.cpp b/imageprocessing.cpp |
| 198 |
index 407d943..b4609a8 100644 |
| 199 |
--- a/imageprocessing.cpp |
| 200 |
+++ b/imageprocessing.cpp |
| 201 |
@@ -1,5 +1,6 @@ |
| 202 |
#include "imageprocessing.h" |
| 203 |
#include <algorithm> |
| 204 |
+#include <cstdlib> |
| 205 |
#include <QDebug> |
| 206 |
#include <QImage> |
| 207 |
#include <QImageReader> |
| 208 |
@@ -18,6 +19,18 @@ |
| 209 |
# define kerErrorMessage ErrorCode::kerErrorMessage |
| 210 |
#endif |
| 211 |
|
| 212 |
+template<class RandomIt> |
| 213 |
+void my_random_shuffle(RandomIt first, RandomIt last) |
| 214 |
+{ |
| 215 |
+ typedef typename std::iterator_traits<RandomIt>::difference_type diff_t; |
| 216 |
+ |
| 217 |
+ for (diff_t i = last - first - 1; i > 0; --i) |
| 218 |
+ { |
| 219 |
+ using std::swap; |
| 220 |
+ swap(first[i], first[std::rand() % (i + 1)]); |
| 221 |
+ } |
| 222 |
+} |
| 223 |
+ |
| 224 |
ImageProcessing::ImageProcessing(QObject *parent) |
| 225 |
: QObject(parent) |
| 226 |
, m_skipBackgroundProcess(false) |
| 227 |
@@ -189,7 +202,7 @@ void ImageProcessing::calculateMosaicPositions(const QSize gridSize, const int s |
| 228 |
for (uint32_t i = startPos; i < startPos + length; ++i) |
| 229 |
positions.push_back(i); |
| 230 |
|
| 231 |
- std::random_shuffle(positions.begin(), positions.end()); |
| 232 |
+ my_random_shuffle(positions.begin(), positions.end()); |
| 233 |
for (auto pos : positions) |
| 234 |
{ |
| 235 |
if (m_skipBackgroundProcess) |