-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPPClient_ImageExample.cpp
More file actions
127 lines (110 loc) · 3.91 KB
/
APPClient_ImageExample.cpp
File metadata and controls
127 lines (110 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#ifdef _MSC_BUILD
#include <Windows.h>
#include <tchar.h>
#pragma comment(lib,"Ws2_32")
#pragma comment(lib,"jsoncpp")
#pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib")
#pragma comment(lib,"XEngine_BaseLib/XEngine_BaseSafe")
#pragma comment(lib,"XEngine_Client/XClient_APIHelp")
#pragma comment(lib,"XEngine_SystemSdk/XEngine_SystemApi")
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <json/json.h>
#include <XEngine_Include/XEngine_CommHdr.h>
#include <XEngine_Include/XEngine_Types.h>
#include <XEngine_Include/XEngine_ProtocolHdr.h>
#include <XEngine_Include/XEngine_BaseLib/BaseLib_Define.h>
#include <XEngine_Include/XEngine_BaseLib/BaseLib_Error.h>
#include <XEngine_Include/XEngine_BaseLib/BaseSafe_Define.h>
#include <XEngine_Include/XEngine_BaseLib/BaseSafe_Error.h>
#include <XEngine_Include/XEngine_Client/APIClient_Define.h>
#include <XEngine_Include/XEngine_Client/APIClient_Error.h>
#include <XEngine_Include/XEngine_SystemSdk/SystemApi_Define.h>
#include <XEngine_Include/XEngine_SystemSdk/SystemApi_Error.h>
//需要优先配置XEngine
//WINDOWS支持VS2022 x64 debug 编译调试
//g++ -std=c++17 -Wall -g APPClient_ImageExample.cpp -o APPClient_ImageExample.exe -I ../../XEngine_Source/XEngine_Depend/XEngine_Module/jsoncpp -L ../../XEngine_Release -lXEngine_BaseLib -lXEngine_BaseSafe -lXClient_APIHelp -ljsoncpp -Wl,-rpath=../../XEngine_Release
bool APPClient_ImageExample_GetAttr(LPCXSTR lpszMsgBuffer, int nMsgLen, int* pInt_Width, int* pInt_Height)
{
int nCode = 0;
LPCXSTR lpszAPIUrl = _X("http://127.0.0.1:5501/api?function=image¶ms1=1");
XCHAR* ptszMsgBuffer = NULL;
if (!APIClient_Http_Request(_X("POST"), lpszAPIUrl, lpszMsgBuffer, &nCode, &ptszMsgBuffer, &nMsgLen))
{
printf("发送投递失败!\n");
return 0;
}
Json::Value st_JsonRoot;
JSONCPP_STRING st_JsonError;
Json::CharReaderBuilder st_JsonBuilder;
//开始解析配置文件
std::unique_ptr<Json::CharReader> const pSt_JsonReader(st_JsonBuilder.newCharReader());
if (!pSt_JsonReader->parse(ptszMsgBuffer, ptszMsgBuffer + nMsgLen, &st_JsonRoot, &st_JsonError))
{
printf("json parse failed\n");
return false;
}
BaseLib_Memory_FreeCStyle((XPPMEM)&ptszMsgBuffer);
Json::Value st_JsonBase = st_JsonRoot["st_BaseInfo"];
*pInt_Width = st_JsonBase["nWidth"].asInt();
*pInt_Height = st_JsonBase["nHeigth"].asInt();
return 0;
}
int test_imgzoom()
{
LPCXSTR lpszFileDir = _X("D:\\Image\\");
int nListCount = 0;
XCHAR** pptszListFile;
SystemApi_File_EnumFile(lpszFileDir, &pptszListFile, &nListCount, false, 1);
for (int i = 0; i < nListCount; i++)
{
int nCode = 0;
int nWidth = 0;
int nHeight = 0;
XCHAR* ptszFileBuffer = (XCHAR*)malloc(XENGINE_MEMORY_SIZE_MAX);
if (NULL == ptszFileBuffer)
{
return -1;
}
memset(ptszFileBuffer, '\0', XENGINE_MEMORY_SIZE_MAX);
FILE* pSt_File = fopen(pptszListFile[i], _X("rb"));
if (NULL == pSt_File)
{
continue;
}
int nRet = fread(ptszFileBuffer, 1, XENGINE_MEMORY_SIZE_MAX, pSt_File);
fclose(pSt_File);
APPClient_ImageExample_GetAttr(ptszFileBuffer, nRet, &nWidth, &nHeight);
XCHAR tszAPIUrl[MAX_PATH] = {};
XCHAR tszFileExt[64] = {};
BaseLib_String_GetFileAndPath(pptszListFile[i], NULL, NULL, NULL, tszFileExt);
_xstprintf(tszAPIUrl, _X("http://127.0.0.1:5501/api?function=image&type=2&ext=%s&width=%d&height=%d"), tszFileExt, nWidth / 2, nHeight / 2);
XCHAR* ptszMsgBuffer = NULL;
if (!APIClient_Http_Request(_X("POST"), tszAPIUrl, ptszFileBuffer, &nCode, &ptszMsgBuffer, &nRet))
{
printf("发送投递失败!\n");
return 0;
}
free(ptszFileBuffer);
pSt_File = _xtfopen(pptszListFile[i], _X("wb"));
fwrite(ptszMsgBuffer, 1, nRet, pSt_File);
fclose(pSt_File);
BaseLib_Memory_FreeCStyle((XPPMEM)&ptszMsgBuffer);
}
return 0;
}
int main()
{
#ifdef _MSC_BUILD
WSADATA st_WSAData;
WSAStartup(MAKEWORD(2, 2), &st_WSAData);
#endif
test_imgzoom();
#ifdef _MSC_BUILD
WSACleanup();
#endif
return 0;
}