Coverage Report

Created: 2026-09-02 06:42

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.15M
{
34
1.15M
    const int tuSize2 = tuSize << 1;
35
36
1.15M
    pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2];
37
38
    // filtering top
39
21.5M
    for (int i = 1; i < tuSize2; i++)
40
20.4M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
41
1.15M
    filtered[tuSize2] = topLast;
42
    
43
    // filtering top-left
44
1.15M
    filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2;
45
46
    // filtering left
47
1.15M
    filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2;
48
20.4M
    for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++)
49
19.2M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
50
1.15M
    filtered[tuSize2 + tuSize2] = leftLast;
51
1.15M
}
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
960k
{
34
960k
    const int tuSize2 = tuSize << 1;
35
36
960k
    pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2];
37
38
    // filtering top
39
15.3M
    for (int i = 1; i < tuSize2; i++)
40
14.4M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
41
960k
    filtered[tuSize2] = topLast;
42
    
43
    // filtering top-left
44
960k
    filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2;
45
46
    // filtering left
47
960k
    filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2;
48
14.4M
    for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++)
49
13.4M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
50
960k
    filtered[tuSize2 + tuSize2] = leftLast;
51
960k
}
intrapred.cpp:void (anonymous namespace)::intraFilter<16>(unsigned char const*, unsigned char*)
Line
Count
Source
33
193k
{
34
193k
    const int tuSize2 = tuSize << 1;
35
36
193k
    pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2];
37
38
    // filtering top
39
6.20M
    for (int i = 1; i < tuSize2; i++)
40
6.00M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
41
193k
    filtered[tuSize2] = topLast;
42
    
43
    // filtering top-left
44
193k
    filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2;
45
46
    // filtering left
47
193k
    filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2;
48
6.00M
    for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++)
49
5.81M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
50
193k
    filtered[tuSize2 + tuSize2] = leftLast;
