Skip to content

Commit a65bbad

Browse files
committed
Init
1 parent 8a3ad35 commit a65bbad

File tree

585 files changed

+225304
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

585 files changed

+225304
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.vs
2+
x64

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# jarkViewer
2+
A simple image viewer
3+
4+
先将 jarkViewer/lib/lib.7z 里面所有 `*.lib` 静态库解压到 ` jarkViewer/lib/` 文件夹中, 再编译

ico.ico

31.5 KB
Binary file not shown.

ico.png

15.3 KB
Loading

ico.psd

425 KB
Binary file not shown.

jarkViewer.sln

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.7.34031.279
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "jarkViewer", "jarkViewer\jarkViewer.vcxproj", "{B0D84475-F869-46B6-BB98-40E788CB86D9}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{B0D84475-F869-46B6-BB98-40E788CB86D9}.Debug|x64.ActiveCfg = Release|x64
17+
{B0D84475-F869-46B6-BB98-40E788CB86D9}.Debug|x86.ActiveCfg = Release|x64
18+
{B0D84475-F869-46B6-BB98-40E788CB86D9}.Release|x64.ActiveCfg = Release|x64
19+
{B0D84475-F869-46B6-BB98-40E788CB86D9}.Release|x64.Build.0 = Release|x64
20+
{B0D84475-F869-46B6-BB98-40E788CB86D9}.Release|x86.ActiveCfg = Release|x64
21+
EndGlobalSection
22+
GlobalSection(SolutionProperties) = preSolution
23+
HideSolutionNode = FALSE
24+
EndGlobalSection
25+
GlobalSection(ExtensibilityGlobals) = postSolution
26+
SolutionGuid = {EE655E8B-52BC-4E46-A759-E8818871747B}
27+
EndGlobalSection
28+
EndGlobal

