OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <limits.h> | 11 #include <limits.h> |
12 #include <math.h> | 12 #include <math.h> |
13 #include <stdio.h> | 13 #include <stdio.h> |
14 | 14 |
15 #include "./vpx_config.h" | 15 #include "./vpx_config.h" |
| 16 #include "./vpx_dsp_rtcd.h" |
16 | 17 |
17 #include "vpx_mem/vpx_mem.h" | 18 #include "vpx_mem/vpx_mem.h" |
| 19 #include "vpx_ports/mem.h" |
18 | 20 |
19 #include "vp9/common/vp9_common.h" | 21 #include "vp9/common/vp9_common.h" |
| 22 #include "vp9/common/vp9_reconinter.h" |
20 | 23 |
21 #include "vp9/encoder/vp9_encoder.h" | 24 #include "vp9/encoder/vp9_encoder.h" |
22 #include "vp9/encoder/vp9_mcomp.h" | 25 #include "vp9/encoder/vp9_mcomp.h" |
23 | 26 |
24 // #define NEW_DIAMOND_SEARCH | 27 // #define NEW_DIAMOND_SEARCH |
25 | 28 |
26 static INLINE const uint8_t *get_buf_from_mv(const struct buf_2d *buf, | 29 static INLINE const uint8_t *get_buf_from_mv(const struct buf_2d *buf, |
27 const MV *mv) { | 30 const MV *mv) { |
28 return &buf->buf[mv->row * buf->stride + mv->col]; | 31 return &buf->buf[mv->row * buf->stride + mv->col]; |
29 } | 32 } |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 const uint8_t *second_pred, | 298 const uint8_t *second_pred, |
296 int w, int h, int offset, | 299 int w, int h, int offset, |
297 int *mvjcost, int *mvcost[2], | 300 int *mvjcost, int *mvcost[2], |
298 unsigned int *sse1, | 301 unsigned int *sse1, |
299 int *distortion) { | 302 int *distortion) { |
300 unsigned int besterr; | 303 unsigned int besterr; |
301 #if CONFIG_VP9_HIGHBITDEPTH | 304 #if CONFIG_VP9_HIGHBITDEPTH |
302 if (second_pred != NULL) { | 305 if (second_pred != NULL) { |
303 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { | 306 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
304 DECLARE_ALIGNED(16, uint16_t, comp_pred16[64 * 64]); | 307 DECLARE_ALIGNED(16, uint16_t, comp_pred16[64 * 64]); |
305 vp9_highbd_comp_avg_pred(comp_pred16, second_pred, w, h, y + offset, | 308 vpx_highbd_comp_avg_pred(comp_pred16, second_pred, w, h, y + offset, |
306 y_stride); | 309 y_stride); |
307 besterr = vfp->vf(CONVERT_TO_BYTEPTR(comp_pred16), w, src, src_stride, | 310 besterr = vfp->vf(CONVERT_TO_BYTEPTR(comp_pred16), w, src, src_stride, |
308 sse1); | 311 sse1); |
309 } else { | 312 } else { |
310 DECLARE_ALIGNED(16, uint8_t, comp_pred[64 * 64]); | 313 DECLARE_ALIGNED(16, uint8_t, comp_pred[64 * 64]); |
311 vp9_comp_avg_pred(comp_pred, second_pred, w, h, y + offset, y_stride); | 314 vpx_comp_avg_pred(comp_pred, second_pred, w, h, y + offset, y_stride); |
312 besterr = vfp->vf(comp_pred, w, src, src_stride, sse1); | 315 besterr = vfp->vf(comp_pred, w, src, src_stride, sse1); |
313 } | 316 } |
314 } else { | 317 } else { |
315 besterr = vfp->vf(y + offset, y_stride, src, src_stride, sse1); | 318 besterr = vfp->vf(y + offset, y_stride, src, src_stride, sse1); |
316 } | 319 } |
317 *distortion = besterr; | 320 *distortion = besterr; |
318 besterr += mv_err_cost(bestmv, ref_mv, mvjcost, mvcost, error_per_bit); | 321 besterr += mv_err_cost(bestmv, ref_mv, mvjcost, mvcost, error_per_bit); |
319 #else | 322 #else |
320 (void) xd; | 323 (void) xd; |
321 if (second_pred != NULL) { | 324 if (second_pred != NULL) { |
322 DECLARE_ALIGNED(16, uint8_t, comp_pred[64 * 64]); | 325 DECLARE_ALIGNED(16, uint8_t, comp_pred[64 * 64]); |
323 vp9_comp_avg_pred(comp_pred, second_pred, w, h, y + offset, y_stride); | 326 vpx_comp_avg_pred(comp_pred, second_pred, w, h, y + offset, y_stride); |
324 besterr = vfp->vf(comp_pred, w, src, src_stride, sse1); | 327 besterr = vfp->vf(comp_pred, w, src, src_stride, sse1); |
325 } else { | 328 } else { |
326 besterr = vfp->vf(y + offset, y_stride, src, src_stride, sse1); | 329 besterr = vfp->vf(y + offset, y_stride, src, src_stride, sse1); |
327 } | 330 } |
328 *distortion = besterr; | 331 *distortion = besterr; |
329 besterr += mv_err_cost(bestmv, ref_mv, mvjcost, mvcost, error_per_bit); | 332 besterr += mv_err_cost(bestmv, ref_mv, mvjcost, mvcost, error_per_bit); |
330 #endif // CONFIG_VP9_HIGHBITDEPTH | 333 #endif // CONFIG_VP9_HIGHBITDEPTH |
331 return besterr; | 334 return besterr; |
332 } | 335 } |
333 | 336 |
(...skipping 1447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1781 } | 1784 } |
1782 | 1785 |
1783 return (center - (bw >> 1)); | 1786 return (center - (bw >> 1)); |
1784 } | 1787 } |
1785 | 1788 |
1786 static const MV search_pos[4] = { | 1789 static const MV search_pos[4] = { |
1787 {-1, 0}, {0, -1}, {0, 1}, {1, 0}, | 1790 {-1, 0}, {0, -1}, {0, 1}, {1, 0}, |
1788 }; | 1791 }; |
1789 | 1792 |
1790 unsigned int vp9_int_pro_motion_estimation(const VP9_COMP *cpi, MACROBLOCK *x, | 1793 unsigned int vp9_int_pro_motion_estimation(const VP9_COMP *cpi, MACROBLOCK *x, |
1791 BLOCK_SIZE bsize) { | 1794 BLOCK_SIZE bsize, |
| 1795 int mi_row, int mi_col) { |
1792 MACROBLOCKD *xd = &x->e_mbd; | 1796 MACROBLOCKD *xd = &x->e_mbd; |
| 1797 MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; |
| 1798 struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0, 0}}; |
1793 DECLARE_ALIGNED(16, int16_t, hbuf[128]); | 1799 DECLARE_ALIGNED(16, int16_t, hbuf[128]); |
1794 DECLARE_ALIGNED(16, int16_t, vbuf[128]); | 1800 DECLARE_ALIGNED(16, int16_t, vbuf[128]); |
1795 DECLARE_ALIGNED(16, int16_t, src_hbuf[64]); | 1801 DECLARE_ALIGNED(16, int16_t, src_hbuf[64]); |
1796 DECLARE_ALIGNED(16, int16_t, src_vbuf[64]); | 1802 DECLARE_ALIGNED(16, int16_t, src_vbuf[64]); |
1797 int idx; | 1803 int idx; |
1798 const int bw = 4 << b_width_log2_lookup[bsize]; | 1804 const int bw = 4 << b_width_log2_lookup[bsize]; |
1799 const int bh = 4 << b_height_log2_lookup[bsize]; | 1805 const int bh = 4 << b_height_log2_lookup[bsize]; |
1800 const int search_width = bw << 1; | 1806 const int search_width = bw << 1; |
1801 const int search_height = bh << 1; | 1807 const int search_height = bh << 1; |
1802 const int src_stride = x->plane[0].src.stride; | 1808 const int src_stride = x->plane[0].src.stride; |
1803 const int ref_stride = xd->plane[0].pre[0].stride; | 1809 const int ref_stride = xd->plane[0].pre[0].stride; |
1804 uint8_t const *ref_buf, *src_buf; | 1810 uint8_t const *ref_buf, *src_buf; |
1805 MV *tmp_mv = &xd->mi[0]->mbmi.mv[0].as_mv; | 1811 MV *tmp_mv = &xd->mi[0]->mbmi.mv[0].as_mv; |
1806 unsigned int best_sad, tmp_sad, this_sad[4]; | 1812 unsigned int best_sad, tmp_sad, this_sad[4]; |
1807 MV this_mv; | 1813 MV this_mv; |
1808 const int norm_factor = 3 + (bw >> 5); | 1814 const int norm_factor = 3 + (bw >> 5); |
| 1815 const YV12_BUFFER_CONFIG *scaled_ref_frame = |
| 1816 vp9_get_scaled_ref_frame(cpi, mbmi->ref_frame[0]); |
| 1817 |
| 1818 if (scaled_ref_frame) { |
| 1819 int i; |
| 1820 // Swap out the reference frame for a version that's been scaled to |
| 1821 // match the resolution of the current frame, allowing the existing |
| 1822 // motion search code to be used without additional modifications. |
| 1823 for (i = 0; i < MAX_MB_PLANE; i++) |
| 1824 backup_yv12[i] = xd->plane[i].pre[0]; |
| 1825 vp9_setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL); |
| 1826 } |
1809 | 1827 |
1810 #if CONFIG_VP9_HIGHBITDEPTH | 1828 #if CONFIG_VP9_HIGHBITDEPTH |
1811 tmp_mv->row = 0; | 1829 { |
1812 tmp_mv->col = 0; | 1830 unsigned int this_sad; |
1813 return cpi->fn_ptr[bsize].sdf(x->plane[0].src.buf, src_stride, | 1831 tmp_mv->row = 0; |
1814 xd->plane[0].pre[0].buf, ref_stride); | 1832 tmp_mv->col = 0; |
| 1833 this_sad = cpi->fn_ptr[bsize].sdf(x->plane[0].src.buf, src_stride, |
| 1834 xd->plane[0].pre[0].buf, ref_stride); |
| 1835 |
| 1836 if (scaled_ref_frame) { |
| 1837 int i; |
| 1838 for (i = 0; i < MAX_MB_PLANE; i++) |
| 1839 xd->plane[i].pre[0] = backup_yv12[i]; |
| 1840 } |
| 1841 return this_sad; |
| 1842 } |
1815 #endif | 1843 #endif |
1816 | 1844 |
1817 // Set up prediction 1-D reference set | 1845 // Set up prediction 1-D reference set |
1818 ref_buf = xd->plane[0].pre[0].buf - (bw >> 1); | 1846 ref_buf = xd->plane[0].pre[0].buf - (bw >> 1); |
1819 for (idx = 0; idx < search_width; idx += 16) { | 1847 for (idx = 0; idx < search_width; idx += 16) { |
1820 vp9_int_pro_row(&hbuf[idx], ref_buf, ref_stride, bh); | 1848 vp9_int_pro_row(&hbuf[idx], ref_buf, ref_stride, bh); |
1821 ref_buf += 16; | 1849 ref_buf += 16; |
1822 } | 1850 } |
1823 | 1851 |
1824 ref_buf = xd->plane[0].pre[0].buf - (bh >> 1) * ref_stride; | 1852 ref_buf = xd->plane[0].pre[0].buf - (bh >> 1) * ref_stride; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1882 tmp_sad = cpi->fn_ptr[bsize].sdf(src_buf, src_stride, | 1910 tmp_sad = cpi->fn_ptr[bsize].sdf(src_buf, src_stride, |
1883 ref_buf, ref_stride); | 1911 ref_buf, ref_stride); |
1884 if (best_sad > tmp_sad) { | 1912 if (best_sad > tmp_sad) { |
1885 *tmp_mv = this_mv; | 1913 *tmp_mv = this_mv; |
1886 best_sad = tmp_sad; | 1914 best_sad = tmp_sad; |
1887 } | 1915 } |
1888 | 1916 |
1889 tmp_mv->row *= 8; | 1917 tmp_mv->row *= 8; |
1890 tmp_mv->col *= 8; | 1918 tmp_mv->col *= 8; |
1891 | 1919 |
| 1920 if (scaled_ref_frame) { |
| 1921 int i; |
| 1922 for (i = 0; i < MAX_MB_PLANE; i++) |
| 1923 xd->plane[i].pre[0] = backup_yv12[i]; |
| 1924 } |
| 1925 |
1892 return best_sad; | 1926 return best_sad; |
1893 } | 1927 } |
1894 | 1928 |
1895 /* do_refine: If last step (1-away) of n-step search doesn't pick the center | 1929 /* do_refine: If last step (1-away) of n-step search doesn't pick the center |
1896 point as the best match, we will do a final 1-away diamond | 1930 point as the best match, we will do a final 1-away diamond |
1897 refining search */ | 1931 refining search */ |
1898 int vp9_full_pixel_diamond(const VP9_COMP *cpi, MACROBLOCK *x, | 1932 int vp9_full_pixel_diamond(const VP9_COMP *cpi, MACROBLOCK *x, |
1899 MV *mvp_full, int step_param, | 1933 MV *mvp_full, int step_param, |
1900 int sadpb, int further_steps, int do_refine, | 1934 int sadpb, int further_steps, int do_refine, |
1901 int *cost_list, | 1935 int *cost_list, |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2318 break; | 2352 break; |
2319 default: | 2353 default: |
2320 assert(0 && "Invalid search method."); | 2354 assert(0 && "Invalid search method."); |
2321 } | 2355 } |
2322 | 2356 |
2323 if (method != NSTEP && rd && var < var_max) | 2357 if (method != NSTEP && rd && var < var_max) |
2324 var = vp9_get_mvpred_var(x, tmp_mv, ref_mv, fn_ptr, 1); | 2358 var = vp9_get_mvpred_var(x, tmp_mv, ref_mv, fn_ptr, 1); |
2325 | 2359 |
2326 return var; | 2360 return var; |
2327 } | 2361 } |
OLD | NEW |