Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
mcychan authored Dec 29, 2024
1 parent a56abc0 commit 61a55f4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
14 changes: 9 additions & 5 deletions nQuantCpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
cmake_minimum_required (VERSION 3.10)

add_executable (nQuantCpp "nQuantCpp.cpp" "nQuantCpp.h" "nQuantCpp.rc" "bitmapUtilities.cpp" "bitmapUtilities.h" "BlueNoise.cpp" "BlueNoise.h" "CIELABConvertor.cpp" "CIELABConvertor.h" "DivQuantizer.cpp" "DivQuantizer.h"
"Dl3Quantizer.cpp" "Dl3Quantizer.h" "EdgeAwareSQuantizer.cpp" "EdgeAwareSQuantizer.h" "GifWriter.cpp" "GifWriter.h" "GilbertCurve.cpp" "GilbertCurve.h" "MedianCut.cpp" "MedianCut.h" "Otsu.cpp" "Otsu.h"
"NeuQuantizer.cpp" "NeuQuantizer.h" "PnnLABQuantizer.cpp" "PnnLABQuantizer.h" "PnnLABGAQuantizer.cpp" "PnnLABGAQuantizer.h" "PnnQuantizer.cpp" "PnnQuantizer.h" "Resource.h"
"SpatialQuantizer.cpp" "SpatialQuantizer.h" "stdafx.cpp" "stdafx.h" "WuQuantizer.cpp" "WuQuantizer.h"
"NsgaIII.cpp" "NsgaIII.h" "APNsgaIII.cpp" "APNsgaIII.h")
if(NOT WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I /usr/include/wine/wine/windows")
endif()
add_executable(nQuantCpp "nQuantCpp.cpp" "nQuantCpp.h" "nQuantCpp.rc" "bitmapUtilities.cpp" "bitmapUtilities.h" "BlueNoise.cpp" "BlueNoise.h" "CIELABConvertor.cpp" "CIELABConvertor.h" "DivQuantizer.cpp" "DivQuantizer.h"
"Dl3Quantizer.cpp" "Dl3Quantizer.h" "EdgeAwareSQuantizer.cpp" "EdgeAwareSQuantizer.h" "GifWriter.cpp" "GifWriter.h" "GilbertCurve.cpp" "GilbertCurve.h" "MedianCut.cpp" "MedianCut.h" "Otsu.cpp" "Otsu.h"
"NeuQuantizer.cpp" "NeuQuantizer.h" "PnnLABQuantizer.cpp" "PnnLABQuantizer.h" "PnnLABGAQuantizer.cpp" "PnnLABGAQuantizer.h" "PnnQuantizer.cpp" "PnnQuantizer.h" "Resource.h"
"SpatialQuantizer.cpp" "SpatialQuantizer.h" "stdafx.cpp" "stdafx.h" "WuQuantizer.cpp" "WuQuantizer.h"
"NsgaIII.cpp" "NsgaIII.h" "APNsgaIII.cpp" "APNsgaIII.h")

find_package(OpenMP)
if(OpenMP_CXX_FOUND)
target_link_libraries(nQuantCpp PUBLIC gdiplus OpenMP::OpenMP_CXX)
Expand Down
18 changes: 10 additions & 8 deletions nQuantCpp/nQuantCpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

#include "stdafx.h"
#include <tchar.h>
#include <algorithm>
#include <chrono>
#ifdef _WIN32
#include <io.h>
#define tcslen wcslen
#endif
#include <iostream>
#include <fcntl.h>
#include <filesystem>
Expand Down Expand Up @@ -44,7 +44,7 @@ GdiplusStartupInput m_gdiplusStartupInput;
ULONG_PTR m_gdiplusToken;

wstring algs[] = { L"PNN", L"PNNLAB", L"PNNLAB+", L"NEU", L"WU", L"EAS", L"SPA", L"DIV", L"DL3", L"MMC", L"OTSU" };
unordered_map<LPCTSTR, CLSID> extensionMap;
unordered_map<LPCWSTR, CLSID> extensionMap;

void PrintUsage()
{
Expand Down Expand Up @@ -149,7 +149,7 @@ inline bool fileExists(const wstring& path)
return fs::exists(fs::path(path));
}

bool OutputImage(const fs::path& sourcePath, const wstring& algorithm, const UINT& nMaxColors, wstring& targetDir, Bitmap* pDest, LPCTSTR defaultExtension = L".png")
bool OutputImage(const fs::path& sourcePath, const wstring& algorithm, const UINT& nMaxColors, wstring& targetDir, Bitmap* pDest, LPCWSTR defaultExtension = L".png")
{
auto fileName = sourcePath.filename().wstring();
fileName = fileName.substr(0, fileName.find_last_of(L'.'));
Expand Down Expand Up @@ -268,7 +268,7 @@ static void OutputImages(const fs::path& sourceDir, wstring& targetDir, const UI
}
}

if (algo == _T("PNN")) {
if (algo == L"PNN") {
if (nMaxColors > 256 || delay < 0) {
int i = 0;
for (auto& sourcePath : sourcePaths)
Expand All @@ -280,7 +280,7 @@ static void OutputImages(const fs::path& sourceDir, wstring& targetDir, const UI

targetDir = fileExists(targetDir) ? fs::canonical(fs::path(targetDir)) : fs::current_path();
auto destPath = targetDir + L"/" + fileName + L"-";
if (algo == _T("PNNLAB")) {
if (algo == L"PNNLAB") {
destPath += L"PNNLABquant.gif";

UINT maxColors = nMaxColors;
Expand Down Expand Up @@ -352,7 +352,9 @@ static void OutputImages(const fs::path& sourceDir, wstring& targetDir, const UI

int _tmain(int argc, _TCHAR** argv)
{
#ifdef _WIN32
_setmode(_fileno(stdout), _O_U16TEXT);
#endif

#ifndef _DEBUG
if (argc <= 1) {
Expand All @@ -371,7 +373,7 @@ int _tmain(int argc, _TCHAR** argv)

vector<wstring> argList(argc);
for (int i = 1; i < argc; ++i)
argList[i] = wstring(argv[i], argv[i] + tcslen(argv[i]));
argList[i] = wstring(argv[i], argv[i] + wcslen(argv[i]));

#ifdef _DEBUG
wstring sourceFile = szDir + L"/../ImgV64.gif";
Expand All @@ -380,7 +382,7 @@ int _tmain(int argc, _TCHAR** argv)
if (!ProcessArgs(argc, algo, nMaxColors, dither, targetDir, argList.data(), delay))
return 0;

wstring sourceFile(argv[1], argv[1] + tcslen(argv[1]));
wstring sourceFile(argv[1], argv[1] + wcslen(argv[1]));
if (!fileExists(sourceFile) && sourceFile.find_first_of(L"\\/") != wstring::npos)
sourceFile = szDir + L"/" + sourceFile;
#endif
Expand Down
2 changes: 2 additions & 0 deletions nQuantCpp/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#pragma comment(linker, "\"/manifestdependency:type='Win32' name='Microsoft.Windows.GdiPlus' version='1.1.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#else
#include <shlobj.h>
#include <gdiplus.h>
using namespace Gdiplus;
#ifndef BYTE
typedef unsigned char BYTE;
Expand Down

0 comments on commit 61a55f4

Please sign in to comment.