Chromium Code Reviews| Index: webrtc/modules/desktop_capture/color.h |
| diff --git a/webrtc/modules/desktop_capture/color.h b/webrtc/modules/desktop_capture/color.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0cfc543731b4660592fe4a4a83d0045970a40229 |
| --- /dev/null |
| +++ b/webrtc/modules/desktop_capture/color.h |
| @@ -0,0 +1,79 @@ |
| +/* |
| + * 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. |
| + */ |
| + |
| +#ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_COLOR_H_ |
| +#define WEBRTC_MODULES_DESKTOP_CAPTURE_COLOR_H_ |
| + |
| +#include <stdint.h> |
| + |
| +#include "webrtc/modules/desktop_capture/desktop_frame.h" |
| + |
| +namespace webrtc { |
| + |
| +// A four bytes strcture to store a color in BGRA format, which can be converted |
|
Jamie
2016/08/26 22:29:09
s/four bytes/four-byte/
s/strcture/structure/
Hzj_jie
2016/08/29 21:57:27
Done.
|
| +// from and to uint32_t format. This structure also provides functions to |
| +// compare with uint8_t array, say, DesktopFrame::data(). When converting from |
| +// or to uint32_t format, it's big-ending and little-ending safe, but it always |
|
Jamie
2016/08/26 22:29:09
s/ending/endian/
Hzj_jie
2016/08/29 21:57:27
Done.
|
| +// uses BGRA order for internal storage to match DesktopFrame::data(). |
| +// |
| +// This struct is for testing purpose only, and should not be used in production |
| +// logic. |
| +struct Color final { |
| + // Creates a color from a BGRA ordered uint. |
| + static Color FromBGRA(uint32_t bgra); |
| + |
| + // Creates an opaque color from a BGR ordered uint, only low 24 bits of |
| + // |bgr| are used. |
| + static Color FromBGR(uint32_t bgr); |
| + |
| + // Creates a color with BGRA channels. |
| + static Color FromBGRA(uint8_t blue, |
| + uint8_t green, |
| + uint8_t red, |
| + uint8_t alpha); |
|
Jamie
2016/08/26 22:29:09
I think it would be better to include only this ct
Hzj_jie
2016/08/29 21:57:27
Done.
|
| + |
| + // Creates a color with BGR channels, and set alpha channel to 255 (opaque). |
| + static Color FromBGR(uint8_t blue, uint8_t green, uint8_t red); |
| + |
| + // Returns true if |bgra| four bytes in BGRA order represents a same color |
| + // as |this|. |
| + bool operator==(const uint8_t* const bgra) const; |
| + |
| + // Returns true if |bgra| four bytes in BGRA order represents a different |
| + // color as |this|. |
| + bool operator!=(const uint8_t* const bgra) const; |
| + |
| + // Returns true if |this| and |right| is the same color. |
| + bool operator==(const Color& right) const; |
| + |
| + // Returns true if |this| and |right| are different colors. |
| + bool operator!=(const Color& right) const; |
| + |
| + // Converts current Color into its uint format in BGRA order for a quick |
| + // assignment or compare. |
| + uint32_t ToUInt32() const; |
| + |
| + uint8_t blue() const; |
| + |
| + uint8_t green() const; |
| + |
| + uint8_t red() const; |
| + |
| + uint8_t alpha() const; |
| + |
| + uint8_t bgra[DesktopFrame::kBytesPerPixel]; |
| +}; |
| +static_assert( |
| + DesktopFrame::kBytesPerPixel == sizeof(uint32_t), |
| + "A pixel in DesktopFrame should be safe to represent by a uint32_t"); |
| + |
| +} // namespace webrtc |
| + |
| +#endif // WEBRTC_MODULES_DESKTOP_CAPTURE_COLOR_H_ |