]> git.sesse.net Git - ffmpeg/blobdiff - libswscale/yuv2rgb.c
lavc: Remove old vaapi decode infrastructure
[ffmpeg] / libswscale / yuv2rgb.c
index f1ce4aaef4140f37f0efd53c0384c67f7e9bb335..fca324299d7a295aea2ed20a3e197c9e0c69b0de 100644 (file)
 #include "swscale.h"
 #include "swscale_internal.h"
 
-extern const uint8_t dither_4x4_16[4][8];
-extern const uint8_t dither_8x8_32[8][8];
-extern const uint8_t dither_8x8_73[8][8];
-extern const uint8_t dither_8x8_220[8][8];
-
+/* Color space conversion coefficients for YCbCr -> RGB mapping.
+ *
+ * Entries are {crv, cbu, cgu, cgv}
+ *
+ *   crv = (255 / 224) * 65536 * (1 - cr) / 0.5
+ *   cbu = (255 / 224) * 65536 * (1 - cb) / 0.5
+ *   cgu = (255 / 224) * 65536 * (cb / cg) * (1 - cb) / 0.5
+ *   cgv = (255 / 224) * 65536 * (cr / cg) * (1 - cr) / 0.5
+ *
+ * where Y = cr * R + cg * G + cb * B and cr + cg + cb = 1.
+ */
 const int32_t ff_yuv2rgb_coeffs[8][4] = {
     { 117504, 138453, 13954, 34903 }, /* no sequence_display_extension */
     { 117504, 138453, 13954, 34903 }, /* ITU-R Rec. 709 (1990) */
@@ -124,7 +130,7 @@ const int *sws_getCoefficients(int colorspace)
     {                                                                       \
         int y;                                                              \
                                                                             \
-        if (!alpha && c->srcFormat == PIX_FMT_YUV422P) {                    \
+        if (!alpha && c->srcFormat == AV_PIX_FMT_YUV422P) {                    \
             srcStride[1] *= 2;                                              \
             srcStride[2] *= 2;                                              \
         }                                                                   \
@@ -264,28 +270,28 @@ YUV2RGBFUNC(yuva2rgba_c, uint32_t, 1)
     PUTRGBA(dst_2, py_2, pa_2, 0, 24);
 
     LOADCHROMA(1);
-    PUTRGBA(dst_2, py_2, pa_1, 1, 24);
-    PUTRGBA(dst_1, py_1, pa_2, 1, 24);
+    PUTRGBA(dst_2, py_2, pa_2, 1, 24);
+    PUTRGBA(dst_1, py_1, pa_1, 1, 24);
 
     LOADCHROMA(2);
     PUTRGBA(dst_1, py_1, pa_1, 2, 24);
     PUTRGBA(dst_2, py_2, pa_2, 2, 24);
 
     LOADCHROMA(3);
-    PUTRGBA(dst_2, py_2, pa_1, 3, 24);
-    PUTRGBA(dst_1, py_1, pa_2, 3, 24);
-    pa_1 += 8; \
-    pa_2 += 8; \
+    PUTRGBA(dst_2, py_2, pa_2, 3, 24);
+    PUTRGBA(dst_1, py_1, pa_1, 3, 24);
+    pa_1 += 8;
+    pa_2 += 8;
 ENDYUV2RGBLINE(8, 0)
     LOADCHROMA(0);
     PUTRGBA(dst_1, py_1, pa_1, 0, 24);
     PUTRGBA(dst_2, py_2, pa_2, 0, 24);
 
     LOADCHROMA(1);
-    PUTRGBA(dst_2, py_2, pa_1, 1, 24);
-    PUTRGBA(dst_1, py_1, pa_2, 1, 24);
-    pa_1 += 4; \
-    pa_2 += 4; \
+    PUTRGBA(dst_2, py_2, pa_2, 1, 24);
+    PUTRGBA(dst_1, py_1, pa_1, 1, 24);
+    pa_1 += 4;
+    pa_2 += 4;
 ENDYUV2RGBLINE(8, 1)
     LOADCHROMA(0);
     PUTRGBA(dst_1, py_1, pa_1, 0, 24);
@@ -308,8 +314,8 @@ YUV2RGBFUNC(yuva2argb_c, uint32_t, 1)
     LOADCHROMA(3);
     PUTRGBA(dst_2, py_2, pa_2, 3, 0);
     PUTRGBA(dst_1, py_1, pa_1, 3, 0);
-    pa_1 += 8; \
-    pa_2 += 8; \
+    pa_1 += 8;
+    pa_2 += 8;
 ENDYUV2RGBLINE(8, 0)
     LOADCHROMA(0);
     PUTRGBA(dst_1, py_1, pa_1, 0, 0);
@@ -318,8 +324,8 @@ ENDYUV2RGBLINE(8, 0)
     LOADCHROMA(1);
     PUTRGBA(dst_2, py_2, pa_2, 1, 0);
     PUTRGBA(dst_1, py_1, pa_1, 1, 0);
-    pa_1 += 4; \
-    pa_2 += 4; \
+    pa_1 += 4;
+    pa_2 += 4;
 ENDYUV2RGBLINE(8, 1)
     LOADCHROMA(0);
     PUTRGBA(dst_1, py_1, pa_1, 0, 0);
@@ -409,7 +415,7 @@ CLOSEYUV2RGBFUNC(8)
 
 // r, g, b, dst_1, dst_2
 YUV2RGBFUNC(yuv2rgb_c_12_ordered_dither, uint16_t, 0)
-    const uint8_t *d16 = dither_4x4_16[y & 3];
+    const uint8_t *d16 = ff_dither_4x4_16[y & 3];
 
 #define PUTRGB12(dst, src, i, o)                    \
     Y              = src[2 * i];                    \
@@ -440,8 +446,8 @@ CLOSEYUV2RGBFUNC(8)
 
 // r, g, b, dst_1, dst_2
 YUV2RGBFUNC(yuv2rgb_c_8_ordered_dither, uint8_t, 0)
-    const uint8_t *d32 = dither_8x8_32[y & 7];
-    const uint8_t *d64 = dither_8x8_73[y & 7];
+    const uint8_t *d32 = ff_dither_8x8_32[y & 7];
+    const uint8_t *d64 = ff_dither_8x8_73[y & 7];
 
 #define PUTRGB8(dst, src, i, o)                     \
     Y              = src[2 * i];                    \
@@ -471,8 +477,8 @@ YUV2RGBFUNC(yuv2rgb_c_8_ordered_dither, uint8_t, 0)
 CLOSEYUV2RGBFUNC(8)
 
 YUV2RGBFUNC(yuv2rgb_c_4_ordered_dither, uint8_t, 0)
-    const uint8_t * d64 = dither_8x8_73[y & 7];
-    const uint8_t *d128 = dither_8x8_220[y & 7];
+    const uint8_t * d64 = ff_dither_8x8_73[y & 7];
+    const uint8_t *d128 = ff_dither_8x8_220[y & 7];
     int acc;
 
 #define PUTRGB4D(dst, src, i, o)                    \
@@ -504,8 +510,8 @@ YUV2RGBFUNC(yuv2rgb_c_4_ordered_dither, uint8_t, 0)
 CLOSEYUV2RGBFUNC(4)
 
 YUV2RGBFUNC(yuv2rgb_c_4b_ordered_dither, uint8_t, 0)
-    const uint8_t *d64  = dither_8x8_73[y & 7];
-    const uint8_t *d128 = dither_8x8_220[y & 7];
+    const uint8_t *d64  = ff_dither_8x8_73[y & 7];
+    const uint8_t *d128 = ff_dither_8x8_220[y & 7];
 
 #define PUTRGB4DB(dst, src, i, o)                   \
     Y              = src[2 * i];                    \
@@ -535,7 +541,7 @@ YUV2RGBFUNC(yuv2rgb_c_4b_ordered_dither, uint8_t, 0)
 CLOSEYUV2RGBFUNC(8)
 
 YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither, uint8_t, 0)
-    const uint8_t *d128 = dither_8x8_220[y & 7];
+    const uint8_t *d128 = ff_dither_8x8_220[y & 7];
     char out_1 = 0, out_2 = 0;
     g = c->table_gU[128] + c->table_gV[128];
 
@@ -565,14 +571,10 @@ SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c)
 {
     SwsFunc t = NULL;
 
-    if (HAVE_MMX)
-        t = ff_yuv2rgb_init_mmx(c);
-    else if (HAVE_VIS)
-        t = ff_yuv2rgb_init_vis(c);
-    else if (HAVE_ALTIVEC)
-        t = ff_yuv2rgb_init_altivec(c);
-    else if (ARCH_BFIN)
-        t = ff_yuv2rgb_get_func_ptr_bfin(c);
+    if (ARCH_PPC)
+        t = ff_yuv2rgb_init_ppc(c);
+    if (ARCH_X86)
+        t = ff_yuv2rgb_init_x86(c);
 
     if (t)
         return t;
@@ -582,44 +584,44 @@ SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c)
            sws_format_name(c->srcFormat), sws_format_name(c->dstFormat));
 
     switch (c->dstFormat) {
-    case PIX_FMT_BGR48BE:
-    case PIX_FMT_BGR48LE:
+    case AV_PIX_FMT_BGR48BE:
+    case AV_PIX_FMT_BGR48LE:
         return yuv2rgb_c_bgr48;
-    case PIX_FMT_RGB48BE:
-    case PIX_FMT_RGB48LE:
+    case AV_PIX_FMT_RGB48BE:
+    case AV_PIX_FMT_RGB48LE:
         return yuv2rgb_c_48;
-    case PIX_FMT_ARGB:
-    case PIX_FMT_ABGR:
-        if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P)
+    case AV_PIX_FMT_ARGB:
+    case AV_PIX_FMT_ABGR:
+        if (CONFIG_SWSCALE_ALPHA && c->srcFormat == AV_PIX_FMT_YUVA420P)
             return yuva2argb_c;
