Skip to content

Commit c471f61

Browse files
committed
c++20
• c++20 threadpool fix • Timer class fix to resolve ambiguity with OIIO Timer • Imath library fix from custom normalize function time
1 parent 11c3d0b commit c471f61

File tree

6 files changed

+102
-54
lines changed

6 files changed

+102
-54
lines changed

Solidify/Solidify.vcxproj

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@
6060
<LibraryPath>E:\DVR\debug\lib;E:\DVR\lib;$(LibraryPath)</LibraryPath>
6161
<IgnoreImportLibrary>true</IgnoreImportLibrary>
6262
<SourcePath>E:\GH\LibRaw\src;E:\GH\OpenColorIO\src;E:\GH\OpenImageIO\src;$(VC_SourcePath);$(SourcePath)</SourcePath>
63-
<ExternalIncludePath>C:\Qt\6.2.4\msvc2019_64\include;E:\DVR\include;e:\DVR\include\boost-1_85;e:\GH\toml11\build\RELEASE\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</ExternalIncludePath>
63+
<ExternalIncludePath>C:\Qt\6.2.4\msvc2019_64\include;E:\DVR\include;e:\DVR\include\boost-1_87;e:\GH\toml11\build\RELEASE\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</ExternalIncludePath>
6464
</PropertyGroup>
6565
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
6666
<LibraryPath>E:\DVR\lib;$(LibraryPath)</LibraryPath>
6767
<SourcePath>E:\GH\LibRaw\src;E:\GH\OpenColorIO\src;E:\GH\OpenImageIO\src;$(VC_SourcePath);$(SourcePath)</SourcePath>
68-
<ExternalIncludePath>C:\Qt\6.2.4\msvc2019_64\include;E:\DVR\include;e:\DVR\include\boost-1_85;$(VC_IncludePath);e:\GH\toml11\build\RELEASE\include;$(WindowsSDK_IncludePath);</ExternalIncludePath>
68+
<ExternalIncludePath>C:\Qt\6.2.4\msvc2019_64\include;E:\DVR\include;e:\DVR\include\boost-1_87;$(VC_IncludePath);e:\GH\toml11\build\RELEASE\include;$(WindowsSDK_IncludePath);</ExternalIncludePath>
6969
</PropertyGroup>
7070
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
7171
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
7272
<ClCompile>
73-
<LanguageStandard>stdcpp17</LanguageStandard>
73+
<LanguageStandard>stdcpp20</LanguageStandard>
7474
<LanguageStandard_C>stdc11</LanguageStandard_C>
7575
<PreprocessorDefinitions />
7676
</ClCompile>
@@ -90,20 +90,27 @@ xcopy /y e:\DVR\bin\jasper.dll "$(TargetDir)"
9090

9191
xcopy /y e:\DVR\bin\OpenColorIO_2_4.dll "$(TargetDir)"
9292

93-
xcopy /y e:\DVR\bin\OpenEXRUtil-3_2.dll "$(TargetDir)"
94-
xcopy /y e:\DVR\bin\OpenEXR-3_2.dll "$(TargetDir)"
95-
xcopy /y e:\DVR\bin\OpenEXRCore-3_2.dll "$(TargetDir)"
96-
xcopy /y e:\DVR\bin\IlmThread-3_2.dll "$(TargetDir)"
97-
xcopy /y e:\DVR\bin\Iex-3_2.dll "$(TargetDir)"
93+
xcopy /y e:\DVR\bin\OpenEXRUtil-3_4.dll "$(TargetDir)"
94+
xcopy /y e:\DVR\bin\OpenEXR-3_4.dll "$(TargetDir)"
95+
xcopy /y e:\DVR\bin\OpenEXRCore-3_4.dll "$(TargetDir)"
96+
xcopy /y e:\DVR\bin\IlmThread-3_4.dll "$(TargetDir)"
97+
xcopy /y e:\DVR\bin\Iex-3_4.dll "$(TargetDir)"
98+
xcopy /y e:\DVR\bin\Imath-3_2.dll "$(TargetDir)"
9899

