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
MythVideoColourSpace Class Reference

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

#include <mythvideocolourspace.h>

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

Classes

struct  ColourPrimaries
 

Public Slots

int ChangePictureAttribute (PictureAttribute Attribute, bool Direction, int Value)
 
void SetPrimariesMode (PrimariesMode Mode)
 

Signals

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

Public Member Functions

 MythVideoColourSpace ()
 
bool UpdateColourSpace (const MythVideoFrame *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

 ~MythVideoColourSpace () 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 }
 

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

MythVideoColourSpace 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 MythVideoColourSpace. 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 20 of file mythvideocolourspace.h.

Constructor & Destructor Documentation

◆ MythVideoColourSpace()

MythVideoColourSpace::MythVideoColourSpace ( )

Definition at line 57 of file mythvideocolourspace.cpp.

◆ ~MythVideoColourSpace()

MythVideoColourSpace::~MythVideoColourSpace ( )
overrideprotected

Definition at line 107 of file mythvideocolourspace.cpp.

Member Function Documentation

◆ ChangePictureAttribute

int MythVideoColourSpace::ChangePictureAttribute ( PictureAttribute  Attribute,
bool  Direction,
int  Value 
)
slot

Definition at line 274 of file mythvideocolourspace.cpp.

Referenced by MythVideoOutputGPU::MythVideoOutputGPU().

◆ SetPrimariesMode

void MythVideoColourSpace::SetPrimariesMode ( PrimariesMode  Mode)
slot

Definition at line 489 of file mythvideocolourspace.cpp.

◆ Updated

void MythVideoColourSpace::Updated ( bool  PrimariesChanged)
signal

◆ PictureAttributeChanged

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

◆ UpdateColourSpace()

