Coverage Report

Created: 2026-06-10 07:00

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.22M
{
34
1.22M
    const int tuSize2 = tuSize << 1;
35
36
1.22M
    pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2];
37
38
    // filtering top
39
22.9M
    for (int i = 1; i < tuSize2; i++)
40
21.7M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
41
1.22M
    filtered[tuSize2] = topLast;
42
    
43
    // filtering top-left
44
1.22M
    filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2;
45
46
    // filtering left
47
1.22M
    filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2;
48
21.7M
    for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++)
49
20.5M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
50
1.22M
    filtered[tuSize2 + tuSize2] = leftLast;
51
1.22M
}
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.02M
{
34
1.02M
    const int tuSize2 = tuSize << 1;
35
36
1.02M
    pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2];
37
38
    // filtering top
39
16.3M
    for (int i = 1; i < tuSize2; i++)
40
15.3M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
41
1.02M
    filtered[tuSize2] = topLast;
42
    
43
    // filtering top-left
44
1.02M
    filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2;
45
46
    // filtering left
47
1.02M
    filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2;
48
15.3M
    for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++)
49
14.3M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
50
1.02M
    filtered[tuSize2 + tuSize2] = leftLast;
51
1.02M
}
intrapred.cpp:void (anonymous namespace)::intraFilter<16>(unsigned char const*, unsigned char*)
Line
Count
Source
33
206k
{
34
206k
    const int tuSize2 = tuSize << 1;
35
36
206k
    pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2];
37
38
    // filtering top
39
6.61M
    for (int i = 1; i < tuSize2; i++)
40
6.40M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
41
206k
    filtered[tuSize2] = topLast;
42
    
43
    // filtering top-left
44
206k
    filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2;
45
46
    // filtering left
47
206k
    filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2;
48
6.40M
    for (int i = tuSize2 + 2; i < tuSize2 + tuSize2; i++)
49
6.20M
        filtered[i] = ((samples[i] << 1) + samples[i - 1] + samples[i + 1] + 2) >> 2;
50
206k
    filtered[tuSize2 + tuSize2] = leftLast;
