MythTV  master
Classes | Public Slots | Signals | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
VideoColourSpace Class Reference

VideoColourSpace contains a QMatrix4x4 that can convert YCbCr data to RGB. More...

#include <videocolourspace.h>

Inheritance diagram for VideoColourSpace:
Inheritance graph
[legend]
Collaboration diagram for VideoColourSpace:
Collaboration graph
[legend]

Classes

struct  ColourPrimaries
 

Public Slots

int SetPictureAttribute (PictureAttribute Attribute, int Value)
 Set the Value for the given PictureAttribute. More...
 
void SetPrimariesMode (PrimariesMode Mode)
 

Signals

void Updated (bool PrimariesChanged)
 
void PictureAttributeChanged (PictureAttribute Attribute, int Value)
 

Public Member Functions

 VideoColourSpace (VideoColourSpace *Parent=nullptr)
 
bool UpdateColourSpace (const VideoFrame *Frame)
 Set the current colourspace to use. More...
 
PictureAttributeSupported SupportedAttributes (void) const
 
void SetSupportedAttributes (PictureAttributeSupported Supported)
 Enable the given set of picture attributes. More...
 
int GetPictureAttribute (PictureAttribute Attribute)
 
void SetAlpha (int Value)
 
QMatrix4x4 GetPrimaryMatrix (void)
 
QStringList GetColourMappingDefines (void)
 
float GetColourGamma (void) const
 
float GetDisplayGamma (void) const
 
PrimariesMode GetPrimariesMode (void)
 
- Public Member Functions inherited from ReferenceCounter
 ReferenceCounter (const QString &debugName, bool logDebug=true)
 Creates reference counter with an initial value of 1. More...
 
virtual int IncrRef (void)
 Increments reference count. More...
 
virtual int DecrRef (void)
 Decrements reference count and deletes on 0. More...
 

Static Public Member Functions

static bool Similar (const ColourPrimaries &First, const ColourPrimaries &Second, float Fuzz)
 
- Static Public Member Functions inherited from ReferenceCounter
static void PrintDebug (void)
 Print out any leaks if that level of debugging is enabled. More...
 

Static Public Attributes

static const ColourPrimaries kBT709
 
static const ColourPrimaries kBT610_525
 
static const ColourPrimaries kBT610_625
 
static const ColourPrimaries kBT2020
 

Protected Member Functions

 ~VideoColourSpace () override
 
- Protected Member Functions inherited from ReferenceCounter
virtual ~ReferenceCounter (void)
 Called on destruction, will warn if object deleted with references in place. More...
 

Private Member Functions

void SetFullRange (bool FullRange)
 
void SetBrightness (int Value)
 
void SetContrast (int Value)
 
void SetHue (int Value)
 
void SetSaturation (int Value)
 
void SaveValue (PictureAttribute Attribute, int Value)
 Save the PictureAttribute value to the database. More...
 
void Update (void)
 Update the matrix for the current settings and colourspace. More...
 
void Debug (void)
 
QMatrix4x4 GetPrimaryConversion (int Source, int Dest)
 

Static Private Member Functions

static ColourPrimaries GetPrimaries (int Primary, float &Gamma)
 
static QMatrix4x4 RGBtoXYZ (ColourPrimaries Primaries)
 Create a conversion matrix for RGB to XYZ with the given primaries. More...
 

Private Attributes

PictureAttributeSupported m_supportedAttributes {kPictureAttributeSupported_None}
 
QMap< PictureAttribute, int > m_dbSettings
 
bool m_fullRange { true }
 
float m_brightness { 0.0F }
 
float m_contrast { 1.0F }
 
float m_saturation { 1.0F }
 
float m_hue { 0.0F }
 
float m_alpha { 1.0F }
 
int m_colourSpace { AVCOL_SPC_UNSPECIFIED }
 
int m_colourSpaceDepth { 8 }
 
int m_range { AVCOL_RANGE_MPEG }
 
bool m_updatesDisabled { true }
 
bool m_colourShifted { false }
 
int m_colourTransfer { AVCOL_TRC_BT709 }
 
