]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/pngenc.c
x86/proresdsp: remove ff_prores_idct_put_10_sse4
[ffmpeg] / libavcodec / pngenc.c
index 9fd8eefd2524d2b345a29dfcb9b670b2e5871904..9bdefc45d39f58194ba3d60fc39229027f0ad7e7 100644 (file)
@@ -26,7 +26,9 @@
 #include "png.h"
 
 #include "libavutil/avassert.h"
+#include "libavutil/libm.h"
 #include "libavutil/opt.h"
+#include "libavutil/color_utils.h"
 
 #include <zlib.h>
 
@@ -231,7 +233,7 @@ static int png_write_row(PNGEncContext *s, const uint8_t *data, int size)
     return 0;
 }
 
-#define AV_WB32_PNG(buf, n) (AV_WB32(buf, round((n) * 100000)))
+#define AV_WB32_PNG(buf, n) AV_WB32(buf, lrint((n) * 100000))
 static int png_get_chrm(enum AVColorPrimaries prim,  uint8_t *buf)
 {
     double rx, ry, gx, gy, bx, by, wx = 0.3127, wy = 0.3290;
@@ -276,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;