]> granicus.if.org Git - libvpx/blob - vp9/encoder/vp9_frame_scale.c
Merge changes I92eb4312,Ibb2afe4e
[libvpx] / vp9 / encoder / vp9_frame_scale.c
1 /*
2  *  Copyright (c) 2017 The WebM project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10
11 #include "./vp9_rtcd.h"
12 #include "./vpx_dsp_rtcd.h"
13 #include "./vpx_scale_rtcd.h"
14 #include "vp9/common/vp9_blockd.h"
15 #include "vpx_dsp/vpx_filter.h"
16 #include "vpx_scale/yv12config.h"
17
18 void vp9_scale_and_extend_frame_c(const YV12_BUFFER_CONFIG *src,
19                                   YV12_BUFFER_CONFIG *dst,
20                                   INTERP_FILTER filter_type, int phase_scaler) {
21   const int src_w = src->y_crop_width;
22   const int src_h = src->y_crop_height;
23   const int dst_w = dst->y_crop_width;
24   const int dst_h = dst->y_crop_height;
25   const uint8_t *const srcs[3] = { src->y_buffer, src->u_buffer,
26                                    src->v_buffer };
27   const int src_strides[3] = { src->y_stride, src->uv_stride, src->uv_stride };
28   uint8_t *const dsts[3] = { dst->y_buffer, dst->u_buffer, dst->v_buffer };
29   const int dst_strides[3] = { dst->y_stride, dst->uv_stride, dst->uv_stride };
30   const InterpKernel *const kernel = vp9_filter_kernels[filter_type];
31   int x, y, i;
32
33   for (i = 0; i < MAX_MB_PLANE; ++i) {
34     const int factor = (i == 0 || i == 3 ? 1 : 2);
35     const int src_stride = src_strides[i];
36     const int dst_stride = dst_strides[i];
37     for (y = 0; y < dst_h; y += 16) {
38       const int y_q4 = y * (16 / factor) * src_h / dst_h + phase_scaler;
39       for (x = 0; x < dst_w; x += 16) {
40         const int x_q4 = x * (16 / factor) * src_w / dst_w + phase_scaler;
41         const uint8_t *src_ptr = srcs[i] +
42                                  (y / factor) * src_h / dst_h * src_stride +
43                                  (x / factor) * src_w / dst_w;
44         uint8_t *dst_ptr = dsts[i] + (y / factor) * dst_stride + (x / factor);
45
46         vpx_scaled_2d(src_ptr, src_stride, dst_ptr, dst_stride,
47                       kernel[x_q4 & 0xf], 16 * src_w / dst_w,
48                       kernel[y_q4 & 0xf], 16 * src_h / dst_h, 16 / factor,
49                       16 / factor);
50       }
51     }
52   }
53
54   vpx_extend_frame_borders(dst);
55 }