9 #include "libavutil/pixfmt.h" 10 #include "libavutil/pixdesc.h" 17 {{{0.640F, 0.330F}, {0.300F, 0.600F}, {0.150F, 0.060F}}, {0.3127F, 0.3290F}};
19 {{{0.640F, 0.340F}, {0.310F, 0.595F}, {0.155F, 0.070F}}, {0.3127F, 0.3290F}};
21 {{{0.640F, 0.330F}, {0.290F, 0.600F}, {0.150F, 0.060F}}, {0.3127F, 0.3290F}};
23 {{{0.708F, 0.292F}, {0.170F, 0.797F}, {0.131F, 0.046F}}, {0.3127F, 0.3290F}};
25 #define LOC QString("ColourSpace: ") 125 Value = std::min(std::max(Value, 0), 100);
166 std::vector<float> rgb;
169 case AVCOL_SPC_RGB: rgb = { 1.0000F, 1.0000F, 1.0000F };
break;
170 case AVCOL_SPC_BT709: rgb = { 0.2126F, 0.7152F, 0.0722F };
break;
171 case AVCOL_SPC_FCC: rgb = { 0.30F, 0.59F, 0.11F };
break;
172 case AVCOL_SPC_BT470BG:
173 case AVCOL_SPC_SMPTE170M: rgb = { 0.299F, 0.587F, 0.114F };
break;
174 case AVCOL_SPC_SMPTE240M: rgb = { 0.212F, 0.701F, 0.087F };
break;
175 case AVCOL_SPC_YCOCG: rgb = { 0.25F, 0.5F, 0.25F };
break;
176 case AVCOL_SPC_BT2020_CL:
177 case AVCOL_SPC_BT2020_NCL: rgb = { 0.2627F, 0.6780F, 0.0593F };
break;
178 case AVCOL_SPC_UNSPECIFIED:
179 case AVCOL_SPC_RESERVED:
180 case AVCOL_SPC_SMPTE2085:
181 case AVCOL_SPC_CHROMA_DERIVED_CL:
182 case AVCOL_SPC_CHROMA_DERIVED_NCL:
183 case AVCOL_SPC_ICTCP:
184 default: rgb = { 0.2126F, 0.7152F, 0.0722F };
187 float bs = rgb[2] == 1.0F ? 0.0F : 0.5F / (rgb[2] - 1.0F);
188 float rs = rgb[0] == 1.0F ? 0.0F : 0.5F / (rgb[0] - 1.0F);
189 QMatrix4x4
rgb2yuv( rgb[0], rgb[1], rgb[2], 0.0F,
190 bs * rgb[0], bs * rgb[1], 0.5F, 0.0F,
191 0.5F, rs * rgb[1], rs * rgb[2], 0.0F,
197 rgb2yuv = QMatrix4x4(0.25F, 0.50F, 0.25F, 0.0F,
198 -0.25F, 0.50F, -0.25F, 0.0F,
199 0.50F, 0.00F, -0.50F, 0.0F,
209 yuv2rgb.translate(0.0F, -0.5F, -0.5F);
222 bool noop = !expand && !contract;
227 float luma_scale = noop ? 1.0F : (expand ? depth / (lumapeak - blacklevel) : (lumapeak - blacklevel) / depth);
228 float chroma_scale = noop ? 1.0F : (expand ? depth / (chromapeak - blacklevel) : (chromapeak - blacklevel) / depth);
229 float offset = noop ? 0.0F : (expand ? -blacklevel / depth : blacklevel / depth);
235 scale(luma_scale, chroma_scale, chroma_scale);
236 translate(offset, offset, offset);
252 static_cast<QMatrix4x4*>(
this)->operator = (this->transposed());
260 bool primchanged = !qFuzzyCompare(tmpsrcgamma,
m_colourGamma) ||
271 LOG(VB_PLAYBACK, LOG_DEBUG,
LOC +
272 QString(
"Brightness: %1 Contrast: %2 Saturation: %3 Hue: %4 Alpha: %5 Range: %6 Primary: %7")
273 .arg(static_cast<qreal>(
m_brightness), 2,
'f', 4, QLatin1Char(
'0'))
274 .arg(static_cast<qreal>(
m_contrast) , 2,
'f', 4, QLatin1Char(
'0'))
275 .arg(static_cast<qreal>(
m_saturation), 2,
'f', 4, QLatin1Char(
'0'))
276 .arg(static_cast<qreal>(
m_hue) , 2,
'f', 4, QLatin1Char(
'0'))
277 .arg(static_cast<qreal>(
m_alpha) , 2,
'f', 4, QLatin1Char(
'0'))
284 QDebug
debug(&stream);
288 LOG(VB_PLAYBACK, LOG_DEBUG, stream);
303 int csp =
Frame->colorspace;
304 int primary =
Frame->colorprimaries;
305 int transfer =
Frame->colortransfer;
317 csp = AVCOL_SPC_UNSPECIFIED;
319 int range =
Frame->colorrange;
320 if (range == AVCOL_RANGE_UNSPECIFIED)
321 range = AVCOL_RANGE_MPEG;
323 if (csp == AVCOL_SPC_UNSPECIFIED)
324 csp = (
Frame->width < 1280) ? AVCOL_SPC_BT470BG : AVCOL_SPC_BT709;
325 if (primary == AVCOL_PRI_UNSPECIFIED)
326 primary = (
Frame->width < 1280) ? AVCOL_PRI_BT470BG : AVCOL_PRI_BT709;
327 if (transfer == AVCOL_TRC_UNSPECIFIED)
328 transfer = (
Frame->width < 1280) ? AVCOL_TRC_GAMMA28 : AVCOL_TRC_BT709;
344 LOG(VB_GENERAL, LOG_WARNING,
LOC + QString(
"Forcing inconsistent colourspace - frame format %1")
347 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"Input : %1(%2) Depth:%3 %4Range:%5")
348 .arg(av_color_space_name(static_cast<AVColorSpace>(
m_colourSpace)))
352 .arg((AVCOL_RANGE_JPEG ==
m_range) ?
"Full" :
"Limited"));
353 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"Input : Primaries:%1 Transfer: %2")
355 .arg(av_color_transfer_name(static_cast<AVColorTransferCharacteristic>(
m_colourTransfer))));
356 LOG(VB_PLAYBACK, LOG_INFO,
LOC + QString(
"Output: Range:%1 Primaries: %2")
365 LOG(VB_GENERAL, LOG_INFO,
LOC + QString(
"Enabled colourspace primaries conversion from %1 to %2")
393 m_hue = Value * -3.6F;
415 result <<
"COLOURMAPPING";
454 dbName =
"PlaybackBrightness";
456 dbName =
"PlaybackContrast";
458 dbName =
"PlaybackColour";
460 dbName =
"PlaybackHue";
462 if (!dbName.isEmpty())
471 auto source = static_cast<AVColorPrimaries>(
Source);
472 auto dest = static_cast<AVColorPrimaries>(Dest);
501 auto primary = static_cast<AVColorPrimaries>(Primary);
505 case AVCOL_PRI_BT470BG:
506 case AVCOL_PRI_BT470M: Out =
BT610_625;
return;
507 case AVCOL_PRI_SMPTE170M:
508 case AVCOL_PRI_SMPTE240M: Out =
BT610_525;
return;
509 case AVCOL_PRI_BT2020: Out =
BT2020; Gamma = 2.4F;
return;
510 default: Out =
BT709;
return;
514 inline float CalcBy(
const float p[3][2],
const float w[2])
516 float val = ((1-w[0])/w[1] - (1-
p[0][0])/
p[0][1]) * (
p[1][0]/
p[1][1] -
p[0][0]/
p[0][1]) -
517 (w[0]/w[1] -
p[0][0]/
p[0][1]) * ((1-
p[1][0])/
p[1][1] - (1-
p[0][0])/
p[0][1]);
518 val /= ((1-
p[2][0])/
p[2][1] - (1-
p[0][0])/
p[0][1]) * (
p[1][0]/
p[1][1] -
p[0][0]/
p[0][1]) -
519 (
p[2][0]/
p[2][1] -
p[0][0]/
p[0][1]) * ((1-
p[1][0])/
p[1][1] - (1-
p[0][0])/
p[0][1]);
523 inline float CalcGy(
const float p[3][2],
const float w[2],
const float By)
525 float val = w[0]/w[1] -
p[0][0]/
p[0][1] - By * (
p[2][0]/
p[2][1] -
p[0][0]/
p[0][1]);
526 val /=
p[1][0]/
p[1][1] -
p[0][0]/
p[0][1];
530 inline float CalcRy(
const float By,
const float Gy)
532 return 1.0F - Gy - By;
546 float Ry =
CalcRy(By, Gy);
558 temp[0][3] = temp[1][3] = temp[2][3] = temp[3][0] = temp[3][1] = temp[3][2] = 0.0F;
560 return QMatrix4x4(temp[0]);
float CalcBy(const float p[3][2], const float w[2])
PrimariesMode GetPrimariesMode(void)
float CalcGy(const float p[3][2], const float w[2], const float By)
VideoColourSpace contains a QMatrix4x4 that can convert YCbCr data to RGB.
QMap< PictureAttribute, int > m_dbSettings
float GetColourGamma(void)
void SetPrimariesMode(PrimariesMode Mode)
PictureAttributeSupported
QString toString(MarkTypes type)
void SaveSetting(const QString &key, int newValue)
General purpose reference counter.
void SetSaturation(int Value)
int GetPictureAttribute(PictureAttribute Attribute)
VideoFrameType PixelFormatToFrameType(AVPixelFormat fmt)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
void SetFullRange(bool FullRange)
static const ColourPrimaries BT610_625
int ColorDepth(int Format)
Return the color depth for the given MythTV frame format.
static void GetPrimaries(int Primary, ColourPrimaries &Out, float &Gamma)
void PictureAttributeChanged(PictureAttribute Attribute, int Value)
static const ColourPrimaries BT610_525
VideoColourSpace(VideoColourSpace *Parent=nullptr)
float m_customDisplayGamma
QMatrix4x4 GetPrimaryMatrix(void)
float GetDisplayGamma(void)
virtual int IncrRef(void)
Increments reference count.
#define VERBOSE_LEVEL_CHECK(_MASK_, _LEVEL_)
static int format_is_hw(VideoFrameType Type)
static int format_is_yuv(VideoFrameType Type)
QStringList GetColourMappingDefines(void)
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
static const ColourPrimaries BT2020
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)
ColourPrimaries * m_customDisplayPrimaries
void Updated(bool PrimariesChanged)
PictureAttributeSupported m_supportedAttributes
void SetBrightness(int Value)
void SetSupportedAttributes(PictureAttributeSupported Supported)
Enable the given set of picture attributes.
int GetNumSetting(const QString &key, int defaultval=0)
PictureAttributeSupported toMask(PictureAttribute pictureattribute)
#define LOG(_MASK_, _LEVEL_, _STRING_)
QMatrix4x4 GetPrimaryConversion(int Source, int Dest)
bool GetBoolSetting(const QString &key, bool defaultval=false)
VERBOSE_PREAMBLE Most debug(nodatabase, notimestamp, noextra)") VERBOSE_MAP(VB_GENERAL
VideoColourSpace * m_parent
PictureAttributeSupported SupportedAttributes(void) const
void SaveValue(PictureAttribute Attribute, int Value)
Save the PictureAttribute value to the database.
const char * format_description(VideoFrameType Type)
int SetPictureAttribute(PictureAttribute Attribute, int Value)
Set the Value for the given PictureAttribute.
QMatrix4x4 m_primaryMatrix
void SetContrast(int Value)
void Update(void)
Update the matrix for the current settings and colourspace.
PrimariesMode m_primariesMode
static const ColourPrimaries BT709
bool UpdateColourSpace(const VideoFrame *Frame)
Set the current colourspace to use.
static QMatrix4x4 RGBtoXYZ(ColourPrimaries Primaries)
Create a conversion matrix for RGB to XYZ with the given primaries.
float CalcRy(const float By, const float Gy)