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 |
18 std::unique_ptr<webrtc::DesktopFrame> LoadDesktopFrameFromPng( | 26 std::unique_ptr<webrtc::DesktopFrame> LoadDesktopFrameFromPng( |
19 const char* name) { | 27 const char* name) { |
20 base::FilePath file_path; | 28 base::FilePath file_path; |
21 PathService::Get(base::DIR_SOURCE_ROOT, &file_path); | 29 PathService::Get(base::DIR_SOURCE_ROOT, &file_path); |
22 file_path = file_path.AppendASCII("remoting"); | 30 file_path = file_path.AppendASCII("remoting"); |
23 file_path = file_path.AppendASCII("test"); | 31 file_path = file_path.AppendASCII("test"); |
24 file_path = file_path.AppendASCII("data"); | 32 file_path = file_path.AppendASCII("data"); |
25 file_path = file_path.AppendASCII(name); | 33 file_path = file_path.AppendASCII(name); |
26 | 34 |
27 std::string file_content; | 35 std::string file_content; |
(...skipping 16 matching lines...) Expand all Loading... |
44 uint32_t color) { | 52 uint32_t color) { |
45 for (int y = rect.top(); y < rect.bottom(); ++y) { | 53 for (int y = rect.top(); y < rect.bottom(); ++y) { |
46 uint32_t* data = reinterpret_cast<uint32_t*>( | 54 uint32_t* data = reinterpret_cast<uint32_t*>( |
47 frame->GetFrameDataAtPos(webrtc::DesktopVector(rect.left(), y))); | 55 frame->GetFrameDataAtPos(webrtc::DesktopVector(rect.left(), y))); |
48 for (int x = 0; x < rect.width(); ++x) { | 56 for (int x = 0; x < rect.width(); ++x) { |
49 data[x] = color; | 57 data[x] = color; |
50 } | 58 } |
51 } | 59 } |
52 } | 60 } |
53 | 61 |
| 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 |
54 } // namespace test | 104 } // namespace test |
55 } // namespace remoting | 105 } // namespace remoting |
OLD | NEW |