History

avcodec/mpegvideo_dec: Don't memset twice

This has been done for the luma plane of missing FLV1 and H263 references. Also remove code duplication by reusing gray_frame(), which has been renamed to color_frame() for this purpose.

Andreas Rheinhardt committed 3 years ago

Commit 06388251 parent 3ede6cc1 file · +5 −23Browse files

Unified · Split

libavcodec/mpegvideo_dec.c+5−23
@@ -245,12 +245,12 @@ static int alloc_picture(MpegEncContext *s, Picture *pic) · 244 unmodified lines
245245 &s->linesize, &s->uvlinesize);
246246 }
247247
248−static void gray_frame(AVFrame *frame)
248+static void color_frame(AVFrame *frame, int luma)
249249 {
250250 int h_chroma_shift, v_chroma_shift;
251251
252252 for (int i = 0; i < frame->height; i++)
253− memset(frame->data[0] + frame->linesize[0] * i, 0x80, frame->width);
253+ memset(frame->data[0] + frame->linesize[0] * i, luma, frame->width);
254254
255255 if (!frame->data[1])
256256 return;
@@ -365,9 +365,6 @@ FF_ENABLE_DEPRECATION_WARNINGS · 108 unmodified lines
365365
366366 if ((!s->last_picture_ptr || !s->last_picture_ptr->f->buf[0]) &&
367367 (s->pict_type != AV_PICTURE_TYPE_I)) {
368− int h_chroma_shift, v_chroma_shift;
369− av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt,
370− &h_chroma_shift, &v_chroma_shift);
371368 if (s->pict_type == AV_PICTURE_TYPE_B && s->next_picture_ptr && s->next_picture_ptr->f->buf[0])
372369 av_log(avctx, AV_LOG_DEBUG,
373370 "allocating dummy last picture for B frame\n");
@@ -393,23 +390,8 @@ FF_ENABLE_DEPRECATION_WARNINGS · 19 unmodified lines
393390 }
394391
395392 if (!avctx->hwaccel) {
396− for (int i = 0; i < avctx->height; i++)
397− memset(s->last_picture_ptr->f->data[0] + s->last_picture_ptr->f->linesize[0]*i,
398− 0x80, avctx->width);
399− if (s->last_picture_ptr->f->data[2]) {
400− for (int i = 0; i < AV_CEIL_RSHIFT(avctx->height, v_chroma_shift); i++) {
401− memset(s->last_picture_ptr->f->data[1] + s->last_picture_ptr->f->linesize[1]*i,
402− 0x80, AV_CEIL_RSHIFT(avctx->width, h_chroma_shift));
403− memset(s->last_picture_ptr->f->data[2] + s->last_picture_ptr->f->linesize[2]*i,
404− 0x80, AV_CEIL_RSHIFT(avctx->width, h_chroma_shift));
405− }
406− }
407−
408− if (s->codec_id == AV_CODEC_ID_FLV1 || s->codec_id == AV_CODEC_ID_H263) {
409− for (int i = 0; i < avctx->height; i++)
410− memset(s->last_picture_ptr->f->data[0] + s->last_picture_ptr->f->linesize[0] * i,
411− 16, avctx->width);
412− }
393+ int luma_val = s->codec_id == AV_CODEC_ID_FLV1 || s->codec_id == AV_CODEC_ID_H263 ? 16 : 0x80;
394+ color_frame(s->last_picture_ptr->f, luma_val);
413395 }
414396
415397 ff_thread_report_progress(&s->last_picture_ptr->tf, INT_MAX, 0);
@@ -480,7 +462,7 @@ FF_ENABLE_DEPRECATION_WARNINGS · 64 unmodified lines
480462 }
481463
482464 if (s->avctx->debug & FF_DEBUG_NOMC)
483− gray_frame(s->current_picture_ptr->f);
465+ color_frame(s->current_picture_ptr->f, 0x80);
484466
485467 return 0;
486468 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t