MCPcopy Create free account
hub / github.com/MaaXYZ/MaaFramework / process_data

Method process_data

source/MaaAdbControlUnit/Screencap/ScreencapHelper.cpp:15–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13#endif
14
15MAA_CTRL_UNIT_NS_BEGIN
16
17std::optional<cv::Mat>
18 ScreencapHelper::process_data(std::string& buffer, std::function<std::optional<cv::Mat>(const std::string& buffer)> decoder)
19{
20 bool tried_clean = false;
21
22#ifdef _WIN32
23 if (end_of_line_ == EndOfLine::UnknownYet) {
24 auto saved = buffer;
25 if (clean_cr(buffer)) {
26 auto res = decoder(buffer);
27 if (res) {
28 LogInfo << "end_of_line is CRLF";
29 end_of_line_ = EndOfLine::CRLF;
30 return res;
31 }
32 else {
33 saved.swap(buffer);
34 }
35 }
36 tried_clean = true;
37 }
38#endif
39
40 if (end_of_line_ == EndOfLine::CRLF) {
41 tried_clean = true;
42 if (!clean_cr(buffer)) {
43 LogInfo << "end_of_line is set to CRLF but no `\\r\\n` found, set it to LF";
44 end_of_line_ = EndOfLine::LF;
45 }
46 }
47
48 auto res = decoder(buffer);
49
50 if (res) {
51 if (end_of_line_ == EndOfLine::UnknownYet) {
52 LogInfo << "end_of_line is LF";
53 end_of_line_ = EndOfLine::LF;
54 }
55 return res;
56 }
57
58 LogInfo << "data is not empty, but image is empty";
59 if (tried_clean) {
60 LogError << "skip retry decoding and decode failed!";
61 return std::nullopt;
62 }
63
64 LogInfo << "try to cvt lf";
65 if (!clean_cr(buffer)) {
66 LogError << "no `\\r\\n` found, skip retry decode";
67 return std::nullopt;
68 }
69
70 res = decoder(buffer);
71
72 if (!res) {

Callers 5

screencapMethod · 0.80
screencapMethod · 0.80
screencapMethod · 0.80
screencapMethod · 0.80
screencapMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected