OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/test/frame_generator_util.h" | 5 #include "remoting/test/frame_generator_util.h" |
6 | 6 |
7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
11 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 11 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
12 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" | 12 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
13 #include "ui/gfx/codec/png_codec.h" | 13 #include "ui/gfx/codec/png_codec.h" |
14 | 14 |
15 namespace remoting { | 15 namespace remoting { |
16 namespace test { | 16 namespace test { |
17 | 17 |
18 namespace { | |
19 const int kBarcodeCellWidth = 8; | |
20 const int kBarcodeCellHeight = 8; | |
21 const int kBarcodeBits = 10; | |
22 const int kBarcodeBlackThreshold = 85; | |
23 const int kBarcodeWhiteThreshold = 170; | |
24 } // namespace | |
25 | |
26 std::unique_ptr<webrtc::DesktopFrame> LoadDesktopFrameFromPng( | 18 std::unique_ptr<webrtc::DesktopFrame> LoadDesktopFrameFromPng( |
27 const char* name) { | 19 const char* name) { |
28 base::FilePath file_path; | 20 base::FilePath file_path; |
29 PathService::Get(base::DIR_SOURCE_ROOT, &file_path); | 21 PathService::Get(base::DIR_SOURCE_ROOT, &file_path); |
30 file_path = file_path.AppendASCII("remoting"); | 22 file_path = file_path.AppendASCII("remoting"); |
31 file_path = file_path.AppendASCII("test"); | 23 file_path = file_path.AppendASCII("test"); |
32 file_path = file_path.AppendASCII("data"); | 24 file_path = file_path.AppendASCII("data"); |
33 file_path = file_path.AppendASCII(name); | 25 file_path = file_path.AppendASCII(name); |
34 | 26 |
35 std::string file_content; | 27 std::string file_content; |
(...skipping 16 matching lines...) Expand all Loading... |
52 uint32_t color) { | 44 uint32_t color) { |
53 for (int y = rect.top(); y < rect.bottom(); ++y) { | 45 for (int y = rect.top(); y < rect.bottom(); ++y) { |
54 uint32_t* data = reinterpret_cast<uint32_t*>( | 46 uint32_t* data = reinterpret_cast<uint32_t*>( |
55 frame->GetFrameDataAtPos(webrtc::DesktopVector(rect.left(), y))); | 47 frame->GetFrameDataAtPos(webrtc::DesktopVector(rect.left(), y))); |
56 for (int x = 0; x < rect.width(); ++x) { | 48 for (int x = 0; x < rect.width(); ++x) { |
57 data[x] = color; | 49 data[x] = color; |
58 } | 50 } |
59 } | 51 } |
60 } | 52 } |
61 | 53 |
62 void DrawBarcode(int value, bool changed, webrtc::DesktopFrame* frame) { | |
63 CHECK(value < (1 << kBarcodeBits)); | |
64 for (int i = 0; i < kBarcodeBits; ++i) { | |
65 DrawRect(frame, webrtc::DesktopRect::MakeXYWH(i * kBarcodeCellWidth, 0, | |
66 kBarcodeCellWidth, | |
67 kBarcodeCellHeight), | |
68 (value & 1) ? 0xffffffff : 0xff000000); | |
69 value >>= 1; | |
70 } | |
71 if (changed) { | |
72 frame->mutable_updated_region()->AddRect(webrtc::DesktopRect::MakeXYWH( | |
73 0, 0, kBarcodeCellWidth * kBarcodeBits, kBarcodeCellHeight)); | |
74 } | |
75 } | |
76 | |
77 int ReadBarcode(const webrtc::DesktopFrame& frame) { | |
78 int result = 0; | |
79 for (int i = kBarcodeBits - 1; i >= 0; --i) { | |
80 // Sample barcode in the center of the cell for each bit. | |
81 int x = i * kBarcodeCellWidth + kBarcodeCellWidth / 2; | |
82 int y = kBarcodeCellHeight / 2; | |
83 uint8_t* data = frame.GetFrameDataAtPos(webrtc::DesktopVector(x, y)); | |
84 int b = data[0]; | |
85 int g = data[1]; | |
86 int r = data[2]; | |
87 bool bit = 0; | |
88 if (b > kBarcodeWhiteThreshold && g > kBarcodeWhiteThreshold && | |
89 r > kBarcodeWhiteThreshold) { | |
90 bit = 1; | |
91 } else if (b < kBarcodeBlackThreshold && g < kBarcodeBlackThreshold && | |
92 r < kBarcodeBlackThreshold) { | |
93 bit = 0; | |
94 } else { | |
95 LOG(FATAL) << "Invalid barcode."; | |
96 } | |
97 result <<= 1; | |
98 if (bit) | |
99 result |= 1; | |
100 } | |
101 return result; | |
102 } | |
103 | |
104 } // namespace test | 54 } // namespace test |
105 } // namespace remoting | 55 } // namespace remoting |
OLD | NEW |