Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Unified Diff: webrtc/modules/desktop_capture/color.cc

Issue 2268093002: [WebRTC] A real ScreenCapturer test (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Resolve review comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/desktop_capture/color.cc
diff --git a/webrtc/modules/desktop_capture/color.cc b/webrtc/modules/desktop_capture/color.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7cd5383fc43b3c6569902f80d6b86435c4c33505
--- /dev/null
+++ b/webrtc/modules/desktop_capture/color.cc
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "webrtc/modules/desktop_capture/color.h"
+
+namespace webrtc {
+
+namespace {
+
+bool AlphaEquals(uint8_t i, uint8_t j) {
+ // On Linux and Windows 8 or early version, '0' was returned for alpha channel
+ // from capturer APIs, on Windows 10, '255' was returned. So a workaround is
+ // to treat 0 as 255.
+ return i == j || ((i == 0 || i == 255) && (j == 0 || j == 255));
+}
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
+
+} // namespace
+
+// static
+Color Color::FromBGRA(uint32_t bgra) {
+ return FromBGRA((bgra & 0xff000000) >> 24, (bgra & 0xff0000) >> 16,
+ (bgra & 0xff00) >> 8, (bgra & 0xff));
+}
+
+// static
+Color Color::FromBGR(uint32_t bgr) {
+ return FromBGRA((bgr << 8) + 0xff);
+}
+
+// static
+Color Color::FromBGRA(uint8_t blue, uint8_t green, uint8_t red, uint8_t alpha) {
+ Color c;
+ c.bgra[0] = blue;
+ c.bgra[1] = green;
+ c.bgra[2] = red;
+ c.bgra[3] = alpha;
+ return c;
+}
+
+// static
+Color Color::FromBGR(uint8_t blue, uint8_t green, uint8_t red) {
+ return FromBGRA(blue, green, red, 0xff);
+}
+
+bool Color::operator==(const uint8_t* const bgra) const {
+ for (int i = 0; i < DesktopFrame::kBytesPerPixel - 1; i++) {
+ if (this->bgra[i] != bgra[i]) {
+ return false;
+ }
+ }
+ return AlphaEquals(this->bgra[DesktopFrame::kBytesPerPixel - 1],
+ bgra[DesktopFrame::kBytesPerPixel - 1]);
+}
+
+bool Color::operator!=(const uint8_t* const bgra) const {
+ return !(*this == bgra);
+}
+
+bool Color::operator==(const Color& right) const {
+ return *this == right.bgra;
+}
+
+bool Color::operator!=(const Color& right) const {
+ return !(*this == right);
+}
+
+uint32_t Color::ToUInt32() const {
+ uint32_t result = 0;
+ for (int i = 0; i < DesktopFrame::kBytesPerPixel; i++) {
+ result <<= 8;
+ result += bgra[i];
+ }
+ return result;
+}
+
+uint8_t Color::blue() const {
+ return bgra[0];
+}
+
+uint8_t Color::green() const {
+ return bgra[1];
+}
+
+uint8_t Color::red() const {
+ return bgra[2];
+}
+
+uint8_t Color::alpha() const {
+ return bgra[3];
+}
+
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698