/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.11M | { |
34 | 1.11M | const int tuSize2 = tuSize << 1; |
35 | | |
36 | 1.11M | pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2]; |
37 | | |
38 | | // filtering top |
39 | 20.8M | for (int i = 1; i < tuSize2; i++) |
40 | 19.7M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; |
41 | 1.11M | filtered[tuSize2] = topLast; |
42 | | |
43 | | // filtering top-left |
44 | 1.11M | filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2; |
45 | | |
46 | | // filtering left |
47 | 1.11M | filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2; |
48 | 19.7M | for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++) |
49 | 18.6M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; |
50 | 1.11M | filtered[tuSize2 + tuSize2] = leftLast; |
51 | 1.11M | } 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 | 928k | { | 34 | 928k | const int tuSize2 = tuSize << 1; | 35 | | | 36 | 928k | pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2]; | 37 | | | 38 | | // filtering top | 39 | 14.8M | for (int i = 1; i < tuSize2; i++) | 40 | 13.9M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; | 41 | 928k | filtered[tuSize2] = topLast; | 42 | | | 43 | | // filtering top-left | 44 | 928k | filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2; | 45 | | | 46 | | // filtering left | 47 | 928k | filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2; | 48 | 13.9M | for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++) | 49 | 12.9M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; | 50 | 928k | filtered[tuSize2 + tuSize2] = leftLast; | 51 | 928k | } |
intrapred.cpp:void (anonymous namespace)::intraFilter<16>(unsigned char const*, unsigned char*) Line | Count | Source | 33 | 187k | { | 34 | 187k | const int tuSize2 = tuSize << 1; | 35 | | | 36 | 187k | pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2]; | 37 | | | 38 | | // filtering top | 39 | 6.00M | for (int i = 1; i < tuSize2; i++) | 40 | 5.82M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; | 41 | 187k | filtered[tuSize2] = topLast; | 42 | | | 43 | | // filtering top-left | 44 | 187k | filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2; | 45 | | | 46 | | // filtering left | 47 | 187k | filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2; | 48 | 5.82M | for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++) | 49 | 5.63M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; | 50 | 187k | filtered[tuSize2 + tuSize2] = leftLast; | 51 | 187k | } |
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.17M | { |
55 | | // boundary pixels processing |
56 | 2.17M | dst[0] = (pixel)((above[0] + left[0] + 2 * dst[0] + 2) >> 2); |
57 | | |
58 | 12.1M | for (int x = 1; x < size; x++) |
59 | 9.92M | dst[x] = (pixel)((above[x] + 3 * dst[x] + 2) >> 2); |
60 | | |
61 | 2.17M | dst += dststride; |
62 | 12.1M | for (int y = 1; y < size; y++) |
63 | 9.92M | { |
64 | 9.92M | *dst = (pixel)((left[y] + 3 * *dst + 2) >> 2); |
65 | 9.92M | dst += dststride; |
66 | 9.92M | } |
67 | 2.17M | } |
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.40M | { |
72 | 3.40M | int k, l; |
73 | | |
74 | 3.40M | int dcVal = width; |
75 | 21.9M | for (int i = 0; i < width; i++) |
76 | 18.5M | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; |
77 | | |
78 | 3.40M | dcVal = dcVal / (width + width); |
79 | 21.9M | for (k = 0; k < width; k++) |
80 | 162M | for (l = 0; l < width; l++) |
81 | 143M | dst[k * dstStride + l] = (pixel)dcVal; |
82 | | |
83 | 3.40M | if (bFilter) |
84 | 2.17M | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); |
85 | 3.40M | } intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<4>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 71 | 2.61M | { | 72 | 2.61M | int k, l; | 73 | | | 74 | 2.61M | int dcVal = width; | 75 | 13.0M | for (int i = 0; i < width; i++) | 76 | 10.4M | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; | 77 | | | 78 | 2.61M | dcVal = dcVal / (width + width); | 79 | 13.0M | for (k = 0; k < width; k++) | 80 | 52.2M | for (l = 0; l < width; l++) | 81 | 41.7M | dst[k * dstStride + l] = (pixel)dcVal; | 82 | | | 83 | 2.61M | if (bFilter) | 84 | 1.56M | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); | 85 | 2.61M | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<8>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 71 | 622k | { | 72 | 622k | int k, l; | 73 | | | 74 | 622k | int dcVal = width; | 75 | 5.60M | for (int i = 0; i < width; i++) | 76 | 4.97M | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; | 77 | | | 78 | 622k | dcVal = dcVal / (width + width); | 79 | 5.59M | for (k = 0; k < width; k++) | 80 | 44.7M | for (l = 0; l < width; l++) | 81 | 39.8M | dst[k * dstStride + l] = (pixel)dcVal; | 82 | | | 83 | 622k | if (bFilter) | 84 | 495k | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); | 85 | 622k | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<16>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 71 | 143k | { | 72 | 143k | int k, l; | 73 | | | 74 | 143k | int dcVal = width; | 75 | 2.43M | for (int i = 0; i < width; i++) | 76 | 2.29M | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; | 77 | | | 78 | 143k | dcVal = dcVal / (width + width); | 79 | 2.43M | for (k = 0; k < width; k++) | 80 | 38.9M | for (l = 0; l < width; l++) | 81 | 36.6M | dst[k * dstStride + l] = (pixel)dcVal; | 82 | | | 83 | 143k | if (bFilter) | 84 | 117k | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); | 85 | 143k | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<32>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 71 | 24.8k | { | 72 | 24.8k | int k, l; | 73 | | | 74 | 24.8k | int dcVal = width; | 75 | 818k | for (int i = 0; i < width; i++) | 76 | 793k | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; | 77 | | | 78 | 24.8k | dcVal = dcVal / (width + width); | 79 | 818k | for (k = 0; k < width; k++) | 80 | 26.1M | for (l = 0; l < width; l++) | 81 | 25.3M | dst[k * dstStride + l] = (pixel)dcVal; | 82 | | | 83 | 24.8k | if (bFilter) | 84 | 0 | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); | 85 | 24.8k | } |
|
86 | | |
87 | | template<int log2Size> |
88 | | void planar_pred_c(pixel* dst, intptr_t dstStride, const pixel* srcPix, int /*dirMode*/, int /*bFilter*/) |
89 | 5.96M | { |
90 | 5.96M | const int blkSize = 1 << log2Size; |
91 | | |
92 | 5.96M | const pixel* above = srcPix + 1; |
93 | 5.96M | const pixel* left = srcPix + (2 * blkSize + 1); |
94 | | |
95 | 5.96M | pixel topRight = above[blkSize]; |
96 | 5.96M | pixel bottomLeft = left[blkSize]; |
97 | 37.3M | for (int y = 0; y < blkSize; y++) |
98 | 255M | for (int x = 0; x < blkSize; x++) |
99 | 223M | 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.96M | } intrapred.cpp:void (anonymous namespace)::planar_pred_c<2>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 89 | 4.66M | { | 90 | 4.66M | const int blkSize = 1 << log2Size; | 91 | | | 92 | 4.66M | const pixel* above = srcPix + 1; | 93 | 4.66M | const pixel* left = srcPix + (2 * blkSize + 1); | 94 | | | 95 | 4.66M | pixel topRight = above[blkSize]; | 96 | 4.66M | pixel bottomLeft = left[blkSize]; | 97 | 23.3M | for (int y = 0; y < blkSize; y++) | 98 | 93.2M | for (int x = 0; x < blkSize; x++) | 99 | 74.6M | 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 | 4.66M | } |
intrapred.cpp:void (anonymous namespace)::planar_pred_c<3>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 89 | 1.05M | { | 90 | 1.05M | const int blkSize = 1 << log2Size; | 91 | | | 92 | 1.05M | const pixel* above = srcPix + 1; | 93 | 1.05M | const pixel* left = srcPix + (2 * blkSize + 1); | 94 | | | 95 | 1.05M | pixel topRight = above[blkSize]; | 96 | 1.05M | pixel bottomLeft = left[blkSize]; | 97 | 9.49M | for (int y = 0; y < blkSize; y++) | 98 | 75.9M | for (int x = 0; x < blkSize; x++) | 99 | 67.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 | 1.05M | } |
intrapred.cpp:void (anonymous namespace)::planar_pred_c<4>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 89 | 211k | { | 90 | 211k | const int blkSize = 1 << log2Size; | 91 | | | 92 | 211k | const pixel* above = srcPix + 1; | 93 | 211k | const pixel* left = srcPix + (2 * blkSize + 1); | 94 | | | 95 | 211k | pixel topRight = above[blkSize]; | 96 | 211k | pixel bottomLeft = left[blkSize]; | 97 | 3.58M | for (int y = 0; y < blkSize; y++) | 98 | 57.3M | for (int x = 0; x < blkSize; x++) | 99 | 53.9M | 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 | 211k | } |
intrapred.cpp:void (anonymous namespace)::planar_pred_c<5>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 89 | 27.1k | { | 90 | 27.1k | const int blkSize = 1 << log2Size; | 91 | | | 92 | 27.1k | const pixel* above = srcPix + 1; | 93 | 27.1k | const pixel* left = srcPix + (2 * blkSize + 1); | 94 | | | 95 | 27.1k | pixel topRight = above[blkSize]; | 96 | 27.1k | pixel bottomLeft = left[blkSize]; | 97 | 895k | for (int y = 0; y < blkSize; y++) | 98 | 28.6M | for (int x = 0; x < blkSize; x++) | 99 | 27.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 | 27.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 | 49.9M | { |
105 | 49.9M | int width2 = width << 1; |
106 | | // Flip the neighbours in the horizontal case. |
107 | 49.9M | int horMode = dirMode < 18; |
108 | 49.9M | pixel neighbourBuf[129]; |
109 | 49.9M | const pixel *srcPix = srcPix0; |
110 | | |
111 | 49.9M | if (horMode) |
112 | 23.8M | { |
113 | 23.8M | neighbourBuf[0] = srcPix[0]; |
114 | 289M | for (int i = 0; i < width << 1; i++) |
115 | 265M | { |
116 | 265M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; |
117 | 265M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; |
118 | 265M | } |
119 | 23.8M | srcPix = neighbourBuf; |
120 | 23.8M | } |
121 | | |
122 | | // Intra prediction angle and inverse angle tables. |
123 | 49.9M | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; |
124 | 49.9M | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; |
125 | | |
126 | | // Get the prediction angle. |
127 | 49.9M | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; |
128 | 49.9M | int angle = angleTable[8 + angleOffset]; |
129 | | |
130 | | // Vertical Prediction. |
131 | 49.9M | if (!angle) |
132 | 5.30M | { |
133 | 32.8M | for (int y = 0; y < width; y++) |
134 | 223M | for (int x = 0; x < width; x++) |
135 | 195M | dst[y * dstStride + x] = srcPix[1 + x]; |
136 | | |
137 | 5.30M | if (bFilter) |
138 | 2.88M | { |
139 | 2.88M | int topLeft = srcPix[0], top = srcPix[1]; |
140 | 18.4M | for (int y = 0; y < width; y++) |
141 | 15.5M | dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1))); |
142 | 2.88M | } |
143 | 5.30M | } |
144 | 44.6M | else // Angular prediction. |
145 | 44.6M | { |
146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). |
147 | 44.6M | pixel refBuf[64]; |
148 | 44.6M | const pixel *ref; |
149 | | |
150 | | // Use the projected left neighbours and the top neighbours. |
151 | 44.6M | if (angle < 0) |
152 | 20.9M | { |
153 | | // Number of neighbours projected. |
154 | 20.9M | int nbProjected = -((width * angle) >> 5) - 1; |
155 | 20.9M | pixel *ref_pix = refBuf + nbProjected + 1; |
156 | | |
157 | | // Project the neighbours. |
158 | 20.9M | int invAngle = invAngleTable[- angleOffset - 1]; |
159 | 20.9M | int invAngleSum = 128; |
160 | 65.2M | for (int i = 0; i < nbProjected; i++) |
161 | 44.2M | { |
162 | 44.2M | invAngleSum += invAngle; |
163 | 44.2M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; |
164 | 44.2M | } |
165 | | |
166 | | // Copy the top-left and top pixels. |
167 | 159M | for (int i = 0; i < width + 1; i++) |
168 | 138M | ref_pix[-1 + i] = srcPix[i]; |
169 | 20.9M | ref = ref_pix; |
170 | 20.9M | } |
171 | 23.6M | else // Use the top and top-right neighbours. |
172 | 23.6M | ref = srcPix + 1; |
173 | | |
174 | | // Pass every row. |
175 | 44.6M | int angleSum = 0; |
176 | 293M | for (int y = 0; y < width; y++) |
177 | 248M | { |
178 | 248M | angleSum += angle; |
179 | 248M | int offset = angleSum >> 5; |
180 | 248M | int fraction = angleSum & 31; |
181 | | |
182 | 248M | if (fraction) // Interpolate |
183 | 1.98G | for (int x = 0; x < width; x++) |
184 | 1.76G | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); |
185 | 29.7M | else // Copy. |
186 | 272M | for (int x = 0; x < width; x++) |
187 | 242M | dst[y * dstStride + x] = ref[offset + x]; |
188 | 248M | } |
189 | 44.6M | } |
190 | | |
191 | | // Flip for horizontal. |
192 | 49.9M | if (horMode) |
193 | 23.8M | { |
194 | 132M | for (int y = 0; y < width - 1; y++) |
195 | 108M | { |
196 | 576M | for (int x = y + 1; x < width; x++) |
197 | 467M | { |
198 | 467M | pixel tmp = dst[y * dstStride + x]; |
199 | 467M | dst[y * dstStride + x] = dst[x * dstStride + y]; |
200 | 467M | dst[x * dstStride + y] = tmp; |
201 | 467M | } |
202 | 108M | } |
203 | 23.8M | } |
204 | 49.9M | } intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<4>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 104 | 37.6M | { | 105 | 37.6M | int width2 = width << 1; | 106 | | // Flip the neighbours in the horizontal case. | 107 | 37.6M | int horMode = dirMode < 18; | 108 | 37.6M | pixel neighbourBuf[129]; | 109 | 37.6M | const pixel *srcPix = srcPix0; | 110 | | | 111 | 37.6M | if (horMode) | 112 | 17.7M | { | 113 | 17.7M | neighbourBuf[0] = srcPix[0]; | 114 | 160M | for (int i = 0; i < width << 1; i++) | 115 | 142M | { | 116 | 142M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; | 117 | 142M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; | 118 | 142M | } | 119 | 17.7M | srcPix = neighbourBuf; | 120 | 17.7M | } | 121 | | | 122 | | // Intra prediction angle and inverse angle tables. | 123 | 37.6M | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; | 124 | 37.6M | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; | 125 | | | 126 | | // Get the prediction angle. | 127 | 37.6M | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; | 128 | 37.6M | int angle = angleTable[8 + angleOffset]; | 129 | | | 130 | | // Vertical Prediction. | 131 | 37.6M | if (!angle) | 132 | 4.24M | { | 133 | 21.2M | for (int y = 0; y < width; y++) | 134 | 84.7M | for (int x = 0; x < width; x++) | 135 | 67.8M | dst[y * dstStride + x] = srcPix[1 + x]; | 136 | | | 137 | 4.24M | if (bFilter) | 138 | 2.14M | { | 139 | 2.14M | int topLeft = srcPix[0], top = srcPix[1]; | 140 | 10.7M | for (int y = 0; y < width; y++) | 141 | 8.59M | dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1))); | 142 | 2.14M | } | 143 | 4.24M | } | 144 | 33.4M | else // Angular prediction. | 145 | 33.4M | { | 146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). | 147 | 33.4M | pixel refBuf[64]; | 148 | 33.4M | const pixel *ref; | 149 | | | 150 | | // Use the projected left neighbours and the top neighbours. | 151 | 33.4M | if (angle < 0) | 152 | 15.6M | { | 153 | | // Number of neighbours projected. | 154 | 15.6M | int nbProjected = -((width * angle) >> 5) - 1; | 155 | 15.6M | pixel *ref_pix = refBuf + nbProjected + 1; | 156 | | | 157 | | // Project the neighbours. | 158 | 15.6M | int invAngle = invAngleTable[- angleOffset - 1]; | 159 | 15.6M | int invAngleSum = 128; | 160 | 37.6M | for (int i = 0; i < nbProjected; i++) | 161 | 21.9M | { | 162 | 21.9M | invAngleSum += invAngle; | 163 | 21.9M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; | 164 | 21.9M | } | 165 | | | 166 | | // Copy the top-left and top pixels. | 167 | 94.1M | for (int i = 0; i < width + 1; i++) | 168 | 78.4M | ref_pix[-1 + i] = srcPix[i]; | 169 | 15.6M | ref = ref_pix; | 170 | 15.6M | } | 171 | 17.7M | else // Use the top and top-right neighbours. | 172 | 17.7M | ref = srcPix + 1; | 173 | | | 174 | | // Pass every row. | 175 | 33.4M | int angleSum = 0; | 176 | 166M | for (int y = 0; y < width; y++) | 177 | 133M | { | 178 | 133M | angleSum += angle; | 179 | 133M | int offset = angleSum >> 5; | 180 | 133M | int fraction = angleSum & 31; | 181 | | | 182 | 133M | if (fraction) // Interpolate | 183 | 583M | for (int x = 0; x < width; x++) | 184 | 466M | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); | 185 | 16.8M | else // Copy. | 186 | 83.8M | for (int x = 0; x < width; x++) | 187 | 67.0M | dst[y * dstStride + x] = ref[offset + x]; | 188 | 133M | } | 189 | 33.4M | } | 190 | | | 191 | | // Flip for horizontal. | 192 | 37.6M | if (horMode) | 193 | 17.8M | { | 194 | 71.1M | for (int y = 0; y < width - 1; y++) | 195 | 53.3M | { | 196 | 159M | for (int x = y + 1; x < width; x++) | 197 | 106M | { | 198 | 106M | pixel tmp = dst[y * dstStride + x]; | 199 | 106M | dst[y * dstStride + x] = dst[x * dstStride + y]; | 200 | 106M | dst[x * dstStride + y] = tmp; | 201 | 106M | } | 202 | 53.3M | } | 203 | 17.8M | } | 204 | 37.6M | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<8>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 104 | 9.71M | { | 105 | 9.71M | int width2 = width << 1; | 106 | | // Flip the neighbours in the horizontal case. | 107 | 9.71M | int horMode = dirMode < 18; | 108 | 9.71M | pixel neighbourBuf[129]; | 109 | 9.71M | const pixel *srcPix = srcPix0; | 110 | | | 111 | 9.71M | if (horMode) | 112 | 4.79M | { | 113 | 4.79M | neighbourBuf[0] = srcPix[0]; | 114 | 81.4M | for (int i = 0; i < width << 1; i++) | 115 | 76.6M | { | 116 | 76.6M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; | 117 | 76.6M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; | 118 | 76.6M | } | 119 | 4.79M | srcPix = neighbourBuf; | 120 | 4.79M | } | 121 | | | 122 | | // Intra prediction angle and inverse angle tables. | 123 | 9.71M | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; | 124 | 9.71M | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; | 125 | | | 126 | | // Get the prediction angle. | 127 | 9.71M | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; | 128 | 9.71M | int angle = angleTable[8 + angleOffset]; | 129 | | | 130 | | // Vertical Prediction. | 131 | 9.71M | if (!angle) | 132 | 860k | { | 133 | 7.73M | for (int y = 0; y < width; y++) | 134 | 61.8M | for (int x = 0; x < width; x++) | 135 | 54.9M | dst[y * dstStride + x] = srcPix[1 + x]; | 136 | | | 137 | 860k | if (bFilter) | 138 | 606k | { | 139 | 606k | int topLeft = srcPix[0], top = srcPix[1]; | 140 | 5.45M | for (int y = 0; y < width; y++) | 141 | 4.84M | dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1))); | 142 | 606k | } | 143 | 860k | } | 144 | 8.85M | else // Angular prediction. | 145 | 8.85M | { | 146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). | 147 | 8.85M | pixel refBuf[64]; | 148 | 8.85M | const pixel *ref; | 149 | | | 150 | | // Use the projected left neighbours and the top neighbours. | 151 | 8.85M | if (angle < 0) | 152 | 4.13M | { | 153 | | // Number of neighbours projected. | 154 | 4.13M | int nbProjected = -((width * angle) >> 5) - 1; | 155 | 4.13M | pixel *ref_pix = refBuf + nbProjected + 1; | 156 | | | 157 | | // Project the neighbours. | 158 | 4.13M | int invAngle = invAngleTable[- angleOffset - 1]; | 159 | 4.13M | int invAngleSum = 128; | 160 | 17.5M | for (int i = 0; i < nbProjected; i++) | 161 | 13.4M | { | 162 | 13.4M | invAngleSum += invAngle; | 163 | 13.4M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; | 164 | 13.4M | } | 165 | | | 166 | | // Copy the top-left and top pixels. | 167 | 41.3M | for (int i = 0; i < width + 1; i++) | 168 | 37.1M | ref_pix[-1 + i] = srcPix[i]; | 169 | 4.13M | ref = ref_pix; | 170 | 4.13M | } | 171 | 4.72M | else // Use the top and top-right neighbours. | 172 | 4.72M | ref = srcPix + 1; | 173 | | | 174 | | // Pass every row. | 175 | 8.85M | int angleSum = 0; | 176 | 79.3M | for (int y = 0; y < width; y++) | 177 | 70.5M | { | 178 | 70.5M | angleSum += angle; | 179 | 70.5M | int offset = angleSum >> 5; | 180 | 70.5M | int fraction = angleSum & 31; | 181 | | | 182 | 70.5M | if (fraction) // Interpolate | 183 | 567M | for (int x = 0; x < width; x++) | 184 | 504M | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); | 185 | 7.37M | else // Copy. | 186 | 65.7M | for (int x = 0; x < width; x++) | 187 | 58.3M | dst[y * dstStride + x] = ref[offset + x]; | 188 | 70.5M | } | 189 | 8.85M | } | 190 | | | 191 | | // Flip for horizontal. | 192 | 9.71M | if (horMode) | 193 | 4.79M | { | 194 | 38.3M | for (int y = 0; y < width - 1; y++) | 195 | 33.5M | { | 196 | 167M | for (int x = y + 1; x < width; x++) | 197 | 134M | { | 198 | 134M | pixel tmp = dst[y * dstStride + x]; | 199 | 134M | dst[y * dstStride + x] = dst[x * dstStride + y]; | 200 | 134M | dst[x * dstStride + y] = tmp; | 201 | 134M | } | 202 | 33.5M | } | 203 | 4.79M | } | 204 | 9.71M | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<16>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 104 | 2.16M | { | 105 | 2.16M | int width2 = width << 1; | 106 | | // Flip the neighbours in the horizontal case. | 107 | 2.16M | int horMode = dirMode < 18; | 108 | 2.16M | pixel neighbourBuf[129]; | 109 | 2.16M | const pixel *srcPix = srcPix0; | 110 | | | 111 | 2.16M | if (horMode) | 112 | 1.03M | { | 113 | 1.03M | neighbourBuf[0] = srcPix[0]; | 114 | 34.2M | for (int i = 0; i < width << 1; i++) | 115 | 33.2M | { | 116 | 33.2M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; | 117 | 33.2M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; | 118 | 33.2M | } | 119 | 1.03M | srcPix = neighbourBuf; | 120 | 1.03M | } | 121 | | | 122 | | // Intra prediction angle and inverse angle tables. | 123 | 2.16M | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; | 124 | 2.16M | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; | 125 | | | 126 | | // Get the prediction angle. | 127 | 2.16M | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; | 128 | 2.16M | int angle = angleTable[8 + angleOffset]; | 129 | | | 130 | | // Vertical Prediction. | 131 | 2.16M | if (!angle) | 132 | 180k | { | 133 | 3.07M | for (int y = 0; y < width; y++) | 134 | 49.1M | for (int x = 0; x < width; x++) | 135 | 46.2M | dst[y * dstStride + x] = srcPix[1 + x]; | 136 | | | 137 | 180k | if (bFilter) | 138 | 129k | { | 139 | 129k | int topLeft = srcPix[0], top = srcPix[1]; | 140 | 2.20M | for (int y = 0; y < width; y++) | 141 | 2.07M | dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1))); | 142 | 129k | } | 143 | 180k | } | 144 | 1.98M | else // Angular prediction. | 145 | 1.98M | { | 146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). | 147 | 1.98M | pixel refBuf[64]; | 148 | 1.98M | const pixel *ref; | 149 | | | 150 | | // Use the projected left neighbours and the top neighbours. | 151 | 1.98M | if (angle < 0) | 152 | 947k | { | 153 | | // Number of neighbours projected. | 154 | 947k | int nbProjected = -((width * angle) >> 5) - 1; | 155 | 947k | pixel *ref_pix = refBuf + nbProjected + 1; | 156 | | | 157 | | // Project the neighbours. | 158 | 947k | int invAngle = invAngleTable[- angleOffset - 1]; | 159 | 947k | int invAngleSum = 128; | 160 | 7.20M | for (int i = 0; i < nbProjected; i++) | 161 | 6.25M | { | 162 | 6.25M | invAngleSum += invAngle; | 163 | 6.25M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; | 164 | 6.25M | } | 165 | | | 166 | | // Copy the top-left and top pixels. | 167 | 17.0M | for (int i = 0; i < width + 1; i++) | 168 | 16.1M | ref_pix[-1 + i] = srcPix[i]; | 169 | 947k | ref = ref_pix; | 170 | 947k | } | 171 | 1.03M | else // Use the top and top-right neighbours. | 172 | 1.03M | ref = srcPix + 1; | 173 | | | 174 | | // Pass every row. | 175 | 1.98M | int angleSum = 0; | 176 | 33.6M | for (int y = 0; y < width; y++) | 177 | 31.6M | { | 178 | 31.6M | angleSum += angle; | 179 | 31.6M | int offset = angleSum >> 5; | 180 | 31.6M | int fraction = angleSum & 31; | 181 | | | 182 | 31.6M | if (fraction) // Interpolate | 183 | 470M | for (int x = 0; x < width; x++) | 184 | 442M | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); | 185 | 3.91M | else // Copy. | 186 | 67.0M | for (int x = 0; x < width; x++) | 187 | 63.1M | dst[y * dstStride + x] = ref[offset + x]; | 188 | 31.6M | } | 189 | 1.98M | } | 190 | | | 191 | | // Flip for horizontal. | 192 | 2.16M | if (horMode) | 193 | 1.03M | { | 194 | 16.5M | for (int y = 0; y < width - 1; y++) | 195 | 15.5M | { | 196 | 139M | for (int x = y + 1; x < width; x++) | 197 | 124M | { | 198 | 124M | pixel tmp = dst[y * dstStride + x]; | 199 | 124M | dst[y * dstStride + x] = dst[x * dstStride + y]; | 200 | 124M | dst[x * dstStride + y] = tmp; | 201 | 124M | } | 202 | 15.5M | } | 203 | 1.03M | } | 204 | 2.16M | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<32>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 104 | 426k | { | 105 | 426k | int width2 = width << 1; | 106 | | // Flip the neighbours in the horizontal case. | 107 | 426k | int horMode = dirMode < 18; | 108 | 426k | pixel neighbourBuf[129]; | 109 | 426k | const pixel *srcPix = srcPix0; | 110 | | | 111 | 426k | if (horMode) | 112 | 207k | { | 113 | 207k | neighbourBuf[0] = srcPix[0]; | 114 | 13.4M | for (int i = 0; i < width << 1; i++) | 115 | 13.2M | { | 116 | 13.2M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; | 117 | 13.2M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; | 118 | 13.2M | } | 119 | 207k | srcPix = neighbourBuf; | 120 | 207k | } | 121 | | | 122 | | // Intra prediction angle and inverse angle tables. | 123 | 426k | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; | 124 | 426k | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; | 125 | | | 126 | | // Get the prediction angle. | 127 | 426k | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; | 128 | 426k | int angle = angleTable[8 + angleOffset]; | 129 | | | 130 | | // Vertical Prediction. | 131 | 426k | if (!angle) | 132 | 26.1k | { | 133 | 862k | for (int y = 0; y < width; y++) | 134 | 27.5M | for (int x = 0; x < width; x++) | 135 | 26.7M | dst[y * dstStride + x] = srcPix[1 + x]; | 136 | | | 137 | 26.1k | 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 | 26.1k | } | 144 | 400k | else // Angular prediction. | 145 | 400k | { | 146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). | 147 | 400k | pixel refBuf[64]; | 148 | 400k | const pixel *ref; | 149 | | | 150 | | // Use the projected left neighbours and the top neighbours. | 151 | 400k | if (angle < 0) | 152 | 193k | { | 153 | | // Number of neighbours projected. | 154 | 193k | int nbProjected = -((width * angle) >> 5) - 1; | 155 | 193k | pixel *ref_pix = refBuf + nbProjected + 1; | 156 | | | 157 | | // Project the neighbours. | 158 | 193k | int invAngle = invAngleTable[- angleOffset - 1]; | 159 | 193k | int invAngleSum = 128; | 160 | 2.80M | for (int i = 0; i < nbProjected; i++) | 161 | 2.61M | { | 162 | 2.61M | invAngleSum += invAngle; | 163 | 2.61M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; | 164 | 2.61M | } | 165 | | | 166 | | // Copy the top-left and top pixels. | 167 | 6.57M | for (int i = 0; i < width + 1; i++) | 168 | 6.37M | ref_pix[-1 + i] = srcPix[i]; | 169 | 193k | ref = ref_pix; | 170 | 193k | } | 171 | 207k | else // Use the top and top-right neighbours. | 172 | 207k | ref = srcPix + 1; | 173 | | | 174 | | // Pass every row. | 175 | 400k | int angleSum = 0; | 176 | 13.1M | for (int y = 0; y < width; y++) | 177 | 12.7M | { | 178 | 12.7M | angleSum += angle; | 179 | 12.7M | int offset = angleSum >> 5; | 180 | 12.7M | int fraction = angleSum & 31; | 181 | | | 182 | 12.7M | if (fraction) // Interpolate | 183 | 361M | for (int x = 0; x < width; x++) | 184 | 350M | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); | 185 | 1.67M | else // Copy. | 186 | 56.0M | for (int x = 0; x < width; x++) | 187 | 54.3M | dst[y * dstStride + x] = ref[offset + x]; | 188 | 12.7M | } | 189 | 400k | } | 190 | | | 191 | | // Flip for horizontal. | 192 | 426k | if (horMode) | 193 | 207k | { | 194 | 6.63M | for (int y = 0; y < width - 1; y++) | 195 | 6.42M | { | 196 | 109M | for (int x = y + 1; x < width; x++) | 197 | 102M | { | 198 | 102M | pixel tmp = dst[y * dstStride + x]; | 199 | 102M | dst[y * dstStride + x] = dst[x * dstStride + y]; | 200 | 102M | dst[x * dstStride + y] = tmp; | 201 | 102M | } | 202 | 6.42M | } | 203 | 207k | } | 204 | 426k | } |
|
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 | | } |