bool MythVideoColourSpace::UpdateColourSpace ( const MythVideoFrame 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 329 of file mythvideocolourspace.cpp.

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

◆ SupportedAttributes()

PictureAttributeSupported MythVideoColourSpace::SupportedAttributes ( void  ) const

◆ SetSupportedAttributes()

void MythVideoColourSpace::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 122 of file mythvideocolourspace.cpp.

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

◆ GetPictureAttribute()

int MythVideoColourSpace::GetPictureAttribute ( PictureAttribute  Attribute)

◆ SetAlpha()

void MythVideoColourSpace::SetAlpha ( int  Value)

Definition at line 443 of file mythvideocolourspace.cpp.

◆ GetPrimaryMatrix()

QMatrix4x4 MythVideoColourSpace::GetPrimaryMatrix ( void  )

◆ GetColourMappingDefines()

QStringList MythVideoColourSpace::GetColourMappingDefines ( void  )

Definition at line 449 of file mythvideocolourspace.cpp.

Referenced by MythOpenGLVideo::CreateVideoShader().

◆ GetColourGamma()

float MythVideoColourSpace::GetColourGamma ( void  ) const

Definition at line 474 of file mythvideocolourspace.cpp.

Referenced by MythOpenGLVideo::ColourSpaceUpdate().

◆ GetDisplayGamma()

float MythVideoColourSpace::GetDisplayGamma ( void  ) const

Definition at line 479 of file mythvideocolourspace.cpp.

Referenced by MythOpenGLVideo::ColourSpaceUpdate().

◆ GetPrimariesMode()

PrimariesMode MythVideoColourSpace::GetPrimariesMode ( void  )

Definition at line 484 of file mythvideocolourspace.cpp.

◆ Similar()

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

Definition at line 565 of file mythvideocolourspace.cpp.

Referenced by GetPrimaryConversion().

◆ SetFullRange()

void MythVideoColourSpace::SetFullRange ( bool  FullRange)
private

Definition at line 413 of file mythvideocolourspace.cpp.

Referenced by MythVideoColourSpace().

◆ SetBrightness()

void MythVideoColourSpace::SetBrightness ( int  Value)
private

Definition at line 419 of file mythvideocolourspace.cpp.

Referenced by ChangePictureAttribute(), and MythVideoColourSpace().

◆ SetContrast()

void MythVideoColourSpace::SetContrast ( int  Value)
private

Definition at line 425 of file mythvideocolourspace.cpp.

Referenced by ChangePictureAttribute(), and MythVideoColourSpace().

◆ SetHue()

void MythVideoColourSpace::SetHue ( int  Value)
private

Definition at line 431 of file mythvideocolourspace.cpp.

Referenced by ChangePictureAttribute(), and MythVideoColourSpace().

◆ SetSaturation()

void MythVideoColourSpace::SetSaturation ( int  Value)
private

Definition at line 437 of file mythvideocolourspace.cpp.

Referenced by ChangePictureAttribute(), and MythVideoColourSpace().

◆ SaveValue()

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

Save the PictureAttribute value to the database.

Definition at line 496 of file mythvideocolourspace.cpp.

Referenced by ChangePictureAttribute().

◆ Update()

void MythVideoColourSpace::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 141 of file mythvideocolourspace.cpp.

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

◆ Debug()

void MythVideoColourSpace::Debug ( void  )
private

Definition at line 249 of file mythvideocolourspace.cpp.

Referenced by Update().

◆ GetPrimaryConversion()

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

Definition at line 514 of file mythvideocolourspace.cpp.

Referenced by Update().

◆ GetPrimaries()

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

Definition at line 550 of file mythvideocolourspace.cpp.

Referenced by GetPrimaryConversion().

◆ RGBtoXYZ()

QMatrix4x4 MythVideoColourSpace::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 606 of file mythvideocolourspace.cpp.

Referenced by GetPrimaryConversion().

Friends And Related Function Documentation

◆ MythVideoOutput

friend class MythVideoOutput
friend

Definition at line 24 of file mythvideocolourspace.h.

Member Data Documentation

◆ kBT709

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

Definition at line 53 of file mythvideocolourspace.h.

Referenced by GetPrimaries().

◆ kBT610_525

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

Definition at line 54 of file mythvideocolourspace.h.

Referenced by GetPrimaries().

◆ kBT610_625

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

Definition at line 55 of file mythvideocolourspace.h.

Referenced by GetPrimaries().

◆ kBT2020

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

Definition at line 56 of file mythvideocolourspace.h.

Referenced by GetPrimaries().

◆ m_supportedAttributes

PictureAttributeSupported MythVideoColourSpace::m_supportedAttributes { kPictureAttributeSupported_None }
private

◆ m_dbSettings

QMap<PictureAttribute,int> MythVideoColourSpace::m_dbSettings
private

Definition at line 78 of file mythvideocolourspace.h.

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

◆ m_fullRange

bool MythVideoColourSpace::m_fullRange { true }
private

Definition at line 80 of file mythvideocolourspace.h.

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

◆ m_brightness

float MythVideoColourSpace::m_brightness { 0.0F }
private

Definition at line 81 of file mythvideocolourspace.h.

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

◆ m_contrast

float MythVideoColourSpace::m_contrast { 1.0F }
private

Definition at line 82 of file mythvideocolourspace.h.

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

◆ m_saturation

float MythVideoColourSpace::m_saturation { 1.0F }
private

Definition at line 83 of file mythvideocolourspace.h.

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

◆ m_hue

float MythVideoColourSpace::m_hue { 0.0F }
private

Definition at line 84 of file mythvideocolourspace.h.

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

◆ m_alpha

float MythVideoColourSpace::m_alpha { 1.0F }
private

Definition at line 85 of file mythvideocolourspace.h.

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

◆ m_colourSpace

int MythVideoColourSpace::m_colourSpace { AVCOL_SPC_UNSPECIFIED }
private

Definition at line 86 of file mythvideocolourspace.h.

Referenced by Update(), and UpdateColourSpace().

◆ m_colourSpaceDepth

int MythVideoColourSpace::m_colourSpaceDepth { 8 }
private

Definition at line 87 of file mythvideocolourspace.h.

Referenced by Update(), and UpdateColourSpace().

◆ m_range

int MythVideoColourSpace::m_range { AVCOL_RANGE_MPEG }
private

Definition at line 88 of file mythvideocolourspace.h.

Referenced by Update(), and UpdateColourSpace().

◆ m_updatesDisabled

bool MythVideoColourSpace::m_updatesDisabled { true }
private

Definition at line 89 of file mythvideocolourspace.h.

Referenced by MythVideoColourSpace(), and Update().

◆ m_colourShifted

bool MythVideoColourSpace::m_colourShifted { false }
private

Definition at line 90 of file mythvideocolourspace.h.

Referenced by Update(), and UpdateColourSpace().

◆ m_colourTransfer

int MythVideoColourSpace::m_colourTransfer { AVCOL_TRC_BT709 }
private

Definition at line 91 of file mythvideocolourspace.h.

Referenced by UpdateColourSpace().

◆ m_primariesMode

PrimariesMode MythVideoColourSpace::m_primariesMode { PrimariesRelaxed }
private

◆ m_colourPrimaries

int MythVideoColourSpace::m_colourPrimaries { AVCOL_PRI_BT709 }
private

Definition at line 93 of file mythvideocolourspace.h.

Referenced by Update(), and UpdateColourSpace().

◆ m_displayPrimaries

int MythVideoColourSpace::m_displayPrimaries { AVCOL_PRI_BT709 }
private

Definition at line 94 of file mythvideocolourspace.h.

Referenced by Update(), and UpdateColourSpace().

◆ m_chromaLocation

int MythVideoColourSpace::m_chromaLocation { AVCHROMA_LOC_LEFT }
private

Definition at line 95 of file mythvideocolourspace.h.

Referenced by GetColourMappingDefines(), and UpdateColourSpace().

◆ m_colourGamma

float MythVideoColourSpace::m_colourGamma { 2.2F }
private

Definition at line 96 of file mythvideocolourspace.h.

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

◆ m_displayGamma

float MythVideoColourSpace::m_displayGamma { 2.2F }
private

Definition at line 97 of file mythvideocolourspace.h.

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

◆ m_primaryMatrix

QMatrix4x4 MythVideoColourSpace::m_primaryMatrix { }
private

◆ m_customDisplayGamma

float MythVideoColourSpace::m_customDisplayGamma { 0.0F }
private

Definition at line 99 of file mythvideocolourspace.h.

Referenced by GetPrimaryConversion().

◆ m_customDisplayPrimaries

ColourPrimaries* MythVideoColourSpace::m_customDisplayPrimaries { nullptr }
private

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