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 #if !defined(_CDEF_BLOCK_H)
13 #define _CDEF_BLOCK_H (1)
14 
15 #include "./odintrin.h"
16 
17 #define CDEF_BLOCKSIZE 64
18 #define CDEF_BLOCKSIZE_LOG2 6
19 #define CDEF_NBLOCKS (CDEF_BLOCKSIZE / 8)
20 #if CONFIG_CDEF_SINGLEPASS
21 #define CDEF_SB_SHIFT (MAX_SB_SIZE_LOG2 - CDEF_BLOCKSIZE_LOG2)
22 #endif
23 
24 /* We need to buffer three vertical lines. */
25 #define CDEF_VBORDER (3)
26 /* We only need to buffer three horizontal pixels too, but let's align to
27    16 bytes (8 x 16 bits) to make vectorization easier. */
28 #define CDEF_HBORDER (8)
29 #define CDEF_BSTRIDE ALIGN_POWER_OF_TWO(CDEF_BLOCKSIZE + 2 * CDEF_HBORDER, 3)
30 
31 #define CDEF_VERY_LARGE (30000)
32 #define CDEF_INBUF_SIZE (CDEF_BSTRIDE * (CDEF_BLOCKSIZE + 2 * CDEF_VBORDER))
33 
34 #if CONFIG_CDEF_SINGLEPASS
35 // Filter configuration
36 #define CDEF_CAP 1   // 1 = Cap change to largest diff
37 #define CDEF_FULL 0  // 1 = 7x7 filter, 0 = 5x5 filter
38 
39 #if CDEF_FULL
40 extern const int cdef_pri_taps[2][3];
41 extern const int cdef_sec_taps[2][2];
42 extern const int cdef_directions[8][3];
43 #else
44 extern const int cdef_pri_taps[2][2];
45 extern const int cdef_sec_taps[2][2];
46 extern const int cdef_directions[8][2];
47 #endif
48 
49 #else  // CONFIG_CDEF_SINGLEPASS
50 extern const int cdef_directions[8][3];
51 #endif
52 
53 typedef struct {
54   uint8_t by;
55   uint8_t bx;
56   uint8_t skip;
57 } cdef_list;
58 
59 #if CONFIG_CDEF_SINGLEPASS
60 typedef void (*cdef_filter_block_func)(uint8_t *dst8, uint16_t *dst16,
61                                        int dstride, const uint16_t *in,
62                                        int pri_strength, int sec_strength,
63                                        int dir, int pri_damping,
64                                        int sec_damping, int bsize, int max);
65 void copy_cdef_16bit_to_16bit(uint16_t *dst, int dstride, uint16_t *src,
66                               cdef_list *dlist, int cdef_count, int bsize);
67 #else
68 typedef void (*cdef_direction_func)(uint16_t *y, int ystride,
69                                     const uint16_t *in, int threshold, int dir,
70                                     int damping);
71 
72 int get_filter_skip(int level);
73 #endif
74 
75 #if CONFIG_CDEF_SINGLEPASS
76 void cdef_filter_fb(uint8_t *dst8, uint16_t *dst16, int dstride, uint16_t *in,
77                     int xdec, int ydec, int dir[CDEF_NBLOCKS][CDEF_NBLOCKS],
78                     int *dirinit, int var[CDEF_NBLOCKS][CDEF_NBLOCKS], int pli,
79                     cdef_list *dlist, int cdef_count, int level,
80                     int sec_strength, int pri_damping, int sec_damping,
81                     int coeff_shift);
82 #else
83 void cdef_filter_fb(uint8_t *dst, int dstride, uint16_t *y, uint16_t *in,
84                     int xdec, int ydec, int dir[CDEF_NBLOCKS][CDEF_NBLOCKS],
85                     int *dirinit, int var[CDEF_NBLOCKS][CDEF_NBLOCKS], int pli,
86                     cdef_list *dlist, int cdef_count, int level,
87                     int sec_strength, int sec_damping, int pri_damping,
88                     int coeff_shift, int skip_dering, int hbd);
89 #endif
90 #endif
91