Coverage Report

Created: 2025-08-28 06:38

/src/libhevc/common/ihevc_sao.c
Line
Count
Source
1
/******************************************************************************
2
*
3
* Copyright (C) 2012 Ittiam Systems Pvt Ltd, Bangalore
4
*
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at:
8
*
9
* http://www.apache.org/licenses/LICENSE-2.0
10
*
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
16
*
17
******************************************************************************/
18
/**
19
*******************************************************************************
20
* @file
21
*  ihevc_sao.c
22
*
23
* @brief
24
*  Contains leaf level function definitions for sample adaptive offset process
25
*
26
* @author
27
*  Srinivas T
28
*
29
* @par List of Functions:
30
*   - ihevc_sao_band_offset_luma()
31
*   - ihevc_sao_band_offset_chroma()
32
*   - ihevc_sao_edge_offset_class0()
33
*   - ihevc_sao_edge_offset_class0_chroma()
34
*   - ihevc_sao_edge_offset_class1()
35
*   - ihevc_sao_edge_offset_class1_chroma()
36
*   - ihevc_sao_edge_offset_class2()
37
*   - ihevc_sao_edge_offset_class2_chroma()
38
*   - ihevc_sao_edge_offset_class3()
39
*   - ihevc_sao_edge_offset_class3_chroma()
40
* @remarks
41
*  None
42
*
43
*******************************************************************************
44
*/
45
#include <stdlib.h>
46
#include <assert.h>
47
#include <string.h>
48
#include "ihevc_typedefs.h"
49
#include "ihevc_macros.h"
50
#include "ihevc_platform_macros.h"
51
#include "ihevc_func_selector.h"
52
#include "ihevc_defs.h"
53
#include "ihevc_structs.h"
54
#include "ihevc_sao.h"
55
56
107k
#define NUM_BAND_TABLE  32
57
58
const WORD32 gi4_ihevc_table_edge_idx[5] = { 1, 2, 0, 3, 4 };
59
/**
60
 * au4_avail is an array of flags - one for each neighboring block specifying if the block is available
61
 * au4_avail[0] - left
62
 * au4_avail[1] - right
63
 * au4_avail[2] - top
64
 * au4_avail[3] - bottom
65
 * au4_avail[4] - top-left
66
 * au4_avail[5] - top-right
67
 * au4_avail[6] - bottom-left
68
 * au4_avail[7] - bottom-right
69
 */
70
71
72
void ihevc_sao_band_offset_luma(UWORD8 *pu1_src,
73
                                WORD32 src_strd,
74
                                UWORD8 *pu1_src_left,
75
                                UWORD8 *pu1_src_top,
76
                                UWORD8 *pu1_src_top_left,
77
                                WORD32 sao_band_pos,
78
                                WORD8 *pi1_sao_offset,
79
                                WORD32 wd,
80
                                WORD32 ht)
81
975
{
82
975
    WORD32 band_shift;
83
975
    WORD32 band_table[NUM_BAND_TABLE];
84
975
    WORD32 i;
85
975
    WORD32 row, col;
86
87
    /* Updating left and top and top-left */
88
32.5k
    for(row = 0; row < ht; row++)
89
31.5k
    {
90
31.5k
        pu1_src_left[row] = pu1_src[row * src_strd + (wd - 1)];
91
31.5k
    }
92
975
    pu1_src_top_left[0] = pu1_src_top[wd - 1];
93
33.4k
    for(col = 0; col < wd; col++)
94
32.5k
    {
95
32.5k
        pu1_src_top[col] = pu1_src[(ht - 1) * src_strd + col];
96
32.5k
    }
97
98
975
    band_shift = BIT_DEPTH_LUMA - 5;
99
32.1k
    for(i = 0; i < NUM_BAND_TABLE; i++)
100
31.2k
    {
101
31.2k
        band_table[i] = 0;
102
31.2k
    }
103
4.87k
    for(i = 0; i < 4; i++)
104
3.90k
    {
105
3.90k
        band_table[(i + sao_band_pos) & 31] = i + 1;
106
3.90k
    }
107
108
32.5k
    for(row = 0; row < ht; row++)
109
31.5k
    {
110
1.08M
        for(col = 0; col < wd; col++)
111
1.05M
        {
112
1.05M
            WORD32 band_idx;
113
114
1.05M
            band_idx = band_table[pu1_src[col] >> band_shift];
115
1.05M
            pu1_src[col] = CLIP3(pu1_src[col] + pi1_sao_offset[band_idx], 0, (1 << (band_shift + 5)) - 1);
116
1.05M
        }
117
31.5k
        pu1_src += src_strd;
118
31.5k
    }
119
975
}
120
121
122
123
/* input 'wd' has to be for the interleaved block and not for each color component */
124
void ihevc_sao_band_offset_chroma(UWORD8 *pu1_src,
125
                                  WORD32 src_strd,
126
                                  UWORD8 *pu1_src_left,
127
                                  UWORD8 *pu1_src_top,
128
                                  UWORD8 *pu1_src_top_left,
129
                                  WORD32 sao_band_pos_u,
130
                                  WORD32 sao_band_pos_v,
131
                                  WORD8 *pi1_sao_offset_u,
132
                                  WORD8 *pi1_sao_offset_v,
133
                                  WORD32 wd,
134
                                  WORD32 ht)
135
2.28k
{
136
2.28k
    WORD32 band_shift;
137
2.28k
    WORD32 band_table_u[NUM_BAND_TABLE];
138
2.28k
    WORD32 band_table_v[NUM_BAND_TABLE];
139
2.28k
    WORD32 i;
140
2.28k
    WORD32 row, col;
141
142
    /* Updating left and top and top-left */
143
38.8k
    for(row = 0; row < ht; row++)
144
36.5k
    {
145
36.5k
        pu1_src_left[2 * row] = pu1_src[row * src_strd + (wd - 2)];
146
36.5k
        pu1_src_left[2 * row + 1] = pu1_src[row * src_strd + (wd - 1)];
147
36.5k
    }
148
2.28k
    pu1_src_top_left[0] = pu1_src_top[wd - 2];
149
2.28k
    pu1_src_top_left[1] = pu1_src_top[wd - 1];
150
75.0k
    for(col = 0; col < wd; col++)
151
72.7k
    {
152
72.7k
        pu1_src_top[col] = pu1_src[(ht - 1) * src_strd + col];
153
72.7k
    }
154
155
156
2.28k
    band_shift = BIT_DEPTH_CHROMA - 5;
157
75.1k
    for(i = 0; i < NUM_BAND_TABLE; i++)
158
72.8k
    {
159
72.8k
        band_table_u[i] = 0;
160
72.8k
        band_table_v[i] = 0;
161
72.8k
    }
162
11.3k
    for(i = 0; i < 4; i++)
163
9.10k
    {
164
9.10k
        band_table_u[(i + sao_band_pos_u) & 31] = i + 1;
165
9.10k
        band_table_v[(i + sao_band_pos_v) & 31] = i + 1;
166
9.10k
    }
167
168
38.6k
    for(row = 0; row < ht; row++)
169
36.3k
    {
170
1.17M
        for(col = 0; col < wd; col++)
171
1.14M
        {
172
1.14M
            WORD32 band_idx;
173
1.14M
            WORD8 *pi1_sao_offset;
174
175
1.14M
            pi1_sao_offset = (0 == col % 2) ? pi1_sao_offset_u : pi1_sao_offset_v;
176
1.14M
            band_idx = (0 == col % 2) ? band_table_u[pu1_src[col] >> band_shift] : band_table_v[pu1_src[col] >> band_shift];
177
1.14M
            pu1_src[col] = CLIP3(pu1_src[col] + pi1_sao_offset[band_idx], 0, (1 << (band_shift + 5)) - 1);
178
1.14M
        }
179
36.3k
        pu1_src += src_strd;
180
36.3k
    }
181
2.28k
}
182
183
184
185
/* Horizontal filtering */
186
void ihevc_sao_edge_offset_class0(UWORD8 *pu1_src,
187
                                  WORD32 src_strd,
188
                                  UWORD8 *pu1_src_left,
189
                                  UWORD8 *pu1_src_top,
190
                                  UWORD8 *pu1_src_top_left,
191
                                  UWORD8 *pu1_src_top_right,
192
                                  UWORD8 *pu1_src_bot_left,
193
                                  UWORD8 *pu1_avail,
194
                                  WORD8 *pi1_sao_offset,
195
                                  WORD32 wd,
196
                                  WORD32 ht)
