Coverage Report

Created: 2026-10-28 06:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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.58M
{
34
1.58M
    const int tuSize2 = tuSize << 1;
35
36
1.58M
    pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2];
37
38
    // filtering top
39
29.6M
    for (int i = 1; i < tuSize2; i++)
40
28.1M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
41
1.58M
    filtered[tuSize2] = topLast;
42
    
43
    // filtering top-left
44
1.58M
    filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2;
45
46
    // filtering left
47
1.58M
    filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2;
48
28.1M
    for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++)
49
26.5M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
50
1.58M
    filtered[tuSize2 + tuSize2] = leftLast;
51
1.58M
}
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.32M
{
34
1.32M
    const int tuSize2 = tuSize << 1;
35
36
1.32M
    pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2];
37
38
    // filtering top
39
21.1M
    for (int i = 1; i < tuSize2; i++)
40
19.8M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
41
1.32M
    filtered[tuSize2] = topLast;
42
    
43
    // filtering top-left
44
1.32M
    filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2;
45
46
    // filtering left
47
1.32M
    filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2;
48
19.8M
    for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++)
49
18.5M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
50
1.32M
    filtered[tuSize2 + tuSize2] = leftLast;
51
1.32M
}
intrapred.cpp:void (anonymous namespace)::intraFilter<16>(unsigned char const*, unsigned char*)
Line
Count
Source
33
267k
{
34
267k
    const int tuSize2 = tuSize << 1;
35
36
267k
    pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2];
37
38
    // filtering top
39
8.54M
    for (int i = 1; i < tuSize2; i++)
40
8.27M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
41
267k
    filtered[tuSize2] = topLast;
42
    
43
    // filtering top-left
44
267k
    filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2;
45
46
    // filtering left
47
267k
    filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2;
48
8.27M
    for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++)
49
8.00M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
50
267k
    filtered[tuSize2 + tuSize2] = leftLast;