jarkViewer/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
x64
2+
lib/*.lib

jarkViewer/LRU.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#pragma once
2+
3+
#include <unordered_map>
4+
5+
template<typename keyType, typename valueType, int MAX_SIZE = 10>
6+
class LRU { // 假假的 LRU
7+
private:
8+
int size = 0;
9+
keyType link[MAX_SIZE];
10+
std::unordered_map<keyType, valueType> mapData;
11+
12+
public:
13+
valueType& get(const keyType& key, valueType(load)(const keyType&), valueType& defaultMat) {
14+
auto it = mapData.find(key);
15+
if (it != mapData.end()) {
16+
for (int i = 0; i < size; i++) { // 顺序查找
17+
if (link[i] != key) continue;
18+
19+
auto backup = std::move(link[i]);
20+
for (int j = i; j > 0; j--)
21+
link[j] = std::move(link[j - 1]);
22+
link[0] = std::move(backup);;
23+
24+
break;
25+
}
26+
return it->second;
27+
}
28+
29+
valueType newData = load(key);
30+
if (newData.empty())
31+
newData = defaultMat;
32+
33+
for (int j = size - 1; j > 0; j--)
34+
link[j] = std::move(link[j - 1]);
35+
36+
link[0] = key;
37+
mapData[key] = std::move(newData);
38+
39+
if (size < MAX_SIZE)
40+
size++;
41+
42+
return mapData[key];
43+
}
44+
};

jarkViewer/Utils.h

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
#pragma once
2+
3+
#include<iostream>
4+
#include<format>
5+
6+
#include<filesystem>
7+
#include<chrono>
8+
#include<mutex>
9+
#include<semaphore>
10+
11+
#include<string>
12+
#include<vector>
13+
#include<set>
14+
#include<map>
15+
#include<unordered_set>
16+
#include<unordered_map>
17+
18+
#include <winsock2.h>
19+
#pragma comment(lib,"ws2_32.lib")
20+
21+
using std::vector;
22+
using std::string;
23+
using std::wstring;
24+
using std::string_view;
25+
using std::set;
26+
using std::map;
27+
using std::unordered_map;
28+
using std::cout;
29+
using std::endl;
30+
31+
//#include "windows.h"
32+
//#pragma comment(lib,"winmm.lib")
33+
34+
#include "framework.h"
35+
#include "resource.h"
36+
37+
#include<opencv2/core.hpp>
38+
#include<opencv2/opencv.hpp>
39+
#include<opencv2/highgui.hpp>
40+
#include<opencv2/highgui/highgui_c.h>
41+
42+
43+
struct rcFileInfo {
44+
uint8_t* addr = nullptr;
45+
size_t size = 0;
46+
};
47+
48+
struct Cood {
49+
int x = 0;
50+
int y = 0;
51+
52+
Cood operator+(const Cood& t) const {
53+
Cood temp;
54+
temp.x = this->x + t.x;
55+
temp.y = this->y + t.y;
56+
return temp;
57+
}
58+
59+
Cood operator-(const Cood& t) const {
60+
Cood temp;
61+
temp.x = this->x - t.x;
62+
temp.y = this->y - t.y;
63+
return temp;
64+
}
65+
};
66+
67+
namespace Utils {
68+
69+
static const bool DEBUG = true;
70+
template<typename... Args>
71+
static void logxx(const string_view fmt, Args&&... args) {
72+
static FILE* fp = nullptr;
73+
74+
return;
75+
76+
if (DEBUG) {
77+
if (!fp) {
78+
fp = fopen("Z:\\log.txt", "a");
79+
if (!fp)return;
80+
}
81+
82+
auto ts = time(nullptr) + 8 * 3600ULL;// UTC+8
83+
int HH = (ts / 3600) % 24;
84+
int MM = (ts / 60) % 60;
85+
int SS = ts % 60;
86+
87+
fprintf(fp, "[%02d:%02d:%02d] ", HH, MM, SS);
88+
89+
const string str = std::vformat(fmt, std::make_format_args(args...));
90+
fwrite(str.c_str(), 1, str.length(), fp);
91+
92+
fwrite("\n", 1, 1, fp);
93+
fflush(fp);
94+
}
95+
else {
96+
cout << std::vformat(fmt, std::make_format_args(args...)) << endl;
97+
}
98+
}
99+
100+
101+
template<typename... Args>
102+
static void log(const string_view fmt, Args&&... args)
103+
{
104+
static SOCKET sockSer = 0;
105+
static SOCKADDR_IN addr_in{
106+
.sin_family = AF_INET,
107+
.sin_port = htons(80),
108+
//.sin_addr = {.S_un = {.S_addr = inet_addr("127.0.0.1")}}
109+
.sin_addr = {.S_un = {.S_un_b = {127,0,0,1}}}
110+
};
111+
112+
if (sockSer <= 0) {
113+
WORD wVersionRequested;
114+
WSADATA wsaData;
115+
wVersionRequested = MAKEWORD(1, 1);
116+
int err = WSAStartup(wVersionRequested, &wsaData);
117+
if (err != 0)
118+
{
119+
return;
120+
}
121+
if (LOBYTE(wsaData.wVersion) != 1 ||
122+
HIBYTE(wsaData.wVersion) != 1)
123+
{
124+
WSACleanup();
125+
return;
126+
}
127+
128+
sockSer = socket(AF_INET, SOCK_DGRAM, 0);
129+
//addr_in.sin_family = AF_INET;
130+
//addr_in.sin_port = htons(60011);
131+
//addr_in.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
132+
}
133+
134+
const string str = std::vformat(fmt, std::make_format_args(args...));
135+
sendto(sockSer, str.c_str(), (int)str.length(), 0, (const sockaddr*)&addr_in, sizeof(SOCKADDR_IN));
136+
return;
137+
}
138+
139+
string bin2Hex(const void* bytes, const size_t len) {
140+
auto charList = "0123456789ABCDEF";
141+
if (len == 0) return "";
142+
string res(len * 3, ' ');
143+
for (size_t i = 0; i < len; i++) {
144+
const uint8_t value = reinterpret_cast<const uint8_t*>(bytes)[i];
145+
res[i * 3] = charList[value >> 4];
146+
res[i * 3 + 1] = charList[value & 0x0f];
147+
}
148+
return res;
149+
}
150+
151+
std::string wstringToUtf8(const std::wstring& wstr) {
152+
const int len = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, nullptr, 0, nullptr, nullptr);
153+
std::string strRet(len, 0);
154+
WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, strRet.data(), len, nullptr, nullptr);
155+
return strRet;
156+
}
157+
158+
std::wstring utf8ToWstring(const std::string& str) {
159+
int len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, nullptr, 0);
160+
std::wstring wstr(len, 0);
161+
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, wstr.data(), len);
162+
return wstr;
163+
}
164+
165+
std::string utf8ToAnsi(const std::string& str) {
166+
int len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, nullptr, 0);
167+
std::wstring wstr(len, 0);
168+
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, wstr.data(), len);
169+
170+
len = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, nullptr, 0, nullptr, nullptr);
171+
std::string strRet(len, 0);
172+
WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, strRet.data(), len, nullptr, nullptr);
173+
return strRet;
174+
}
175+
176+
std::string ansiToUtf8(const std::string& str) {
177+
int len = MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, nullptr, 0);
178+
std::wstring wstr(len, 0);
179+
MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, wstr.data(), len);
180+
181+
len = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, nullptr, 0, nullptr, nullptr);
182+
std::string strRet(len, 0);
183+
WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, strRet.data(), len, nullptr, nullptr);
184+
return strRet;
185+
}
186+
187+
188+
std::wstring ansiToWstring(const std::string& str) {
189+
int len = MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, nullptr, 0);
190+
std::wstring wstr(len, 0);
191+
MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, wstr.data(), len);
192+
return wstr;
193+
}
194+
195+
std::string wstringToAnsi(const std::wstring& wstr) {
196+
int len = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, nullptr, 0, nullptr, nullptr);
197+
std::string strRet(len, 0);
198+
WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, strRet.data(), len, nullptr, nullptr);
199+
return strRet;
200+
}
201+
202+
rcFileInfo GetResource(unsigned int idi, const wchar_t* type)
203+
{
204+
rcFileInfo rc;
205+
206+
HMODULE ghmodule = GetModuleHandle(NULL);
207+
if (ghmodule == NULL) {
208+
//log("ghmodule null");
209+
return rc;
210+
}
211+
212+
HRSRC hrsrc = FindResource(ghmodule, MAKEINTRESOURCE(idi), type);
213+
if (hrsrc == NULL) {
214+
//log("hrstc null");
215+
return rc;
216+
}
217+
218+
HGLOBAL hg = LoadResource(ghmodule, hrsrc);
219+
if (hg == NULL) {
220+
//log("hg null");
221+
return rc;
222+
}
223+
224+
rc.addr = (unsigned char*)(LockResource(hg));
225+
rc.size = SizeofResource(ghmodule, hrsrc);
226+
return rc;
227+
}
228+
229+
230+
cv::Mat loadMat(const string& path) {
231+
//log("loading: {}", path);
232+
cv::Mat img = imread(path, cv::IMREAD_UNCHANGED);
233+
234+
//if (img.empty())
235+
// log("Cannot load: {}", path);
236+
237+
if (img.channels() != 1 && img.channels() != 3 && img.channels() != 4) {
238+
//log("Unsupport channel: {}", img.channels());
239+
img.release();
240+
}
241+
return img;
242+
}
243+
}

jarkViewer/file/LXGWNeoXiHei.ttf

5.17 MB
Binary file not shown.

0 commit comments

Comments
 (0)