197
247k
{
198
247k
    WORD32 row, col;
199
247k
    UWORD8 au1_mask[MAX_CTB_SIZE];
200
247k
    UWORD8 au1_src_left_tmp[MAX_CTB_SIZE];
201
247k
    WORD8 u1_sign_left, u1_sign_right;
202
247k
    WORD32 bit_depth;
203
247k
    UNUSED(pu1_src_top_right);
204
247k
    UNUSED(pu1_src_bot_left);
205
247k
    bit_depth = BIT_DEPTH_LUMA;
206
207
    /* Initialize the mask values */
208
247k
    memset(au1_mask, 0xFF, MAX_CTB_SIZE);
209
210
    /* Update top and top-left arrays */
211
247k
    *pu1_src_top_left = pu1_src_top[wd - 1];
212
15.4M
    for(row = 0; row < ht; row++)
213
15.1M
    {
214
15.1M
        au1_src_left_tmp[row] = pu1_src[row * src_strd + wd - 1];
215
15.1M
    }
216
15.5M
    for(col = 0; col < wd; col++)
217
15.2M
    {
218
15.2M
        pu1_src_top[col] = pu1_src[(ht - 1) * src_strd + col];
219
15.2M
    }
220
221
    /* Update masks based on the availability flags */
222
247k
    if(0 == pu1_avail[0])
223
114k
    {
224
114k
        au1_mask[0] = 0;
225
114k
    }
226
247k
    if(0 == pu1_avail[1])
227
116k
    {
228
116k
        au1_mask[wd - 1] = 0;
229
116k
    }
230
231
    /* Processing is done on the intermediate buffer and the output is written to the source buffer */
232
247k
    {
233
15.4M
        for(row = 0; row < ht; row++)
234
15.1M
        {
235
15.1M
            u1_sign_left = SIGN(pu1_src[0] - pu1_src_left[row]);
236
954M
            for(col = 0; col < wd; col++)
237
939M
            {
238
939M
                WORD32 edge_idx;
239
240
939M
                u1_sign_right = SIGN(pu1_src[col] - pu1_src[col + 1]);
241
939M
                edge_idx = 2 + u1_sign_left + u1_sign_right;
242
939M
                u1_sign_left = -u1_sign_right;
243
244
939M
                edge_idx = gi4_ihevc_table_edge_idx[edge_idx] & au1_mask[col];
245
246
939M
                if(0 != edge_idx)
247
34.4M
                {
248
34.4M
                    pu1_src[col] = CLIP3(pu1_src[col] + pi1_sao_offset[edge_idx], 0, (1 << bit_depth) - 1);
249
34.4M
                }
250
939M
            }
251
252
15.1M
            pu1_src += src_strd;
253
15.1M
        }
254
247k
    }
255
256
    /* Update left array */
257
15.4M
    for(row = 0; row < ht; row++)
258
15.1M
    {
259
15.1M
        pu1_src_left[row] = au1_src_left_tmp[row];
260
15.1M
    }
261
262
247k
}
263
264
265
266
267
/* input 'wd' has to be for the interleaved block and not for each color component */
268
void ihevc_sao_edge_offset_class0_chroma(UWORD8 *pu1_src,
269
                                         WORD32 src_strd,
270
                                         UWORD8 *pu1_src_left,
271
                                         UWORD8 *pu1_src_top,
272
                                         UWORD8 *pu1_src_top_left,
273
                                         UWORD8 *pu1_src_top_right,
274
                                         UWORD8 *pu1_src_bot_left,
275
                                         UWORD8 *pu1_avail,
276
                                         WORD8 *pi1_sao_offset_u,
277
                                         WORD8 *pi1_sao_offset_v,
278
                                         WORD32 wd,
279
                                         WORD32 ht)
280
109k
{
281
109k
    WORD32 row, col;
282
109k
    UWORD8 au1_mask[MAX_CTB_SIZE];
283
109k
    UWORD8 au1_src_left_tmp[2 * MAX_CTB_SIZE];
284
109k
    WORD8 u1_sign_left_u, u1_sign_right_u;
285
109k
    WORD8 u1_sign_left_v, u1_sign_right_v;
286
109k
    WORD32 bit_depth;
287
109k
    UNUSED(pu1_src_top_right);
288
109k
    UNUSED(pu1_src_bot_left);
289
109k
    bit_depth = BIT_DEPTH_CHROMA;
290
291
    /* Initialize the mask values */
292
109k
    memset(au1_mask, 0xFF, MAX_CTB_SIZE);
293
294
    /* Update left, top and top-left arrays */
295
109k
    pu1_src_top_left[0] = pu1_src_top[wd - 2];
296
109k
    pu1_src_top_left[1] = pu1_src_top[wd - 1];
297
3.45M
    for(row = 0; row < ht; row++)
298
3.35M
    {
299
3.35M
        au1_src_left_tmp[2 * row] = pu1_src[row * src_strd + wd - 2];
300
3.35M
        au1_src_left_tmp[2 * row + 1] = pu1_src[row * src_strd + wd - 1];
301
3.35M
    }
302
6.86M
    for(col = 0; col < wd; col++)
303
6.75M
    {
304
6.75M
        pu1_src_top[col] = pu1_src[(ht - 1) * src_strd + col];
305
6.75M
    }
306
307
    /* Update masks based on the availability flags */
308
109k
    if(0 == pu1_avail[0])
309
41.7k
    {
310
41.7k
        au1_mask[0] = 0;
311
41.7k
    }
312
109k
    if(0 == pu1_avail[1])
313
43.9k
    {
314
43.9k
        au1_mask[(wd - 1) >> 1] = 0;
315
43.9k
    }
316
317
    /* Processing is done on the intermediate buffer and the output is written to the source buffer */
318
109k
    {
319
3.45M
        for(row = 0; row < ht; row++)
320
3.35M
        {
321
3.35M
            u1_sign_left_u = SIGN(pu1_src[0] - pu1_src_left[2 * row]);
322
3.35M
            u1_sign_left_v = SIGN(pu1_src[1] - pu1_src_left[2 * row + 1]);
323
210M
            for(col = 0; col < wd; col++)
324
206M
            {
325
206M
                WORD32 edge_idx;
326
206M
                WORD8 *pi1_sao_offset;
327
328
206M
                if(0 == col % 2)
329
103M
                {
330
103M
                    pi1_sao_offset = pi1_sao_offset_u;
331
103M
                    u1_sign_right_u = SIGN(pu1_src[col] - pu1_src[col + 2]);
332
103M
                    edge_idx = 2 + u1_sign_left_u + u1_sign_right_u;
333
103M
                    u1_sign_left_u = -u1_sign_right_u;
334
103M
                }
335
103M
                else
336
103M
                {
337
103M
                    pi1_sao_offset = pi1_sao_offset_v;
338
103M
                    u1_sign_right_v = SIGN(pu1_src[col] - pu1_src[col + 2]);
339
103M
                    edge_idx = 2 + u1_sign_left_v + u1_sign_right_v;
340
103M
                    u1_sign_left_v = -u1_sign_right_v;
341
103M
                }
342
343
206M
                edge_idx = gi4_ihevc_table_edge_idx[edge_idx] & au1_mask[col >> 1];
344
345
206M
                if(0 != edge_idx)
346
8.15M
                {
347
8.15M
                    pu1_src[col] = CLIP3(pu1_src[col] + pi1_sao_offset[edge_idx], 0, (1 << bit_depth) - 1);
348
8.15M
                }
349
206M
            }
350
351
3.35M
            pu1_src += src_strd;
352
3.35M
        }
353
109k
    }
354
355
6.80M
    for(row = 0; row < 2 * ht; row++)
356
6.70M
    {
357
6.70M
        pu1_src_left[row] = au1_src_left_tmp[row];
358
6.70M
    }
359
360
109k
}
361
362
363
364
/* Vertical filtering */
365
void ihevc_sao_edge_offset_class1(UWORD8 *pu1_src,
366
                                  WORD32 src_strd,
367
                                  UWORD8 *pu1_src_left,
368
                                  UWORD8 *pu1_src_top,
369
                                  UWORD8 *pu1_src_top_left,
370
                                  UWORD8 *pu1_src_top_right,
371
                                  UWORD8 *pu1_src_bot_left,
372
                                  UWORD8 *pu1_avail,
373
                                  WORD8 *pi1_sao_offset,
374
                                  WORD32 wd,
375
                                  WORD32 ht)
