Coverage Report

Created: 2026-09-14 06:44

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.32M
{
34
1.32M
    const int tuSize2 = tuSize << 1;
35
36
1.32M
    pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2];
37
38
    // filtering top
39
24.8M
    for (int i = 1; i < tuSize2; i++)
40
23.5M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
41
1.32M
    filtered[tuSize2] = topLast;
42
    
43
    // filtering top-left
44
1.32M
    filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2;
45
46
    // filtering left
47
1.32M
    filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2;
48
23.5M
    for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++)
49
22.1M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
50
1.32M
    filtered[tuSize2 + tuSize2] = leftLast;
51
1.32M
}
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.10M
{
34
1.10M
    const int tuSize2 = tuSize << 1;
35
36
1.10M
    pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2];
37
38
    // filtering top
39
17.6M
    for (int i = 1; i < tuSize2; i++)
40
16.5M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
41
1.10M
    filtered[tuSize2] = topLast;
42
    
43
    // filtering top-left
44
1.10M
    filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2;
45
46
    // filtering left
47
1.10M
    filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2;
48
16.5M
    for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++)
49
15.4M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
50
1.10M
    filtered[tuSize2 + tuSize2] = leftLast;
51
1.10M
}
intrapred.cpp:void (anonymous namespace)::intraFilter<16>(unsigned char const*, unsigned char*)
Line
Count
Source
33
223k
{
34
223k
    const int tuSize2 = tuSize << 1;
35
36
223k
    pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2];
37
38
    // filtering top
39
7.14M
    for (int i = 1; i < tuSize2; i++)
40
6.92M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
41
223k
    filtered[tuSize2] = topLast;
42
    
43
    // filtering top-left
44
223k
    filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2;
45
46
    // filtering left
47
223k
    filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2;
48
6.92M
    for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++)
49
6.69M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
50
223k
    filtered[tuSize2 + tuSize2] = leftLast;
