Coverage Report

Created: 2026-08-13 07:22

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.36M
{
34
1.36M
    const int tuSize2 = tuSize << 1;
35
36
1.36M
    pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2];
37
38
    // filtering top
39
25.5M
    for (int i = 1; i < tuSize2; i++)
40
24.1M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
41
1.36M
    filtered[tuSize2] = topLast;
42
    
43
    // filtering top-left
44
1.36M
    filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2;
45
46
    // filtering left
47
1.36M
    filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2;
48
24.1M
    for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++)
49
22.7M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
50
1.36M
    filtered[tuSize2 + tuSize2] = leftLast;
51
1.36M
}
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.13M
{
34
1.13M
    const int tuSize2 = tuSize << 1;
35
36
1.13M
    pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2];
37
38
    // filtering top
39
18.1M
    for (int i = 1; i < tuSize2; i++)
40
17.0M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
41
1.13M
    filtered[tuSize2] = topLast;
42
    
43
    // filtering top-left
44
1.13M
    filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2;
45
46
    // filtering left
47
1.13M
    filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2;
48
17.0M
    for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++)
49
15.9M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
50
1.13M
    filtered[tuSize2 + tuSize2] = leftLast;
51
1.13M
}
intrapred.cpp:void (anonymous namespace)::intraFilter<16>(unsigned char const*, unsigned char*)
Line
Count
Source
33
228k
{
34
228k
    const int tuSize2 = tuSize << 1;
35
36
228k
    pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2];
37
38
    // filtering top
39
7.32M
    for (int i = 1; i < tuSize2; i++)
40
7.09M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
41
228k
    filtered[tuSize2] = topLast;
42
    
43
    // filtering top-left
44
228k
    filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2;
45
46
    // filtering left
47
228k
    filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2;
48
7.09M
    for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++)
49
6.86M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
50
228k
    filtered[tuSize2 + tuSize2] = leftLast;