PrimariesMode m_primariesMode { PrimariesRelaxed }
 
int m_colourPrimaries { AVCOL_PRI_BT709 }
 
int m_displayPrimaries { AVCOL_PRI_BT709 }
 
int m_chromaLocation { AVCHROMA_LOC_LEFT }
 
float m_colourGamma { 2.2F }
 
float m_displayGamma { 2.2F }
 
QMatrix4x4 m_primaryMatrix { }
 
float m_customDisplayGamma { 0.0F }
 
ColourPrimariesm_customDisplayPrimaries { nullptr }
 
VideoColourSpacem_parent { nullptr }
 

Friends

class MythVideoOutput
 

Additional Inherited Members

- Protected Attributes inherited from ReferenceCounter
bool m_logDebug
 This is used to suppress creating LoggingItem classes for LoggingItem reference count changes. More...
 
QAtomicInt m_referenceCount {1}
 

Detailed Description

VideoColourSpace contains a QMatrix4x4 that can convert YCbCr data to RGB.

A 4x4 matrix is created that is customised for the source colourspace and user defined adjustments for brightness, contrast, hue, saturation (colour) and 'levels'.

An alpha value is also added for rendering purposes. This assumes the raw data is in the form YCbCrA.

Levels are expanded to the full RGB colourspace range by default but enabling studio levels will ensure there is no adjustment. In both cases it is assumed the display device is setup appropriately.

Each instance may have a parent VideoColourSpace. This configuration is used for Picture In Picture support. The master/parent object will receive requests to update the various attributes and will signal changes to the children. Each instance manages its own underlying video colourspace for the stream it is playing. In this way, picture adjustments affect each player in the same way whilst each underlying stream dictates the video colourspace to use. 'Child' instances do not interrogate or update the database settings.

Note
This class is not complete and will have limitations for certain source material and displays. It currently assumes an 8bit display (and GPU framebuffer) with a 'traditional' gamma of 2.2 (most colourspace standards have a reference gamma of 2.2). Hence colour rendition may not be optimal for material that specificies a colourspace that has a different reference gamma (e.g. Rec 2020) or when using an HDR display. Futher work is required.

Definition at line 17 of file videocolourspace.h.

Constructor & Destructor Documentation

◆ VideoColourSpace()

VideoColourSpace::VideoColourSpace ( VideoColourSpace Parent = nullptr)
explicit

Definition at line 57 of file videocolourspace.cpp.

◆ ~VideoColourSpace()

VideoColourSpace::~VideoColourSpace ( )
overrideprotected

Definition at line 123 of file videocolourspace.cpp.

Member Function Documentation

◆ UpdateColourSpace()

bool VideoColourSpace::UpdateColourSpace ( const VideoFrame Frame)

Set the current colourspace to use.

We rely on FFmpeg to detect and report the correct colourspace. In the event that no colourspace is found we use sensible defaults for standard and high definition content (BT470BG/BT601 and BT709 respectively).

Definition at line 332 of file videocolourspace.cpp.

Referenced by MythDRMPRIMEInterop::Acquire(), MythMediaCodecInterop::Acquire(), MythMMALInterop::Acquire(), MythNVDECInterop::Acquire(), MythVAAPIInteropDRM::Acquire(), MythVDPAUInterop::Acquire(), MythOpenGLVideo::ProcessFrame(), and MythVTBInterop::Verify().

◆ SupportedAttributes()

PictureAttributeSupported VideoColourSpace::SupportedAttributes ( void  ) const

◆ SetSupportedAttributes()

void VideoColourSpace::SetSupportedAttributes ( PictureAttributeSupported  Supported)

Enable the given set of picture attributes.

This is determined by the video rendering classes and is usually dependant upon the rendering method in use and type of video frame (e.g. hardware decoded or not).

Definition at line 140 of file videocolourspace.cpp.

