summaryrefslogtreecommitdiff
path: root/libavcodec/pngenc.c
diff options
context:
space:
mode:
authorKevin Wheatley <kevin.j.wheatley@gmail.com>2015-03-05 10:37:51 +0000
committerMichael Niedermayer <michaelni@gmx.at>2015-03-05 12:26:22 +0100
commit86b59e6a50c8498efd2ccbd541ac46dac16e958c (patch)
tree0ede04bd9773229821f3df72df1190c9bccde313 /libavcodec/pngenc.c
parent6db20926c32ea297418f1f819585007c6b7b6160 (diff)
avutil: Extract gamma determination from PNG encoder for future use. Adds private avpriv_get_gamma_from_trc() function to libavutil.
Signed-off-by: Kevin Wheatley <kevin.j.wheatley@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/pngenc.c')
-rw-r--r--libavcodec/pngenc.c29
1 files changed, 4 insertions, 25 deletions
diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c
index 6c9f43ede8..9bdefc45d3 100644
--- a/libavcodec/pngenc.c
+++ b/libavcodec/pngenc.c
@@ -28,6 +28,7 @@
#include "libavutil/avassert.h"
#include "libavutil/libm.h"
#include "libavutil/opt.h"
+#include "libavutil/color_utils.h"
#include <zlib.h>
@@ -277,31 +278,9 @@ static int png_get_chrm(enum AVColorPrimaries prim, uint8_t *buf)
static int png_get_gama(enum AVColorTransferCharacteristic trc, uint8_t *buf)
{
- double gamma;
- switch (trc) {
- case AVCOL_TRC_BT709:
- case AVCOL_TRC_SMPTE170M:
- case AVCOL_TRC_SMPTE240M:
- case AVCOL_TRC_BT1361_ECG:
- case AVCOL_TRC_BT2020_10:
- case AVCOL_TRC_BT2020_12:
- /* these share a segmented TRC, but gamma 1.961 is a close
- approximation, and also more correct for decoding content */
- gamma = 1.961;
- break;
- case AVCOL_TRC_GAMMA22:
- case AVCOL_TRC_IEC61966_2_1:
- gamma = 2.2;
- break;
- case AVCOL_TRC_GAMMA28:
- gamma = 2.8;
- break;
- case AVCOL_TRC_LINEAR:
- gamma = 1.0;
- break;
- default:
- return 0;
- }
+ double gamma = avpriv_get_gamma_from_trc(trc);
+ if (gamma <= 1e-6)
+ return 0;
AV_WB32_PNG(buf, 1.0 / gamma);
return 1;