[FFmpeg-devel] [PATCH v2 2/2] libswscale: add AVBSwapDSPContext and use
mindmark at gmail.com
mindmark at gmail.com
Tue Dec 6 00:16:41 EET 2022
From: Mark Reid <mindmark at gmail.com>
There are some places in input.c that could use it too
but they aren't currently being pass the SwsContext
---
libswscale/output.c | 36 +++++++++++++++--------------------
libswscale/swscale_internal.h | 3 +++
libswscale/swscale_unscaled.c | 26 +++++++++----------------
libswscale/utils.c | 2 ++
4 files changed, 29 insertions(+), 38 deletions(-)
diff --git a/libswscale/output.c b/libswscale/output.c
index 5c85bff971..cd44081e3d 100644
--- a/libswscale/output.c
+++ b/libswscale/output.c
@@ -2313,13 +2313,11 @@ yuv2gbrp_full_X_c(SwsContext *c, const int16_t *lumFilter,
}
}
if (SH != 22 && (!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
- for (i = 0; i < dstW; i++) {
- dest16[0][i] = av_bswap16(dest16[0][i]);
- dest16[1][i] = av_bswap16(dest16[1][i]);
- dest16[2][i] = av_bswap16(dest16[2][i]);
- if (hasAlpha)
- dest16[3][i] = av_bswap16(dest16[3][i]);
- }
+ c->bsdsp.bswap16_buf(dest16[0], dest16[0], dstW);
+ c->bsdsp.bswap16_buf(dest16[1], dest16[1], dstW);
+ c->bsdsp.bswap16_buf(dest16[2], dest16[2], dstW);
+ if (hasAlpha)
+ c->bsdsp.bswap16_buf(dest16[3], dest16[3], dstW);
}
}
@@ -2385,13 +2383,11 @@ yuv2gbrp16_full_X_c(SwsContext *c, const int16_t *lumFilter,
dest16[3][i] = av_clip_uintp2(A, 30) >> 14;
}
if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
- for (i = 0; i < dstW; i++) {
- dest16[0][i] = av_bswap16(dest16[0][i]);
- dest16[1][i] = av_bswap16(dest16[1][i]);
- dest16[2][i] = av_bswap16(dest16[2][i]);
- if (hasAlpha)
- dest16[3][i] = av_bswap16(dest16[3][i]);
- }
+ c->bsdsp.bswap16_buf(dest16[0], dest16[0], dstW);
+ c->bsdsp.bswap16_buf(dest16[1], dest16[1], dstW);
+ c->bsdsp.bswap16_buf(dest16[2], dest16[2], dstW);
+ if (hasAlpha)
+ c->bsdsp.bswap16_buf(dest16[3], dest16[3], dstW);
}
}
@@ -2461,13 +2457,11 @@ yuv2gbrpf32_full_X_c(SwsContext *c, const int16_t *lumFilter,
dest32[3][i] = av_float2int(float_mult * (float)(av_clip_uintp2(A, 30) >> 14));
}
if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
- for (i = 0; i < dstW; i++) {
- dest32[0][i] = av_bswap32(dest32[0][i]);
- dest32[1][i] = av_bswap32(dest32[1][i]);
- dest32[2][i] = av_bswap32(dest32[2][i]);
- if (hasAlpha)
- dest32[3][i] = av_bswap32(dest32[3][i]);
- }
+ c->bsdsp.bswap32_buf(dest32[0], dest32[0], dstW);
+ c->bsdsp.bswap32_buf(dest32[1], dest32[1], dstW);
+ c->bsdsp.bswap32_buf(dest32[2], dest32[2], dstW);
+ if (hasAlpha)
+ c->bsdsp.bswap32_buf(dest32[3], dest32[3], dstW);
}
}
diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h
index abeebbb002..400f0bc8ed 100644
--- a/libswscale/swscale_internal.h
+++ b/libswscale/swscale_internal.h
@@ -26,6 +26,7 @@
#include "config.h"
#include "libavutil/avassert.h"
+#include "libavutil/bswapdsp.h"
#include "libavutil/common.h"
#include "libavutil/frame.h"
#include "libavutil/intreadwrite.h"
@@ -682,6 +683,8 @@ typedef struct SwsContext {
atomic_int data_unaligned_warned;
Half2FloatTables *h2f_tables;
+
+ AVBSwapDSPContext bsdsp;
} SwsContext;
//FIXME check init (where 0)
diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c
index 9af2e7ecc3..0010ab24d1 100644
--- a/libswscale/swscale_unscaled.c
+++ b/libswscale/swscale_unscaled.c
@@ -468,7 +468,7 @@ static int bswap_16bpc(SwsContext *c, const uint8_t *src[],
int srcStride[], int srcSliceY, int srcSliceH,
uint8_t *dst[], int dstStride[])
{
- int i, j, p;
+ int i, p;
for (p = 0; p < 4; p++) {
int srcstr = srcStride[p] / 2;
@@ -480,9 +480,7 @@ static int bswap_16bpc(SwsContext *c, const uint8_t *src[],
continue;
dstPtr += (srcSliceY >> c->chrDstVSubSample) * dststr;
for (i = 0; i < (srcSliceH >> c->chrDstVSubSample); i++) {
- for (j = 0; j < min_stride; j++) {
- dstPtr[j] = av_bswap16(srcPtr[j]);
- }
+ c->bsdsp.bswap16_buf(dstPtr, srcPtr, min_stride);
srcPtr += srcstr;
dstPtr += dststr;
}
@@ -495,7 +493,7 @@ static int bswap_32bpc(SwsContext *c, const uint8_t *src[],
int srcStride[], int srcSliceY, int srcSliceH,
uint8_t *dst[], int dstStride[])
{
- int i, j, p;
+ int i, p;
for (p = 0; p < 4; p++) {
int srcstr = srcStride[p] / 4;
@@ -507,9 +505,7 @@ static int bswap_32bpc(SwsContext *c, const uint8_t *src[],
continue;
dstPtr += (srcSliceY >> c->chrDstVSubSample) * dststr;
for (i = 0; i < (srcSliceH >> c->chrDstVSubSample); i++) {
- for (j = 0; j < min_stride; j++) {
- dstPtr[j] = av_bswap32(srcPtr[j]);
- }
+ c->bsdsp.bswap32_buf(dstPtr, srcPtr, min_stride);
srcPtr += srcstr;
dstPtr += dststr;
}
@@ -1616,19 +1612,17 @@ static int rgbToRgbWrapper(SwsContext *c, const uint8_t *src[], int srcStride[],
conv(srcPtr, dstPtr + dstStride[0] * srcSliceY,
(srcSliceH - 1) * srcStride[0] + c->srcW * srcBpp);
else {
- int i, j;
+ int i;
dstPtr += dstStride[0] * srcSliceY;
for (i = 0; i < srcSliceH; i++) {
if(src_bswap) {
- for(j=0; j<c->srcW; j++)
- ((uint16_t*)c->formatConvBuffer)[j] = av_bswap16(((uint16_t*)srcPtr)[j]);
+ c->bsdsp.bswap16_buf((uint16_t*)c->formatConvBuffer, (uint16_t*)srcPtr, c->srcW);
conv(c->formatConvBuffer, dstPtr, c->srcW * srcBpp);
}else
conv(srcPtr, dstPtr, c->srcW * srcBpp);
if(dst_bswap)
- for(j=0; j<c->srcW; j++)
- ((uint16_t*)dstPtr)[j] = av_bswap16(((uint16_t*)dstPtr)[j]);
+ c->bsdsp.bswap16_buf((uint16_t*)dstPtr, (uint16_t*)dstPtr, c->srcW);
srcPtr += srcStride[0];
dstPtr += dstStride[0];
}
@@ -1932,16 +1926,14 @@ static int planarCopyWrapper(SwsContext *c, const uint8_t *src[],
isBE(c->srcFormat) != isBE(c->dstFormat)) {
for (i = 0; i < height; i++) {
- for (j = 0; j < length; j++)
- ((uint16_t *) dstPtr)[j] = av_bswap16(((const uint16_t *) srcPtr)[j]);
+ c->bsdsp.bswap16_buf((uint16_t *)dstPtr, (const uint16_t *)srcPtr, length);
srcPtr += srcStride[plane];
dstPtr += dstStride[plane];
}
} else if (isFloat(c->srcFormat) && isFloat(c->dstFormat) &&
isBE(c->srcFormat) != isBE(c->dstFormat)) { /* swap float plane */
for (i = 0; i < height; i++) {
- for (j = 0; j < length; j++)
- ((uint32_t *) dstPtr)[j] = av_bswap32(((const uint32_t *) srcPtr)[j]);
+ c->bsdsp.bswap32_buf((uint32_t *)dstPtr, (const uint32_t *)srcPtr, length);
srcPtr += srcStride[plane];
dstPtr += dstStride[plane];
}
diff --git a/libswscale/utils.c b/libswscale/utils.c
index 90734f66ef..0514062d85 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -1921,6 +1921,8 @@ static av_cold int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter,
return 0;
}
+ av_bswapdsp_init(&c->bsdsp);
+
/* unscaled special cases */
if (unscaled && !usesHFilter && !usesVFilter &&
(c->srcRange == c->dstRange || isAnyRGB(dstFormat) ||
--
2.31.1.windows.1
More information about the ffmpeg-devel
mailing list