Skip to content
Snippets Groups Projects
Commit b0a4abc8 authored by Guillaume Roguez's avatar Guillaume Roguez
Browse files

video_scaler: fix VideoScaler::scale_and_pad

This method doesn't shift correctly in case of YUYV422 output format.
This patch simplify the code and force the x-shift to be correct.

Issue: #81116
Change-Id: I049d61f51a944476f5a1c3743ecb905308becc83
parent 485da039
Branches
Tags
No related merge requests found
...@@ -117,17 +117,19 @@ VideoScaler::scale_and_pad(const VideoFrame& input, VideoFrame& output, ...@@ -117,17 +117,19 @@ VideoScaler::scale_and_pad(const VideoFrame& input, VideoFrame& output,
// Make an offset'ed copy of output data from xoff and yoff // Make an offset'ed copy of output data from xoff and yoff
const auto out_desc = av_pix_fmt_desc_get((AVPixelFormat)output_frame->format); const auto out_desc = av_pix_fmt_desc_get((AVPixelFormat)output_frame->format);
if (libav_utils::is_yuv_planar(*out_desc)) { memset(tmp_data_, 0, sizeof(tmp_data_));
unsigned x_shift = out_desc->log2_chroma_w; for (int i = 0; i < 4 && output_frame->linesize[i]; i++) {
unsigned y_shift = out_desc->log2_chroma_h; unsigned x_shift=xoff, y_shift=yoff;
if (i == 1 || i == 2) {
tmp_data_[0] = output_frame->data[0] + yoff * output_frame->linesize[0] + xoff; x_shift = -((-x_shift) >> out_desc->log2_chroma_w);
tmp_data_[1] = output_frame->data[1] + (yoff >> y_shift) * output_frame->linesize[1] + (xoff >> x_shift); y_shift = -((-y_shift) >> out_desc->log2_chroma_h);
tmp_data_[2] = output_frame->data[2] + (yoff >> y_shift) * output_frame->linesize[2] + (xoff >> x_shift); }
tmp_data_[3] = nullptr; #if LIBAVUTIL_VERSION_MAJOR < 56
} else { auto x_step = out_desc->comp[i].step_minus1 + 1; // using deprecated api
memcpy(tmp_data_, output_frame->data, sizeof(tmp_data_)); #else
tmp_data_[0] += yoff * output_frame->linesize[0] + xoff; auto x_step = out_desc->comp[i].step;
#endif
tmp_data_[i] = output_frame->data[i] + y_shift * output_frame->linesize[i] + x_shift * x_step;
} }
sws_scale(ctx_, input_frame->data, input_frame->linesize, 0, sws_scale(ctx_, input_frame->data, input_frame->linesize, 0,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment