Coverage Report

Created: 2026-12-01 06:52

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.48M
{
34
1.48M
    const int tuSize2 = tuSize << 1;
35
36
1.48M
    pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2];
37
38
    // filtering top
39
27.7M
    for (int i = 1; i < tuSize2; i++)
40
26.2M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
41
1.48M
    filtered[tuSize2] = topLast;
42
    
43
    // filtering top-left
44
1.48M
    filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2;
45
46
    // filtering left
47
1.48M
    filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2;
48
26.2M
    for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++)
49
24.7M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
50
1.48M
    filtered[tuSize2 + tuSize2] = leftLast;
51
1.48M
}
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.23M
{
34
1.23M
    const int tuSize2 = tuSize << 1;
35
36
1.23M
    pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2];
37
38
    // filtering top
39
19.7M
    for (int i = 1; i < tuSize2; i++)
40
18.5M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
41
1.23M
    filtered[tuSize2] = topLast;
42
    
43
    // filtering top-left
44
1.23M
    filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2;
45
46
    // filtering left
47
1.23M
    filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2;
48
18.5M
    for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++)
49
17.2M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
50
1.23M
    filtered[tuSize2 + tuSize2] = leftLast;
51
1.23M
}
intrapred.cpp:void (anonymous namespace)::intraFilter<16>(unsigned char const*, unsigned char*)
Line
Count
Source
33
249k
{
34
249k
    const int tuSize2 = tuSize << 1;
35
36
249k
    pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2];
37
38
    // filtering top
39
7.97M
    for (int i = 1; i < tuSize2; i++)
40
7.72M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
41
249k
    filtered[tuSize2] = topLast;
42
    
43
    // filtering top-left
44
249k
    filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2;
45
46
    // filtering left
47
249k
    filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2;
48
7.72M
    for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++)
49
7.47M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
50
249k
    filtered[tuSize2 + tuSize2] = leftLast;