99100
xcopy /y e:\DVR\bin\raw_r.dll "$(TargetDir)"
100101
xcopy /y e:\DVR\bin\raw.dll "$(TargetDir)"
101102

103+
xcopy /y e:\DVR\bin\jxl.dll "$(TargetDir)"
104+
xcopy /y e:\DVR\bin\jxl_threads.dll "$(TargetDir)"
105+
xcopy /y e:\DVR\bin\jxl_cms.dll "$(TargetDir)"
106+
xcopy /y e:\DVR\bin\hwy.dll "$(TargetDir)"
107+
102108
xcopy /y e:\DVR\bin\heif.dll "$(TargetDir)"
103109
xcopy /y e:\DVR\bin\libde265.dll "$(TargetDir)"
104110
xcopy /y e:\DVR\bin\libx265.dll "$(TargetDir)"
105111
xcopy /y e:\DVR\bin\kvazaar.dll "$(TargetDir)"
106112
xcopy /y e:\DVR\bin\brotlidec.dll "$(TargetDir)"
113+
xcopy /y e:\DVR\bin\brotlienc.dll "$(TargetDir)"
107114
xcopy /y e:\DVR\bin\brotlicommon.dll "$(TargetDir)"
108115

109116
xcopy /fy e:\DVR\lib\bz2.dll "$(TargetDir)bz2-1.dll"*
@@ -115,21 +122,20 @@ xcopy /y e:\DVR\bin\turbojpeg.dll "$(TargetDir)"
115122
xcopy /y e:\DVR\bin\jpeg62.dll "$(TargetDir)"
116123
xcopy /y e:\DVR\bin\tiff.dll "$(TargetDir)"
117124
xcopy /y e:\DVR\bin\deflate.dll "$(TargetDir)"
118-
xcopy /y e:\DVR\bin\Imath-3_1.dll "$(TargetDir)"
119125
xcopy /y e:\DVR\bin\openjp2.dll "$(TargetDir)"
120126
xcopy /y e:\DVR\bin\libexpat.dll "$(TargetDir)"
121127
xcopy /y e:\DVR\bin\gif.dll "$(TargetDir)"
122128

123-
xcopy /y e:\GH\Little-CMS\RELEASE\bin\lcms2.dll "$(TargetDir)"
129+
xcopy /y e:\GH\Little-CMS\bin\lcms2.dll "$(TargetDir)"
124130

125131
xcopy /y e:\DVR\bin\OpenImageIO.dll "$(TargetDir)"
126132
xcopy /y e:\DVR\bin\OpenImageIO_Util.dll "$(TargetDir)"
127133

128-
xcopy /y e:\DVR\lib\boost_atomic-vc143-mt-x64-1_85.dll "$(TargetDir)"
129-
xcopy /y e:\DVR\lib\boost_filesystem-vc143-mt-x64-1_85.dll "$(TargetDir)"
130-
xcopy /y e:\DVR\lib\boost_log_setup-vc143-mt-x64-1_85.dll "$(TargetDir)"
131-
xcopy /y e:\DVR\lib\boost_log-vc143-mt-x64-1_85.dll "$(TargetDir)"
132-
xcopy /y e:\DVR\lib\boost_thread-vc143-mt-x64-1_85.dll "$(TargetDir)"
134+
xcopy /y e:\DVR\lib\boost_atomic-vc143-mt-x64-1_87.dll "$(TargetDir)"
135+
xcopy /y e:\DVR\lib\boost_filesystem-vc143-mt-x64-1_87.dll "$(TargetDir)"
136+
xcopy /y e:\DVR\lib\boost_log_setup-vc143-mt-x64-1_87.dll "$(TargetDir)"
137+
xcopy /y e:\DVR\lib\boost_log-vc143-mt-x64-1_87.dll "$(TargetDir)"
138+
xcopy /y e:\DVR\lib\boost_thread-vc143-mt-x64-1_87.dll "$(TargetDir)"
133139