51
206k
}
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.40M
{
55
    // boundary pixels processing
56
2.40M
    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.40M
    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.40M
}
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.75M
{
72
3.75M
    int k, l;
73
74
3.75M
    int dcVal = width;
75
24.2M
    for (int i = 0; i < width; i++)
76
20.4M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
3.75M
    dcVal = dcVal / (width + width);
79
24.2M
    for (k = 0; k < width; k++)
80
179M
        for (l = 0; l < width; l++)
81
159M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
3.75M
    if (bFilter)
84
2.41M
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
3.75M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<4>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
2.88M
{
72
2.88M
    int k, l;
73
74
2.88M
    int dcVal = width;
75
14.4M
    for (int i = 0; i < width; i++)
76
11.5M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
2.88M
    dcVal = dcVal / (width + width);
79
14.4M
    for (k = 0; k < width; k++)
80
57.6M
        for (l = 0; l < width; l++)
81
46.1M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
2.88M
    if (bFilter)
84
1.73M
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
2.88M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<8>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
687k
{
72
687k
    int k, l;
73
74
687k
    int dcVal = width;
75
6.18M
    for (int i = 0; i < width; i++)
76
5.50M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
687k
    dcVal = dcVal / (width + width);
79
6.18M
    for (k = 0; k < width; k++)
80
49.5M
        for (l = 0; l < width; l++)
81
44.0M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
687k
    if (bFilter)
84
548k
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
687k
}
intrapred.cpp:void (anonymous namespace)::intra_pred_dc_c<16>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
71
159k
{
72
159k
    int k, l;
73
74
159k
    int dcVal = width;
75
2.71M
    for (int i = 0; i < width; i++)
76
2.55M
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
159k
    dcVal = dcVal / (width + width);
79
2.70M
    for (k = 0; k < width; k++)
80
43.3M
        for (l = 0; l < width; l++)
81
40.7M
            dst[k * dstStride + l] = (pixel)dcVal;
82
83
159k
    if (bFilter)
84
130k
        dcPredFilter(srcPix + 1, srcPix + (2 * width + 1), dst, dstStride, width);
85
159k
}
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
920k
    for (int i = 0; i < width; i++)
76
892k
        dcVal += srcPix[1 + i] + srcPix[2 * width + 1 + i];
77
78
27.8k
    dcVal = dcVal / (width + width);
79
920k
    for (k = 0; k < width; k++)
80
29.4M
        for (l = 0; l < width; l++)
81
28.5M
            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.56M
{
90
6.56M
    const int blkSize = 1 << log2Size;
91
92
6.56M
    const pixel* above = srcPix + 1;
93
6.56M
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
6.56M
    pixel topRight = above[blkSize];
96
6.56M
    pixel bottomLeft = left[blkSize];
97
41.0M
    for (int y = 0; y < blkSize; y++)
98
281M
        for (int x = 0; x < blkSize; x++)
99
247M
            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.56M
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<2>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
5.13M
{
90
5.13M
    const int blkSize = 1 << log2Size;
91
92
5.13M
    const pixel* above = srcPix + 1;
93
5.13M
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
5.13M
    pixel topRight = above[blkSize];
96
5.13M
    pixel bottomLeft = left[blkSize];
97
25.6M
    for (int y = 0; y < blkSize; y++)
98
102M
        for (int x = 0; x < blkSize; x++)
99
82.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
5.13M
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<3>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
1.16M
{
90
1.16M
    const int blkSize = 1 << log2Size;
91
92
1.16M
    const pixel* above = srcPix + 1;
93
1.16M
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
1.16M
    pixel topRight = above[blkSize];
96
1.16M
    pixel bottomLeft = left[blkSize];
97
10.4M
    for (int y = 0; y < blkSize; y++)
98
83.6M
        for (int x = 0; x < blkSize; x++)
99
74.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.16M
}
intrapred.cpp:void (anonymous namespace)::planar_pred_c<4>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
89
233k
{
90
233k
    const int blkSize = 1 << log2Size;
91
92
233k
    const pixel* above = srcPix + 1;
93
233k
    const pixel* left  = srcPix + (2 * blkSize + 1);
94
95
233k
    pixel topRight = above[blkSize];
96
233k
    pixel bottomLeft = left[blkSize];
97
3.95M
    for (int y = 0; y < blkSize; y++)
98
63.3M
        for (int x = 0; x < blkSize; x++)
99
59.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
233k
}
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.0M
        for (int x = 0; x < blkSize; x++)
99
31.0M
            dst[y * dstStride + x] = (pixel) (((blkSize - 1 - x) * left[y] + (blkSize - 1 -y) * above[x] + (x + 1) * topRight + (y + 1) * bottomLeft + blkSize) >> (log2Size + 1));
100
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.8M
{
105
54.8M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
54.8M
    int horMode = dirMode < 18;
108
54.8M
    pixel neighbourBuf[129];
109
54.8M
    const pixel *srcPix = srcPix0;
110
111
54.8M
    if (horMode)
112
26.2M
    {
113
26.2M
        neighbourBuf[0] = srcPix[0];
114
319M
        for (int i = 0; i < width << 1; i++)
115
292M
        {
116
292M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
292M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
292M
        }
119
26.2M
        srcPix = neighbourBuf;
120
26.2M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
54.8M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
54.8M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
54.8M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
54.8M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
54.8M
    if (!angle)
132
5.84M
    {
133
36.2M
        for (int y = 0; y < width; y++)
134
246M
            for (int x = 0; x < width; x++)
135
216M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
5.84M
        if (bFilter)
138
3.17M
        {
139
3.17M
            int topLeft = srcPix[0], top = srcPix[1];
140
20.2M
            for (int y = 0; y < width; y++)
141
17.0M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
3.17M
        }
143
5.84M
    }
144
49.0M
    else // Angular prediction.
145
49.0M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
49.0M
        pixel refBuf[64];
148
49.0M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
49.0M
        if (angle < 0)
152
23.1M
        {
153
            // Number of neighbours projected. 
154
23.1M
            int nbProjected = -((width * angle) >> 5) - 1;
155
23.1M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
23.1M
            int invAngle = invAngleTable[- angleOffset - 1];
159
23.1M
            int invAngleSum = 128;
160
72.0M
            for (int i = 0; i < nbProjected; i++)
161
48.8M
            {
162
48.8M
                invAngleSum += invAngle;
163
48.8M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
48.8M
            }
165
166
            // Copy the top-left and top pixels.
167
175M
            for (int i = 0; i < width + 1; i++)
168
152M
                ref_pix[-1 + i] = srcPix[i];
169
23.1M
            ref = ref_pix;
170
23.1M
        }
171
25.9M
        else // Use the top and top-right neighbours.
172
25.9M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
49.0M
        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.2M
            else // Copy.
186
301M
                for (int x = 0; x < width; x++)
187
268M
                    dst[y * dstStride + x] = ref[offset + x];
188
272M
        }
189
49.0M
    }
190
191
    // Flip for horizontal.
192
54.8M
    if (horMode)
193
26.2M
    {
194
146M
        for (int y = 0; y < width - 1; y++)
195
120M
        {
196
636M
            for (int x = y + 1; x < width; x++)
197
516M
            {
198
516M
                pixel tmp              = dst[y * dstStride + x];
199
516M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
516M
                dst[x * dstStride + y] = tmp;
201
516M
            }
202
120M
        }
203
26.2M
    }
204
54.8M
}
intrapred.cpp:void (anonymous namespace)::intra_pred_ang_c<4>(unsigned char*, long, unsigned char const*, int, int)
Line
Count
Source
104
41.3M
{
105
41.3M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
41.3M
    int horMode = dirMode < 18;
108
41.3M
    pixel neighbourBuf[129];
109
41.3M
    const pixel *srcPix = srcPix0;
110
111
41.3M
    if (horMode)
112
19.6M
    {
113
19.6M
        neighbourBuf[0] = srcPix[0];
114
176M
        for (int i = 0; i < width << 1; i++)
115
156M
        {
116
156M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
156M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
156M
        }
119
19.6M
        srcPix = neighbourBuf;
120
19.6M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
41.3M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
41.3M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
41.3M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
41.3M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
41.3M
    if (!angle)
132
4.66M
    {
133
23.3M
        for (int y = 0; y < width; y++)
134
93.3M
            for (int x = 0; x < width; x++)
135
74.6M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
4.66M
        if (bFilter)
138
2.36M
        {
139
2.36M
            int topLeft = srcPix[0], top = srcPix[1];
140
11.8M
            for (int y = 0; y < width; y++)
141
9.46M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
2.36M
        }
143
4.66M
    }
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.3M
        {
153
            // Number of neighbours projected. 
154
17.3M
            int nbProjected = -((width * angle) >> 5) - 1;
155
17.3M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
17.3M
            int invAngle = invAngleTable[- angleOffset - 1];
159
17.3M
            int invAngleSum = 128;
160
41.5M
            for (int i = 0; i < nbProjected; i++)
161
24.2M
            {
162
24.2M
                invAngleSum += invAngle;
163
24.2M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
24.2M
            }
165
166
            // Copy the top-left and top pixels.
167
103M
            for (int i = 0; i < width + 1; i++)
168
86.4M
                ref_pix[-1 + i] = srcPix[i];
169
17.3M
            ref = ref_pix;
170
17.3M
        }
171
19.3M
        else // Use the top and top-right neighbours.
172
19.3M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
36.6M
        int angleSum = 0;
176
182M
        for (int y = 0; y < width; y++)
177
145M
        {
178
145M
            angleSum += angle;
179
145M
            int offset = angleSum >> 5;
180
145M
            int fraction = angleSum & 31;
181
182
145M
            if (fraction) // Interpolate
183
637M
                for (int x = 0; x < width; x++)
184
510M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
18.1M
            else // Copy.
186
91.9M
                for (int x = 0; x < width; x++)
187
73.8M
                    dst[y * dstStride + x] = ref[offset + x];
188
145M
        }
189
36.6M
    }
190
191
    // Flip for horizontal.
192
41.3M
    if (horMode)
193
19.6M
    {
194
78.4M
        for (int y = 0; y < width - 1; y++)
195
58.8M
        {
196
176M
            for (int x = y + 1; x < width; x++)
197
117M
            {
198
117M
                pixel tmp              = dst[y * dstStride + x];
199
117M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
117M
                dst[x * dstStride + y] = tmp;
201
117M
            }
202
58.8M
        }
203
19.6M
    }
204
41.3M
}
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.28M
    {
113
5.28M
        neighbourBuf[0] = srcPix[0];
114
89.8M
        for (int i = 0; i < width << 1; i++)
115
84.5M
        {
116
84.5M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
84.5M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
84.5M
        }
119
5.28M
        srcPix = neighbourBuf;
120
5.28M
    }
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
946k
    {
133
8.51M
        for (int y = 0; y < width; y++)
134
68.1M
            for (int x = 0; x < width; x++)
135
60.5M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
946k
        if (bFilter)
138
667k
        {
139
667k
            int topLeft = srcPix[0], top = srcPix[1];
140
6.01M
            for (int y = 0; y < width; y++)
141
5.34M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
667k
        }
143
946k
    }
144
9.74M
    else // Angular prediction.
145
9.74M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
9.74M
        pixel refBuf[64];
148
9.74M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
9.74M
        if (angle < 0)
152
4.55M
        {
153
            // Number of neighbours projected. 
154
4.55M
            int nbProjected = -((width * angle) >> 5) - 1;
155
4.55M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
4.55M
            int invAngle = invAngleTable[- angleOffset - 1];
159
4.55M
            int invAngleSum = 128;
160
19.3M
            for (int i = 0; i < nbProjected; i++)
161
14.8M
            {
162
14.8M
                invAngleSum += invAngle;
163
14.8M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
14.8M
            }
165
166
            // Copy the top-left and top pixels.
167
45.5M
            for (int i = 0; i < width + 1; i++)
168
40.9M
                ref_pix[-1 + i] = srcPix[i];
169
4.55M
            ref = ref_pix;
170
4.55M
        }
171
5.19M
        else // Use the top and top-right neighbours.
172
5.19M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
9.74M
        int angleSum = 0;
176
87.4M
        for (int y = 0; y < width; y++)
177
77.7M
        {
178
77.7M
            angleSum += angle;
179
77.7M
            int offset = angleSum >> 5;
180
77.7M
            int fraction = angleSum & 31;
181
182
77.7M
            if (fraction) // Interpolate
183
626M
                for (int x = 0; x < width; x++)
184
556M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
7.96M
            else // Copy.
186
72.3M
                for (int x = 0; x < width; x++)
187
64.3M
                    dst[y * dstStride + x] = ref[offset + x];
188
77.7M
        }
189
9.74M
    }
190
191
    // Flip for horizontal.
192
10.6M
    if (horMode)
193
5.28M
    {
194
42.2M
        for (int y = 0; y < width - 1; y++)
195
36.9M
        {
196
184M
            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
36.9M
        }
203
5.28M
    }
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.38M
{
105
2.38M
    int width2 = width << 1;
106
    // Flip the neighbours in the horizontal case.
107
2.38M
    int horMode = dirMode < 18;
108
2.38M
    pixel neighbourBuf[129];
109
2.38M
    const pixel *srcPix = srcPix0;
110
111
2.38M
    if (horMode)
112
1.14M
    {
113
1.14M
        neighbourBuf[0] = srcPix[0];
114
37.7M
        for (int i = 0; i < width << 1; i++)
115
36.5M
        {
116
36.5M
            neighbourBuf[1 + i] = srcPix[width2 + 1 + i];
117
36.5M
            neighbourBuf[width2 + 1 + i] = srcPix[1 + i];
118
36.5M
        }
119
1.14M
        srcPix = neighbourBuf;
120
1.14M
    }
121
122
    // Intra prediction angle and inverse angle tables.
123
2.38M
    const int8_t angleTable[17] = { -32, -26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32 };
124
2.38M
    const int16_t invAngleTable[8] = { 4096, 1638, 910, 630, 482, 390, 315, 256 };
125
126
    // Get the prediction angle.
127
2.38M
    int angleOffset = horMode ? 10 - dirMode : dirMode - 26;
128
2.38M
    int angle = angleTable[8 + angleOffset];
129
130
    // Vertical Prediction.
131
2.38M
    if (!angle)
132
199k
    {
133
3.39M
        for (int y = 0; y < width; y++)
134
54.3M
            for (int x = 0; x < width; x++)
135
51.1M
                dst[y * dstStride + x] = srcPix[1 + x];
136
137
199k
        if (bFilter)
138
142k
        {
139
142k
            int topLeft = srcPix[0], top = srcPix[1];
140
2.42M
            for (int y = 0; y < width; y++)
141
2.27M
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
142k
        }
143
199k
    }
144
2.18M
    else // Angular prediction.
145
2.18M
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
2.18M
        pixel refBuf[64];
148
2.18M
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
2.18M
        if (angle < 0)
152
1.04M
        {
153
            // Number of neighbours projected. 
154
1.04M
            int nbProjected = -((width * angle) >> 5) - 1;
155
1.04M
            pixel *ref_pix = refBuf + nbProjected + 1;
156
157
            // Project the neighbours.
158
1.04M
            int invAngle = invAngleTable[- angleOffset - 1];
159
1.04M
            int invAngleSum = 128;
160
7.92M
            for (int i = 0; i < nbProjected; i++)
161
6.88M
            {
162
6.88M
                invAngleSum += invAngle;
163
6.88M
                ref_pix[- 2 - i] = srcPix[width2 + (invAngleSum >> 8)];
164
6.88M
            }
165
166
            // Copy the top-left and top pixels.
167
18.7M
            for (int i = 0; i < width + 1; i++)
168
17.7M
                ref_pix[-1 + i] = srcPix[i];
169
1.04M
            ref = ref_pix;
170
1.04M
        }
171
1.14M
        else // Use the top and top-right neighbours.
172
1.14M
            ref = srcPix + 1;
173
174
        // Pass every row.
175
2.18M
        int angleSum = 0;
176
36.8M
        for (int y = 0; y < width; y++)
177
34.6M
        {
178
34.6M
            angleSum += angle;
179
34.6M
            int offset = angleSum >> 5;
180
34.6M
            int fraction = angleSum & 31;
181
182
34.6M
            if (fraction) // Interpolate
183
515M
                for (int x = 0; x < width; x++)
184
485M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
4.26M
            else // Copy.
186
73.8M
                for (int x = 0; x < width; x++)
187
69.6M
                    dst[y * dstStride + x] = ref[offset + x];
188
34.6M
        }
189
2.18M
    }
190
191
    // Flip for horizontal.
192
2.38M
    if (horMode)
193
1.14M
    {
194
18.2M
        for (int y = 0; y < width - 1; y++)
195
17.1M
        {
196
154M
            for (int x = y + 1; x < width; x++)
197
137M
            {
198
137M
                pixel tmp              = dst[y * dstStride + x];
199
137M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
137M
                dst[x * dstStride + y] = tmp;
201
137M
            }
202
17.1M
        }
203
1.14M
    }
204
2.38M
}
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.0M
        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.3k
    {
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.3k
        if (bFilter)
138
0
        {
139
0
            int topLeft = srcPix[0], top = srcPix[1];
140
0
            for (int y = 0; y < width; y++)
141
0
                dst[y * dstStride] = x265_clip((int16_t)(top + ((srcPix[width2 + 1 + y] - topLeft) >> 1)));
142
0
        }
143
29.3k
    }
144
448k
    else // Angular prediction.
145
448k
    {
146
        // Get the reference pixels. The reference base is the first pixel to the top (neighbourBuf[1]).
147
448k
        pixel refBuf[64];
148
448k
        const pixel *ref;
149
150
        // Use the projected left neighbours and the top neighbours.
151
448k
        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.36M
            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
448k
        int angleSum = 0;
176
14.6M
        for (int y = 0; y < width; y++)
177
14.1M
        {
178
14.1M
            angleSum += angle;
179
14.1M
            int offset = angleSum >> 5;
180
14.1M
            int fraction = angleSum & 31;
181
182
14.1M
            if (fraction) // Interpolate
183
404M
                for (int x = 0; x < width; x++)
184
391M
                    dst[y * dstStride + x] = (pixel)(((32 - fraction) * ref[offset + x] + fraction * ref[offset + x + 1] + 16) >> 5);
185
1.85M
            else // Copy.
186
62.8M
                for (int x = 0; x < width; x++)
187
61.0M
                    dst[y * dstStride + x] = ref[offset + x];
188
14.1M
        }
189
448k
    }
190
191
    // Flip for horizontal.
192
478k
    if (horMode)
193
232k
    {
194
7.37M
        for (int y = 0; y < width - 1; y++)
195
7.14M
        {
196
121M
            for (int x = y + 1; x < width; x++)
197
114M
            {
198
114M
                pixel tmp              = dst[y * dstStride + x];
199
114M
                dst[y * dstStride + x] = dst[x * dstStride + y];
200
114M
                dst[x * dstStride + y] = tmp;
201
114M
            }
202
7.14M
        }
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
}