376
164k
{
377
164k
    WORD32 row, col;
378
164k
    UWORD8 au1_mask[MAX_CTB_SIZE];
379
164k
    UWORD8 au1_src_top_tmp[MAX_CTB_SIZE];
380
164k
    WORD8 au1_sign_up[MAX_CTB_SIZE];
381
164k
    WORD8 u1_sign_down;
382
164k
    WORD32 bit_depth;
383
164k
    UNUSED(pu1_src_top_right);
384
164k
    UNUSED(pu1_src_bot_left);
385
386
164k
    bit_depth = BIT_DEPTH_LUMA;
387
388
    /* Initialize the mask values */
389
164k
    memset(au1_mask, 0xFF, MAX_CTB_SIZE);
390
391
    /* Update left, top and top-left arrays */
392
164k
    *pu1_src_top_left = pu1_src_top[wd - 1];
393
10.2M
    for(row = 0; row < ht; row++)
394
10.1M
    {
395
10.1M
        pu1_src_left[row] = pu1_src[row * src_strd + wd - 1];
396
10.1M
    }
397
10.3M
    for(col = 0; col < wd; col++)
398
10.1M
    {
399
10.1M
        au1_src_top_tmp[col] = pu1_src[(ht - 1) * src_strd + col];
400
10.1M
    }
401
402
    /* Update height and source pointers based on the availability flags */
403
164k
    if(0 == pu1_avail[2])
404
101k
    {
405
101k
        pu1_src += src_strd;
406
101k
        ht--;
407
6.36M
        for(col = 0; col < wd; col++)
408
6.26M
        {
409
6.26M
            au1_sign_up[col] = SIGN(pu1_src[col] - pu1_src[col - src_strd]);
410
6.26M
        }
411
101k
    }
412
62.8k
    else
413
62.8k
    {
414
3.95M
        for(col = 0; col < wd; col++)
415
3.88M
        {
416
3.88M
            au1_sign_up[col] = SIGN(pu1_src[col] - pu1_src_top[col]);
417
3.88M
        }
418
62.8k
    }
419
164k
    if(0 == pu1_avail[3])
420
101k
    {
421
101k
        ht--;
422
101k
    }
423
424
    /* Processing is done on the intermediate buffer and the output is written to the source buffer */
425
164k
    {
426
10.0M
        for(row = 0; row < ht; row++)
427
9.91M
        {
428
623M
            for(col = 0; col < wd; col++)
429
613M
            {
430
613M
                WORD32 edge_idx;
431
432
613M
                u1_sign_down = SIGN(pu1_src[col] - pu1_src[col + src_strd]);
433
613M
                edge_idx = 2 + au1_sign_up[col] + u1_sign_down;
434
613M
                au1_sign_up[col] = -u1_sign_down;
435
436
613M
                edge_idx = gi4_ihevc_table_edge_idx[edge_idx] & au1_mask[col];
437
438
613M
                if(0 != edge_idx)
439
24.9M
                {
440
24.9M
                    pu1_src[col] = CLIP3(pu1_src[col] + pi1_sao_offset[edge_idx], 0, (1 << bit_depth) - 1);
441
24.9M
                }
442
613M
            }
443
444
9.91M
            pu1_src += src_strd;
445
9.91M
        }
446
164k
    }
447
448
10.3M
    for(col = 0; col < wd; col++)
449
10.1M
    {
450
10.1M
        pu1_src_top[col] = au1_src_top_tmp[col];
451
10.1M
    }
452
453
164k
}
454
455
456
457
/* input 'wd' has to be for the interleaved block and not for each color component */
458
void ihevc_sao_edge_offset_class1_chroma(UWORD8 *pu1_src,
459
                                         WORD32 src_strd,
460
                                         UWORD8 *pu1_src_left,
461
                                         UWORD8 *pu1_src_top,
462
                                         UWORD8 *pu1_src_top_left,
463
                                         UWORD8 *pu1_src_top_right,
464
                                         UWORD8 *pu1_src_bot_left,
465
                                         UWORD8 *pu1_avail,
466
                                         WORD8 *pi1_sao_offset_u,
467
                                         WORD8 *pi1_sao_offset_v,
468
                                         WORD32 wd,
469
                                         WORD32 ht)
470
26.4k
{
471
26.4k
    WORD32 row, col;
472
26.4k
    UWORD8 au1_mask[MAX_CTB_SIZE];
473
26.4k
    UWORD8 au1_src_top_tmp[MAX_CTB_SIZE];
474
26.4k
    WORD8 au1_sign_up[MAX_CTB_SIZE];
475
26.4k
    WORD8 u1_sign_down;
476
26.4k
    WORD32 bit_depth;
477
26.4k
    UNUSED(pu1_src_top_right);
478
26.4k
    UNUSED(pu1_src_bot_left);
479
480
26.4k
    bit_depth = BIT_DEPTH_CHROMA;
481
482
    /* Initialize the mask values */
483
26.4k
    memset(au1_mask, 0xFF, MAX_CTB_SIZE);
484
485
    /* Update left, top and top-left arrays */
486
26.4k
    pu1_src_top_left[0] = pu1_src_top[wd - 2];
487
26.4k
    pu1_src_top_left[1] = pu1_src_top[wd - 1];
488
840k
    for(row = 0; row < ht; row++)
489
814k
    {
490
814k
        pu1_src_left[2 * row] = pu1_src[row * src_strd + wd - 2];
491
814k
        pu1_src_left[2 * row + 1] = pu1_src[row * src_strd + wd - 1];
492
814k
    }
493
1.65M
    for(col = 0; col < wd; col++)
494
1.62M
    {
495
1.62M
        au1_src_top_tmp[col] = pu1_src[(ht - 1) * src_strd + col];
496
1.62M
    }
497
498
    /* Update height and source pointers based on the availability flags */
499
26.4k
    if(0 == pu1_avail[2])
500
19.1k
    {
501
19.1k
        pu1_src += src_strd;
502
19.1k
        ht--;
503
1.19M
        for(col = 0; col < wd; col++)
504
1.17M
        {
505
1.17M
            au1_sign_up[col] = SIGN(pu1_src[col] - pu1_src[col - src_strd]);
506
1.17M
        }
507
19.1k
    }
508
7.31k
    else
509
7.31k
    {
510
461k
        for(col = 0; col < wd; col++)
511
454k
        {
512
454k
            au1_sign_up[col] = SIGN(pu1_src[col] - pu1_src_top[col]);
513
454k
        }
514
7.31k
    }
515
26.4k
    if(0 == pu1_avail[3])
516
19.1k
    {
517
19.1k
        ht--;
518
19.1k
    }
519
520
    /* Processing is done on the intermediate buffer and the output is written to the source buffer */
521
26.4k
    {
522
802k
        for(row = 0; row < ht; row++)
523
776k
        {
524
48.4M
            for(col = 0; col < wd; col++)
525
47.6M
            {
526
47.6M
                WORD32 edge_idx;
527
47.6M
                WORD8 *pi1_sao_offset;
528
529
47.6M
                pi1_sao_offset = (0 == col % 2) ? pi1_sao_offset_u : pi1_sao_offset_v;
530
531
47.6M
                u1_sign_down = SIGN(pu1_src[col] - pu1_src[col + src_strd]);
532
47.6M
                edge_idx = 2 + au1_sign_up[col] + u1_sign_down;
533
47.6M
                au1_sign_up[col] = -u1_sign_down;
534
535
47.6M
                edge_idx = gi4_ihevc_table_edge_idx[edge_idx] & au1_mask[col >> 1];
536
537
47.6M
                if(0 != edge_idx)
538
3.00M
                {
539
3.00M
                    pu1_src[col] = CLIP3(pu1_src[col] + pi1_sao_offset[edge_idx], 0, (1 << bit_depth) - 1);
540
3.00M
                }
541
47.6M
            }
542
543
776k
            pu1_src += src_strd;
544
776k
        }
545
26.4k
    }
546
547
1.65M
    for(col = 0; col < wd; col++)
548
1.62M
    {
549
1.62M
        pu1_src_top[col] = au1_src_top_tmp[col];
550
1.62M
    }
551
552
26.4k
}
553
554
555
556
/* 135 degree filtering */
557
void ihevc_sao_edge_offset_class2(UWORD8 *pu1_src,
558
                                  WORD32 src_strd,
559
                                  UWORD8 *pu1_src_left,
560
                                  UWORD8 *pu1_src_top,
561
                                  UWORD8 *pu1_src_top_left,
562
                                  UWORD8 *pu1_src_top_right,
563
                                  UWORD8 *pu1_src_bot_left,
564
                                  UWORD8 *pu1_avail,
565
                                  WORD8 *pi1_sao_offset,
566
                                  WORD32 wd,
567
                                  WORD32 ht)