51
267k
}
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
3.11M
{
55
    // boundary pixels processing
56
3.11M
    dst[0] = (pixel)((above[0] + left[0] + 2 * dst[0] + 2) >> 2);
57
58
17.2M
    for (int x = 1; x < size; x++)
59
14.1M
        dst[x] = (pixel)((above[x] +  3 * dst[x] + 2) >> 2);
60
61
3.11M
    dst += dststride;
62
17.2M
    for (int y = 1; y < size; y++)
63
14.1M
    {
64
14.1M
        *dst = (pixel)((left[y] + 3 * *dst + 2) >> 2);
65
14.1M
        dst += dststride;
66
14.1M
    }
67
3.11M
}
68
69
template<int width>
70
void intra_pred_dc_c(pixel* dst, intptr_t dstStride, const pixel* srcPix, int /*dirMode*/, int bFilter)
71
4.85M
{
72
4.85M
    int k, l;
73
74
4.85M
    int dcVal = width;
75
31.3M
    for (int i = 0; i < width; i++)
76
26.4M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
4.85M
    dcVal = dcVal / (width + width);
79
31.3M
    for (k = 0; k < width; k++)
80
232M
        for (l = 0; l < width; l++)
81
206M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
4.85M
    if (bFilter)
84
3.11M
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
4.85M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<4>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
3.72M
{
72
3.72M
    int k, l;
73
74
3.72M
    int dcVal = width;
75
18.6M
    for (int i = 0; i < width; i++)
76
14.9M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
3.72M
    dcVal = dcVal / (width + width);
79
18.6M
    for (k = 0; k < width; k++)
80
74.4M
        for (l = 0; l < width; l++)
81
59.5M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
3.72M
    if (bFilter)
84
2.23M
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
3.72M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<8>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
888k
{
72
888k
    int k, l;
73
74
888k
    int dcVal = width;
75
7.99M
    for (int i = 0; i < width; i++)
76
7.10M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
888k
    dcVal = dcVal / (width + width);
79
7.99M
    for (k = 0; k < width; k++)
80
63.9M
        for (l = 0; l < width; l++)
81
56.8M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
888k
    if (bFilter)
84
707k
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
888k
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<16>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
205k
{
72
205k
    int k, l;
73
74
205k
    int dcVal = width;
75
3.50M
    for (int i = 0; i < width; i++)
76
3.29M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
205k
    dcVal = dcVal / (width + width);
79
3.50M
    for (k = 0; k < width; k++)
80
55.9M
        for (l = 0; l < width; l++)
81
52.7M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
205k
    if (bFilter)
84
168k
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
205k
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<32>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
36.2k
{
72
36.2k
    int k, l;
73
74
36.2k
    int dcVal = width;
75
1.19M
    for (int i = 0; i < width; i++)
76
1.15M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
36.2k
    dcVal = dcVal / (width + width);
79
1.19M
    for (k = 0; k < width; k++)
80
38.2M
        for (l = 0; l < width; l++)
81
37.0M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
36.2k
    if (bFilter)
84
0
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
36.2k
}
86
87
template<int log2Size>
88
void planar_pred_c(pixel* dst, intptr_t dstStride, const pixel* srcPix, int /*dirMode*/, int /*bFilter*/)
89
8.49M
{
90
8.49M
    const int blkSize = 1 << log2Size;
91
92
8.49M
    const pixel* above = srcPix + 1;
93
8.49M
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
8.49M
    pixel topRight = above[blkSize];
96
8.49M
    pixel bottomLeft = left[blkSize];
97
53.1M
    for (int y = 0; y < blkSize; y++)
98
364M
        for (int x = 0; x < blkSize; x++)
99
319M
            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
8.49M
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<2>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
6.65M
{
90
6.65M
    const int blkSize = 1 << log2Size;
91
92
6.65M
    const pixel* above = srcPix + 1;
93
6.65M
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
6.65M
    pixel topRight = above[blkSize];
96
6.65M
    pixel bottomLeft = left[blkSize];
97
33.2M
    for (int y = 0; y < blkSize; y++)
98
132M
        for (int x = 0; x < blkSize; x++)
99
106M
            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.65M
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<3>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
1.50M
{
90
1.50M
    const int blkSize = 1 << log2Size;
91
92
1.50M
    const pixel* above = srcPix + 1;
93
1.50M
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
1.50M
    pixel topRight = above[blkSize];
96
1.50M
    pixel bottomLeft = left[blkSize];
97
13.5M
    for (int y = 0; y < blkSize; y++)
98
108M
        for (int x = 0; x < blkSize; x++)
99
96.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
1.50M
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<4>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
301k
{
90
301k
    const int blkSize = 1 << log2Size;
91
92
301k
    const pixel* above = srcPix + 1;
93
301k
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
301k
    pixel topRight = above[blkSize];
96
301k
    pixel bottomLeft = left[blkSize];
97
5.11M
    for (int y = 0; y < blkSize; y++)
98
81.8M
        for (int x = 0; x < blkSize; x++)
99
77.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
301k
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<5>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
39.4k
{
90
39.4k
    const int blkSize = 1 << log2Size;
91
92
39.4k
    const pixel* above = srcPix + 1;
93
39.4k
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
39.4k
    pixel topRight = above[blkSize];
96
39.4k
    pixel bottomLeft = left[blkSize];
97
1.30M
    for (int y = 0; y < blkSize; y++)
98
41.6M
        for (int x = 0; x < blkSize; x++)
99
40.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
39.4k
}
101
102
template<int width>
103
void intra_pred_ang_c(pixel* dst, intptr_t dstStride, const pixel *srcPix0, int dirMode, int bFilter)
104
71.1M
{
105
71.1M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
71.1M
    int horMode = dirMode < 18;
108
71.1M
    pixel neighbourBuf[129];
109
71.1M
    const pixel *srcPix = srcPix0;
110
111
71.1M
    if (horMode)
112
33.9M
    {
113
33.9M
        neighbourBuf[0] = srcPix[0];
114
412M
        for (int i = 0; i < width << 1; i++)
115
378M
        {
116
378M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
378M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
378M
        }
119
33.9M
        srcPix = neighbourBuf;
120
33.9M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
71.1M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
71.1M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
71.1M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
71.1M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
71.1M
    if (!angle)
132
7.55M
    {
133
46.7M
        for (int y = 0; y < width; y++)
134
318M
            for (int x = 0; x < width; x++)
135
279M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
7.55M
        if (bFilter)
138
4.09M
        {
139
4.09M
            int topLeft = srcPix[0], top = srcPix[1];
140
26.1M
            for (int y = 0; y < width; y++)
141
22.0M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
4.09M
        }
143
7.55M
    }
144
63.5M
    else // Angular prediction.
145
63.5M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
63.5M
        pixel refBuf[64];
148
63.5M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
63.5M
        if (angle < 0)
152
29.8M
        {
153
            // Number of neighbours projected. 
154
29.8M
            int nbProjected = -((width * angle) >> 5) - 1;
155
29.8M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
29.8M
            int invAngle = invAngleTable[- angleOffset - 1];
159
29.8M
            int invAngleSum = 128;
160
92.9M
            for (int i = 0; i < nbProjected; i++)
161
63.1M
            {
162
63.1M
                invAngleSum += invAngle;
163
63.1M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
63.1M
            }
165
166
            // Copy the top-left and top pixels.
167
226M
            for (int i = 0; i < width + 1; i++)
168
196M
                ref_pix[-1 + i] = srcPix[i];
169
29.8M
            ref = ref_pix;
170
29.8M
        }
171
33.7M
        else // Use the top and top-right neighbours.
172
33.7M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
63.5M
        int angleSum = 0;
176
417M
        for (int y = 0; y < width; y++)
177
353M
        {
178
353M
            angleSum += angle;
179
353M
            int offset = angleSum >> 5;
180
353M
            int fraction = angleSum & 31;
181
182
353M
            if (fraction) // Interpolate
183
2.83G
                for (int x = 0; x < width; x++)
184
2.52G
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
42.4M
            else // Copy.
186
390M
                for (int x = 0; x < width; x++)
187
347M
                    dst[y * dstStride + x] = ref[offset + x];
188
353M
        }
189
63.5M
    }
190
191
    // Flip for horizontal.
192
71.1M
    if (horMode)
193
33.9M
    {
194
189M
        for (int y = 0; y < width - 1; y++)
195
155M
        {
196
823M
            for (int x = y + 1; x < width; x++)
197
668M
            {
198
668M
                pixel tmp              = dst[y * dstStride + x];
199
668M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
668M
                dst[x * dstStride + y] = tmp;
201
668M
            }
202
155M
        }
203
33.9M
    }
204
71.1M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<4>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
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.3M
    {
113
25.3M
        neighbourBuf[0] = srcPix[0];
114
227M
        for (int i = 0; i < width << 1; i++)
115
202M
        {
116
202M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
202M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
202M
        }
119
25.3M
        srcPix = neighbourBuf;
120
25.3M
    }
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
6.03M
    {
133
30.1M
        for (int y = 0; y < width; y++)
134
120M
            for (int x = 0; x < width; x++)
135
96.4M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
6.03M
        if (bFilter)
138
3.05M
        {
139
3.05M
            int topLeft = srcPix[0], top = srcPix[1];
140
15.2M
            for (int y = 0; y < width; y++)
141
12.2M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
3.05M
        }
143
6.03M
    }
144
47.5M
    else // Angular prediction.
145
47.5M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
47.5M
        pixel refBuf[64];
148
47.5M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
47.5M
        if (angle < 0)
152
22.3M
        {
153
            // Number of neighbours projected. 
154
22.3M
            int nbProjected = -((width * angle) >> 5) - 1;
155
22.3M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
22.3M
            int invAngle = invAngleTable[- angleOffset - 1];
159
22.3M
            int invAngleSum = 128;
160
53.6M
            for (int i = 0; i < nbProjected; i++)
161
31.2M
            {
162
31.2M
                invAngleSum += invAngle;
163
31.2M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
31.2M
            }
165
166
            // Copy the top-left and top pixels.
167
134M
            for (int i = 0; i < width + 1; i++)
168
111M
                ref_pix[-1 + i] = srcPix[i];
169
22.3M
            ref = ref_pix;
170
22.3M
        }
171
25.2M
        else // Use the top and top-right neighbours.
172
25.2M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
47.5M
        int angleSum = 0;
176
237M
        for (int y = 0; y < width; y++)
177
189M
        {
178
189M
            angleSum += angle;
179
189M
            int offset = angleSum >> 5;
180
189M
            int fraction = angleSum & 31;
181
182
189M
            if (fraction) // Interpolate
183
826M
                for (int x = 0; x < width; x++)
184
660M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
23.9M
            else // Copy.
186
119M
                for (int x = 0; x < width; x++)
187
95.4M
                    dst[y * dstStride + x] = ref[offset + x];
188
189M
        }
189
47.5M
    }
190
191
    // Flip for horizontal.
192
53.5M
    if (horMode)
193
25.3M
    {
194
101M
        for (int y = 0; y < width - 1; y++)
195
75.8M
        {
196
227M
            for (int x = y + 1; x < width; x++)
197
151M
            {
198
151M
                pixel tmp              = dst[y * dstStride + x];
199
151M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
151M
                dst[x * dstStride + y] = tmp;
201
151M
            }
202
75.8M
        }
203
25.3M
    }
204
53.5M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<8>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
104
13.8M
{
105
13.8M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
13.8M
    int horMode = dirMode < 18;
108
13.8M
    pixel neighbourBuf[129];
109
13.8M
    const pixel *srcPix = srcPix0;
110
111
13.8M
    if (horMode)
112
6.82M
    {
113
6.82M
        neighbourBuf[0] = srcPix[0];
114
116M
        for (int i = 0; i < width << 1; i++)
115
109M
        {
116
109M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
109M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
109M
        }
119
6.82M
        srcPix = neighbourBuf;
120
6.82M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
13.8M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
13.8M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
13.8M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
13.8M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
13.8M
    if (!angle)
132
1.22M
    {
133
10.9M
        for (int y = 0; y < width; y++)
134
87.9M
            for (int x = 0; x < width; x++)
135
78.1M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
1.22M
        if (bFilter)
138
861k
        {
139
861k
            int topLeft = srcPix[0], top = srcPix[1];
140
7.75M
            for (int y = 0; y < width; y++)
141
6.88M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
861k
        }
143
1.22M
    }
144
12.6M
    else // Angular prediction.
145
12.6M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
12.6M
        pixel refBuf[64];
148
12.6M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
12.6M
        if (angle < 0)
152
5.88M
        {
153
            // Number of neighbours projected. 
154
5.88M
            int nbProjected = -((width * angle) >> 5) - 1;
155
5.88M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
5.88M
            int invAngle = invAngleTable[- angleOffset - 1];
159
5.88M
            int invAngleSum = 128;
160
25.0M
            for (int i = 0; i < nbProjected; i++)
161
19.1M
            {
162
19.1M
                invAngleSum += invAngle;
163
19.1M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
19.1M
            }
165
166
            // Copy the top-left and top pixels.
167
58.8M
            for (int i = 0; i < width + 1; i++)
168
52.9M
                ref_pix[-1 + i] = srcPix[i];
169
5.88M
            ref = ref_pix;
170
5.88M
        }
171
6.72M
        else // Use the top and top-right neighbours.
172
6.72M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
12.6M
        int angleSum = 0;
176
113M
        for (int y = 0; y < width; y++)
177
100M
        {
178
100M
            angleSum += angle;
179
100M
            int offset = angleSum >> 5;
180
100M
            int fraction = angleSum & 31;
181
182
100M
            if (fraction) // Interpolate
183
810M
                for (int x = 0; x < width; x++)
184
720M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
10.4M
            else // Copy.
186
93.5M
                for (int x = 0; x < width; x++)
187
83.1M
                    dst[y * dstStride + x] = ref[offset + x];
188
100M
        }
189
12.6M
    }
190
191
    // Flip for horizontal.
192
13.8M
    if (horMode)
193
6.83M
    {
194
54.5M
        for (int y = 0; y < width - 1; y++)
195
47.7M
        {
196
238M
            for (int x = y + 1; x < width; x++)
197
190M
            {
198
190M
                pixel tmp              = dst[y * dstStride + x];
199
190M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
190M
                dst[x * dstStride + y] = tmp;
201
190M
            }
202
47.7M
        }
203
6.83M
    }
204
13.8M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<16>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
104
3.07M
{
105
3.07M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
3.07M
    int horMode = dirMode < 18;
108
3.07M
    pixel neighbourBuf[129];
109
3.07M
    const pixel *srcPix = srcPix0;
110
111
3.07M
    if (horMode)
112
1.47M
    {
113
1.47M
        neighbourBuf[0] = srcPix[0];
114
48.6M
        for (int i = 0; i < width << 1; i++)
115
47.2M
        {
116
47.2M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
47.2M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
47.2M
        }
119
1.47M
        srcPix = neighbourBuf;
120
1.47M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
3.07M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
3.07M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
3.07M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
3.07M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
3.07M
    if (!angle)
132
257k
    {
133
4.38M
        for (int y = 0; y < width; y++)
134
70.0M
            for (int x = 0; x < width; x++)
135
65.9M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
257k
        if (bFilter)
138
183k
        {
139
183k
            int topLeft = srcPix[0], top = srcPix[1];
140
3.11M
            for (int y = 0; y < width; y++)
141
2.93M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
183k
        }
143
257k
    }
144
2.82M
    else // Angular prediction.
145
2.82M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
2.82M
        pixel refBuf[64];
148
2.82M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
2.82M
        if (angle < 0)
152
1.34M
        {
153
            // Number of neighbours projected. 
154
1.34M
            int nbProjected = -((width * angle) >> 5) - 1;
155
1.34M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
1.34M
            int invAngle = invAngleTable[- angleOffset - 1];
159
1.34M
            int invAngleSum = 128;
160
10.2M
            for (int i = 0; i < nbProjected; i++)
161
8.88M
            {
162
8.88M
                invAngleSum += invAngle;
163
8.88M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
8.88M
            }
165
166
            // Copy the top-left and top pixels.
167
24.2M
            for (int i = 0; i < width + 1; i++)
168
22.8M
                ref_pix[-1 + i] = srcPix[i];
169
1.34M
            ref = ref_pix;
170
1.34M
        }
171
1.47M
        else // Use the top and top-right neighbours.
172
1.47M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
2.82M
        int angleSum = 0;
176
47.6M
        for (int y = 0; y < width; y++)
177
44.8M
        {
178
44.8M
            angleSum += angle;
179
44.8M
            int offset = angleSum >> 5;
180
44.8M
            int fraction = angleSum & 31;
181
182
44.8M
            if (fraction) // Interpolate
183
665M
                for (int x = 0; x < width; x++)
184
625M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
5.54M
            else // Copy.
186
95.3M
                for (int x = 0; x < width; x++)
187
89.8M
                    dst[y * dstStride + x] = ref[offset + x];
188
44.8M
        }
189
2.82M
    }
190
191
    // Flip for horizontal.
192
3.07M
    if (horMode)
193
1.47M
    {
194
23.5M
        for (int y = 0; y < width - 1; y++)
195
22.1M
        {
196
199M
            for (int x = y + 1; x < width; x++)
197
176M
            {
198
176M
                pixel tmp              = dst[y * dstStride + x];
199
176M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
176M
                dst[x * dstStride + y] = tmp;
201
176M
            }
202
22.1M
        }
203
1.47M
    }
204
3.07M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<32>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
104
621k
{
105
621k
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
621k
    int horMode = dirMode < 18;
108
621k
    pixel neighbourBuf[129];
109
621k
    const pixel *srcPix = srcPix0;
110
111
621k
    if (horMode)
112
302k
    {
113
302k
        neighbourBuf[0] = srcPix[0];
114
19.6M
        for (int i = 0; i < width << 1; i++)
115
19.3M
        {
116
19.3M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
19.3M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
19.3M
        }
119
302k
        srcPix = neighbourBuf;
120
302k
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
621k
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
621k
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
621k
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
621k
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
621k
    if (!angle)
132
38.0k
    {
133
1.25M
        for (int y = 0; y < width; y++)
134
40.1M
            for (int x = 0; x < width; x++)
135
38.9M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
38.0k
        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
38.0k
    }
144
583k
    else // Angular prediction.
145
583k
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
583k
        pixel refBuf[64];
148
583k
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
583k
        if (angle < 0)
152
281k
        {
153
            // Number of neighbours projected. 
154
281k
            int nbProjected = -((width * angle) >> 5) - 1;
155
281k
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
281k
            int invAngle = invAngleTable[- angleOffset - 1];
159
281k
            int invAngleSum = 128;
160
4.09M
            for (int i = 0; i < nbProjected; i++)
161
3.81M
            {
162
3.81M
                invAngleSum += invAngle;
163
3.81M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
3.81M
            }
165
166
            // Copy the top-left and top pixels.
167
9.57M
            for (int i = 0; i < width + 1; i++)
168
9.29M
                ref_pix[-1 + i] = srcPix[i];
169
281k
            ref = ref_pix;
170
281k
        }
171
302k
        else // Use the top and top-right neighbours.
172
302k
            ref = srcPix + 1;
173
174
        // Pass every row.
175
583k
        int angleSum = 0;
176
19.2M
        for (int y = 0; y < width; y++)
177
18.6M
        {
178
18.6M
            angleSum += angle;
179
18.6M
            int offset = angleSum >> 5;
180
18.6M
            int fraction = angleSum & 31;
181
182
18.6M
            if (fraction) // Interpolate
183
530M
                for (int x = 0; x < width; x++)
184
514M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
2.46M
            else // Copy.
186
81.7M
                for (int x = 0; x < width; x++)
187
79.3M
                    dst[y * dstStride + x] = ref[offset + x];
188
18.6M
        }
189
583k
    }
190
191
    // Flip for horizontal.
192
621k
    if (horMode)
193
302k
    {
194
9.64M
        for (int y = 0; y < width - 1; y++)
195
9.34M
        {
196
158M
            for (int x = y + 1; x < width; x++)
197
149M
            {
198
149M
                pixel tmp              = dst[y * dstStride + x];
199
149M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
149M
                dst[x * dstStride + y] = tmp;
201
149M
            }
202
9.34M
        }
203
302k
    }
204
621k
}
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
}