[FFmpeg-devel] [PATCH] avfilter/vf_lut: gammaval709()

Peter Ross pross at xvid.org
Thu Nov 13 23:14:24 CET 2014


See http://www.itu.int/rec/R-REC-BT.709
Item 1.2, overall opto-electronic transfer characteristics at source

Signed-off-by: Peter Ross <pross at xvid.org>
---

This is required for cine playback.
(Yes, the transform still occurs in yuv colorspace, which is a limitation.)

 libavfilter/vf_lut.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/libavfilter/vf_lut.c b/libavfilter/vf_lut.c
index fff5a2b..0b7a2ca 100644
--- a/libavfilter/vf_lut.c
+++ b/libavfilter/vf_lut.c
@@ -161,15 +161,32 @@ static double compute_gammaval(void *opaque, double gamma)
     return pow((val-minval)/(maxval-minval), gamma) * (maxval-minval)+minval;
 }
 
+/**
+ * Compute Rec.709 gama correction of value val
+ */
+static double compute_gammaval709(void *opaque, double gamma)
+{
+    LutContext *s = opaque;
+    double val    = s->var_values[VAR_CLIPVAL];
+    double minval = s->var_values[VAR_MINVAL];
+    double maxval = s->var_values[VAR_MAXVAL];
+    double level = (val - minval) / (maxval - minval);
+    level = level < 0.018 ? 4.5 * level
+                          : 1.099 * pow(level, 1.0 / gamma) - 0.099;
+    return level * (maxval - minval) + minval;
+}
+
 static double (* const funcs1[])(void *, double) = {
     (void *)clip,
     (void *)compute_gammaval,
+    (void *)compute_gammaval709,
     NULL
 };
 
 static const char * const funcs1_names[] = {
     "clip",
     "gammaval",
+    "gammaval709",
     NULL
 };
 
-- 
2.1.0

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20141114/d5909b33/attachment.asc>


More information about the ffmpeg-devel mailing list