/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.29M | { |
34 | 1.29M | const int tuSize2 = tuSize << 1; |
35 | | |
36 | 1.29M | pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2]; |
37 | | |
38 | | // filtering top |
39 | 24.2M | for (int i = 1; i < tuSize2; i++) |
40 | 22.9M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; |
41 | 1.29M | filtered[tuSize2] = topLast; |
42 | | |
43 | | // filtering top-left |
44 | 1.29M | filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2; |
45 | | |
46 | | // filtering left |
47 | 1.29M | filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2; |
48 | 22.9M | for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++) |
49 | 21.6M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; |
50 | 1.29M | filtered[tuSize2 + tuSize2] = leftLast; |
51 | 1.29M | } 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.08M | { | 34 | 1.08M | const int tuSize2 = tuSize << 1; | 35 | | | 36 | 1.08M | pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2]; | 37 | | | 38 | | // filtering top | 39 | 17.2M | for (int i = 1; i < tuSize2; i++) | 40 | 16.2M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; | 41 | 1.08M | filtered[tuSize2] = topLast; | 42 | | | 43 | | // filtering top-left | 44 | 1.08M | filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2; | 45 | | | 46 | | // filtering left | 47 | 1.08M | filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2; | 48 | 16.2M | for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++) | 49 | 15.1M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; | 50 | 1.08M | filtered[tuSize2 + tuSize2] = leftLast; | 51 | 1.08M | } |
intrapred.cpp:void (anonymous namespace)::intraFilter<16>(unsigned char const*, unsigned char*) Line | Count | Source | 33 | 218k | { | 34 | 218k | const int tuSize2 = tuSize << 1; | 35 | | | 36 | 218k | pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2]; | 37 | | | 38 | | // filtering top | 39 | 6.98M | for (int i = 1; i < tuSize2; i++) | 40 | 6.76M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; | 41 | 218k | filtered[tuSize2] = topLast; | 42 | | | 43 | | // filtering top-left | 44 | 218k | filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2; | 45 | | | 46 | | // filtering left | 47 | 218k | filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2; | 48 | 6.76M | for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++) | 49 | 6.54M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; | 50 | 218k | filtered[tuSize2 + tuSize2] = leftLast; | 51 | 218k | } |
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.54M | { |
55 | | // boundary pixels processing |
56 | 2.54M | dst[0] = (pixel)((above[0] + left[0] + 2 * dst[0] + 2) >> 2); |
57 | | |
58 | 14.1M | for (int x = 1; x < size; x++) |
59 | 11.6M | dst[x] = (pixel)((above[x] + 3 * dst[x] + 2) >> 2); |
60 | | |
61 | 2.54M | dst += dststride; |
62 | 14.1M | for (int y = 1; y < size; y++) |
63 | 11.6M | { |
64 | 11.6M | *dst = (pixel)((left[y] + 3 * *dst + 2) >> 2); |
65 | 11.6M | dst += dststride; |
66 | 11.6M | } |
67 | 2.54M | } |
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.97M | { |
72 | 3.97M | int k, l; |
73 | | |
74 | 3.97M | int dcVal = width; |
75 | 25.6M | for (int i = 0; i < width; i++) |
76 | 21.6M | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; |
77 | | |
78 | 3.97M | dcVal = dcVal / (width + width); |
79 | 25.6M | for (k = 0; k < width; k++) |
80 | 190M | for (l = 0; l < width; l++) |
81 | 168M | dst[k * dstStride + l] = (pixel)dcVal; |
82 | | |
83 | 3.97M | if (bFilter) |
84 | 2.54M | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); |
85 | 3.97M | } intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<4>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 71 | 3.05M | { | 72 | 3.05M | int k, l; | 73 | | | 74 | 3.05M | int dcVal = width; | 75 | 15.2M | for (int i = 0; i < width; i++) | 76 | 12.2M | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; | 77 | | | 78 | 3.05M | dcVal = dcVal / (width + width); | 79 | 15.2M | for (k = 0; k < width; k++) | 80 | 60.9M | for (l = 0; l < width; l++) | 81 | 48.7M | dst[k * dstStride + l] = (pixel)dcVal; | 82 | | | 83 | 3.05M | if (bFilter) | 84 | 1.83M | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); | 85 | 3.05M | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<8>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 71 | 727k | { | 72 | 727k | int k, l; | 73 | | | 74 | 727k | int dcVal = width; | 75 | 6.54M | for (int i = 0; i < width; i++) | 76 | 5.81M | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; | 77 | | | 78 | 727k | dcVal = dcVal / (width + width); | 79 | 6.54M | for (k = 0; k < width; k++) | 80 | 52.3M | for (l = 0; l < width; l++) | 81 | 46.5M | dst[k * dstStride + l] = (pixel)dcVal; | 82 | | | 83 | 727k | if (bFilter) | 84 | 579k | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); | 85 | 727k | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<16>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 71 | 168k | { | 72 | 168k | int k, l; | 73 | | | 74 | 168k | int dcVal = width; | 75 | 2.85M | for (int i = 0; i < width; i++) | 76 | 2.69M | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; | 77 | | | 78 | 168k | dcVal = dcVal / (width + width); | 79 | 2.85M | for (k = 0; k < width; k++) | 80 | 45.7M | for (l = 0; l < width; l++) | 81 | 43.0M | dst[k * dstStride + l] = (pixel)dcVal; | 82 | | | 83 | 168k | if (bFilter) | 84 | 137k | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); | 85 | 168k | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<32>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 71 | 29.4k | { | 72 | 29.4k | int k, l; | 73 | | | 74 | 29.4k | int dcVal = width; | 75 | 972k | for (int i = 0; i < width; i++) | 76 | 942k | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; | 77 | | | 78 | 29.4k | dcVal = dcVal / (width + width); | 79 | 972k | for (k = 0; k < width; k++) | 80 | 31.0M | for (l = 0; l < width; l++) | 81 | 30.1M | dst[k * dstStride + l] = (pixel)dcVal; | 82 | | | 83 | 29.4k | if (bFilter) | 84 | 0 | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); | 85 | 29.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.94M | { |
90 | 6.94M | const int blkSize = 1 << log2Size; |
91 | | |
92 | 6.94M | const pixel* above = srcPix + 1; |
93 | 6.94M | const pixel* left = srcPix + (2 * blkSize + 1); |
94 | | |
95 | 6.94M | pixel topRight = above[blkSize]; |
96 | 6.94M | pixel bottomLeft = left[blkSize]; |
97 | 43.4M | for (int y = 0; y < blkSize; y++) |
98 | 297M | for (int x = 0; x < blkSize; x++) |
99 | 261M | 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.94M | } intrapred.cpp:void (anonymous namespace)::planar_pred_c<2>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 89 | 5.43M | { | 90 | 5.43M | const int blkSize = 1 << log2Size; | 91 | | | 92 | 5.43M | const pixel* above = srcPix + 1; | 93 | 5.43M | const pixel* left = srcPix + (2 * blkSize + 1); | 94 | | | 95 | 5.43M | pixel topRight = above[blkSize]; | 96 | 5.43M | pixel bottomLeft = left[blkSize]; | 97 | 27.1M | for (int y = 0; y < blkSize; y++) | 98 | 108M | for (int x = 0; x < blkSize; x++) | 99 | 86.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 | 5.43M | } |
intrapred.cpp:void (anonymous namespace)::planar_pred_c<3>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 89 | 1.22M | { | 90 | 1.22M | const int blkSize = 1 << log2Size; | 91 | | | 92 | 1.22M | const pixel* above = srcPix + 1; | 93 | 1.22M | const pixel* left = srcPix + (2 * blkSize + 1); | 94 | | | 95 | 1.22M | pixel topRight = above[blkSize]; | 96 | 1.22M | pixel bottomLeft = left[blkSize]; | 97 | 11.0M | for (int y = 0; y < blkSize; y++) | 98 | 88.3M | for (int x = 0; x < blkSize; x++) | 99 | 78.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.22M | } |
intrapred.cpp:void (anonymous namespace)::planar_pred_c<4>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 89 | 245k | { | 90 | 245k | const int blkSize = 1 << log2Size; | 91 | | | 92 | 245k | const pixel* above = srcPix + 1; | 93 | 245k | const pixel* left = srcPix + (2 * blkSize + 1); | 94 | | | 95 | 245k | pixel topRight = above[blkSize]; | 96 | 245k | pixel bottomLeft = left[blkSize]; | 97 | 4.18M | for (int y = 0; y < blkSize; y++) | 98 | 66.8M | for (int x = 0; x < blkSize; x++) | 99 | 62.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 | 245k | } |
intrapred.cpp:void (anonymous namespace)::planar_pred_c<5>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 89 | 32.0k | { | 90 | 32.0k | const int blkSize = 1 << log2Size; | 91 | | | 92 | 32.0k | const pixel* above = srcPix + 1; | 93 | 32.0k | const pixel* left = srcPix + (2 * blkSize + 1); | 94 | | | 95 | 32.0k | pixel topRight = above[blkSize]; | 96 | 32.0k | pixel bottomLeft = left[blkSize]; | 97 | 1.05M | for (int y = 0; y < blkSize; y++) | 98 | 33.8M | for (int x = 0; x < blkSize; x++) | 99 | 32.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 | 32.0k | } |
|
101 | | |
102 | | template<int width> |
103 | | void intra_pred_ang_c(pixel* dst, intptr_t dstStride, const pixel *srcPix0, int dirMode, int bFilter) |
104 | 58.2M | { |
105 | 58.2M | int width2 = width << 1; |
106 | | // Flip the neighbours in the horizontal case. |
107 | 58.2M | int horMode = dirMode < 18; |
108 | 58.2M | pixel neighbourBuf[129]; |
109 | 58.2M | const pixel *srcPix = srcPix0; |
110 | | |
111 | 58.2M | if (horMode) |
112 | 27.7M | { |
113 | 27.7M | neighbourBuf[0] = srcPix[0]; |
114 | 337M | for (int i = 0; i < width << 1; i++) |
115 | 309M | { |
116 | 309M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; |
117 | 309M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; |
118 | 309M | } |
119 | 27.7M | srcPix = neighbourBuf; |
120 | 27.7M | } |
121 | | |
122 | | // Intra prediction angle and inverse angle tables. |
123 | 58.2M | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; |
124 | 58.2M | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; |
125 | | |
126 | | // Get the prediction angle. |
127 | 58.2M | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; |
128 | 58.2M | int angle = angleTable[8 + angleOffset]; |
129 | | |
130 | | // Vertical Prediction. |
131 | 58.2M | if (!angle) |
132 | 6.18M | { |
133 | 38.2M | for (int y = 0; y < width; y++) |
134 | 260M | for (int x = 0; x < width; x++) |
135 | 228M | dst[y * dstStride + x] = srcPix[1 + x]; |
136 | | |
137 | 6.18M | if (bFilter) |
138 | 3.35M | { |
139 | 3.35M | int topLeft = srcPix[0], top = srcPix[1]; |
140 | 21.4M | for (int y = 0; y < width; y++) |
141 | 18.0M | dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1))); |
142 | 3.35M | } |
143 | 6.18M | } |
144 | 52.0M | else // Angular prediction. |
145 | 52.0M | { |
146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). |
147 | 52.0M | pixel refBuf[64]; |
148 | 52.0M | const pixel *ref; |
149 | | |
150 | | // Use the projected left neighbours and the top neighbours. |
151 | 52.0M | if (angle < 0) |
152 | 24.4M | { |
153 | | // Number of neighbours projected. |
154 | 24.4M | int nbProjected = -((width * angle) >> 5) - 1; |
155 | 24.4M | pixel *ref_pix = refBuf + nbProjected + 1; |
156 | | |
157 | | // Project the neighbours. |
158 | 24.4M | int invAngle = invAngleTable[- angleOffset - 1]; |
159 | 24.4M | int invAngleSum = 128; |
160 | 76.0M | for (int i = 0; i < nbProjected; i++) |
161 | 51.6M | { |
162 | 51.6M | invAngleSum += invAngle; |
163 | 51.6M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; |
164 | 51.6M | } |
165 | | |
166 | | // Copy the top-left and top pixels. |
167 | 185M | for (int i = 0; i < width + 1; i++) |
168 | 160M | ref_pix[-1 + i] = srcPix[i]; |
169 | 24.4M | ref = ref_pix; |
170 | 24.4M | } |
171 | 27.6M | else // Use the top and top-right neighbours. |
172 | 27.6M | ref = srcPix + 1; |
173 | | |
174 | | // Pass every row. |
175 | 52.0M | int angleSum = 0; |
176 | 341M | for (int y = 0; y < width; y++) |
177 | 289M | { |
178 | 289M | angleSum += angle; |
179 | 289M | int offset = angleSum >> 5; |
180 | 289M | int fraction = angleSum & 31; |
181 | | |
182 | 289M | if (fraction) // Interpolate |
183 | 2.31G | for (int x = 0; x < width; x++) |
184 | 2.06G | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); |
185 | 34.7M | else // Copy. |
186 | 318M | for (int x = 0; x < width; x++) |
187 | 284M | dst[y * dstStride + x] = ref[offset + x]; |
188 | 289M | } |
189 | 52.0M | } |
190 | | |
191 | | // Flip for horizontal. |
192 | 58.2M | if (horMode) |
193 | 27.7M | { |
194 | 154M | for (int y = 0; y < width - 1; y++) |
195 | 126M | { |
196 | 673M | for (int x = y + 1; x < width; x++) |
197 | 546M | { |
198 | 546M | pixel tmp = dst[y * dstStride + x]; |
199 | 546M | dst[y * dstStride + x] = dst[x * dstStride + y]; |
200 | 546M | dst[x * dstStride + y] = tmp; |
201 | 546M | } |
202 | 126M | } |
203 | 27.7M | } |
204 | 58.2M | } intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<4>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 104 | 43.8M | { | 105 | 43.8M | int width2 = width << 1; | 106 | | // Flip the neighbours in the horizontal case. | 107 | 43.8M | int horMode = dirMode < 18; | 108 | 43.8M | pixel neighbourBuf[129]; | 109 | 43.8M | const pixel *srcPix = srcPix0; | 110 | | | 111 | 43.8M | if (horMode) | 112 | 20.7M | { | 113 | 20.7M | neighbourBuf[0] = srcPix[0]; | 114 | 186M | for (int i = 0; i < width << 1; i++) | 115 | 165M | { | 116 | 165M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; | 117 | 165M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; | 118 | 165M | } | 119 | 20.7M | srcPix = neighbourBuf; | 120 | 20.7M | } | 121 | | | 122 | | // Intra prediction angle and inverse angle tables. | 123 | 43.8M | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; | 124 | 43.8M | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; | 125 | | | 126 | | // Get the prediction angle. | 127 | 43.8M | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; | 128 | 43.8M | int angle = angleTable[8 + angleOffset]; | 129 | | | 130 | | // Vertical Prediction. | 131 | 43.8M | if (!angle) | 132 | 4.94M | { | 133 | 24.6M | for (int y = 0; y < width; y++) | 134 | 98.7M | for (int x = 0; x < width; x++) | 135 | 78.9M | dst[y * dstStride + x] = srcPix[1 + x]; | 136 | | | 137 | 4.94M | if (bFilter) | 138 | 2.49M | { | 139 | 2.49M | int topLeft = srcPix[0], top = srcPix[1]; | 140 | 12.4M | for (int y = 0; y < width; y++) | 141 | 9.99M | dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1))); | 142 | 2.49M | } | 143 | 4.94M | } | 144 | 38.9M | else // Angular prediction. | 145 | 38.9M | { | 146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). | 147 | 38.9M | pixel refBuf[64]; | 148 | 38.9M | const pixel *ref; | 149 | | | 150 | | // Use the projected left neighbours and the top neighbours. | 151 | 38.9M | if (angle < 0) | 152 | 18.2M | { | 153 | | // Number of neighbours projected. | 154 | 18.2M | int nbProjected = -((width * angle) >> 5) - 1; | 155 | 18.2M | pixel *ref_pix = refBuf + nbProjected + 1; | 156 | | | 157 | | // Project the neighbours. | 158 | 18.2M | int invAngle = invAngleTable[- angleOffset - 1]; | 159 | 18.2M | int invAngleSum = 128; | 160 | 43.8M | for (int i = 0; i < nbProjected; i++) | 161 | 25.6M | { | 162 | 25.6M | invAngleSum += invAngle; | 163 | 25.6M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; | 164 | 25.6M | } | 165 | | | 166 | | // Copy the top-left and top pixels. | 167 | 109M | for (int i = 0; i < width + 1; i++) | 168 | 91.3M | ref_pix[-1 + i] = srcPix[i]; | 169 | 18.2M | ref = ref_pix; | 170 | 18.2M | } | 171 | 20.6M | else // Use the top and top-right neighbours. | 172 | 20.6M | ref = srcPix + 1; | 173 | | | 174 | | // Pass every row. | 175 | 38.9M | int angleSum = 0; | 176 | 194M | for (int y = 0; y < width; y++) | 177 | 155M | { | 178 | 155M | angleSum += angle; | 179 | 155M | int offset = angleSum >> 5; | 180 | 155M | int fraction = angleSum & 31; | 181 | | | 182 | 155M | if (fraction) // Interpolate | 183 | 679M | for (int x = 0; x < width; x++) | 184 | 543M | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); | 185 | 19.6M | else // Copy. | 186 | 97.7M | for (int x = 0; x < width; x++) | 187 | 78.0M | dst[y * dstStride + x] = ref[offset + x]; | 188 | 155M | } | 189 | 38.9M | } | 190 | | | 191 | | // Flip for horizontal. | 192 | 43.8M | if (horMode) | 193 | 20.7M | { | 194 | 82.8M | for (int y = 0; y < width - 1; y++) | 195 | 62.1M | { | 196 | 186M | 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 | 62.1M | } | 203 | 20.7M | } | 204 | 43.8M | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<8>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 104 | 11.3M | { | 105 | 11.3M | int width2 = width << 1; | 106 | | // Flip the neighbours in the horizontal case. | 107 | 11.3M | int horMode = dirMode < 18; | 108 | 11.3M | pixel neighbourBuf[129]; | 109 | 11.3M | const pixel *srcPix = srcPix0; | 110 | | | 111 | 11.3M | if (horMode) | 112 | 5.58M | { | 113 | 5.58M | neighbourBuf[0] = srcPix[0]; | 114 | 94.9M | for (int i = 0; i < width << 1; i++) | 115 | 89.3M | { | 116 | 89.3M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; | 117 | 89.3M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; | 118 | 89.3M | } | 119 | 5.58M | srcPix = neighbourBuf; | 120 | 5.58M | } | 121 | | | 122 | | // Intra prediction angle and inverse angle tables. | 123 | 11.3M | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; | 124 | 11.3M | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; | 125 | | | 126 | | // Get the prediction angle. | 127 | 11.3M | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; | 128 | 11.3M | int angle = angleTable[8 + angleOffset]; | 129 | | | 130 | | // Vertical Prediction. | 131 | 11.3M | if (!angle) | 132 | 1.00M | { | 133 | 9.00M | for (int y = 0; y < width; y++) | 134 | 71.9M | for (int x = 0; x < width; x++) | 135 | 63.9M | dst[y * dstStride + x] = srcPix[1 + x]; | 136 | | | 137 | 1.00M | if (bFilter) | 138 | 705k | { | 139 | 705k | int topLeft = srcPix[0], top = srcPix[1]; | 140 | 6.34M | for (int y = 0; y < width; y++) | 141 | 5.64M | dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1))); | 142 | 705k | } | 143 | 1.00M | } | 144 | 10.3M | else // Angular prediction. | 145 | 10.3M | { | 146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). | 147 | 10.3M | pixel refBuf[64]; | 148 | 10.3M | const pixel *ref; | 149 | | | 150 | | // Use the projected left neighbours and the top neighbours. | 151 | 10.3M | if (angle < 0) | 152 | 4.81M | { | 153 | | // Number of neighbours projected. | 154 | 4.81M | int nbProjected = -((width * angle) >> 5) - 1; | 155 | 4.81M | pixel *ref_pix = refBuf + nbProjected + 1; | 156 | | | 157 | | // Project the neighbours. | 158 | 4.81M | int invAngle = invAngleTable[- angleOffset - 1]; | 159 | 4.81M | int invAngleSum = 128; | 160 | 20.4M | for (int i = 0; i < nbProjected; i++) | 161 | 15.6M | { | 162 | 15.6M | invAngleSum += invAngle; | 163 | 15.6M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; | 164 | 15.6M | } | 165 | | | 166 | | // Copy the top-left and top pixels. | 167 | 48.1M | for (int i = 0; i < width + 1; i++) | 168 | 43.3M | ref_pix[-1 + i] = srcPix[i]; | 169 | 4.81M | ref = ref_pix; | 170 | 4.81M | } | 171 | 5.50M | else // Use the top and top-right neighbours. | 172 | 5.50M | ref = srcPix + 1; | 173 | | | 174 | | // Pass every row. | 175 | 10.3M | int angleSum = 0; | 176 | 92.6M | for (int y = 0; y < width; y++) | 177 | 82.2M | { | 178 | 82.2M | angleSum += angle; | 179 | 82.2M | int offset = angleSum >> 5; | 180 | 82.2M | int fraction = angleSum & 31; | 181 | | | 182 | 82.2M | if (fraction) // Interpolate | 183 | 662M | for (int x = 0; x < width; x++) | 184 | 588M | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); | 185 | 8.57M | else // Copy. | 186 | 76.5M | for (int x = 0; x < width; x++) | 187 | 68.0M | dst[y * dstStride + x] = ref[offset + x]; | 188 | 82.2M | } | 189 | 10.3M | } | 190 | | | 191 | | // Flip for horizontal. | 192 | 11.3M | if (horMode) | 193 | 5.58M | { | 194 | 44.6M | for (int y = 0; y < width - 1; y++) | 195 | 39.0M | { | 196 | 195M | for (int x = y + 1; x < width; x++) | 197 | 156M | { | 198 | 156M | pixel tmp = dst[y * dstStride + x]; | 199 | 156M | dst[y * dstStride + x] = dst[x * dstStride + y]; | 200 | 156M | dst[x * dstStride + y] = tmp; | 201 | 156M | } | 202 | 39.0M | } | 203 | 5.58M | } | 204 | 11.3M | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<16>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 104 | 2.51M | { | 105 | 2.51M | int width2 = width << 1; | 106 | | // Flip the neighbours in the horizontal case. | 107 | 2.51M | int horMode = dirMode < 18; | 108 | 2.51M | pixel neighbourBuf[129]; | 109 | 2.51M | const pixel *srcPix = srcPix0; | 110 | | | 111 | 2.51M | if (horMode) | 112 | 1.20M | { | 113 | 1.20M | neighbourBuf[0] = srcPix[0]; | 114 | 39.8M | for (int i = 0; i < width << 1; i++) | 115 | 38.6M | { | 116 | 38.6M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; | 117 | 38.6M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; | 118 | 38.6M | } | 119 | 1.20M | srcPix = neighbourBuf; | 120 | 1.20M | } | 121 | | | 122 | | // Intra prediction angle and inverse angle tables. | 123 | 2.51M | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; | 124 | 2.51M | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; | 125 | | | 126 | | // Get the prediction angle. | 127 | 2.51M | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; | 128 | 2.51M | int angle = angleTable[8 + angleOffset]; | 129 | | | 130 | | // Vertical Prediction. | 131 | 2.51M | if (!angle) | 132 | 210k | { | 133 | 3.58M | for (int y = 0; y < width; y++) | 134 | 57.3M | for (int x = 0; x < width; x++) | 135 | 53.9M | dst[y * dstStride + x] = srcPix[1 + x]; | 136 | | | 137 | 210k | if (bFilter) | 138 | 150k | { | 139 | 150k | int topLeft = srcPix[0], top = srcPix[1]; | 140 | 2.55M | for (int y = 0; y < width; y++) | 141 | 2.40M | dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1))); | 142 | 150k | } | 143 | 210k | } | 144 | 2.30M | else // Angular prediction. | 145 | 2.30M | { | 146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). | 147 | 2.30M | pixel refBuf[64]; | 148 | 2.30M | const pixel *ref; | 149 | | | 150 | | // Use the projected left neighbours and the top neighbours. | 151 | 2.30M | if (angle < 0) | 152 | 1.10M | { | 153 | | // Number of neighbours projected. | 154 | 1.10M | int nbProjected = -((width * angle) >> 5) - 1; | 155 | 1.10M | pixel *ref_pix = refBuf + nbProjected + 1; | 156 | | | 157 | | // Project the neighbours. | 158 | 1.10M | int invAngle = invAngleTable[- angleOffset - 1]; | 159 | 1.10M | int invAngleSum = 128; | 160 | 8.36M | for (int i = 0; i < nbProjected; i++) | 161 | 7.26M | { | 162 | 7.26M | invAngleSum += invAngle; | 163 | 7.26M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; | 164 | 7.26M | } | 165 | | | 166 | | // Copy the top-left and top pixels. | 167 | 19.8M | for (int i = 0; i < width + 1; i++) | 168 | 18.7M | ref_pix[-1 + i] = srcPix[i]; | 169 | 1.10M | ref = ref_pix; | 170 | 1.10M | } | 171 | 1.20M | else // Use the top and top-right neighbours. | 172 | 1.20M | ref = srcPix + 1; | 173 | | | 174 | | // Pass every row. | 175 | 2.30M | int angleSum = 0; | 176 | 39.0M | for (int y = 0; y < width; y++) | 177 | 36.7M | { | 178 | 36.7M | angleSum += angle; | 179 | 36.7M | int offset = angleSum >> 5; | 180 | 36.7M | int fraction = angleSum & 31; | 181 | | | 182 | 36.7M | if (fraction) // Interpolate | 183 | 547M | for (int x = 0; x < width; x++) | 184 | 514M | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); | 185 | 4.56M | else // Copy. | 186 | 78.0M | for (int x = 0; x < width; x++) | 187 | 73.4M | dst[y * dstStride + x] = ref[offset + x]; | 188 | 36.7M | } | 189 | 2.30M | } | 190 | | | 191 | | // Flip for horizontal. | 192 | 2.51M | if (horMode) | 193 | 1.20M | { | 194 | 19.2M | for (int y = 0; y < width - 1; y++) | 195 | 18.0M | { | 196 | 162M | for (int x = y + 1; x < width; x++) | 197 | 144M | { | 198 | 144M | pixel tmp = dst[y * dstStride + x]; | 199 | 144M | dst[y * dstStride + x] = dst[x * dstStride + y]; | 200 | 144M | dst[x * dstStride + y] = tmp; | 201 | 144M | } | 202 | 18.0M | } | 203 | 1.20M | } | 204 | 2.51M | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<32>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 104 | 505k | { | 105 | 505k | int width2 = width << 1; | 106 | | // Flip the neighbours in the horizontal case. | 107 | 505k | int horMode = dirMode < 18; | 108 | 505k | pixel neighbourBuf[129]; | 109 | 505k | const pixel *srcPix = srcPix0; | 110 | | | 111 | 505k | if (horMode) | 112 | 245k | { | 113 | 245k | neighbourBuf[0] = srcPix[0]; | 114 | 15.9M | for (int i = 0; i < width << 1; i++) | 115 | 15.7M | { | 116 | 15.7M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; | 117 | 15.7M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; | 118 | 15.7M | } | 119 | 245k | srcPix = neighbourBuf; | 120 | 245k | } | 121 | | | 122 | | // Intra prediction angle and inverse angle tables. | 123 | 505k | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; | 124 | 505k | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; | 125 | | | 126 | | // Get the prediction angle. | 127 | 505k | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; | 128 | 505k | int angle = angleTable[8 + angleOffset]; | 129 | | | 130 | | // Vertical Prediction. | 131 | 505k | if (!angle) | 132 | 30.9k | { | 133 | 1.02M | for (int y = 0; y < width; y++) | 134 | 32.6M | for (int x = 0; x < width; x++) | 135 | 31.6M | dst[y * dstStride + x] = srcPix[1 + x]; | 136 | | | 137 | 30.9k | 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.9k | } | 144 | 474k | else // Angular prediction. | 145 | 474k | { | 146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). | 147 | 474k | pixel refBuf[64]; | 148 | 474k | const pixel *ref; | 149 | | | 150 | | // Use the projected left neighbours and the top neighbours. | 151 | 474k | if (angle < 0) | 152 | 228k | { | 153 | | // Number of neighbours projected. | 154 | 228k | int nbProjected = -((width * angle) >> 5) - 1; | 155 | 228k | pixel *ref_pix = refBuf + nbProjected + 1; | 156 | | | 157 | | // Project the neighbours. | 158 | 228k | int invAngle = invAngleTable[- angleOffset - 1]; | 159 | 228k | int invAngleSum = 128; | 160 | 3.32M | for (int i = 0; i < nbProjected; i++) | 161 | 3.09M | { | 162 | 3.09M | invAngleSum += invAngle; | 163 | 3.09M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; | 164 | 3.09M | } | 165 | | | 166 | | // Copy the top-left and top pixels. | 167 | 7.78M | for (int i = 0; i < width + 1; i++) | 168 | 7.55M | ref_pix[-1 + i] = srcPix[i]; | 169 | 228k | ref = ref_pix; | 170 | 228k | } | 171 | 245k | else // Use the top and top-right neighbours. | 172 | 245k | ref = srcPix + 1; | 173 | | | 174 | | // Pass every row. | 175 | 474k | int angleSum = 0; | 176 | 15.5M | for (int y = 0; y < width; y++) | 177 | 15.1M | { | 178 | 15.1M | angleSum += angle; | 179 | 15.1M | int offset = angleSum >> 5; | 180 | 15.1M | int fraction = angleSum & 31; | 181 | | | 182 | 15.1M | if (fraction) // Interpolate | 183 | 430M | for (int x = 0; x < width; x++) | 184 | 417M | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); | 185 | 1.99M | else // Copy. | 186 | 66.4M | for (int x = 0; x < width; x++) | 187 | 64.4M | dst[y * dstStride + x] = ref[offset + x]; | 188 | 15.1M | } | 189 | 474k | } | 190 | | | 191 | | // Flip for horizontal. | 192 | 505k | if (horMode) | 193 | 245k | { | 194 | 7.86M | for (int y = 0; y < width - 1; y++) | 195 | 7.61M | { | 196 | 129M | 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 | 7.61M | } | 203 | 245k | } | 204 | 505k | } |
|
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 | | } |