-    case PIX_FMT_RGBA:
-    case PIX_FMT_BGRA:
-        if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P)
+    case AV_PIX_FMT_RGBA:
+    case AV_PIX_FMT_BGRA:
+        if (CONFIG_SWSCALE_ALPHA && c->srcFormat == AV_PIX_FMT_YUVA420P)
             return yuva2rgba_c;
         else
             return yuv2rgb_c_32;
-    case PIX_FMT_RGB24:
+    case AV_PIX_FMT_RGB24:
         return yuv2rgb_c_24_rgb;
-    case PIX_FMT_BGR24:
+    case AV_PIX_FMT_BGR24:
         return yuv2rgb_c_24_bgr;
-    case PIX_FMT_RGB565:
-    case PIX_FMT_BGR565:
-    case PIX_FMT_RGB555:
-    case PIX_FMT_BGR555:
+    case AV_PIX_FMT_RGB565:
+    case AV_PIX_FMT_BGR565:
+    case AV_PIX_FMT_RGB555:
+    case AV_PIX_FMT_BGR555:
         return yuv2rgb_c_16;
-    case PIX_FMT_RGB444:
-    case PIX_FMT_BGR444:
+    case AV_PIX_FMT_RGB444:
+    case AV_PIX_FMT_BGR444:
         return yuv2rgb_c_12_ordered_dither;
