1*c0909341SAndroid Build Coastguard Worker /*
2*c0909341SAndroid Build Coastguard Worker * Copyright © 2018, VideoLAN and dav1d authors
3*c0909341SAndroid Build Coastguard Worker * Copyright © 2018, Two Orioles, LLC
4*c0909341SAndroid Build Coastguard Worker * All rights reserved.
5*c0909341SAndroid Build Coastguard Worker *
6*c0909341SAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without
7*c0909341SAndroid Build Coastguard Worker * modification, are permitted provided that the following conditions are met:
8*c0909341SAndroid Build Coastguard Worker *
9*c0909341SAndroid Build Coastguard Worker * 1. Redistributions of source code must retain the above copyright notice, this
10*c0909341SAndroid Build Coastguard Worker * list of conditions and the following disclaimer.
11*c0909341SAndroid Build Coastguard Worker *
12*c0909341SAndroid Build Coastguard Worker * 2. Redistributions in binary form must reproduce the above copyright notice,
13*c0909341SAndroid Build Coastguard Worker * this list of conditions and the following disclaimer in the documentation
14*c0909341SAndroid Build Coastguard Worker * and/or other materials provided with the distribution.
15*c0909341SAndroid Build Coastguard Worker *
16*c0909341SAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17*c0909341SAndroid Build Coastguard Worker * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18*c0909341SAndroid Build Coastguard Worker * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19*c0909341SAndroid Build Coastguard Worker * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20*c0909341SAndroid Build Coastguard Worker * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21*c0909341SAndroid Build Coastguard Worker * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22*c0909341SAndroid Build Coastguard Worker * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23*c0909341SAndroid Build Coastguard Worker * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24*c0909341SAndroid Build Coastguard Worker * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25*c0909341SAndroid Build Coastguard Worker * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*c0909341SAndroid Build Coastguard Worker */
27*c0909341SAndroid Build Coastguard Worker
28*c0909341SAndroid Build Coastguard Worker #ifndef DAV1D_SRC_IPRED_PREPARE_H
29*c0909341SAndroid Build Coastguard Worker #define DAV1D_SRC_IPRED_PREPARE_H
30*c0909341SAndroid Build Coastguard Worker
31*c0909341SAndroid Build Coastguard Worker #include <stddef.h>
32*c0909341SAndroid Build Coastguard Worker #include <stdint.h>
33*c0909341SAndroid Build Coastguard Worker
34*c0909341SAndroid Build Coastguard Worker #include "common/bitdepth.h"
35*c0909341SAndroid Build Coastguard Worker
36*c0909341SAndroid Build Coastguard Worker #include "src/env.h"
37*c0909341SAndroid Build Coastguard Worker #include "src/intra_edge.h"
38*c0909341SAndroid Build Coastguard Worker #include "src/levels.h"
39*c0909341SAndroid Build Coastguard Worker
40*c0909341SAndroid Build Coastguard Worker /*
41*c0909341SAndroid Build Coastguard Worker * Luma intra edge preparation.
42*c0909341SAndroid Build Coastguard Worker *
43*c0909341SAndroid Build Coastguard Worker * x/y/start/w/h are in luma block (4px) units:
44*c0909341SAndroid Build Coastguard Worker * - x and y are the absolute block positions in the image;
45*c0909341SAndroid Build Coastguard Worker * - start/w/h are the *dependent tile* boundary positions. In practice, start
46*c0909341SAndroid Build Coastguard Worker * is the horizontal tile start, w is the horizontal tile end, the vertical
47*c0909341SAndroid Build Coastguard Worker * tile start is assumed to be 0 and h is the vertical image end.
48*c0909341SAndroid Build Coastguard Worker *
49*c0909341SAndroid Build Coastguard Worker * edge_flags signals which edges are available for this transform-block inside
50*c0909341SAndroid Build Coastguard Worker * the given partition, as well as for the partition inside the superblock
51*c0909341SAndroid Build Coastguard Worker * structure.
52*c0909341SAndroid Build Coastguard Worker *
53*c0909341SAndroid Build Coastguard Worker * dst and stride are pointers to the top/left position of the current block,
54*c0909341SAndroid Build Coastguard Worker * and can be used to locate the top, left, top/left, top/right and bottom/left
55*c0909341SAndroid Build Coastguard Worker * edge pointers also.
56*c0909341SAndroid Build Coastguard Worker *
57*c0909341SAndroid Build Coastguard Worker * angle is the angle_delta [-3..3] on input, and the absolute angle on output.
58*c0909341SAndroid Build Coastguard Worker *
59*c0909341SAndroid Build Coastguard Worker * mode is the intra prediction mode as coded in the bitstream. The return value
60*c0909341SAndroid Build Coastguard Worker * is this same mode, converted to an index in the DSP functions.
61*c0909341SAndroid Build Coastguard Worker *
62*c0909341SAndroid Build Coastguard Worker * tw/th are the size of the transform block in block (4px) units.
63*c0909341SAndroid Build Coastguard Worker *
64*c0909341SAndroid Build Coastguard Worker * topleft_out is a pointer to scratch memory that will be filled with the edge
65*c0909341SAndroid Build Coastguard Worker * pixels. The memory array should have space to be indexed in the [-2*w,2*w]
66*c0909341SAndroid Build Coastguard Worker * range, in the following order:
67*c0909341SAndroid Build Coastguard Worker * - [0] will be the top/left edge pixel;
68*c0909341SAndroid Build Coastguard Worker * - [1..w] will be the top edge pixels (1 being left-most, w being right-most);
69*c0909341SAndroid Build Coastguard Worker * - [w+1..2*w] will be the top/right edge pixels;
70*c0909341SAndroid Build Coastguard Worker * - [-1..-w] will be the left edge pixels (-1 being top-most, -w being bottom-
71*c0909341SAndroid Build Coastguard Worker * most);
72*c0909341SAndroid Build Coastguard Worker * - [-w-1..-2*w] will be the bottom/left edge pixels.
73*c0909341SAndroid Build Coastguard Worker * Each edge may remain uninitialized if it is not used by the returned mode
74*c0909341SAndroid Build Coastguard Worker * index. If edges are not available (because the edge position is outside the
75*c0909341SAndroid Build Coastguard Worker * tile dimensions or because edge_flags indicates lack of edge availability),
76*c0909341SAndroid Build Coastguard Worker * they will be extended from nearby edges as defined by the av1 spec.
77*c0909341SAndroid Build Coastguard Worker */
78*c0909341SAndroid Build Coastguard Worker enum IntraPredMode
79*c0909341SAndroid Build Coastguard Worker bytefn(dav1d_prepare_intra_edges)(int x, int have_left, int y, int have_top,
80*c0909341SAndroid Build Coastguard Worker int w, int h, enum EdgeFlags edge_flags,
81*c0909341SAndroid Build Coastguard Worker const pixel *dst, ptrdiff_t stride,
82*c0909341SAndroid Build Coastguard Worker const pixel *prefilter_toplevel_sb_edge,
83*c0909341SAndroid Build Coastguard Worker enum IntraPredMode mode, int *angle,
84*c0909341SAndroid Build Coastguard Worker int tw, int th, int filter_edge,
85*c0909341SAndroid Build Coastguard Worker pixel *topleft_out HIGHBD_DECL_SUFFIX);
86*c0909341SAndroid Build Coastguard Worker
87*c0909341SAndroid Build Coastguard Worker // These flags are OR'd with the angle argument into intra predictors.
88*c0909341SAndroid Build Coastguard Worker // ANGLE_USE_EDGE_FILTER_FLAG signals that edges should be convolved
89*c0909341SAndroid Build Coastguard Worker // with a filter before using them to predict values in a block.
90*c0909341SAndroid Build Coastguard Worker // ANGLE_SMOOTH_EDGE_FLAG means that edges are smooth and should use
91*c0909341SAndroid Build Coastguard Worker // reduced filter strength.
92*c0909341SAndroid Build Coastguard Worker #define ANGLE_USE_EDGE_FILTER_FLAG 1024
93*c0909341SAndroid Build Coastguard Worker #define ANGLE_SMOOTH_EDGE_FLAG 512
94*c0909341SAndroid Build Coastguard Worker
sm_flag(const BlockContext * const b,const int idx)95*c0909341SAndroid Build Coastguard Worker static inline int sm_flag(const BlockContext *const b, const int idx) {
96*c0909341SAndroid Build Coastguard Worker if (!b->intra[idx]) return 0;
97*c0909341SAndroid Build Coastguard Worker const enum IntraPredMode m = b->mode[idx];
98*c0909341SAndroid Build Coastguard Worker return (m == SMOOTH_PRED || m == SMOOTH_H_PRED ||
99*c0909341SAndroid Build Coastguard Worker m == SMOOTH_V_PRED) ? ANGLE_SMOOTH_EDGE_FLAG : 0;
100*c0909341SAndroid Build Coastguard Worker }
101*c0909341SAndroid Build Coastguard Worker
sm_uv_flag(const BlockContext * const b,const int idx)102*c0909341SAndroid Build Coastguard Worker static inline int sm_uv_flag(const BlockContext *const b, const int idx) {
103*c0909341SAndroid Build Coastguard Worker const enum IntraPredMode m = b->uvmode[idx];
104*c0909341SAndroid Build Coastguard Worker return (m == SMOOTH_PRED || m == SMOOTH_H_PRED ||
105*c0909341SAndroid Build Coastguard Worker m == SMOOTH_V_PRED) ? ANGLE_SMOOTH_EDGE_FLAG : 0;
106*c0909341SAndroid Build Coastguard Worker }
107*c0909341SAndroid Build Coastguard Worker
108*c0909341SAndroid Build Coastguard Worker #endif /* DAV1D_SRC_IPRED_PREPARE_H */
109