Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ add_compile_options(
/Zc:preprocessor
/wd4100
/wd4201
/wd4324
)

if(MSVC)
Expand Down
14 changes: 14 additions & 0 deletions include/core/ImageDecoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include <filesystem>
#include <optional>
#include <functional>
#include <atomic>
#include <condition_variable>
#include <mutex>
#include <wrl/client.h>
#include <wincodec.h>

Expand Down Expand Up @@ -57,6 +60,9 @@ class ImageDecoder {
ImageDecoder();
~ImageDecoder();

ImageDecoder(const ImageDecoder&) = delete;
ImageDecoder& operator=(const ImageDecoder&) = delete;

// Main decoding interface
std::unique_ptr<DecodedImage> Decode(
const std::filesystem::path& filePath,
Expand Down Expand Up @@ -84,6 +90,13 @@ class ImageDecoder {
static std::vector<std::wstring> GetSupportedExtensions();

private:
struct AsyncDecodeState {
std::atomic<bool> shuttingDown{false};
std::mutex mutex;
std::condition_variable idle;
size_t activeTasks = 0;
};

// WIC decoder implementation
std::unique_ptr<DecodedImage> DecodeWithWIC(
const std::filesystem::path& filePath,
Expand All @@ -103,6 +116,7 @@ class ImageDecoder {
);

Microsoft::WRL::ComPtr<IWICImagingFactory2> wicFactory_;
std::shared_ptr<AsyncDecodeState> asyncState_;
};

} // namespace Core
Expand Down
14 changes: 9 additions & 5 deletions src/core/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace {
void DebugLog(const char* msg) {
static FILE* f = nullptr;
if (!f) {
f = fopen("debug_log.txt", "w");
fopen_s(&f, "debug_log.txt", "w");
}
if (f) {
fprintf(f, "%s\n", msg);
Expand Down Expand Up @@ -1343,7 +1343,8 @@ void Application::SaveScanCache(const std::vector<ScannedImage>& results)
// [24..31] reserved, already zero

// Write entire buffer in one call
FILE* f = _wfopen(filePath.c_str(), L"wb");
FILE* f = nullptr;
_wfopen_s(&f, filePath.c_str(), L"wb");
if (!f) return;

fwrite(header, 1, kHeaderSize, f);
Expand All @@ -1365,7 +1366,8 @@ std::vector<ScannedImage> Application::LoadScanCache()
if (filePath.empty()) return results;

try {
FILE* f = _wfopen(filePath.c_str(), L"rb");
FILE* f = nullptr;
_wfopen_s(&f, filePath.c_str(), L"rb");
if (!f) return results;

// Get file size
Expand Down Expand Up @@ -1456,7 +1458,8 @@ void Application::LoadFolderProfiles()
auto path = GetFolderProfilePath();
if (path.empty()) return;

FILE* f = _wfopen(path.c_str(), L"rb");
FILE* f = nullptr;
_wfopen_s(&f, path.c_str(), L"rb");
if (!f) return;

// Header: "FPROF" + version(4) + count(4)
Expand Down Expand Up @@ -1497,7 +1500,8 @@ void Application::SaveFolderProfiles()
std::lock_guard lock(scanMutex_);

std::filesystem::create_directories(path.parent_path());
FILE* f = _wfopen(path.c_str(), L"wb");
FILE* f = nullptr;
_wfopen_s(&f, path.c_str(), L"wb");
if (!f) return;

fwrite("FPROF", 1, 5, f);
Expand Down
Loading