/work/x265/source/common/intrapred.cpp
Line | Count | Source |
1 | | /***************************************************************************** |
2 | | * Copyright (C) 2013-2020 MulticoreWare, Inc |
3 | | * |
4 | | * Authors: Min Chen <chenm003@163.com> |
5 | | * |
6 | | * This program is free software; you can redistribute it and/or modify |
7 | | * it under the terms of the GNU General Public License as published by |
8 | | * the Free Software Foundation; either version 2 of the License, or |
9 | | * (at your option) any later version. |
10 | | * |
11 | | * This program is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU General Public License |
17 | | * along with this program; if not, write to the Free Software |
18 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. |
19 | | * |
20 | | * This program is also available under a commercial proprietary license. |
21 | | * For more information, contact us at license @ x265.com. |
22 | | *****************************************************************************/ |
23 | | |
24 | | #include "common.h" |
25 | | #include "primitives.h" |
26 | | |
27 | | using namespace X265_NS; |
28 | | |
29 | | namespace { |
30 | | |
31 | | template<int tuSize> |
32 | | void intraFilter(const pixel* samples, pixel* filtered) /* 1:2:1 filtering of left and top reference samples */ |
33 | 1.26M | { |
34 | 1.26M | const int tuSize2 = tuSize << 1; |
35 | | |
36 | 1.26M | pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2]; |
37 | | |
38 | | // filtering top |
39 | 23.7M | for (int i = 1; i < tuSize2; i++) |
40 | 22.4M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; |
41 | 1.26M | filtered[tuSize2] = topLast; |
42 | | |
43 | | // filtering top-left |
44 | 1.26M | filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2; |
45 | | |
46 | | // filtering left |
47 | 1.26M | filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2; |
48 | 22.4M | for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++) |
49 | 21.1M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; |
50 | 1.26M | filtered[tuSize2 + tuSize2] = leftLast; |
51 | 1.26M | } Unexecuted instantiation: intrapred.cpp:void (anonymous namespace)::intraFilter<4>(unsigned char const*, unsigned char*) intrapred.cpp:void (anonymous namespace)::intraFilter<8>(unsigned char const*, unsigned char*) Line | Count | Source | 33 | 1.05M | { | 34 | 1.05M | const int tuSize2 = tuSize << 1; | 35 | | | 36 | 1.05M | pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2]; | 37 | | | 38 | | // filtering top | 39 | 16.8M | for (int i = 1; i < tuSize2; i++) | 40 | 15.8M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; | 41 | 1.05M | filtered[tuSize2] = topLast; | 42 | | | 43 | | // filtering top-left | 44 | 1.05M | filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2; | 45 | | | 46 | | // filtering left | 47 | 1.05M | filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2; | 48 | 15.8M | for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++) | 49 | 14.7M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; | 50 | 1.05M | filtered[tuSize2 + tuSize2] = leftLast; | 51 | 1.05M | } |
intrapred.cpp:void (anonymous namespace)::intraFilter<16>(unsigned char const*, unsigned char*) Line | Count | Source | 33 | 213k | { | 34 | 213k | const int tuSize2 = tuSize << 1; | 35 | | | 36 | 213k | pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2]; | 37 | | | 38 | | // filtering top | 39 | 6.82M | for (int i = 1; i < tuSize2; i++) | 40 | 6.61M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; | 41 | 213k | filtered[tuSize2] = topLast; | 42 | | | 43 | | // filtering top-left | 44 | 213k | filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2; | 45 | | | 46 | | // filtering left | 47 | 213k | filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2; | 48 | 6.61M | for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++) | 49 | 6.40M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; | 50 | 213k | filtered[tuSize2 + tuSize2] = leftLast; | 51 | 213k | } |
Unexecuted instantiation: intrapred.cpp:void (anonymous namespace)::intraFilter<32>(unsigned char const*, unsigned char*) |
52 | | |
53 | | static void dcPredFilter(const pixel* above, const pixel* left, pixel* dst, intptr_t dststride, int size) |
54 | 2.48M | { |
55 | | // boundary pixels processing |
56 | 2.48M | dst[0] = (pixel)((above[0] + left[0] + 2 * dst[0] + 2) >> 2); |
57 | | |
58 | 13.8M | for (int x = 1; x < size; x++) |
59 | 11.3M | dst[x] = (pixel)((above[x] + 3 * dst[x] + 2) >> 2); |
60 | | |
61 | 2.48M | dst += dststride; |
62 | 13.8M | for (int y = 1; y < size; y++) |
63 | 11.3M | { |
64 | 11.3M | *dst = (pixel)((left[y] + 3 * *dst + 2) >> 2); |
65 | 11.3M | dst += dststride; |
66 | 11.3M | } |
67 | 2.48M | } |
68 | | |
69 | | template<int width> |
70 | | void intra_pred_dc_c(pixel* dst, intptr_t dstStride, const pixel* srcPix, int /*dirMode*/, int bFilter) |
71 | 3.88M | { |
72 | 3.88M | int k, l; |
73 | | |
74 | 3.88M | int dcVal = width; |
75 | 25.0M | for (int i = 0; i < width; i++) |
76 | 21.1M | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; |
77 | | |
78 | 3.88M | dcVal = dcVal / (width + width); |
79 | 25.0M | for (k = 0; k < width; k++) |
80 | 185M | for (l = 0; l < width; l++) |
81 | 164M | dst[k * dstStride + l] = (pixel)dcVal; |
82 | | |
83 | 3.88M | if (bFilter) |
84 | 2.48M | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); |
85 | 3.88M | } intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<4>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 71 | 2.97M | { | 72 | 2.97M | int k, l; | 73 | | | 74 | 2.97M | int dcVal = width; | 75 | 14.8M | for (int i = 0; i < width; i++) | 76 | 11.9M | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; | 77 | | | 78 | 2.97M | dcVal = dcVal / (width + width); | 79 | 14.8M | for (k = 0; k < width; k++) | 80 | 59.5M | for (l = 0; l < width; l++) | 81 | 47.6M | dst[k * dstStride + l] = (pixel)dcVal; | 82 | | | 83 | 2.97M | if (bFilter) | 84 | 1.78M | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); | 85 | 2.97M | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<8>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 71 | 710k | { | 72 | 710k | int k, l; | 73 | | | 74 | 710k | int dcVal = width; | 75 | 6.39M | for (int i = 0; i < width; i++) | 76 | 5.68M | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; | 77 | | | 78 | 710k | dcVal = dcVal / (width + width); | 79 | 6.39M | for (k = 0; k < width; k++) | 80 | 51.1M | for (l = 0; l < width; l++) | 81 | 45.4M | dst[k * dstStride + l] = (pixel)dcVal; | 82 | | | 83 | 710k | if (bFilter) | 84 | 566k | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); | 85 | 710k | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<16>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 71 | 163k | { | 72 | 163k | int k, l; | 73 | | | 74 | 163k | int dcVal = width; | 75 | 2.78M | for (int i = 0; i < width; i++) | 76 | 2.62M | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; | 77 | | | 78 | 163k | dcVal = dcVal / (width + width); | 79 | 2.78M | for (k = 0; k < width; k++) | 80 | 44.5M | for (l = 0; l < width; l++) | 81 | 41.9M | dst[k * dstStride + l] = (pixel)dcVal; | 82 | | | 83 | 163k | if (bFilter) | 84 | 134k | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); | 85 | 163k | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<32>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 71 | 28.4k | { | 72 | 28.4k | int k, l; | 73 | | | 74 | 28.4k | int dcVal = width; | 75 | 940k | for (int i = 0; i < width; i++) | 76 | 911k | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; | 77 | | | 78 | 28.4k | dcVal = dcVal / (width + width); | 79 | 940k | for (k = 0; k < width; k++) | 80 | 30.0M | for (l = 0; l < width; l++) | 81 | 29.1M | dst[k * dstStride + l] = (pixel)dcVal; | 82 | | | 83 | 28.4k | if (bFilter) | 84 | 0 | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); | 85 | 28.4k | } |
|
86 | | |
87 | | template<int log2Size> |
88 | | void planar_pred_c(pixel* dst, intptr_t dstStride, const pixel* srcPix, int /*dirMode*/, int /*bFilter*/) |
89 | 6.77M | { |
90 | 6.77M | const int blkSize = 1 << log2Size; |
91 | | |
92 | 6.77M | const pixel* above = srcPix + 1; |
93 | 6.77M | const pixel* left = srcPix + (2 * blkSize + 1); |
94 | | |
95 | 6.77M | pixel topRight = above[blkSize]; |
96 | 6.77M | pixel bottomLeft = left[blkSize]; |
97 | 42.4M | for (int y = 0; y < blkSize; y++) |
98 | 290M | for (int x = 0; x < blkSize; x++) |
99 | 254M | dst[y * dstStride + x] = (pixel) (((blkSize - 1 - x) * left[y] + (blkSize - 1 -y) * above[x] + (x + 1) * topRight + (y + 1) * bottomLeft + blkSize) >> (log2Size + 1)); |
100 | 6.77M | } intrapred.cpp:void (anonymous namespace)::planar_pred_c<2>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 89 | 5.30M | { | 90 | 5.30M | const int blkSize = 1 << log2Size; | 91 | | | 92 | 5.30M | const pixel* above = srcPix + 1; | 93 | 5.30M | const pixel* left = srcPix + (2 * blkSize + 1); | 94 | | | 95 | 5.30M | pixel topRight = above[blkSize]; | 96 | 5.30M | pixel bottomLeft = left[blkSize]; | 97 | 26.5M | for (int y = 0; y < blkSize; y++) | 98 | 106M | for (int x = 0; x < blkSize; x++) | 99 | 84.8M | dst[y * dstStride + x] = (pixel) (((blkSize - 1 - x) * left[y] + (blkSize - 1 -y) * above[x] + (x + 1) * topRight + (y + 1) * bottomLeft + blkSize) >> (log2Size + 1)); | 100 | 5.30M | } |
intrapred.cpp:void (anonymous namespace)::planar_pred_c<3>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 89 | 1.20M | { | 90 | 1.20M | const int blkSize = 1 << log2Size; | 91 | | | 92 | 1.20M | const pixel* above = srcPix + 1; | 93 | 1.20M | const pixel* left = srcPix + (2 * blkSize + 1); | 94 | | | 95 | 1.20M | pixel topRight = above[blkSize]; | 96 | 1.20M | pixel bottomLeft = left[blkSize]; | 97 | 10.7M | for (int y = 0; y < blkSize; y++) | 98 | 86.3M | for (int x = 0; x < blkSize; x++) | 99 | 76.7M | dst[y * dstStride + x] = (pixel) (((blkSize - 1 - x) * left[y] + (blkSize - 1 -y) * above[x] + (x + 1) * topRight + (y + 1) * bottomLeft + blkSize) >> (log2Size + 1)); | 100 | 1.20M | } |
intrapred.cpp:void (anonymous namespace)::planar_pred_c<4>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 89 | 240k | { | 90 | 240k | const int blkSize = 1 << log2Size; | 91 | | | 92 | 240k | const pixel* above = srcPix + 1; | 93 | 240k | const pixel* left = srcPix + (2 * blkSize + 1); | 94 | | | 95 | 240k | pixel topRight = above[blkSize]; | 96 | 240k | pixel bottomLeft = left[blkSize]; | 97 | 4.08M | for (int y = 0; y < blkSize; y++) | 98 | 65.2M | for (int x = 0; x < blkSize; x++) | 99 | 61.4M | dst[y * dstStride + x] = (pixel) (((blkSize - 1 - x) * left[y] + (blkSize - 1 -y) * above[x] + (x + 1) * topRight + (y + 1) * bottomLeft + blkSize) >> (log2Size + 1)); | 100 | 240k | } |
intrapred.cpp:void (anonymous namespace)::planar_pred_c<5>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 89 | 31.1k | { | 90 | 31.1k | const int blkSize = 1 << log2Size; | 91 | | | 92 | 31.1k | const pixel* above = srcPix + 1; | 93 | 31.1k | const pixel* left = srcPix + (2 * blkSize + 1); | 94 | | | 95 | 31.1k | pixel topRight = above[blkSize]; | 96 | 31.1k | pixel bottomLeft = left[blkSize]; | 97 | 1.02M | for (int y = 0; y < blkSize; y++) | 98 | 32.8M | for (int x = 0; x < blkSize; x++) | 99 | 31.8M | dst[y * dstStride + x] = (pixel) (((blkSize - 1 - x) * left[y] + (blkSize - 1 -y) * above[x] + (x + 1) * topRight + (y + 1) * bottomLeft + blkSize) >> (log2Size + 1)); | 100 | 31.1k | } |
|
101 | | |
102 | | template<int width> |
103 | | void intra_pred_ang_c(pixel* dst, intptr_t dstStride, const pixel *srcPix0, int dirMode, int bFilter) |
104 | 56.6M | { |
105 | 56.6M | int width2 = width << 1; |
106 | | // Flip the neighbours in the horizontal case. |
107 | 56.6M | int horMode = dirMode < 18; |
108 | 56.6M | pixel neighbourBuf[129]; |
109 | 56.6M | const pixel *srcPix = srcPix0; |
110 | | |
111 | 56.6M | if (horMode) |
112 | 27.1M | { |
113 | 27.1M | neighbourBuf[0] = srcPix[0]; |
114 | 329M | for (int i = 0; i < width << 1; i++) |
115 | 302M | { |
116 | 302M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; |
117 | 302M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; |
118 | 302M | } |
119 | 27.1M | srcPix = neighbourBuf; |
120 | 27.1M | } |
121 | | |
122 | | // Intra prediction angle and inverse angle tables. |
123 | 56.6M | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; |
124 | 56.6M | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; |
125 | | |
126 | | // Get the prediction angle. |
127 | 56.6M | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; |
128 | 56.6M | int angle = angleTable[8 + angleOffset]; |
129 | | |
130 | | // Vertical Prediction. |
131 | 56.6M | if (!angle) |
132 | 6.03M | { |
133 | 37.4M | for (int y = 0; y < width; y++) |
134 | 254M | for (int x = 0; x < width; x++) |
135 | 223M | dst[y * dstStride + x] = srcPix[1 + x]; |
136 | | |
137 | 6.03M | if (bFilter) |
138 | 3.28M | { |
139 | 3.28M | int topLeft = srcPix[0], top = srcPix[1]; |
140 | 20.9M | for (int y = 0; y < width; y++) |
141 | 17.6M | dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1))); |
142 | 3.28M | } |
143 | 6.03M | } |
144 | 50.6M | else // Angular prediction. |
145 | 50.6M | { |
146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). |
147 | 50.6M | pixel refBuf[64]; |
148 | 50.6M | const pixel *ref; |
149 | | |
150 | | // Use the projected left neighbours and the top neighbours. |
151 | 50.6M | if (angle < 0) |
152 | 23.8M | { |
153 | | // Number of neighbours projected. |
154 | 23.8M | int nbProjected = -((width * angle) >> 5) - 1; |
155 | 23.8M | pixel *ref_pix = refBuf + nbProjected + 1; |
156 | | |
157 | | // Project the neighbours. |
158 | 23.8M | int invAngle = invAngleTable[- angleOffset - 1]; |
159 | 23.8M | int invAngleSum = 128; |
160 | 74.3M | for (int i = 0; i < nbProjected; i++) |
161 | 50.4M | { |
162 | 50.4M | invAngleSum += invAngle; |
163 | 50.4M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; |
164 | 50.4M | } |
165 | | |
166 | | // Copy the top-left and top pixels. |
167 | 181M | for (int i = 0; i < width + 1; i++) |
168 | 157M | ref_pix[-1 + i] = srcPix[i]; |
169 | 23.8M | ref = ref_pix; |
170 | 23.8M | } |
171 | 26.7M | else // Use the top and top-right neighbours. |
172 | 26.7M | ref = srcPix + 1; |
173 | | |
174 | | // Pass every row. |
175 | 50.6M | int angleSum = 0; |
176 | 331M | for (int y = 0; y < width; y++) |
177 | 281M | { |
178 | 281M | angleSum += angle; |
179 | 281M | int offset = angleSum >> 5; |
180 | 281M | int fraction = angleSum & 31; |
181 | | |
182 | 281M | if (fraction) // Interpolate |
183 | 2.25G | for (int x = 0; x < width; x++) |
184 | 2.00G | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); |
185 | 33.2M | else // Copy. |
186 | 310M | for (int x = 0; x < width; x++) |
187 | 277M | dst[y * dstStride + x] = ref[offset + x]; |
188 | 281M | } |
189 | 50.6M | } |
190 | | |
191 | | // Flip for horizontal. |
192 | 56.6M | if (horMode) |
193 | 27.1M | { |
194 | 151M | for (int y = 0; y < width - 1; y++) |
195 | 123M | { |
196 | 657M | for (int x = y + 1; x < width; x++) |
197 | 533M | { |
198 | 533M | pixel tmp = dst[y * dstStride + x]; |
199 | 533M | dst[y * dstStride + x] = dst[x * dstStride + y]; |
200 | 533M | dst[x * dstStride + y] = tmp; |
201 | 533M | } |
202 | 123M | } |
203 | 27.1M | } |
204 | 56.6M | } intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<4>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 104 | 42.6M | { | 105 | 42.6M | int width2 = width << 1; | 106 | | // Flip the neighbours in the horizontal case. | 107 | 42.6M | int horMode = dirMode < 18; | 108 | 42.6M | pixel neighbourBuf[129]; | 109 | 42.6M | const pixel *srcPix = srcPix0; | 110 | | | 111 | 42.6M | if (horMode) | 112 | 20.2M | { | 113 | 20.2M | neighbourBuf[0] = srcPix[0]; | 114 | 182M | for (int i = 0; i < width << 1; i++) | 115 | 161M | { | 116 | 161M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; | 117 | 161M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; | 118 | 161M | } | 119 | 20.2M | srcPix = neighbourBuf; | 120 | 20.2M | } | 121 | | | 122 | | // Intra prediction angle and inverse angle tables. | 123 | 42.6M | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; | 124 | 42.6M | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; | 125 | | | 126 | | // Get the prediction angle. | 127 | 42.6M | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; | 128 | 42.6M | int angle = angleTable[8 + angleOffset]; | 129 | | | 130 | | // Vertical Prediction. | 131 | 42.6M | if (!angle) | 132 | 4.82M | { | 133 | 24.1M | for (int y = 0; y < width; y++) | 134 | 96.4M | for (int x = 0; x < width; x++) | 135 | 77.1M | dst[y * dstStride + x] = srcPix[1 + x]; | 136 | | | 137 | 4.82M | if (bFilter) | 138 | 2.44M | { | 139 | 2.44M | int topLeft = srcPix[0], top = srcPix[1]; | 140 | 12.2M | for (int y = 0; y < width; y++) | 141 | 9.77M | dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1))); | 142 | 2.44M | } | 143 | 4.82M | } | 144 | 37.8M | else // Angular prediction. | 145 | 37.8M | { | 146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). | 147 | 37.8M | pixel refBuf[64]; | 148 | 37.8M | const pixel *ref; | 149 | | | 150 | | // Use the projected left neighbours and the top neighbours. | 151 | 37.8M | if (angle < 0) | 152 | 17.8M | { | 153 | | // Number of neighbours projected. | 154 | 17.8M | int nbProjected = -((width * angle) >> 5) - 1; | 155 | 17.8M | pixel *ref_pix = refBuf + nbProjected + 1; | 156 | | | 157 | | // Project the neighbours. | 158 | 17.8M | int invAngle = invAngleTable[- angleOffset - 1]; | 159 | 17.8M | int invAngleSum = 128; | 160 | 42.8M | for (int i = 0; i < nbProjected; i++) | 161 | 25.0M | { | 162 | 25.0M | invAngleSum += invAngle; | 163 | 25.0M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; | 164 | 25.0M | } | 165 | | | 166 | | // Copy the top-left and top pixels. | 167 | 107M | for (int i = 0; i < width + 1; i++) | 168 | 89.3M | ref_pix[-1 + i] = srcPix[i]; | 169 | 17.8M | ref = ref_pix; | 170 | 17.8M | } | 171 | 20.0M | else // Use the top and top-right neighbours. | 172 | 20.0M | ref = srcPix + 1; | 173 | | | 174 | | // Pass every row. | 175 | 37.8M | int angleSum = 0; | 176 | 188M | for (int y = 0; y < width; y++) | 177 | 150M | { | 178 | 150M | angleSum += angle; | 179 | 150M | int offset = angleSum >> 5; | 180 | 150M | int fraction = angleSum & 31; | 181 | | | 182 | 150M | if (fraction) // Interpolate | 183 | 659M | for (int x = 0; x < width; x++) | 184 | 527M | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); | 185 | 18.7M | else // Copy. | 186 | 94.9M | for (int x = 0; x < width; x++) | 187 | 76.2M | dst[y * dstStride + x] = ref[offset + x]; | 188 | 150M | } | 189 | 37.8M | } | 190 | | | 191 | | // Flip for horizontal. | 192 | 42.6M | if (horMode) | 193 | 20.2M | { | 194 | 81.0M | for (int y = 0; y < width - 1; y++) | 195 | 60.7M | { | 196 | 182M | for (int x = y + 1; x < width; x++) | 197 | 121M | { | 198 | 121M | pixel tmp = dst[y * dstStride + x]; | 199 | 121M | dst[y * dstStride + x] = dst[x * dstStride + y]; | 200 | 121M | dst[x * dstStride + y] = tmp; | 201 | 121M | } | 202 | 60.7M | } | 203 | 20.2M | } | 204 | 42.6M | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<8>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 104 | 11.0M | { | 105 | 11.0M | int width2 = width << 1; | 106 | | // Flip the neighbours in the horizontal case. | 107 | 11.0M | int horMode = dirMode < 18; | 108 | 11.0M | pixel neighbourBuf[129]; | 109 | 11.0M | const pixel *srcPix = srcPix0; | 110 | | | 111 | 11.0M | if (horMode) | 112 | 5.45M | { | 113 | 5.45M | neighbourBuf[0] = srcPix[0]; | 114 | 92.7M | for (int i = 0; i < width << 1; i++) | 115 | 87.3M | { | 116 | 87.3M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; | 117 | 87.3M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; | 118 | 87.3M | } | 119 | 5.45M | srcPix = neighbourBuf; | 120 | 5.45M | } | 121 | | | 122 | | // Intra prediction angle and inverse angle tables. | 123 | 11.0M | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; | 124 | 11.0M | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; | 125 | | | 126 | | // Get the prediction angle. | 127 | 11.0M | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; | 128 | 11.0M | int angle = angleTable[8 + angleOffset]; | 129 | | | 130 | | // Vertical Prediction. | 131 | 11.0M | if (!angle) | 132 | 978k | { | 133 | 8.80M | for (int y = 0; y < width; y++) | 134 | 70.4M | for (int x = 0; x < width; x++) | 135 | 62.5M | dst[y * dstStride + x] = srcPix[1 + x]; | 136 | | | 137 | 978k | if (bFilter) | 138 | 690k | { | 139 | 690k | int topLeft = srcPix[0], top = srcPix[1]; | 140 | 6.20M | for (int y = 0; y < width; y++) | 141 | 5.51M | dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1))); | 142 | 690k | } | 143 | 978k | } | 144 | 10.0M | else // Angular prediction. | 145 | 10.0M | { | 146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). | 147 | 10.0M | pixel refBuf[64]; | 148 | 10.0M | const pixel *ref; | 149 | | | 150 | | // Use the projected left neighbours and the top neighbours. | 151 | 10.0M | if (angle < 0) | 152 | 4.70M | { | 153 | | // Number of neighbours projected. | 154 | 4.70M | int nbProjected = -((width * angle) >> 5) - 1; | 155 | 4.70M | pixel *ref_pix = refBuf + nbProjected + 1; | 156 | | | 157 | | // Project the neighbours. | 158 | 4.70M | int invAngle = invAngleTable[- angleOffset - 1]; | 159 | 4.70M | int invAngleSum = 128; | 160 | 20.0M | for (int i = 0; i < nbProjected; i++) | 161 | 15.3M | { | 162 | 15.3M | invAngleSum += invAngle; | 163 | 15.3M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; | 164 | 15.3M | } | 165 | | | 166 | | // Copy the top-left and top pixels. | 167 | 47.0M | for (int i = 0; i < width + 1; i++) | 168 | 42.3M | ref_pix[-1 + i] = srcPix[i]; | 169 | 4.70M | ref = ref_pix; | 170 | 4.70M | } | 171 | 5.36M | else // Use the top and top-right neighbours. | 172 | 5.36M | ref = srcPix + 1; | 173 | | | 174 | | // Pass every row. | 175 | 10.0M | int angleSum = 0; | 176 | 89.9M | for (int y = 0; y < width; y++) | 177 | 79.9M | { | 178 | 79.9M | angleSum += angle; | 179 | 79.9M | int offset = angleSum >> 5; | 180 | 79.9M | int fraction = angleSum & 31; | 181 | | | 182 | 79.9M | if (fraction) // Interpolate | 183 | 645M | for (int x = 0; x < width; x++) | 184 | 573M | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); | 185 | 8.18M | else // Copy. | 186 | 74.6M | for (int x = 0; x < width; x++) | 187 | 66.4M | dst[y * dstStride + x] = ref[offset + x]; | 188 | 79.9M | } | 189 | 10.0M | } | 190 | | | 191 | | // Flip for horizontal. | 192 | 11.0M | if (horMode) | 193 | 5.46M | { | 194 | 43.6M | for (int y = 0; y < width - 1; y++) | 195 | 38.1M | { | 196 | 190M | for (int x = y + 1; x < width; x++) | 197 | 152M | { | 198 | 152M | pixel tmp = dst[y * dstStride + x]; | 199 | 152M | dst[y * dstStride + x] = dst[x * dstStride + y]; | 200 | 152M | dst[x * dstStride + y] = tmp; | 201 | 152M | } | 202 | 38.1M | } | 203 | 5.46M | } | 204 | 11.0M | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<16>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 104 | 2.46M | { | 105 | 2.46M | int width2 = width << 1; | 106 | | // Flip the neighbours in the horizontal case. | 107 | 2.46M | int horMode = dirMode < 18; | 108 | 2.46M | pixel neighbourBuf[129]; | 109 | 2.46M | const pixel *srcPix = srcPix0; | 110 | | | 111 | 2.46M | if (horMode) | 112 | 1.18M | { | 113 | 1.18M | neighbourBuf[0] = srcPix[0]; | 114 | 38.9M | for (int i = 0; i < width << 1; i++) | 115 | 37.7M | { | 116 | 37.7M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; | 117 | 37.7M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; | 118 | 37.7M | } | 119 | 1.18M | srcPix = neighbourBuf; | 120 | 1.18M | } | 121 | | | 122 | | // Intra prediction angle and inverse angle tables. | 123 | 2.46M | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; | 124 | 2.46M | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; | 125 | | | 126 | | // Get the prediction angle. | 127 | 2.46M | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; | 128 | 2.46M | int angle = angleTable[8 + angleOffset]; | 129 | | | 130 | | // Vertical Prediction. | 131 | 2.46M | if (!angle) | 132 | 205k | { | 133 | 3.49M | for (int y = 0; y < width; y++) | 134 | 55.9M | for (int x = 0; x < width; x++) | 135 | 52.6M | dst[y * dstStride + x] = srcPix[1 + x]; | 136 | | | 137 | 205k | if (bFilter) | 138 | 147k | { | 139 | 147k | int topLeft = srcPix[0], top = srcPix[1]; | 140 | 2.50M | for (int y = 0; y < width; y++) | 141 | 2.35M | dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1))); | 142 | 147k | } | 143 | 205k | } | 144 | 2.25M | else // Angular prediction. | 145 | 2.25M | { | 146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). | 147 | 2.25M | pixel refBuf[64]; | 148 | 2.25M | const pixel *ref; | 149 | | | 150 | | // Use the projected left neighbours and the top neighbours. | 151 | 2.25M | if (angle < 0) | 152 | 1.07M | { | 153 | | // Number of neighbours projected. | 154 | 1.07M | int nbProjected = -((width * angle) >> 5) - 1; | 155 | 1.07M | pixel *ref_pix = refBuf + nbProjected + 1; | 156 | | | 157 | | // Project the neighbours. | 158 | 1.07M | int invAngle = invAngleTable[- angleOffset - 1]; | 159 | 1.07M | int invAngleSum = 128; | 160 | 8.18M | for (int i = 0; i < nbProjected; i++) | 161 | 7.11M | { | 162 | 7.11M | invAngleSum += invAngle; | 163 | 7.11M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; | 164 | 7.11M | } | 165 | | | 166 | | // Copy the top-left and top pixels. | 167 | 19.3M | for (int i = 0; i < width + 1; i++) | 168 | 18.3M | ref_pix[-1 + i] = srcPix[i]; | 169 | 1.07M | ref = ref_pix; | 170 | 1.07M | } | 171 | 1.17M | else // Use the top and top-right neighbours. | 172 | 1.17M | ref = srcPix + 1; | 173 | | | 174 | | // Pass every row. | 175 | 2.25M | int angleSum = 0; | 176 | 38.1M | for (int y = 0; y < width; y++) | 177 | 35.8M | { | 178 | 35.8M | angleSum += angle; | 179 | 35.8M | int offset = angleSum >> 5; | 180 | 35.8M | int fraction = angleSum & 31; | 181 | | | 182 | 35.8M | if (fraction) // Interpolate | 183 | 533M | for (int x = 0; x < width; x++) | 184 | 502M | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); | 185 | 4.42M | else // Copy. | 186 | 76.2M | for (int x = 0; x < width; x++) | 187 | 71.8M | dst[y * dstStride + x] = ref[offset + x]; | 188 | 35.8M | } | 189 | 2.25M | } | 190 | | | 191 | | // Flip for horizontal. | 192 | 2.46M | if (horMode) | 193 | 1.18M | { | 194 | 18.8M | for (int y = 0; y < width - 1; y++) | 195 | 17.6M | { | 196 | 159M | for (int x = y + 1; x < width; x++) | 197 | 141M | { | 198 | 141M | pixel tmp = dst[y * dstStride + x]; | 199 | 141M | dst[y * dstStride + x] = dst[x * dstStride + y]; | 200 | 141M | dst[x * dstStride + y] = tmp; | 201 | 141M | } | 202 | 17.6M | } | 203 | 1.18M | } | 204 | 2.46M | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<32>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 104 | 489k | { | 105 | 489k | int width2 = width << 1; | 106 | | // Flip the neighbours in the horizontal case. | 107 | 489k | int horMode = dirMode < 18; | 108 | 489k | pixel neighbourBuf[129]; | 109 | 489k | const pixel *srcPix = srcPix0; | 110 | | | 111 | 489k | if (horMode) | 112 | 238k | { | 113 | 238k | neighbourBuf[0] = srcPix[0]; | 114 | 15.4M | for (int i = 0; i < width << 1; i++) | 115 | 15.2M | { | 116 | 15.2M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; | 117 | 15.2M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; | 118 | 15.2M | } | 119 | 238k | srcPix = neighbourBuf; | 120 | 238k | } | 121 | | | 122 | | // Intra prediction angle and inverse angle tables. | 123 | 489k | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; | 124 | 489k | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; | 125 | | | 126 | | // Get the prediction angle. | 127 | 489k | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; | 128 | 489k | int angle = angleTable[8 + angleOffset]; | 129 | | | 130 | | // Vertical Prediction. | 131 | 489k | if (!angle) | 132 | 30.0k | { | 133 | 990k | for (int y = 0; y < width; y++) | 134 | 31.6M | for (int x = 0; x < width; x++) | 135 | 30.7M | dst[y * dstStride + x] = srcPix[1 + x]; | 136 | | | 137 | 30.0k | if (bFilter) | 138 | 0 | { | 139 | 0 | int topLeft = srcPix[0], top = srcPix[1]; | 140 | 0 | for (int y = 0; y < width; y++) | 141 | 0 | dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1))); | 142 | 0 | } | 143 | 30.0k | } | 144 | 459k | else // Angular prediction. | 145 | 459k | { | 146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). | 147 | 459k | pixel refBuf[64]; | 148 | 459k | const pixel *ref; | 149 | | | 150 | | // Use the projected left neighbours and the top neighbours. | 151 | 459k | if (angle < 0) | 152 | 221k | { | 153 | | // Number of neighbours projected. | 154 | 221k | int nbProjected = -((width * angle) >> 5) - 1; | 155 | 221k | pixel *ref_pix = refBuf + nbProjected + 1; | 156 | | | 157 | | // Project the neighbours. | 158 | 221k | int invAngle = invAngleTable[- angleOffset - 1]; | 159 | 221k | int invAngleSum = 128; | 160 | 3.22M | for (int i = 0; i < nbProjected; i++) | 161 | 3.00M | { | 162 | 3.00M | invAngleSum += invAngle; | 163 | 3.00M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; | 164 | 3.00M | } | 165 | | | 166 | | // Copy the top-left and top pixels. | 167 | 7.54M | for (int i = 0; i < width + 1; i++) | 168 | 7.32M | ref_pix[-1 + i] = srcPix[i]; | 169 | 221k | ref = ref_pix; | 170 | 221k | } | 171 | 238k | else // Use the top and top-right neighbours. | 172 | 238k | ref = srcPix + 1; | 173 | | | 174 | | // Pass every row. | 175 | 459k | int angleSum = 0; | 176 | 15.0M | for (int y = 0; y < width; y++) | 177 | 14.5M | { | 178 | 14.5M | angleSum += angle; | 179 | 14.5M | int offset = angleSum >> 5; | 180 | 14.5M | int fraction = angleSum & 31; | 181 | | | 182 | 14.5M | if (fraction) // Interpolate | 183 | 416M | for (int x = 0; x < width; x++) | 184 | 403M | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); | 185 | 1.91M | else // Copy. | 186 | 64.4M | for (int x = 0; x < width; x++) | 187 | 62.4M | dst[y * dstStride + x] = ref[offset + x]; | 188 | 14.5M | } | 189 | 459k | } | 190 | | | 191 | | // Flip for horizontal. | 192 | 489k | if (horMode) | 193 | 238k | { | 194 | 7.61M | for (int y = 0; y < width - 1; y++) | 195 | 7.37M | { | 196 | 125M | for (int x = y + 1; x < width; x++) | 197 | 117M | { | 198 | 117M | pixel tmp = dst[y * dstStride + x]; | 199 | 117M | dst[y * dstStride + x] = dst[x * dstStride + y]; | 200 | 117M | dst[x * dstStride + y] = tmp; | 201 | 117M | } | 202 | 7.37M | } | 203 | 238k | } | 204 | 489k | } |
|
205 | | |
206 | | template<int log2Size> |
207 | | void all_angs_pred_c(pixel *dest, pixel *refPix, pixel *filtPix, int bLuma) |
208 | 0 | { |
209 | 0 | const int size = 1 << log2Size; |
210 | 0 | for (int mode = 2; mode <= 34; mode++) |
211 | 0 | { |
212 | 0 | pixel *srcPix = (g_intraFilterFlags[mode] & size ? filtPix : refPix); |
213 | 0 | pixel *out = dest + ((mode - 2) << (log2Size * 2)); |
214 | |
|
215 | 0 | intra_pred_ang_c<size>(out, size, srcPix, mode, bLuma); |
216 | | |
217 | | // Optimize code don't flip buffer |
218 | 0 | bool modeHor = (mode < 18); |
219 | | |
220 | | // transpose the block if this is a horizontal mode |
221 | 0 | if (modeHor) |
222 | 0 | { |
223 | 0 | for (int k = 0; k < size - 1; k++) |
224 | 0 | { |
225 | 0 | for (int l = k + 1; l < size; l++) |
226 | 0 | { |
227 | 0 | pixel tmp = out[k * size + l]; |
228 | 0 | out[k * size + l] = out[l * size + k]; |
229 | 0 | out[l * size + k] = tmp; |
230 | 0 | } |
231 | 0 | } |
232 | 0 | } |
233 | 0 | } |
234 | 0 | } Unexecuted instantiation: intrapred.cpp:void (anonymous namespace)::all_angs_pred_c<2>(unsigned char*, unsigned char*, unsigned char*, int) Unexecuted instantiation: intrapred.cpp:void (anonymous namespace)::all_angs_pred_c<3>(unsigned char*, unsigned char*, unsigned char*, int) Unexecuted instantiation: intrapred.cpp:void (anonymous namespace)::all_angs_pred_c<4>(unsigned char*, unsigned char*, unsigned char*, int) Unexecuted instantiation: intrapred.cpp:void (anonymous namespace)::all_angs_pred_c<5>(unsigned char*, unsigned char*, unsigned char*, int) |
235 | | } |
236 | | |
237 | | namespace X265_NS { |
238 | | // x265 private namespace |
239 | | |
240 | | void setupIntraPrimitives_c(EncoderPrimitives& p) |
241 | 1 | { |
242 | 1 | p.cu[BLOCK_4x4].intra_filter = intraFilter<4>; |
243 | 1 | p.cu[BLOCK_8x8].intra_filter = intraFilter<8>; |
244 | 1 | p.cu[BLOCK_16x16].intra_filter = intraFilter<16>; |
245 | 1 | p.cu[BLOCK_32x32].intra_filter = intraFilter<32>; |
246 | | |
247 | 1 | p.cu[BLOCK_4x4].intra_pred[PLANAR_IDX] = planar_pred_c<2>; |
248 | 1 | p.cu[BLOCK_8x8].intra_pred[PLANAR_IDX] = planar_pred_c<3>; |
249 | 1 | p.cu[BLOCK_16x16].intra_pred[PLANAR_IDX] = planar_pred_c<4>; |
250 | 1 | p.cu[BLOCK_32x32].intra_pred[PLANAR_IDX] = planar_pred_c<5>; |
251 | | |
252 | 1 | p.cu[BLOCK_4x4].intra_pred[DC_IDX] = intra_pred_dc_c<4>; |
253 | 1 | p.cu[BLOCK_8x8].intra_pred[DC_IDX] = intra_pred_dc_c<8>; |
254 | 1 | p.cu[BLOCK_16x16].intra_pred[DC_IDX] = intra_pred_dc_c<16>; |
255 | 1 | p.cu[BLOCK_32x32].intra_pred[DC_IDX] = intra_pred_dc_c<32>; |
256 | | |
257 | 34 | for (int i = 2; i < NUM_INTRA_MODE; i++) |
258 | 33 | { |
259 | 33 | p.cu[BLOCK_4x4].intra_pred[i] = intra_pred_ang_c<4>; |
260 | 33 | p.cu[BLOCK_8x8].intra_pred[i] = intra_pred_ang_c<8>; |
261 | 33 | p.cu[BLOCK_16x16].intra_pred[i] = intra_pred_ang_c<16>; |
262 | 33 | p.cu[BLOCK_32x32].intra_pred[i] = intra_pred_ang_c<32>; |
263 | 33 | } |
264 | | |
265 | 1 | p.cu[BLOCK_4x4].intra_pred_allangs = all_angs_pred_c<2>; |
266 | 1 | p.cu[BLOCK_8x8].intra_pred_allangs = all_angs_pred_c<3>; |
267 | 1 | p.cu[BLOCK_16x16].intra_pred_allangs = all_angs_pred_c<4>; |
268 | 1 | p.cu[BLOCK_32x32].intra_pred_allangs = all_angs_pred_c<5>; |
269 | 1 | } |
270 | | } |