Referenced by MythDRMPRIMEInterop::Acquire(), MythMediaCodecInterop::Acquire(), MythMMALInterop::Acquire(), MythNVDECInterop::Acquire(), MythVAAPIInteropDRM::Acquire(), MythVDPAUInterop::Acquire(), MythVAAPIInteropGLX::InitPictureAttributes(), MythVideoOutputOpenGL::InitPictureAttributes(), and MythVTBInterop::Verify().

◆ GetPictureAttribute()

int VideoColourSpace::GetPictureAttribute ( PictureAttribute  Attribute)

◆ SetAlpha()

void VideoColourSpace::SetAlpha ( int  Value)

Definition at line 446 of file videocolourspace.cpp.

◆ GetPrimaryMatrix()

QMatrix4x4 VideoColourSpace::GetPrimaryMatrix ( void  )

◆ GetColourMappingDefines()

QStringList VideoColourSpace::GetColourMappingDefines ( void  )

Definition at line 452 of file videocolourspace.cpp.

Referenced by MythOpenGLVideo::CreateVideoShader().

◆ GetColourGamma()

float VideoColourSpace::GetColourGamma ( void  ) const

Definition at line 477 of file videocolourspace.cpp.

Referenced by MythOpenGLVideo::UpdateColourSpace().

◆ GetDisplayGamma()

float VideoColourSpace::GetDisplayGamma ( void  ) const

Definition at line 482 of file videocolourspace.cpp.

Referenced by MythOpenGLVideo::UpdateColourSpace().

◆ GetPrimariesMode()

PrimariesMode VideoColourSpace::GetPrimariesMode ( void  )

Definition at line 487 of file videocolourspace.cpp.

Referenced by VideoColourSpace().

◆ Similar()

bool VideoColourSpace::Similar ( const ColourPrimaries First,
const ColourPrimaries Second,
float  Fuzz 
)
static

Definition at line 572 of file videocolourspace.cpp.

Referenced by GetPrimaryConversion().

◆ SetPictureAttribute

int VideoColourSpace::SetPictureAttribute ( PictureAttribute  Attribute,
int  Value 
)
slot

Set the Value for the given PictureAttribute.

Definition at line 154 of file videocolourspace.cpp.

Referenced by MythVideoOutput::SetPictureAttribute(), and VideoColourSpace().

◆ SetPrimariesMode

void VideoColourSpace::SetPrimariesMode ( PrimariesMode  Mode)
slot

Definition at line 492 of file videocolourspace.cpp.

◆ Updated

void VideoColourSpace::Updated ( bool  PrimariesChanged)
signal

◆ PictureAttributeChanged

void VideoColourSpace::PictureAttributeChanged ( PictureAttribute  Attribute,
int  Value 
)
signal

◆ SetFullRange()

void VideoColourSpace::SetFullRange ( bool  FullRange)
private

Definition at line 416 of file videocolourspace.cpp.

Referenced by VideoColourSpace().

◆ SetBrightness()

void VideoColourSpace::SetBrightness ( int  Value)
private

Definition at line 422 of file videocolourspace.cpp.

Referenced by SetPictureAttribute(), and VideoColourSpace().

◆ SetContrast()

void VideoColourSpace::SetContrast ( int  Value)
private

Definition at line 428 of file videocolourspace.cpp.

Referenced by SetPictureAttribute(), and VideoColourSpace().

◆ SetHue()

void VideoColourSpace::SetHue ( int  Value)
private

Definition at line 434 of file videocolourspace.cpp.

Referenced by SetPictureAttribute(), and VideoColourSpace().

◆ SetSaturation()

void VideoColourSpace::SetSaturation ( int  Value)
private

Definition at line 440 of file videocolourspace.cpp.

Referenced by SetPictureAttribute(), and VideoColourSpace().

◆ SaveValue()

void VideoColourSpace::SaveValue ( PictureAttribute  Attribute,
int  Value 
)
private

Save the PictureAttribute value to the database.

Definition at line 499 of file videocolourspace.cpp.

Referenced by SetPictureAttribute().

◆ Update()

void VideoColourSpace::Update ( void  )
private

Update the matrix for the current settings and colourspace.

The matrix is built from first principles to help with maintainability. This an expensive task but it is only recalculated when a change is detected or notified.