134140
xcopy /y c:\Qt\6.2.4\msvc2019_64\bin\Qt6Core.dll "$(TargetDir)"
135141
xcopy /y c:\Qt\6.2.4\msvc2019_64\bin\Qt6Gui.dll "$(TargetDir)"
@@ -165,7 +171,7 @@ xcopy /y e:\DVR\bin\libwebpmux.dll "$(TargetDir)"</Command>
165171
</ItemDefinitionGroup>
166172
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
167173
<ClCompile>
168-
<LanguageStandard>stdcpp17</LanguageStandard>
174+
<LanguageStandard>stdcpp20</LanguageStandard>
169175
<LanguageStandard_C>stdc11</LanguageStandard_C>
170176
</ClCompile>
171177
<QtMoc>
@@ -192,11 +198,12 @@ xcopy /y e:\DVR\debug\bin\jasper.dll "$(TargetDir)"
192198

193199
xcopy /y e:\DVR\bin\OpenColorIO_d_2_4.dll "$(TargetDir)"
194200

195-
xcopy /y e:\DVR\bin\OpenEXRUtil-3_2_d.dll "$(TargetDir)"
196-
xcopy /y e:\DVR\bin\OpenEXR-3_2_d.dll "$(TargetDir)"
197-
xcopy /y e:\DVR\bin\OpenEXRCore-3_2_d.dll "$(TargetDir)"
198-
xcopy /y e:\DVR\bin\IlmThread-3_2_d.dll "$(TargetDir)"
199-
xcopy /y e:\DVR\bin\Iex-3_2_d.dll "$(TargetDir)"
201+
xcopy /y e:\DVR\bin\OpenEXRUtil-3_4_d.dll "$(TargetDir)"
202+
xcopy /y e:\DVR\bin\OpenEXR-3_4_d.dll "$(TargetDir)"
203+
xcopy /y e:\DVR\bin\OpenEXRCore-3_4_d.dll "$(TargetDir)"
204+
xcopy /y e:\DVR\bin\IlmThread-3_4_d.dll "$(TargetDir)"
205+
xcopy /y e:\DVR\bin\Iex-3_4_d.dll "$(TargetDir)"
206+
xcopy /y e:\DVR\bin\Imath-3_2_d.dll "$(TargetDir)"
200207

201208
xcopy /y e:\DVR\bin\raw_rd.dll "$(TargetDir)"
202209
xcopy /y e:\DVR\bin\rawd.dll "$(TargetDir)"
@@ -209,9 +216,15 @@ xcopy /y e:\DVR\bin\libx265d.dll "$(TargetDir)"
209216

210217
xcopy /y e:\DVR\lib\bz2d.dll "$(TargetDir)bz2-1.dll"*
211218

219+
xcopy /y e:\DVR\bin\jxld.dll "$(TargetDir)"
220+
xcopy /y e:\DVR\bin\jxl_threadsd.dll "$(TargetDir)"
221+
xcopy /y e:\DVR\bin\jxl_cmsd.dll "$(TargetDir)"
222+
xcopy /y e:\DVR\bin\hwyd.dll "$(TargetDir)"
223+
212224
xcopy /y e:\DVR\bin\kvazaard.dll "$(TargetDir)"
213225
xcopy /y e:\DVR\bin\brotliencd.dll "$(TargetDir)"
214226
xcopy /y e:\DVR\bin\brotlidecd.dll "$(TargetDir)"
227+
xcopy /y e:\DVR\bin\brotliencd.dll "$(TargetDir)"
215228
xcopy /y e:\DVR\bin\brotlicommond.dll "$(TargetDir)"
216229

