/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.19M | { |
34 | 1.19M | const int tuSize2 = tuSize << 1; |
35 | | |
36 | 1.19M | pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2]; |
37 | | |
38 | | // filtering top |
39 | 22.3M | for (int i = 1; i < tuSize2; i++) |
40 | 21.1M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; |
41 | 1.19M | filtered[tuSize2] = topLast; |
42 | | |
43 | | // filtering top-left |
44 | 1.19M | filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2; |
45 | | |
46 | | // filtering left |
47 | 1.19M | filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2; |
48 | 21.1M | for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++) |
49 | 19.9M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; |
50 | 1.19M | filtered[tuSize2 + tuSize2] = leftLast; |
51 | 1.19M | } 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 | 995k | { | 34 | 995k | const int tuSize2 = tuSize << 1; | 35 | | | 36 | 995k | pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2]; | 37 | | | 38 | | // filtering top | 39 | 15.9M | for (int i = 1; i < tuSize2; i++) | 40 | 14.9M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; | 41 | 995k | filtered[tuSize2] = topLast; | 42 | | | 43 | | // filtering top-left | 44 | 995k | filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2; | 45 | | | 46 | | // filtering left | 47 | 995k | filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2; | 48 | 14.9M | for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++) | 49 | 13.9M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; | 50 | 995k | filtered[tuSize2 + tuSize2] = leftLast; | 51 | 995k | } |
intrapred.cpp:void (anonymous namespace)::intraFilter<16>(unsigned char const*, unsigned char*) Line | Count | Source | 33 | 201k | { | 34 | 201k | const int tuSize2 = tuSize << 1; | 35 | | | 36 | 201k | pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2]; | 37 | | | 38 | | // filtering top | 39 | 6.44M | for (int i = 1; i < tuSize2; i++) | 40 | 6.24M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; | 41 | 201k | filtered[tuSize2] = topLast; | 42 | | | 43 | | // filtering top-left | 44 | 201k | filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2; | 45 | | | 46 | | // filtering left | 47 | 201k | filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2; | 48 | 6.24M | for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++) | 49 | 6.03M | filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2; | 50 | 201k | filtered[tuSize2 + tuSize2] = leftLast; | 51 | 201k | } |
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.34M | { |
55 | | // boundary pixels processing |
56 | 2.34M | dst[0] = (pixel)((above[0] + left[0] + 2 * dst[0] + 2) >> 2); |
57 | | |
58 | 13.0M | for (int x = 1; x < size; x++) |
59 | 10.7M | dst[x] = (pixel)((above[x] + 3 * dst[x] + 2) >> 2); |
60 | | |
61 | 2.34M | dst += dststride; |
62 | 13.0M | for (int y = 1; y < size; y++) |
63 | 10.7M | { |
64 | 10.7M | *dst = (pixel)((left[y] + 3 * *dst + 2) >> 2); |
65 | 10.7M | dst += dststride; |
66 | 10.7M | } |
67 | 2.34M | } |
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.66M | { |
72 | 3.66M | int k, l; |
73 | | |
74 | 3.66M | int dcVal = width; |
75 | 23.6M | for (int i = 0; i < width; i++) |
76 | 19.9M | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; |
77 | | |
78 | 3.66M | dcVal = dcVal / (width + width); |
79 | 23.6M | for (k = 0; k < width; k++) |
80 | 175M | for (l = 0; l < width; l++) |
81 | 155M | dst[k * dstStride + l] = (pixel)dcVal; |
82 | | |
83 | 3.66M | if (bFilter) |
84 | 2.34M | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); |
85 | 3.66M | } intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<4>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 71 | 2.80M | { | 72 | 2.80M | int k, l; | 73 | | | 74 | 2.80M | int dcVal = width; | 75 | 14.0M | for (int i = 0; i < width; i++) | 76 | 11.2M | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; | 77 | | | 78 | 2.80M | dcVal = dcVal / (width + width); | 79 | 14.0M | for (k = 0; k < width; k++) | 80 | 56.1M | for (l = 0; l < width; l++) | 81 | 44.9M | dst[k * dstStride + l] = (pixel)dcVal; | 82 | | | 83 | 2.80M | if (bFilter) | 84 | 1.68M | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); | 85 | 2.80M | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<8>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 71 | 670k | { | 72 | 670k | int k, l; | 73 | | | 74 | 670k | int dcVal = width; | 75 | 6.03M | for (int i = 0; i < width; i++) | 76 | 5.36M | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; | 77 | | | 78 | 670k | dcVal = dcVal / (width + width); | 79 | 6.03M | for (k = 0; k < width; k++) | 80 | 48.2M | for (l = 0; l < width; l++) | 81 | 42.8M | dst[k * dstStride + l] = (pixel)dcVal; | 82 | | | 83 | 670k | if (bFilter) | 84 | 534k | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); | 85 | 670k | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<16>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 71 | 155k | { | 72 | 155k | int k, l; | 73 | | | 74 | 155k | int dcVal = width; | 75 | 2.63M | for (int i = 0; i < width; i++) | 76 | 2.48M | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; | 77 | | | 78 | 155k | dcVal = dcVal / (width + width); | 79 | 2.63M | for (k = 0; k < width; k++) | 80 | 42.1M | for (l = 0; l < width; l++) | 81 | 39.6M | dst[k * dstStride + l] = (pixel)dcVal; | 82 | | | 83 | 155k | if (bFilter) | 84 | 127k | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); | 85 | 155k | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<32>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 71 | 27.1k | { | 72 | 27.1k | int k, l; | 73 | | | 74 | 27.1k | int dcVal = width; | 75 | 894k | for (int i = 0; i < width; i++) | 76 | 867k | dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i]; | 77 | | | 78 | 27.1k | dcVal = dcVal / (width + width); | 79 | 894k | for (k = 0; k < width; k++) | 80 | 28.6M | for (l = 0; l < width; l++) | 81 | 27.7M | dst[k * dstStride + l] = (pixel)dcVal; | 82 | | | 83 | 27.1k | if (bFilter) | 84 | 0 | dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width); | 85 | 27.1k | } |
|
86 | | |
87 | | template<int log2Size> |
88 | | void planar_pred_c(pixel* dst, intptr_t dstStride, const pixel* srcPix, int /*dirMode*/, int /*bFilter*/) |
89 | 6.39M | { |
90 | 6.39M | const int blkSize = 1 << log2Size; |
91 | | |
92 | 6.39M | const pixel* above = srcPix + 1; |
93 | 6.39M | const pixel* left = srcPix + (2 * blkSize + 1); |
94 | | |
95 | 6.39M | pixel topRight = above[blkSize]; |
96 | 6.39M | pixel bottomLeft = left[blkSize]; |
97 | 40.0M | for (int y = 0; y < blkSize; y++) |
98 | 274M | for (int x = 0; x < blkSize; x++) |
99 | 240M | 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.39M | } intrapred.cpp:void (anonymous namespace)::planar_pred_c<2>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 89 | 5.00M | { | 90 | 5.00M | const int blkSize = 1 << log2Size; | 91 | | | 92 | 5.00M | const pixel* above = srcPix + 1; | 93 | 5.00M | const pixel* left = srcPix + (2 * blkSize + 1); | 94 | | | 95 | 5.00M | pixel topRight = above[blkSize]; | 96 | 5.00M | pixel bottomLeft = left[blkSize]; | 97 | 25.0M | for (int y = 0; y < blkSize; y++) | 98 | 100M | for (int x = 0; x < blkSize; x++) | 99 | 80.0M | 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.00M | } |
intrapred.cpp:void (anonymous namespace)::planar_pred_c<3>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 89 | 1.13M | { | 90 | 1.13M | const int blkSize = 1 << log2Size; | 91 | | | 92 | 1.13M | const pixel* above = srcPix + 1; | 93 | 1.13M | const pixel* left = srcPix + (2 * blkSize + 1); | 94 | | | 95 | 1.13M | pixel topRight = above[blkSize]; | 96 | 1.13M | pixel bottomLeft = left[blkSize]; | 97 | 10.1M | for (int y = 0; y < blkSize; y++) | 98 | 81.4M | for (int x = 0; x < blkSize; x++) | 99 | 72.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 | 1.13M | } |
intrapred.cpp:void (anonymous namespace)::planar_pred_c<4>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 89 | 226k | { | 90 | 226k | const int blkSize = 1 << log2Size; | 91 | | | 92 | 226k | const pixel* above = srcPix + 1; | 93 | 226k | const pixel* left = srcPix + (2 * blkSize + 1); | 94 | | | 95 | 226k | pixel topRight = above[blkSize]; | 96 | 226k | pixel bottomLeft = left[blkSize]; | 97 | 3.85M | for (int y = 0; y < blkSize; y++) | 98 | 61.6M | for (int x = 0; x < blkSize; x++) | 99 | 58.0M | 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 | 226k | } |
intrapred.cpp:void (anonymous namespace)::planar_pred_c<5>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 89 | 29.7k | { | 90 | 29.7k | const int blkSize = 1 << log2Size; | 91 | | | 92 | 29.7k | const pixel* above = srcPix + 1; | 93 | 29.7k | const pixel* left = srcPix + (2 * blkSize + 1); | 94 | | | 95 | 29.7k | pixel topRight = above[blkSize]; | 96 | 29.7k | pixel bottomLeft = left[blkSize]; | 97 | 980k | for (int y = 0; y < blkSize; y++) | 98 | 31.3M | for (int x = 0; x < blkSize; x++) | 99 | 30.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 | 29.7k | } |
|
101 | | |
102 | | template<int width> |
103 | | void intra_pred_ang_c(pixel* dst, intptr_t dstStride, const pixel *srcPix0, int dirMode, int bFilter) |
104 | 53.5M | { |
105 | 53.5M | int width2 = width << 1; |
106 | | // Flip the neighbours in the horizontal case. |
107 | 53.5M | int horMode = dirMode < 18; |
108 | 53.5M | pixel neighbourBuf[129]; |
109 | 53.5M | const pixel *srcPix = srcPix0; |
110 | | |
111 | 53.5M | if (horMode) |
112 | 25.5M | { |
113 | 25.5M | neighbourBuf[0] = srcPix[0]; |
114 | 310M | for (int i = 0; i < width << 1; i++) |
115 | 285M | { |
116 | 285M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; |
117 | 285M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; |
118 | 285M | } |
119 | 25.5M | srcPix = neighbourBuf; |
120 | 25.5M | } |
121 | | |
122 | | // Intra prediction angle and inverse angle tables. |
123 | 53.5M | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; |
124 | 53.5M | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; |
125 | | |
126 | | // Get the prediction angle. |
127 | 53.5M | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; |
128 | 53.5M | int angle = angleTable[8 + angleOffset]; |
129 | | |
130 | | // Vertical Prediction. |
131 | 53.5M | if (!angle) |
132 | 5.70M | { |
133 | 35.3M | for (int y = 0; y < width; y++) |
134 | 240M | for (int x = 0; x < width; x++) |
135 | 211M | dst[y * dstStride + x] = srcPix[1 + x]; |
136 | | |
137 | 5.70M | if (bFilter) |
138 | 3.10M | { |
139 | 3.10M | int topLeft = srcPix[0], top = srcPix[1]; |
140 | 19.7M | for (int y = 0; y < width; y++) |
141 | 16.6M | dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1))); |
142 | 3.10M | } |
143 | 5.70M | } |
144 | 47.8M | else // Angular prediction. |
145 | 47.8M | { |
146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). |
147 | 47.8M | pixel refBuf[64]; |
148 | 47.8M | const pixel *ref; |
149 | | |
150 | | // Use the projected left neighbours and the top neighbours. |
151 | 47.8M | if (angle < 0) |
152 | 22.5M | { |
153 | | // Number of neighbours projected. |
154 | 22.5M | int nbProjected = -((width * angle) >> 5) - 1; |
155 | 22.5M | pixel *ref_pix = refBuf + nbProjected + 1; |
156 | | |
157 | | // Project the neighbours. |
158 | 22.5M | int invAngle = invAngleTable[- angleOffset - 1]; |
159 | 22.5M | int invAngleSum = 128; |
160 | 70.1M | for (int i = 0; i < nbProjected; i++) |
161 | 47.6M | { |
162 | 47.6M | invAngleSum += invAngle; |
163 | 47.6M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; |
164 | 47.6M | } |
165 | | |
166 | | // Copy the top-left and top pixels. |
167 | 170M | for (int i = 0; i < width + 1; i++) |
168 | 148M | ref_pix[-1 + i] = srcPix[i]; |
169 | 22.5M | ref = ref_pix; |
170 | 22.5M | } |
171 | 25.2M | else // Use the top and top-right neighbours. |
172 | 25.2M | ref = srcPix + 1; |
173 | | |
174 | | // Pass every row. |
175 | 47.8M | int angleSum = 0; |
176 | 313M | for (int y = 0; y < width; y++) |
177 | 265M | { |
178 | 265M | angleSum += angle; |
179 | 265M | int offset = angleSum >> 5; |
180 | 265M | int fraction = angleSum & 31; |
181 | | |
182 | 265M | if (fraction) // Interpolate |
183 | 2.13G | for (int x = 0; x < width; x++) |
184 | 1.89G | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); |
185 | 31.5M | else // Copy. |
186 | 293M | for (int x = 0; x < width; x++) |
187 | 262M | dst[y * dstStride + x] = ref[offset + x]; |
188 | 265M | } |
189 | 47.8M | } |
190 | | |
191 | | // Flip for horizontal. |
192 | 53.5M | if (horMode) |
193 | 25.6M | { |
194 | 142M | for (int y = 0; y < width - 1; y++) |
195 | 117M | { |
196 | 621M | for (int x = y + 1; x < width; x++) |
197 | 504M | { |
198 | 504M | pixel tmp = dst[y * dstStride + x]; |
199 | 504M | dst[y * dstStride + x] = dst[x * dstStride + y]; |
200 | 504M | dst[x * dstStride + y] = tmp; |
201 | 504M | } |
202 | 117M | } |
203 | 25.6M | } |
204 | 53.5M | } intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<4>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 104 | 40.2M | { | 105 | 40.2M | int width2 = width << 1; | 106 | | // Flip the neighbours in the horizontal case. | 107 | 40.2M | int horMode = dirMode < 18; | 108 | 40.2M | pixel neighbourBuf[129]; | 109 | 40.2M | const pixel *srcPix = srcPix0; | 110 | | | 111 | 40.2M | if (horMode) | 112 | 19.1M | { | 113 | 19.1M | neighbourBuf[0] = srcPix[0]; | 114 | 171M | for (int i = 0; i < width << 1; i++) | 115 | 152M | { | 116 | 152M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; | 117 | 152M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; | 118 | 152M | } | 119 | 19.1M | srcPix = neighbourBuf; | 120 | 19.1M | } | 121 | | | 122 | | // Intra prediction angle and inverse angle tables. | 123 | 40.2M | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; | 124 | 40.2M | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; | 125 | | | 126 | | // Get the prediction angle. | 127 | 40.2M | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; | 128 | 40.2M | int angle = angleTable[8 + angleOffset]; | 129 | | | 130 | | // Vertical Prediction. | 131 | 40.2M | if (!angle) | 132 | 4.55M | { | 133 | 22.7M | for (int y = 0; y < width; y++) | 134 | 91.0M | for (int x = 0; x < width; x++) | 135 | 72.8M | dst[y * dstStride + x] = srcPix[1 + x]; | 136 | | | 137 | 4.55M | if (bFilter) | 138 | 2.31M | { | 139 | 2.31M | int topLeft = srcPix[0], top = srcPix[1]; | 140 | 11.5M | for (int y = 0; y < width; y++) | 141 | 9.24M | dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1))); | 142 | 2.31M | } | 143 | 4.55M | } | 144 | 35.7M | else // Angular prediction. | 145 | 35.7M | { | 146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). | 147 | 35.7M | pixel refBuf[64]; | 148 | 35.7M | const pixel *ref; | 149 | | | 150 | | // Use the projected left neighbours and the top neighbours. | 151 | 35.7M | if (angle < 0) | 152 | 16.8M | { | 153 | | // Number of neighbours projected. | 154 | 16.8M | int nbProjected = -((width * angle) >> 5) - 1; | 155 | 16.8M | pixel *ref_pix = refBuf + nbProjected + 1; | 156 | | | 157 | | // Project the neighbours. | 158 | 16.8M | int invAngle = invAngleTable[- angleOffset - 1]; | 159 | 16.8M | int invAngleSum = 128; | 160 | 40.4M | for (int i = 0; i < nbProjected; i++) | 161 | 23.6M | { | 162 | 23.6M | invAngleSum += invAngle; | 163 | 23.6M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; | 164 | 23.6M | } | 165 | | | 166 | | // Copy the top-left and top pixels. | 167 | 101M | for (int i = 0; i < width + 1; i++) | 168 | 84.2M | ref_pix[-1 + i] = srcPix[i]; | 169 | 16.8M | ref = ref_pix; | 170 | 16.8M | } | 171 | 18.8M | else // Use the top and top-right neighbours. | 172 | 18.8M | ref = srcPix + 1; | 173 | | | 174 | | // Pass every row. | 175 | 35.7M | int angleSum = 0; | 176 | 178M | for (int y = 0; y < width; y++) | 177 | 142M | { | 178 | 142M | angleSum += angle; | 179 | 142M | int offset = angleSum >> 5; | 180 | 142M | int fraction = angleSum & 31; | 181 | | | 182 | 142M | if (fraction) // Interpolate | 183 | 622M | for (int x = 0; x < width; x++) | 184 | 497M | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); | 185 | 17.7M | else // Copy. | 186 | 89.7M | for (int x = 0; x < width; x++) | 187 | 71.9M | dst[y * dstStride + x] = ref[offset + x]; | 188 | 142M | } | 189 | 35.7M | } | 190 | | | 191 | | // Flip for horizontal. | 192 | 40.2M | if (horMode) | 193 | 19.1M | { | 194 | 76.4M | for (int y = 0; y < width - 1; y++) | 195 | 57.3M | { | 196 | 172M | for (int x = y + 1; x < width; x++) | 197 | 114M | { | 198 | 114M | pixel tmp = dst[y * dstStride + x]; | 199 | 114M | dst[y * dstStride + x] = dst[x * dstStride + y]; | 200 | 114M | dst[x * dstStride + y] = tmp; | 201 | 114M | } | 202 | 57.3M | } | 203 | 19.1M | } | 204 | 40.2M | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<8>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 104 | 10.4M | { | 105 | 10.4M | int width2 = width << 1; | 106 | | // Flip the neighbours in the horizontal case. | 107 | 10.4M | int horMode = dirMode < 18; | 108 | 10.4M | pixel neighbourBuf[129]; | 109 | 10.4M | const pixel *srcPix = srcPix0; | 110 | | | 111 | 10.4M | if (horMode) | 112 | 5.15M | { | 113 | 5.15M | neighbourBuf[0] = srcPix[0]; | 114 | 87.5M | for (int i = 0; i < width << 1; i++) | 115 | 82.4M | { | 116 | 82.4M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; | 117 | 82.4M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; | 118 | 82.4M | } | 119 | 5.15M | srcPix = neighbourBuf; | 120 | 5.15M | } | 121 | | | 122 | | // Intra prediction angle and inverse angle tables. | 123 | 10.4M | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; | 124 | 10.4M | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; | 125 | | | 126 | | // Get the prediction angle. | 127 | 10.4M | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; | 128 | 10.4M | int angle = angleTable[8 + angleOffset]; | 129 | | | 130 | | // Vertical Prediction. | 131 | 10.4M | if (!angle) | 132 | 924k | { | 133 | 8.31M | for (int y = 0; y < width; y++) | 134 | 66.5M | for (int x = 0; x < width; x++) | 135 | 59.1M | dst[y * dstStride + x] = srcPix[1 + x]; | 136 | | | 137 | 924k | if (bFilter) | 138 | 652k | { | 139 | 652k | int topLeft = srcPix[0], top = srcPix[1]; | 140 | 5.87M | for (int y = 0; y < width; y++) | 141 | 5.21M | dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1))); | 142 | 652k | } | 143 | 924k | } | 144 | 9.50M | else // Angular prediction. | 145 | 9.50M | { | 146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). | 147 | 9.50M | pixel refBuf[64]; | 148 | 9.50M | const pixel *ref; | 149 | | | 150 | | // Use the projected left neighbours and the top neighbours. | 151 | 9.50M | if (angle < 0) | 152 | 4.43M | { | 153 | | // Number of neighbours projected. | 154 | 4.43M | int nbProjected = -((width * angle) >> 5) - 1; | 155 | 4.43M | pixel *ref_pix = refBuf + nbProjected + 1; | 156 | | | 157 | | // Project the neighbours. | 158 | 4.43M | int invAngle = invAngleTable[- angleOffset - 1]; | 159 | 4.43M | int invAngleSum = 128; | 160 | 18.8M | for (int i = 0; i < nbProjected; i++) | 161 | 14.4M | { | 162 | 14.4M | invAngleSum += invAngle; | 163 | 14.4M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; | 164 | 14.4M | } | 165 | | | 166 | | // Copy the top-left and top pixels. | 167 | 44.3M | for (int i = 0; i < width + 1; i++) | 168 | 39.9M | ref_pix[-1 + i] = srcPix[i]; | 169 | 4.43M | ref = ref_pix; | 170 | 4.43M | } | 171 | 5.06M | else // Use the top and top-right neighbours. | 172 | 5.06M | ref = srcPix + 1; | 173 | | | 174 | | // Pass every row. | 175 | 9.50M | int angleSum = 0; | 176 | 85.2M | for (int y = 0; y < width; y++) | 177 | 75.7M | { | 178 | 75.7M | angleSum += angle; | 179 | 75.7M | int offset = angleSum >> 5; | 180 | 75.7M | int fraction = angleSum & 31; | 181 | | | 182 | 75.7M | if (fraction) // Interpolate | 183 | 610M | for (int x = 0; x < width; x++) | 184 | 542M | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); | 185 | 7.79M | else // Copy. | 186 | 70.5M | for (int x = 0; x < width; x++) | 187 | 62.7M | dst[y * dstStride + x] = ref[offset + x]; | 188 | 75.7M | } | 189 | 9.50M | } | 190 | | | 191 | | // Flip for horizontal. | 192 | 10.4M | if (horMode) | 193 | 5.15M | { | 194 | 41.1M | for (int y = 0; y < width - 1; y++) | 195 | 36.0M | { | 196 | 180M | 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 | 36.0M | } | 203 | 5.15M | } | 204 | 10.4M | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<16>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 104 | 2.32M | { | 105 | 2.32M | int width2 = width << 1; | 106 | | // Flip the neighbours in the horizontal case. | 107 | 2.32M | int horMode = dirMode < 18; | 108 | 2.32M | pixel neighbourBuf[129]; | 109 | 2.32M | const pixel *srcPix = srcPix0; | 110 | | | 111 | 2.32M | if (horMode) | 112 | 1.11M | { | 113 | 1.11M | neighbourBuf[0] = srcPix[0]; | 114 | 36.7M | for (int i = 0; i < width << 1; i++) | 115 | 35.6M | { | 116 | 35.6M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; | 117 | 35.6M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; | 118 | 35.6M | } | 119 | 1.11M | srcPix = neighbourBuf; | 120 | 1.11M | } | 121 | | | 122 | | // Intra prediction angle and inverse angle tables. | 123 | 2.32M | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; | 124 | 2.32M | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; | 125 | | | 126 | | // Get the prediction angle. | 127 | 2.32M | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; | 128 | 2.32M | int angle = angleTable[8 + angleOffset]; | 129 | | | 130 | | // Vertical Prediction. | 131 | 2.32M | if (!angle) | 132 | 194k | { | 133 | 3.31M | for (int y = 0; y < width; y++) | 134 | 52.9M | for (int x = 0; x < width; x++) | 135 | 49.8M | dst[y * dstStride + x] = srcPix[1 + x]; | 136 | | | 137 | 194k | if (bFilter) | 138 | 138k | { | 139 | 138k | int topLeft = srcPix[0], top = srcPix[1]; | 140 | 2.36M | for (int y = 0; y < width; y++) | 141 | 2.22M | dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1))); | 142 | 138k | } | 143 | 194k | } | 144 | 2.12M | else // Angular prediction. | 145 | 2.12M | { | 146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). | 147 | 2.12M | pixel refBuf[64]; | 148 | 2.12M | const pixel *ref; | 149 | | | 150 | | // Use the projected left neighbours and the top neighbours. | 151 | 2.12M | if (angle < 0) | 152 | 1.01M | { | 153 | | // Number of neighbours projected. | 154 | 1.01M | int nbProjected = -((width * angle) >> 5) - 1; | 155 | 1.01M | pixel *ref_pix = refBuf + nbProjected + 1; | 156 | | | 157 | | // Project the neighbours. | 158 | 1.01M | int invAngle = invAngleTable[- angleOffset - 1]; | 159 | 1.01M | int invAngleSum = 128; | 160 | 7.72M | for (int i = 0; i < nbProjected; i++) | 161 | 6.70M | { | 162 | 6.70M | invAngleSum += invAngle; | 163 | 6.70M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; | 164 | 6.70M | } | 165 | | | 166 | | // Copy the top-left and top pixels. | 167 | 18.2M | for (int i = 0; i < width + 1; i++) | 168 | 17.2M | ref_pix[-1 + i] = srcPix[i]; | 169 | 1.01M | ref = ref_pix; | 170 | 1.01M | } | 171 | 1.11M | else // Use the top and top-right neighbours. | 172 | 1.11M | ref = srcPix + 1; | 173 | | | 174 | | // Pass every row. | 175 | 2.12M | int angleSum = 0; | 176 | 35.8M | for (int y = 0; y < width; y++) | 177 | 33.7M | { | 178 | 33.7M | angleSum += angle; | 179 | 33.7M | int offset = angleSum >> 5; | 180 | 33.7M | int fraction = angleSum & 31; | 181 | | | 182 | 33.7M | if (fraction) // Interpolate | 183 | 502M | for (int x = 0; x < width; x++) | 184 | 472M | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); | 185 | 4.17M | else // Copy. | 186 | 71.9M | for (int x = 0; x < width; x++) | 187 | 67.8M | dst[y * dstStride + x] = ref[offset + x]; | 188 | 33.7M | } | 189 | 2.12M | } | 190 | | | 191 | | // Flip for horizontal. | 192 | 2.32M | if (horMode) | 193 | 1.11M | { | 194 | 17.8M | for (int y = 0; y < width - 1; y++) | 195 | 16.6M | { | 196 | 150M | for (int x = y + 1; x < width; x++) | 197 | 133M | { | 198 | 133M | pixel tmp = dst[y * dstStride + x]; | 199 | 133M | dst[y * dstStride + x] = dst[x * dstStride + y]; | 200 | 133M | dst[x * dstStride + y] = tmp; | 201 | 133M | } | 202 | 16.6M | } | 203 | 1.11M | } | 204 | 2.32M | } |
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<32>(unsigned char*, long, unsigned char const*, int, int) Line | Count | Source | 104 | 466k | { | 105 | 466k | int width2 = width << 1; | 106 | | // Flip the neighbours in the horizontal case. | 107 | 466k | int horMode = dirMode < 18; | 108 | 466k | pixel neighbourBuf[129]; | 109 | 466k | const pixel *srcPix = srcPix0; | 110 | | | 111 | 466k | if (horMode) | 112 | 226k | { | 113 | 226k | neighbourBuf[0] = srcPix[0]; | 114 | 14.7M | for (int i = 0; i < width << 1; i++) | 115 | 14.5M | { | 116 | 14.5M | neighbourBuf[1 + i] = srcPix[width2 + 1 + i]; | 117 | 14.5M | neighbourBuf[width2 + 1 + i] = srcPix[1 + i]; | 118 | 14.5M | } | 119 | 226k | srcPix = neighbourBuf; | 120 | 226k | } | 121 | | | 122 | | // Intra prediction angle and inverse angle tables. | 123 | 466k | const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 }; | 124 | 466k | const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 }; | 125 | | | 126 | | // Get the prediction angle. | 127 | 466k | int angleOffset = horMode ? 10 - dirMode : dirMode - 26; | 128 | 466k | int angle = angleTable[8 + angleOffset]; | 129 | | | 130 | | // Vertical Prediction. | 131 | 466k | if (!angle) | 132 | 28.5k | { | 133 | 943k | for (int y = 0; y < width; y++) | 134 | 30.1M | for (int x = 0; x < width; x++) | 135 | 29.2M | dst[y * dstStride + x] = srcPix[1 + x]; | 136 | | | 137 | 28.5k | 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 | 28.5k | } | 144 | 438k | else // Angular prediction. | 145 | 438k | { | 146 | | // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]). | 147 | 438k | pixel refBuf[64]; | 148 | 438k | const pixel *ref; | 149 | | | 150 | | // Use the projected left neighbours and the top neighbours. | 151 | 438k | if (angle < 0) | 152 | 211k | { | 153 | | // Number of neighbours projected. | 154 | 211k | int nbProjected = -((width * angle) >> 5) - 1; | 155 | 211k | pixel *ref_pix = refBuf + nbProjected + 1; | 156 | | | 157 | | // Project the neighbours. | 158 | 211k | int invAngle = invAngleTable[- angleOffset - 1]; | 159 | 211k | int invAngleSum = 128; | 160 | 3.07M | for (int i = 0; i < nbProjected; i++) | 161 | 2.86M | { | 162 | 2.86M | invAngleSum += invAngle; | 163 | 2.86M | ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)]; | 164 | 2.86M | } | 165 | | | 166 | | // Copy the top-left and top pixels. | 167 | 7.18M | for (int i = 0; i < width + 1; i++) | 168 | 6.97M | ref_pix[-1 + i] = srcPix[i]; | 169 | 211k | ref = ref_pix; | 170 | 211k | } | 171 | 226k | else // Use the top and top-right neighbours. | 172 | 226k | ref = srcPix + 1; | 173 | | | 174 | | // Pass every row. | 175 | 438k | int angleSum = 0; | 176 | 14.3M | for (int y = 0; y < width; y++) | 177 | 13.8M | { | 178 | 13.8M | angleSum += angle; | 179 | 13.8M | int offset = angleSum >> 5; | 180 | 13.8M | int fraction = angleSum & 31; | 181 | | | 182 | 13.8M | if (fraction) // Interpolate | 183 | 396M | for (int x = 0; x < width; x++) | 184 | 384M | dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5); | 185 | 1.82M | else // Copy. | 186 | 61.3M | for (int x = 0; x < width; x++) | 187 | 59.5M | dst[y * dstStride + x] = ref[offset + x]; | 188 | 13.8M | } | 189 | 438k | } | 190 | | | 191 | | // Flip for horizontal. | 192 | 466k | if (horMode) | 193 | 227k | { | 194 | 7.25M | for (int y = 0; y < width - 1; y++) | 195 | 7.02M | { | 196 | 119M | for (int x = y + 1; x < width; x++) | 197 | 112M | { | 198 | 112M | pixel tmp = dst[y * dstStride + x]; | 199 | 112M | dst[y * dstStride + x] = dst[x * dstStride + y]; | 200 | 112M | dst[x * dstStride + y] = tmp; | 201 | 112M | } | 202 | 7.02M | } | 203 | 227k | } | 204 | 466k | } |
|
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 | | } |