OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/desktop_capture/rgba_color.h" | 11 #include "webrtc/modules/desktop_capture/rgba_color.h" |
12 | 12 |
13 #include "webrtc/typedefs.h" | |
14 | |
13 namespace webrtc { | 15 namespace webrtc { |
14 | 16 |
15 namespace { | 17 namespace { |
16 | 18 |
17 bool AlphaEquals(uint8_t i, uint8_t j) { | 19 bool AlphaEquals(uint8_t i, uint8_t j) { |
18 // On Linux and Windows 8 or early version, '0' was returned for alpha channel | 20 // 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 | 21 // from capturer APIs, on Windows 10, '255' was returned. So a workaround is |
20 // to treat 0 as 255. | 22 // to treat 0 as 255. |
21 return i == j || ((i == 0 || i == 255) && (j == 0 || j == 255)); | 23 return i == j || ((i == 0 || i == 255) && (j == 0 || j == 255)); |
22 } | 24 } |
23 | 25 |
24 } // namespace | 26 } // namespace |
25 | 27 |
26 RgbaColor::RgbaColor(uint8_t blue, uint8_t green, uint8_t red, uint8_t alpha) { | 28 RgbaColor::RgbaColor(uint8_t blue, uint8_t green, uint8_t red, uint8_t alpha) { |
27 this->blue = blue; | 29 this->blue = blue; |
28 this->green = green; | 30 this->green = green; |
29 this->red = red; | 31 this->red = red; |
30 this->alpha = alpha; | 32 this->alpha = alpha; |
31 } | 33 } |
32 | 34 |
33 RgbaColor::RgbaColor(uint8_t blue, uint8_t green, uint8_t red) | 35 RgbaColor::RgbaColor(uint8_t blue, uint8_t green, uint8_t red) |
34 : RgbaColor(blue, green, red, 0xff) {} | 36 : RgbaColor(blue, green, red, 0xff) {} |
35 | 37 |
36 RgbaColor::RgbaColor(const uint8_t* bgra) | 38 RgbaColor::RgbaColor(const uint8_t* bgra) |
37 : RgbaColor(bgra[0], bgra[1], bgra[2], bgra[3]) {} | 39 : RgbaColor(bgra[0], bgra[1], bgra[2], bgra[3]) {} |
38 | 40 |
41 // Converting from or to uint32 in big-endian system has not been supported. | |
42 #if defined(WEBRTC_ARCH_LITTLE_ENDIAN) | |
43 RgbaColor::RgbaColor(uint32_t bgra) | |
44 : RgbaColor((bgra & 0xff000000) >> 24, | |
Sergey Ulanov
2016/09/20 21:06:41
nit: the old version of this constructor with rein
Hzj_jie
2016/09/20 23:50:12
Then I think we do not need to add big-endian or l
| |
45 (bgra & 0x00ff0000) >> 16, | |
46 (bgra & 0x0000ff00) >> 8, | |
47 (bgra & 0x000000ff)) {} | |
48 #endif | |
49 | |
39 bool RgbaColor::operator==(const RgbaColor& right) const { | 50 bool RgbaColor::operator==(const RgbaColor& right) const { |
40 return blue == right.blue && green == right.green && red == right.red && | 51 return blue == right.blue && green == right.green && red == right.red && |
41 AlphaEquals(alpha, right.alpha); | 52 AlphaEquals(alpha, right.alpha); |
42 } | 53 } |
43 | 54 |
44 bool RgbaColor::operator!=(const RgbaColor& right) const { | 55 bool RgbaColor::operator!=(const RgbaColor& right) const { |
45 return !(*this == right); | 56 return !(*this == right); |
46 } | 57 } |
47 | 58 |
59 // Converting from or to uint32 in big-endian system has not been supported. | |
60 #if defined(WEBRTC_ARCH_LITTLE_ENDIAN) | |
Sergey Ulanov
2016/09/20 21:06:41
It's better to put this inside the body of this fu
Hzj_jie
2016/09/20 23:50:12
Since supporting big-endian is pretty simple, inst
| |
61 uint32_t RgbaColor::ToUInt32() const { | |
62 return (blue << 24) | (green << 16) | (red << 8) | alpha; | |
63 } | |
64 #endif | |
65 | |
48 } // namespace webrtc | 66 } // namespace webrtc |
OLD | NEW |