568
155k
{
569
155k
    WORD32 row, col;
570
155k
    UWORD8 au1_mask[MAX_CTB_SIZE];
571
155k
    UWORD8 au1_src_left_tmp[MAX_CTB_SIZE], au1_src_top_tmp[MAX_CTB_SIZE];
572
155k
    UWORD8 u1_src_top_left_tmp;
573
155k
    WORD8 au1_sign_up[MAX_CTB_SIZE + 1], au1_sign_up_tmp[MAX_CTB_SIZE + 1];
574
155k
    WORD8 u1_sign_down;
575
155k
    WORD8 *pu1_sign_up;
576
155k
    WORD8 *pu1_sign_up_tmp;
577
155k
    UWORD8 *pu1_src_left_cpy;
578
579
155k
    WORD32 bit_depth;
580
155k
    UWORD8 u1_pos_0_0_tmp;
581
155k
    UWORD8 u1_pos_wd_ht_tmp;
582
155k
    UNUSED(pu1_src_top_right);
583
155k
    UNUSED(pu1_src_bot_left);
584
585
155k
    bit_depth = BIT_DEPTH_LUMA;
586
155k
    pu1_sign_up = au1_sign_up;
587
155k
    pu1_sign_up_tmp = au1_sign_up_tmp;
588
155k
    pu1_src_left_cpy = pu1_src_left;
589
590
    /* Initialize the mask values */
591
155k
    memset(au1_mask, 0xFF, MAX_CTB_SIZE);
592
593
    /* Update left, top and top-left arrays */
594
155k
    u1_src_top_left_tmp = pu1_src_top[wd - 1];
595
9.70M
    for(row = 0; row < ht; row++)
596
9.54M
    {
597
9.54M
        au1_src_left_tmp[row] = pu1_src[row * src_strd + wd - 1];
598
9.54M
    }
599
9.74M
    for(col = 0; col < wd; col++)
600
9.59M
    {
601
9.59M
        au1_src_top_tmp[col] = pu1_src[(ht - 1) * src_strd + col];
602
9.59M
    }
603
604
605
    /* If top-left is available, process separately */
606
155k
    if(0 != pu1_avail[4])
607
48.5k
    {
608
48.5k
        WORD32 edge_idx;
609
610
48.5k
        edge_idx = 2 + SIGN(pu1_src[0] - pu1_src_top_left[0]) +
611
48.5k
                        SIGN(pu1_src[0] - pu1_src[1 + src_strd]);
612
613
48.5k
        edge_idx = gi4_ihevc_table_edge_idx[edge_idx];
614
615
48.5k
        if(0 != edge_idx)
616
2.90k
        {
617
2.90k
            u1_pos_0_0_tmp = CLIP3(pu1_src[0] + pi1_sao_offset[edge_idx], 0, (1 << bit_depth) - 1);
618
2.90k
        }
619
45.6k
        else
620
45.6k
        {
621
45.6k
            u1_pos_0_0_tmp = pu1_src[0];
622
45.6k
        }
623
48.5k
    }
624
106k
    else
625
106k
    {
626
106k
        u1_pos_0_0_tmp = pu1_src[0];
627
106k
    }
628
629
    /* If bottom-right is available, process separately */
630
155k
    if(0 != pu1_avail[7])
631
48.2k
    {
632
48.2k
        WORD32 edge_idx;
633
634
48.2k
        edge_idx = 2 + SIGN(pu1_src[wd - 1 + (ht - 1) * src_strd] - pu1_src[wd - 1 + (ht - 1) * src_strd - 1 - src_strd]) +
635
48.2k
                        SIGN(pu1_src[wd - 1 + (ht - 1) * src_strd] - pu1_src[wd - 1 + (ht - 1) * src_strd + 1 + src_strd]);
636
637
48.2k
        edge_idx = gi4_ihevc_table_edge_idx[edge_idx];
638
639
48.2k
        if(0 != edge_idx)
640
3.04k
        {
641
3.04k
            u1_pos_wd_ht_tmp = CLIP3(pu1_src[wd - 1 + (ht - 1) * src_strd] + pi1_sao_offset[edge_idx], 0, (1 << bit_depth) - 1);
642
3.04k
        }
643
45.2k
        else
644
45.2k
        {
645
45.2k
            u1_pos_wd_ht_tmp = pu1_src[wd - 1 + (ht - 1) * src_strd];
646
45.2k
        }
647
48.2k
    }
648
106k
    else
649
106k
    {
650
106k
        u1_pos_wd_ht_tmp = pu1_src[wd - 1 + (ht - 1) * src_strd];
651
106k
    }
652
653
    /* If Left is not available */
654
155k
    if(0 == pu1_avail[0])
655
81.1k
    {
656
81.1k
        au1_mask[0] = 0;
657
81.1k
    }
658
659
    /* If Top is not available */
660
155k
    if(0 == pu1_avail[2])
661
92.2k
    {
662
92.2k
        pu1_src += src_strd;
663
92.2k
        ht--;
664
92.2k
        pu1_src_left_cpy += 1;
665
5.70M
        for(col = 1; col < wd; col++)
666
5.61M
        {
667
5.61M
            pu1_sign_up[col] = SIGN(pu1_src[col] - pu1_src[col - 1 - src_strd]);
668
5.61M
        }
669
92.2k
    }
670
62.7k
    else
671
62.7k
    {
672
3.88M
        for(col = 1; col < wd; col++)
673
3.82M
        {
674
3.82M
            pu1_sign_up[col] = SIGN(pu1_src[col] - pu1_src_top[col - 1]);
675
3.82M
        }
676
62.7k
    }
677
678
    /* If Right is not available */
679
155k
    if(0 == pu1_avail[1])
680
81.2k
    {
681
81.2k
        au1_mask[wd - 1] = 0;
682
81.2k
    }
683
684
    /* If Bottom is not available */
685
155k
    if(0 == pu1_avail[3])
686
92.4k
    {
687
92.4k
        ht--;
688
92.4k
    }
689
690
    /* Processing is done on the intermediate buffer and the output is written to the source buffer */
691
155k
    {
692
9.51M
        for(row = 0; row < ht; row++)
693
9.36M
        {
694
9.36M
            pu1_sign_up[0] = SIGN(pu1_src[0] - pu1_src_left_cpy[row - 1]);
695
589M
            for(col = 0; col < wd; col++)
696
579M
            {
697
579M
                WORD32 edge_idx;
698
699
579M
                u1_sign_down = SIGN(pu1_src[col] - pu1_src[col + 1 + src_strd]);
700
579M
                edge_idx = 2 + pu1_sign_up[col] + u1_sign_down;
701
579M
                pu1_sign_up_tmp[col + 1] = -u1_sign_down;
702
703
579M
                edge_idx = gi4_ihevc_table_edge_idx[edge_idx] & au1_mask[col];
704
705
579M
                if(0 != edge_idx)
706
27.7M
                {
707
27.7M
                    pu1_src[col] = CLIP3(pu1_src[col] + pi1_sao_offset[edge_idx], 0, (1 << bit_depth) - 1);
708
27.7M
                }
709
579M
            }
710
711
            /* Swapping pu1_sign_up_tmp and pu1_sign_up */
712
9.36M
            {
713
9.36M
                WORD8 *pu1_swap_tmp = pu1_sign_up;
714
9.36M
                pu1_sign_up = pu1_sign_up_tmp;
715
9.36M
                pu1_sign_up_tmp = pu1_swap_tmp;
716
9.36M
            }
717
718
9.36M
            pu1_src += src_strd;
719
9.36M
        }
720
721
155k
        pu1_src[-(pu1_avail[2] ? ht : ht + 1) * src_strd] = u1_pos_0_0_tmp;
722
155k
        pu1_src[(pu1_avail[3] ? wd - 1 - src_strd : wd - 1)] = u1_pos_wd_ht_tmp;
723
155k
    }
724
725
155k
    if(0 == pu1_avail[2])
726
92.2k
        ht++;
727
155k
    if(0 == pu1_avail[3])
728
92.4k
        ht++;
729
155k
    *pu1_src_top_left = u1_src_top_left_tmp;
730
9.70M
    for(row = 0; row < ht; row++)
731
9.54M
    {
732
9.54M
        pu1_src_left[row] = au1_src_left_tmp[row];
733
9.54M
    }
734
9.74M
    for(col = 0; col < wd; col++)
735
9.59M
    {
736
9.59M
        pu1_src_top[col] = au1_src_top_tmp[col];
737
9.59M
    }
738
739
155k
}
740
741
742
743
744
/* 135 degree filtering */
745
void ihevc_sao_edge_offset_class2_chroma(UWORD8 *pu1_src,
746
                                         WORD32 src_strd,
747
                                         UWORD8 *pu1_src_left,
748
                                         UWORD8 *pu1_src_top,
749
                                         UWORD8 *pu1_src_top_left,
750
                                         UWORD8 *pu1_src_top_right,
751
                                         UWORD8 *pu1_src_bot_left,
752
                                         UWORD8 *pu1_avail,
753
                                         WORD8 *pi1_sao_offset_u,
754
                                         WORD8 *pi1_sao_offset_v,
755
                                         WORD32 wd,
756
                                         WORD32 ht)
