 Chromium Code Reviews
 Chromium Code Reviews Issue 2268093002:
  [WebRTC] A real ScreenCapturer test  (Closed) 
  Base URL: https://chromium.googlesource.com/external/webrtc.git@master
    
  
    Issue 2268093002:
  [WebRTC] A real ScreenCapturer test  (Closed) 
  Base URL: https://chromium.googlesource.com/external/webrtc.git@master| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license | |
| 5 * that can be found in the LICENSE file in the root of the source | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #include "webrtc/modules/desktop_capture/color.h" | |
| 12 | |
| 13 namespace webrtc { | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 bool AlphaEquals(uint8_t i, uint8_t j) { | |
| 18 // On Linux and Windows 8 or early version, '0' was returned for alpha channel | |
| 19 // from capturer APIs, on Windows 10, '255' was returned. So a workaround is | |
| 20 // to treat 0 as 255. | |
| 21 return i == j || ((i == 0 || i == 255) && (j == 0 || j == 255)); | |
| 22 } | |
| 
Jamie
2016/08/26 22:29:09
Do we have any capturers that return a meaningful
 
Hzj_jie
2016/08/29 21:57:27
This class will also be used by FrameGenerator (in
 
Jamie
2016/08/31 17:39:39
Assuming that this class will only be used by test
 
Hzj_jie
2016/08/31 21:22:39
Oh, I should explain more about the scenario in ch
 | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 // static | |
| 27 Color Color::FromBGRA(uint32_t bgra) { | |
| 28 return FromBGRA((bgra & 0xff000000) >> 24, (bgra & 0xff0000) >> 16, | |
| 29 (bgra & 0xff00) >> 8, (bgra & 0xff)); | |
| 30 } | |
| 31 | |
| 32 // static | |
| 33 Color Color::FromBGR(uint32_t bgr) { | |
| 34 return FromBGRA((bgr << 8) + 0xff); | |
| 35 } | |
| 36 | |
| 37 // static | |
| 38 Color Color::FromBGRA(uint8_t blue, uint8_t green, uint8_t red, uint8_t alpha) { | |
| 39 Color c; | |
| 40 c.bgra[0] = blue; | |
| 41 c.bgra[1] = green; | |
| 42 c.bgra[2] = red; | |
| 43 c.bgra[3] = alpha; | |
| 44 return c; | |
| 45 } | |
| 46 | |
| 47 // static | |
| 48 Color Color::FromBGR(uint8_t blue, uint8_t green, uint8_t red) { | |
| 49 return FromBGRA(blue, green, red, 0xff); | |
| 50 } | |
| 51 | |
| 52 bool Color::operator==(const uint8_t* const bgra) const { | |
| 53 for (int i = 0; i < DesktopFrame::kBytesPerPixel - 1; i++) { | |
| 54 if (this->bgra[i] != bgra[i]) { | |
| 55 return false; | |
| 56 } | |
| 57 } | |
| 58 return AlphaEquals(this->bgra[DesktopFrame::kBytesPerPixel - 1], | |
| 59 bgra[DesktopFrame::kBytesPerPixel - 1]); | |
| 60 } | |
| 61 | |
| 62 bool Color::operator!=(const uint8_t* const bgra) const { | |
| 63 return !(*this == bgra); | |
| 64 } | |
| 65 | |
| 66 bool Color::operator==(const Color& right) const { | |
| 67 return *this == right.bgra; | |
| 68 } | |
| 69 | |
| 70 bool Color::operator!=(const Color& right) const { | |
| 71 return !(*this == right); | |
| 72 } | |
| 73 | |
| 74 uint32_t Color::ToUInt32() const { | |
| 75 uint32_t result = 0; | |
| 76 for (int i = 0; i < DesktopFrame::kBytesPerPixel; i++) { | |
| 77 result <<= 8; | |
| 78 result += bgra[i]; | |
| 79 } | |
| 80 return result; | |
| 81 } | |
| 82 | |
| 83 uint8_t Color::blue() const { | |
| 84 return bgra[0]; | |
| 85 } | |
| 86 | |
| 87 uint8_t Color::green() const { | |
| 88 return bgra[1]; | |
| 89 } | |
| 90 | |
| 91 uint8_t Color::red() const { | |
| 92 return bgra[2]; | |
| 93 } | |
| 94 | |
| 95 uint8_t Color::alpha() const { | |
| 96 return bgra[3]; | |
| 97 } | |
| 98 | |
| 99 } // namespace webrtc | |
| OLD | NEW |