51
223k
}
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.60M
{
55
    // boundary pixels processing
56
2.60M
    dst[0] = (pixel)((above[0] + left[0] + 2 * dst[0] + 2) >> 2);
57
58
14.4M
    for (int x = 1; x < size; x++)
59
11.8M
        dst[x] = (pixel)((above[x] +  3 * dst[x] + 2) >> 2);
60
61
2.60M
    dst += dststride;
62
14.4M
    for (int y = 1; y < size; y++)
63
11.8M
    {
64
11.8M
        *dst = (pixel)((left[y] + 3 * *dst + 2) >> 2);
65
11.8M
        dst += dststride;
66
11.8M
    }
67
2.60M
}
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.06M
{
72
4.06M
    int k, l;
73
74
4.06M
    int dcVal = width;
75
26.2M
    for (int i = 0; i < width; i++)
76
22.1M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
4.06M
    dcVal = dcVal / (width + width);
79
26.2M
    for (k = 0; k < width; k++)
80
194M
        for (l = 0; l < width; l++)
81
172M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
4.06M
    if (bFilter)
84
2.60M
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
4.06M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<4>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
3.11M
{
72
3.11M
    int k, l;
73
74
3.11M
    int dcVal = width;
75
15.5M
    for (int i = 0; i < width; i++)
76
12.4M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
3.11M
    dcVal = dcVal / (width + width);
79
15.5M
    for (k = 0; k < width; k++)
80
62.3M
        for (l = 0; l < width; l++)
81
49.8M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
3.11M
    if (bFilter)
84
1.87M
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
3.11M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<8>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
744k
{
72
744k
    int k, l;
73
74
744k
    int dcVal = width;
75
6.69M
    for (int i = 0; i < width; i++)
76
5.95M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
744k
    dcVal = dcVal / (width + width);
79
6.69M
    for (k = 0; k < width; k++)
80
53.5M
        for (l = 0; l < width; l++)
81
47.6M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
744k
    if (bFilter)
84
593k
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
744k
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<16>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
172k
{
72
172k
    int k, l;
73
74
172k
    int dcVal = width;
75
2.93M
    for (int i = 0; i < width; i++)
76
2.76M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
172k
    dcVal = dcVal / (width + width);
79
2.93M
    for (k = 0; k < width; k++)
80
46.9M
        for (l = 0; l < width; l++)
81
44.1M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
172k
    if (bFilter)
84
141k
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
172k
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<32>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
30.2k
{
72
30.2k
    int k, l;
73
74
30.2k
    int dcVal = width;
75
997k
    for (int i = 0; i < width; i++)
76
967k
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
30.2k
    dcVal = dcVal / (width + width);
79
997k
    for (k = 0; k < width; k++)
80
31.8M
        for (l = 0; l < width; l++)
81
30.9M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
30.2k
    if (bFilter)
84
0
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
30.2k
}
86
87
template<int log2Size>
88
void planar_pred_c(pixel* dst, intptr_t dstStride, const pixel* srcPix, int /*dirMode*/, int /*bFilter*/)
89
7.10M
{
90
7.10M
    const int blkSize = 1 << log2Size;
91
92
7.10M
    const pixel* above = srcPix + 1;
93
7.10M
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
7.10M
    pixel topRight = above[blkSize];
96
7.10M
    pixel bottomLeft = left[blkSize];
97
44.4M
    for (int y = 0; y < blkSize; y++)
98
304M
        for (int x = 0; x < blkSize; x++)
99
267M
            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.10M
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<2>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
5.56M
{
90
5.56M
    const int blkSize = 1 << log2Size;
91
92
5.56M
    const pixel* above = srcPix + 1;
93
5.56M
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
5.56M
    pixel topRight = above[blkSize];
96
5.56M
    pixel bottomLeft = left[blkSize];
97
27.8M
    for (int y = 0; y < blkSize; y++)
98
111M
        for (int x = 0; x < blkSize; x++)
99
88.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
5.56M
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<3>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
1.25M
{
90
1.25M
    const int blkSize = 1 << log2Size;
91
92
1.25M
    const pixel* above = srcPix + 1;
93
1.25M
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
1.25M
    pixel topRight = above[blkSize];
96
1.25M
    pixel bottomLeft = left[blkSize];
97
11.3M
    for (int y = 0; y < blkSize; y++)
98
90.4M
        for (int x = 0; x < blkSize; x++)
99
80.3M
            dst[y * dstStride + x] = (pixel) (((blkSize - 1 - x) * left[y] + (blkSize - 1 -y) * above[x] + (x + 1) * topRight + (y + 1) * bottomLeft + blkSize) >> (log2Size + 1));
100
1.25M
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<4>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
251k
{
90
251k
    const int blkSize = 1 << log2Size;
91
92
251k
    const pixel* above = srcPix + 1;
93
251k
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
251k
    pixel topRight = above[blkSize];
96
251k
    pixel bottomLeft = left[blkSize];
97
4.28M
    for (int y = 0; y < blkSize; y++)
98
68.4M
        for (int x = 0; x < blkSize; x++)
99
64.3M
            dst[y * dstStride + x] = (pixel) (((blkSize - 1 - x) * left[y] + (blkSize - 1 -y) * above[x] + (x + 1) * topRight + (y + 1) * bottomLeft + blkSize) >> (log2Size + 1));
100
251k
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<5>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
32.8k
{
90
32.8k
    const int blkSize = 1 << log2Size;
91
92
32.8k
    const pixel* above = srcPix + 1;
93
32.8k
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
32.8k
    pixel topRight = above[blkSize];
96
32.8k
    pixel bottomLeft = left[blkSize];
97
1.08M
    for (int y = 0; y < blkSize; y++)
98
34.6M
        for (int x = 0; x < blkSize; x++)
99
33.6M
            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
32.8k
}
101
102
template<int width>
103
void intra_pred_ang_c(pixel* dst, intptr_t dstStride, const pixel *srcPix0, int dirMode, int bFilter)
104
59.3M
{
105
59.3M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
59.3M
    int horMode = dirMode < 18;
108
59.3M
    pixel neighbourBuf[129];
109
59.3M
    const pixel *srcPix = srcPix0;
110
111
59.3M
    if (horMode)
112
28.3M
    {
113
28.3M
        neighbourBuf[0] = srcPix[0];
114
344M
        for (int i = 0; i < width << 1; i++)
115
316M
        {
116
316M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
316M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
316M
        }
119
28.3M
        srcPix = neighbourBuf;
120
28.3M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
59.3M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
59.3M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
59.3M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
59.3M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
59.3M
    if (!angle)
132
6.32M
    {
133
39.1M
        for (int y = 0; y < width; y++)
134
266M
            for (int x = 0; x < width; x++)
135
233M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
6.32M
        if (bFilter)
138
3.43M
        {
139
3.43M
            int topLeft = srcPix[0], top = srcPix[1];
140
21.9M
            for (int y = 0; y < width; y++)
141
18.4M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
3.43M
        }
143
6.32M
    }
144
53.0M
    else // Angular prediction.
145
53.0M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
53.0M
        pixel refBuf[64];
148
53.0M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
53.0M
        if (angle < 0)
152
24.9M
        {
153
            // Number of neighbours projected. 
154
24.9M
            int nbProjected = -((width * angle) >> 5) - 1;
155
24.9M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
24.9M
            int invAngle = invAngleTable[- angleOffset - 1];
159
24.9M
            int invAngleSum = 128;
160
77.7M
            for (int i = 0; i < nbProjected; i++)
161
52.7M
            {
162
52.7M
                invAngleSum += invAngle;
163
52.7M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
52.7M
            }
165
166
            // Copy the top-left and top pixels.
167
189M
            for (int i = 0; i < width + 1; i++)
168
164M
                ref_pix[-1 + i] = srcPix[i];
169
24.9M
            ref = ref_pix;
170
24.9M
        }
171
28.0M
        else // Use the top and top-right neighbours.
172
28.0M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
53.0M
        int angleSum = 0;
176
347M
        for (int y = 0; y < width; y++)
177
294M
        {
178
294M
            angleSum += angle;
179
294M
            int offset = angleSum >> 5;
180
294M
            int fraction = angleSum & 31;
181
182
294M
            if (fraction) // Interpolate
183
2.34G
                for (int x = 0; x < width; x++)
184
2.08G
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
36.0M
            else // Copy.
186
326M
                for (int x = 0; x < width; x++)
187
290M
                    dst[y * dstStride + x] = ref[offset + x];
188
294M
        }
189
53.0M
    }
190
191
    // Flip for horizontal.
192
59.3M
    if (horMode)
193
28.4M
    {
194
157M
        for (int y = 0; y < width - 1; y++)
195
129M
        {
196
686M
            for (int x = y + 1; x < width; x++)
197
557M
            {
198
557M
                pixel tmp              = dst[y * dstStride + x];
199
557M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
557M
                dst[x * dstStride + y] = tmp;
201
557M
            }
202
129M
        }
203
28.4M
    }
204
59.3M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<4>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
104
44.6M
{
105
44.6M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
44.6M
    int horMode = dirMode < 18;
108
44.6M
    pixel neighbourBuf[129];
109
44.6M
    const pixel *srcPix = srcPix0;
110
111
44.6M
    if (horMode)
112
21.1M
    {
113
21.1M
        neighbourBuf[0] = srcPix[0];
114
190M
        for (int i = 0; i < width << 1; i++)
115
169M
        {
116
169M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
169M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
169M
        }
119
21.1M
        srcPix = neighbourBuf;
120
21.1M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
44.6M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
44.6M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
44.6M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
44.6M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
44.6M
    if (!angle)
132
5.05M
    {
133
25.2M
        for (int y = 0; y < width; y++)
134
100M
            for (int x = 0; x < width; x++)
135
80.7M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
5.05M
        if (bFilter)
138
2.55M
        {
139
2.55M
            int topLeft = srcPix[0], top = srcPix[1];
140
12.7M
            for (int y = 0; y < width; y++)
141
10.2M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
2.55M
        }
143
5.05M
    }
144
39.6M
    else // Angular prediction.
145
39.6M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
39.6M
        pixel refBuf[64];
148
39.6M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
39.6M
        if (angle < 0)
152
18.6M
        {
153
            // Number of neighbours projected. 
154
18.6M
            int nbProjected = -((width * angle) >> 5) - 1;
155
18.6M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
18.6M
            int invAngle = invAngleTable[- angleOffset - 1];
159
18.6M
            int invAngleSum = 128;
160
44.8M
            for (int i = 0; i < nbProjected; i++)
161
26.1M
            {
162
26.1M
                invAngleSum += invAngle;
163
26.1M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
26.1M
            }
165
166
            // Copy the top-left and top pixels.
167
111M
            for (int i = 0; i < width + 1; i++)
168
93.2M
                ref_pix[-1 + i] = srcPix[i];
169
18.6M
            ref = ref_pix;
170
18.6M
        }
171
20.9M
        else // Use the top and top-right neighbours.
172
20.9M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
39.6M
        int angleSum = 0;
176
197M
        for (int y = 0; y < width; y++)
177
157M
        {
178
157M
            angleSum += angle;
179
157M
            int offset = angleSum >> 5;
180
157M
            int fraction = angleSum & 31;
181
182
157M
            if (fraction) // Interpolate
183
684M
                for (int x = 0; x < width; x++)
184
547M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
20.2M
            else // Copy.
186
100M
                for (int x = 0; x < width; x++)
187
79.8M
                    dst[y * dstStride + x] = ref[offset + x];
188
157M
        }
189
39.6M
    }
190
191
    // Flip for horizontal.
192
44.6M
    if (horMode)
193
21.2M
    {
194
84.6M
        for (int y = 0; y < width - 1; y++)
195
63.3M
        {
196
190M
            for (int x = y + 1; x < width; x++)
197
126M
            {
198
126M
                pixel tmp              = dst[y * dstStride + x];
199
126M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
126M
                dst[x * dstStride + y] = tmp;
201
126M
            }
202
63.3M
        }
203
21.2M
    }
204
44.6M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<8>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
104
11.5M
{
105
11.5M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
11.5M
    int horMode = dirMode < 18;
108
11.5M
    pixel neighbourBuf[129];
109
11.5M
    const pixel *srcPix = srcPix0;
110
111
11.5M
    if (horMode)
112
5.71M
    {
113
5.71M
        neighbourBuf[0] = srcPix[0];
114
97.0M
        for (int i = 0; i < width << 1; i++)
115
91.3M
        {
116
91.3M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
91.3M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
91.3M
        }
119
5.71M
        srcPix = neighbourBuf;
120
5.71M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
11.5M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
11.5M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
11.5M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
11.5M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
11.5M
    if (!angle)
132
1.02M
    {
133
9.21M
        for (int y = 0; y < width; y++)
134
73.6M
            for (int x = 0; x < width; x++)
135
65.4M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
1.02M
        if (bFilter)
138
722k
        {
139
722k
            int topLeft = srcPix[0], top = srcPix[1];
140
6.49M
            for (int y = 0; y < width; y++)
141
5.77M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
722k
        }
143
1.02M
    }
144
10.5M
    else // Angular prediction.
145
10.5M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
10.5M
        pixel refBuf[64];
148
10.5M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
10.5M
        if (angle < 0)
152
4.92M
        {
153
            // Number of neighbours projected. 
154
4.92M
            int nbProjected = -((width * angle) >> 5) - 1;
155
4.92M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
4.92M
            int invAngle = invAngleTable[- angleOffset - 1];
159
4.92M
            int invAngleSum = 128;
160
20.9M
            for (int i = 0; i < nbProjected; i++)
161
16.0M
            {
162
16.0M
                invAngleSum += invAngle;
163
16.0M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
16.0M
            }
165
166
            // Copy the top-left and top pixels.
167
49.2M
            for (int i = 0; i < width + 1; i++)
168
44.2M
                ref_pix[-1 + i] = srcPix[i];
169
4.92M
            ref = ref_pix;
170
4.92M
        }
171
5.61M
        else // Use the top and top-right neighbours.
172
5.61M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
10.5M
        int angleSum = 0;
176
94.6M
        for (int y = 0; y < width; y++)
177
84.1M
        {
178
84.1M
            angleSum += angle;
179
84.1M
            int offset = angleSum >> 5;
180
84.1M
            int fraction = angleSum & 31;
181
182
84.1M
            if (fraction) // Interpolate
183
672M
                for (int x = 0; x < width; x++)
184
598M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
9.19M
            else // Copy.
186
78.7M
                for (int x = 0; x < width; x++)
187
69.5M
                    dst[y * dstStride + x] = ref[offset + x];
188
84.1M
        }
189
10.5M
    }
190
191
    // Flip for horizontal.
192
11.5M
    if (horMode)
193
5.71M
    {
194
45.5M
        for (int y = 0; y < width - 1; y++)
195
39.8M
        {
196
198M
            for (int x = y + 1; x < width; x++)
197
158M
            {
198
158M
                pixel tmp              = dst[y * dstStride + x];
199
158M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
158M
                dst[x * dstStride + y] = tmp;
201
158M
            }
202
39.8M
        }
203
5.71M
    }
204
11.5M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<16>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
104
2.58M
{
105
2.58M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
2.58M
    int horMode = dirMode < 18;
108
2.58M
    pixel neighbourBuf[129];
109
2.58M
    const pixel *srcPix = srcPix0;
110
111
2.58M
    if (horMode)
112
1.23M
    {
113
1.23M
        neighbourBuf[0] = srcPix[0];
114
40.8M
        for (int i = 0; i < width << 1; i++)
115
39.5M
        {
116
39.5M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
39.5M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
39.5M
        }
119
1.23M
        srcPix = neighbourBuf;
120
1.23M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
2.58M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
2.58M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
2.58M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
2.58M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
2.58M
    if (!angle)
132
216k
    {
133
3.67M
        for (int y = 0; y < width; y++)
134
58.7M
            for (int x = 0; x < width; x++)
135
55.2M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
216k
        if (bFilter)
138
154k
        {
139
154k
            int topLeft = srcPix[0], top = srcPix[1];
140
2.62M
            for (int y = 0; y < width; y++)
141
2.46M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
154k
        }
143
216k
    }
144
2.36M
    else // Angular prediction.
145
2.36M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
2.36M
        pixel refBuf[64];
148
2.36M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
2.36M
        if (angle < 0)
152
1.12M
        {
153
            // Number of neighbours projected. 
154
1.12M
            int nbProjected = -((width * angle) >> 5) - 1;
155
1.12M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
1.12M
            int invAngle = invAngleTable[- angleOffset - 1];
159
1.12M
            int invAngleSum = 128;
160
8.57M
            for (int i = 0; i < nbProjected; i++)
161
7.44M
            {
162
7.44M
                invAngleSum += invAngle;
163
7.44M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
7.44M
            }
165
166
            // Copy the top-left and top pixels.
167
20.3M
            for (int i = 0; i < width + 1; i++)
168
19.1M
                ref_pix[-1 + i] = srcPix[i];
169
1.12M
            ref = ref_pix;
170
1.12M
        }
171
1.23M
        else // Use the top and top-right neighbours.
172
1.23M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
2.36M
        int angleSum = 0;
176
39.6M
        for (int y = 0; y < width; y++)
177
37.2M
        {
178
37.2M
            angleSum += angle;
179
37.2M
            int offset = angleSum >> 5;
180
37.2M
            int fraction = angleSum & 31;
181
182
37.2M
            if (fraction) // Interpolate
183
553M
                for (int x = 0; x < width; x++)
184
520M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
4.60M
            else // Copy.
186
79.9M
                for (int x = 0; x < width; x++)
187
75.2M
                    dst[y * dstStride + x] = ref[offset + x];
188
37.2M
        }
189
2.36M
    }
190
191
    // Flip for horizontal.
192
2.58M
    if (horMode)
193
1.23M
    {
194
19.7M
        for (int y = 0; y < width - 1; y++)
195
18.4M
        {
196
166M
            for (int x = y + 1; x < width; x++)
197
147M
            {
198
147M
                pixel tmp              = dst[y * dstStride + x];
199
147M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
147M
                dst[x * dstStride + y] = tmp;
201
147M
            }
202
18.4M
        }
203
1.23M
    }
204
2.58M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<32>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
104
518k
{
105
518k
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
518k
    int horMode = dirMode < 18;
108
518k
    pixel neighbourBuf[129];
109
518k
    const pixel *srcPix = srcPix0;
110
111
518k
    if (horMode)
112
251k
    {
113
251k
        neighbourBuf[0] = srcPix[0];
114
16.3M
        for (int i = 0; i < width << 1; i++)
115
16.1M
        {
116
16.1M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
16.1M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
16.1M
        }
119
251k
        srcPix = neighbourBuf;
120
251k
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
518k
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
518k
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
518k
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
518k
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
518k
    if (!angle)
132
31.7k
    {
133
1.04M
        for (int y = 0; y < width; y++)
134
33.4M
            for (int x = 0; x < width; x++)
135
32.4M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
31.7k
        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
31.7k
    }
144
486k
    else // Angular prediction.
145
486k
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
486k
        pixel refBuf[64];
148
486k
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
486k
        if (angle < 0)
152
234k
        {
153
            // Number of neighbours projected. 
154
234k
            int nbProjected = -((width * angle) >> 5) - 1;
155
234k
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
234k
            int invAngle = invAngleTable[- angleOffset - 1];
159
234k
            int invAngleSum = 128;
160
3.41M
            for (int i = 0; i < nbProjected; i++)
161
3.17M
            {
162
3.17M
                invAngleSum += invAngle;
163
3.17M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
3.17M
            }
165
166
            // Copy the top-left and top pixels.
167
7.98M
            for (int i = 0; i < width + 1; i++)
168
7.74M
                ref_pix[-1 + i] = srcPix[i];
169
234k
            ref = ref_pix;
170
234k
        }
171
251k
        else // Use the top and top-right neighbours.
172
251k
            ref = srcPix + 1;
173
174
        // Pass every row.
175
486k
        int angleSum = 0;
176
15.5M
        for (int y = 0; y < width; y++)
177
15.0M
        {
178
15.0M
            angleSum += angle;
179
15.0M
            int offset = angleSum >> 5;
180
15.0M
            int fraction = angleSum & 31;
181
182
15.0M
            if (fraction) // Interpolate
183
432M
                for (int x = 0; x < width; x++)
184
418M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
1.95M
            else // Copy.
186
67.9M
                for (int x = 0; x < width; x++)
187
66.0M
                    dst[y * dstStride + x] = ref[offset + x];
188
15.0M
        }
189
486k
    }
190
191
    // Flip for horizontal.
192
518k
    if (horMode)
193
251k
    {
194
7.97M
        for (int y = 0; y < width - 1; y++)
195
7.72M
        {
196
131M
            for (int x = y + 1; x < width; x++)
197
123M
            {
198
123M
                pixel tmp              = dst[y * dstStride + x];
199
123M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
123M
                dst[x * dstStride + y] = tmp;
201
123M
            }
202
7.72M
        }
203
251k
    }
204
518k
}
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
}