Definition at line 193 of file videocolourspace.cpp.

Referenced by SetAlpha(), SetBrightness(), SetContrast(), SetFullRange(), SetHue(), SetPrimariesMode(), SetSaturation(), UpdateColourSpace(), and VideoColourSpace().

◆ Debug()

void VideoColourSpace::Debug ( void  )
private

Definition at line 301 of file videocolourspace.cpp.

Referenced by Update().

◆ GetPrimaryConversion()

QMatrix4x4 VideoColourSpace::GetPrimaryConversion ( int  Source,
int  Dest 
)
private

Definition at line 521 of file videocolourspace.cpp.

Referenced by Update().

◆ GetPrimaries()

VideoColourSpace::ColourPrimaries VideoColourSpace::GetPrimaries ( int  Primary,
float &  Gamma 
)
staticprivate

Definition at line 557 of file videocolourspace.cpp.

Referenced by GetPrimaryConversion().

◆ RGBtoXYZ()

QMatrix4x4 VideoColourSpace::RGBtoXYZ ( ColourPrimaries  Primaries)
staticprivate

Create a conversion matrix for RGB to XYZ with the given primaries.

This is a joyous mindbender. There are various explanations on the interweb but this is based on the Kodi implementation - with due credit to Team Kodi.

Note
We use QMatrix4x4 because QMatrix3x3 has no inverted method.

Definition at line 613 of file videocolourspace.cpp.

Referenced by GetPrimaryConversion().

Friends And Related Function Documentation

◆ MythVideoOutput

friend class MythVideoOutput
friend

Definition at line 21 of file videocolourspace.h.

Member Data Documentation

◆ kBT709

const VideoColourSpace::ColourPrimaries VideoColourSpace::kBT709
static
Initial value:
=
{{{0.640F, 0.330F}, {0.300F, 0.600F}, {0.150F, 0.060F}}, {0.3127F, 0.3290F}}

Definition at line 43 of file videocolourspace.h.

Referenced by GetPrimaries().

◆ kBT610_525

const VideoColourSpace::ColourPrimaries VideoColourSpace::kBT610_525
static
Initial value:
=
{{{0.630F, 0.340F}, {0.310F, 0.595F}, {0.155F, 0.070F}}, {0.3127F, 0.3290F}}

Definition at line 44 of file videocolourspace.h.

Referenced by GetPrimaries().

◆ kBT610_625

const VideoColourSpace::ColourPrimaries VideoColourSpace::kBT610_625
static
Initial value:
=
{{{0.640F, 0.330F}, {0.290F, 0.600F}, {0.150F, 0.060F}}, {0.3127F, 0.3290F}}

Definition at line 45 of file videocolourspace.h.

Referenced by GetPrimaries().

◆ kBT2020

const VideoColourSpace::ColourPrimaries VideoColourSpace::kBT2020
static
Initial value:
=
{{{0.708F, 0.292F}, {0.170F, 0.797F}, {0.131F, 0.046F}}, {0.3127F, 0.3290F}}

Definition at line 46 of file videocolourspace.h.

Referenced by GetPrimaries().

◆ m_supportedAttributes

PictureAttributeSupported VideoColourSpace::m_supportedAttributes {kPictureAttributeSupported_None}
private

◆ m_dbSettings

QMap<PictureAttribute,int> VideoColourSpace::m_dbSettings
private

Definition at line 76 of file videocolourspace.h.

Referenced by GetPictureAttribute(), SaveValue(), and VideoColourSpace().

◆ m_fullRange

bool VideoColourSpace::m_fullRange { true }
private

Definition at line 78 of file videocolourspace.h.

Referenced by Debug(), SetFullRange(), Update(), and UpdateColourSpace().

◆ m_brightness

float VideoColourSpace::m_brightness { 0.0F }
private

Definition at line 79 of file videocolourspace.h.

Referenced by Debug(), SetBrightness(), and Update().

◆ m_contrast

float VideoColourSpace::m_contrast { 1.0F }
private

Definition at line 80 of file videocolourspace.h.

