aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2018-12-24 01:14:51 +0100
committerMichael Niedermayer <michael@niedermayer.cc>2020-01-06 11:30:43 +0100
commit18e5ce4d0d779d31858274d02851aa33ee831927 (patch)
tree0788fcac885cbf96d413b776f6952d83daccaa84 /libavcodec
parente6cff05befb185642f4cd6d98e88faf076930ff5 (diff)
downloadffmpeg-18e5ce4d0d779d31858274d02851aa33ee831927.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')
-rw-r--r--libavcodec/utils.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 41153d1c1c..10259ba664 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -417,13 +417,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];
+ }
}
}
}