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

Unified Diff: media/base/video_color_space.h

Issue 2088273003: Video Color Managament (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: bugfix Created 4 years, 5 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: media/base/video_color_space.h
diff --git a/media/base/video_color_space.h b/media/base/video_color_space.h
new file mode 100644
index 0000000000000000000000000000000000000000..2be5b1d809a890f67274a4460cc5a822b5ad0673
--- /dev/null
+++ b/media/base/video_color_space.h
@@ -0,0 +1,188 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_BASE_COLOR_SPACE_H_
+#define MEDIA_BASE_COLOR_SPACE_H_
+
+#include <cstdint>
+#include <vector>
+
+#include "base/memory/ref_counted.h"
+#include "media/base/media_export.h"
+#include "media/base/video_types.h"
+
+namespace media {
+
+class VideoFrame;
+
+class MEDIA_EXPORT VideoColorSpace {
+ public:
+ enum PrimaryID : int16_t {
+ // The first 0-255 values should match the H264 specification.
+ PRI_RESERVED0 = 0,
+ PRI_BT709 = 1,
+ PRI_UNSPECIFIED = 2,
+ PRI_RESERVED = 3,
+ PRI_BT470M = 4,
+ PRI_BT470BG = 5,
+ PRI_SMPTE170M = 6,
+ PRI_SMPTE240M = 7,
+ PRI_FILM = 8,
+ PRI_BT2020 = 9,
+ PRI_SMPTEST428_1 = 10,
+ PRI_SMPTEST431_2 = 11,
+ PRI_SMPTEST432_1 = 12,
+
+ // Chrome-specific values start at 1000.
+ PRI_XYZ_D50 = 1000,
+ PRI_LAST = PRI_XYZ_D50
+ };
+
+ enum TransferID : int16_t {
+ // The first 0-255 values should match the H264 specification.
+ TRC_RESERVED0 = 0,
+ TRC_BT709 = 1,
+ TRC_UNSPECIFIED = 2,
+ TRC_RESERVED = 3,
+ TRC_GAMMA22 = 4,
+ TRC_GAMMA28 = 5,
+ TRC_SMPTE170M = 6,
+ TRC_SMPTE240M = 7,
+ TRC_LINEAR = 8,
+ TRC_LOG = 9,
+ TRC_LOG_SQRT = 10,
+ TRC_IEC61966_2_4 = 11,
+ TRC_BT1361_ECG = 12,
+ TRC_IEC61966_2_1 = 13,
+ TRC_BT2020_10 = 14,
+ TRC_BT2020_12 = 15,
+ TRC_SMPTEST2084 = 16,
+ TRC_SMPTEST428_1 = 17,
+
+ // Chrome-specific values start at 1000.
+ TRC_GAMMA24 = 1000,
+
+ TRC_LAST = TRC_GAMMA24
+ };
+
+ enum MatrixID : int16_t {
+ // The first 0-255 values should match the H264 specification.
+ SPC_RGB = 0,
+ SPC_BT709 = 1,
+ SPC_UNSPECIFIED = 2,
+ SPC_RESERVED = 3,
+ SPC_FCC = 4,
+ SPC_BT470BG = 5,
+ SPC_SMPTE170M = 6,
+ SPC_SMPTE240M = 7,
+ SPC_YCOCG = 8,
+ SPC_BT2020_NCL = 9,
+ SPC_BT2020_CL = 10,
+ SPC_YDZDX = 11,
+
+ // Chrome-specific values start at 1000
+ SPC_LAST = SPC_BT2020_CL
+ };
+
+ typedef float Quad[4];
+ struct Matrix4x4 {
+ Quad rows[4];
+ };
+ // Tristimulus value, RGB, XYZ or YUV
+ struct TriStim {
+ TriStim() {
+ values[0] = 0.0f;
+ values[1] = 0.0f;
+ values[2] = 0.0f;
+ }
+ TriStim(float a, float b, float c) {
+ values[0] = a;
+ values[1] = b;
+ values[2] = c;
+ }
+ float values[3];
+ };
+
+ // Used to represent the XY coordinate of a primary.
+ typedef std::pair<float, float> XY;
+
+ VideoColorSpace();
+ VideoColorSpace(PrimaryID primaries,
+ TransferID transfer,
+ MatrixID matrix,
+ bool full_range);
+
+ bool operator==(const VideoColorSpace& other) const;
+ bool operator<(const VideoColorSpace& other) const;
+
+ // Get a color space from a video frame.
+ explicit VideoColorSpace(const scoped_refptr<VideoFrame>& frame);
+ explicit VideoColorSpace(ColorSpace color_space);
+ void SetVideoFrameColorSpace(const scoped_refptr<VideoFrame>& frame);
+
+ // Return the XYZ (D50) color space.
+ static VideoColorSpace XYZ();
+ // Return the SRGB color space.
+ static VideoColorSpace SRGB();
+
+ static std::vector<XY> GetPrimaries(PrimaryID id);
+ std::vector<XY> GetPrimaries() const { return GetPrimaries(primaries); }
+
+ // Get a matrix for convertnig from the given primaries to XYZD50.
+ static Matrix4x4 GetPrimaryMatrix(const std::vector<XY>& primaries);
+ static Matrix4x4 GetPrimaryMatrix(PrimaryID id) {
+ return GetPrimaryMatrix(GetPrimaries(id));
+ }
+ Matrix4x4 GetPrimaryMatrix() const {
+ return GetPrimaryMatrix(GetPrimaries());
+ }
+
+ // Undo gamma correction.
+ static float toLinear(TransferID id, float f);
+ float toLinear(float f) const { return toLinear(transfer, f); }
+
+ // Do gamma correction.
+ static float fromLinear(TransferID id, float f);
+ float fromLinear(float f) const { return fromLinear(transfer, f); }
+
+ // Get the matrix for YUV->primaries (rgb) conversion.
+ static Matrix4x4 GetTransferMatrix(MatrixID id);
+ Matrix4x4 GetTransferMatrix() const { return GetTransferMatrix(matrix); }
+
+ // Get the values needed to correct the range.
+ // Returns false if offset == 0.0 && multiplier == 1.0.
+ bool GetRangeAdjust(TriStim* offset, TriStim* multiplier) const;
+ Matrix4x4 GetRangeAdjustMatrix() const;
+
+ static Matrix4x4 Multiply(const Matrix4x4& a, const Matrix4x4& b);
+ static TriStim Multiply(const Matrix4x4& a, const TriStim& b);
+ static Matrix4x4 Invert(Matrix4x4 a);
+
+ PrimaryID primaries;
+ TransferID transfer;
+ MatrixID matrix;
+ bool full_range;
+};
+
+class MEDIA_EXPORT ColorTransform {
+ public:
+ enum Intent {
+ INTENT_ABSOLUTE,
+ INTENT_PERCEIVED,
+ };
+
+ ColorTransform(const VideoColorSpace& from,
+ const VideoColorSpace& to,
+ Intent intent);
+ void transform(VideoColorSpace::TriStim* colors, size_t num);
+
+ private:
+ VideoColorSpace from_;
+ VideoColorSpace to_;
+ VideoColorSpace::Matrix4x4 transforms_[3];
+};
+
+} // namespace media
+
+#endif // MEDIA_BASE_COLOR_SPACE_H_

Powered by Google App Engine
This is Rietveld 408576698