| Index: remoting/test/frame_generator_util.cc
|
| diff --git a/remoting/test/frame_generator_util.cc b/remoting/test/frame_generator_util.cc
|
| index bf78b0f14ae415af1c2a53d9d4c7a46d4efded32..c84115a482a8a24f4a8024169f95de0df1b48bff 100644
|
| --- a/remoting/test/frame_generator_util.cc
|
| +++ b/remoting/test/frame_generator_util.cc
|
| @@ -14,6 +14,14 @@
|
|
|
| namespace remoting {
|
| namespace test {
|
| +
|
| +namespace {
|
| +const int kBarcodeCellWidth = 8;
|
| +const int kBarcodeCellHeight = 8;
|
| +const int kBarcodeBits = 10;
|
| +const int kBarcodeBlackThreshold = 85;
|
| +const int kBarcodeWhiteThreshold = 170;
|
| +} // namespace
|
|
|
| std::unique_ptr<webrtc::DesktopFrame> LoadDesktopFrameFromPng(
|
| const char* name) {
|
| @@ -51,5 +59,47 @@
|
| }
|
| }
|
|
|
| +void DrawBarcode(int value, bool changed, webrtc::DesktopFrame* frame) {
|
| + CHECK(value < (1 << kBarcodeBits));
|
| + for (int i = 0; i < kBarcodeBits; ++i) {
|
| + DrawRect(frame, webrtc::DesktopRect::MakeXYWH(i * kBarcodeCellWidth, 0,
|
| + kBarcodeCellWidth,
|
| + kBarcodeCellHeight),
|
| + (value & 1) ? 0xffffffff : 0xff000000);
|
| + value >>= 1;
|
| + }
|
| + if (changed) {
|
| + frame->mutable_updated_region()->AddRect(webrtc::DesktopRect::MakeXYWH(
|
| + 0, 0, kBarcodeCellWidth * kBarcodeBits, kBarcodeCellHeight));
|
| + }
|
| +}
|
| +
|
| +int ReadBarcode(const webrtc::DesktopFrame& frame) {
|
| + int result = 0;
|
| + for (int i = kBarcodeBits - 1; i >= 0; --i) {
|
| + // Sample barcode in the center of the cell for each bit.
|
| + int x = i * kBarcodeCellWidth + kBarcodeCellWidth / 2;
|
| + int y = kBarcodeCellHeight / 2;
|
| + uint8_t* data = frame.GetFrameDataAtPos(webrtc::DesktopVector(x, y));
|
| + int b = data[0];
|
| + int g = data[1];
|
| + int r = data[2];
|
| + bool bit = 0;
|
| + if (b > kBarcodeWhiteThreshold && g > kBarcodeWhiteThreshold &&
|
| + r > kBarcodeWhiteThreshold) {
|
| + bit = 1;
|
| + } else if (b < kBarcodeBlackThreshold && g < kBarcodeBlackThreshold &&
|
| + r < kBarcodeBlackThreshold) {
|
| + bit = 0;
|
| + } else {
|
| + LOG(FATAL) << "Invalid barcode.";
|
| + }
|
| + result <<= 1;
|
| + if (bit)
|
| + result |= 1;
|
| + }
|
| + return result;
|
| +}
|
| +
|
| } // namespace test
|
| } // namespace remoting
|
|
|