aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/utils.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2018-12-24 01:14:51 +0100
committerMichael Niedermayer <michael@niedermayer.cc>2020-07-01 12:49:26 +0200
commit71e047e45ce69f46c33ad26e86d25954473d602a (patch)
tree77a5d4bdf819b983997f2d1eef2f751c95ac4bb7 /libavcodec/utils.c
parent8527e9702cf1ed7c5582c3f8e6c17c6fc7e256cd (diff)
downloadffmpeg-71e047e45ce69f46c33ad26e86d25954473d602a.tar.gz
avcodec/utils: Optimize ff_color_frame() using memcpy()
4650975 -> 4493240 dezicycles This optimizes lines 2 and later. Line 1 still uses av_memcpy_backptr() This change originally fixed ossfuzz 10790 but this is now fixed by other optimizations already Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> (cherry picked from commit 95e5396919b13a00264466b5d766f80f1a4f7fdc) Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavcodec/utils.c')
-rw-r--r--libavcodec/utils.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 5333f03746..e0643fddc3 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -717,13 +717,19 @@ void ff_color_frame(AVFrame *frame, const int c[4])
int is_chroma = p == 1 || p == 2;
int bytes = is_chroma ? AV_CEIL_RSHIFT(frame->width, desc->log2_chroma_w) : frame->width;
int height = is_chroma ? AV_CEIL_RSHIFT(frame->height, desc->log2_chroma_h) : frame->height;
- for (y = 0; y < height; y++) {
- if (desc->comp[0].depth >= 9) {
- ((uint16_t*)dst)[0] = c[p];
- av_memcpy_backptr(dst + 2, 2, bytes - 2);
- }else
- memset(dst, c[p], bytes);
+ if (desc->comp[0].depth >= 9) {
+ ((uint16_t*)dst)[0] = c[p];
+ av_memcpy_backptr(dst + 2, 2, bytes - 2);
dst += frame->linesize[p];
+ for (y = 1; y < height; y++) {
+ memcpy(dst, frame->data[p], 2*bytes);
+ dst += frame->linesize[p];
+ }
+ } else {
+ for (y = 0; y < height; y++) {
+ memset(dst, c[p], bytes);
+ dst += frame->linesize[p];
+ }
}
}
}