51
228k
}
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.67M
{
55
    // boundary pixels processing
56
2.67M
    dst[0] = (pixel)((above[0] + left[0] + 2 * dst[0] + 2) >> 2);
57
58
14.9M
    for (int x = 1; x < size; x++)
59
12.2M
        dst[x] = (pixel)((above[x] +  3 * dst[x] + 2) >> 2);
60
61
2.67M
    dst += dststride;
62
14.9M
    for (int y = 1; y < size; y++)
63
12.2M
    {
64
12.2M
        *dst = (pixel)((left[y] + 3 * *dst + 2) >> 2);
65
12.2M
        dst += dststride;
66
12.2M
    }
67
2.67M
}
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.17M
{
72
4.17M
    int k, l;
73
74
4.17M
    int dcVal = width;
75
26.9M
    for (int i = 0; i < width; i++)
76
22.7M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
4.17M
    dcVal = dcVal / (width + width);
79
26.9M
    for (k = 0; k < width; k++)
80
200M
        for (l = 0; l < width; l++)
81
177M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
4.17M
    if (bFilter)
84
2.67M
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
4.17M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<4>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
3.20M
{
72
3.20M
    int k, l;
73
74
3.20M
    int dcVal = width;
75
16.0M
    for (int i = 0; i < width; i++)
76
12.8M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
3.20M
    dcVal = dcVal / (width + width);
79
16.0M
    for (k = 0; k < width; k++)
80
64.0M
        for (l = 0; l < width; l++)
81
51.2M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
3.20M
    if (bFilter)
84
1.92M
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
3.20M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<8>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
764k
{
72
764k
    int k, l;
73
74
764k
    int dcVal = width;
75
6.88M
    for (int i = 0; i < width; i++)
76
6.11M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
764k
    dcVal = dcVal / (width + width);
79
6.88M
    for (k = 0; k < width; k++)
80
55.0M
        for (l = 0; l < width; l++)
81
48.9M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
764k
    if (bFilter)
84
609k
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
764k
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<16>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
178k
{
72
178k
    int k, l;
73
74
178k
    int dcVal = width;
75
3.02M
    for (int i = 0; i < width; i++)
76
2.84M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
178k
    dcVal = dcVal / (width + width);
79
3.02M
    for (k = 0; k < width; k++)
80
48.4M
        for (l = 0; l < width; l++)
81
45.5M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
178k
    if (bFilter)
84
145k
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
178k
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<32>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
31.4k
{
72
31.4k
    int k, l;
73
74
31.4k
    int dcVal = width;
75
1.03M
    for (int i = 0; i < width; i++)
76
1.00M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
31.4k
    dcVal = dcVal / (width + width);
79
1.03M
    for (k = 0; k < width; k++)
80
33.1M
        for (l = 0; l < width; l++)
81
32.1M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
31.4k
    if (bFilter)
84
0
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
31.4k
}
86
87
template<int log2Size>
88
void planar_pred_c(pixel* dst, intptr_t dstStride, const pixel* srcPix, int /*dirMode*/, int /*bFilter*/)
89
7.30M
{
90
7.30M
    const int blkSize = 1 << log2Size;
91
92
7.30M
    const pixel* above = srcPix + 1;
93
7.30M
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
7.30M
    pixel topRight = above[blkSize];
96
7.30M
    pixel bottomLeft = left[blkSize];
97
45.7M
    for (int y = 0; y < blkSize; y++)
98
313M
        for (int x = 0; x < blkSize; x++)
99
275M
            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.30M
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<2>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
5.72M
{
90
5.72M
    const int blkSize = 1 << log2Size;
91
92
5.72M
    const pixel* above = srcPix + 1;
93
5.72M
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
5.72M
    pixel topRight = above[blkSize];
96
5.72M
    pixel bottomLeft = left[blkSize];
97
28.5M
    for (int y = 0; y < blkSize; y++)
98
114M
        for (int x = 0; x < blkSize; x++)
99
91.4M
            dst[y * dstStride + x] = (pixel) (((blkSize - 1 - x) * left[y] + (blkSize - 1 -y) * above[x] + (x + 1) * topRight + (y + 1) * bottomLeft + blkSize) >> (log2Size + 1));
100
5.72M
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<3>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
1.29M
{
90
1.29M
    const int blkSize = 1 << log2Size;
91
92
1.29M
    const pixel* above = srcPix + 1;
93
1.29M
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
1.29M
    pixel topRight = above[blkSize];
96
1.29M
    pixel bottomLeft = left[blkSize];
97
11.6M
    for (int y = 0; y < blkSize; y++)
98
92.8M
        for (int x = 0; x < blkSize; x++)
99
82.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.29M
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<4>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
258k
{
90
258k
    const int blkSize = 1 << log2Size;
91
92
258k
    const pixel* above = srcPix + 1;
93
258k
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
258k
    pixel topRight = above[blkSize];
96
258k
    pixel bottomLeft = left[blkSize];
97
4.39M
    for (int y = 0; y < blkSize; y++)
98
70.2M
        for (int x = 0; x < blkSize; x++)
99
66.1M
            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
258k
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<5>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
34.0k
{
90
34.0k
    const int blkSize = 1 << log2Size;
91
92
34.0k
    const pixel* above = srcPix + 1;
93
34.0k
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
34.0k
    pixel topRight = above[blkSize];
96
34.0k
    pixel bottomLeft = left[blkSize];
97
1.12M
    for (int y = 0; y < blkSize; y++)
98
35.9M
        for (int x = 0; x < blkSize; x++)
99
34.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
34.0k
}
101
102
template<int width>
103
void intra_pred_ang_c(pixel* dst, intptr_t dstStride, const pixel *srcPix0, int dirMode, int bFilter)
104
61.1M
{
105
61.1M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
61.1M
    int horMode = dirMode < 18;
108
61.1M
    pixel neighbourBuf[129];
109
61.1M
    const pixel *srcPix = srcPix0;
110
111
61.1M
    if (horMode)
112
29.1M
    {
113
29.1M
        neighbourBuf[0] = srcPix[0];
114
354M
        for (int i = 0; i < width << 1; i++)
115
325M
        {
116
325M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
325M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
325M
        }
119
29.1M
        srcPix = neighbourBuf;
120
29.1M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
61.1M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
61.1M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
61.1M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
61.1M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
61.1M
    if (!angle)
132
6.48M
    {
133
40.1M
        for (int y = 0; y < width; y++)
134
274M
            for (int x = 0; x < width; x++)
135
240M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
6.48M
        if (bFilter)
138
3.51M
        {
139
3.51M
            int topLeft = srcPix[0], top = srcPix[1];
140
22.4M
            for (int y = 0; y < width; y++)
141
18.9M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
3.51M
        }
143
6.48M
    }
144
54.6M
    else // Angular prediction.
145
54.6M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
54.6M
        pixel refBuf[64];
148
54.6M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
54.6M
        if (angle < 0)
152
25.6M
        {
153
            // Number of neighbours projected. 
154
25.6M
            int nbProjected = -((width * angle) >> 5) - 1;
155
25.6M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
25.6M
            int invAngle = invAngleTable[- angleOffset - 1];
159
25.6M
            int invAngleSum = 128;
160
79.9M
            for (int i = 0; i < nbProjected; i++)
161
54.2M
            {
162
54.2M
                invAngleSum += invAngle;
163
54.2M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
54.2M
            }
165
166
            // Copy the top-left and top pixels.
167
194M
            for (int i = 0; i < width + 1; i++)
168
169M
                ref_pix[-1 + i] = srcPix[i];
169
25.6M
            ref = ref_pix;
170
25.6M
        }
171
28.9M
        else // Use the top and top-right neighbours.
172
28.9M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
54.6M
        int angleSum = 0;
176
358M
        for (int y = 0; y < width; y++)
177
304M
        {
178
304M
            angleSum += angle;
179
304M
            int offset = angleSum >> 5;
180
304M
            int fraction = angleSum & 31;
181
182
304M
            if (fraction) // Interpolate
183
2.43G
                for (int x = 0; x < width; x++)
184
2.16G
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
36.5M
            else // Copy.
186
335M
                for (int x = 0; x < width; x++)
187
299M
                    dst[y * dstStride + x] = ref[offset + x];
188
304M
        }
189
54.6M
    }
190
191
    // Flip for horizontal.
192
61.1M
    if (horMode)
193
29.2M
    {
194
162M
        for (int y = 0; y < width - 1; y++)
195
133M
        {
196
709M
            for (int x = y + 1; x < width; x++)
197
575M
            {
198
575M
                pixel tmp              = dst[y * dstStride + x];
199
575M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
575M
                dst[x * dstStride + y] = tmp;
201
575M
            }
202
133M
        }
203
29.2M
    }
204
61.1M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<4>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
104
46.0M
{
105
46.0M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
46.0M
    int horMode = dirMode < 18;
108
46.0M
    pixel neighbourBuf[129];
109
46.0M
    const pixel *srcPix = srcPix0;
110
111
46.0M
    if (horMode)
112
21.7M
    {
113
21.7M
        neighbourBuf[0] = srcPix[0];
114
195M
        for (int i = 0; i < width << 1; i++)
115
173M
        {
116
173M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
173M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
173M
        }
119
21.7M
        srcPix = neighbourBuf;
120
21.7M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
46.0M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
46.0M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
46.0M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
46.0M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
46.0M
    if (!angle)
132
5.18M
    {
133
25.8M
        for (int y = 0; y < width; y++)
134
103M
            for (int x = 0; x < width; x++)
135
82.8M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
5.18M
        if (bFilter)
138
2.61M
        {
139
2.61M
            int topLeft = srcPix[0], top = srcPix[1];
140
13.0M
            for (int y = 0; y < width; y++)
141
10.4M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
2.61M
        }
143
5.18M
    }
144
40.8M
    else // Angular prediction.
145
40.8M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
40.8M
        pixel refBuf[64];
148
40.8M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
40.8M
        if (angle < 0)
152
19.1M
        {
153
            // Number of neighbours projected. 
154
19.1M
            int nbProjected = -((width * angle) >> 5) - 1;
155
19.1M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
19.1M
            int invAngle = invAngleTable[- angleOffset - 1];
159
19.1M
            int invAngleSum = 128;
160
46.0M
            for (int i = 0; i < nbProjected; i++)
161
26.8M
            {
162
26.8M
                invAngleSum += invAngle;
163
26.8M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
26.8M
            }
165
166
            // Copy the top-left and top pixels.
167
115M
            for (int i = 0; i < width + 1; i++)
168
95.9M
                ref_pix[-1 + i] = srcPix[i];
169
19.1M
            ref = ref_pix;
170
19.1M
        }
171
21.6M
        else // Use the top and top-right neighbours.
172
21.6M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
40.8M
        int angleSum = 0;
176
204M
        for (int y = 0; y < width; y++)
177
163M
        {
178
163M
            angleSum += angle;
179
163M
            int offset = angleSum >> 5;
180
163M
            int fraction = angleSum & 31;
181
182
163M
            if (fraction) // Interpolate
183
713M
                for (int x = 0; x < width; x++)
184
570M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
20.6M
            else // Copy.
186
102M
                for (int x = 0; x < width; x++)
187
82.0M
                    dst[y * dstStride + x] = ref[offset + x];
188
163M
        }
189
40.8M
    }
190
191
    // Flip for horizontal.
192
46.0M
    if (horMode)
193
21.8M
    {
194
87.0M
        for (int y = 0; y < width - 1; y++)
195
65.2M
        {
196
195M
            for (int x = y + 1; x < width; x++)
197
130M
            {
198
130M
                pixel tmp              = dst[y * dstStride + x];
199
130M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
130M
                dst[x * dstStride + y] = tmp;
201
130M
            }
202
65.2M
        }
203
21.8M
    }
204
46.0M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<8>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
104
11.8M
{
105
11.8M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
11.8M
    int horMode = dirMode < 18;
108
11.8M
    pixel neighbourBuf[129];
109
11.8M
    const pixel *srcPix = srcPix0;
110
111
11.8M
    if (horMode)
112
5.87M
    {
113
5.87M
        neighbourBuf[0] = srcPix[0];
114
99.8M
        for (int i = 0; i < width << 1; i++)
115
93.9M
        {
116
93.9M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
93.9M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
93.9M
        }
119
5.87M
        srcPix = neighbourBuf;
120
5.87M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
11.8M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
11.8M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
11.8M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
11.8M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
11.8M
    if (!angle)
132
1.04M
    {
133
9.43M
        for (int y = 0; y < width; y++)
134
75.4M
            for (int x = 0; x < width; x++)
135
67.0M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
1.04M
        if (bFilter)
138
739k
        {
139
739k
            int topLeft = srcPix[0], top = srcPix[1];
140
6.65M
            for (int y = 0; y < width; y++)
141
5.91M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
739k
        }
143
1.04M
    }
144
10.8M
    else // Angular prediction.
145
10.8M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
10.8M
        pixel refBuf[64];
148
10.8M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
10.8M
        if (angle < 0)
152
5.06M
        {
153
            // Number of neighbours projected. 
154
5.06M
            int nbProjected = -((width * angle) >> 5) - 1;
155
5.06M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
5.06M
            int invAngle = invAngleTable[- angleOffset - 1];
159
5.06M
            int invAngleSum = 128;
160
21.5M
            for (int i = 0; i < nbProjected; i++)
161
16.4M
            {
162
16.4M
                invAngleSum += invAngle;
163
16.4M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
16.4M
            }
165
166
            // Copy the top-left and top pixels.
167
50.5M
            for (int i = 0; i < width + 1; i++)
168
45.5M
                ref_pix[-1 + i] = srcPix[i];
169
5.06M
            ref = ref_pix;
170
5.06M
        }
171
5.78M
        else // Use the top and top-right neighbours.
172
5.78M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
10.8M
        int angleSum = 0;
176
97.2M
        for (int y = 0; y < width; y++)
177
86.3M
        {
178
86.3M
            angleSum += angle;
179
86.3M
            int offset = angleSum >> 5;
180
86.3M
            int fraction = angleSum & 31;
181
182
86.3M
            if (fraction) // Interpolate
183
695M
                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
8.99M
            else // Copy.
186
80.4M
                for (int x = 0; x < width; x++)
187
71.4M
                    dst[y * dstStride + x] = ref[offset + x];
188
86.3M
        }
189
10.8M
    }
190
191
    // Flip for horizontal.
192
11.8M
    if (horMode)
193
5.87M
    {
194
46.9M
        for (int y = 0; y < width - 1; y++)
195
41.0M
        {
196
205M
            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
41.0M
        }
203
5.87M
    }
204
11.8M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<16>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
104
2.64M
{
105
2.64M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
2.64M
    int horMode = dirMode < 18;
108
2.64M
    pixel neighbourBuf[129];
109
2.64M
    const pixel *srcPix = srcPix0;
110
111
2.64M
    if (horMode)
112
1.26M
    {
113
1.26M
        neighbourBuf[0] = srcPix[0];
114
41.8M
        for (int i = 0; i < width << 1; i++)
115
40.5M
        {
116
40.5M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
40.5M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
40.5M
        }
119
1.26M
        srcPix = neighbourBuf;
120
1.26M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
2.64M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
2.64M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
2.64M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
2.64M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
2.64M
    if (!angle)
132
221k
    {
133
3.77M
        for (int y = 0; y < width; y++)
134
60.2M
            for (int x = 0; x < width; x++)
135
56.7M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
221k
        if (bFilter)
138
157k
        {
139
157k
            int topLeft = srcPix[0], top = srcPix[1];
140
2.67M
            for (int y = 0; y < width; y++)
141
2.51M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
157k
        }
143
221k
    }
144
2.42M
    else // Angular prediction.
145
2.42M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
2.42M
        pixel refBuf[64];
148
2.42M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
2.42M
        if (angle < 0)
152
1.15M
        {
153
            // Number of neighbours projected. 
154
1.15M
            int nbProjected = -((width * angle) >> 5) - 1;
155
1.15M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
1.15M
            int invAngle = invAngleTable[- angleOffset - 1];
159
1.15M
            int invAngleSum = 128;
160
8.78M
            for (int i = 0; i < nbProjected; i++)
161
7.62M
            {
162
7.62M
                invAngleSum += invAngle;
163
7.62M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
7.62M
            }
165
166
            // Copy the top-left and top pixels.
167
20.8M
            for (int i = 0; i < width + 1; i++)
168
19.6M
                ref_pix[-1 + i] = srcPix[i];
169
1.15M
            ref = ref_pix;
170
1.15M
        }
171
1.26M
        else // Use the top and top-right neighbours.
172
1.26M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
2.42M
        int angleSum = 0;
176
40.9M
        for (int y = 0; y < width; y++)
177
38.5M
        {
178
38.5M
            angleSum += angle;
179
38.5M
            int offset = angleSum >> 5;
180
38.5M
            int fraction = angleSum & 31;
181
182
38.5M
            if (fraction) // Interpolate
183
572M
                for (int x = 0; x < width; x++)
184
538M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
4.76M
            else // Copy.
186
82.0M
                for (int x = 0; x < width; x++)
187
77.2M
                    dst[y * dstStride + x] = ref[offset + x];
188
38.5M
        }
189
2.42M
    }
190
191
    // Flip for horizontal.
192
2.64M
    if (horMode)
193
1.26M
    {
194
20.2M
        for (int y = 0; y < width - 1; y++)
195
19.0M
        {
196
171M
            for (int x = y + 1; x < width; x++)
197
152M
            {
198
152M
                pixel tmp              = dst[y * dstStride + x];
199
152M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
152M
                dst[x * dstStride + y] = tmp;
201
152M
            }
202
19.0M
        }
203
1.26M
    }
204
2.64M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<32>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
104
538k
{
105
538k
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
538k
    int horMode = dirMode < 18;
108
538k
    pixel neighbourBuf[129];
109
538k
    const pixel *srcPix = srcPix0;
110
111
538k
    if (horMode)
112
261k
    {
113
261k
        neighbourBuf[0] = srcPix[0];
114
17.0M
        for (int i = 0; i < width << 1; i++)
115
16.7M
        {
116
16.7M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
16.7M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
16.7M
        }
119
261k
        srcPix = neighbourBuf;
120
261k
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
538k
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
538k
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
538k
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
538k
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
538k
    if (!angle)
132
32.9k
    {
133
1.08M
        for (int y = 0; y < width; y++)
134
34.7M
            for (int x = 0; x < width; x++)
135
33.6M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
32.9k
        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
32.9k
    }
144
505k
    else // Angular prediction.
145
505k
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
505k
        pixel refBuf[64];
148
505k
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
505k
        if (angle < 0)
152
243k
        {
153
            // Number of neighbours projected. 
154
243k
            int nbProjected = -((width * angle) >> 5) - 1;
155
243k
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
243k
            int invAngle = invAngleTable[- angleOffset - 1];
159
243k
            int invAngleSum = 128;
160
3.54M
            for (int i = 0; i < nbProjected; i++)
161
3.30M
            {
162
3.30M
                invAngleSum += invAngle;
163
3.30M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
3.30M
            }
165
166
            // Copy the top-left and top pixels.
167
8.28M
            for (int i = 0; i < width + 1; i++)
168
8.04M
                ref_pix[-1 + i] = srcPix[i];
169
243k
            ref = ref_pix;
170
243k
        }
171
261k
        else // Use the top and top-right neighbours.
172
261k
            ref = srcPix + 1;
173
174
        // Pass every row.
175
505k
        int angleSum = 0;
176
16.5M
        for (int y = 0; y < width; y++)
177
16.0M
        {
178
16.0M
            angleSum += angle;
179
16.0M
            int offset = angleSum >> 5;
180
16.0M
            int fraction = angleSum & 31;
181
182
16.0M
            if (fraction) // Interpolate
183
456M
                for (int x = 0; x < width; x++)
184
442M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
2.11M
            else // Copy.
186
70.7M
                for (int x = 0; x < width; x++)
187
68.5M
                    dst[y * dstStride + x] = ref[offset + x];
188
16.0M
        }
189
505k
    }
190
191
    // Flip for horizontal.
192
538k
    if (horMode)
193
261k
    {
194
8.34M
        for (int y = 0; y < width - 1; y++)
195
8.08M
        {
196
137M
            for (int x = y + 1; x < width; x++)
197
129M
            {
198
129M
                pixel tmp              = dst[y * dstStride + x];
199
129M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
129M
                dst[x * dstStride + y] = tmp;
201
129M
            }
202
8.08M
        }
203
261k
    }
204
538k
}
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
}