Commit c7699419e5 for ffmpeg
commit c7699419e540252aa42ad5f97da8054ab6253b6a
Author: Ramiro Polla <ramiro.polla@gmail.com>
Date: Sun Nov 8 23:44:35 2026 -0300
swscale/output: reuse YA16 templates for YAF32
This gives the same precision as the existing GRAYF32 output and simplifies
code.
Signed-off-by: James Almer <jamrial@gmail.com>
diff --git a/libswscale/output.c b/libswscale/output.c
index 55cba1ea5f..97f8960938 100644
--- a/libswscale/output.c
+++ b/libswscale/output.c
@@ -305,70 +305,16 @@ static void yuv2planeX_float ## BE_LE ## _c(const int16_t *filter, int filterSiz
template(filter, filterSize, (const int32_t **)src, (dest_type *)dest, dstW, 1); \
}
-#define yuv2yaf32_1(template, dest_type, BE_LE, is_be) \
-static void yuv2yaf32 ## BE_LE ## _1_c(SwsInternal *c, const int16_t *lumSrc, \
- const int16_t *chrUSrc[2], \
- const int16_t *chrVSrc[2], \
- const int16_t *alpSrc, uint8_t *dest, \
- int dstW, int uvalpha, int y) \
-{ \
- dest_type *dst = (dest_type *) dest; \
- template((const int32_t *)lumSrc, dst, dstW, 2); \
- if (alpSrc) { \
- template((const int32_t *)alpSrc, dst + 1, dstW, 2); \
- } else { \
- for (int i = 0; i < dstW; i++) { \
- if (is_be) { \
- AV_WB32(&dst[2 * i + 1], av_float2int(1.0f)); \
- } else { \
- AV_WL32(&dst[2 * i + 1], av_float2int(1.0f)); \
- } \
- } \
- } \
-}
-
-#define yuv2yaf32_X(template, dest_type, BE_LE, is_be) \
-static void yuv2yaf32 ## BE_LE ## _X_c(SwsInternal *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) \
-{ \
- dest_type *dst = (dest_type *) dest; \
- template(lumFilter, lumFilterSize, (const int32_t **) lumSrc, dst, dstW, 2); \
- if (alpSrc) { \
- template(lumFilter, lumFilterSize, (const int32_t **) alpSrc, dst + 1, dstW, 2); \
- } else { \
- for (int i = 0; i < dstW; i++) { \
- if (is_be) { \
- AV_WB32(&dst[2 * i + 1], av_float2int(1.0f)); \
- } else { \
- AV_WL32(&dst[2 * i + 1], av_float2int(1.0f)); \
- } \
- } \
- } \
-}
-
#if HAVE_BIGENDIAN
yuv2plane1_float(yuv2plane1_float_c_template, float, BE)
yuv2plane1_float(yuv2plane1_float_bswap_c_template, uint32_t, LE)
yuv2planeX_float(yuv2planeX_float_c_template, float, BE)
yuv2planeX_float(yuv2planeX_float_bswap_c_template, uint32_t, LE)
-yuv2yaf32_1(yuv2plane1_float_c_template, float, be, 1)
-yuv2yaf32_1(yuv2plane1_float_bswap_c_template, uint32_t, le, 0)
-yuv2yaf32_X(yuv2planeX_float_c_template, float, be, 1)
-yuv2yaf32_X(yuv2planeX_float_bswap_c_template, uint32_t, le, 0)
#else
yuv2plane1_float(yuv2plane1_float_c_template, float, LE)
yuv2plane1_float(yuv2plane1_float_bswap_c_template, uint32_t, BE)
yuv2planeX_float(yuv2planeX_float_c_template, float, LE)
yuv2planeX_float(yuv2planeX_float_bswap_c_template, uint32_t, BE)
-yuv2yaf32_1(yuv2plane1_float_c_template, float, le, 0)
-yuv2yaf32_1(yuv2plane1_float_bswap_c_template, uint32_t, be, 1)
-yuv2yaf32_X(yuv2planeX_float_c_template, float, le, 0)
-yuv2yaf32_X(yuv2planeX_float_bswap_c_template, uint32_t, be, 1)
#endif
#undef output_pixel
@@ -1071,6 +1017,26 @@ YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, AV_PIX_FMT_UYVY422)
} else { \
AV_WL16(pos, val); \
}
+#define output_pixel32(pos, val) \
+ if (is_be) { \
+ AV_WB32(pos, val); \
+ } else { \
+ AV_WL32(pos, val); \
+ }
+
+static av_always_inline void
+output_pixel_ya(uint16_t *dest, int i, int Y, int A,
+ enum AVPixelFormat target, int is_be)
+{
+ if (target == AV_PIX_FMT_YAF32LE || target == AV_PIX_FMT_YAF32BE) {
+ static const float float_mult = 1.0f / 65535.0f;
+ output_pixel32(&dest[4 * i ], av_float2int(float_mult * Y));
+ output_pixel32(&dest[4 * i + 2], av_float2int(float_mult * A));
+ } else {
+ output_pixel(&dest[2 * i ], Y);
+ output_pixel(&dest[2 * i + 1], A);
+ }
+}
static av_always_inline void
yuv2ya16_X_c_template(SwsInternal *c, const int16_t *lumFilter,
@@ -1106,8 +1072,7 @@ yuv2ya16_X_c_template(SwsInternal *c, const int16_t *lumFilter,
A = av_clip_uint16(A);
}
- output_pixel(&dest[2 * i ], Y);
- output_pixel(&dest[2 * i + 1], A);
+ output_pixel_ya(dest, i, Y, A, target, is_be);
}
}
@@ -1140,8 +1105,7 @@ yuv2ya16_2_c_template(SwsInternal *c, const int32_t *buf[2],
A = av_clip_uint16(A);
}
- output_pixel(&dest[2 * i ], Y);
- output_pixel(&dest[2 * i + 1], hasAlpha ? A : 65535);
+ output_pixel_ya(dest, i, Y, hasAlpha ? A : 65535, target, is_be);
}
}
@@ -1167,8 +1131,7 @@ yuv2ya16_1_c_template(SwsInternal *c, const int32_t *buf0,
A = av_clip_uint16(A);
}
- output_pixel(&dest[2 * i ], Y);
- output_pixel(&dest[2 * i + 1], hasAlpha ? A : 65535);
+ output_pixel_ya(dest, i, Y, hasAlpha ? A : 65535, target, is_be);
}
}
@@ -1632,6 +1595,7 @@ yuv2rgba64_full_1_c_template(SwsInternal *c, const int32_t *buf0,
}
#undef output_pixel
+#undef output_pixel32
#undef r_b
#undef b_r
@@ -1697,6 +1661,8 @@ YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64be, AV_PIX_FMT_BGRA64, BE, 0, 1)
YUV2PACKED16WRAPPER(yuv2, rgba64, bgrx64le, AV_PIX_FMT_BGRA64, LE, 0, 1)
YUV2PACKED16WRAPPER(yuv2, ya16, ya16be, AV_PIX_FMT_YA16, BE, 1, 0)
YUV2PACKED16WRAPPER(yuv2, ya16, ya16le, AV_PIX_FMT_YA16, LE, 1, 0)
+YUV2PACKED16WRAPPER(yuv2, ya16, yaf32be, AV_PIX_FMT_YAF32, BE, 1, 0)
+YUV2PACKED16WRAPPER(yuv2, ya16, yaf32le, AV_PIX_FMT_YAF32, LE, 1, 0)
YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48be_full, AV_PIX_FMT_RGB48, BE, 0, 0)
YUV2PACKED16WRAPPER(yuv2, rgba64_full, rgb48le_full, AV_PIX_FMT_RGB48, LE, 0, 0)
@@ -3894,10 +3860,12 @@ av_cold void ff_sws_init_output_funcs(SwsInternal *c,
break;
case AV_PIX_FMT_YAF32LE:
*yuv2packed1 = yuv2yaf32le_1_c;
+ *yuv2packed2 = yuv2yaf32le_2_c;
*yuv2packedX = yuv2yaf32le_X_c;
break;
case AV_PIX_FMT_YAF32BE:
*yuv2packed1 = yuv2yaf32be_1_c;
+ *yuv2packed2 = yuv2yaf32be_2_c;
*yuv2packedX = yuv2yaf32be_X_c;
break;
case AV_PIX_FMT_V30XLE:
diff --git a/tests/ref/fate/filter-pixdesc-yaf32be b/tests/ref/fate/filter-pixdesc-yaf32be
index 310f352e98..31cfa195c8 100644
--- a/tests/ref/fate/filter-pixdesc-yaf32be
+++ b/tests/ref/fate/filter-pixdesc-yaf32be
@@ -1 +1 @@
-pixdesc-yaf32be 52967c7979f408430ea08da36adf51e9
+pixdesc-yaf32be 11ca5e3f990380a7d84bf505bee7cd60
diff --git a/tests/ref/fate/filter-pixdesc-yaf32le b/tests/ref/fate/filter-pixdesc-yaf32le
index 731f569e2b..1551983ae4 100644
--- a/tests/ref/fate/filter-pixdesc-yaf32le
+++ b/tests/ref/fate/filter-pixdesc-yaf32le
@@ -1 +1 @@
-pixdesc-yaf32le afe5b813bca1972266f6f3023b71f892
+pixdesc-yaf32le 8a084fad1b4d5d74a1f4b4e4b7998387
diff --git a/tests/ref/fate/filter-pixfmts-copy b/tests/ref/fate/filter-pixfmts-copy
index 28e1102c94..5c02a63897 100644
--- a/tests/ref/fate/filter-pixfmts-copy
+++ b/tests/ref/fate/filter-pixfmts-copy
@@ -125,8 +125,8 @@ y216le 0e99aeddfee304e72d525d72998d9e9b
ya16be c7a868787e0f3d487dbc8af804d15d81
ya16le a5299b6c9cb1b5b1f5fb62546b9c6c4e
ya8 dbb99fbcdc204aaa1a7397ff561f1a67
-yaf32be 0d7f48b22abca63936637d8e22985299
-yaf32le decb6e2e85575573608c503af244df57
+yaf32be 0f4f26673a6fe8ba9b74ad45611c8488
+yaf32le eacd43d54c8127ee1b9f88d79545933f
yuv410p 5d4d992a7728431aa4e0700f87fb7fd8
yuv411p 7e1300e89f5bc07939e2c4a6acbdf267
yuv420p a014c7eb7a8385d1dd092b7a583f1bff
diff --git a/tests/ref/fate/filter-pixfmts-crop b/tests/ref/fate/filter-pixfmts-crop
index 55c6dbf185..261336f7cf 100644
--- a/tests/ref/fate/filter-pixfmts-crop
+++ b/tests/ref/fate/filter-pixfmts-crop
@@ -119,8 +119,8 @@ xyz12le 122fb7eea3575b4edbbd83219bc7af91
ya16be e2b490dc18f6ca3814fe9d68193ba263
ya16le 33b0e26f3c2e89c651345970474f6703
ya8 51a8dd297e35d40b06d3ebe8f4717895
-yaf32be 9294ff8cc89b6dda482b931286fb7c05
-yaf32le 6ebf9e1338a6de1d9a553c38a85da251
+yaf32be 6524649877583eac52f8076be68d1cf9
+yaf32le 0df188030b0d07a2c909103f95e12267
yuv410p 3bb6c7b64f2c46bc5e8b77198ce4ea58
yuv411p 693e4afe96998e6dd91734037d75d887
yuv420p 510d36163e4d3710988c23c2240ca6dc
diff --git a/tests/ref/fate/filter-pixfmts-field b/tests/ref/fate/filter-pixfmts-field
index f783d04ef5..1e137f4b47 100644
--- a/tests/ref/fate/filter-pixfmts-field
+++ b/tests/ref/fate/filter-pixfmts-field
@@ -125,8 +125,8 @@ y216le e65b5bfae1b40edbbed2012e9cd45e31
ya16be 466e6864b69dc93be890d32e021f4ab1
ya16le bd151aacfa82c803983e5c7bdc23b58b
ya8 28cea4f98ed452bd3da9c752e5e3399c
-yaf32be 3e440e683f461143e924b666d86f3d1c
-yaf32le 6d69152d5a1dd44f7943e0126e08b85a
+yaf32be af630161f967366e657afb6d6a514caa
+yaf32le 2d8e57abc7ec69c4d5b12e4559336c66
yuv410p a85920d6bd26f51306e2ecbe71d1c554
yuv411p 9106e283d5dbcfba01c611886d58871a
yuv420p 9ea8ed3c22c31c0354b7face540bb280
diff --git a/tests/ref/fate/filter-pixfmts-fieldorder b/tests/ref/fate/filter-pixfmts-fieldorder
index 68c230eb43..93bea75fbb 100644
--- a/tests/ref/fate/filter-pixfmts-fieldorder
+++ b/tests/ref/fate/filter-pixfmts-fieldorder
@@ -114,8 +114,8 @@ y216le 360cb98ac80b13d3a8ec61c9f1ff3bac
ya16be 9462d3dded4802b9d9f96e8a40709067
ya16le f7eefa08ae0bfa77baf48c7064f59c13
ya8 055ac5ab5ff8533dd319edc17a398af1
-yaf32be 64c009faa0df2a44a5db191a1c5ae2b9
-yaf32le 55adc32f0c975d444c508a3b7ffbf179
+yaf32be 2f615d187b0ecf4cf383b72c3920f0e4
+yaf32le 7e0c94a67b37ce9fb102fc7e6aca01f6
yuv411p e4a040e0e786c4dae07d9d3f90a54905
yuv422p 16ce67249c6ce7ef57a433646ad6dfc1
yuv422p10be 62ae323dcc41aabf8ff6ecc53b119ce8
diff --git a/tests/ref/fate/filter-pixfmts-hflip b/tests/ref/fate/filter-pixfmts-hflip
index 76b21757e2..05fc467a9d 100644
--- a/tests/ref/fate/filter-pixfmts-hflip
+++ b/tests/ref/fate/filter-pixfmts-hflip
@@ -119,8 +119,8 @@ xyz12le a8273fe17f2a738f3fd7f457de5c1df4
ya16be e7665e62e476df4eb143420e57cc9ec2
ya16le 3a23b71db418b74e1cc304d7cd3e1989
ya8 4ad5920716de3d2fbbc49f95adb60345
-yaf32be a0fd0741821b0734a6ecbcc989127e40
-yaf32le 3832240b5772affc0c04189200c35dd4
+yaf32be a167b4fa890b06259d7a15296822b87e
+yaf32le 920d0367d5292dacadaf451221b5874d
yuv410p c49fd0c55c41185b1580aac77211992b
yuv411p c416371077dce13d31bf1dc706111ae7
yuv420p eb8d9f02db98e10400781428c43e9438
diff --git a/tests/ref/fate/filter-pixfmts-il b/tests/ref/fate/filter-pixfmts-il
index b3824c3ac1..b790105e36 100644
--- a/tests/ref/fate/filter-pixfmts-il
+++ b/tests/ref/fate/filter-pixfmts-il
@@ -124,8 +124,8 @@ y216le 9e44c6d76b09bcbe71738423b4b3d67a
ya16be d08393d66f14fb1e31a9e9cbcb3df664
ya16le 372426fb917ea93365d775c3d1ef491a
ya8 a38d6e288f582f1a04310232ed764afc
-yaf32be 011351dda00897c16b407c96a1007f30
-yaf32le 47e7b8e817394855721e2397c9967c8c
+yaf32be b761a322922f30c5b1d14e428b267a76
+yaf32le 986cbcc484546eda7fcf57da21eb1224
yuv410p dea1ab8843465adf5b8240b2d98fd85b
yuv411p 8bf73777a5ff43c126be274245aceff1
yuv420p f1f4e7e94a76d5320049464bdeac24ed
diff --git a/tests/ref/fate/filter-pixfmts-null b/tests/ref/fate/filter-pixfmts-null
index 28e1102c94..5c02a63897 100644
--- a/tests/ref/fate/filter-pixfmts-null
+++ b/tests/ref/fate/filter-pixfmts-null
@@ -125,8 +125,8 @@ y216le 0e99aeddfee304e72d525d72998d9e9b
ya16be c7a868787e0f3d487dbc8af804d15d81
ya16le a5299b6c9cb1b5b1f5fb62546b9c6c4e
ya8 dbb99fbcdc204aaa1a7397ff561f1a67
-yaf32be 0d7f48b22abca63936637d8e22985299
-yaf32le decb6e2e85575573608c503af244df57
+yaf32be 0f4f26673a6fe8ba9b74ad45611c8488
+yaf32le eacd43d54c8127ee1b9f88d79545933f
yuv410p 5d4d992a7728431aa4e0700f87fb7fd8
yuv411p 7e1300e89f5bc07939e2c4a6acbdf267
yuv420p a014c7eb7a8385d1dd092b7a583f1bff
diff --git a/tests/ref/fate/filter-pixfmts-scale b/tests/ref/fate/filter-pixfmts-scale
index c8a3cff578..54f0db1a76 100644
--- a/tests/ref/fate/filter-pixfmts-scale
+++ b/tests/ref/fate/filter-pixfmts-scale
@@ -125,8 +125,8 @@ y216le 17be2999e97d36b8ed903f07ef428c09
ya16be 2c473f0f4c9330c1ed61bcc80ee11022
ya16le 76d4ff84d1014db24397f936dad9d0fa
ya8 0a9db5bb4b009de9197eede5e9d19e16
-yaf32be e3aad2e56b46ac9ecb7cdb76de8bd954
-yaf32le 7ece90b90ad6e132421a9feea6273a3e
+yaf32be 485ab8e871268a1e1a441055fe07be8c
+yaf32le 075edf21cc05db2c98db56af25dd0b15
yuv410p e8f49b5fb9335b62c074f7f8bb0234fc
yuv411p 5af32557c93beb482e26e7af693104c6
yuv420p 5d3ac239c3712143560b1dfbd48a7ddd
diff --git a/tests/ref/fate/filter-pixfmts-transpose b/tests/ref/fate/filter-pixfmts-transpose
index f492c2c3ba..4b07f1bd79 100644
--- a/tests/ref/fate/filter-pixfmts-transpose
+++ b/tests/ref/fate/filter-pixfmts-transpose
@@ -109,8 +109,8 @@ xyz12le 77912a89e6525f6809d8c31fed87a439
ya16be 9bb39f9567d807be0fb8631dcfa8d5f8
ya16le b13453818b83c8dc2610975095393ac1
ya8 d4b7a62f80681fa44c977ff3a64f4ce4
-yaf32be b8e5b5fdfc7cbc60f47d93a34d4277b0
-yaf32le c1905efebcef8574bdf883bceb158434
+yaf32be a117a36318e1bba2b5265d153fb0f045
+yaf32le ba12f8a6a60b8d367ce73dabaa790164
yuv410p 4c0143429edd30aa01493447c90132ea
yuv420p 2fa5b2201c75034206cc20e2c6134aed
yuv420p10be 0931660f930d9be8aea9d0c76b406055
diff --git a/tests/ref/fate/filter-pixfmts-vflip b/tests/ref/fate/filter-pixfmts-vflip
index d5ca454c85..7f08bc9254 100644
--- a/tests/ref/fate/filter-pixfmts-vflip
+++ b/tests/ref/fate/filter-pixfmts-vflip
@@ -125,8 +125,8 @@ y216le 985db498aedf3fb1c547ad07442b7258
ya16be 633230e223ca00e8398e46514d35422d
ya16le 9bee2882baafbfeba9adb8787c61f2f4
ya8 4299c6ca3b470a7d8a420e26eb485b1d
-yaf32be 24987299dc2a16dd391d7d48b94c3d64
-yaf32le 09b87da5eeaeabc36bdbcd49955cc05f
+yaf32be 782a52cad5a7ded8ca0b3e3069f50517
+yaf32le 5cdc04f5ab16d9780ac0e92857f72718
yuv410p c7adfe96c8e043a6cb9290c39bf8063c
yuv411p 3fce29db403a25f81be39e01aaf6ff3a
yuv420p d64fae96fac22aefa8fbcf45a09f37c1