757
17.3k
{
758
17.3k
    WORD32 row, col;
759
17.3k
    UWORD8 au1_mask[MAX_CTB_SIZE];
760
17.3k
    UWORD8 au1_src_left_tmp[2 * MAX_CTB_SIZE], au1_src_top_tmp[MAX_CTB_SIZE];
761
17.3k
    UWORD8 au1_src_top_left_tmp[2];
762
17.3k
    WORD8 au1_sign_up[MAX_CTB_SIZE + 2], au1_sign_up_tmp[MAX_CTB_SIZE + 2];
763
17.3k
    WORD8 u1_sign_down;
764
17.3k
    WORD8 *pu1_sign_up;
765
17.3k
    WORD8 *pu1_sign_up_tmp;
766
17.3k
    UWORD8 *pu1_src_left_cpy;
767
768
17.3k
    WORD32 bit_depth;
769
770
17.3k
    UWORD8 u1_pos_0_0_tmp_u;
771
17.3k
    UWORD8 u1_pos_0_0_tmp_v;
772
17.3k
    UWORD8 u1_pos_wd_ht_tmp_u;
773
17.3k
    UWORD8 u1_pos_wd_ht_tmp_v;
774
17.3k
    UNUSED(pu1_src_top_right);
775
17.3k
    UNUSED(pu1_src_bot_left);
776
777
778
17.3k
    bit_depth = BIT_DEPTH_CHROMA;
779
17.3k
    pu1_sign_up = au1_sign_up;
780
17.3k
    pu1_sign_up_tmp = au1_sign_up_tmp;
781
17.3k
    pu1_src_left_cpy = pu1_src_left;
782
783
    /* Initialize the mask values */
784
17.3k
    memset(au1_mask, 0xFF, MAX_CTB_SIZE);
785
786
    /* Update left, top and top-left arrays */
787
17.3k
    au1_src_top_left_tmp[0] = pu1_src_top[wd - 2];
788
17.3k
    au1_src_top_left_tmp[1] = pu1_src_top[wd - 1];
789
545k
    for(row = 0; row < ht; row++)
790
527k
    {
791
527k
        au1_src_left_tmp[2 * row] = pu1_src[row * src_strd + wd - 2];
792
527k
        au1_src_left_tmp[2 * row + 1] = pu1_src[row * src_strd + wd - 1];
793
527k
    }
794
1.08M
    for(col = 0; col < wd; col++)
795
1.06M
    {
796
1.06M
        au1_src_top_tmp[col] = pu1_src[(ht - 1) * src_strd + col];
797
1.06M
    }
798
799
800
    /* If top-left is available, process separately */
801
17.3k
    if(0 != pu1_avail[4])
802
5.69k
    {
803
5.69k
        WORD32 edge_idx;
804
805
        /* U */
806
5.69k
        edge_idx = 2 + SIGN(pu1_src[0] - pu1_src_top_left[0]) +
807
5.69k
                        SIGN(pu1_src[0] - pu1_src[2 + src_strd]);
808
809
5.69k
        edge_idx = gi4_ihevc_table_edge_idx[edge_idx];
810
811
5.69k
        if(0 != edge_idx)
812
485
        {
813
485
            u1_pos_0_0_tmp_u = CLIP3(pu1_src[0] + pi1_sao_offset_u[edge_idx], 0, (1 << bit_depth) - 1);
814
485
        }
815
5.20k
        else
816
5.20k
        {
817
5.20k
            u1_pos_0_0_tmp_u = pu1_src[0];
818
5.20k
        }
819
820
        /* V */
821
5.69k
        edge_idx = 2 + SIGN(pu1_src[1] - pu1_src_top_left[1]) +
822
5.69k
                        SIGN(pu1_src[1] - pu1_src[1 + 2 + src_strd]);
823
824
5.69k
        edge_idx = gi4_ihevc_table_edge_idx[edge_idx];
825
826
5.69k
        if(0 != edge_idx)
827
377
        {
828
377
            u1_pos_0_0_tmp_v = CLIP3(pu1_src[1] + pi1_sao_offset_v[edge_idx], 0, (1 << bit_depth) - 1);
829
377
        }
830
5.31k
        else
831
5.31k
        {
832
5.31k
            u1_pos_0_0_tmp_v = pu1_src[1];
833
5.31k
        }
834
5.69k
    }
835
11.6k
    else
836
11.6k
    {
837
11.6k
        u1_pos_0_0_tmp_u = pu1_src[0];
838
11.6k
        u1_pos_0_0_tmp_v = pu1_src[1];
839
11.6k
    }
840
841
    /* If bottom-right is available, process separately */
842
17.3k
    if(0 != pu1_avail[7])
843
5.34k
    {
844
5.34k
        WORD32 edge_idx;
845
846
        /* U */
847
5.34k
        edge_idx = 2 + SIGN(pu1_src[wd - 2 + (ht - 1) * src_strd] - pu1_src[wd - 2 + (ht - 1) * src_strd - 2 - src_strd]) +
848
5.34k
                        SIGN(pu1_src[wd - 2 + (ht - 1) * src_strd] - pu1_src[wd - 2 + (ht - 1) * src_strd + 2 + src_strd]);
849
850
5.34k
        edge_idx = gi4_ihevc_table_edge_idx[edge_idx];
851
852
5.34k
        if(0 != edge_idx)
853
516
        {
854
516
            u1_pos_wd_ht_tmp_u = CLIP3(pu1_src[wd - 2 + (ht - 1) * src_strd] + pi1_sao_offset_u[edge_idx], 0, (1 << bit_depth) - 1);
855
516
        }
856
4.82k
        else
857
4.82k
        {
858
4.82k
            u1_pos_wd_ht_tmp_u = pu1_src[wd - 2 + (ht - 1) * src_strd];
859
4.82k
        }
860
861
        /* V */
862
5.34k
        edge_idx = 2 + SIGN(pu1_src[wd - 1 + (ht - 1) * src_strd] - pu1_src[wd - 1 + (ht - 1) * src_strd - 2 - src_strd]) +
863
5.34k
                        SIGN(pu1_src[wd - 1 + (ht - 1) * src_strd] - pu1_src[wd - 1 + (ht - 1) * src_strd + 2 + src_strd]);
864
865
5.34k
        edge_idx = gi4_ihevc_table_edge_idx[edge_idx];
866
867
5.34k
        if(0 != edge_idx)
868
387
        {
869
387
            u1_pos_wd_ht_tmp_v = CLIP3(pu1_src[wd - 1 + (ht - 1) * src_strd] + pi1_sao_offset_v[edge_idx], 0, (1 << bit_depth) - 1);
870
387
        }
871
4.95k
        else
872
4.95k
        {
873
4.95k
            u1_pos_wd_ht_tmp_v = pu1_src[wd - 1 + (ht - 1) * src_strd];
874
4.95k
        }
875
5.34k
    }
876
11.9k
    else
877
11.9k
    {
878
11.9k
        u1_pos_wd_ht_tmp_u = pu1_src[wd - 2 + (ht - 1) * src_strd];
879
11.9k
        u1_pos_wd_ht_tmp_v = pu1_src[wd - 1 + (ht - 1) * src_strd];
880
11.9k
    }
881
882
    /* If Left is not available */
883
17.3k
    if(0 == pu1_avail[0])
884
8.82k
    {
885
8.82k
        au1_mask[0] = 0;
886
8.82k
    }
887
888
    /* If Top is not available */
889
17.3k
    if(0 == pu1_avail[2])
890
10.0k
    {
891
10.0k
        pu1_src += src_strd;
892
10.0k
        pu1_src_left_cpy += 2;
893
10.0k
        ht--;
894
605k
        for(col = 2; col < wd; col++)
895
595k
        {
896
595k
            pu1_sign_up[col] = SIGN(pu1_src[col] - pu1_src[col - 2 - src_strd]);
897
595k
        }
898
10.0k
    }
899
7.25k
    else
900
7.25k
    {
901
442k
        for(col = 2; col < wd; col++)
902
434k
        {
903
434k
            pu1_sign_up[col] = SIGN(pu1_src[col] - pu1_src_top[col - 2]);
904
434k
        }
905
7.25k
    }
906
907
    /* If Right is not available */
908
17.3k
    if(0 == pu1_avail[1])
909
8.96k
    {
910
8.96k
        au1_mask[(wd - 1) >> 1] = 0;
911
8.96k
    }
912
913
    /* If Bottom is not available */
914
17.3k
    if(0 == pu1_avail[3])
915
10.2k
    {
916
10.2k
        ht--;
917
10.2k
    }
918
919
    /* Processing is done on the intermediate buffer and the output is written to the source buffer */
920
17.3k
    {
921
524k
        for(row = 0; row < ht; row++)
922
507k
        {
923
507k
            pu1_sign_up[0] = SIGN(pu1_src[0] - pu1_src_left_cpy[2 * (row - 1)]);
924
507k
            pu1_sign_up[1] = SIGN(pu1_src[1] - pu1_src_left_cpy[2 * (row - 1) + 1]);
925
31.7M
            for(col = 0; col < wd; col++)
926
31.2M
            {
927
31.2M
                WORD32 edge_idx;
928
31.2M
                WORD8 *pi1_sao_offset;
929
930
31.2M
                pi1_sao_offset = (0 == col % 2) ? pi1_sao_offset_u : pi1_sao_offset_v;
931
932
31.2M
                u1_sign_down = SIGN(pu1_src[col] - pu1_src[col + 2 + src_strd]);
933
31.2M
                edge_idx = 2 + pu1_sign_up[col] + u1_sign_down;
934
31.2M
                pu1_sign_up_tmp[col + 2] = -u1_sign_down;
935
936
31.2M
                edge_idx = gi4_ihevc_table_edge_idx[edge_idx] & au1_mask[col >> 1];
937
938
31.2M
                if(0 != edge_idx)
939
2.39M
                {
940
2.39M
                    pu1_src[col] = CLIP3(pu1_src[col] + pi1_sao_offset[edge_idx], 0, (1 << bit_depth) - 1);
941
2.39M
                }
942
31.2M
            }
943
944
            /* Swapping pu1_sign_up_tmp and pu1_sign_up */
945
507k
            {
946
507k
                WORD8 *pu1_swap_tmp = pu1_sign_up;
947
507k
                pu1_sign_up = pu1_sign_up_tmp;
948
507k
                pu1_sign_up_tmp = pu1_swap_tmp;
949
507k
            }
950
951
507k
            pu1_src += src_strd;
952
507k
        }
953
954
17.3k
        pu1_src[-(pu1_avail[2] ? ht : ht + 1) * src_strd] = u1_pos_0_0_tmp_u;
955
17.3k
        pu1_src[-(pu1_avail[2] ? ht : ht + 1) * src_strd + 1] = u1_pos_0_0_tmp_v;
956
17.3k
        pu1_src[(pu1_avail[3] ? wd - 2 - src_strd : wd - 2)] = u1_pos_wd_ht_tmp_u;
957
17.3k
        pu1_src[(pu1_avail[3] ? wd - 1 - src_strd : wd - 1)] = u1_pos_wd_ht_tmp_v;
958
17.3k
    }
959
960
17.3k
    if(0 == pu1_avail[2])
961
10.0k
        ht++;
962
17.3k
    if(0 == pu1_avail[3])
963
10.2k
        ht++;
964
17.3k
    pu1_src_top_left[0] = au1_src_top_left_tmp[0];
965
17.3k
    pu1_src_top_left[1] = au1_src_top_left_tmp[1];
966
1.07M
    for(row = 0; row < 2 * ht; row++)
967
1.05M
    {
968
1.05M
        pu1_src_left[row] = au1_src_left_tmp[row];
969
1.05M
    }
970
1.08M
    for(col = 0; col < wd; col++)
971
1.06M
    {
972
1.06M
        pu1_src_top[col] = au1_src_top_tmp[col];
973
1.06M
    }
974
975
17.3k
}
976
977
978
979
980
/* 45 degree filtering */
981
void ihevc_sao_edge_offset_class3(UWORD8 *pu1_src,
982
                                  WORD32 src_strd,
983
                                  UWORD8 *pu1_src_left,
984
                                  UWORD8 *pu1_src_top,
985
                                  UWORD8 *pu1_src_top_left,
986
                                  UWORD8 *pu1_src_top_right,
987
                                  UWORD8 *pu1_src_bot_left,
988
                                  UWORD8 *pu1_avail,
989
                                  WORD8 *pi1_sao_offset,
990
                                  WORD32 wd,
991
                                  WORD32 ht)