217230
xcopy /y e:\DVR\bin\freetyped.dll "$(TargetDir)"
@@ -221,26 +234,25 @@ xcopy /y e:\DVR\debug\bin\turbojpeg.dll "$(TargetDir)"
221234
xcopy /y e:\DVR\debug\bin\jpeg62.dll "$(TargetDir)"
222235
xcopy /y e:\DVR\bin\tiffd.dll "$(TargetDir)"
223236
xcopy /y e:\DVR\debug\bin\deflate.dll "$(TargetDir)"
224-
xcopy /y e:\DVR\bin\Imath-3_1_d.dll "$(TargetDir)"
225237
xcopy /y e:\DVR\bin\openjp2d.dll "$(TargetDir)"
226238
xcopy /y e:\DVR\bin\libexpatd.dll "$(TargetDir)"
227239
xcopy /y e:\DVR\debug\bin\gif.dll "$(TargetDir)"
228240

229-
xcopy /y e:\GH\Little-CMS\DEBUG\bin\lcms2.dll "$(TargetDir)"
241+
xcopy /y e:\GH\Little-CMS\bin\lcms2d.dll "$(TargetDir)"
230242

231243
xcopy /y e:\DVR\bin\OpenImageIO_d.dll "$(TargetDir)"
232244
xcopy /y e:\DVR\bin\OpenImageIO_Util_d.dll "$(TargetDir)"
233245

234-
xcopy /y e:\DVR\lib\boost_atomic-vc143-mt-gd-x64-1_85.dll "$(TargetDir)"
235-
xcopy /y e:\DVR\lib\boost_filesystem-vc143-mt-gd-x64-1_85.dll "$(TargetDir)"
236-
xcopy /y e:\DVR\lib\boost_log_setup-vc143-mt-gd-x64-1_85.dll "$(TargetDir)"
237-
xcopy /y e:\DVR\lib\boost_log-vc143-mt-gd-x64-1_85.dll "$(TargetDir)"
238-
xcopy /y e:\DVR\lib\boost_thread-vc143-mt-gd-x64-1_85.dll "$(TargetDir)"
246+
xcopy /y e:\DVR\lib\boost_atomic-vc143-mt-gd-x64-1_87.dll "$(TargetDir)"
247+
xcopy /y e:\DVR\lib\boost_filesystem-vc143-mt-gd-x64-1_87.dll "$(TargetDir)"
248+
xcopy /y e:\DVR\lib\boost_log_setup-vc143-mt-gd-x64-1_87.dll "$(TargetDir)"
249+
xcopy /y e:\DVR\lib\boost_log-vc143-mt-gd-x64-1_87.dll "$(TargetDir)"
250+
xcopy /y e:\DVR\lib\boost_thread-vc143-mt-gd-x64-1_87.dll "$(TargetDir)"
239251

240-
xcopy /y c:\Qt\6.2.4\msvc2019_64\bin\Qt5Cored.dll "$(TargetDir)"
241-
xcopy /y c:\Qt\6.2.4\msvc2019_64\bin\Qt5Guid.dll "$(TargetDir)"
242-
xcopy /y c:\Qt\6.2.4\msvc2019_64\bin\Qt5Widgetsd.dll "$(TargetDir)"
243-
xcopy /y c:\Qt\6.2.4\msvc2019_64\bin\Qt5Svgd.dll "$(TargetDir)"
252+
xcopy /y c:\Qt\6.2.4\msvc2019_64\bin\Qt6Cored.dll "$(TargetDir)"
253+
xcopy /y c:\Qt\6.2.4\msvc2019_64\bin\Qt6Guid.dll "$(TargetDir)"
254+
xcopy /y c:\Qt\6.2.4\msvc2019_64\bin\Qt6Widgetsd.dll "$(TargetDir)"
255+
xcopy /y c:\Qt\6.2.4\msvc2019_64\bin\Qt6Svgd.dll "$(TargetDir)"
244256

245257
mkdir "$(TargetDir)\plugins\platforms"
246258
mkdir "$(TargetDir)\plugins\imageformats"

Solidify/src/Timer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424

2525
using std::chrono::high_resolution_clock;
2626

