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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_BASE_COLOR_SPACE_H_
6 #define MEDIA_BASE_COLOR_SPACE_H_
7
8 #include <cstdint>
9 #include <vector>
10
11 #include "base/memory/ref_counted.h"
12 #include "media/base/media_export.h"
13 #include "media/base/video_types.h"
14
15 namespace media {
16
17 class VideoFrame;
18
19 class MEDIA_EXPORT VideoColorSpace {
20 public:
21 enum PrimaryID : int16_t {
22 // The first 0-255 values should match the H264 specification.
23 PRI_RESERVED0 = 0,
24 PRI_BT709 = 1,
25 PRI_UNSPECIFIED = 2,
26 PRI_RESERVED = 3,
27 PRI_BT470M = 4,
28 PRI_BT470BG = 5,
29 PRI_SMPTE170M = 6,
30 PRI_SMPTE240M = 7,
31 PRI_FILM = 8,
32 PRI_BT2020 = 9,
33 PRI_SMPTEST428_1 = 10,
34 PRI_SMPTEST431_2 = 11,
35 PRI_SMPTEST432_1 = 12,
36
37 // Chrome-specific values start at 1000.
38 PRI_XYZ_D50 = 1000,
39 PRI_LAST = PRI_XYZ_D50
40 };
41
42 enum TransferID : int16_t {
43 // The first 0-255 values should match the H264 specification.
44 TRC_RESERVED0 = 0,
45 TRC_BT709 = 1,
46 TRC_UNSPECIFIED = 2,
47 TRC_RESERVED = 3,
48 TRC_GAMMA22 = 4,
49 TRC_GAMMA28 = 5,
50 TRC_SMPTE170M = 6,
51 TRC_SMPTE240M = 7,
52 TRC_LINEAR = 8,
53 TRC_LOG = 9,
54 TRC_LOG_SQRT = 10,
55 TRC_IEC61966_2_4 = 11,
56 TRC_BT1361_ECG = 12,
57 TRC_IEC61966_2_1 = 13,
58 TRC_BT2020_10 = 14,
59 TRC_BT2020_12 = 15,
60 TRC_SMPTEST2084 = 16,
61 TRC_SMPTEST428_1 = 17,
62
63 // Chrome-specific values start at 1000.
64 TRC_GAMMA24 = 1000,
65
66 TRC_LAST = TRC_GAMMA24
67 };
68
69 enum MatrixID : int16_t {
70 // The first 0-255 values should match the H264 specification.
71 SPC_RGB = 0,
72 SPC_BT709 = 1,
73 SPC_UNSPECIFIED = 2,
74 SPC_RESERVED = 3,
75 SPC_FCC = 4,
76 SPC_BT470BG = 5,
77 SPC_SMPTE170M = 6,
78 SPC_SMPTE240M = 7,
79 SPC_YCOCG = 8,
80 SPC_BT2020_NCL = 9,
81 SPC_BT2020_CL = 10,
82 SPC_YDZDX = 11,
83
84 // Chrome-specific values start at 1000
85 SPC_LAST = SPC_BT2020_CL
86 };
87
88 typedef float Quad[4];
89 struct Matrix4x4 {
90 Quad rows[4];
91 };
92 // Tristimulus value, RGB, XYZ or YUV
93 struct TriStim {
94 TriStim() {
95 values[0] = 0.0f;
96 values[1] = 0.0f;
97 values[2] = 0.0f;
98 }
99 TriStim(float a, float b, float c) {
100 values[0] = a;
101 values[1] = b;
102 values[2] = c;
103 }
104 float values[3];
105 };
106
107 // Used to represent the XY coordinate of a primary.
108 typedef std::pair<float, float> XY;
109
110 VideoColorSpace();
111 VideoColorSpace(PrimaryID primaries,
112 TransferID transfer,
113 MatrixID matrix,
114 bool full_range);
115
116 bool operator==(const VideoColorSpace& other) const;
117 bool operator<(const VideoColorSpace& other) const;
118
119 // Get a color space from a video frame.
120 explicit VideoColorSpace(const scoped_refptr<VideoFrame>& frame);
121 explicit VideoColorSpace(ColorSpace color_space);
122 void SetVideoFrameColorSpace(const scoped_refptr<VideoFrame>& frame);
123
124 // Return the XYZ (D50) color space.
125 static VideoColorSpace XYZ();
126 // Return the SRGB color space.
127 static VideoColorSpace SRGB();
128
129 static std::vector<XY> GetPrimaries(PrimaryID id);
130 std::vector<XY> GetPrimaries() const { return GetPrimaries(primaries); }
131
132 // Get a matrix for convertnig from the given primaries to XYZD50.
133 static Matrix4x4 GetPrimaryMatrix(const std::vector<XY>& primaries);
134 static Matrix4x4 GetPrimaryMatrix(PrimaryID id) {
135 return GetPrimaryMatrix(GetPrimaries(id));
136 }
137 Matrix4x4 GetPrimaryMatrix() const {
138 return GetPrimaryMatrix(GetPrimaries());
139 }
140
141 // Undo gamma correction.
142 static float toLinear(TransferID id, float f);
143 float toLinear(float f) const { return toLinear(transfer, f); }
144
145 // Do gamma correction.
146 static float fromLinear(TransferID id, float f);
147 float fromLinear(float f) const { return fromLinear(transfer, f); }
148
149 // Get the matrix for YUV->primaries (rgb) conversion.
150 static Matrix4x4 GetTransferMatrix(MatrixID id);
151 Matrix4x4 GetTransferMatrix() const { return GetTransferMatrix(matrix); }
152
153 // Get the values needed to correct the range.
154 // Returns false if offset == 0.0 && multiplier == 1.0.
155 bool GetRangeAdjust(TriStim* offset, TriStim* multiplier) const;
156 Matrix4x4 GetRangeAdjustMatrix() const;
157
158 static Matrix4x4 Multiply(const Matrix4x4& a, const Matrix4x4& b);
159 static TriStim Multiply(const Matrix4x4& a, const TriStim& b);
160 static Matrix4x4 Invert(Matrix4x4 a);
161
162 PrimaryID primaries;
163 TransferID transfer;
164 MatrixID matrix;
165 bool full_range;
166 };
167
168 class MEDIA_EXPORT ColorTransform {
169 public:
170 enum Intent {
171 INTENT_ABSOLUTE,
172 INTENT_PERCEIVED,
173 };
174
175 ColorTransform(const VideoColorSpace& from,
176 const VideoColorSpace& to,
177 Intent intent);
178 void transform(VideoColorSpace::TriStim* colors, size_t num);
179
180 private:
181 VideoColorSpace from_;
182 VideoColorSpace to_;
183 VideoColorSpace::Matrix4x4 transforms_[3];
184 };
185
186 } // namespace media
187
188 #endif // MEDIA_BASE_COLOR_SPACE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698