Skip to content

Commit 82ef3ab

Browse files
committed
chore: 优化image编码及log
1 parent 5b40c04 commit 82ef3ab

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

source/MaaUtils/Codec/Codec.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,21 @@ bool regex_valid(const std::wstring& regex)
158158

159159
cv::Mat decode_image(const std::string& data)
160160
{
161+
if (data.empty()) {
162+
return {};
163+
}
164+
161165
std::string base64 = base64::base64_decode(data);
162166
std::vector<uchar> buffer(std::make_move_iterator(base64.begin()), std::make_move_iterator(base64.end()));
163167
return cv::imdecode(buffer, cv::IMREAD_COLOR);
164168
}
165169

166170
std::string encode_image(const cv::Mat& image)
167171
{
172+
if (image.empty()) {
173+
return {};
174+
}
175+
168176
std::vector<uchar> buffer;
169177
cv::imencode(".png", image, buffer);
170178
return base64::base64_encode(buffer.data(), buffer.size());

source/include/MaaAgent/Message.hpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -907,9 +907,17 @@ inline std::string short_str(const std::string& str)
907907
inline json::value log_msg(const json::value& j)
908908
{
909909
json::value j_copy = j;
910-
if (j.exists("image")) {
910+
if (j_copy.exists("image")) {
911911
j_copy["image"] = short_str(j.at("image").as_string());
912912
}
913+
if (j_copy.exists("raw")) {
914+
j_copy["raw"] = short_str(j.at("raw").as_string());
915+
}
916+
if (j_copy.exists("draws")) {
917+
for (auto& d : j_copy["draws"].as_array()) {
918+
d = short_str(d.as_string());
919+
}
920+
}
913921
return j_copy;
914922
}
915923

0 commit comments

Comments
 (0)