-    case PIX_FMT_RGB8:
-    case PIX_FMT_BGR8:
+    case AV_PIX_FMT_RGB8:
+    case AV_PIX_FMT_BGR8:
         return yuv2rgb_c_8_ordered_dither;
-    case PIX_FMT_RGB4:
-    case PIX_FMT_BGR4:
+    case AV_PIX_FMT_RGB4:
+    case AV_PIX_FMT_BGR4:
         return yuv2rgb_c_4_ordered_dither;
-    case PIX_FMT_RGB4_BYTE:
-    case PIX_FMT_BGR4_BYTE:
+    case AV_PIX_FMT_RGB4_BYTE:
+    case AV_PIX_FMT_BGR4_BYTE:
         return yuv2rgb_c_4b_ordered_dither;
-    case PIX_FMT_MONOBLACK:
+    case AV_PIX_FMT_MONOBLACK:
         return yuv2rgb_c_1_ordered_dither;
     default:
         assert(0);
@@ -670,25 +672,25 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
                                      int fullRange, int brightness,
                                      int contrast, int saturation)
 {
-    const int isRgb = c->dstFormat == PIX_FMT_RGB32     ||
-                      c->dstFormat == PIX_FMT_RGB32_1   ||
-                      c->dstFormat == PIX_FMT_BGR24     ||
-                      c->dstFormat == PIX_FMT_RGB565BE  ||
-                      c->dstFormat == PIX_FMT_RGB565LE  ||
-                      c->dstFormat == PIX_FMT_RGB555BE  ||
-                      c->dstFormat == PIX_FMT_RGB555LE  ||
-                      c->dstFormat == PIX_FMT_RGB444BE  ||
-                      c->dstFormat == PIX_FMT_RGB444LE  ||
-                      c->dstFormat == PIX_FMT_RGB8      ||
-                      c->dstFormat == PIX_FMT_RGB4      ||
-                      c->dstFormat == PIX_FMT_RGB4_BYTE ||
-                      c->dstFormat == PIX_FMT_MONOBLACK;
-    const int isNotNe = c->dstFormat == PIX_FMT_NE(RGB565LE, RGB565BE) ||
-                        c->dstFormat == PIX_FMT_NE(RGB555LE, RGB555BE) ||
-                        c->dstFormat == PIX_FMT_NE(RGB444LE, RGB444BE) ||
-                        c->dstFormat == PIX_FMT_NE(BGR565LE, BGR565BE) ||
-                        c->dstFormat == PIX_FMT_NE(BGR555LE, BGR555BE) ||
-                        c->dstFormat == PIX_FMT_NE(BGR444LE, BGR444BE);
+    const int isRgb = c->dstFormat == AV_PIX_FMT_RGB32     ||
+                      c->dstFormat == AV_PIX_FMT_RGB32_1   ||
+                      c->dstFormat == AV_PIX_FMT_BGR24     ||
+                      c->dstFormat == AV_PIX_FMT_RGB565BE  ||
+                      c->dstFormat == AV_PIX_FMT_RGB565LE  ||
+                      c->dstFormat == AV_PIX_FMT_RGB555BE  ||
+                      c->dstFormat == AV_PIX_FMT_RGB555LE  ||
+                      c->dstFormat == AV_PIX_FMT_RGB444BE  ||
+                      c->dstFormat == AV_PIX_FMT_RGB444LE  ||
+                      c->dstFormat == AV_PIX_FMT_RGB8      ||
+                      c->dstFormat == AV_PIX_FMT_RGB4      ||
+                      c->dstFormat == AV_PIX_FMT_RGB4_BYTE ||
+                      c->dstFormat == AV_PIX_FMT_MONOBLACK;
+    const int isNotNe = c->dstFormat == AV_PIX_FMT_NE(RGB565LE, RGB565BE) ||
+                        c->dstFormat == AV_PIX_FMT_NE(RGB555LE, RGB555BE) ||
+                        c->dstFormat == AV_PIX_FMT_NE(RGB444LE, RGB444BE) ||
+                        c->dstFormat == AV_PIX_FMT_NE(BGR565LE, BGR565BE) ||
+                        c->dstFormat == AV_PIX_FMT_NE(BGR555LE, BGR555BE) ||
+                        c->dstFormat == AV_PIX_FMT_NE(BGR444LE, BGR444BE);
     const int bpp = c->dstFormatBpp;
     uint8_t *y_table;
     uint16_t *y_table16;
@@ -745,9 +747,13 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
 
     av_free(c->yuvTable);
 
+#define ALLOC_YUV_TABLE(x)          \
+        c->yuvTable = av_malloc(x); \
+        if (!c->yuvTable)           \
+            return AVERROR(ENOMEM);
     switch (bpp) {
     case 1:
-        c->yuvTable = av_malloc(1024);
+        ALLOC_YUV_TABLE(1024);
         y_table     = c->yuvTable;
         yb = -(384 << 16) - oy;
         for (i = 0; i < 1024 - 110; i++) {
@@ -762,7 +768,7 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
         rbase       = isRgb ? 3 : 0;
         gbase       = 1;
         bbase       = isRgb ? 0 : 3;
-        c->yuvTable = av_malloc(1024 * 3);
+        ALLOC_YUV_TABLE(1024 * 3);
         y_table     = c->yuvTable;
         yb = -(384 << 16) - oy;
         for (i = 0; i < 1024 - 110; i++) {
@@ -781,7 +787,7 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
         rbase       = isRgb ? 5 : 0;
         gbase       = isRgb ? 2 : 3;
         bbase       = isRgb ? 0 : 6;
-        c->yuvTable = av_malloc(1024 * 3);
+        ALLOC_YUV_TABLE(1024 * 3);
         y_table     = c->yuvTable;
         yb = -(384 << 16) - oy;
         for (i = 0; i < 1024 - 38; i++) {
@@ -800,7 +806,7 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
         rbase       = isRgb ? 8 : 0;
         gbase       = 4;
         bbase       = isRgb ? 0 : 8;
-        c->yuvTable = av_malloc(1024 * 3 * 2);
+        ALLOC_YUV_TABLE(1024 * 3 * 2);
         y_table16   = c->yuvTable;
         yb = -(384 << 16) - oy;
         for (i = 0; i < 1024; i++) {
@@ -823,7 +829,7 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
         rbase       = isRgb ? bpp - 5 : 0;
         gbase       = 5;
         bbase       = isRgb ? 0 : (bpp - 5);
-        c->yuvTable = av_malloc(1024 * 3 * 2);
+        ALLOC_YUV_TABLE(1024 * 3 * 2);
         y_table16   = c->yuvTable;
         yb = -(384 << 16) - oy;
         for (i = 0; i < 1024; i++) {
@@ -843,7 +849,7 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
         break;
     case 24:
     case 48:
-        c->yuvTable = av_malloc(1024);
+        ALLOC_YUV_TABLE(1024);
         y_table     = c->yuvTable;
         yb = -(384 << 16) - oy;
         for (i = 0; i < 1024; i++) {
@@ -856,15 +862,15 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
         fill_gv_table(c->table_gV, 1, cgv);
         break;
     case 32:
-        base      = (c->dstFormat == PIX_FMT_RGB32_1 ||
-                     c->dstFormat == PIX_FMT_BGR32_1) ? 8 : 0;
+        base      = (c->dstFormat == AV_PIX_FMT_RGB32_1 ||
+                     c->dstFormat == AV_PIX_FMT_BGR32_1) ? 8 : 0;
         rbase     = base + (isRgb ? 16 : 0);
         gbase     = base + 8;
         bbase     = base + (isRgb ? 0 : 16);
         needAlpha = CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat);
         if (!needAlpha)
             abase = (base + 24) & 31;
-        c->yuvTable = av_malloc(1024 * 3 * 4);
+        ALLOC_YUV_TABLE(1024 * 3 * 4);
         y_table32   = c->yuvTable;
         yb = -(384 << 16) - oy;
         for (i = 0; i < 1024; i++) {
@@ -882,7 +888,8 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
         break;
     default:
         c->yuvTable = NULL;
-        av_log(c, AV_LOG_ERROR, "%ibpp not supported by yuv2rgb\n", bpp);
+        if(!isPlanar(c->dstFormat) || bpp <= 24)
+            av_log(c, AV_LOG_ERROR, "%ibpp not supported by yuv2rgb\n", bpp);
         return -1;
     }
     return 0;