/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.14M | { |
34 | 1.14M | const int tuSize2 = tuSize << 1; |
35 | | |
36 | 1.14M | pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2]; |
37 | | |
38 | | // filtering top |
39 | 21.3M | for (int i = 1; i < tuSize2; i++) |
40 | 20.1M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; |
41 | 1.14M | filtered[tuSize2] = topLast; |
42 | | |
43 | | // filtering top-left |
44 | 1.14M | filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2; |
45 | | |
46 | | // filtering left |
47 | 1.14M | filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2; |
48 | 20.1M | for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++) |
49 | 19.0M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; |
50 | 1.14M | filtered[tuSize2 + tuSize2] = leftLast; |
51 | 1.14M | } 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 | 949k | { | 34 | 949k | const int tuSize2 = tuSize << 1; | 35 | | | 36 | 949k | pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2]; | 37 | | | 38 | | // filtering top | 39 | 15.1M | for (int i = 1; i < tuSize2; i++) | 40 | 14.2M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; | 41 | 949k | filtered[tuSize2] = topLast; | 42 | | | 43 | | // filtering top-left | 44 | 949k | filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2; | 45 | | | 46 | | // filtering left | 47 | 949k | filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2; | 48 | 14.2M | for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++) | 49 | 13.2M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; | 50 | 949k | filtered[tuSize2 + tuSize2] = leftLast; | 51 | 949k | } |
intrapred.cpp:void (anonymous namespace)::intraFilter<16>(unsigned char const*, unsigned char*) Line | Count | Source | 33 | 191k | { | 34 | 191k | const int tuSize2 = tuSize << 1; | 35 | | | 36 | 191k | pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2]; | 37 | | | 38 | | // filtering top | 39 | 6.13M | for (int i = 1; i < tuSize2; i++) | 40 | 5.94M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; | 41 | 191k | filtered[tuSize2] = topLast; | 42 | | | 43 | | // filtering top-left | 44 | 191k | filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2; | 45 | | | 46 | | // filtering left | 47 | 191k | filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2; | 48 | 5.94M | for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++) | 49 | 5.75M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; | 50 | 191k | filtered[tuSize2 + tuSize2] = leftLast; | 51 | 191k | } |
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.23M | { |
55 | | // boundary pixels processing |
56 | 2.23M | dst[0] = (pixel)((above[0] + left[0] + 2 * dst[0] + 2) >> 2); |
57 | | |
58 | 12.4M | for (int x = 1; x < size; x++) |
59 | 10.2M | dst[x] = (pixel)((above[x] + 3 * dst[x] + 2) >> 2); |
60 | | |
61 | 2.23M | dst += dststride; |
62 | 12.4M | for (int y = 1; y < size; y++) |
63 | 10.2M | { |
64 | 10.2M | *dst = (pixel)((left[y] + 3 * *dst + 2) >> 2); |
65 | 10.2M | dst += dststride; |
66 | 10.2M | } |
67 | 2.23M | } |
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.49M | { |
72 | 3.49M | int k, l; |
73 | | |
74 | 3.49M | int dcVal = width; |
75 | 22.4M | for (int i = 0; i < width; i++) |
76 | 19.0M | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; |
77 | | |
78 | 3.49M | dcVal = dcVal / (width + width); |
79 | 22.4M | for (k = 0; k < width; k++) |
80 | 166M | for (l = 0; l < width; l++) |
81 | 147M | dst[k * dstStride + l] = (pixel)dcVal; |
82 | | |
83 | 3.49M | if (bFilter) |
84 | 2.23M | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); |
85 | 3.49M | } intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<4>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 71 | 2.67M | { | 72 | 2.67M | int k, l; | 73 | | | 74 | 2.67M | int dcVal = width; | 75 | 13.3M | for (int i = 0; i < width; i++) | 76 | 10.7M | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; | 77 | | | 78 | 2.67M | dcVal = dcVal / (width + width); | 79 | 13.3M | for (k = 0; k < width; k++) | 80 | 53.5M | for (l = 0; l < width; l++) | 81 | 42.8M | dst[k * dstStride + l] = (pixel)dcVal; | 82 | | | 83 | 2.67M | if (bFilter) | 84 | 1.60M | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); | 85 | 2.67M | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<8>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 71 | 639k | { | 72 | 639k | int k, l; | 73 | | | 74 | 639k | int dcVal = width; | 75 | 5.75M | for (int i = 0; i < width; i++) | 76 | 5.11M | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; | 77 | | | 78 | 639k | dcVal = dcVal / (width + width); | 79 | 5.75M | for (k = 0; k < width; k++) | 80 | 45.9M | for (l = 0; l < width; l++) | 81 | 40.8M | dst[k * dstStride + l] = (pixel)dcVal; | 82 | | | 83 | 639k | if (bFilter) | 84 | 509k | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); | 85 | 639k | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<16>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 71 | 147k | { | 72 | 147k | int k, l; | 73 | | | 74 | 147k | int dcVal = width; | 75 | 2.50M | for (int i = 0; i < width; i++) | 76 | 2.35M | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; | 77 | | | 78 | 147k | dcVal = dcVal / (width + width); | 79 | 2.50M | for (k = 0; k < width; k++) | 80 | 40.0M | for (l = 0; l < width; l++) | 81 | 37.6M | dst[k * dstStride + l] = (pixel)dcVal; | 82 | | | 83 | 147k | if (bFilter) | 84 | 121k | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); | 85 | 147k | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<32>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 71 | 25.5k | { | 72 | 25.5k | int k, l; | 73 | | | 74 | 25.5k | int dcVal = width; | 75 | 841k | for (int i = 0; i < width; i++) | 76 | 816k | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; | 77 | | | 78 | 25.5k | dcVal = dcVal / (width + width); | 79 | 841k | for (k = 0; k < width; k++) | 80 | 26.9M | for (l = 0; l < width; l++) | 81 | 26.0M | dst[k * dstStride + l] = (pixel)dcVal; | 82 | | | 83 | 25.5k | if (bFilter) | 84 | 0 | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); | 85 | 25.5k | } |
|
86 | | |
87 | | template<int log2Size> |
88 | | void planar_pred_c(pixel* dst, intptr_t dstStride, const pixel* srcPix, int /*dirMode*/, int /*bFilter*/) |
89 | 6.10M | { |
90 | 6.10M | const int blkSize = 1 << log2Size; |
91 | | |
92 | 6.10M | const pixel* above = srcPix + 1; |
93 | 6.10M | const pixel* left = srcPix + (2 * blkSize + 1); |
94 | | |
95 | 6.10M | pixel topRight = above[blkSize]; |
96 | 6.10M | pixel bottomLeft = left[blkSize]; |
97 | 38.1M | for (int y = 0; y < blkSize; y++) |
98 | 261M | for (int x = 0; x < blkSize; x++) |
99 | 229M | 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.10M | } intrapred.cpp:void (anonymous namespace)::planar_pred_c<2>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 89 | 4.77M | { | 90 | 4.77M | const int blkSize = 1 << log2Size; | 91 | | | 92 | 4.77M | const pixel* above = srcPix + 1; | 93 | 4.77M | const pixel* left = srcPix + (2 * blkSize + 1); | 94 | | | 95 | 4.77M | pixel topRight = above[blkSize]; | 96 | 4.77M | pixel bottomLeft = left[blkSize]; | 97 | 23.8M | for (int y = 0; y < blkSize; y++) | 98 | 95.4M | for (int x = 0; x < blkSize; x++) | 99 | 76.3M | 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.77M | } |
intrapred.cpp:void (anonymous namespace)::planar_pred_c<3>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 89 | 1.07M | { | 90 | 1.07M | const int blkSize = 1 << log2Size; | 91 | | | 92 | 1.07M | const pixel* above = srcPix + 1; | 93 | 1.07M | const pixel* left = srcPix + (2 * blkSize + 1); | 94 | | | 95 | 1.07M | pixel topRight = above[blkSize]; | 96 | 1.07M | pixel bottomLeft = left[blkSize]; | 97 | 9.70M | for (int y = 0; y < blkSize; y++) | 98 | 77.6M | for (int x = 0; x < blkSize; x++) | 99 | 68.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 | 1.07M | } |
intrapred.cpp:void (anonymous namespace)::planar_pred_c<4>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 89 | 215k | { | 90 | 215k | const int blkSize = 1 << log2Size; | 91 | | | 92 | 215k | const pixel* above = srcPix + 1; | 93 | 215k | const pixel* left = srcPix + (2 * blkSize + 1); | 94 | | | 95 | 215k | pixel topRight = above[blkSize]; | 96 | 215k | pixel bottomLeft = left[blkSize]; | 97 | 3.66M | for (int y = 0; y < blkSize; y++) | 98 | 58.6M | for (int x = 0; x < blkSize; x++) | 99 | 55.1M | 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 | 215k | } |
intrapred.cpp:void (anonymous namespace)::planar_pred_c<5>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 89 | 27.8k | { | 90 | 27.8k | const int blkSize = 1 << log2Size; | 91 | | | 92 | 27.8k | const pixel* above = srcPix + 1; | 93 | 27.8k | const pixel* left = srcPix + (2 * blkSize + 1); | 94 | | | 95 | 27.8k | pixel topRight = above[blkSize]; | 96 | 27.8k | pixel bottomLeft = left[blkSize]; | 97 | 919k | for (int y = 0; y < blkSize; y++) | 98 | 29.4M | for (int x = 0; x < blkSize; x++) | 99 | 28.5M | 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.8k | } |
|
101 | | |
102 | | template<int width> |
103 | | void intra_pred_ang_c(pixel* dst, intptr_t dstStride, const pixel *srcPix0, int dirMode, int bFilter) |
104 | 51.0M | { |
105 | 51.0M | int width2 = width << 1; |
106 | | // Flip the neighbours in the horizontal case. |
107 | 51.0M | int horMode = dirMode < 18; |
108 | 51.0M | pixel neighbourBuf[129]; |
109 | 51.0M | const pixel *srcPix = srcPix0; |
110 | | |
111 | 51.0M | if (horMode) |
112 | 24.3M | { |
113 | 24.3M | neighbourBuf[0] = srcPix[0]; |
114 | 296M | for (int i = 0; i < width << 1; i++) |
115 | 271M | { |
116 | 271M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; |
117 | 271M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; |
118 | 271M | } |
119 | 24.3M | srcPix = neighbourBuf; |
120 | 24.3M | } |
121 | | |
122 | | // Intra prediction angle and inverse angle tables. |
123 | 51.0M | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; |
124 | 51.0M | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; |
125 | | |
126 | | // Get the prediction angle. |
127 | 51.0M | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; |
128 | 51.0M | int angle = angleTable[8 + angleOffset]; |
129 | | |
130 | | // Vertical Prediction. |
131 | 51.0M | if (!angle) |
132 | 5.43M | { |
133 | 33.6M | for (int y = 0; y < width; y++) |
134 | 228M | for (int x = 0; x < width; x++) |
135 | 200M | dst[y * dstStride + x] = srcPix[1 + x]; |
136 | | |
137 | 5.43M | if (bFilter) |
138 | 2.95M | { |
139 | 2.95M | int topLeft = srcPix[0], top = srcPix[1]; |
140 | 18.8M | for (int y = 0; y < width; y++) |
141 | 15.8M | dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1))); |
142 | 2.95M | } |
143 | 5.43M | } |
144 | 45.6M | else // Angular prediction. |
145 | 45.6M | { |
146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). |
147 | 45.6M | pixel refBuf[64]; |
148 | 45.6M | const pixel *ref; |
149 | | |
150 | | // Use the projected left neighbours and the top neighbours. |
151 | 45.6M | if (angle < 0) |
152 | 21.4M | { |
153 | | // Number of neighbours projected. |
154 | 21.4M | int nbProjected = -((width * angle) >> 5) - 1; |
155 | 21.4M | pixel *ref_pix = refBuf + nbProjected + 1; |
156 | | |
157 | | // Project the neighbours. |
158 | 21.4M | int invAngle = invAngleTable[- angleOffset - 1]; |
159 | 21.4M | int invAngleSum = 128; |
160 | 66.7M | for (int i = 0; i < nbProjected; i++) |
161 | 45.3M | { |
162 | 45.3M | invAngleSum += invAngle; |
163 | 45.3M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; |
164 | 45.3M | } |
165 | | |
166 | | // Copy the top-left and top pixels. |
167 | 162M | for (int i = 0; i < width + 1; i++) |
168 | 141M | ref_pix[-1 + i] = srcPix[i]; |
169 | 21.4M | ref = ref_pix; |
170 | 21.4M | } |
171 | 24.1M | else // Use the top and top-right neighbours. |
172 | 24.1M | ref = srcPix + 1; |
173 | | |
174 | | // Pass every row. |
175 | 45.6M | int angleSum = 0; |
176 | 299M | for (int y = 0; y < width; y++) |
177 | 253M | { |
178 | 253M | angleSum += angle; |
179 | 253M | int offset = angleSum >> 5; |
180 | 253M | int fraction = angleSum & 31; |
181 | | |
182 | 253M | if (fraction) // Interpolate |
183 | 2.02G | for (int x = 0; x < width; x++) |
184 | 1.80G | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); |
185 | 30.4M | else // Copy. |
186 | 279M | for (int x = 0; x < width; x++) |
187 | 248M | dst[y * dstStride + x] = ref[offset + x]; |
188 | 253M | } |
189 | 45.6M | } |
190 | | |
191 | | // Flip for horizontal. |
192 | 51.0M | if (horMode) |
193 | 24.4M | { |
194 | 135M | for (int y = 0; y < width - 1; y++) |
195 | 111M | { |
196 | 590M | for (int x = y + 1; x < width; x++) |
197 | 478M | { |
198 | 478M | pixel tmp = dst[y * dstStride + x]; |
199 | 478M | dst[y * dstStride + x] = dst[x * dstStride + y]; |
200 | 478M | dst[x * dstStride + y] = tmp; |
201 | 478M | } |
202 | 111M | } |
203 | 24.4M | } |
204 | 51.0M | } intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<4>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 104 | 38.4M | { | 105 | 38.4M | int width2 = width << 1; | 106 | | // Flip the neighbours in the horizontal case. | 107 | 38.4M | int horMode = dirMode < 18; | 108 | 38.4M | pixel neighbourBuf[129]; | 109 | 38.4M | const pixel *srcPix = srcPix0; | 110 | | | 111 | 38.4M | if (horMode) | 112 | 18.1M | { | 113 | 18.1M | neighbourBuf[0] = srcPix[0]; | 114 | 163M | for (int i = 0; i < width << 1; i++) | 115 | 145M | { | 116 | 145M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; | 117 | 145M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; | 118 | 145M | } | 119 | 18.1M | srcPix = neighbourBuf; | 120 | 18.1M | } | 121 | | | 122 | | // Intra prediction angle and inverse angle tables. | 123 | 38.4M | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; | 124 | 38.4M | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; | 125 | | | 126 | | // Get the prediction angle. | 127 | 38.4M | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; | 128 | 38.4M | int angle = angleTable[8 + angleOffset]; | 129 | | | 130 | | // Vertical Prediction. | 131 | 38.4M | if (!angle) | 132 | 4.34M | { | 133 | 21.7M | for (int y = 0; y < width; y++) | 134 | 86.8M | for (int x = 0; x < width; x++) | 135 | 69.4M | dst[y * dstStride + x] = srcPix[1 + x]; | 136 | | | 137 | 4.34M | if (bFilter) | 138 | 2.20M | { | 139 | 2.20M | int topLeft = srcPix[0], top = srcPix[1]; | 140 | 11.0M | for (int y = 0; y < width; y++) | 141 | 8.80M | dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1))); | 142 | 2.20M | } | 143 | 4.34M | } | 144 | 34.1M | else // Angular prediction. | 145 | 34.1M | { | 146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). | 147 | 34.1M | pixel refBuf[64]; | 148 | 34.1M | const pixel *ref; | 149 | | | 150 | | // Use the projected left neighbours and the top neighbours. | 151 | 34.1M | if (angle < 0) | 152 | 16.0M | { | 153 | | // Number of neighbours projected. | 154 | 16.0M | int nbProjected = -((width * angle) >> 5) - 1; | 155 | 16.0M | pixel *ref_pix = refBuf + nbProjected + 1; | 156 | | | 157 | | // Project the neighbours. | 158 | 16.0M | int invAngle = invAngleTable[- angleOffset - 1]; | 159 | 16.0M | int invAngleSum = 128; | 160 | 38.5M | for (int i = 0; i < nbProjected; i++) | 161 | 22.4M | { | 162 | 22.4M | invAngleSum += invAngle; | 163 | 22.4M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; | 164 | 22.4M | } | 165 | | | 166 | | // Copy the top-left and top pixels. | 167 | 96.2M | for (int i = 0; i < width + 1; i++) | 168 | 80.2M | ref_pix[-1 + i] = srcPix[i]; | 169 | 16.0M | ref = ref_pix; | 170 | 16.0M | } | 171 | 18.0M | else // Use the top and top-right neighbours. | 172 | 18.0M | ref = srcPix + 1; | 173 | | | 174 | | // Pass every row. | 175 | 34.1M | int angleSum = 0; | 176 | 170M | for (int y = 0; y < width; y++) | 177 | 136M | { | 178 | 136M | angleSum += angle; | 179 | 136M | int offset = angleSum >> 5; | 180 | 136M | int fraction = angleSum & 31; | 181 | | | 182 | 136M | if (fraction) // Interpolate | 183 | 595M | for (int x = 0; x < width; x++) | 184 | 475M | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); | 185 | 17.2M | else // Copy. | 186 | 85.8M | for (int x = 0; x < width; x++) | 187 | 68.6M | dst[y * dstStride + x] = ref[offset + x]; | 188 | 136M | } | 189 | 34.1M | } | 190 | | | 191 | | // Flip for horizontal. | 192 | 38.4M | if (horMode) | 193 | 18.2M | { | 194 | 72.7M | for (int y = 0; y < width - 1; y++) | 195 | 54.5M | { | 196 | 163M | for (int x = y + 1; x < width; x++) | 197 | 108M | { | 198 | 108M | pixel tmp = dst[y * dstStride + x]; | 199 | 108M | dst[y * dstStride + x] = dst[x * dstStride + y]; | 200 | 108M | dst[x * dstStride + y] = tmp; | 201 | 108M | } | 202 | 54.5M | } | 203 | 18.2M | } | 204 | 38.4M | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<8>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 104 | 9.95M | { | 105 | 9.95M | int width2 = width << 1; | 106 | | // Flip the neighbours in the horizontal case. | 107 | 9.95M | int horMode = dirMode < 18; | 108 | 9.95M | pixel neighbourBuf[129]; | 109 | 9.95M | const pixel *srcPix = srcPix0; | 110 | | | 111 | 9.95M | if (horMode) | 112 | 4.91M | { | 113 | 4.91M | neighbourBuf[0] = srcPix[0]; | 114 | 83.4M | for (int i = 0; i < width << 1; i++) | 115 | 78.5M | { | 116 | 78.5M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; | 117 | 78.5M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; | 118 | 78.5M | } | 119 | 4.91M | srcPix = neighbourBuf; | 120 | 4.91M | } | 121 | | | 122 | | // Intra prediction angle and inverse angle tables. | 123 | 9.95M | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; | 124 | 9.95M | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; | 125 | | | 126 | | // Get the prediction angle. | 127 | 9.95M | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; | 128 | 9.95M | int angle = angleTable[8 + angleOffset]; | 129 | | | 130 | | // Vertical Prediction. | 131 | 9.95M | if (!angle) | 132 | 881k | { | 133 | 7.92M | for (int y = 0; y < width; y++) | 134 | 63.3M | for (int x = 0; x < width; x++) | 135 | 56.3M | dst[y * dstStride + x] = srcPix[1 + x]; | 136 | | | 137 | 881k | if (bFilter) | 138 | 621k | { | 139 | 621k | int topLeft = srcPix[0], top = srcPix[1]; | 140 | 5.58M | for (int y = 0; y < width; y++) | 141 | 4.96M | dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1))); | 142 | 621k | } | 143 | 881k | } | 144 | 9.07M | else // Angular prediction. | 145 | 9.07M | { | 146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). | 147 | 9.07M | pixel refBuf[64]; | 148 | 9.07M | const pixel *ref; | 149 | | | 150 | | // Use the projected left neighbours and the top neighbours. | 151 | 9.07M | if (angle < 0) | 152 | 4.23M | { | 153 | | // Number of neighbours projected. | 154 | 4.23M | int nbProjected = -((width * angle) >> 5) - 1; | 155 | 4.23M | pixel *ref_pix = refBuf + nbProjected + 1; | 156 | | | 157 | | // Project the neighbours. | 158 | 4.23M | int invAngle = invAngleTable[- angleOffset - 1]; | 159 | 4.23M | int invAngleSum = 128; | 160 | 18.0M | for (int i = 0; i < nbProjected; i++) | 161 | 13.7M | { | 162 | 13.7M | invAngleSum += invAngle; | 163 | 13.7M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; | 164 | 13.7M | } | 165 | | | 166 | | // Copy the top-left and top pixels. | 167 | 42.3M | for (int i = 0; i < width + 1; i++) | 168 | 38.0M | ref_pix[-1 + i] = srcPix[i]; | 169 | 4.23M | ref = ref_pix; | 170 | 4.23M | } | 171 | 4.83M | else // Use the top and top-right neighbours. | 172 | 4.83M | ref = srcPix + 1; | 173 | | | 174 | | // Pass every row. | 175 | 9.07M | int angleSum = 0; | 176 | 81.3M | for (int y = 0; y < width; y++) | 177 | 72.3M | { | 178 | 72.3M | angleSum += angle; | 179 | 72.3M | int offset = angleSum >> 5; | 180 | 72.3M | int fraction = angleSum & 31; | 181 | | | 182 | 72.3M | if (fraction) // Interpolate | 183 | 581M | for (int x = 0; x < width; x++) | 184 | 517M | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); | 185 | 7.57M | else // Copy. | 186 | 67.3M | for (int x = 0; x < width; x++) | 187 | 59.8M | dst[y * dstStride + x] = ref[offset + x]; | 188 | 72.3M | } | 189 | 9.07M | } | 190 | | | 191 | | // Flip for horizontal. | 192 | 9.95M | if (horMode) | 193 | 4.91M | { | 194 | 39.2M | for (int y = 0; y < width - 1; y++) | 195 | 34.3M | { | 196 | 171M | for (int x = y + 1; x < width; x++) | 197 | 137M | { | 198 | 137M | pixel tmp = dst[y * dstStride + x]; | 199 | 137M | dst[y * dstStride + x] = dst[x * dstStride + y]; | 200 | 137M | dst[x * dstStride + y] = tmp; | 201 | 137M | } | 202 | 34.3M | } | 203 | 4.91M | } | 204 | 9.95M | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<16>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 104 | 2.21M | { | 105 | 2.21M | int width2 = width << 1; | 106 | | // Flip the neighbours in the horizontal case. | 107 | 2.21M | int horMode = dirMode < 18; | 108 | 2.21M | pixel neighbourBuf[129]; | 109 | 2.21M | const pixel *srcPix = srcPix0; | 110 | | | 111 | 2.21M | if (horMode) | 112 | 1.06M | { | 113 | 1.06M | neighbourBuf[0] = srcPix[0]; | 114 | 35.0M | for (int i = 0; i < width << 1; i++) | 115 | 34.0M | { | 116 | 34.0M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; | 117 | 34.0M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; | 118 | 34.0M | } | 119 | 1.06M | srcPix = neighbourBuf; | 120 | 1.06M | } | 121 | | | 122 | | // Intra prediction angle and inverse angle tables. | 123 | 2.21M | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; | 124 | 2.21M | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; | 125 | | | 126 | | // Get the prediction angle. | 127 | 2.21M | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; | 128 | 2.21M | int angle = angleTable[8 + angleOffset]; | 129 | | | 130 | | // Vertical Prediction. | 131 | 2.21M | if (!angle) | 132 | 185k | { | 133 | 3.14M | for (int y = 0; y < width; y++) | 134 | 50.3M | for (int x = 0; x < width; x++) | 135 | 47.3M | dst[y * dstStride + x] = srcPix[1 + x]; | 136 | | | 137 | 185k | if (bFilter) | 138 | 132k | { | 139 | 132k | int topLeft = srcPix[0], top = srcPix[1]; | 140 | 2.25M | for (int y = 0; y < width; y++) | 141 | 2.12M | dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1))); | 142 | 132k | } | 143 | 185k | } | 144 | 2.03M | else // Angular prediction. | 145 | 2.03M | { | 146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). | 147 | 2.03M | pixel refBuf[64]; | 148 | 2.03M | const pixel *ref; | 149 | | | 150 | | // Use the projected left neighbours and the top neighbours. | 151 | 2.03M | if (angle < 0) | 152 | 970k | { | 153 | | // Number of neighbours projected. | 154 | 970k | int nbProjected = -((width * angle) >> 5) - 1; | 155 | 970k | pixel *ref_pix = refBuf + nbProjected + 1; | 156 | | | 157 | | // Project the neighbours. | 158 | 970k | int invAngle = invAngleTable[- angleOffset - 1]; | 159 | 970k | int invAngleSum = 128; | 160 | 7.37M | for (int i = 0; i < nbProjected; i++) | 161 | 6.40M | { | 162 | 6.40M | invAngleSum += invAngle; | 163 | 6.40M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; | 164 | 6.40M | } | 165 | | | 166 | | // Copy the top-left and top pixels. | 167 | 17.4M | for (int i = 0; i < width + 1; i++) | 168 | 16.4M | ref_pix[-1 + i] = srcPix[i]; | 169 | 970k | ref = ref_pix; | 170 | 970k | } | 171 | 1.06M | else // Use the top and top-right neighbours. | 172 | 1.06M | ref = srcPix + 1; | 173 | | | 174 | | // Pass every row. | 175 | 2.03M | int angleSum = 0; | 176 | 34.3M | for (int y = 0; y < width; y++) | 177 | 32.2M | { | 178 | 32.2M | angleSum += angle; | 179 | 32.2M | int offset = angleSum >> 5; | 180 | 32.2M | int fraction = angleSum & 31; | 181 | | | 182 | 32.2M | if (fraction) // Interpolate | 183 | 479M | for (int x = 0; x < width; x++) | 184 | 451M | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); | 185 | 3.96M | else // Copy. | 186 | 68.5M | for (int x = 0; x < width; x++) | 187 | 64.6M | dst[y * dstStride + x] = ref[offset + x]; | 188 | 32.2M | } | 189 | 2.03M | } | 190 | | | 191 | | // Flip for horizontal. | 192 | 2.21M | if (horMode) | 193 | 1.06M | { | 194 | 16.9M | for (int y = 0; y < width - 1; y++) | 195 | 15.9M | { | 196 | 143M | for (int x = y + 1; x < width; x++) | 197 | 127M | { | 198 | 127M | pixel tmp = dst[y * dstStride + x]; | 199 | 127M | dst[y * dstStride + x] = dst[x * dstStride + y]; | 200 | 127M | dst[x * dstStride + y] = tmp; | 201 | 127M | } | 202 | 15.9M | } | 203 | 1.06M | } | 204 | 2.21M | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<32>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 104 | 438k | { | 105 | 438k | int width2 = width << 1; | 106 | | // Flip the neighbours in the horizontal case. | 107 | 438k | int horMode = dirMode < 18; | 108 | 438k | pixel neighbourBuf[129]; | 109 | 438k | const pixel *srcPix = srcPix0; | 110 | | | 111 | 438k | if (horMode) | 112 | 213k | { | 113 | 213k | neighbourBuf[0] = srcPix[0]; | 114 | 13.8M | for (int i = 0; i < width << 1; i++) | 115 | 13.6M | { | 116 | 13.6M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; | 117 | 13.6M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; | 118 | 13.6M | } | 119 | 213k | srcPix = neighbourBuf; | 120 | 213k | } | 121 | | | 122 | | // Intra prediction angle and inverse angle tables. | 123 | 438k | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; | 124 | 438k | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; | 125 | | | 126 | | // Get the prediction angle. | 127 | 438k | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; | 128 | 438k | int angle = angleTable[8 + angleOffset]; | 129 | | | 130 | | // Vertical Prediction. | 131 | 438k | if (!angle) | 132 | 26.8k | { | 133 | 886k | for (int y = 0; y < width; y++) | 134 | 28.3M | for (int x = 0; x < width; x++) | 135 | 27.4M | dst[y * dstStride + x] = srcPix[1 + x]; | 136 | | | 137 | 26.8k | 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.8k | } | 144 | 411k | else // Angular prediction. | 145 | 411k | { | 146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). | 147 | 411k | pixel refBuf[64]; | 148 | 411k | const pixel *ref; | 149 | | | 150 | | // Use the projected left neighbours and the top neighbours. | 151 | 411k | if (angle < 0) | 152 | 198k | { | 153 | | // Number of neighbours projected. | 154 | 198k | int nbProjected = -((width * angle) >> 5) - 1; | 155 | 198k | pixel *ref_pix = refBuf + nbProjected + 1; | 156 | | | 157 | | // Project the neighbours. | 158 | 198k | int invAngle = invAngleTable[- angleOffset - 1]; | 159 | 198k | int invAngleSum = 128; | 160 | 2.88M | for (int i = 0; i < nbProjected; i++) | 161 | 2.68M | { | 162 | 2.68M | invAngleSum += invAngle; | 163 | 2.68M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; | 164 | 2.68M | } | 165 | | | 166 | | // Copy the top-left and top pixels. | 167 | 6.74M | for (int i = 0; i < width + 1; i++) | 168 | 6.55M | ref_pix[-1 + i] = srcPix[i]; | 169 | 198k | ref = ref_pix; | 170 | 198k | } | 171 | 213k | else // Use the top and top-right neighbours. | 172 | 213k | ref = srcPix + 1; | 173 | | | 174 | | // Pass every row. | 175 | 411k | int angleSum = 0; | 176 | 13.4M | for (int y = 0; y < width; y++) | 177 | 13.0M | { | 178 | 13.0M | angleSum += angle; | 179 | 13.0M | int offset = angleSum >> 5; | 180 | 13.0M | int fraction = angleSum & 31; | 181 | | | 182 | 13.0M | if (fraction) // Interpolate | 183 | 371M | for (int x = 0; x < width; x++) | 184 | 360M | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); | 185 | 1.72M | else // Copy. | 186 | 57.5M | for (int x = 0; x < width; x++) | 187 | 55.8M | dst[y * dstStride + x] = ref[offset + x]; | 188 | 13.0M | } | 189 | 411k | } | 190 | | | 191 | | // Flip for horizontal. | 192 | 438k | if (horMode) | 193 | 213k | { | 194 | 6.81M | for (int y = 0; y < width - 1; y++) | 195 | 6.60M | { | 196 | 112M | for (int x = y + 1; x < width; x++) | 197 | 105M | { | 198 | 105M | pixel tmp = dst[y * dstStride + x]; | 199 | 105M | dst[y * dstStride + x] = dst[x * dstStride + y]; | 200 | 105M | dst[x * dstStride + y] = tmp; | 201 | 105M | } | 202 | 6.60M | } | 203 | 213k | } | 204 | 438k | } |
|
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 | | } |