summaryrefslogtreecommitdiff
path: root/chromium/media/base/video_color_space.h
blob: c61077554672c9d7c377457baa804b9c5b3eb381 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright 2017 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_VIDEO_COLOR_SPACE_H_
#define MEDIA_BASE_VIDEO_COLOR_SPACE_H_

#include "media/base/media_export.h"
#include "ui/gfx/color_space.h"

namespace media {

// Described in ISO 23001-8:2016
class MEDIA_EXPORT VideoColorSpace {
 public:
  // These values are persisted to logs. Entries should not be renumbered or
  // removed and numeric values should never be reused.
  // Please keep in sync with "VideoColorSpace.PrimaryID"
  // in src/tools/metrics/histograms/enums.xml.
  // Table 2
  enum class PrimaryID : uint8_t {
    INVALID = 0,
    BT709 = 1,
    UNSPECIFIED = 2,
    BT470M = 4,
    BT470BG = 5,
    SMPTE170M = 6,
    SMPTE240M = 7,
    FILM = 8,
    BT2020 = 9,
    SMPTEST428_1 = 10,
    SMPTEST431_2 = 11,
    SMPTEST432_1 = 12,
    EBU_3213_E = 22,
    kMaxValue = EBU_3213_E,
  };

  // These values are persisted to logs. Entries should not be renumbered or
  // removed and numeric values should never be reused.
  // Please keep in sync with "VideoColorSpace.TransferID"
  // in src/tools/metrics/histograms/enums.xml.
  // Table 3
  enum class TransferID : uint8_t {
    INVALID = 0,
    BT709 = 1,
    UNSPECIFIED = 2,
    GAMMA22 = 4,
    GAMMA28 = 5,
    SMPTE170M = 6,
    SMPTE240M = 7,
    LINEAR = 8,
    LOG = 9,
    LOG_SQRT = 10,
    IEC61966_2_4 = 11,
    BT1361_ECG = 12,
    IEC61966_2_1 = 13,
    BT2020_10 = 14,
    BT2020_12 = 15,
    SMPTEST2084 = 16,
    SMPTEST428_1 = 17,

    // Not yet standardized
    ARIB_STD_B67 = 18,  // AKA hybrid-log gamma, HLG.

    kMaxValue = ARIB_STD_B67,
  };

  // Table 4
  enum class MatrixID : uint8_t {
    RGB = 0,
    BT709 = 1,
    UNSPECIFIED = 2,
    FCC = 4,
    BT470BG = 5,
    SMPTE170M = 6,
    SMPTE240M = 7,
    YCOCG = 8,
    BT2020_NCL = 9,
    BT2020_CL = 10,
    YDZDX = 11,
    INVALID = 255,
    kMaxValue = INVALID,
  };

  VideoColorSpace();
  VideoColorSpace(int primaries,
                  int transfer,
                  int matrix,
                  gfx::ColorSpace::RangeID range);
  VideoColorSpace(PrimaryID primaries,
                  TransferID transfer,
                  MatrixID matrix,
                  gfx::ColorSpace::RangeID range);

  bool operator==(const VideoColorSpace& other) const;
  bool operator!=(const VideoColorSpace& other) const;
  // Returns true if any of the fields have a value other
  // than INVALID or UNSPECIFIED.
  bool IsSpecified() const;

  // These will return INVALID if the number you give it
  // is not a valid enum value.
  static PrimaryID GetPrimaryID(int primary);
  static TransferID GetTransferID(int transfer);
  static MatrixID GetMatrixID(int matrix);

  static VideoColorSpace REC709();
  static VideoColorSpace REC601();
  static VideoColorSpace JPEG();

  gfx::ColorSpace ToGfxColorSpace() const;

  static VideoColorSpace FromGfxColorSpace(const gfx::ColorSpace& color_space);

  // Note, these are public variables.
  PrimaryID primaries = PrimaryID::INVALID;
  TransferID transfer = TransferID::INVALID;
  MatrixID matrix = MatrixID::INVALID;
  gfx::ColorSpace::RangeID range = gfx::ColorSpace::RangeID::INVALID;
};

}  // namespace media

#endif  // MEDIA_BASE_VIDEO_COLOR_SPACE_H_