swscale: implement YA8 output
authorPaul B Mahol <onemda@gmail.com>
Wed, 1 Jul 2015 19:40:26 +0000 (19:40 +0000)
committerPaul B Mahol <onemda@gmail.com>
Thu, 2 Jul 2015 17:36:05 +0000 (17:36 +0000)
Signed-off-by: Paul B Mahol <onemda@gmail.com>
13 files changed:
libswscale/output.c
libswscale/utils.c
tests/ref/fate/filter-pixdesc-ya8 [new file with mode: 0644]
tests/ref/fate/filter-pixfmts-copy
tests/ref/fate/filter-pixfmts-crop
tests/ref/fate/filter-pixfmts-field
tests/ref/fate/filter-pixfmts-fieldorder
tests/ref/fate/filter-pixfmts-hflip
tests/ref/fate/filter-pixfmts-il
tests/ref/fate/filter-pixfmts-null
tests/ref/fate/filter-pixfmts-pad
tests/ref/fate/filter-pixfmts-scale
tests/ref/fate/filter-pixfmts-vflip

index f63af3b..09e3369 100644 (file)
@@ -1917,6 +1917,97 @@ yuv2gbrp_full_X_c(SwsContext *c, const int16_t *lumFilter,
     }
 }
 
+static void
+yuv2ya8_1_c(SwsContext *c, const int16_t *buf0,
+            const int16_t *ubuf[2], const int16_t *vbuf[2],
+            const int16_t *abuf0, uint8_t *dest, int dstW,
+            int uvalpha, int y)
+{
+    int hasAlpha = !!abuf0;
+    int i;
+
+    for (i = 0; i < dstW; i++) {
+        int Y = (buf0[i] + 64) >> 7;
+        int A;
+
+        Y = av_clip_uint8(Y);
+
+        if (hasAlpha) {
+            A = (abuf0[i] + 64) >> 7;
+            if (A & 0x100)
+                A = av_clip_uint8(A);
+        }
+
+        dest[i * 2    ] = Y;
+        dest[i * 2 + 1] = hasAlpha ? A : 255;
+    }
+}
+
+static void
+yuv2ya8_2_c(SwsContext *c, const int16_t *buf[2],
+            const int16_t *ubuf[2], const int16_t *vbuf[2],
+            const int16_t *abuf[2], uint8_t *dest, int dstW,
+            int yalpha, int uvalpha, int y)
+{
+    int hasAlpha = abuf[0] && abuf[1];
+    const int16_t *buf0  = buf[0],  *buf1  = buf[1],
+                  *abuf0 = hasAlpha ? abuf[0] : NULL,
+                  *abuf1 = hasAlpha ? abuf[1] : NULL;
+    int  yalpha1 = 4096 - yalpha;
+    int i;
+
+    for (i = 0; i < dstW; i++) {
+        int Y = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
+        int A;
+
+        Y = av_clip_uint8(Y);
+
+        if (hasAlpha) {
+            A = (abuf0[i * 2] * yalpha1 + abuf1[i * 2] * yalpha) >> 19;
+            A = av_clip_uint8(A);
+        }
+
+        dest[i * 2    ] = Y;
+        dest[i * 2 + 1] = hasAlpha ? A : 255;
+    }
+}
+
+static void
+yuv2ya8_X_c(SwsContext *c, const int16_t *lumFilter,
+            const int16_t **lumSrc, int lumFilterSize,
+            const int16_t *chrFilter, const int16_t **chrUSrc,
+            const int16_t **chrVSrc, int chrFilterSize,
+            const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
+{
+    int hasAlpha = !!alpSrc;
+    int i;
+
+    for (i = 0; i < dstW; i++) {
+        int j;
+        int Y = 1 << 18, A = 1 << 18;
+
+        for (j = 0; j < lumFilterSize; j++)
+            Y += lumSrc[j][i] * lumFilter[j];
+
+        Y >>= 19;
+        if (Y  & 0x100)
+            Y = av_clip_uint8(Y);
+
+        if (hasAlpha) {
+            for (j = 0; j < lumFilterSize; j++)
+                A += alpSrc[j][i] * lumFilter[j];
+
+            A >>= 19;
+
+            if (A & 0x100)
+                A = av_clip_uint8(A);
+        }
+
+        dest[2 * i    ] = Y;
+        dest[2 * i + 1] = hasAlpha ? A : 255;
+    }
+}
+
 av_cold void ff_sws_init_output_funcs(SwsContext *c,
                                       yuv2planar1_fn *yuv2plane1,
                                       yuv2planarX_fn *yuv2planeX,
@@ -2361,5 +2452,10 @@ av_cold void ff_sws_init_output_funcs(SwsContext *c,
         *yuv2packed2 = yuv2uyvy422_2_c;
         *yuv2packedX = yuv2uyvy422_X_c;
         break;
+    case AV_PIX_FMT_YA8:
+        *yuv2packed1 = yuv2ya8_1_c;
+        *yuv2packed2 = yuv2ya8_2_c;
+        *yuv2packedX = yuv2ya8_X_c;
+        break;
     }
 }
index 074f8c0..c384aa5 100644 (file)
@@ -166,7 +166,7 @@ static const FormatEntry format_entries[AV_PIX_FMT_NB] = {
     [AV_PIX_FMT_RGB444BE]    = { 1, 1 },
     [AV_PIX_FMT_BGR444LE]    = { 1, 1 },
     [AV_PIX_FMT_BGR444BE]    = { 1, 1 },
-    [AV_PIX_FMT_YA8]         = { 1, 0 },
+    [AV_PIX_FMT_YA8]         = { 1, 1 },
     [AV_PIX_FMT_YA16BE]      = { 1, 0 },
     [AV_PIX_FMT_YA16LE]      = { 1, 0 },
     [AV_PIX_FMT_BGR48BE]     = { 1, 1 },
diff --git a/tests/ref/fate/filter-pixdesc-ya8 b/tests/ref/fate/filter-pixdesc-ya8
new file mode 100644 (file)
index 0000000..78aae77
--- /dev/null
@@ -0,0 +1 @@
+pixdesc-ya8         1719d17930180793286230dd38d18edb
index 6281711..defdb19 100644 (file)
@@ -53,6 +53,7 @@ rgba64le            b91e1d77f799eb92241a2d2d28437b15
 uyvy422             3bcf3c80047592f2211fae3260b1b65d
 xyz12be             a1ef56bf746d71f59669c28e48fc8450
 xyz12le             831ff03c1ba4ef19374686f16a064d8c
+ya8                 e4bdc2165c1fe29905accfc68e7597ca
 yuv410p             5d4d992a7728431aa4e0700f87fb7fd8
 yuv411p             7e1300e89f5bc07939e2c4a6acbdf267
 yuv420p             a014c7eb7a8385d1dd092b7a583f1bff
index 1b1a763..b9e117b 100644 (file)
@@ -50,6 +50,7 @@ rgba64be            89910046972ab3c68e2a348302cc8ca9
 rgba64le            fea8ebfc869b52adf353778f29eac7a7
 xyz12be             cb4571f9aaa7b59f999ef327276104b7
 xyz12le             cd6aae8d26b18bdb4b9d068586276d91
+ya8                 2a888cb3018a09443435ce8bfa731cc1
 yuv410p             3bb6c7b64f2c46bc5e8b77198ce4ea58
 yuv411p             693e4afe96998e6dd91734037d75d887
 yuv420p             510d36163e4d3710988c23c2240ca6dc
index 9ba8e58..5bec7f8 100644 (file)
@@ -53,6 +53,7 @@ rgba64le            dfdba4de4a7cac9abf08852666c341d3
 uyvy422             1c49e44ab3f060e85fc4a3a9464f045e
 xyz12be             d2fa69ec91d3ed862f2dac3f8e7a3437
 xyz12le             02bccd5e0b6824779a1f848b0ea3e3b5
+ya8                 9b3f26c05060aab832817967bf3c90ab
 yuv410p             a85920d6bd26f51306e2ecbe71d1c554
 yuv411p             9106e283d5dbcfba01c611886d58871a
 yuv420p             9ea8ed3c22c31c0354b7face540bb280
index 085b053..832e51d 100644 (file)
@@ -48,6 +48,7 @@ rgba64le            b34e6e30621ae579519a2d91a96a0acf
 uyvy422             75de70e31c435dde878002d3f22b238a
 xyz12be             15f5cda71de5fef9cec5e75e3833b6bc
 xyz12le             7be6c8781f38c21a6b8f602f62ca31e6
+ya8                 9dab461f986b50151ccb2eb3bac75da9
 yuv411p             e4a040e0e786c4dae07d9d3f90a54905
 yuv422p             16ce67249c6ce7ef57a433646ad6dfc1
 yuv422p10be         62ae323dcc41aabf8ff6ecc53b119ce8
index 206462a..8f41f12 100644 (file)
@@ -50,6 +50,7 @@ rgba64be            c910444019f4cfbf4d995227af55da8d
 rgba64le            0c810d8b3a6bca10321788e1cb145340
 xyz12be             25f90259ff8a226befdaec3dfe82996e
 xyz12le             926c0791d59aaff61b2778e8ada3316d
+ya8                 68b888a5e5e5e51f57c282d98e736ad4
 yuv410p             c49fd0c55c41185b1580aac77211992b
 yuv411p             c416371077dce13d31bf1dc706111ae7
 yuv420p             eb8d9f02db98e10400781428c43e9438
index d6f510c..87538c5 100644 (file)
@@ -52,6 +52,7 @@ rgba64le            a8a2daae04374a27219bc1c890204007
 uyvy422             d6ee3ca43356d08c392382b24b22cda5
 xyz12be             7c7d54c55f136cbbc50b18029f3be0b3
 xyz12le             090ba6b1170baf2b1358b43b971d33b0
+ya8                 ec043b98eb0fd044fd8072d91d9cd31a
 yuv410p             dea1ab8843465adf5b8240b2d98fd85b
 yuv411p             8bf73777a5ff43c126be274245aceff1
 yuv420p             f1f4e7e94a76d5320049464bdeac24ed
index 6281711..defdb19 100644 (file)
@@ -53,6 +53,7 @@ rgba64le            b91e1d77f799eb92241a2d2d28437b15
 uyvy422             3bcf3c80047592f2211fae3260b1b65d
 xyz12be             a1ef56bf746d71f59669c28e48fc8450
 xyz12le             831ff03c1ba4ef19374686f16a064d8c
+ya8                 e4bdc2165c1fe29905accfc68e7597ca
 yuv410p             5d4d992a7728431aa4e0700f87fb7fd8
 yuv411p             7e1300e89f5bc07939e2c4a6acbdf267
 yuv420p             a014c7eb7a8385d1dd092b7a583f1bff
index 122f1ff..8ee874c 100644 (file)
@@ -11,6 +11,7 @@ gray                ddc663a0491df3959d9c5795dceaa72e
 rgb0                78d500c8361ab6423a4826a00268c908
 rgb24               17f9e2e0c609009acaf2175c42d4a2a5
 rgba                b157c90191463d34fb3ce77b36c96386
+ya8                 310847fa55017bcb2ceb5dcbbea3557c
 yuv410p             cb871dcc1e84a7ef1d21f9237b88cf6e
 yuv411p             aec2c1740de9a62db0d41f4dda9121b0
 yuv420p             4398e408fc35436ce4b20468946f58b6
index 553a4c5..18a6800 100644 (file)
@@ -53,6 +53,7 @@ rgba64le            783d2779adfafe3548bdb671ec0de69e
 uyvy422             aeb4ba4f9f003ae21f6d18089198244f
 xyz12be             c7ba8345998c0141ddc079cdd29b1a40
 xyz12le             95f5d3a0de834cc495c9032a14987cde
+ya8                 9d08dbcf1ed51bd4e437cc1f1db583e4
 yuv410p             e8f49b5fb9335b62c074f7f8bb0234fc
 yuv411p             5af32557c93beb482e26e7af693104c6
 yuv420p             5d3ac239c3712143560b1dfbd48a7ddd
index ac9f003..732bb63 100644 (file)
@@ -53,6 +53,7 @@ rgba64le            48f45b10503b7dd140329c3dd0d54c98
 uyvy422             3a237e8376264e0cfa78f8a3fdadec8a
 xyz12be             810644e008deb231850d779aaa27cc7e
 xyz12le             829701db461b43533cf9241e0743bc61
+ya8                 4ac56b8d1c3efc54d5fb585608a8c688
 yuv410p             c7adfe96c8e043a6cb9290c39bf8063c
 yuv411p             3fce29db403a25f81be39e01aaf6ff3a
 yuv420p             d64fae96fac22aefa8fbcf45a09f37c1