The branch, master has been updated
via a2b47ccfbf7fe68de9405e4a113ee4c2f05f1fc3 (commit)
via 00e43619cd32f995278b236496fe879b42431da4 (commit)
from 3115c0c0e6c27c689a02a7267dcf8e61fa2ac425 (commit)
- Log -----------------------------------------------------------------
commit a2b47ccfbf7fe68de9405e4a113ee4c2f05f1fc3
Author: Kacper MichajÅow <[email protected]>
AuthorDate: Mon Oct 13 02:37:40 2025 +0200
Commit: Kacper MichajÅow <[email protected]>
CommitDate: Fri Oct 24 22:24:54 2025 +0000
avcodec/{png,mov}enc: use EOTF gamma approximation for gAMA chunk
This is how images encoded with specific transfer function should be
viewed. Image viewers that doesn't support named trc metadata, will
fallback to simple gAMA value and both of those cases should produce the
same image apperance for the viewer.
Fixes: https://github.com/mpv-player/mpv/issues/13438
Signed-off-by: Kacper MichajÅow <[email protected]>
diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c
index 07f5452157..96894bf7fd 100644
--- a/libavcodec/pngenc.c
+++ b/libavcodec/pngenc.c
@@ -323,7 +323,7 @@ static int png_get_chrm(enum AVColorPrimaries prim,
uint8_t *buf)
static int png_get_gama(enum AVColorTransferCharacteristic trc, uint8_t *buf)
{
- double gamma = av_csp_approximate_trc_gamma(trc);
+ double gamma = av_csp_approximate_eotf_gamma(trc);
if (gamma <= 1e-6)
return 0;
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 7d5d8f27e2..eabc1b95ca 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -2523,7 +2523,7 @@ static int mov_write_gama_tag(AVFormatContext *s,
AVIOContext *pb, MOVTrack *tra
{
uint32_t gama = 0;
if (gamma <= 0.0)
- gamma = av_csp_approximate_trc_gamma(track->par->color_trc);
+ gamma = av_csp_approximate_eotf_gamma(track->par->color_trc);
av_log(s, AV_LOG_DEBUG, "gamma value %g\n", gamma);
if (gamma > 1e-6) {
commit 00e43619cd32f995278b236496fe879b42431da4
Author: Kacper MichajÅow <[email protected]>
AuthorDate: Mon Oct 13 02:36:35 2025 +0200
Commit: Kacper MichajÅow <[email protected]>
CommitDate: Fri Oct 24 22:24:54 2025 +0000
avutil/csp: add av_csp_approximate_eotf_gamma()
2.2 gamma was used for bt.1886 aproximation as the most common target in
real world.
Signed-off-by: Kacper MichajÅow <[email protected]>
diff --git a/doc/APIchanges b/doc/APIchanges
index 6e7f5d2037..3ec8e25f03 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2025-03-28
API changes, most recent first:
+2025-10-xx - xxxxxxxxxx - lavu 60.14.100 - csp.h
+ Add av_csp_approximate_eotf_gamma().
+
2025-08-xx - xxxxxxxxxx - lavf 62.6.100 - oggparsevorbis.h oggparseopus.h
oggparseflac.h
Drop header packets from secondary chained ogg/{flac, opus, vorbis} streams
from demuxer output.
diff --git a/libavutil/csp.c b/libavutil/csp.c
index 75ac871616..4cd41fbee7 100644
--- a/libavutil/csp.c
+++ b/libavutil/csp.c
@@ -157,6 +157,27 @@ double av_csp_approximate_trc_gamma(enum
AVColorTransferCharacteristic trc)
return 0.0;
}
+static const double approximate_eotf_gamma[AVCOL_TRC_NB] = {
+ [AVCOL_TRC_BT709] = 2.2,
+ [AVCOL_TRC_SMPTE170M] = 2.2,
+ [AVCOL_TRC_SMPTE240M] = 2.2,
+ [AVCOL_TRC_BT1361_ECG] = 2.2,
+ [AVCOL_TRC_BT2020_10] = 2.2,
+ [AVCOL_TRC_BT2020_12] = 2.2,
+ [AVCOL_TRC_GAMMA22] = 2.2,
+ [AVCOL_TRC_IEC61966_2_1] = 2.2,
+ [AVCOL_TRC_GAMMA28] = 2.8,
+ [AVCOL_TRC_LINEAR] = 1.0,
+ [AVCOL_TRC_SMPTE428] = 2.6,
+};
+
+double av_csp_approximate_eotf_gamma(enum AVColorTransferCharacteristic trc)
+{
+ if ((unsigned)trc >= AVCOL_TRC_NB)
+ return 0.0;
+ return approximate_eotf_gamma[trc];
+}
+
#define BT709_alpha 1.099296826809442
#define BT709_beta 0.018053968510807
diff --git a/libavutil/csp.h b/libavutil/csp.h
index 9871b1c9b2..9d75ccbb64 100644
--- a/libavutil/csp.h
+++ b/libavutil/csp.h
@@ -133,6 +133,22 @@ enum AVColorPrimaries av_csp_primaries_id_from_desc(const
AVColorPrimariesDesc *
*/
double av_csp_approximate_trc_gamma(enum AVColorTransferCharacteristic trc);
+/**
+ * Determine a suitable EOTF 'gamma' value to match the supplied
+ * AVColorTransferCharacteristic.
+ *
+ * This function returns the gamma value (exponent) for a simple pure power
+ * function approximation of the supplied AVColorTransferCharacteristic, or 0.
+ * if no reasonable approximation exists.
+ *
+ * EOTF(v) = (L_w - L_b) * v^gamma + L_b
+ *
+ * @return Will return an approximation to the simple gamma function matching
+ * the supplied Transfer Characteristic EOTF, Will return 0.0 for any
+ * we cannot reasonably match against.
+ */
+double av_csp_approximate_eotf_gamma(enum AVColorTransferCharacteristic trc);
+
/**
* Determine the function needed to apply the given
* AVColorTransferCharacteristic to linear input.
diff --git a/libavutil/version.h b/libavutil/version.h
index 1099715076..176b99aef3 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 60
-#define LIBAVUTIL_VERSION_MINOR 13
+#define LIBAVUTIL_VERSION_MINOR 14
#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-----------------------------------------------------------------------
Summary of changes:
doc/APIchanges | 3 +++
libavcodec/pngenc.c | 2 +-
libavformat/movenc.c | 2 +-
libavutil/csp.c | 21 +++++++++++++++++++++
libavutil/csp.h | 16 ++++++++++++++++
libavutil/version.h | 2 +-
6 files changed, 43 insertions(+), 3 deletions(-)
hooks/post-receive
--
_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]