Coverage Report

Created: 2026-07-16 06:32

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.27M
{
34
1.27M
    const int tuSize2 = tuSize << 1;
35
36
1.27M
    pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2];
37
38
    // filtering top
39
23.8M
    for (int i = 1; i < tuSize2; i++)
40
22.5M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
41
1.27M
    filtered[tuSize2] = topLast;
42
    
43
    // filtering top-left
44
1.27M
    filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2;
45
46
    // filtering left
47
1.27M
    filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2;
48
22.5M
    for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++)
49
21.2M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
50
1.27M
    filtered[tuSize2 + tuSize2] = leftLast;
51
1.27M
}
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
16.9M
    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.8M
        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
214k
{
34
214k
    const int tuSize2 = tuSize << 1;
35
36
214k
    pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2];
37
38
    // filtering top
39
6.85M
    for (int i = 1; i < tuSize2; i++)
40
6.64M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
41
214k
    filtered[tuSize2] = topLast;
42
    
43
    // filtering top-left
44
214k
    filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2;
45
46
    // filtering left
47
214k
    filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2;
48
6.64M
    for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++)
49
6.42M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
50
214k
    filtered[tuSize2 + tuSize2] = leftLast;
51
214k
}
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.50M
{
55
    // boundary pixels processing
56
2.50M
    dst[0] = (pixel)((above[0] + left[0] + 2 * dst[0] + 2) >> 2);
57
58
13.9M
    for (int x = 1; x < size; x++)
59
11.4M
        dst[x] = (pixel)((above[x] +  3 * dst[x] + 2) >> 2);
60
61
2.50M
    dst += dststride;
62
13.9M
    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.50M
}
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.90M
{
72
3.90M
    int k, l;
73
74
3.90M
    int dcVal = width;
75
25.1M
    for (int i = 0; i < width; i++)
76
21.2M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
3.90M
    dcVal = dcVal / (width + width);
79
25.1M
    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.90M
    if (bFilter)
84
2.50M
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
3.90M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<4>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
2.99M
{
72
2.99M
    int k, l;
73
74
2.99M
    int dcVal = width;
75
14.9M
    for (int i = 0; i < width; i++)
76
11.9M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
2.99M
    dcVal = dcVal / (width + width);
79
14.9M
    for (k = 0; k < width; k++)
80
59.8M
        for (l = 0; l < width; l++)
81
47.8M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
2.99M
    if (bFilter)
84
1.79M
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
2.99M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<8>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
715k
{
72
715k
    int k, l;
73
74
715k
    int dcVal = width;
75
6.43M
    for (int i = 0; i < width; i++)
76
5.72M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
715k
    dcVal = dcVal / (width + width);
79
6.43M
    for (k = 0; k < width; k++)
80
51.4M
        for (l = 0; l < width; l++)
81
45.7M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
715k
    if (bFilter)
84
570k
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
715k
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<16>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
166k
{
72
166k
    int k, l;
73
74
166k
    int dcVal = width;
75
2.82M
    for (int i = 0; i < width; i++)
76
2.65M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
166k
    dcVal = dcVal / (width + width);
79
2.82M
    for (k = 0; k < width; k++)
80
45.1M
        for (l = 0; l < width; l++)
81
42.5M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
166k
    if (bFilter)
84
136k
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
166k
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<32>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
29.0k
{
72
29.0k
    int k, l;
73
74
29.0k
    int dcVal = width;
75
959k
    for (int i = 0; i < width; i++)
76
930k
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
29.0k
    dcVal = dcVal / (width + width);
79
959k
    for (k = 0; k < width; k++)
80
30.6M
        for (l = 0; l < width; l++)
81
29.7M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
29.0k
    if (bFilter)
84
0
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
29.0k
}
86
87
template<int log2Size>
88
void planar_pred_c(pixel* dst, intptr_t dstStride, const pixel* srcPix, int /*dirMode*/, int /*bFilter*/)
89
6.81M
{
90
6.81M
    const int blkSize = 1 << log2Size;
91
92
6.81M
    const pixel* above = srcPix + 1;
93
6.81M
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
6.81M
    pixel topRight = above[blkSize];
96
6.81M
    pixel bottomLeft = left[blkSize];
97
42.6M
    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.81M
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<2>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
5.34M
{
90
5.34M
    const int blkSize = 1 << log2Size;
91
92
5.34M
    const pixel* above = srcPix + 1;
93
5.34M
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
5.34M
    pixel topRight = above[blkSize];
96
5.34M
    pixel bottomLeft = left[blkSize];
97
26.6M
    for (int y = 0; y < blkSize; y++)
98
106M
        for (int x = 0; x < blkSize; x++)
99
85.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
5.34M
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<3>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
1.20M
{
90
1.20M
    const int blkSize = 1 << log2Size;
91
92
1.20M
    const pixel* above = srcPix + 1;
93
1.20M
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
1.20M
    pixel topRight = above[blkSize];
96
1.20M
    pixel bottomLeft = left[blkSize];
97
10.8M
    for (int y = 0; y < blkSize; y++)
98
86.7M
        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
1.20M
}
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.6M
        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
31.6k
{
90
31.6k
    const int blkSize = 1 << log2Size;
91
92
31.6k
    const pixel* above = srcPix + 1;
93
31.6k
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
31.6k
    pixel topRight = above[blkSize];
96
31.6k
    pixel bottomLeft = left[blkSize];
97
1.04M
    for (int y = 0; y < blkSize; y++)
98
33.3M
        for (int x = 0; x < blkSize; x++)
99
32.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
31.6k
}
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.1M
{
105
57.1M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
57.1M
    int horMode = dirMode < 18;
108
57.1M
    pixel neighbourBuf[129];
109
57.1M
    const pixel *srcPix = srcPix0;
110
111
57.1M
    if (horMode)
112
27.2M
    {
113
27.2M
        neighbourBuf[0] = srcPix[0];
114
331M
        for (int i = 0; i < width << 1; i++)
115
303M
        {
116
303M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
303M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
303M
        }
119
27.2M
        srcPix = neighbourBuf;
120
27.2M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
57.1M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
57.1M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
57.1M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
57.1M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
57.1M
    if (!angle)
132
6.07M
    {
133
37.6M
        for (int y = 0; y < width; y++)
134
256M
            for (int x = 0; x < width; x++)
135
224M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
6.07M
        if (bFilter)
138
3.29M
        {
139
3.29M
            int topLeft = srcPix[0], top = srcPix[1];
140
21.0M
            for (int y = 0; y < width; y++)
141
17.7M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
3.29M
        }
143
6.07M
    }
144
51.0M
    else // Angular prediction.
145
51.0M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
51.0M
        pixel refBuf[64];
148
51.0M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
51.0M
        if (angle < 0)
152
23.9M
        {
153
            // Number of neighbours projected. 
154
23.9M
            int nbProjected = -((width * angle) >> 5) - 1;
155
23.9M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
23.9M
            int invAngle = invAngleTable[- angleOffset - 1];
159
23.9M
            int invAngleSum = 128;
160
74.6M
            for (int i = 0; i < nbProjected; i++)
161
50.7M
            {
162
50.7M
                invAngleSum += invAngle;
163
50.7M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
50.7M
            }
165
166
            // Copy the top-left and top pixels.
167
182M
            for (int i = 0; i < width + 1; i++)
168
158M
                ref_pix[-1 + i] = srcPix[i];
169
23.9M
            ref = ref_pix;
170
23.9M
        }
171
27.0M
        else // Use the top and top-right neighbours.
172
27.0M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
51.0M
        int angleSum = 0;
176
335M
        for (int y = 0; y < width; y++)
177
284M
        {
178
284M
            angleSum += angle;
179
284M
            int offset = angleSum >> 5;
180
284M
            int fraction = angleSum & 31;
181
182
284M
            if (fraction) // Interpolate
183
2.27G
                for (int x = 0; x < width; x++)
184
2.02G
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
34.1M
            else // Copy.
186
313M
                for (int x = 0; x < width; x++)
187
279M
                    dst[y * dstStride + x] = ref[offset + x];
188
284M
        }
189
51.0M
    }
190
191
    // Flip for horizontal.
192
57.1M
    if (horMode)
193
27.2M
    {
194
151M
        for (int y = 0; y < width - 1; y++)
195
124M
        {
196
662M
            for (int x = y + 1; x < width; x++)
197
537M
            {
198
537M
                pixel tmp              = dst[y * dstStride + x];
199
537M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
537M
                dst[x * dstStride + y] = tmp;
201
537M
            }
202
124M
        }
203
27.2M
    }
204
57.1M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<4>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
104
43.0M
{
105
43.0M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
43.0M
    int horMode = dirMode < 18;
108
43.0M
    pixel neighbourBuf[129];
109
43.0M
    const pixel *srcPix = srcPix0;
110
111
43.0M
    if (horMode)
112
20.3M
    {
113
20.3M
        neighbourBuf[0] = srcPix[0];
114
182M
        for (int i = 0; i < width << 1; i++)
115
162M
        {
116
162M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
162M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
162M
        }
119
20.3M
        srcPix = neighbourBuf;
120
20.3M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
43.0M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
43.0M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
43.0M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
43.0M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
43.0M
    if (!angle)
132
4.85M
    {
133
24.2M
        for (int y = 0; y < width; y++)
134
96.8M
            for (int x = 0; x < width; x++)
135
77.5M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
4.85M
        if (bFilter)
138
2.45M
        {
139
2.45M
            int topLeft = srcPix[0], top = srcPix[1];
140
12.2M
            for (int y = 0; y < width; y++)
141
9.81M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
2.45M
        }
143
4.85M
    }
144
38.1M
    else // Angular prediction.
145
38.1M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
38.1M
        pixel refBuf[64];
148
38.1M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
38.1M
        if (angle < 0)
152
17.9M
        {
153
            // Number of neighbours projected. 
154
17.9M
            int nbProjected = -((width * angle) >> 5) - 1;
155
17.9M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
17.9M
            int invAngle = invAngleTable[- angleOffset - 1];
159
17.9M
            int invAngleSum = 128;
160
43.0M
            for (int i = 0; i < nbProjected; i++)
161
25.1M
            {
162
25.1M
                invAngleSum += invAngle;
163
25.1M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
25.1M
            }
165
166
            // Copy the top-left and top pixels.
167
107M
            for (int i = 0; i < width + 1; i++)
168
89.6M
                ref_pix[-1 + i] = srcPix[i];
169
17.9M
            ref = ref_pix;
170
17.9M
        }
171
20.2M
        else // Use the top and top-right neighbours.
172
20.2M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
38.1M
        int angleSum = 0;
176
190M
        for (int y = 0; y < width; y++)
177
152M
        {
178
152M
            angleSum += angle;
179
152M
            int offset = angleSum >> 5;
180
152M
            int fraction = angleSum & 31;
181
182
152M
            if (fraction) // Interpolate
183
666M
                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.2M
            else // Copy.
186
95.9M
                for (int x = 0; x < width; x++)
187
76.6M
                    dst[y * dstStride + x] = ref[offset + x];
188
152M
        }
189
38.1M
    }
190
191
    // Flip for horizontal.
192
43.0M
    if (horMode)
193
20.3M
    {
194
81.3M
        for (int y = 0; y < width - 1; y++)
195
61.0M
        {
196
183M
            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.0M
        }
203
20.3M
    }
204
43.0M
}
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.48M
    {
113
5.48M
        neighbourBuf[0] = srcPix[0];
114
93.2M
        for (int i = 0; i < width << 1; i++)
115
87.7M
        {
116
87.7M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
87.7M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
87.7M
        }
119
5.48M
        srcPix = neighbourBuf;
120
5.48M
    }
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
982k
    {
133
8.84M
        for (int y = 0; y < width; y++)
134
70.7M
            for (int x = 0; x < width; x++)
135
62.8M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
982k
        if (bFilter)
138
692k
        {
139
692k
            int topLeft = srcPix[0], top = srcPix[1];
140
6.23M
            for (int y = 0; y < width; y++)
141
5.54M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
692k
        }
143
982k
    }
144
10.1M
    else // Angular prediction.
145
10.1M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
10.1M
        pixel refBuf[64];
148
10.1M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
10.1M
        if (angle < 0)
152
4.72M
        {
153
            // Number of neighbours projected. 
154
4.72M
            int nbProjected = -((width * angle) >> 5) - 1;
155
4.72M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
4.72M
            int invAngle = invAngleTable[- angleOffset - 1];
159
4.72M
            int invAngleSum = 128;
160
20.1M
            for (int i = 0; i < nbProjected; i++)
161
15.3M
            {
162
15.3M
                invAngleSum += invAngle;
163
15.3M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
15.3M
            }
165
166
            // Copy the top-left and top pixels.
167
47.2M
            for (int i = 0; i < width + 1; i++)
168
42.5M
                ref_pix[-1 + i] = srcPix[i];
169
4.72M
            ref = ref_pix;
170
4.72M
        }
171
5.40M
        else // Use the top and top-right neighbours.
172
5.40M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
10.1M
        int angleSum = 0;
176
90.8M
        for (int y = 0; y < width; y++)
177
80.7M
        {
178
80.7M
            angleSum += angle;
179
80.7M
            int offset = angleSum >> 5;
180
80.7M
            int fraction = angleSum & 31;
181
182
80.7M
            if (fraction) // Interpolate
183
649M
                for (int x = 0; x < width; x++)
184
577M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
8.40M
            else // Copy.
186
75.2M
                for (int x = 0; x < width; x++)
187
66.7M
                    dst[y * dstStride + x] = ref[offset + x];
188
80.7M
        }
189
10.1M
    }
190
191
    // Flip for horizontal.
192
11.1M
    if (horMode)
193
5.48M
    {
194
43.8M
        for (int y = 0; y < width - 1; y++)
195
38.3M
        {
196
191M
            for (int x = y + 1; x < width; x++)
197
153M
            {
198
153M
                pixel tmp              = dst[y * dstStride + x];
199
153M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
153M
                dst[x * dstStride + y] = tmp;
201
153M
            }
202
38.3M
        }
203
5.48M
    }
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.47M
{
105
2.47M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
2.47M
    int horMode = dirMode < 18;
108
2.47M
    pixel neighbourBuf[129];
109
2.47M
    const pixel *srcPix = srcPix0;
110
111
2.47M
    if (horMode)
112
1.18M
    {
113
1.18M
        neighbourBuf[0] = srcPix[0];
114
39.1M
        for (int i = 0; i < width << 1; i++)
115
38.0M
        {
116
38.0M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
38.0M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
38.0M
        }
119
1.18M
        srcPix = neighbourBuf;
120
1.18M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
2.47M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
2.47M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
2.47M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
2.47M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
2.47M
    if (!angle)
132
207k
    {
133
3.52M
        for (int y = 0; y < width; y++)
134
56.4M
            for (int x = 0; x < width; x++)
135
53.1M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
207k
        if (bFilter)
138
147k
        {
139
147k
            int topLeft = srcPix[0], top = srcPix[1];
140
2.51M
            for (int y = 0; y < width; y++)
141
2.36M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
147k
        }
143
207k
    }
144
2.27M
    else // Angular prediction.
145
2.27M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
2.27M
        pixel refBuf[64];
148
2.27M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
2.27M
        if (angle < 0)
152
1.08M
        {
153
            // Number of neighbours projected. 
154
1.08M
            int nbProjected = -((width * angle) >> 5) - 1;
155
1.08M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
1.08M
            int invAngle = invAngleTable[- angleOffset - 1];
159
1.08M
            int invAngleSum = 128;
160
8.23M
            for (int i = 0; i < nbProjected; i++)
161
7.14M
            {
162
7.14M
                invAngleSum += invAngle;
163
7.14M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
7.14M
            }
165
166
            // Copy the top-left and top pixels.
167
19.4M
            for (int i = 0; i < width + 1; i++)
168
18.4M
                ref_pix[-1 + i] = srcPix[i];
169
1.08M
            ref = ref_pix;
170
1.08M
        }
171
1.18M
        else // Use the top and top-right neighbours.
172
1.18M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
2.27M
        int angleSum = 0;
176
38.3M
        for (int y = 0; y < width; y++)
177
36.1M
        {
178
36.1M
            angleSum += angle;
179
36.1M
            int offset = angleSum >> 5;
180
36.1M
            int fraction = angleSum & 31;
181
182
36.1M
            if (fraction) // Interpolate
183
536M
                for (int x = 0; x < width; x++)
184
504M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
4.46M
            else // Copy.
186
76.8M
                for (int x = 0; x < width; x++)
187
72.3M
                    dst[y * dstStride + x] = ref[offset + x];
188
36.1M
        }
189
2.27M
    }
190
191
    // Flip for horizontal.
192
2.47M
    if (horMode)
193
1.18M
    {
194
18.9M
        for (int y = 0; y < width - 1; y++)
195
17.8M
        {
196
160M
            for (int x = y + 1; x < width; x++)
197
142M
            {
198
142M
                pixel tmp              = dst[y * dstStride + x];
199
142M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
142M
                dst[x * dstStride + y] = tmp;
201
142M
            }
202
17.8M
        }
203
1.18M
    }
204
2.47M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<32>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
104
498k
{
105
498k
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
498k
    int horMode = dirMode < 18;
108
498k
    pixel neighbourBuf[129];
109
498k
    const pixel *srcPix = srcPix0;
110
111
498k
    if (horMode)
112
242k
    {
113
242k
        neighbourBuf[0] = srcPix[0];
114
15.7M
        for (int i = 0; i < width << 1; i++)
115
15.5M
        {
116
15.5M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
15.5M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
15.5M
        }
119
242k
        srcPix = neighbourBuf;
120
242k
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
498k
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
498k
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
498k
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
498k
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
498k
    if (!angle)
132
30.5k
    {
133
1.00M
        for (int y = 0; y < width; y++)
134
32.2M
            for (int x = 0; x < width; x++)
135
31.2M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
30.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
30.5k
    }
144
468k
    else // Angular prediction.
145
468k
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
468k
        pixel refBuf[64];
148
468k
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
468k
        if (angle < 0)
152
225k
        {
153
            // Number of neighbours projected. 
154
225k
            int nbProjected = -((width * angle) >> 5) - 1;
155
225k
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
225k
            int invAngle = invAngleTable[- angleOffset - 1];
159
225k
            int invAngleSum = 128;
160
3.28M
            for (int i = 0; i < nbProjected; i++)
161
3.05M
            {
162
3.05M
                invAngleSum += invAngle;
163
3.05M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
3.05M
            }
165
166
            // Copy the top-left and top pixels.
167
7.68M
            for (int i = 0; i < width + 1; i++)
168
7.45M
                ref_pix[-1 + i] = srcPix[i];
169
225k
            ref = ref_pix;
170
225k
        }
171
242k
        else // Use the top and top-right neighbours.
172
242k
            ref = srcPix + 1;
173
174
        // Pass every row.
175
468k
        int angleSum = 0;
176
15.3M
        for (int y = 0; y < width; y++)
177
14.8M
        {
178
14.8M
            angleSum += angle;
179
14.8M
            int offset = angleSum >> 5;
180
14.8M
            int fraction = angleSum & 31;
181
182
14.8M
            if (fraction) // Interpolate
183
422M
                for (int x = 0; x < width; x++)
184
409M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
1.96M
            else // Copy.
186
65.4M
                for (int x = 0; x < width; x++)
187
63.5M
                    dst[y * dstStride + x] = ref[offset + x];
188
14.8M
        }
189
468k
    }
190
191
    // Flip for horizontal.
192
498k
    if (horMode)
193
242k
    {
194
7.73M
        for (int y = 0; y < width - 1; y++)
195
7.49M
        {
196
127M
            for (int x = y + 1; x < width; x++)
197
119M
            {
198
119M
                pixel tmp              = dst[y * dstStride + x];
199
119M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
119M
                dst[x * dstStride + y] = tmp;
201
119M
            }
202
7.49M
        }
203
242k
    }
204
498k
}
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
}