51
193k
}
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.26M
{
55
    // boundary pixels processing
56
2.26M
    dst[0] = (pixel)((above[0] + left[0] + 2 * dst[0] + 2) >> 2);
57
58
12.5M
    for (int x = 1; x < size; x++)
59
10.3M
        dst[x] = (pixel)((above[x] +  3 * dst[x] + 2) >> 2);
60
61
2.26M
    dst += dststride;
62
12.5M
    for (int y = 1; y < size; y++)
63
10.3M
    {
64
10.3M
        *dst = (pixel)((left[y] + 3 * *dst + 2) >> 2);
65
10.3M
        dst += dststride;
66
10.3M
    }
67
2.26M
}
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.52M
{
72
3.52M
    int k, l;
73
74
3.52M
    int dcVal = width;
75
22.7M
    for (int i = 0; i < width; i++)
76
19.2M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
3.52M
    dcVal = dcVal / (width + width);
79
22.7M
    for (k = 0; k < width; k++)
80
168M
        for (l = 0; l < width; l++)
81
149M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
3.52M
    if (bFilter)
84
2.26M
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
3.52M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<4>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
2.70M
{
72
2.70M
    int k, l;
73
74
2.70M
    int dcVal = width;
75
13.5M
    for (int i = 0; i < width; i++)
76
10.8M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
2.70M
    dcVal = dcVal / (width + width);
79
13.5M
    for (k = 0; k < width; k++)
80
54.1M
        for (l = 0; l < width; l++)
81
43.3M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
2.70M
    if (bFilter)
84
1.62M
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
2.70M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<8>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
646k
{
72
646k
    int k, l;
73
74
646k
    int dcVal = width;
75
5.81M
    for (int i = 0; i < width; i++)
76
5.16M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
646k
    dcVal = dcVal / (width + width);
79
5.81M
    for (k = 0; k < width; k++)
80
46.5M
        for (l = 0; l < width; l++)
81
41.3M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
646k
    if (bFilter)
84
515k
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
646k
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<16>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
149k
{
72
149k
    int k, l;
73
74
149k
    int dcVal = width;
75
2.53M
    for (int i = 0; i < width; i++)
76
2.38M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
149k
    dcVal = dcVal / (width + width);
79
2.53M
    for (k = 0; k < width; k++)
80
40.5M
        for (l = 0; l < width; l++)
81
38.1M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
149k
    if (bFilter)
84
122k
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
149k
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<32>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
25.9k
{
72
25.9k
    int k, l;
73
74
25.9k
    int dcVal = width;
75
857k
    for (int i = 0; i < width; i++)
76
831k
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
25.9k
    dcVal = dcVal / (width + width);
79
856k
    for (k = 0; k < width; k++)
80
27.4M
        for (l = 0; l < width; l++)
81
26.5M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
25.9k
    if (bFilter)
84
0
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
25.9k
}
86
87
template<int log2Size>
88
void planar_pred_c(pixel* dst, intptr_t dstStride, const pixel* srcPix, int /*dirMode*/, int /*bFilter*/)
89
6.16M
{
90
6.16M
    const int blkSize = 1 << log2Size;
91
92
6.16M
    const pixel* above = srcPix + 1;
93
6.16M
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
6.16M
    pixel topRight = above[blkSize];
96
6.16M
    pixel bottomLeft = left[blkSize];
97
38.5M
    for (int y = 0; y < blkSize; y++)
98
264M
        for (int x = 0; x < blkSize; x++)
99
231M
            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.16M
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<2>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
4.82M
{
90
4.82M
    const int blkSize = 1 << log2Size;
91
92
4.82M
    const pixel* above = srcPix + 1;
93
4.82M
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
4.82M
    pixel topRight = above[blkSize];
96
4.82M
    pixel bottomLeft = left[blkSize];
97
24.1M
    for (int y = 0; y < blkSize; y++)
98
96.5M
        for (int x = 0; x < blkSize; x++)
99
77.2M
            dst[y * dstStride + x] = (pixel) (((blkSize - 1 - x) * left[y] + (blkSize - 1 -y) * above[x] + (x + 1) * topRight + (y + 1) * bottomLeft + blkSize) >> (log2Size + 1));
100
4.82M
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<3>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
1.09M
{
90
1.09M
    const int blkSize = 1 << log2Size;
91
92
1.09M
    const pixel* above = srcPix + 1;
93
1.09M
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
1.09M
    pixel topRight = above[blkSize];
96
1.09M
    pixel bottomLeft = left[blkSize];
97
9.81M
    for (int y = 0; y < blkSize; y++)
98
78.5M
        for (int x = 0; x < blkSize; x++)
99
69.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
1.09M
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<4>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
218k
{
90
218k
    const int blkSize = 1 << log2Size;
91
92
218k
    const pixel* above = srcPix + 1;
93
218k
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
218k
    pixel topRight = above[blkSize];
96
218k
    pixel bottomLeft = left[blkSize];
97
3.71M
    for (int y = 0; y < blkSize; y++)
98
59.3M
        for (int x = 0; x < blkSize; x++)
99
55.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
218k
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<5>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
28.3k
{
90
28.3k
    const int blkSize = 1 << log2Size;
91
92
28.3k
    const pixel* above = srcPix + 1;
93
28.3k
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
28.3k
    pixel topRight = above[blkSize];
96
28.3k
    pixel bottomLeft = left[blkSize];
97
935k
    for (int y = 0; y < blkSize; y++)
98
29.9M
        for (int x = 0; x < blkSize; x++)
99
29.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
28.3k
}
101
102
template<int width>
103
void intra_pred_ang_c(pixel* dst, intptr_t dstStride, const pixel *srcPix0, int dirMode, int bFilter)
104
51.5M
{
105
51.5M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
51.5M
    int horMode = dirMode < 18;
108
51.5M
    pixel neighbourBuf[129];
109
51.5M
    const pixel *srcPix = srcPix0;
110
111
51.5M
    if (horMode)
112
24.6M
    {
113
24.6M
        neighbourBuf[0] = srcPix[0];
114
299M
        for (int i = 0; i < width << 1; i++)
115
275M
        {
116
275M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
275M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
275M
        }
119
24.6M
        srcPix = neighbourBuf;
120
24.6M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
51.5M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
51.5M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
51.5M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
51.5M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
51.5M
    if (!angle)
132
5.49M
    {
133
34.0M
        for (int y = 0; y < width; y++)
134
231M
            for (int x = 0; x < width; x++)
135
203M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
5.49M
        if (bFilter)
138
2.98M
        {
139
2.98M
            int topLeft = srcPix[0], top = srcPix[1];
140
19.0M
            for (int y = 0; y < width; y++)
141
16.0M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
2.98M
        }
143
5.49M
    }
144
46.0M
    else // Angular prediction.
145
46.0M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
46.0M
        pixel refBuf[64];
148
46.0M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
46.0M
        if (angle < 0)
152
21.7M
        {
153
            // Number of neighbours projected. 
154
21.7M
            int nbProjected = -((width * angle) >> 5) - 1;
155
21.7M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
21.7M
            int invAngle = invAngleTable[- angleOffset - 1];
159
21.7M
            int invAngleSum = 128;
160
67.6M
            for (int i = 0; i < nbProjected; i++)
161
45.9M
            {
162
45.9M
                invAngleSum += invAngle;
163
45.9M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
45.9M
            }
165
166
            // Copy the top-left and top pixels.
167
164M
            for (int i = 0; i < width + 1; i++)
168
143M
                ref_pix[-1 + i] = srcPix[i];
169
21.7M
            ref = ref_pix;
170
21.7M
        }
171
24.3M
        else // Use the top and top-right neighbours.
172
24.3M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
46.0M
        int angleSum = 0;
176
301M
        for (int y = 0; y < width; y++)
177
255M
        {
178
255M
            angleSum += angle;
179
255M
            int offset = angleSum >> 5;
180
255M
            int fraction = angleSum & 31;
181
182
255M
            if (fraction) // Interpolate
183
2.05G
                for (int x = 0; x < width; x++)
184
1.82G
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
30.2M
            else // Copy.
186
282M
                for (int x = 0; x < width; x++)
187
252M
                    dst[y * dstStride + x] = ref[offset + x];
188
255M
        }
189
46.0M
    }
190
191
    // Flip for horizontal.
192
51.5M
    if (horMode)
193
24.7M
    {
194
137M
        for (int y = 0; y < width - 1; y++)
195
112M
        {
196
597M
            for (int x = y + 1; x < width; x++)
197
484M
            {
198
484M
                pixel tmp              = dst[y * dstStride + x];
199
484M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
484M
                dst[x * dstStride + y] = tmp;
201
484M
            }
202
112M
        }
203
24.7M
    }
204
51.5M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<4>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
104
38.8M
{
105
38.8M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
38.8M
    int horMode = dirMode < 18;
108
38.8M
    pixel neighbourBuf[129];
109
38.8M
    const pixel *srcPix = srcPix0;
110
111
38.8M
    if (horMode)
112
18.4M
    {
113
18.4M
        neighbourBuf[0] = srcPix[0];
114
165M
        for (int i = 0; i < width << 1; i++)
115
147M
        {
116
147M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
147M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
147M
        }
119
18.4M
        srcPix = neighbourBuf;
120
18.4M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
38.8M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
38.8M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
38.8M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
38.8M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
38.8M
    if (!angle)
132
4.39M
    {
133
21.9M
        for (int y = 0; y < width; y++)
134
87.7M
            for (int x = 0; x < width; x++)
135
70.2M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
4.39M
        if (bFilter)
138
2.22M
        {
139
2.22M
            int topLeft = srcPix[0], top = srcPix[1];
140
11.1M
            for (int y = 0; y < width; y++)
141
8.90M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
2.22M
        }
143
4.39M
    }
144
34.4M
    else // Angular prediction.
145
34.4M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
34.4M
        pixel refBuf[64];
148
34.4M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
34.4M
        if (angle < 0)
152
16.2M
        {
153
            // Number of neighbours projected. 
154
16.2M
            int nbProjected = -((width * angle) >> 5) - 1;
155
16.2M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
16.2M
            int invAngle = invAngleTable[- angleOffset - 1];
159
16.2M
            int invAngleSum = 128;
160
39.0M
            for (int i = 0; i < nbProjected; i++)
161
22.7M
            {
162
22.7M
                invAngleSum += invAngle;
163
22.7M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
22.7M
            }
165
166
            // Copy the top-left and top pixels.
167
97.5M
            for (int i = 0; i < width + 1; i++)
168
81.2M
                ref_pix[-1 + i] = srcPix[i];
169
16.2M
            ref = ref_pix;
170
16.2M
        }
171
18.2M
        else // Use the top and top-right neighbours.
172
18.2M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
34.4M
        int angleSum = 0;
176
171M
        for (int y = 0; y < width; y++)
177
136M
        {
178
136M
            angleSum += angle;
179
136M
            int offset = angleSum >> 5;
180
136M
            int fraction = angleSum & 31;
181
182
136M
            if (fraction) // Interpolate
183
598M
                for (int x = 0; x < width; x++)
184
478M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
16.9M
            else // Copy.
186
86.3M
                for (int x = 0; x < width; x++)
187
69.3M
                    dst[y * dstStride + x] = ref[offset + x];
188
136M
        }
189
34.4M
    }
190
191
    // Flip for horizontal.
192
38.8M
    if (horMode)
193
18.4M
    {
194
73.7M
        for (int y = 0; y < width - 1; y++)
195
55.2M
        {
196
165M
            for (int x = y + 1; x < width; x++)
197
110M
            {
198
110M
                pixel tmp              = dst[y * dstStride + x];
199
110M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
110M
                dst[x * dstStride + y] = tmp;
201
110M
            }
202
55.2M
        }
203
18.4M
    }
204
38.8M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<8>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
104
10.0M
{
105
10.0M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
10.0M
    int horMode = dirMode < 18;
108
10.0M
    pixel neighbourBuf[129];
109
10.0M
    const pixel *srcPix = srcPix0;
110
111
10.0M
    if (horMode)
112
4.96M
    {
113
4.96M
        neighbourBuf[0] = srcPix[0];
114
84.4M
        for (int i = 0; i < width << 1; i++)
115
79.4M
        {
116
79.4M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
79.4M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
79.4M
        }
119
4.96M
        srcPix = neighbourBuf;
120
4.96M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
10.0M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
10.0M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
10.0M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
10.0M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
10.0M
    if (!angle)
132
890k
    {
133
8.01M
        for (int y = 0; y < width; y++)
134
64.0M
            for (int x = 0; x < width; x++)
135
56.9M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
890k
        if (bFilter)
138
628k
        {
139
628k
            int topLeft = srcPix[0], top = srcPix[1];
140
5.65M
            for (int y = 0; y < width; y++)
141
5.02M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
628k
        }
143
890k
    }
144
9.16M
    else // Angular prediction.
145
9.16M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
9.16M
        pixel refBuf[64];
148
9.16M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
9.16M
        if (angle < 0)
152
4.28M
        {
153
            // Number of neighbours projected. 
154
4.28M
            int nbProjected = -((width * angle) >> 5) - 1;
155
4.28M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
4.28M
            int invAngle = invAngleTable[- angleOffset - 1];
159
4.28M
            int invAngleSum = 128;
160
18.2M
            for (int i = 0; i < nbProjected; i++)
161
13.9M
            {
162
13.9M
                invAngleSum += invAngle;
163
13.9M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
13.9M
            }
165
166
            // Copy the top-left and top pixels.
167
42.8M
            for (int i = 0; i < width + 1; i++)
168
38.5M
                ref_pix[-1 + i] = srcPix[i];
169
4.28M
            ref = ref_pix;
170
4.28M
        }
171
4.88M
        else // Use the top and top-right neighbours.
172
4.88M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
9.16M
        int angleSum = 0;
176
82.2M
        for (int y = 0; y < width; y++)
177
73.0M
        {
178
73.0M
            angleSum += angle;
179
73.0M
            int offset = angleSum >> 5;
180
73.0M
            int fraction = angleSum & 31;
181
182
73.0M
            if (fraction) // Interpolate
183
589M
                for (int x = 0; x < width; x++)
184
523M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
7.51M
            else // Copy.
186
68.0M
                for (int x = 0; x < width; x++)
187
60.5M
                    dst[y * dstStride + x] = ref[offset + x];
188
73.0M
        }
189
9.16M
    }
190
191
    // Flip for horizontal.
192
10.0M
    if (horMode)
193
4.97M
    {
194
39.6M
        for (int y = 0; y < width - 1; y++)
195
34.7M
        {
196
173M
            for (int x = y + 1; x < width; x++)
197
138M
            {
198
138M
                pixel tmp              = dst[y * dstStride + x];
199
138M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
138M
                dst[x * dstStride + y] = tmp;
201
138M
            }
202
34.7M
        }
203
4.97M
    }
204
10.0M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<16>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
104
2.23M
{
105
2.23M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
2.23M
    int horMode = dirMode < 18;
108
2.23M
    pixel neighbourBuf[129];
109
2.23M
    const pixel *srcPix = srcPix0;
110
111
2.23M
    if (horMode)
112
1.07M
    {
113
1.07M
        neighbourBuf[0] = srcPix[0];
114
35.4M
        for (int i = 0; i < width << 1; i++)
115
34.3M
        {
116
34.3M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
34.3M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
34.3M
        }
119
1.07M
        srcPix = neighbourBuf;
120
1.07M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
2.23M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
2.23M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
2.23M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
2.23M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
2.23M
    if (!angle)
132
187k
    {
133
3.18M
        for (int y = 0; y < width; y++)
134
50.9M
            for (int x = 0; x < width; x++)
135
47.9M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
187k
        if (bFilter)
138
133k
        {
139
133k
            int topLeft = srcPix[0], top = srcPix[1];
140
2.27M
            for (int y = 0; y < width; y++)
141
2.14M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
133k
        }
143
187k
    }
144
2.04M
    else // Angular prediction.
145
2.04M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
2.04M
        pixel refBuf[64];
148
2.04M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
2.04M
        if (angle < 0)
152
978k
        {
153
            // Number of neighbours projected. 
154
978k
            int nbProjected = -((width * angle) >> 5) - 1;
155
978k
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
978k
            int invAngle = invAngleTable[- angleOffset - 1];
159
978k
            int invAngleSum = 128;
160
7.44M
            for (int i = 0; i < nbProjected; i++)
161
6.46M
            {
162
6.46M
                invAngleSum += invAngle;
163
6.46M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
6.46M
            }
165
166
            // Copy the top-left and top pixels.
167
17.6M
            for (int i = 0; i < width + 1; i++)
168
16.6M
                ref_pix[-1 + i] = srcPix[i];
169
978k
            ref = ref_pix;
170
978k
        }
171
1.06M
        else // Use the top and top-right neighbours.
172
1.06M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
2.04M
        int angleSum = 0;
176
34.6M
        for (int y = 0; y < width; y++)
177
32.6M
        {
178
32.6M
            angleSum += angle;
179
32.6M
            int offset = angleSum >> 5;
180
32.6M
            int fraction = angleSum & 31;
181
182
32.6M
            if (fraction) // Interpolate
183
485M
                for (int x = 0; x < width; x++)
184
456M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
4.02M
            else // Copy.
186
69.3M
                for (int x = 0; x < width; x++)
187
65.3M
                    dst[y * dstStride + x] = ref[offset + x];
188
32.6M
        }
189
2.04M
    }
190
191
    // Flip for horizontal.
192
2.23M
    if (horMode)
193
1.07M
    {
194
17.1M
        for (int y = 0; y < width - 1; y++)
195
16.0M
        {
196
144M
            for (int x = y + 1; x < width; x++)
197
128M
            {
198
128M
                pixel tmp              = dst[y * dstStride + x];
199
128M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
128M
                dst[x * dstStride + y] = tmp;
201
128M
            }
202
16.0M
        }
203
1.07M
    }
204
2.23M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<32>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
104
445k
{
105
445k
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
445k
    int horMode = dirMode < 18;
108
445k
    pixel neighbourBuf[129];
109
445k
    const pixel *srcPix = srcPix0;
110
111
445k
    if (horMode)
112
216k
    {
113
216k
        neighbourBuf[0] = srcPix[0];
114
14.0M
        for (int i = 0; i < width << 1; i++)
115
13.8M
        {
116
13.8M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
13.8M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
13.8M
        }
119
216k
        srcPix = neighbourBuf;
120
216k
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
445k
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
445k
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
445k
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
445k
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
445k
    if (!angle)
132
27.3k
    {
133
901k
        for (int y = 0; y < width; y++)
134
28.8M
            for (int x = 0; x < width; x++)
135
27.9M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
27.3k
        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
27.3k
    }
144
418k
    else // Angular prediction.
145
418k
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
418k
        pixel refBuf[64];
148
418k
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
418k
        if (angle < 0)
152
202k
        {
153
            // Number of neighbours projected. 
154
202k
            int nbProjected = -((width * angle) >> 5) - 1;
155
202k
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
202k
            int invAngle = invAngleTable[- angleOffset - 1];
159
202k
            int invAngleSum = 128;
160
2.93M
            for (int i = 0; i < nbProjected; i++)
161
2.73M
            {
162
2.73M
                invAngleSum += invAngle;
163
2.73M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
2.73M
            }
165
166
            // Copy the top-left and top pixels.
167
6.86M
            for (int i = 0; i < width + 1; i++)
168
6.66M
                ref_pix[-1 + i] = srcPix[i];
169
202k
            ref = ref_pix;
170
202k
        }
171
216k
        else // Use the top and top-right neighbours.
172
216k
            ref = srcPix + 1;
173
174
        // Pass every row.
175
418k
        int angleSum = 0;
176
13.6M
        for (int y = 0; y < width; y++)
177
13.2M
        {
178
13.2M
            angleSum += angle;
179
13.2M
            int offset = angleSum >> 5;
180
13.2M
            int fraction = angleSum & 31;
181
182
13.2M
            if (fraction) // Interpolate
183
378M
                for (int x = 0; x < width; x++)
184
366M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
1.73M
            else // Copy.
186
58.6M
                for (int x = 0; x < width; x++)
187
56.9M
                    dst[y * dstStride + x] = ref[offset + x];
188
13.2M
        }
189
418k
    }
190
191
    // Flip for horizontal.
192
445k
    if (horMode)
193
216k
    {
194
6.90M
        for (int y = 0; y < width - 1; y++)
195
6.69M
        {
196
113M
            for (int x = y + 1; x < width; x++)
197
106M
            {
198
106M
                pixel tmp              = dst[y * dstStride + x];
199
106M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
106M
                dst[x * dstStride + y] = tmp;
201
106M
            }
202
6.69M
        }
203
216k
    }
204
445k
}
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
}