992
153k
{
993
153k
    WORD32 row, col;
994
153k
    UWORD8 au1_mask[MAX_CTB_SIZE];
995
153k
    UWORD8 au1_src_top_tmp[MAX_CTB_SIZE];
996
153k
    UWORD8 au1_src_left_tmp[MAX_CTB_SIZE];
997
153k
    UWORD8 u1_src_top_left_tmp;
998
153k
    WORD8 au1_sign_up[MAX_CTB_SIZE];
999
153k
    UWORD8 *pu1_src_left_cpy;
1000
153k
    WORD8 u1_sign_down;
1001
153k
    WORD32 bit_depth;
1002
1003
153k
    UWORD8 u1_pos_0_ht_tmp;
1004
153k
    UWORD8 u1_pos_wd_0_tmp;
1005
1006
153k
    bit_depth = BIT_DEPTH_LUMA;
1007
153k
    pu1_src_left_cpy = pu1_src_left;
1008
1009
    /* Initialize the mask values */
1010
153k
    memset(au1_mask, 0xFF, MAX_CTB_SIZE);
1011
1012
    /* Update left, top and top-left arrays */
1013
153k
    u1_src_top_left_tmp = pu1_src_top[wd - 1];
1014
9.59M
    for(row = 0; row < ht; row++)
1015
9.44M
    {
1016
9.44M
        au1_src_left_tmp[row] = pu1_src[row * src_strd + wd - 1];
1017
9.44M
    }
1018
9.64M
    for(col = 0; col < wd; col++)
1019
9.49M
    {
1020
9.49M
        au1_src_top_tmp[col] = pu1_src[(ht - 1) * src_strd + col];
1021
9.49M
    }
1022
1023
    /* If top-right is available, process separately */
1024
153k
    if(0 != pu1_avail[5])
1025
47.2k
    {
1026
47.2k
        WORD32 edge_idx;
1027
1028
47.2k
        edge_idx = 2 + SIGN(pu1_src[wd - 1] - pu1_src_top_right[0]) +
1029
47.2k
                        SIGN(pu1_src[wd - 1] - pu1_src[wd - 1 - 1 + src_strd]);
1030
1031
47.2k
        edge_idx = gi4_ihevc_table_edge_idx[edge_idx];
1032
1033
47.2k
        if(0 != edge_idx)
1034
2.89k
        {
1035
2.89k
            u1_pos_wd_0_tmp = CLIP3(pu1_src[wd - 1] + pi1_sao_offset[edge_idx], 0, (1 << bit_depth) - 1);
1036
2.89k
        }
1037
44.4k
        else
1038
44.4k
        {
1039
44.4k
            u1_pos_wd_0_tmp = pu1_src[wd - 1];
1040
44.4k
        }
1041
47.2k
    }
1042
106k
    else
1043
106k
    {
1044
106k
        u1_pos_wd_0_tmp = pu1_src[wd - 1];
1045
106k
    }
1046
1047
    /* If bottom-left is available, process separately */
1048
153k
    if(0 != pu1_avail[6])
1049
47.3k
    {
1050
47.3k
        WORD32 edge_idx;
1051
1052
47.3k
        edge_idx = 2 + SIGN(pu1_src[(ht - 1) * src_strd] - pu1_src[(ht - 1) * src_strd + 1 - src_strd]) +
1053
47.3k
                        SIGN(pu1_src[(ht - 1) * src_strd] - pu1_src_bot_left[0]);
1054
1055
47.3k
        edge_idx = gi4_ihevc_table_edge_idx[edge_idx];
1056
1057
47.3k
        if(0 != edge_idx)
1058
2.84k
        {
1059
2.84k
            u1_pos_0_ht_tmp = CLIP3(pu1_src[(ht - 1) * src_strd] + pi1_sao_offset[edge_idx], 0, (1 << bit_depth) - 1);
1060
2.84k
        }
1061
44.4k
        else
1062
44.4k
        {
1063
44.4k
            u1_pos_0_ht_tmp = pu1_src[(ht - 1) * src_strd];
1064
44.4k
        }
1065
47.3k
    }
1066
106k
    else
1067
106k
    {
1068
106k
        u1_pos_0_ht_tmp = pu1_src[(ht - 1) * src_strd];
1069
106k
    }
1070
1071
    /* If Left is not available */
1072
153k
    if(0 == pu1_avail[0])
1073
81.2k
    {
1074
81.2k
        au1_mask[0] = 0;
1075
81.2k
    }
1076
1077
    /* If Top is not available */
1078
153k
    if(0 == pu1_avail[2])
1079
91.7k
    {
1080
91.7k
        pu1_src += src_strd;
1081
91.7k
        ht--;
1082
91.7k
        pu1_src_left_cpy += 1;
1083
5.68M
        for(col = 0; col < wd - 1; col++)
1084
5.58M
        {
1085
5.58M
            au1_sign_up[col] = SIGN(pu1_src[col] - pu1_src[col + 1 - src_strd]);
1086
5.58M
        }
1087
91.7k
    }
1088
61.6k
    else
1089
61.6k
    {
1090
3.80M
        for(col = 0; col < wd - 1; col++)
1091
3.74M
        {
1092
3.74M
            au1_sign_up[col] = SIGN(pu1_src[col] - pu1_src_top[col + 1]);
1093
3.74M
        }
1094
61.6k
    }
1095
1096
    /* If Right is not available */
1097
153k
    if(0 == pu1_avail[1])
1098
81.4k
    {
1099
81.4k
        au1_mask[wd - 1] = 0;
1100
81.4k
    }
1101
1102
    /* If Bottom is not available */
1103
153k
    if(0 == pu1_avail[3])
1104
92.0k
    {
1105
92.0k
        ht--;
1106
92.0k
    }
1107
1108
    /* Processing is done on the intermediate buffer and the output is written to the source buffer */
1109
153k
    {
1110
9.41M
        for(row = 0; row < ht; row++)
1111
9.26M
        {
1112
9.26M
            au1_sign_up[wd - 1] = SIGN(pu1_src[wd - 1] - pu1_src[wd - 1 + 1 - src_strd]);
1113
582M
            for(col = 0; col < wd; col++)
1114
573M
            {
1115
573M
                WORD32 edge_idx;
1116
1117
573M
                u1_sign_down = SIGN(pu1_src[col] - ((col == 0) ? pu1_src_left_cpy[row + 1] :
1118
573M
                                                                 pu1_src[col - 1 + src_strd]));
1119
573M
                edge_idx = 2 + au1_sign_up[col] + u1_sign_down;
1120
573M
                if(col > 0)
1121
564M
                    au1_sign_up[col - 1] = -u1_sign_down;
1122
1123
573M
                edge_idx = gi4_ihevc_table_edge_idx[edge_idx] & au1_mask[col];
1124
1125
573M
                if(0 != edge_idx)
1126
27.4M
                {
1127
27.4M
                    pu1_src[col] = CLIP3(pu1_src[col] + pi1_sao_offset[edge_idx], 0, (1 << bit_depth) - 1);
1128
27.4M
                }
1129
573M
            }
1130
1131
9.26M
            pu1_src += src_strd;
1132
9.26M
        }
1133
1134
153k
        pu1_src[-(pu1_avail[2] ? ht : ht + 1) * src_strd + wd - 1] = u1_pos_wd_0_tmp;
1135
153k
        pu1_src[(pu1_avail[3] ?  (-src_strd) : 0)] = u1_pos_0_ht_tmp;
1136
153k
    }
1137
1138
153k
    if(0 == pu1_avail[2])
1139
91.7k
        ht++;
1140
153k
    if(0 == pu1_avail[3])
1141
92.0k
        ht++;
1142
153k
    *pu1_src_top_left = u1_src_top_left_tmp;
1143
9.59M
    for(row = 0; row < ht; row++)
1144
9.44M
    {
1145
9.44M
        pu1_src_left[row] = au1_src_left_tmp[row];
1146
9.44M
    }
1147
9.64M
    for(col = 0; col < wd; col++)
1148
9.49M
    {
1149
9.49M
        pu1_src_top[col] = au1_src_top_tmp[col];
1150
9.49M
    }
1151
1152
153k
}
1153
1154
1155
1156
1157
void ihevc_sao_edge_offset_class3_chroma(UWORD8 *pu1_src,
1158
                                         WORD32 src_strd,
1159
                                         UWORD8 *pu1_src_left,
1160
                                         UWORD8 *pu1_src_top,
1161
                                         UWORD8 *pu1_src_top_left,
1162
                                         UWORD8 *pu1_src_top_right,
1163
                                         UWORD8 *pu1_src_bot_left,
1164
                                         UWORD8 *pu1_avail,
1165
                                         WORD8 *pi1_sao_offset_u,
1166
                                         WORD8 *pi1_sao_offset_v,
1167
                                         WORD32 wd,
1168
                                         WORD32 ht)
