11#include "libavutil/pixfmt.h"
12#include "libavutil/pixdesc.h"
18#define LOC QString("ColourSpace: ")
42 m_updatesDisabled(
false)
123 return found->second;
140 std::vector<float> rgb;
143 case AVCOL_SPC_RGB: rgb = { 1.0000F, 1.0000F, 1.0000F };
break;
144 case AVCOL_SPC_BT709: rgb = { 0.2126F, 0.7152F, 0.0722F };
break;
145 case AVCOL_SPC_FCC: rgb = { 0.30F, 0.59F, 0.11F };
break;
146 case AVCOL_SPC_BT470BG:
147 case AVCOL_SPC_SMPTE170M: rgb = { 0.299F, 0.587F, 0.114F };
break;
148 case AVCOL_SPC_SMPTE240M: rgb = { 0.212F, 0.701F, 0.087F };
break;
149 case AVCOL_SPC_YCOCG: rgb = { 0.25F, 0.5F, 0.25F };
break;
150 case AVCOL_SPC_BT2020_CL:
151 case AVCOL_SPC_BT2020_NCL: rgb = { 0.2627F, 0.6780F, 0.0593F };
break;
152 case AVCOL_SPC_UNSPECIFIED:
153 case AVCOL_SPC_RESERVED:
154 case AVCOL_SPC_SMPTE2085:
155 case AVCOL_SPC_CHROMA_DERIVED_CL:
156 case AVCOL_SPC_CHROMA_DERIVED_NCL:
157 case AVCOL_SPC_ICTCP:
158 default: rgb = { 0.2126F, 0.7152F, 0.0722F };
161 float bs = rgb[2] == 1.0F ? 0.0F : 0.5F / (rgb[2] - 1.0F);
162 float rs = rgb[0] == 1.0F ? 0.0F : 0.5F / (rgb[0] - 1.0F);
163 QMatrix4x4
rgb2yuv( rgb[0], rgb[1], rgb[2], 0.0F,
164 bs * rgb[0], bs * rgb[1], 0.5F, 0.0F,
165 0.5F, rs * rgb[1], rs * rgb[2], 0.0F,
171 rgb2yuv = QMatrix4x4(0.25F, 0.50F, 0.25F, 0.0F,
172 -0.25F, 0.50F, -0.25F, 0.0F,
173 0.50F, 0.00F, -0.50F, 0.0F,
183 yuv2rgb.translate(0.0F, -0.5F, -0.5F);
196 bool noop = !expand && !contract;
201 float luma_scale {NAN};
202 float chroma_scale {NAN};
212 luma_scale = depth / (lumapeak - blacklevel);
213 chroma_scale = depth / (chromapeak - blacklevel);
214 offset = -blacklevel / depth;
216 luma_scale = (lumapeak - blacklevel) / depth;
217 chroma_scale = (chromapeak - blacklevel) / depth;
218 offset = blacklevel / depth;
225 scale(luma_scale, chroma_scale, chroma_scale);
226 translate(offset, offset, offset);
242 static_cast<QMatrix4x4*
>(
this)->
operator = (this->transposed());
250 bool primchanged = !qFuzzyCompare(tmpsrcgamma,
m_colourGamma) ||
261 LOG(VB_PLAYBACK, LOG_DEBUG,
LOC +
262 QString(
"Brightness: %1 Contrast: %2 Saturation: %3 Hue: %4 Alpha: %5 Range: %6 Primary: %7")
263 .arg(
static_cast<qreal
>(
m_brightness), 2,
'f', 4, QLatin1Char(
'0'))
264 .arg(
static_cast<qreal
>(
m_contrast) , 2,
'f', 4, QLatin1Char(
'0'))
265 .arg(
static_cast<qreal
>(
m_saturation), 2,
'f', 4, QLatin1Char(
'0'))
266 .arg(
static_cast<qreal
>(
m_hue) , 2,
'f', 4, QLatin1Char(
'0'))
267 .arg(
static_cast<qreal
>(
m_alpha) , 2,
'f', 4, QLatin1Char(
'0'))
274 QDebug
debug(&stream);
278 LOG(VB_PLAYBACK, LOG_DEBUG, stream);
291 int newvalue = Value;
294 newvalue =
current + ((Direction) ? +1 : -1);
296 newvalue = newvalue % 100;
342 int csp =
Frame->m_colorspace;
343 int primary =
Frame->m_colorprimaries;
344 int transfer =
Frame->m_colortransfer;
345 int chroma =
Frame->m_chromalocation;
347 int rawchroma = chroma;
358 csp = AVCOL_SPC_UNSPECIFIED;
360 int range =
Frame->m_colorrange;
361 if (range == AVCOL_RANGE_UNSPECIFIED)
362 range = AVCOL_RANGE_MPEG;
364 if (csp == AVCOL_SPC_UNSPECIFIED)
365 csp = (
Frame->m_width < 1280) ? AVCOL_SPC_BT470BG : AVCOL_SPC_BT709;
366 if (primary == AVCOL_PRI_UNSPECIFIED)
367 primary = (
Frame->m_width < 1280) ? AVCOL_PRI_BT470BG : AVCOL_PRI_BT709;
368 if (transfer == AVCOL_TRC_UNSPECIFIED)
369 transfer = (
Frame->m_width < 1280) ? AVCOL_TRC_GAMMA28 : AVCOL_TRC_BT709;
370 if (chroma == AVCHROMA_LOC_UNSPECIFIED)
371 chroma = AVCHROMA_LOC_LEFT;
389 LOG(VB_GENERAL, LOG_WARNING,
LOC + QString(
"Forcing inconsistent colourspace - frame format %1")
392 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"Input : %1(%2) Depth:%3 %4Range:%5")
393 .arg(av_color_space_name(
static_cast<AVColorSpace
>(
m_colourSpace)),
397 (AVCOL_RANGE_JPEG ==
m_range) ?
"Full" :
"Limited"));
398 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"Input : Primaries:%1 Transfer: %2")
400 av_color_transfer_name(
static_cast<AVColorTransferCharacteristic
>(
m_colourTransfer))));
401 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"Output: Range:%1 Primaries: %2")
405 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"Chroma location: %1 %2")
406 .arg(av_chroma_location_name(
static_cast<AVChromaLocation
>(
m_chromaLocation)),
413 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"Enabled colourspace primaries conversion from %1 to %2")
442 m_hue = Value * -3.6F;
468 result <<
"CHROMALEFT";
472 result <<
"COLOURMAPPING";
517 dbName =
"PlaybackBrightness";
519 dbName =
"PlaybackContrast";
521 dbName =
"PlaybackColour";
523 dbName =
"PlaybackHue";
525 if (!dbName.isEmpty())
540 auto source =
static_cast<AVColorPrimaries
>(
Source);
541 auto dest =
static_cast<AVColorPrimaries
>(Dest);
545 if (!custom && (source ==
dest))
570 auto primary =
static_cast<AVColorPrimaries
>(Primary);
574 case AVCOL_PRI_BT470BG:
576 case AVCOL_PRI_SMPTE170M:
static VideoFrameType PixelFormatToFrameType(AVPixelFormat Fmt)
static bool Alike(const MythColourSpace &First, const MythColourSpace &Second, float Fuzz)
static QMatrix4x4 RGBtoXYZ(const MythColourSpace &Primaries)
Create a conversion matrix for RGB to XYZ with the given primaries.
static MythColourSpace s_BT610_625
static MythColourSpace s_BT709
static MythColourSpace s_BT610_525
static MythColourSpace s_BT2020
void SaveSetting(const QString &key, int newValue)
QString GetSetting(const QString &key, const QString &defaultval="")
int GetNumSetting(const QString &key, int defaultval=0)
bool GetBoolSetting(const QString &key, bool defaultval=false)
PictureAttributeSupported m_supportedAttributes
float GetDisplayGamma(void) const
void Update(void)
Update the matrix for the current settings and colourspace.
void SetPrimariesMode(PrimariesMode Mode)
void PictureAttributeChanged(PictureAttribute Attribute, int Value)
~MythVideoColourSpace() override
void SetSupportedAttributes(PictureAttributeSupported Supported)
Enable the given set of picture attributes.
MythColourSpace * m_customDisplayPrimaries
void SetContrast(int Value)
int GetPictureAttribute(PictureAttribute Attribute)
void SetSaturation(int Value)
void Updated(bool PrimariesChanged)
int GetColourSpace() const
std::map< PictureAttribute, int > m_dbSettings
static MythColourSpace GetPrimaries(int Primary, float &Gamma)
void SetBrightness(int Value)
PictureAttributeSupported SupportedAttributes(void) const
void SupportedAttributesChanged(PictureAttributeSupported Supported)
PrimariesMode m_primariesMode
QStringList GetColourMappingDefines(void)
QMatrix4x4 GetPrimaryMatrix(void)
void PictureAttributesUpdated(const std::map< PictureAttribute, int > &Values)
PrimariesMode GetPrimariesMode(void)
bool UpdateColourSpace(const MythVideoFrame *Frame)
Set the current colourspace to use.
float GetColourGamma(void) const
int ChangePictureAttribute(PictureAttribute Attribute, bool Direction, int Value)
QMatrix4x4 m_primaryMatrix
float m_customDisplayGamma
void SetFullRange(bool FullRange)
QMatrix4x4 GetPrimaryConversion(int Source, int Dest)
void SaveValue(PictureAttribute Attribute, int Value)
Save the PictureAttribute value to the database.
static QString FormatDescription(VideoFrameType Type)
static bool YUVFormat(VideoFrameType Type)
static int ColorDepth(int Format)
static bool HardwareFormat(VideoFrameType Type)
General purpose reference counter.
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
static bool VERBOSE_LEVEL_CHECK(uint64_t mask, LogLevel_t level)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
static QString Source(const QNetworkRequest &request)
static void yuv2rgb(int y, int cr, int cb, eu8 *r, eu8 *g, eu8 *b)
static void rgb2yuv(eu8 r, eu8 g, eu8 b, eu8 *y, eu8 *cr, eu8 *cb)
static eu8 clamp(eu8 value, eu8 low, eu8 high)
VERBOSE_PREAMBLE Most debug(nodatabase, notimestamp, noextra)") VERBOSE_MAP(VB_GENERAL
PictureAttributeSupported
PrimariesMode toPrimariesMode(const QString &Mode)
@ kPictureAttribute_Range
@ kPictureAttribute_Contrast
@ kPictureAttribute_Brightness
@ kPictureAttribute_Colour
PictureAttributeSupported toMask(PictureAttribute PictureAttribute)