51
249k
}
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.89M
{
55
    // boundary pixels processing
56
2.89M
    dst[0] = (pixel)((above[0] + left[0] + 2 * dst[0] + 2) >> 2);
57
58
16.1M
    for (int x = 1; x < size; x++)
59
13.2M
        dst[x] = (pixel)((above[x] +  3 * dst[x] + 2) >> 2);
60
61
2.89M
    dst += dststride;
62
16.1M
    for (int y = 1; y < size; y++)
63
13.2M
    {
64
13.2M
        *dst = (pixel)((left[y] + 3 * *dst + 2) >> 2);
65
13.2M
        dst += dststride;
66
13.2M
    }
67
2.89M
}
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.52M
{
72
4.52M
    int k, l;
73
74
4.52M
    int dcVal = width;
75
29.1M
    for (int i = 0; i < width; i++)
76
24.6M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
4.52M
    dcVal = dcVal / (width + width);
79
29.1M
    for (k = 0; k < width; k++)
80
217M
        for (l = 0; l < width; l++)
81
192M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
4.52M
    if (bFilter)
84
2.89M
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
4.52M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<4>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
3.46M
{
72
3.46M
    int k, l;
73
74
3.46M
    int dcVal = width;
75
17.3M
    for (int i = 0; i < width; i++)
76
13.8M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
3.46M
    dcVal = dcVal / (width + width);
79
17.3M
    for (k = 0; k < width; k++)
80
69.3M
        for (l = 0; l < width; l++)
81
55.4M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
3.46M
    if (bFilter)
84
2.08M
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
3.46M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<8>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
826k
{
72
826k
    int k, l;
73
74
826k
    int dcVal = width;
75
7.44M
    for (int i = 0; i < width; i++)
76
6.61M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
826k
    dcVal = dcVal / (width + width);
79
7.43M
    for (k = 0; k < width; k++)
80
59.5M
        for (l = 0; l < width; l++)
81
52.8M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
826k
    if (bFilter)
84
659k
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
826k
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<16>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
192k
{
72
192k
    int k, l;
73
74
192k
    int dcVal = width;
75
3.26M
    for (int i = 0; i < width; i++)
76
3.07M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
192k
    dcVal = dcVal / (width + width);
79
3.26M
    for (k = 0; k < width; k++)
80
52.2M
        for (l = 0; l < width; l++)
81
49.1M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
192k
    if (bFilter)
84
157k
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
192k
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<32>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
34.0k
{
72
34.0k
    int k, l;
73
74
34.0k
    int dcVal = width;
75
1.12M
    for (int i = 0; i < width; i++)
76
1.08M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
34.0k
    dcVal = dcVal / (width + width);
79
1.12M
    for (k = 0; k < width; k++)
80
35.9M
        for (l = 0; l < width; l++)
81
34.8M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
34.0k
    if (bFilter)
84
0
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
34.0k
}
86
87
template<int log2Size>
88
void planar_pred_c(pixel* dst, intptr_t dstStride, const pixel* srcPix, int /*dirMode*/, int /*bFilter*/)
89
7.93M
{
90
7.93M
    const int blkSize = 1 << log2Size;
91
92
7.93M
    const pixel* above = srcPix + 1;
93
7.93M
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
7.93M
    pixel topRight = above[blkSize];
96
7.93M
    pixel bottomLeft = left[blkSize];
97
49.6M
    for (int y = 0; y < blkSize; y++)
98
340M
        for (int x = 0; x < blkSize; x++)
99
298M
            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
7.93M
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<2>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
6.21M
{
90
6.21M
    const int blkSize = 1 << log2Size;
91
92
6.21M
    const pixel* above = srcPix + 1;
93
6.21M
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
6.21M
    pixel topRight = above[blkSize];
96
6.21M
    pixel bottomLeft = left[blkSize];
97
31.0M
    for (int y = 0; y < blkSize; y++)
98
124M
        for (int x = 0; x < blkSize; x++)
99
99.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
6.21M
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<3>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
1.40M
{
90
1.40M
    const int blkSize = 1 << log2Size;
91
92
1.40M
    const pixel* above = srcPix + 1;
93
1.40M
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
1.40M
    pixel topRight = above[blkSize];
96
1.40M
    pixel bottomLeft = left[blkSize];
97
12.6M
    for (int y = 0; y < blkSize; y++)
98
100M
        for (int x = 0; x < blkSize; x++)
99
89.5M
            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.40M
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<4>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
281k
{
90
281k
    const int blkSize = 1 << log2Size;
91
92
281k
    const pixel* above = srcPix + 1;
93
281k
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
281k
    pixel topRight = above[blkSize];
96
281k
    pixel bottomLeft = left[blkSize];
97
4.78M
    for (int y = 0; y < blkSize; y++)
98
76.4M
        for (int x = 0; x < blkSize; x++)
99
71.9M
            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
281k
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<5>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
37.1k
{
90
37.1k
    const int blkSize = 1 << log2Size;
91
92
37.1k
    const pixel* above = srcPix + 1;
93
37.1k
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
37.1k
    pixel topRight = above[blkSize];
96
37.1k
    pixel bottomLeft = left[blkSize];
97
1.22M
    for (int y = 0; y < blkSize; y++)
98
39.1M
        for (int x = 0; x < blkSize; x++)
99
38.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
37.1k
}
101
102
template<int width>
103
void intra_pred_ang_c(pixel* dst, intptr_t dstStride, const pixel *srcPix0, int dirMode, int bFilter)
104
66.2M
{
105
66.2M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
66.2M
    int horMode = dirMode < 18;
108
66.2M
    pixel neighbourBuf[129];
109
66.2M
    const pixel *srcPix = srcPix0;
110
111
66.2M
    if (horMode)
112
31.6M
    {
113
31.6M
        neighbourBuf[0] = srcPix[0];
114
384M
        for (int i = 0; i < width << 1; i++)
115
352M
        {
116
352M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
352M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
352M
        }
119
31.6M
        srcPix = neighbourBuf;
120
31.6M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
66.2M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
66.2M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
66.2M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
66.2M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
66.2M
    if (!angle)
132
7.01M
    {
133
43.4M
        for (int y = 0; y < width; y++)
134
296M
            for (int x = 0; x < width; x++)
135
260M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
7.01M
        if (bFilter)
138
3.79M
        {
139
3.79M
            int topLeft = srcPix[0], top = srcPix[1];
140
24.2M
            for (int y = 0; y < width; y++)
141
20.4M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
3.79M
        }
143
7.01M
    }
144
59.2M
    else // Angular prediction.
145
59.2M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
59.2M
        pixel refBuf[64];
148
59.2M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
59.2M
        if (angle < 0)
152
27.8M
        {
153
            // Number of neighbours projected. 
154
27.8M
            int nbProjected = -((width * angle) >> 5) - 1;
155
27.8M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
27.8M
            int invAngle = invAngleTable[- angleOffset - 1];
159
27.8M
            int invAngleSum = 128;
160
86.6M
            for (int i = 0; i < nbProjected; i++)
161
58.8M
            {
162
58.8M
                invAngleSum += invAngle;
163
58.8M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
58.8M
            }
165
166
            // Copy the top-left and top pixels.
167
211M
            for (int i = 0; i < width + 1; i++)
168
183M
                ref_pix[-1 + i] = srcPix[i];
169
27.8M
            ref = ref_pix;
170
27.8M
        }
171
31.4M
        else // Use the top and top-right neighbours.
172
31.4M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
59.2M
        int angleSum = 0;
176
389M
        for (int y = 0; y < width; y++)
177
329M
        {
178
329M
            angleSum += angle;
179
329M
            int offset = angleSum >> 5;
180
329M
            int fraction = angleSum & 31;
181
182
329M
            if (fraction) // Interpolate
183
2.64G
                for (int x = 0; x < width; x++)
184
2.35G
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
39.5M
            else // Copy.
186
364M
                for (int x = 0; x < width; x++)
187
324M
                    dst[y * dstStride + x] = ref[offset + x];
188
329M
        }
189
59.2M
    }
190
191
    // Flip for horizontal.
192
66.2M
    if (horMode)
193
31.6M
    {
194
176M
        for (int y = 0; y < width - 1; y++)
195
144M
        {
196
768M
            for (int x = y + 1; x < width; x++)
197
623M
            {
198
623M
                pixel tmp              = dst[y * dstStride + x];
199
623M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
623M
                dst[x * dstStride + y] = tmp;
201
623M
            }
202
144M
        }
203
31.6M
    }
204
66.2M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<4>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
104
49.9M
{
105
49.9M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
49.9M
    int horMode = dirMode < 18;
108
49.9M
    pixel neighbourBuf[129];
109
49.9M
    const pixel *srcPix = srcPix0;
110
111
49.9M
    if (horMode)
112
23.5M
    {
113
23.5M
        neighbourBuf[0] = srcPix[0];
114
212M
        for (int i = 0; i < width << 1; i++)
115
188M
        {
116
188M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
188M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
188M
        }
119
23.5M
        srcPix = neighbourBuf;
120
23.5M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
49.9M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
49.9M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
49.9M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
49.9M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
49.9M
    if (!angle)
132
5.60M
    {
133
28.0M
        for (int y = 0; y < width; y++)
134
111M
            for (int x = 0; x < width; x++)
135
89.5M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
5.60M
        if (bFilter)
138
2.82M
        {
139
2.82M
            int topLeft = srcPix[0], top = srcPix[1];
140
14.1M
            for (int y = 0; y < width; y++)
141
11.3M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
2.82M
        }
143
5.60M
    }
144
44.3M
    else // Angular prediction.
145
44.3M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
44.3M
        pixel refBuf[64];
148
44.3M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
44.3M
        if (angle < 0)
152
20.8M
        {
153
            // Number of neighbours projected. 
154
20.8M
            int nbProjected = -((width * angle) >> 5) - 1;
155
20.8M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
20.8M
            int invAngle = invAngleTable[- angleOffset - 1];
159
20.8M
            int invAngleSum = 128;
160
49.9M
            for (int i = 0; i < nbProjected; i++)
161
29.1M
            {
162
29.1M
                invAngleSum += invAngle;
163
29.1M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
29.1M
            }
165
166
            // Copy the top-left and top pixels.
167
124M
            for (int i = 0; i < width + 1; i++)
168
104M
                ref_pix[-1 + i] = srcPix[i];
169
20.8M
            ref = ref_pix;
170
20.8M
        }
171
23.5M
        else // Use the top and top-right neighbours.
172
23.5M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
44.3M
        int angleSum = 0;
176
221M
        for (int y = 0; y < width; y++)
177
177M
        {
178
177M
            angleSum += angle;
179
177M
            int offset = angleSum >> 5;
180
177M
            int fraction = angleSum & 31;
181
182
177M
            if (fraction) // Interpolate
183
773M
                for (int x = 0; x < width; x++)
184
618M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
22.3M
            else // Copy.
186
111M
                for (int x = 0; x < width; x++)
187
88.8M
                    dst[y * dstStride + x] = ref[offset + x];
188
177M
        }
189
44.3M
    }
190
191
    // Flip for horizontal.
192
49.9M
    if (horMode)
193
23.6M
    {
194
94.2M
        for (int y = 0; y < width - 1; y++)
195
70.6M
        {
196
212M
            for (int x = y + 1; x < width; x++)
197
141M
            {
198
141M
                pixel tmp              = dst[y * dstStride + x];
199
141M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
141M
                dst[x * dstStride + y] = tmp;
201
141M
            }
202
70.6M
        }
203
23.6M
    }
204
49.9M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<8>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
104
12.8M
{
105
12.8M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
12.8M
    int horMode = dirMode < 18;
108
12.8M
    pixel neighbourBuf[129];
109
12.8M
    const pixel *srcPix = srcPix0;
110
111
12.8M
    if (horMode)
112
6.35M
    {
113
6.35M
        neighbourBuf[0] = srcPix[0];
114
108M
        for (int i = 0; i < width << 1; i++)
115
101M
        {
116
101M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
101M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
101M
        }
119
6.35M
        srcPix = neighbourBuf;
120
6.35M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
12.8M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
12.8M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
12.8M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
12.8M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
12.8M
    if (!angle)
132
1.13M
    {
133
10.1M
        for (int y = 0; y < width; y++)
134
81.5M
            for (int x = 0; x < width; x++)
135
72.4M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
1.13M
        if (bFilter)
138
798k
        {
139
798k
            int topLeft = srcPix[0], top = srcPix[1];
140
7.18M
            for (int y = 0; y < width; y++)
141
6.38M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
798k
        }
143
1.13M
    }
144
11.7M
    else // Angular prediction.
145
11.7M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
11.7M
        pixel refBuf[64];
148
11.7M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
11.7M
        if (angle < 0)
152
5.47M
        {
153
            // Number of neighbours projected. 
154
5.47M
            int nbProjected = -((width * angle) >> 5) - 1;
155
5.47M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
5.47M
            int invAngle = invAngleTable[- angleOffset - 1];
159
5.47M
            int invAngleSum = 128;
160
23.3M
            for (int i = 0; i < nbProjected; i++)
161
17.8M
            {
162
17.8M
                invAngleSum += invAngle;
163
17.8M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
17.8M
            }
165
166
            // Copy the top-left and top pixels.
167
54.7M
            for (int i = 0; i < width + 1; i++)
168
49.3M
                ref_pix[-1 + i] = srcPix[i];
169
5.47M
            ref = ref_pix;
170
5.47M
        }
171
6.26M
        else // Use the top and top-right neighbours.
172
6.26M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
11.7M
        int angleSum = 0;
176
105M
        for (int y = 0; y < width; y++)
177
93.6M
        {
178
93.6M
            angleSum += angle;
179
93.6M
            int offset = angleSum >> 5;
180
93.6M
            int fraction = angleSum & 31;
181
182
93.6M
            if (fraction) // Interpolate
183
753M
                for (int x = 0; x < width; x++)
184
670M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
9.70M
            else // Copy.
186
87.0M
                for (int x = 0; x < width; x++)
187
77.3M
                    dst[y * dstStride + x] = ref[offset + x];
188
93.6M
        }
189
11.7M
    }
190
191
    // Flip for horizontal.
192
12.8M
    if (horMode)
193
6.35M
    {
194
50.8M
        for (int y = 0; y < width - 1; y++)
195
44.4M
        {
196
222M
            for (int x = y + 1; x < width; x++)
197
177M
            {
198
177M
                pixel tmp              = dst[y * dstStride + x];
199
177M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
177M
                dst[x * dstStride + y] = tmp;
201
177M
            }
202
44.4M
        }
203
6.35M
    }
204
12.8M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<16>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
104
2.86M
{
105
2.86M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
2.86M
    int horMode = dirMode < 18;
108
2.86M
    pixel neighbourBuf[129];
109
2.86M
    const pixel *srcPix = srcPix0;
110
111
2.86M
    if (horMode)
112
1.37M
    {
113
1.37M
        neighbourBuf[0] = srcPix[0];
114
45.2M
        for (int i = 0; i < width << 1; i++)
115
43.9M
        {
116
43.9M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
43.9M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
43.9M
        }
119
1.37M
        srcPix = neighbourBuf;
120
1.37M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
2.86M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
2.86M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
2.86M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
2.86M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
2.86M
    if (!angle)
132
240k
    {
133
4.07M
        for (int y = 0; y < width; y++)
134
65.2M
            for (int x = 0; x < width; x++)
135
61.4M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
240k
        if (bFilter)
138
169k
        {
139
169k
            int topLeft = srcPix[0], top = srcPix[1];
140
2.88M
            for (int y = 0; y < width; y++)
141
2.71M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
169k
        }
143
240k
    }
144
2.62M
    else // Angular prediction.
145
2.62M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
2.62M
        pixel refBuf[64];
148
2.62M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
2.62M
        if (angle < 0)
152
1.25M
        {
153
            // Number of neighbours projected. 
154
1.25M
            int nbProjected = -((width * angle) >> 5) - 1;
155
1.25M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
1.25M
            int invAngle = invAngleTable[- angleOffset - 1];
159
1.25M
            int invAngleSum = 128;
160
9.50M
            for (int i = 0; i < nbProjected; i++)
161
8.25M
            {
162
8.25M
                invAngleSum += invAngle;
163
8.25M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
8.25M
            }
165
166
            // Copy the top-left and top pixels.
167
22.5M
            for (int i = 0; i < width + 1; i++)
168
21.2M
                ref_pix[-1 + i] = srcPix[i];
169
1.25M
            ref = ref_pix;
170
1.25M
        }
171
1.37M
        else // Use the top and top-right neighbours.
172
1.37M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
2.62M
        int angleSum = 0;
176
44.3M
        for (int y = 0; y < width; y++)
177
41.7M
        {
178
41.7M
            angleSum += angle;
179
41.7M
            int offset = angleSum >> 5;
180
41.7M
            int fraction = angleSum & 31;
181
182
41.7M
            if (fraction) // Interpolate
183
620M
                for (int x = 0; x < width; x++)
184
583M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
5.21M
            else // Copy.
186
88.8M
                for (int x = 0; x < width; x++)
187
83.6M
                    dst[y * dstStride + x] = ref[offset + x];
188
41.7M
        }
189
2.62M
    }
190
191
    // Flip for horizontal.
192
2.86M
    if (horMode)
193
1.37M
    {
194
21.9M
        for (int y = 0; y < width - 1; y++)
195
20.5M
        {
196
184M
            for (int x = y + 1; x < width; x++)
197
164M
            {
198
164M
                pixel tmp              = dst[y * dstStride + x];
199
164M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
164M
                dst[x * dstStride + y] = tmp;
201
164M
            }
202
20.5M
        }
203
1.37M
    }
204
2.86M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<32>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
104
585k
{
105
585k
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
585k
    int horMode = dirMode < 18;
108
585k
    pixel neighbourBuf[129];
109
585k
    const pixel *srcPix = srcPix0;
110
111
585k
    if (horMode)
112
284k
    {
113
284k
        neighbourBuf[0] = srcPix[0];
114
18.4M
        for (int i = 0; i < width << 1; i++)
115
18.1M
        {
116
18.1M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
18.1M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
18.1M
        }
119
284k
        srcPix = neighbourBuf;
120
284k
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
585k
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
585k
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
585k
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
585k
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
585k
    if (!angle)
132
35.8k
    {
133
1.18M
        for (int y = 0; y < width; y++)
134
37.7M
            for (int x = 0; x < width; x++)
135
36.6M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
35.8k
        if (bFilter)
138
0
        {
139
0
            int topLeft = srcPix[0], top = srcPix[1];
140
0
            for (int y = 0; y < width; y++)
141
0
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
0
        }
143
35.8k
    }
144
549k
    else // Angular prediction.
145
549k
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
549k
        pixel refBuf[64];
148
549k
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
549k
        if (angle < 0)
152
264k
        {
153
            // Number of neighbours projected. 
154
264k
            int nbProjected = -((width * angle) >> 5) - 1;
155
264k
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
264k
            int invAngle = invAngleTable[- angleOffset - 1];
159
264k
            int invAngleSum = 128;
160
3.84M
            for (int i = 0; i < nbProjected; i++)
161
3.58M
            {
162
3.58M
                invAngleSum += invAngle;
163
3.58M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
3.58M
            }
165
166
            // Copy the top-left and top pixels.
167
9.00M
            for (int i = 0; i < width + 1; i++)
168
8.74M
                ref_pix[-1 + i] = srcPix[i];
169
264k
            ref = ref_pix;
170
264k
        }
171
284k
        else // Use the top and top-right neighbours.
172
284k
            ref = srcPix + 1;
173
174
        // Pass every row.
175
549k
        int angleSum = 0;
176
18.0M
        for (int y = 0; y < width; y++)
177
17.4M
        {
178
17.4M
            angleSum += angle;
179
17.4M
            int offset = angleSum >> 5;
180
17.4M
            int fraction = angleSum & 31;
181
182
17.4M
            if (fraction) // Interpolate
183
497M
                for (int x = 0; x < width; x++)
184
481M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
2.30M
            else // Copy.
186
76.8M
                for (int x = 0; x < width; x++)
187
74.5M
                    dst[y * dstStride + x] = ref[offset + x];
188
17.4M
        }
189
549k
    }
190
191
    // Flip for horizontal.
192
585k
    if (horMode)
193
284k
    {
194
9.07M
        for (int y = 0; y < width - 1; y++)
195
8.79M
        {
196
149M
            for (int x = y + 1; x < width; x++)
197
140M
            {
198
140M
                pixel tmp              = dst[y * dstStride + x];
199
140M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
140M
                dst[x * dstStride + y] = tmp;
201
140M
            }
202
8.79M
        }
203
284k
    }
204
585k
}
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
}