1169
15.6k
{
1170
15.6k
    WORD32 row, col;
1171
15.6k
    UWORD8 au1_mask[MAX_CTB_SIZE];
1172
15.6k
    UWORD8 au1_src_left_tmp[2 * MAX_CTB_SIZE], au1_src_top_tmp[MAX_CTB_SIZE];
1173
15.6k
    UWORD8 au1_src_top_left_tmp[2];
1174
15.6k
    WORD8 au1_sign_up[MAX_CTB_SIZE];
1175
15.6k
    UWORD8 *pu1_src_left_cpy;
1176
15.6k
    WORD8 u1_sign_down;
1177
15.6k
    WORD32 bit_depth;
1178
1179
15.6k
    UWORD8 u1_pos_wd_0_tmp_u;
1180
15.6k
    UWORD8 u1_pos_wd_0_tmp_v;
1181
15.6k
    UWORD8 u1_pos_0_ht_tmp_u;
1182
15.6k
    UWORD8 u1_pos_0_ht_tmp_v;
1183
1184
15.6k
    bit_depth = BIT_DEPTH_CHROMA;
1185
15.6k
    pu1_src_left_cpy = pu1_src_left;
1186
1187
    /* Initialize the mask values */
1188
15.6k
    memset(au1_mask, 0xFF, MAX_CTB_SIZE);
1189
1190
    /* Update left, top and top-left arrays */
1191
15.6k
    au1_src_top_left_tmp[0] = pu1_src_top[wd - 2];
1192
15.6k
    au1_src_top_left_tmp[1] = pu1_src_top[wd - 1];
1193
493k
    for(row = 0; row < ht; row++)
1194
477k
    {
1195
477k
        au1_src_left_tmp[2 * row] = pu1_src[row * src_strd + wd - 2];
1196
477k
        au1_src_left_tmp[2 * row + 1] = pu1_src[row * src_strd + wd - 1];
1197
477k
    }
1198
977k
    for(col = 0; col < wd; col++)
1199
961k
    {
1200
961k
        au1_src_top_tmp[col] = pu1_src[(ht - 1) * src_strd + col];
1201
961k
    }
1202
1203
1204
    /* If top-right is available, process separately */
1205
15.6k
    if(0 != pu1_avail[5])
1206
4.38k
    {
1207
4.38k
        WORD32 edge_idx;
1208
1209
        /* U */
1210
4.38k
        edge_idx = 2 + SIGN(pu1_src[wd - 2] - pu1_src_top_right[0]) +
1211
4.38k
                        SIGN(pu1_src[wd - 2] - pu1_src[wd - 2 - 2 + src_strd]);
1212
1213
4.38k
        edge_idx = gi4_ihevc_table_edge_idx[edge_idx];
1214
1215
4.38k
        if(0 != edge_idx)
1216
655
        {
1217
655
            u1_pos_wd_0_tmp_u = CLIP3(pu1_src[wd - 2] + pi1_sao_offset_u[edge_idx], 0, (1 << bit_depth) - 1);
1218
655
        }
1219
3.73k
        else
1220
3.73k
        {
1221
3.73k
            u1_pos_wd_0_tmp_u = pu1_src[wd - 2];
1222
3.73k
        }
1223
1224
        /* V */
1225
4.38k
        edge_idx = 2 + SIGN(pu1_src[wd - 1] - pu1_src_top_right[1]) +
1226
4.38k
                        SIGN(pu1_src[wd - 1] - pu1_src[wd - 1 - 2 + src_strd]);
1227
1228
4.38k
        edge_idx = gi4_ihevc_table_edge_idx[edge_idx];
1229
1230
4.38k
        if(0 != edge_idx)
1231
412
        {
1232
412
            u1_pos_wd_0_tmp_v = CLIP3(pu1_src[wd - 1] + pi1_sao_offset_v[edge_idx], 0, (1 << bit_depth) - 1);
1233
412
        }
1234
3.97k
        else
1235
3.97k
        {
1236
3.97k
            u1_pos_wd_0_tmp_v = pu1_src[wd - 1];
1237
3.97k
        }
1238
4.38k
    }
1239
11.2k
    else
1240
11.2k
    {
1241
11.2k
        u1_pos_wd_0_tmp_u = pu1_src[wd - 2];
1242
11.2k
        u1_pos_wd_0_tmp_v = pu1_src[wd - 1];
1243
11.2k
    }
1244
1245
    /* If bottom-left is available, process separately */
1246
15.6k
    if(0 != pu1_avail[6])
1247
4.38k
    {
1248
4.38k
        WORD32 edge_idx;
1249
1250
        /* U */
1251
4.38k
        edge_idx = 2 + SIGN(pu1_src[(ht - 1) * src_strd] - pu1_src[(ht - 1) * src_strd + 2 - src_strd]) +
1252
4.38k
                        SIGN(pu1_src[(ht - 1) * src_strd] - pu1_src_bot_left[0]);
1253
1254
4.38k
        edge_idx = gi4_ihevc_table_edge_idx[edge_idx];
1255
1256
4.38k
        if(0 != edge_idx)
1257
636
        {
1258
636
            u1_pos_0_ht_tmp_u = CLIP3(pu1_src[(ht - 1) * src_strd] + pi1_sao_offset_u[edge_idx], 0, (1 << bit_depth) - 1);
1259
636
        }
1260
3.74k
        else
1261
3.74k
        {
1262
3.74k
            u1_pos_0_ht_tmp_u = pu1_src[(ht - 1) * src_strd];
1263
3.74k
        }
1264
1265
        /* V */
1266
4.38k
        edge_idx = 2 + SIGN(pu1_src[(ht - 1) * src_strd + 1] - pu1_src[(ht - 1) * src_strd + 1 + 2 - src_strd]) +
1267
4.38k
                        SIGN(pu1_src[(ht - 1) * src_strd + 1] - pu1_src_bot_left[1]);
1268
1269
4.38k
        edge_idx = gi4_ihevc_table_edge_idx[edge_idx];
1270
1271
4.38k
        if(0 != edge_idx)
1272
418
        {
1273
418
            u1_pos_0_ht_tmp_v = CLIP3(pu1_src[(ht - 1) * src_strd + 1] + pi1_sao_offset_v[edge_idx], 0, (1 << bit_depth) - 1);
1274
418
        }
1275
3.96k
        else
1276
3.96k
        {
1277
3.96k
            u1_pos_0_ht_tmp_v = pu1_src[(ht - 1) * src_strd + 1];
1278
3.96k
        }
1279
4.38k
    }
1280
11.3k
    else
1281
11.3k
    {
1282
11.3k
        u1_pos_0_ht_tmp_u = pu1_src[(ht - 1) * src_strd];
1283
11.3k
        u1_pos_0_ht_tmp_v = pu1_src[(ht - 1) * src_strd + 1];
1284
11.3k
    }
1285
1286
    /* If Left is not available */
1287
15.6k
    if(0 == pu1_avail[0])
1288
8.93k
    {
1289
8.93k
        au1_mask[0] = 0;
1290
8.93k
    }
1291
1292
    /* If Top is not available */
1293
15.6k
    if(0 == pu1_avail[2])
1294
9.55k
    {
1295
9.55k
        pu1_src += src_strd;
1296
9.55k
        ht--;
1297
9.55k
        pu1_src_left_cpy += 2;
1298
576k
        for(col = 0; col < wd - 2; col++)
1299
567k
        {
1300
567k
            au1_sign_up[col] = SIGN(pu1_src[col] - pu1_src[col + 2 - src_strd]);
1301
567k
        }
1302
9.55k
    }
1303
6.13k
    else
1304
6.13k
    {
1305
368k
        for(col = 0; col < wd - 2; col++)
1306
362k
        {
1307
362k
            au1_sign_up[col] = SIGN(pu1_src[col] - pu1_src_top[col + 2]);
1308
362k
        }
1309
6.13k
    }
1310
1311
    /* If Right is not available */
1312
15.6k
    if(0 == pu1_avail[1])
1313
9.13k
    {
1314
9.13k
        au1_mask[(wd - 1) >> 1] = 0;
1315
9.13k
    }
1316
1317
    /* If Bottom is not available */
1318
15.6k
    if(0 == pu1_avail[3])
1319
9.87k
    {
1320
9.87k
        ht--;
1321
9.87k
    }
1322
1323
    /* Processing is done on the intermediate buffer and the output is written to the source buffer */
1324
15.6k
    {
1325
473k
        for(row = 0; row < ht; row++)
1326
458k
        {
1327
458k
            au1_sign_up[wd - 2] = SIGN(pu1_src[wd - 2] - pu1_src[wd - 2 + 2 - src_strd]);
1328
458k
            au1_sign_up[wd - 1] = SIGN(pu1_src[wd - 1] - pu1_src[wd - 1 + 2 - src_strd]);
1329
28.6M
            for(col = 0; col < wd; col++)
1330
28.1M
            {
1331
28.1M
                WORD32 edge_idx;
1332
28.1M
                WORD8 *pi1_sao_offset;
1333
1334
28.1M
                pi1_sao_offset = (0 == col % 2) ? pi1_sao_offset_u : pi1_sao_offset_v;
1335
1336
28.1M
                u1_sign_down = SIGN(pu1_src[col] - ((col < 2) ? pu1_src_left_cpy[2 * (row + 1) + col] :
1337
28.1M
                                                                pu1_src[col - 2 + src_strd]));
1338
28.1M
                edge_idx = 2 + au1_sign_up[col] + u1_sign_down;
1339
28.1M
                if(col > 1)
1340
27.2M
                    au1_sign_up[col - 2] = -u1_sign_down;
1341
1342
28.1M
                edge_idx = gi4_ihevc_table_edge_idx[edge_idx] & au1_mask[col >> 1];
1343
1344
28.1M
                if(0 != edge_idx)
1345
2.47M
                {
1346
2.47M
                    pu1_src[col] = CLIP3(pu1_src[col] + pi1_sao_offset[edge_idx], 0, (1 << bit_depth) - 1);
1347
2.47M
                }
1348
28.1M
            }
1349
1350
458k
            pu1_src += src_strd;
1351
458k
        }
1352
1353
15.6k
        pu1_src[-(pu1_avail[2] ? ht : ht + 1) * src_strd + wd - 2] = u1_pos_wd_0_tmp_u;
1354
15.6k
        pu1_src[-(pu1_avail[2] ? ht : ht + 1) * src_strd + wd - 1] = u1_pos_wd_0_tmp_v;
1355
15.6k
        pu1_src[(pu1_avail[3] ?  (-src_strd) : 0)] = u1_pos_0_ht_tmp_u;
1356
15.6k
        pu1_src[(pu1_avail[3] ?  (-src_strd) : 0) + 1] = u1_pos_0_ht_tmp_v;
1357
15.6k
    }
1358
1359
15.6k
    if(0 == pu1_avail[2])
1360
9.55k
        ht++;
1361
15.6k
    if(0 == pu1_avail[3])
1362
9.87k
        ht++;
1363
15.6k
    pu1_src_top_left[0] = au1_src_top_left_tmp[0];
1364
15.6k
    pu1_src_top_left[1] = au1_src_top_left_tmp[1];
1365
970k
    for(row = 0; row < 2 * ht; row++)
1366
955k
    {
1367
955k
        pu1_src_left[row] = au1_src_left_tmp[row];
1368
955k
    }
1369
977k
    for(col = 0; col < wd; col++)
1370
961k
    {
1371
961k
        pu1_src_top[col] = au1_src_top_tmp[col];
1372
961k
    }
1373
1374
15.6k
}