Home | History | Annotate | Download | only in common
      1 /*
      2  * Copyright (c) 2016, Alliance for Open Media. All rights reserved
      3  *
      4  * This source code is subject to the terms of the BSD 2 Clause License and
      5  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
      6  * was not distributed with this source code in the LICENSE file, you can
      7  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
      8  * Media Patent License 1.0 was not distributed with this source code in the
      9  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
     10  */
     11 
     12 #ifndef AOM_AV1_COMMON_WARPED_MOTION_H_
     13 #define AOM_AV1_COMMON_WARPED_MOTION_H_
     14 
     15 #include <stdio.h>
     16 #include <stdlib.h>
     17 #include <memory.h>
     18 #include <math.h>
     19 #include <assert.h>
     20 
     21 #include "config/aom_config.h"
     22 
     23 #include "aom_ports/mem.h"
     24 #include "aom_dsp/aom_dsp_common.h"
     25 #include "av1/common/mv.h"
     26 #include "av1/common/convolve.h"
     27 
     28 #define MAX_PARAMDIM 9
     29 #define LEAST_SQUARES_SAMPLES_MAX_BITS 3
     30 #define LEAST_SQUARES_SAMPLES_MAX (1 << LEAST_SQUARES_SAMPLES_MAX_BITS)
     31 #define SAMPLES_ARRAY_SIZE (LEAST_SQUARES_SAMPLES_MAX * 2)
     32 #define WARPED_MOTION_DEBUG 0
     33 #define DEFAULT_WMTYPE AFFINE
     34 
     35 extern const int16_t warped_filter[WARPEDPIXEL_PREC_SHIFTS * 3 + 1][8];
     36 
     37 static const uint8_t warp_pad_left[14][16] = {
     38   { 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
     39   { 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
     40   { 3, 3, 3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
     41   { 4, 4, 4, 4, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
     42   { 5, 5, 5, 5, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
     43   { 6, 6, 6, 6, 6, 6, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
     44   { 7, 7, 7, 7, 7, 7, 7, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
     45   { 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 10, 11, 12, 13, 14, 15 },
     46   { 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 11, 12, 13, 14, 15 },
     47   { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 12, 13, 14, 15 },
     48   { 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 13, 14, 15 },
     49   { 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 14, 15 },
     50   { 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 15 },
     51   { 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15 },
     52 };
     53 
     54 static const uint8_t warp_pad_right[14][16] = {
     55   { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 14 },
     56   { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 13, 13 },
     57   { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 12, 12 },
     58   { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 11, 11, 11 },
     59   { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 10 },
     60   { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9, 9, 9, 9, 9 },
     61   { 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8, 8, 8 },
     62   { 0, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7 },
     63   { 0, 1, 2, 3, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 },
     64   { 0, 1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 },
     65   { 0, 1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 },
     66   { 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
     67   { 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
     68   { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
     69 };
     70 
     71 // Returns the error between the result of applying motion 'wm' to the frame
     72 // described by 'ref' and the frame described by 'dst'.
     73 int64_t av1_warp_error(WarpedMotionParams *wm, int use_hbd, int bd,
     74                        const uint8_t *ref, int width, int height, int stride,
     75                        uint8_t *dst, int p_col, int p_row, int p_width,
     76                        int p_height, int p_stride, int subsampling_x,
     77                        int subsampling_y, int64_t best_error);
     78 
     79 // Returns the error between the frame described by 'ref' and the frame
     80 // described by 'dst'.
     81 int64_t av1_frame_error(int use_hbd, int bd, const uint8_t *ref, int stride,
     82                         uint8_t *dst, int p_width, int p_height, int p_stride);
     83 
     84 void av1_warp_plane(WarpedMotionParams *wm, int use_hbd, int bd,
     85                     const uint8_t *ref, int width, int height, int stride,
     86                     uint8_t *pred, int p_col, int p_row, int p_width,
     87                     int p_height, int p_stride, int subsampling_x,
     88                     int subsampling_y, ConvolveParams *conv_params);
     89 
     90 int find_projection(int np, int *pts1, int *pts2, BLOCK_SIZE bsize, int mvy,
     91                     int mvx, WarpedMotionParams *wm_params, int mi_row,
     92                     int mi_col);
     93 
     94 int get_shear_params(WarpedMotionParams *wm);
     95 #endif  // AOM_AV1_COMMON_WARPED_MOTION_H_
     96