Coverage Report

Created: 2026-09-13 06:34

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.21M
{
34
1.21M
    const int tuSize2 = tuSize << 1;
35
36
1.21M
    pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2];
37
38
    // filtering top
39
22.7M
    for (int i = 1; i < tuSize2; i++)
40
21.5M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
41
1.21M
    filtered[tuSize2] = topLast;
42
    
43
    // filtering top-left
44
1.21M
    filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2;
45
46
    // filtering left
47
1.21M
    filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2;
48
21.5M
    for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++)
49
20.3M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
50
1.21M
    filtered[tuSize2 + tuSize2] = leftLast;
51
1.21M
}
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.01M
{
34
1.01M
    const int tuSize2 = tuSize << 1;
35
36
1.01M
    pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2];
37
38
    // filtering top
39
16.2M
    for (int i = 1; i < tuSize2; i++)
40
15.2M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
41
1.01M
    filtered[tuSize2] = topLast;
42
    
43
    // filtering top-left
44
1.01M
    filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2;
45
46
    // filtering left
47
1.01M
    filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2;
48
15.2M
    for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++)
49
14.2M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
50
1.01M
    filtered[tuSize2 + tuSize2] = leftLast;
51
1.01M
}
intrapred.cpp:void (anonymous namespace)::intraFilter<16>(unsigned char const*, unsigned char*)
Line
Count
Source
33
204k
{
34
204k
    const int tuSize2 = tuSize << 1;
35
36
204k
    pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2];
37
38
    // filtering top
39
6.55M
    for (int i = 1; i < tuSize2; i++)
40
6.34M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
41
204k
    filtered[tuSize2] = topLast;
42
    
43
    // filtering top-left
44
204k
    filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2;
45
46
    // filtering left
47
204k
    filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2;
48
6.34M
    for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++)
49
6.14M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
50
204k
    filtered[tuSize2 + tuSize2] = leftLast;