27-
class Timer {
27+
class VTimer {
2828
public:
29-
Timer() : start_(high_resolution_clock::now()) {};
30-
~Timer() {};
29+
VTimer() : start_(high_resolution_clock::now()) {};
30+
~VTimer() {};
3131

3232
template <typename T>
3333
T now(const bool reset = true)

Solidify/src/imageio.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <OpenImageIO/imagebuf.h>
2929
#include <OpenImageIO/imagebufalgo.h>
3030
#include <OpenImageIO/imagebufalgo_util.h>
31-
#include <Imath/half.h>
3231
#include <OpenImageIO/half.h>
3332

3433
using namespace OIIO;

Solidify/src/processing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ QString getOutName(const QString& fileName, Settings* settings) {
148148

149149
bool doProcessing(QList<QUrl> urls, QProgressBar* progressBar, MainWindow* mainWindow) {
150150
std::vector<QString> fileNames; // This will hold the names of all files
151-
Timer f_timer;
151+
VTimer f_timer;
152152

153153
for (const QUrl& url : urls) {
154154
QString fileName = url.toLocalFile();

Solidify/src/solidify.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void* getTypedPointer(OIIO::ImageBuf& buf, const OIIO::TypeDesc& type) {
5757

5858
bool solidify_main(const std::string& inputFileName, const std::string& outputFileName, std::pair<ImageBuf, ImageBuf> mask_pair,
5959
QProgressBar* progressBar, MainWindow* mainWindow) {
60-
Timer g_timer;
60+
VTimer g_timer;
6161

6262
//
6363
// Generate a random delay
@@ -72,7 +72,8 @@ bool solidify_main(const std::string& inputFileName, const std::string& outputFi
7272

7373
ImageSpec config;
7474
config["raw:user_flip"] = settings.rawRot;
75-
75+
//config["oiio:reorient"] = 0;
76+
7677
config["oiio:UnassociatedAlpha"] = 0;
7778
config["tiff:UnassociatedAlpha"] = 0;
7879
config["oiio:ColorSpace"] = "Linear";
@@ -88,6 +89,16 @@ bool solidify_main(const std::string& inputFileName, const std::string& outputFi
8889

8990
TypeDesc orig_format = input_buf.spec().format;
9091

92+
// // check EXIF rotation
93+
// int orientation = 1;
94+
// auto& tspec = input_buf.spec();
95+
// auto& extspec = tspec.extra_attribs;
96+
// for (auto& attr : extspec) {
97+
// std::string name = attr.name().string();
98+
// std::string value = attr.get_string();
99+
// LOG(info) << name << " : " << value << std::endl;
100+
//}
101+
91102
LOG(info) << "File bith depth: " << formatText(orig_format) << std::endl;
92103

93104
//ImageBuf::ImageBuf(config, input_buf);
@@ -187,7 +198,7 @@ bool solidify_main(const std::string& inputFileName, const std::string& outputFi
187198

188199
if (settings.isSolidify && isValid) {
189200
LOG(info) << "Filling holes in process...\n";
190-
Timer pushpull_timer;
201+
VTimer pushpull_timer;
191202

192203
if (external_alpha) {
193204
ImageBuf* alpha_buf_ptr = &mask_pair.first;
@@ -261,7 +272,7 @@ bool solidify_main(const std::string& inputFileName, const std::string& outputFi
261272
}
262273

263274
if (settings.repairMode > 0) {
264-
Timer normalize_timer;
275+
VTimer normalize_timer;
265276
bool success = true;
266277
int sign = 1;
267278

@@ -308,7 +319,7 @@ bool solidify_main(const std::string& inputFileName, const std::string& outputFi
308319
}
309320

310321
if (doNormalize) {
311-
Timer normalize_timer;
322+
VTimer normalize_timer;
312323
bool success = true;
313324

314325
ROI roi(0, result_buf.spec().width, 0, result_buf.spec().height, 0, 1, 0, result_buf.spec().nchannels);

Solidify/src/threadpool.h

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,72 +16,98 @@
1616
*/
1717
#pragma once
1818

19+
#pragma once
20+
1921
#include <queue>
2022
#include <vector>
2123
#include <thread>
2224
#include <functional>
2325
#include <mutex>
2426
#include <condition_variable>
25-
#include <atomic>
27+
#include <future>
28+
#include <type_traits>
29+
#include <utility>
2630

2731
class ThreadPool {
2832
public:
33+
// Constructor that creates a thread pool with the specified number of threads
2934
ThreadPool(size_t threads) : stop(false) {
35+
// Create the specified number of worker threads
3036
for (size_t i = 0; i < threads; ++i)
3137
workers.emplace_back([this] {
3238
for (;;) {
3339
std::function<void()> task;
3440
{
35-
std::unique_lock<std::mutex> lock(this->queue_mutex);
41+
// Lock the queue to access tasks
42+
std::unique_lock lock(this->queue_mutex);
43+
// Wait for a task to be available or for stop signal
3644
this->condition.wait(lock, [this] { return this->stop || !this->tasks.empty(); });
45+
// If stop is true and there are no tasks, exit the thread
3746
if (this->stop && this->tasks.empty())
3847
return;
48+
// Get the next task from the queue
3949
task = std::move(this->tasks.front());
4050
this->tasks.pop();
4151
}
52+
// Execute the task
4253
task();
4354
}
4455
});
4556
}
4657

58+
// Method to add a new task to the thread pool
4759
template<class F, class... Args>
48-
auto enqueue(F&& f, Args&&... args) -> std::future<typename std::result_of<F(Args...)>::type>
60+
auto enqueue(F&& f, Args&&... args) -> std::future<std::invoke_result_t<F, Args...>>
4961
{
50-
using return_type = typename std::result_of<F(Args...)>::type;
62+
using return_type = std::invoke_result_t<F, Args...>;
5163

52-
auto task = std::make_shared< std::packaged_task<return_type()> >(
53-
std::bind(std::forward<F>(f), std::forward<Args>(args)...)
64+
// Create a packaged task that wraps the function and its arguments
65+
auto task = std::make_shared<std::packaged_task<return_type()>>(
66+
[func = std::forward<F>(f), ...captured_args = std::forward<Args>(args)]() mutable {
67+
return std::invoke(std::move(func), std::move(captured_args)...);
68+
}
5469
);
5570

71+
// Get a future to allow the caller to retrieve the result of the task
5672
std::future<return_type> res = task->get_future();
5773
{
58-
std::unique_lock<std::mutex> lock(queue_mutex);
74+
std::unique_lock lock(queue_mutex);
5975

60-
// don't allow enqueueing after stopping the pool
76+
// Don't allow enqueueing after the pool has been stopped
6177
if (stop)
6278
throw std::runtime_error("enqueue on stopped ThreadPool");
6379

80+
// Add the task to the queue
6481
tasks.emplace([task]() { (*task)(); });
6582
}
83+
// Notify one waiting thread that a new task is available
6684
condition.notify_one();
6785
return res;
6886
}
6987

70-
88+
// Destructor that joins all threads and stops the thread pool
7189
~ThreadPool() {
7290
{
73-
std::unique_lock<std::mutex> lock(queue_mutex);
91+
std::unique_lock lock(queue_mutex);
92+
// Set stop to true to indicate that no more tasks should be processed
7493
stop = true;
7594
}
95+
// Notify all threads to wake up and check the stop condition
7696
condition.notify_all();
97+
// Join all worker threads to ensure they complete before destruction
7798
for (std::thread& worker : workers)
7899
worker.join();
79100
}
80101

81102
private:
103+
// Vector to hold all worker threads
82104
std::vector<std::thread> workers;
105+
// Queue to hold pending tasks
83106
std::queue<std::function<void()>> tasks;
107+
// Mutex to synchronize access to the task queue
84108
std::mutex queue_mutex;
109+
// Condition variable to notify worker threads of new tasks or stop signal
85110
std::condition_variable condition;
86-
std::atomic<bool> stop;
87-
};
111+
// Boolean flag to indicate if the pool should stop accepting new tasks
112+
bool stop;
113+
};

0 commit comments

Comments
 (0)