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 #include <string.h> |
| 14 |
| 15 namespace webrtc { |
| 16 |
| 17 namespace { |
| 18 |
| 19 bool AlphaEquals(uint8_t i, uint8_t j) { |
| 20 // On Linux and Windows 8 or early version, '0' was returned for alpha channel |
| 21 // from capturer APIs, on Windows 10, '255' was returned. So a workaround is |
| 22 // to treat 0 as 255. |
| 23 return i == j || ((i == 0 || i == 255) && (j == 0 || j == 255)); |
| 24 } |
| 25 |
| 26 } // namespace |
| 27 |
| 28 Color::Color(uint8_t blue, uint8_t green, uint8_t red, uint8_t alpha) { |
| 29 bgra[0] = blue; |
| 30 bgra[1] = green; |
| 31 bgra[2] = red; |
| 32 bgra[3] = alpha; |
| 33 } |
| 34 |
| 35 Color::Color(uint8_t blue, uint8_t green, uint8_t red) |
| 36 : Color(blue, green, red, 0xff) {} |
| 37 |
| 38 bool Color::operator==(const uint8_t* const bgra) const { |
| 39 for (int i = 0; i < DesktopFrame::kBytesPerPixel - 1; i++) { |
| 40 if (this->bgra[i] != bgra[i]) { |
| 41 return false; |
| 42 } |
| 43 } |
| 44 return AlphaEquals(this->bgra[DesktopFrame::kBytesPerPixel - 1], |
| 45 bgra[DesktopFrame::kBytesPerPixel - 1]); |
| 46 } |
| 47 |
| 48 bool Color::operator!=(const uint8_t* const bgra) const { |
| 49 return !(*this == bgra); |
| 50 } |
| 51 |
| 52 bool Color::operator==(const Color& right) const { |
| 53 return *this == right.bgra; |
| 54 } |
| 55 |
| 56 bool Color::operator!=(const Color& right) const { |
| 57 return !(*this == right); |
| 58 } |
| 59 |
| 60 uint8_t Color::blue() const { |
| 61 return bgra[0]; |
| 62 } |
| 63 |
| 64 uint8_t Color::green() const { |
| 65 return bgra[1]; |
| 66 } |
| 67 |
| 68 uint8_t Color::red() const { |
| 69 return bgra[2]; |
| 70 } |
| 71 |
| 72 uint8_t Color::alpha() const { |
| 73 return bgra[3]; |
| 74 } |
| 75 |
| 76 } // namespace webrtc |
OLD | NEW |