51
204k
}
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.39M
{
55
    // boundary pixels processing
56
2.39M
    dst[0] = (pixel)((above[0] + left[0] + 2 * dst[0] + 2) >> 2);
57
58
13.3M
    for (int x = 1; x < size; x++)
59
10.9M
        dst[x] = (pixel)((above[x] +  3 * dst[x] + 2) >> 2);
60
61
2.39M
    dst += dststride;
62
13.3M
    for (int y = 1; y < size; y++)
63
10.9M
    {
64
10.9M
        *dst = (pixel)((left[y] + 3 * *dst + 2) >> 2);
65
10.9M
        dst += dststride;
66
10.9M
    }
67
2.39M
}
68
69
template<int width>
70
void intra_pred_dc_c(pixel* dst, intptr_t dstStride, const pixel* srcPix, int /*dirMode*/, int bFilter)
71
3.74M
{
72
3.74M
    int k, l;
73
74
3.74M
    int dcVal = width;
75
24.1M
    for (int i = 0; i < width; i++)
76
20.4M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
3.74M
    dcVal = dcVal / (width + width);
79
24.1M
    for (k = 0; k < width; k++)
80
179M
        for (l = 0; l < width; l++)
81
158M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
3.74M
    if (bFilter)
84
2.39M
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
3.74M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<4>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
2.87M
{
72
2.87M
    int k, l;
73
74
2.87M
    int dcVal = width;
75
14.3M
    for (int i = 0; i < width; i++)
76
11.4M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
2.87M
    dcVal = dcVal / (width + width);
79
14.3M
    for (k = 0; k < width; k++)
80
57.4M
        for (l = 0; l < width; l++)
81
45.9M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
2.87M
    if (bFilter)
84
1.72M
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
2.87M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<8>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
685k
{
72
685k
    int k, l;
73
74
685k
    int dcVal = width;
75
6.16M
    for (int i = 0; i < width; i++)
76
5.48M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
685k
    dcVal = dcVal / (width + width);
79
6.16M
    for (k = 0; k < width; k++)
80
49.3M
        for (l = 0; l < width; l++)
81
43.8M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
685k
    if (bFilter)
84
546k
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
685k
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<16>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
158k
{
72
158k
    int k, l;
73
74
158k
    int dcVal = width;
75
2.70M
    for (int i = 0; i < width; i++)
76
2.54M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
158k
    dcVal = dcVal / (width + width);
79
2.70M
    for (k = 0; k < width; k++)
80
43.2M
        for (l = 0; l < width; l++)
81
40.6M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
158k
    if (bFilter)
84
130k
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
158k
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<32>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
27.8k
{
72
27.8k
    int k, l;
73
74
27.8k
    int dcVal = width;
75
919k
    for (int i = 0; i < width; i++)
76
891k
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
27.8k
    dcVal = dcVal / (width + width);
79
918k
    for (k = 0; k < width; k++)
80
29.3M
        for (l = 0; l < width; l++)
81
28.4M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
27.8k
    if (bFilter)
84
0
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
27.8k
}
86
87
template<int log2Size>
88
void planar_pred_c(pixel* dst, intptr_t dstStride, const pixel* srcPix, int /*dirMode*/, int /*bFilter*/)
89
6.53M
{
90
6.53M
    const int blkSize = 1 << log2Size;
91
92
6.53M
    const pixel* above = srcPix + 1;
93
6.53M
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
6.53M
    pixel topRight = above[blkSize];
96
6.53M
    pixel bottomLeft = left[blkSize];
97
40.8M
    for (int y = 0; y < blkSize; y++)
98
280M
        for (int x = 0; x < blkSize; x++)
99
245M
            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.53M
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<2>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
5.11M
{
90
5.11M
    const int blkSize = 1 << log2Size;
91
92
5.11M
    const pixel* above = srcPix + 1;
93
5.11M
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
5.11M
    pixel topRight = above[blkSize];
96
5.11M
    pixel bottomLeft = left[blkSize];
97
25.5M
    for (int y = 0; y < blkSize; y++)
98
102M
        for (int x = 0; x < blkSize; x++)
99
81.7M
            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.11M
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<3>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
1.15M
{
90
1.15M
    const int blkSize = 1 << log2Size;
91
92
1.15M
    const pixel* above = srcPix + 1;
93
1.15M
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
1.15M
    pixel topRight = above[blkSize];
96
1.15M
    pixel bottomLeft = left[blkSize];
97
10.3M
    for (int y = 0; y < blkSize; y++)
98
82.9M
        for (int x = 0; x < blkSize; x++)
99
73.7M
            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.15M
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<4>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
231k
{
90
231k
    const int blkSize = 1 << log2Size;
91
92
231k
    const pixel* above = srcPix + 1;
93
231k
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
231k
    pixel topRight = above[blkSize];
96
231k
    pixel bottomLeft = left[blkSize];
97
3.92M
    for (int y = 0; y < blkSize; y++)
98
62.8M
        for (int x = 0; x < blkSize; x++)
99
59.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
231k
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<5>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
30.4k
{
90
30.4k
    const int blkSize = 1 << log2Size;
91
92
30.4k
    const pixel* above = srcPix + 1;
93
30.4k
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
30.4k
    pixel topRight = above[blkSize];
96
30.4k
    pixel bottomLeft = left[blkSize];
97
1.00M
    for (int y = 0; y < blkSize; y++)
98
32.1M
        for (int x = 0; x < blkSize; x++)
99
31.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
30.4k
}
101
102
template<int width>
103
void intra_pred_ang_c(pixel* dst, intptr_t dstStride, const pixel *srcPix0, int dirMode, int bFilter)
104
54.7M
{
105
54.7M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
54.7M
    int horMode = dirMode < 18;
108
54.7M
    pixel neighbourBuf[129];
109
54.7M
    const pixel *srcPix = srcPix0;
110
111
54.7M
    if (horMode)
112
26.1M
    {
113
26.1M
        neighbourBuf[0] = srcPix[0];
114
317M
        for (int i = 0; i < width << 1; i++)
115
291M
        {
116
291M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
291M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
291M
        }
119
26.1M
        srcPix = neighbourBuf;
120
26.1M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
54.7M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
54.7M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
54.7M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
54.7M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
54.7M
    if (!angle)
132
5.81M
    {
133
36.0M
        for (int y = 0; y < width; y++)
134
245M
            for (int x = 0; x < width; x++)
135
215M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
5.81M
        if (bFilter)
138
3.15M
        {
139
3.15M
            int topLeft = srcPix[0], top = srcPix[1];
140
20.1M
            for (int y = 0; y < width; y++)
141
16.9M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
3.15M
        }
143
5.81M
    }
144
48.9M
    else // Angular prediction.
145
48.9M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
48.9M
        pixel refBuf[64];
148
48.9M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
48.9M
        if (angle < 0)
152
22.9M
        {
153
            // Number of neighbours projected. 
154
22.9M
            int nbProjected = -((width * angle) >> 5) - 1;
155
22.9M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
22.9M
            int invAngle = invAngleTable[- angleOffset - 1];
159
22.9M
            int invAngleSum = 128;
160
71.5M
            for (int i = 0; i < nbProjected; i++)
161
48.5M
            {
162
48.5M
                invAngleSum += invAngle;
163
48.5M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
48.5M
            }
165
166
            // Copy the top-left and top pixels.
167
174M
            for (int i = 0; i < width + 1; i++)
168
151M
                ref_pix[-1 + i] = srcPix[i];
169
22.9M
            ref = ref_pix;
170
22.9M
        }
171
25.9M
        else // Use the top and top-right neighbours.
172
25.9M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
48.9M
        int angleSum = 0;
176
321M
        for (int y = 0; y < width; y++)
177
272M
        {
178
272M
            angleSum += angle;
179
272M
            int offset = angleSum >> 5;
180
272M
            int fraction = angleSum & 31;
181
182
272M
            if (fraction) // Interpolate
183
2.18G
                for (int x = 0; x < width; x++)
184
1.94G
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
32.6M
            else // Copy.
186
300M
                for (int x = 0; x < width; x++)
187
267M
                    dst[y * dstStride + x] = ref[offset + x];
188
272M
        }
189
48.9M
    }
190
191
    // Flip for horizontal.
192
54.7M
    if (horMode)
193
26.1M
    {
194
145M
        for (int y = 0; y < width - 1; y++)
195
119M
        {
196
633M
            for (int x = y + 1; x < width; x++)
197
514M
            {
198
514M
                pixel tmp              = dst[y * dstStride + x];
199
514M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
514M
                dst[x * dstStride + y] = tmp;
201
514M
            }
202
119M
        }
203
26.1M
    }
204
54.7M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<4>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
104
41.2M
{
105
41.2M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
41.2M
    int horMode = dirMode < 18;
108
41.2M
    pixel neighbourBuf[129];
109
41.2M
    const pixel *srcPix = srcPix0;
110
111
41.2M
    if (horMode)
112
19.4M
    {
113
19.4M
        neighbourBuf[0] = srcPix[0];
114
175M
        for (int i = 0; i < width << 1; i++)
115
155M
        {
116
155M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
155M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
155M
        }
119
19.4M
        srcPix = neighbourBuf;
120
19.4M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
41.2M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
41.2M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
41.2M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
41.2M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
41.2M
    if (!angle)
132
4.64M
    {
133
23.2M
        for (int y = 0; y < width; y++)
134
92.8M
            for (int x = 0; x < width; x++)
135
74.2M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
4.64M
        if (bFilter)
138
2.34M
        {
139
2.34M
            int topLeft = srcPix[0], top = srcPix[1];
140
11.7M
            for (int y = 0; y < width; y++)
141
9.39M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
2.34M
        }
143
4.64M
    }
144
36.6M
    else // Angular prediction.
145
36.6M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
36.6M
        pixel refBuf[64];
148
36.6M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
36.6M
        if (angle < 0)
152
17.1M
        {
153
            // Number of neighbours projected. 
154
17.1M
            int nbProjected = -((width * angle) >> 5) - 1;
155
17.1M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
17.1M
            int invAngle = invAngleTable[- angleOffset - 1];
159
17.1M
            int invAngleSum = 128;
160
41.2M
            for (int i = 0; i < nbProjected; i++)
161
24.0M
            {
162
24.0M
                invAngleSum += invAngle;
163
24.0M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
24.0M
            }
165
166
            // Copy the top-left and top pixels.
167
103M
            for (int i = 0; i < width + 1; i++)
168
85.9M
                ref_pix[-1 + i] = srcPix[i];
169
17.1M
            ref = ref_pix;
170
17.1M
        }
171
19.4M
        else // Use the top and top-right neighbours.
172
19.4M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
36.6M
        int angleSum = 0;
176
182M
        for (int y = 0; y < width; y++)
177
146M
        {
178
146M
            angleSum += angle;
179
146M
            int offset = angleSum >> 5;
180
146M
            int fraction = angleSum & 31;
181
182
146M
            if (fraction) // Interpolate
183
639M
                for (int x = 0; x < width; x++)
184
511M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
18.4M
            else // Copy.
186
91.9M
                for (int x = 0; x < width; x++)
187
73.4M
                    dst[y * dstStride + x] = ref[offset + x];
188
146M
        }
189
36.6M
    }
190
191
    // Flip for horizontal.
192
41.2M
    if (horMode)
193
19.5M
    {
194
77.9M
        for (int y = 0; y < width - 1; y++)
195
58.4M
        {
196
175M
            for (int x = y + 1; x < width; x++)
197
116M
            {
198
116M
                pixel tmp              = dst[y * dstStride + x];
199
116M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
116M
                dst[x * dstStride + y] = tmp;
201
116M
            }
202
58.4M
        }
203
19.5M
    }
204
41.2M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<8>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
104
10.6M
{
105
10.6M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
10.6M
    int horMode = dirMode < 18;
108
10.6M
    pixel neighbourBuf[129];
109
10.6M
    const pixel *srcPix = srcPix0;
110
111
10.6M
    if (horMode)
112
5.25M
    {
113
5.25M
        neighbourBuf[0] = srcPix[0];
114
89.3M
        for (int i = 0; i < width << 1; i++)
115
84.0M
        {
116
84.0M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
84.0M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
84.0M
        }
119
5.25M
        srcPix = neighbourBuf;
120
5.25M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
10.6M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
10.6M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
10.6M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
10.6M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
10.6M
    if (!angle)
132
940k
    {
133
8.46M
        for (int y = 0; y < width; y++)
134
67.6M
            for (int x = 0; x < width; x++)
135
60.1M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
940k
        if (bFilter)
138
663k
        {
139
663k
            int topLeft = srcPix[0], top = srcPix[1];
140
5.96M
            for (int y = 0; y < width; y++)
141
5.30M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
663k
        }
143
940k
    }
144
9.70M
    else // Angular prediction.
145
9.70M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
9.70M
        pixel refBuf[64];
148
9.70M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
9.70M
        if (angle < 0)
152
4.52M
        {
153
            // Number of neighbours projected. 
154
4.52M
            int nbProjected = -((width * angle) >> 5) - 1;
155
4.52M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
4.52M
            int invAngle = invAngleTable[- angleOffset - 1];
159
4.52M
            int invAngleSum = 128;
160
19.2M
            for (int i = 0; i < nbProjected; i++)
161
14.7M
            {
162
14.7M
                invAngleSum += invAngle;
163
14.7M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
14.7M
            }
165
166
            // Copy the top-left and top pixels.
167
45.2M
            for (int i = 0; i < width + 1; i++)
168
40.7M
                ref_pix[-1 + i] = srcPix[i];
169
4.52M
            ref = ref_pix;
170
4.52M
        }
171
5.17M
        else // Use the top and top-right neighbours.
172
5.17M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
9.70M
        int angleSum = 0;
176
87.0M
        for (int y = 0; y < width; y++)
177
77.3M
        {
178
77.3M
            angleSum += angle;
179
77.3M
            int offset = angleSum >> 5;
180
77.3M
            int fraction = angleSum & 31;
181
182
77.3M
            if (fraction) // Interpolate
183
623M
                for (int x = 0; x < width; x++)
184
553M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
8.04M
            else // Copy.
186
72.0M
                for (int x = 0; x < width; x++)
187
63.9M
                    dst[y * dstStride + x] = ref[offset + x];
188
77.3M
        }
189
9.70M
    }
190
191
    // Flip for horizontal.
192
10.6M
    if (horMode)
193
5.25M
    {
194
41.9M
        for (int y = 0; y < width - 1; y++)
195
36.7M
        {
196
183M
            for (int x = y + 1; x < width; x++)
197
146M
            {
198
146M
                pixel tmp              = dst[y * dstStride + x];
199
146M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
146M
                dst[x * dstStride + y] = tmp;
201
146M
            }
202
36.7M
        }
203
5.25M
    }
204
10.6M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<16>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
104
2.36M
{
105
2.36M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
2.36M
    int horMode = dirMode < 18;
108
2.36M
    pixel neighbourBuf[129];
109
2.36M
    const pixel *srcPix = srcPix0;
110
111
2.36M
    if (horMode)
112
1.13M
    {
113
1.13M
        neighbourBuf[0] = srcPix[0];
114
37.4M
        for (int i = 0; i < width << 1; i++)
115
36.3M
        {
116
36.3M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
36.3M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
36.3M
        }
119
1.13M
        srcPix = neighbourBuf;
120
1.13M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
2.36M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
2.36M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
2.36M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
2.36M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
2.36M
    if (!angle)
132
198k
    {
133
3.37M
        for (int y = 0; y < width; y++)
134
53.9M
            for (int x = 0; x < width; x++)
135
50.8M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
198k
        if (bFilter)
138
141k
        {
139
141k
            int topLeft = srcPix[0], top = srcPix[1];
140
2.40M
            for (int y = 0; y < width; y++)
141
2.25M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
141k
        }
143
198k
    }
144
2.16M
    else // Angular prediction.
145
2.16M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
2.16M
        pixel refBuf[64];
148
2.16M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
2.16M
        if (angle < 0)
152
1.03M
        {
153
            // Number of neighbours projected. 
154
1.03M
            int nbProjected = -((width * angle) >> 5) - 1;
155
1.03M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
1.03M
            int invAngle = invAngleTable[- angleOffset - 1];
159
1.03M
            int invAngleSum = 128;
160
7.86M
            for (int i = 0; i < nbProjected; i++)
161
6.82M
            {
162
6.82M
                invAngleSum += invAngle;
163
6.82M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
6.82M
            }
165
166
            // Copy the top-left and top pixels.
167
18.6M
            for (int i = 0; i < width + 1; i++)
168
17.5M
                ref_pix[-1 + i] = srcPix[i];
169
1.03M
            ref = ref_pix;
170
1.03M
        }
171
1.13M
        else // Use the top and top-right neighbours.
172
1.13M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
2.16M
        int angleSum = 0;
176
36.7M
        for (int y = 0; y < width; y++)
177
34.5M
        {
178
34.5M
            angleSum += angle;
179
34.5M
            int offset = angleSum >> 5;
180
34.5M
            int fraction = angleSum & 31;
181
182
34.5M
            if (fraction) // Interpolate
183
513M
                for (int x = 0; x < width; x++)
184
482M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
4.29M
            else // Copy.
186
73.4M
                for (int x = 0; x < width; x++)
187
69.1M
                    dst[y * dstStride + x] = ref[offset + x];
188
34.5M
        }
189
2.16M
    }
190
191
    // Flip for horizontal.
192
2.36M
    if (horMode)
193
1.13M
    {
194
18.1M
        for (int y = 0; y < width - 1; y++)
195
16.9M
        {
196
152M
            for (int x = y + 1; x < width; x++)
197
135M
            {
198
135M
                pixel tmp              = dst[y * dstStride + x];
199
135M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
135M
                dst[x * dstStride + y] = tmp;
201
135M
            }
202
16.9M
        }
203
1.13M
    }
204
2.36M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<32>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
104
478k
{
105
478k
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
478k
    int horMode = dirMode < 18;
108
478k
    pixel neighbourBuf[129];
109
478k
    const pixel *srcPix = srcPix0;
110
111
478k
    if (horMode)
112
232k
    {
113
232k
        neighbourBuf[0] = srcPix[0];
114
15.1M
        for (int i = 0; i < width << 1; i++)
115
14.8M
        {
116
14.8M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
14.8M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
14.8M
        }
119
232k
        srcPix = neighbourBuf;
120
232k
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
478k
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
478k
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
478k
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
478k
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
478k
    if (!angle)
132
29.2k
    {
133
966k
        for (int y = 0; y < width; y++)
134
30.9M
            for (int x = 0; x < width; x++)
135
29.9M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
29.2k
        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
29.2k
    }
144
449k
    else // Angular prediction.
145
449k
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
449k
        pixel refBuf[64];
148
449k
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
449k
        if (angle < 0)
152
216k
        {
153
            // Number of neighbours projected. 
154
216k
            int nbProjected = -((width * angle) >> 5) - 1;
155
216k
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
216k
            int invAngle = invAngleTable[- angleOffset - 1];
159
216k
            int invAngleSum = 128;
160
3.15M
            for (int i = 0; i < nbProjected; i++)
161
2.93M
            {
162
2.93M
                invAngleSum += invAngle;
163
2.93M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
2.93M
            }
165
166
            // Copy the top-left and top pixels.
167
7.37M
            for (int i = 0; i < width + 1; i++)
168
7.15M
                ref_pix[-1 + i] = srcPix[i];
169
216k
            ref = ref_pix;
170
216k
        }
171
232k
        else // Use the top and top-right neighbours.
172
232k
            ref = srcPix + 1;
173
174
        // Pass every row.
175
449k
        int angleSum = 0;
176
14.7M
        for (int y = 0; y < width; y++)
177
14.2M
        {
178
14.2M
            angleSum += angle;
179
14.2M
            int offset = angleSum >> 5;
180
14.2M
            int fraction = angleSum & 31;
181
182
14.2M
            if (fraction) // Interpolate
183
407M
                for (int x = 0; x < width; x++)
184
394M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
1.88M
            else // Copy.
186
62.9M
                for (int x = 0; x < width; x++)
187
61.0M
                    dst[y * dstStride + x] = ref[offset + x];
188
14.2M
        }
189
449k
    }
190
191
    // Flip for horizontal.
192
478k
    if (horMode)
193
232k
    {
194
7.43M
        for (int y = 0; y < width - 1; y++)
195
7.19M
        {
196
122M
            for (int x = y + 1; x < width; x++)
197
115M
            {
198
115M
                pixel tmp              = dst[y * dstStride + x];
199
115M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
115M
                dst[x * dstStride + y] = tmp;
201
115M
            }
202
7.19M
        }
203
232k
    }
204
478k
}
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
}