Skip to content

Commit 1f5347c

Browse files
committed
perf: Agent 尝试使用gzip bmp传输图片
1 parent 1961509 commit 1f5347c

File tree

5 files changed

+15
-330
lines changed

5 files changed

+15
-330
lines changed

3rdparty/include/cpp-base64/base64.hpp

-319
This file was deleted.

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ _请留意,仅当您准备开发 MaaFramework 本身时,才需要阅读本
168168
A massively spiffy yet delicately unobtrusive compression library.
169169
- [gzip-hpp](https://github.com/mapbox/gzip-hpp)
170170
Gzip header-only C++ library
171-
- [cpp-base64](https://github.com/ReneNyffenegger/cpp-base64)
172-
base64 encoding and decoding with c++
173171
- ~~[protobuf](https://github.com/protocolbuffers/protobuf)~~
174172
~~Protocol Buffers - Google's data interchange format~~
175173
- ~~[grpc](https://github.com/grpc/grpc)~~

README_en.md

-2
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,6 @@ _Please note that you only need to read this chapter if you are ready to develop
167167
A massively spiffy yet delicately unobtrusive compression library.
168168
- [gzip-hpp](https://github.com/mapbox/gzip-hpp)
169169
Gzip header-only C++ library
170-
- [cpp-base64](https://github.com/ReneNyffenegger/cpp-base64)
171-
base64 encoding and decoding with c++
172170
- ~~[protobuf](https://github.com/protocolbuffers/protobuf)~~
173171
~~Protocol Buffers - Google's data interchange format~~
174172
- ~~[grpc](https://github.com/grpc/grpc)~~

source/MaaUtils/Codec/Codec.cpp

+14-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55
#include <regex>
66
#include <string>
77

8-
#include <cpp-base64/base64.hpp>
8+
#ifdef _MSC_VER
9+
#pragma warning(push)
10+
#pragma warning(disable: 4068)
11+
#endif
12+
#include <gzip/decompress.hpp>
13+
#include <gzip/compress.hpp>
14+
#ifdef _MSC_VER
15+
#pragma warning(pop)
16+
#endif
917

1018
#include "Utils/Logger.h"
1119
#include "Utils/NoWarningCV.hpp"
@@ -162,9 +170,8 @@ cv::Mat decode_image(const std::string& data)
162170
return {};
163171
}
164172

165-
std::string base64 = base64::base64_decode(data);
166-
std::vector<uchar> buffer(std::make_move_iterator(base64.begin()), std::make_move_iterator(base64.end()));
167-
return cv::imdecode(buffer, cv::IMREAD_COLOR);
173+
auto buffer = gzip::decompress(data.data(), data.size());
174+
return cv::imdecode({ buffer.data(), static_cast<int>(buffer.size()) }, cv::IMREAD_COLOR);
168175
}
169176

170177
std::string encode_image(const cv::Mat& image)
@@ -174,8 +181,9 @@ std::string encode_image(const cv::Mat& image)
174181
}
175182

176183
std::vector<uchar> buffer;
177-
cv::imencode(".png", image, buffer);
178-
return base64::base64_encode(buffer.data(), buffer.size());
184+
cv::imencode(".bmp", image, buffer);
185+
186+
return gzip::compress(reinterpret_cast<char*>(buffer.data()), buffer.size(), 0);
179187
}
180188

181189
MAA_NS_END

source/include/MaaAgent/Message.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ MAA_AGENT_NS_BEGIN
1414
// ReverseRequest: server -> client
1515

1616
using MessageTypePlaceholder = int;
17-
inline static constexpr int kProtocolVersion = 1;
17+
inline static constexpr int kProtocolVersion = 2;
1818

1919
struct StartUpRequest
2020
{

0 commit comments

Comments
 (0)