Referenced by Debug(), SetContrast(), and Update().

◆ m_saturation

float VideoColourSpace::m_saturation { 1.0F }
private

Definition at line 81 of file videocolourspace.h.

Referenced by Debug(), SetSaturation(), and Update().

◆ m_hue

float VideoColourSpace::m_hue { 0.0F }
private

Definition at line 82 of file videocolourspace.h.

Referenced by Debug(), SetHue(), and Update().

◆ m_alpha

float VideoColourSpace::m_alpha { 1.0F }
private

Definition at line 83 of file videocolourspace.h.

Referenced by Debug(), SetAlpha(), and Update().

◆ m_colourSpace

int VideoColourSpace::m_colourSpace { AVCOL_SPC_UNSPECIFIED }
private

Definition at line 84 of file videocolourspace.h.

Referenced by Update(), and UpdateColourSpace().

◆ m_colourSpaceDepth

int VideoColourSpace::m_colourSpaceDepth { 8 }
private

Definition at line 85 of file videocolourspace.h.

Referenced by Update(), and UpdateColourSpace().

◆ m_range

int VideoColourSpace::m_range { AVCOL_RANGE_MPEG }
private

Definition at line 86 of file videocolourspace.h.

Referenced by Update(), and UpdateColourSpace().

◆ m_updatesDisabled

bool VideoColourSpace::m_updatesDisabled { true }
private

Definition at line 87 of file videocolourspace.h.

Referenced by Update(), and VideoColourSpace().

◆ m_colourShifted

bool VideoColourSpace::m_colourShifted { false }
private

Definition at line 88 of file videocolourspace.h.

Referenced by Update(), and UpdateColourSpace().

◆ m_colourTransfer

int VideoColourSpace::m_colourTransfer { AVCOL_TRC_BT709 }
private

Definition at line 89 of file videocolourspace.h.

Referenced by UpdateColourSpace().

◆ m_primariesMode

PrimariesMode VideoColourSpace::m_primariesMode { PrimariesRelaxed }
private

◆ m_colourPrimaries

int VideoColourSpace::m_colourPrimaries { AVCOL_PRI_BT709 }
private

Definition at line 91 of file videocolourspace.h.

Referenced by Update(), and UpdateColourSpace().

◆ m_displayPrimaries

int VideoColourSpace::m_displayPrimaries { AVCOL_PRI_BT709 }
private

Definition at line 92 of file videocolourspace.h.

Referenced by Update(), and UpdateColourSpace().

◆ m_chromaLocation

int VideoColourSpace::m_chromaLocation { AVCHROMA_LOC_LEFT }
private

Definition at line 93 of file videocolourspace.h.

Referenced by GetColourMappingDefines(), and UpdateColourSpace().

◆ m_colourGamma

float VideoColourSpace::m_colourGamma { 2.2F }
private

Definition at line 94 of file videocolourspace.h.

Referenced by GetColourGamma(), GetPrimaryConversion(), and Update().

◆ m_displayGamma

float VideoColourSpace::m_displayGamma { 2.2F }
private

Definition at line 95 of file videocolourspace.h.

Referenced by GetDisplayGamma(), GetPrimaryConversion(), and Update().

◆ m_primaryMatrix

QMatrix4x4 VideoColourSpace::m_primaryMatrix { }
private

◆ m_customDisplayGamma

float VideoColourSpace::m_customDisplayGamma { 0.0F }
private

Definition at line 97 of file videocolourspace.h.

Referenced by GetPrimaryConversion().

◆ m_customDisplayPrimaries

ColourPrimaries* VideoColourSpace::m_customDisplayPrimaries { nullptr }
private

Definition at line 98 of file videocolourspace.h.

Referenced by GetPrimaryConversion(), UpdateColourSpace(), and ~VideoColourSpace().

◆ m_parent

VideoColourSpace* VideoColourSpace::m_parent { nullptr }
private

Definition at line 99 of file videocolourspace.h.

Referenced by SaveValue(), VideoColourSpace(), and ~VideoColourSpace().


The documentation for this class was generated from the following files: