+static av_always_inline void
+yuv2gray16_X_c_template(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, enum PixelFormat target)
+{
+ int i;
+
+#define output_pixel(pos, val) \
+ if (target == PIX_FMT_GRAY16BE) { \
+ AV_WB16(pos, val); \
+ } else { \
+ AV_WL16(pos, val); \
+ }
+ for (i = 0; i < (dstW >> 1); i++) {
+ int j;
+ int Y1 = 1 << 18;
+ int Y2 = 1 << 18;
+ const int i2 = 2 * i;
+
+ for (j = 0; j < lumFilterSize; j++) {
+ Y1 += lumSrc[j][i2] * lumFilter[j];
+ Y2 += lumSrc[j][i2+1] * lumFilter[j];
+ }
+ Y1 >>= 11;
+ Y2 >>= 11;
+ if ((Y1 | Y2) & 0x10000) {
+ Y1 = av_clip_uint16(Y1);
+ Y2 = av_clip_uint16(Y2);
+ }
+ output_pixel(&dest[2 * i2 + 0], Y1);
+ output_pixel(&dest[2 * i2 + 2], Y2);
+ }
+}
+
+static av_always_inline void
+yuv2gray16_2_c_template(SwsContext *c, const uint16_t *buf0,
+ const uint16_t *buf1, const uint16_t *ubuf0,
+ const uint16_t *ubuf1, const uint16_t *vbuf0,
+ const uint16_t *vbuf1, const uint16_t *abuf0,
+ const uint16_t *abuf1, uint8_t *dest, int dstW,
+ int yalpha, int uvalpha, int y,
+ enum PixelFormat target)
+{
+ int yalpha1 = 4095 - yalpha; \
+ int i;
+
+ for (i = 0; i < (dstW >> 1); i++) {
+ const int i2 = 2 * i;
+ int Y1 = (buf0[i2 ] * yalpha1 + buf1[i2 ] * yalpha) >> 11;
+ int Y2 = (buf0[i2+1] * yalpha1 + buf1[i2+1] * yalpha) >> 11;
+
+ output_pixel(&dest[2 * i2 + 0], Y1);
+ output_pixel(&dest[2 * i2 + 2], Y2);
+ }
+}
+
+static av_always_inline void
+yuv2gray16_1_c_template(SwsContext *c, const uint16_t *buf0,
+ const uint16_t *ubuf0, const uint16_t *ubuf1,
+ const uint16_t *vbuf0, const uint16_t *vbuf1,
+ const uint16_t *abuf0, uint8_t *dest, int dstW,
+ int uvalpha, enum PixelFormat dstFormat,
+ int flags, int y, enum PixelFormat target)
+{
+ int i;
+
+ for (i = 0; i < (dstW >> 1); i++) {
+ const int i2 = 2 * i;
+ int Y1 = buf0[i2 ] << 1;
+ int Y2 = buf0[i2+1] << 1;
+
+ output_pixel(&dest[2 * i2 + 0], Y1);
+ output_pixel(&dest[2 * i2 + 2], Y2);
+ }
+#undef output_pixel
+}
+
+#define YUV2PACKEDWRAPPER(name, ext, fmt) \
+static void name ## ext ## _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) \
+{ \
+ name ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \
+ chrFilter, chrUSrc, chrVSrc, chrFilterSize, \
+ alpSrc, dest, dstW, y, fmt); \
+} \
+ \
+static void name ## ext ## _2_c(SwsContext *c, const uint16_t *buf0, \
+ const uint16_t *buf1, const uint16_t *ubuf0, \
+ const uint16_t *ubuf1, const uint16_t *vbuf0, \
+ const uint16_t *vbuf1, const uint16_t *abuf0, \
+ const uint16_t *abuf1, uint8_t *dest, int dstW, \
+ int yalpha, int uvalpha, int y) \
+{ \
+ name ## _2_c_template(c, buf0, buf1, ubuf0, ubuf1, \
+ vbuf0, vbuf1, abuf0, abuf1, \
+ dest, dstW, yalpha, uvalpha, y, fmt); \
+} \
+ \
+static void name ## ext ## _1_c(SwsContext *c, const uint16_t *buf0, \
+ const uint16_t *ubuf0, const uint16_t *ubuf1, \
+ const uint16_t *vbuf0, const uint16_t *vbuf1, \
+ const uint16_t *abuf0, uint8_t *dest, int dstW, \
+ int uvalpha, enum PixelFormat dstFormat, \
+ int flags, int y) \
+{ \
+ name ## _1_c_template(c, buf0, ubuf0, ubuf1, vbuf0, \
+ vbuf1, abuf0, dest, dstW, uvalpha, \
+ dstFormat, flags, y, fmt); \
+}
+
+YUV2PACKEDWRAPPER(yuv2gray16, LE, PIX_FMT_GRAY16LE);
+YUV2PACKEDWRAPPER(yuv2gray16, BE, PIX_FMT_GRAY16BE);
+