/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.28M | { |
34 | 1.28M | const int tuSize2 = tuSize << 1; |
35 | | |
36 | 1.28M | pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2]; |
37 | | |
38 | | // filtering top |
39 | 23.9M | for (int i = 1; i < tuSize2; i++) |
40 | 22.6M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; |
41 | 1.28M | filtered[tuSize2] = topLast; |
42 | | |
43 | | // filtering top-left |
44 | 1.28M | filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2; |
45 | | |
46 | | // filtering left |
47 | 1.28M | filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2; |
48 | 22.6M | for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++) |
49 | 21.3M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; |
50 | 1.28M | filtered[tuSize2 + tuSize2] = leftLast; |
51 | 1.28M | } 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.06M | { | 34 | 1.06M | const int tuSize2 = tuSize << 1; | 35 | | | 36 | 1.06M | pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2]; | 37 | | | 38 | | // filtering top | 39 | 17.0M | for (int i = 1; i < tuSize2; i++) | 40 | 15.9M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; | 41 | 1.06M | filtered[tuSize2] = topLast; | 42 | | | 43 | | // filtering top-left | 44 | 1.06M | filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2; | 45 | | | 46 | | // filtering left | 47 | 1.06M | filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2; | 48 | 15.9M | for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++) | 49 | 14.9M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; | 50 | 1.06M | filtered[tuSize2 + tuSize2] = leftLast; | 51 | 1.06M | } |
intrapred.cpp:void (anonymous namespace)::intraFilter<16>(unsigned char const*, unsigned char*) Line | Count | Source | 33 | 215k | { | 34 | 215k | const int tuSize2 = tuSize << 1; | 35 | | | 36 | 215k | pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2]; | 37 | | | 38 | | // filtering top | 39 | 6.89M | for (int i = 1; i < tuSize2; i++) | 40 | 6.67M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; | 41 | 215k | filtered[tuSize2] = topLast; | 42 | | | 43 | | // filtering top-left | 44 | 215k | filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2; | 45 | | | 46 | | // filtering left | 47 | 215k | filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2; | 48 | 6.67M | for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++) | 49 | 6.46M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; | 50 | 215k | filtered[tuSize2 + tuSize2] = leftLast; | 51 | 215k | } |
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.52M | { |
55 | | // boundary pixels processing |
56 | 2.52M | dst[0] = (pixel)((above[0] + left[0] + 2 * dst[0] + 2) >> 2); |
57 | | |
58 | 14.0M | for (int x = 1; x < size; x++) |
59 | 11.4M | dst[x] = (pixel)((above[x] + 3 * dst[x] + 2) >> 2); |
60 | | |
61 | 2.52M | dst += dststride; |
62 | 14.0M | for (int y = 1; y < size; y++) |
63 | 11.4M | { |
64 | 11.4M | *dst = (pixel)((left[y] + 3 * *dst + 2) >> 2); |
65 | 11.4M | dst += dststride; |
66 | 11.4M | } |
67 | 2.52M | } |
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.93M | { |
72 | 3.93M | int k, l; |
73 | | |
74 | 3.93M | int dcVal = width; |
75 | 25.3M | for (int i = 0; i < width; i++) |
76 | 21.3M | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; |
77 | | |
78 | 3.93M | dcVal = dcVal / (width + width); |
79 | 25.3M | for (k = 0; k < width; k++) |
80 | 187M | for (l = 0; l < width; l++) |
81 | 165M | dst[k * dstStride + l] = (pixel)dcVal; |
82 | | |
83 | 3.93M | if (bFilter) |
84 | 2.52M | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); |
85 | 3.93M | } intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<4>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 71 | 3.01M | { | 72 | 3.01M | int k, l; | 73 | | | 74 | 3.01M | int dcVal = width; | 75 | 15.0M | for (int i = 0; i < width; i++) | 76 | 12.0M | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; | 77 | | | 78 | 3.01M | dcVal = dcVal / (width + width); | 79 | 15.0M | for (k = 0; k < width; k++) | 80 | 60.3M | for (l = 0; l < width; l++) | 81 | 48.2M | dst[k * dstStride + l] = (pixel)dcVal; | 82 | | | 83 | 3.01M | if (bFilter) | 84 | 1.81M | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); | 85 | 3.01M | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<8>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 71 | 720k | { | 72 | 720k | int k, l; | 73 | | | 74 | 720k | int dcVal = width; | 75 | 6.48M | for (int i = 0; i < width; i++) | 76 | 5.76M | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; | 77 | | | 78 | 720k | dcVal = dcVal / (width + width); | 79 | 6.47M | for (k = 0; k < width; k++) | 80 | 51.8M | for (l = 0; l < width; l++) | 81 | 46.0M | dst[k * dstStride + l] = (pixel)dcVal; | 82 | | | 83 | 720k | if (bFilter) | 84 | 573k | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); | 85 | 720k | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<16>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 71 | 165k | { | 72 | 165k | int k, l; | 73 | | | 74 | 165k | int dcVal = width; | 75 | 2.81M | for (int i = 0; i < width; i++) | 76 | 2.64M | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; | 77 | | | 78 | 165k | dcVal = dcVal / (width + width); | 79 | 2.81M | for (k = 0; k < width; k++) | 80 | 44.9M | for (l = 0; l < width; l++) | 81 | 42.3M | dst[k * dstStride + l] = (pixel)dcVal; | 82 | | | 83 | 165k | if (bFilter) | 84 | 136k | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); | 85 | 165k | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<32>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 71 | 28.4k | { | 72 | 28.4k | int k, l; | 73 | | | 74 | 28.4k | int dcVal = width; | 75 | 940k | for (int i = 0; i < width; i++) | 76 | 911k | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; | 77 | | | 78 | 28.4k | dcVal = dcVal / (width + width); | 79 | 939k | for (k = 0; k < width; k++) | 80 | 30.0M | for (l = 0; l < width; l++) | 81 | 29.1M | dst[k * dstStride + l] = (pixel)dcVal; | 82 | | | 83 | 28.4k | if (bFilter) | 84 | 0 | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); | 85 | 28.4k | } |
|
86 | | |
87 | | template<int log2Size> |
88 | | void planar_pred_c(pixel* dst, intptr_t dstStride, const pixel* srcPix, int /*dirMode*/, int /*bFilter*/) |
89 | 6.84M | { |
90 | 6.84M | const int blkSize = 1 << log2Size; |
91 | | |
92 | 6.84M | const pixel* above = srcPix + 1; |
93 | 6.84M | const pixel* left = srcPix + (2 * blkSize + 1); |
94 | | |
95 | 6.84M | pixel topRight = above[blkSize]; |
96 | 6.84M | pixel bottomLeft = left[blkSize]; |
97 | 42.8M | for (int y = 0; y < blkSize; y++) |
98 | 292M | for (int x = 0; x < blkSize; x++) |
99 | 256M | 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.84M | } intrapred.cpp:void (anonymous namespace)::planar_pred_c<2>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 89 | 5.36M | { | 90 | 5.36M | const int blkSize = 1 << log2Size; | 91 | | | 92 | 5.36M | const pixel* above = srcPix + 1; | 93 | 5.36M | const pixel* left = srcPix + (2 * blkSize + 1); | 94 | | | 95 | 5.36M | pixel topRight = above[blkSize]; | 96 | 5.36M | pixel bottomLeft = left[blkSize]; | 97 | 26.7M | for (int y = 0; y < blkSize; y++) | 98 | 107M | for (int x = 0; x < blkSize; x++) | 99 | 85.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 | 5.36M | } |
intrapred.cpp:void (anonymous namespace)::planar_pred_c<3>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 89 | 1.21M | { | 90 | 1.21M | const int blkSize = 1 << log2Size; | 91 | | | 92 | 1.21M | const pixel* above = srcPix + 1; | 93 | 1.21M | const pixel* left = srcPix + (2 * blkSize + 1); | 94 | | | 95 | 1.21M | pixel topRight = above[blkSize]; | 96 | 1.21M | pixel bottomLeft = left[blkSize]; | 97 | 10.9M | for (int y = 0; y < blkSize; y++) | 98 | 87.1M | for (int x = 0; x < blkSize; x++) | 99 | 77.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.21M | } |
intrapred.cpp:void (anonymous namespace)::planar_pred_c<4>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 89 | 241k | { | 90 | 241k | const int blkSize = 1 << log2Size; | 91 | | | 92 | 241k | const pixel* above = srcPix + 1; | 93 | 241k | const pixel* left = srcPix + (2 * blkSize + 1); | 94 | | | 95 | 241k | pixel topRight = above[blkSize]; | 96 | 241k | pixel bottomLeft = left[blkSize]; | 97 | 4.10M | for (int y = 0; y < blkSize; y++) | 98 | 65.7M | for (int x = 0; x < blkSize; x++) | 99 | 61.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 | 241k | } |
intrapred.cpp:void (anonymous namespace)::planar_pred_c<5>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 89 | 30.9k | { | 90 | 30.9k | const int blkSize = 1 << log2Size; | 91 | | | 92 | 30.9k | const pixel* above = srcPix + 1; | 93 | 30.9k | const pixel* left = srcPix + (2 * blkSize + 1); | 94 | | | 95 | 30.9k | pixel topRight = above[blkSize]; | 96 | 30.9k | pixel bottomLeft = left[blkSize]; | 97 | 1.01M | for (int y = 0; y < blkSize; y++) | 98 | 32.6M | for (int x = 0; x < blkSize; x++) | 99 | 31.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 | 30.9k | } |
|
101 | | |
102 | | template<int width> |
103 | | void intra_pred_ang_c(pixel* dst, intptr_t dstStride, const pixel *srcPix0, int dirMode, int bFilter) |
104 | 57.5M | { |
105 | 57.5M | int width2 = width << 1; |
106 | | // Flip the neighbours in the horizontal case. |
107 | 57.5M | int horMode = dirMode < 18; |
108 | 57.5M | pixel neighbourBuf[129]; |
109 | 57.5M | const pixel *srcPix = srcPix0; |
110 | | |
111 | 57.5M | if (horMode) |
112 | 27.4M | { |
113 | 27.4M | neighbourBuf[0] = srcPix[0]; |
114 | 333M | for (int i = 0; i < width << 1; i++) |
115 | 305M | { |
116 | 305M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; |
117 | 305M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; |
118 | 305M | } |
119 | 27.4M | srcPix = neighbourBuf; |
120 | 27.4M | } |
121 | | |
122 | | // Intra prediction angle and inverse angle tables. |
123 | 57.5M | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; |
124 | 57.5M | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; |
125 | | |
126 | | // Get the prediction angle. |
127 | 57.5M | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; |
128 | 57.5M | int angle = angleTable[8 + angleOffset]; |
129 | | |
130 | | // Vertical Prediction. |
131 | 57.5M | if (!angle) |
132 | 6.13M | { |
133 | 38.0M | for (int y = 0; y < width; y++) |
134 | 257M | for (int x = 0; x < width; x++) |
135 | 225M | dst[y * dstStride + x] = srcPix[1 + x]; |
136 | | |
137 | 6.13M | if (bFilter) |
138 | 3.34M | { |
139 | 3.34M | int topLeft = srcPix[0], top = srcPix[1]; |
140 | 21.3M | for (int y = 0; y < width; y++) |
141 | 17.9M | dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1))); |
142 | 3.34M | } |
143 | 6.13M | } |
144 | 51.3M | else // Angular prediction. |
145 | 51.3M | { |
146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). |
147 | 51.3M | pixel refBuf[64]; |
148 | 51.3M | const pixel *ref; |
149 | | |
150 | | // Use the projected left neighbours and the top neighbours. |
151 | 51.3M | if (angle < 0) |
152 | 24.1M | { |
153 | | // Number of neighbours projected. |
154 | 24.1M | int nbProjected = -((width * angle) >> 5) - 1; |
155 | 24.1M | pixel *ref_pix = refBuf + nbProjected + 1; |
156 | | |
157 | | // Project the neighbours. |
158 | 24.1M | int invAngle = invAngleTable[- angleOffset - 1]; |
159 | 24.1M | int invAngleSum = 128; |
160 | 75.1M | for (int i = 0; i < nbProjected; i++) |
161 | 51.0M | { |
162 | 51.0M | invAngleSum += invAngle; |
163 | 51.0M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; |
164 | 51.0M | } |
165 | | |
166 | | // Copy the top-left and top pixels. |
167 | 183M | for (int i = 0; i < width + 1; i++) |
168 | 159M | ref_pix[-1 + i] = srcPix[i]; |
169 | 24.1M | ref = ref_pix; |
170 | 24.1M | } |
171 | 27.2M | else // Use the top and top-right neighbours. |
172 | 27.2M | ref = srcPix + 1; |
173 | | |
174 | | // Pass every row. |
175 | 51.3M | int angleSum = 0; |
176 | 337M | for (int y = 0; y < width; y++) |
177 | 285M | { |
178 | 285M | angleSum += angle; |
179 | 285M | int offset = angleSum >> 5; |
180 | 285M | int fraction = angleSum & 31; |
181 | | |
182 | 285M | if (fraction) // Interpolate |
183 | 2.28G | for (int x = 0; x < width; x++) |
184 | 2.03G | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); |
185 | 34.2M | else // Copy. |
186 | 313M | for (int x = 0; x < width; x++) |
187 | 279M | dst[y * dstStride + x] = ref[offset + x]; |
188 | 285M | } |
189 | 51.3M | } |
190 | | |
191 | | // Flip for horizontal. |
192 | 57.5M | if (horMode) |
193 | 27.4M | { |
194 | 152M | for (int y = 0; y < width - 1; y++) |
195 | 125M | { |
196 | 663M | for (int x = y + 1; x < width; x++) |
197 | 538M | { |
198 | 538M | pixel tmp = dst[y * dstStride + x]; |
199 | 538M | dst[y * dstStride + x] = dst[x * dstStride + y]; |
200 | 538M | dst[x * dstStride + y] = tmp; |
201 | 538M | } |
202 | 125M | } |
203 | 27.4M | } |
204 | 57.5M | } intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<4>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 104 | 43.3M | { | 105 | 43.3M | int width2 = width << 1; | 106 | | // Flip the neighbours in the horizontal case. | 107 | 43.3M | int horMode = dirMode < 18; | 108 | 43.3M | pixel neighbourBuf[129]; | 109 | 43.3M | const pixel *srcPix = srcPix0; | 110 | | | 111 | 43.3M | if (horMode) | 112 | 20.4M | { | 113 | 20.4M | neighbourBuf[0] = srcPix[0]; | 114 | 184M | for (int i = 0; i < width << 1; i++) | 115 | 163M | { | 116 | 163M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; | 117 | 163M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; | 118 | 163M | } | 119 | 20.4M | srcPix = neighbourBuf; | 120 | 20.4M | } | 121 | | | 122 | | // Intra prediction angle and inverse angle tables. | 123 | 43.3M | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; | 124 | 43.3M | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; | 125 | | | 126 | | // Get the prediction angle. | 127 | 43.3M | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; | 128 | 43.3M | int angle = angleTable[8 + angleOffset]; | 129 | | | 130 | | // Vertical Prediction. | 131 | 43.3M | if (!angle) | 132 | 4.90M | { | 133 | 24.5M | for (int y = 0; y < width; y++) | 134 | 97.9M | for (int x = 0; x < width; x++) | 135 | 78.3M | dst[y * dstStride + x] = srcPix[1 + x]; | 136 | | | 137 | 4.90M | 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.96M | dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1))); | 142 | 2.49M | } | 143 | 4.90M | } | 144 | 38.4M | else // Angular prediction. | 145 | 38.4M | { | 146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). | 147 | 38.4M | pixel refBuf[64]; | 148 | 38.4M | const pixel *ref; | 149 | | | 150 | | // Use the projected left neighbours and the top neighbours. | 151 | 38.4M | if (angle < 0) | 152 | 18.0M | { | 153 | | // Number of neighbours projected. | 154 | 18.0M | int nbProjected = -((width * angle) >> 5) - 1; | 155 | 18.0M | pixel *ref_pix = refBuf + nbProjected + 1; | 156 | | | 157 | | // Project the neighbours. | 158 | 18.0M | int invAngle = invAngleTable[- angleOffset - 1]; | 159 | 18.0M | int invAngleSum = 128; | 160 | 43.3M | for (int i = 0; i < nbProjected; i++) | 161 | 25.3M | { | 162 | 25.3M | invAngleSum += invAngle; | 163 | 25.3M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; | 164 | 25.3M | } | 165 | | | 166 | | // Copy the top-left and top pixels. | 167 | 108M | for (int i = 0; i < width + 1; i++) | 168 | 90.3M | ref_pix[-1 + i] = srcPix[i]; | 169 | 18.0M | ref = ref_pix; | 170 | 18.0M | } | 171 | 20.3M | else // Use the top and top-right neighbours. | 172 | 20.3M | ref = srcPix + 1; | 173 | | | 174 | | // Pass every row. | 175 | 38.4M | int angleSum = 0; | 176 | 191M | for (int y = 0; y < width; y++) | 177 | 153M | { | 178 | 153M | angleSum += angle; | 179 | 153M | int offset = angleSum >> 5; | 180 | 153M | int fraction = angleSum & 31; | 181 | | | 182 | 153M | if (fraction) // Interpolate | 183 | 667M | for (int x = 0; x < width; x++) | 184 | 533M | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); | 185 | 19.3M | else // Copy. | 186 | 96.6M | for (int x = 0; x < width; x++) | 187 | 77.2M | dst[y * dstStride + x] = ref[offset + x]; | 188 | 153M | } | 189 | 38.4M | } | 190 | | | 191 | | // Flip for horizontal. | 192 | 43.3M | if (horMode) | 193 | 20.5M | { | 194 | 81.9M | for (int y = 0; y < width - 1; y++) | 195 | 61.4M | { | 196 | 184M | for (int x = y + 1; x < width; x++) | 197 | 122M | { | 198 | 122M | pixel tmp = dst[y * dstStride + x]; | 199 | 122M | dst[y * dstStride + x] = dst[x * dstStride + y]; | 200 | 122M | dst[x * dstStride + y] = tmp; | 201 | 122M | } | 202 | 61.4M | } | 203 | 20.5M | } | 204 | 43.3M | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<8>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 104 | 11.1M | { | 105 | 11.1M | int width2 = width << 1; | 106 | | // Flip the neighbours in the horizontal case. | 107 | 11.1M | int horMode = dirMode < 18; | 108 | 11.1M | pixel neighbourBuf[129]; | 109 | 11.1M | const pixel *srcPix = srcPix0; | 110 | | | 111 | 11.1M | if (horMode) | 112 | 5.52M | { | 113 | 5.52M | neighbourBuf[0] = srcPix[0]; | 114 | 93.8M | for (int i = 0; i < width << 1; i++) | 115 | 88.3M | { | 116 | 88.3M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; | 117 | 88.3M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; | 118 | 88.3M | } | 119 | 5.52M | srcPix = neighbourBuf; | 120 | 5.52M | } | 121 | | | 122 | | // Intra prediction angle and inverse angle tables. | 123 | 11.1M | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; | 124 | 11.1M | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; | 125 | | | 126 | | // Get the prediction angle. | 127 | 11.1M | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; | 128 | 11.1M | int angle = angleTable[8 + angleOffset]; | 129 | | | 130 | | // Vertical Prediction. | 131 | 11.1M | if (!angle) | 132 | 996k | { | 133 | 8.96M | for (int y = 0; y < width; y++) | 134 | 71.6M | for (int x = 0; x < width; x++) | 135 | 63.7M | dst[y * dstStride + x] = srcPix[1 + x]; | 136 | | | 137 | 996k | if (bFilter) | 138 | 702k | { | 139 | 702k | int topLeft = srcPix[0], top = srcPix[1]; | 140 | 6.32M | for (int y = 0; y < width; y++) | 141 | 5.61M | dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1))); | 142 | 702k | } | 143 | 996k | } | 144 | 10.2M | else // Angular prediction. | 145 | 10.2M | { | 146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). | 147 | 10.2M | pixel refBuf[64]; | 148 | 10.2M | const pixel *ref; | 149 | | | 150 | | // Use the projected left neighbours and the top neighbours. | 151 | 10.2M | if (angle < 0) | 152 | 4.76M | { | 153 | | // Number of neighbours projected. | 154 | 4.76M | int nbProjected = -((width * angle) >> 5) - 1; | 155 | 4.76M | pixel *ref_pix = refBuf + nbProjected + 1; | 156 | | | 157 | | // Project the neighbours. | 158 | 4.76M | int invAngle = invAngleTable[- angleOffset - 1]; | 159 | 4.76M | int invAngleSum = 128; | 160 | 20.2M | for (int i = 0; i < nbProjected; i++) | 161 | 15.4M | { | 162 | 15.4M | invAngleSum += invAngle; | 163 | 15.4M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; | 164 | 15.4M | } | 165 | | | 166 | | // Copy the top-left and top pixels. | 167 | 47.6M | for (int i = 0; i < width + 1; i++) | 168 | 42.8M | ref_pix[-1 + i] = srcPix[i]; | 169 | 4.76M | ref = ref_pix; | 170 | 4.76M | } | 171 | 5.43M | else // Use the top and top-right neighbours. | 172 | 5.43M | ref = srcPix + 1; | 173 | | | 174 | | // Pass every row. | 175 | 10.2M | int angleSum = 0; | 176 | 91.6M | for (int y = 0; y < width; y++) | 177 | 81.4M | { | 178 | 81.4M | angleSum += angle; | 179 | 81.4M | int offset = angleSum >> 5; | 180 | 81.4M | int fraction = angleSum & 31; | 181 | | | 182 | 81.4M | if (fraction) // Interpolate | 183 | 655M | for (int x = 0; x < width; x++) | 184 | 582M | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); | 185 | 8.49M | else // Copy. | 186 | 75.8M | for (int x = 0; x < width; x++) | 187 | 67.3M | dst[y * dstStride + x] = ref[offset + x]; | 188 | 81.4M | } | 189 | 10.2M | } | 190 | | | 191 | | // Flip for horizontal. | 192 | 11.1M | if (horMode) | 193 | 5.52M | { | 194 | 44.1M | for (int y = 0; y < width - 1; y++) | 195 | 38.5M | { | 196 | 192M | for (int x = y + 1; x < width; x++) | 197 | 154M | { | 198 | 154M | pixel tmp = dst[y * dstStride + x]; | 199 | 154M | dst[y * dstStride + x] = dst[x * dstStride + y]; | 200 | 154M | dst[x * dstStride + y] = tmp; | 201 | 154M | } | 202 | 38.5M | } | 203 | 5.52M | } | 204 | 11.1M | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<16>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 104 | 2.50M | { | 105 | 2.50M | int width2 = width << 1; | 106 | | // Flip the neighbours in the horizontal case. | 107 | 2.50M | int horMode = dirMode < 18; | 108 | 2.50M | pixel neighbourBuf[129]; | 109 | 2.50M | const pixel *srcPix = srcPix0; | 110 | | | 111 | 2.50M | if (horMode) | 112 | 1.19M | { | 113 | 1.19M | neighbourBuf[0] = srcPix[0]; | 114 | 39.5M | for (int i = 0; i < width << 1; i++) | 115 | 38.3M | { | 116 | 38.3M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; | 117 | 38.3M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; | 118 | 38.3M | } | 119 | 1.19M | srcPix = neighbourBuf; | 120 | 1.19M | } | 121 | | | 122 | | // Intra prediction angle and inverse angle tables. | 123 | 2.50M | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; | 124 | 2.50M | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; | 125 | | | 126 | | // Get the prediction angle. | 127 | 2.50M | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; | 128 | 2.50M | int angle = angleTable[8 + angleOffset]; | 129 | | | 130 | | // Vertical Prediction. | 131 | 2.50M | if (!angle) | 132 | 208k | { | 133 | 3.54M | for (int y = 0; y < width; y++) | 134 | 56.6M | for (int x = 0; x < width; x++) | 135 | 53.3M | dst[y * dstStride + x] = srcPix[1 + x]; | 136 | | | 137 | 208k | 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 | 208k | } | 144 | 2.29M | else // Angular prediction. | 145 | 2.29M | { | 146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). | 147 | 2.29M | pixel refBuf[64]; | 148 | 2.29M | const pixel *ref; | 149 | | | 150 | | // Use the projected left neighbours and the top neighbours. | 151 | 2.29M | if (angle < 0) | 152 | 1.09M | { | 153 | | // Number of neighbours projected. | 154 | 1.09M | int nbProjected = -((width * angle) >> 5) - 1; | 155 | 1.09M | pixel *ref_pix = refBuf + nbProjected + 1; | 156 | | | 157 | | // Project the neighbours. | 158 | 1.09M | int invAngle = invAngleTable[- angleOffset - 1]; | 159 | 1.09M | int invAngleSum = 128; | 160 | 8.31M | for (int i = 0; i < nbProjected; i++) | 161 | 7.22M | { | 162 | 7.22M | invAngleSum += invAngle; | 163 | 7.22M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; | 164 | 7.22M | } | 165 | | | 166 | | // Copy the top-left and top pixels. | 167 | 19.6M | for (int i = 0; i < width + 1; i++) | 168 | 18.6M | ref_pix[-1 + i] = srcPix[i]; | 169 | 1.09M | ref = ref_pix; | 170 | 1.09M | } | 171 | 1.19M | else // Use the top and top-right neighbours. | 172 | 1.19M | ref = srcPix + 1; | 173 | | | 174 | | // Pass every row. | 175 | 2.29M | int angleSum = 0; | 176 | 38.7M | for (int y = 0; y < width; y++) | 177 | 36.4M | { | 178 | 36.4M | angleSum += angle; | 179 | 36.4M | int offset = angleSum >> 5; | 180 | 36.4M | int fraction = angleSum & 31; | 181 | | | 182 | 36.4M | if (fraction) // Interpolate | 183 | 541M | for (int x = 0; x < width; x++) | 184 | 509M | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); | 185 | 4.48M | else // Copy. | 186 | 77.2M | for (int x = 0; x < width; x++) | 187 | 72.7M | dst[y * dstStride + x] = ref[offset + x]; | 188 | 36.4M | } | 189 | 2.29M | } | 190 | | | 191 | | // Flip for horizontal. | 192 | 2.50M | if (horMode) | 193 | 1.19M | { | 194 | 19.1M | for (int y = 0; y < width - 1; y++) | 195 | 17.9M | { | 196 | 161M | for (int x = y + 1; x < width; x++) | 197 | 143M | { | 198 | 143M | pixel tmp = dst[y * dstStride + x]; | 199 | 143M | dst[y * dstStride + x] = dst[x * dstStride + y]; | 200 | 143M | dst[x * dstStride + y] = tmp; | 201 | 143M | } | 202 | 17.9M | } | 203 | 1.19M | } | 204 | 2.50M | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<32>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 104 | 487k | { | 105 | 487k | int width2 = width << 1; | 106 | | // Flip the neighbours in the horizontal case. | 107 | 487k | int horMode = dirMode < 18; | 108 | 487k | pixel neighbourBuf[129]; | 109 | 487k | const pixel *srcPix = srcPix0; | 110 | | | 111 | 487k | if (horMode) | 112 | 237k | { | 113 | 237k | neighbourBuf[0] = srcPix[0]; | 114 | 15.4M | for (int i = 0; i < width << 1; i++) | 115 | 15.1M | { | 116 | 15.1M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; | 117 | 15.1M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; | 118 | 15.1M | } | 119 | 237k | srcPix = neighbourBuf; | 120 | 237k | } | 121 | | | 122 | | // Intra prediction angle and inverse angle tables. | 123 | 487k | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; | 124 | 487k | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; | 125 | | | 126 | | // Get the prediction angle. | 127 | 487k | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; | 128 | 487k | int angle = angleTable[8 + angleOffset]; | 129 | | | 130 | | // Vertical Prediction. | 131 | 487k | if (!angle) | 132 | 29.8k | { | 133 | 986k | for (int y = 0; y < width; y++) | 134 | 31.5M | for (int x = 0; x < width; x++) | 135 | 30.5M | dst[y * dstStride + x] = srcPix[1 + x]; | 136 | | | 137 | 29.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 | 29.8k | } | 144 | 457k | else // Angular prediction. | 145 | 457k | { | 146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). | 147 | 457k | pixel refBuf[64]; | 148 | 457k | const pixel *ref; | 149 | | | 150 | | // Use the projected left neighbours and the top neighbours. | 151 | 457k | if (angle < 0) | 152 | 220k | { | 153 | | // Number of neighbours projected. | 154 | 220k | int nbProjected = -((width * angle) >> 5) - 1; | 155 | 220k | pixel *ref_pix = refBuf + nbProjected + 1; | 156 | | | 157 | | // Project the neighbours. | 158 | 220k | int invAngle = invAngleTable[- angleOffset - 1]; | 159 | 220k | int invAngleSum = 128; | 160 | 3.20M | for (int i = 0; i < nbProjected; i++) | 161 | 2.98M | { | 162 | 2.98M | invAngleSum += invAngle; | 163 | 2.98M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; | 164 | 2.98M | } | 165 | | | 166 | | // Copy the top-left and top pixels. | 167 | 7.50M | for (int i = 0; i < width + 1; i++) | 168 | 7.28M | ref_pix[-1 + i] = srcPix[i]; | 169 | 220k | ref = ref_pix; | 170 | 220k | } | 171 | 237k | else // Use the top and top-right neighbours. | 172 | 237k | ref = srcPix + 1; | 173 | | | 174 | | // Pass every row. | 175 | 457k | int angleSum = 0; | 176 | 15.0M | for (int y = 0; y < width; y++) | 177 | 14.6M | { | 178 | 14.6M | angleSum += angle; | 179 | 14.6M | int offset = angleSum >> 5; | 180 | 14.6M | int fraction = angleSum & 31; | 181 | | | 182 | 14.6M | if (fraction) // Interpolate | 183 | 417M | for (int x = 0; x < width; x++) | 184 | 404M | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); | 185 | 1.93M | else // Copy. | 186 | 64.1M | for (int x = 0; x < width; x++) | 187 | 62.2M | dst[y * dstStride + x] = ref[offset + x]; | 188 | 14.6M | } | 189 | 457k | } | 190 | | | 191 | | // Flip for horizontal. | 192 | 487k | if (horMode) | 193 | 237k | { | 194 | 7.57M | for (int y = 0; y < width - 1; y++) | 195 | 7.33M | { | 196 | 124M | for (int x = y + 1; x < width; x++) | 197 | 117M | { | 198 | 117M | pixel tmp = dst[y * dstStride + x]; | 199 | 117M | dst[y * dstStride + x] = dst[x * dstStride + y]; | 200 | 117M | dst[x * dstStride + y] = tmp; | 201 | 117M | } | 202 | 7.33M | } | 203 | 237k | } | 204 | 487k | } |
|
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 | | } |