Line data Source code
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 : #include "./clpf.h"
13 : #include "./av1_rtcd.h"
14 : #include "./cdef.h"
15 : #include "aom/aom_image.h"
16 : #include "aom_dsp/aom_dsp_common.h"
17 :
18 0 : int av1_clpf_sample(int X, int A, int B, int C, int D, int E, int F, int G,
19 : int H, int s, unsigned int dmp) {
20 0 : int delta = 1 * constrain(A - X, s, dmp) + 3 * constrain(B - X, s, dmp) +
21 0 : 1 * constrain(C - X, s, dmp) + 3 * constrain(D - X, s, dmp) +
22 0 : 3 * constrain(E - X, s, dmp) + 1 * constrain(F - X, s, dmp) +
23 0 : 3 * constrain(G - X, s, dmp) + 1 * constrain(H - X, s, dmp);
24 0 : return (8 + delta - (delta < 0)) >> 4;
25 : }
26 :
27 0 : int av1_clpf_hsample(int X, int A, int B, int C, int D, int s,
28 : unsigned int dmp) {
29 0 : int delta = 1 * constrain(A - X, s, dmp) + 3 * constrain(B - X, s, dmp) +
30 0 : 3 * constrain(C - X, s, dmp) + 1 * constrain(D - X, s, dmp);
31 0 : return (4 + delta - (delta < 0)) >> 3;
32 : }
33 :
34 0 : void aom_clpf_block_c(uint8_t *dst, const uint16_t *src, int dstride,
35 : int sstride, int sizex, int sizey, unsigned int strength,
36 : unsigned int damping) {
37 : int x, y;
38 :
39 0 : for (y = 0; y < sizey; y++) {
40 0 : for (x = 0; x < sizex; x++) {
41 0 : const int X = src[y * sstride + x];
42 0 : const int A = src[(y - 2) * sstride + x];
43 0 : const int B = src[(y - 1) * sstride + x];
44 0 : const int C = src[y * sstride + x - 2];
45 0 : const int D = src[y * sstride + x - 1];
46 0 : const int E = src[y * sstride + x + 1];
47 0 : const int F = src[y * sstride + x + 2];
48 0 : const int G = src[(y + 1) * sstride + x];
49 0 : const int H = src[(y + 2) * sstride + x];
50 0 : const int delta =
51 0 : av1_clpf_sample(X, A, B, C, D, E, F, G, H, strength, damping);
52 0 : dst[y * dstride + x] = X + delta;
53 : }
54 : }
55 0 : }
56 :
57 : // Identical to aom_clpf_block_c() apart from "dst".
58 0 : void aom_clpf_block_hbd_c(uint16_t *dst, const uint16_t *src, int dstride,
59 : int sstride, int sizex, int sizey,
60 : unsigned int strength, unsigned int damping) {
61 : int x, y;
62 :
63 0 : for (y = 0; y < sizey; y++) {
64 0 : for (x = 0; x < sizex; x++) {
65 0 : const int X = src[y * sstride + x];
66 0 : const int A = src[(y - 2) * sstride + x];
67 0 : const int B = src[(y - 1) * sstride + x];
68 0 : const int C = src[y * sstride + x - 2];
69 0 : const int D = src[y * sstride + x - 1];
70 0 : const int E = src[y * sstride + x + 1];
71 0 : const int F = src[y * sstride + x + 2];
72 0 : const int G = src[(y + 1) * sstride + x];
73 0 : const int H = src[(y + 2) * sstride + x];
74 0 : const int delta =
75 0 : av1_clpf_sample(X, A, B, C, D, E, F, G, H, strength, damping);
76 0 : dst[y * dstride + x] = X + delta;
77 : }
78 : }
79 0 : }
80 :
81 : // Vertically restricted filter
82 0 : void aom_clpf_hblock_c(uint8_t *dst, const uint16_t *src, int dstride,
83 : int sstride, int sizex, int sizey, unsigned int strength,
84 : unsigned int damping) {
85 : int x, y;
86 :
87 0 : for (y = 0; y < sizey; y++) {
88 0 : for (x = 0; x < sizex; x++) {
89 0 : const int X = src[y * sstride + x];
90 0 : const int A = src[y * sstride + x - 2];
91 0 : const int B = src[y * sstride + x - 1];
92 0 : const int C = src[y * sstride + x + 1];
93 0 : const int D = src[y * sstride + x + 2];
94 0 : const int delta = av1_clpf_hsample(X, A, B, C, D, strength, damping);
95 0 : dst[y * dstride + x] = X + delta;
96 : }
97 : }
98 0 : }
99 :
100 0 : void aom_clpf_hblock_hbd_c(uint16_t *dst, const uint16_t *src, int dstride,
101 : int sstride, int sizex, int sizey,
102 : unsigned int strength, unsigned int damping) {
103 : int x, y;
104 :
105 0 : for (y = 0; y < sizey; y++) {
106 0 : for (x = 0; x < sizex; x++) {
107 0 : const int X = src[y * sstride + x];
108 0 : const int A = src[y * sstride + x - 2];
109 0 : const int B = src[y * sstride + x - 1];
110 0 : const int C = src[y * sstride + x + 1];
111 0 : const int D = src[y * sstride + x + 2];
112 0 : const int delta = av1_clpf_hsample(X, A, B, C, D, strength, damping);
113 0 : dst[y * dstride + x] = X + delta;
114 : }
115 : }
116 0 : }
|