Coverage Report

Created: 2026-01-10 07:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
10.3M
#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
206k
{
82
206k
    WORD32 band_shift;
83
206k
    WORD32 band_table[NUM_BAND_TABLE];
84
206k
    WORD32 i;
85
206k
    WORD32 row, col;
86
87
    /* Updating left and top and top-left */
88
6.29M
    for(row = 0; row < ht; row++)
89
6.08M
    {
90
6.08M
        pu1_src_left[row] = pu1_src[row * src_strd + (wd - 1)];
91
6.08M
    }
92
206k
    pu1_src_top_left[0] = pu1_src_top[wd - 1];
93
6.44M
    for(col = 0; col < wd; col++)
94
6.23M
    {
95
6.23M
        pu1_src_top[col] = pu1_src[(ht - 1) * src_strd + col];
96
6.23M
    }
97
98
206k
    band_shift = BIT_DEPTH_LUMA - 5;
99
6.79M
    for(i = 0; i < NUM_BAND_TABLE; i++)
100
6.58M
    {
101
6.58M
        band_table[i] = 0;
102
6.58M
    }
103
1.02M
    for(i = 0; i < 4; i++)
104
823k
    {
105
823k
        band_table[(i + sao_band_pos) & 31] = i + 1;
106
823k
    }
107
108
6.25M
    for(row = 0; row < ht; row++)
109
6.05M
    {
110
200M
        for(col = 0; col < wd; col++)
111
194M
        {
112
194M
            WORD32 band_idx;
113
114
194M
            band_idx = band_table[pu1_src[col] >> band_shift];
115
194M
            pu1_src[col] = CLIP3(pu1_src[col] + pi1_sao_offset[band_idx], 0, (1 << (band_shift + 5)) - 1);
116
194M
        }
117
6.05M
        pu1_src += src_strd;
118
6.05M
    }
119
206k
}
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
108k
{
136
108k
    WORD32 band_shift;
137
108k
    WORD32 band_table_u[NUM_BAND_TABLE];
138
108k
    WORD32 band_table_v[NUM_BAND_TABLE];
139
108k
    WORD32 i;
140
108k
    WORD32 row, col;
141
142
    /* Updating left and top and top-left */
143
1.76M
    for(row = 0; row < ht; row++)
144
1.65M
    {
145
1.65M
        pu1_src_left[2 * row] = pu1_src[row * src_strd + (wd - 2)];
146
1.65M
        pu1_src_left[2 * row + 1] = pu1_src[row * src_strd + (wd - 1)];
147
1.65M
    }
148
108k
    pu1_src_top_left[0] = pu1_src_top[wd - 2];
149
108k
    pu1_src_top_left[1] = pu1_src_top[wd - 1];
150
3.47M
    for(col = 0; col < wd; col++)
151
3.36M
    {
152
3.36M
        pu1_src_top[col] = pu1_src[(ht - 1) * src_strd + col];
153
3.36M
    }
154
155
156
108k
    band_shift = BIT_DEPTH_CHROMA - 5;
157
3.56M
    for(i = 0; i < NUM_BAND_TABLE; i++)
158
3.45M
    {
159
3.45M
        band_table_u[i] = 0;
160
3.45M
        band_table_v[i] = 0;
161
3.45M
    }
162
540k
    for(i = 0; i < 4; i++)
163
432k
    {
164
432k
        band_table_u[(i + sao_band_pos_u) & 31] = i + 1;
165
432k
        band_table_v[(i + sao_band_pos_v) & 31] = i + 1;
166
432k
    }
167
168
1.76M
    for(row = 0; row < ht; row++)
169
1.65M
    {
170
54.4M
        for(col = 0; col < wd; col++)
171
52.8M
        {
172
52.8M
            WORD32 band_idx;
173
52.8M
            WORD8 *pi1_sao_offset;
174
175
52.8M
            pi1_sao_offset = (0 == col % 2) ? pi1_sao_offset_u : pi1_sao_offset_v;
176
52.8M
            band_idx = (0 == col % 2) ? band_table_u[pu1_src[col] >> band_shift] : band_table_v[pu1_src[col] >> band_shift];
177
52.8M
            pu1_src[col] = CLIP3(pu1_src[col] + pi1_sao_offset[band_idx], 0, (1 << (band_shift + 5)) - 1);
178
52.8M
        }
179
1.65M
        pu1_src += src_strd;
180
1.65M
    }
181
108k
}
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
85.3k
{
198
85.3k
    WORD32 row, col;
199
85.3k
    UWORD8 au1_mask[MAX_CTB_SIZE];
200
85.3k
    UWORD8 au1_src_left_tmp[MAX_CTB_SIZE];
201
85.3k
    WORD8 u1_sign_left, u1_sign_right;
202
85.3k
    WORD32 bit_depth;
203
85.3k
    UNUSED(pu1_src_top_right);
204
85.3k
    UNUSED(pu1_src_bot_left);
205
85.3k
    bit_depth = BIT_DEPTH_LUMA;
206
207
    /* Initialize the mask values */
208
85.3k
    memset(au1_mask, 0xFF, MAX_CTB_SIZE);
209
210
    /* Update top and top-left arrays */
211
85.3k
    *pu1_src_top_left = pu1_src_top[wd - 1];
212
3.67M
    for(row = 0; row < ht; row++)
213
3.59M
    {
214
3.59M
        au1_src_left_tmp[row] = pu1_src[row * src_strd + wd - 1];
215
3.59M
    }
216
3.69M
    for(col = 0; col < wd; col++)
217
3.61M
    {
218
3.61M
        pu1_src_top[col] = pu1_src[(ht - 1) * src_strd + col];
219
3.61M
    }
220
221
    /* Update masks based on the availability flags */
222
85.3k
    if(0 == pu1_avail[0])
223
13.9k
    {
224
13.9k
        au1_mask[0] = 0;
225
13.9k
    }
226
85.3k
    if(0 == pu1_avail[1])
227
11.9k
    {
228
11.9k
        au1_mask[wd - 1] = 0;
229
11.9k
    }
230
231
    /* Processing is done on the intermediate buffer and the output is written to the source buffer */
232
85.3k
    {
233
3.67M
        for(row = 0; row < ht; row++)
234
3.59M
        {
235
3.59M
            u1_sign_left = SIGN(pu1_src[0] - pu1_src_left[row]);
236
180M
            for(col = 0; col < wd; col++)
237
177M
            {
238
177M
                WORD32 edge_idx;
239
240
177M
                u1_sign_right = SIGN(pu1_src[col] - pu1_src[col + 1]);
241
177M
                edge_idx = 2 + u1_sign_left + u1_sign_right;
242
177M
                u1_sign_left = -u1_sign_right;
243
244
177M
                edge_idx = gi4_ihevc_table_edge_idx[edge_idx] & au1_mask[col];
245
246
177M
                if(0 != edge_idx)
247
41.5M
                {
248
41.5M
                    pu1_src[col] = CLIP3(pu1_src[col] + pi1_sao_offset[edge_idx], 0, (1 << bit_depth) - 1);
249
41.5M
                }
250
177M
            }
251
252
3.59M
            pu1_src += src_strd;
253
3.59M
        }
254
85.3k
    }
255
256
    /* Update left array */
257
3.67M
    for(row = 0; row < ht; row++)
258
3.59M
    {
259
3.59M
        pu1_src_left[row] = au1_src_left_tmp[row];
260
3.59M
    }
261
262
85.3k
}
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
46.7k
{
281
46.7k
    WORD32 row, col;
282
46.7k
    UWORD8 au1_mask[MAX_CTB_SIZE];
283
46.7k
    UWORD8 au1_src_left_tmp[2 * MAX_CTB_SIZE];
284
46.7k
    WORD8 u1_sign_left_u, u1_sign_right_u;
285
46.7k
    WORD8 u1_sign_left_v, u1_sign_right_v;
286
46.7k
    WORD32 bit_depth;
287
46.7k
    UNUSED(pu1_src_top_right);
288
46.7k
    UNUSED(pu1_src_bot_left);
289
46.7k
    bit_depth = BIT_DEPTH_CHROMA;
290
291
    /* Initialize the mask values */
292
46.7k
    memset(au1_mask, 0xFF, MAX_CTB_SIZE);
293
294
    /* Update left, top and top-left arrays */
295
46.7k
    pu1_src_top_left[0] = pu1_src_top[wd - 2];
296
46.7k
    pu1_src_top_left[1] = pu1_src_top[wd - 1];
297
1.05M
    for(row = 0; row < ht; row++)
298
1.01M
    {
299
1.01M
        au1_src_left_tmp[2 * row] = pu1_src[row * src_strd + wd - 2];
300
1.01M
        au1_src_left_tmp[2 * row + 1] = pu1_src[row * src_strd + wd - 1];
301
1.01M
    }
302
2.08M
    for(col = 0; col < wd; col++)
303
2.04M
    {
304
2.04M
        pu1_src_top[col] = pu1_src[(ht - 1) * src_strd + col];
305
2.04M
    }
306
307
    /* Update masks based on the availability flags */
308
46.7k
    if(0 == pu1_avail[0])
309
6.98k
    {
310
6.98k
        au1_mask[0] = 0;
311
6.98k
    }
312
46.7k
    if(0 == pu1_avail[1])
313
6.36k
    {
314
6.36k
        au1_mask[(wd - 1) >> 1] = 0;
315
6.36k
    }
316
317
    /* Processing is done on the intermediate buffer and the output is written to the source buffer */
318
46.7k
    {
319
1.05M
        for(row = 0; row < ht; row++)
320
1.01M
        {
321
1.01M
            u1_sign_left_u = SIGN(pu1_src[0] - pu1_src_left[2 * row]);
322
1.01M
            u1_sign_left_v = SIGN(pu1_src[1] - pu1_src_left[2 * row + 1]);
323
50.4M
            for(col = 0; col < wd; col++)
324
49.4M
            {
325
49.4M
                WORD32 edge_idx;
326
49.4M
                WORD8 *pi1_sao_offset;
327
328
49.4M
                if(0 == col % 2)
329
24.7M
                {
330
24.7M
                    pi1_sao_offset = pi1_sao_offset_u;
331
24.7M
                    u1_sign_right_u = SIGN(pu1_src[col] - pu1_src[col + 2]);
332
24.7M
                    edge_idx = 2 + u1_sign_left_u + u1_sign_right_u;
333
24.7M
                    u1_sign_left_u = -u1_sign_right_u;
334
24.7M
                }
335
24.7M
                else
336
24.7M
                {
337
24.7M
                    pi1_sao_offset = pi1_sao_offset_v;
338
24.7M
                    u1_sign_right_v = SIGN(pu1_src[col] - pu1_src[col + 2]);
339
24.7M
                    edge_idx = 2 + u1_sign_left_v + u1_sign_right_v;
340
24.7M
                    u1_sign_left_v = -u1_sign_right_v;
341
24.7M
                }
342
343
49.4M
                edge_idx = gi4_ihevc_table_edge_idx[edge_idx] & au1_mask[col >> 1];
344
345
49.4M
                if(0 != edge_idx)
346
7.11M
                {
347
7.11M
                    pu1_src[col] = CLIP3(pu1_src[col] + pi1_sao_offset[edge_idx], 0, (1 << bit_depth) - 1);
348
7.11M
                }
349
49.4M
            }
350
351
1.01M
            pu1_src += src_strd;
352
1.01M
        }
353
46.7k
    }
354
355
2.07M
    for(row = 0; row < 2 * ht; row++)
356
2.02M
    {
357
2.02M
        pu1_src_left[row] = au1_src_left_tmp[row];
358
2.02M
    }
359
360
46.7k
}
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
68.7k
{
377
68.7k
    WORD32 row, col;
378
68.7k
    UWORD8 au1_mask[MAX_CTB_SIZE];
379
68.7k
    UWORD8 au1_src_top_tmp[MAX_CTB_SIZE];
380
68.7k
    WORD8 au1_sign_up[MAX_CTB_SIZE];
381
68.7k
    WORD8 u1_sign_down;
382
68.7k
    WORD32 bit_depth;
383
68.7k
    UNUSED(pu1_src_top_right);
384
68.7k
    UNUSED(pu1_src_bot_left);
385
386
68.7k
    bit_depth = BIT_DEPTH_LUMA;
387
388
    /* Initialize the mask values */
389
68.7k
    memset(au1_mask, 0xFF, MAX_CTB_SIZE);
390
391
    /* Update left, top and top-left arrays */
392
68.7k
    *pu1_src_top_left = pu1_src_top[wd - 1];
393
2.66M
    for(row = 0; row < ht; row++)
394
2.59M
    {
395
2.59M
        pu1_src_left[row] = pu1_src[row * src_strd + wd - 1];
396
2.59M
    }
397
2.73M
    for(col = 0; col < wd; col++)
398
2.66M
    {
399
2.66M
        au1_src_top_tmp[col] = pu1_src[(ht - 1) * src_strd + col];
400
2.66M
    }
401
402
    /* Update height and source pointers based on the availability flags */
403
68.7k
    if(0 == pu1_avail[2])
404
16.8k
    {
405
16.8k
        pu1_src += src_strd;
406
16.8k
        ht--;
407
866k
        for(col = 0; col < wd; col++)
408
850k
        {
409
850k
            au1_sign_up[col] = SIGN(pu1_src[col] - pu1_src[col - src_strd]);
410
850k
        }
411
16.8k
    }
412
51.9k
    else
413
51.9k
    {
414
1.86M
        for(col = 0; col < wd; col++)
415
1.81M
        {
416
1.81M
            au1_sign_up[col] = SIGN(pu1_src[col] - pu1_src_top[col]);
417
1.81M
        }
418
51.9k
    }
419
68.7k
    if(0 == pu1_avail[3])
420
15.4k
    {
421
15.4k
        ht--;
422
15.4k
    }
423
424
    /* Processing is done on the intermediate buffer and the output is written to the source buffer */
425
68.7k
    {
426
2.63M
        for(row = 0; row < ht; row++)
427
2.56M
        {
428
125M
            for(col = 0; col < wd; col++)
429
123M
            {
430
123M
                WORD32 edge_idx;
431
432
123M
                u1_sign_down = SIGN(pu1_src[col] - pu1_src[col + src_strd]);
433
123M
                edge_idx = 2 + au1_sign_up[col] + u1_sign_down;
434
123M
                au1_sign_up[col] = -u1_sign_down;
435
436
123M
                edge_idx = gi4_ihevc_table_edge_idx[edge_idx] & au1_mask[col];
437
438
123M
                if(0 != edge_idx)
439
31.4M
                {
440
31.4M
                    pu1_src[col] = CLIP3(pu1_src[col] + pi1_sao_offset[edge_idx], 0, (1 << bit_depth) - 1);
441
31.4M
                }
442
123M
            }
443
444
2.56M
            pu1_src += src_strd;
445
2.56M
        }
446
68.7k
    }
447
448
2.73M
    for(col = 0; col < wd; col++)
449
2.66M
    {
450
2.66M
        pu1_src_top[col] = au1_src_top_tmp[col];
451
2.66M
    }
452
453
68.7k
}
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
36.5k
{
471
36.5k
    WORD32 row, col;
472
36.5k
    UWORD8 au1_mask[MAX_CTB_SIZE];
473
36.5k
    UWORD8 au1_src_top_tmp[MAX_CTB_SIZE];
474
36.5k
    WORD8 au1_sign_up[MAX_CTB_SIZE];
475
36.5k
    WORD8 u1_sign_down;
476
36.5k
    WORD32 bit_depth;
477
36.5k
    UNUSED(pu1_src_top_right);
478
36.5k
    UNUSED(pu1_src_bot_left);
479
480
36.5k
    bit_depth = BIT_DEPTH_CHROMA;
481
482
    /* Initialize the mask values */
483
36.5k
    memset(au1_mask, 0xFF, MAX_CTB_SIZE);
484
485
    /* Update left, top and top-left arrays */
486
36.5k
    pu1_src_top_left[0] = pu1_src_top[wd - 2];
487
36.5k
    pu1_src_top_left[1] = pu1_src_top[wd - 1];
488
715k
    for(row = 0; row < ht; row++)
489
679k
    {
490
679k
        pu1_src_left[2 * row] = pu1_src[row * src_strd + wd - 2];
491
679k
        pu1_src_left[2 * row + 1] = pu1_src[row * src_strd + wd - 1];
492
679k
    }
493
1.41M
    for(col = 0; col < wd; col++)
494
1.38M
    {
495
1.38M
        au1_src_top_tmp[col] = pu1_src[(ht - 1) * src_strd + col];
496
1.38M
    }
497
498
    /* Update height and source pointers based on the availability flags */
499
36.5k
    if(0 == pu1_avail[2])
500
8.01k
    {
501
8.01k
        pu1_src += src_strd;
502
8.01k
        ht--;
503
330k
        for(col = 0; col < wd; col++)
504
322k
        {
505
322k
            au1_sign_up[col] = SIGN(pu1_src[col] - pu1_src[col - src_strd]);
506
322k
        }
507
8.01k
    }
508
28.5k
    else
509
28.5k
    {
510
1.08M
        for(col = 0; col < wd; col++)
511
1.05M
        {
512
1.05M
            au1_sign_up[col] = SIGN(pu1_src[col] - pu1_src_top[col]);
513
1.05M
        }
514
28.5k
    }
515
36.5k
    if(0 == pu1_avail[3])
516
6.30k
    {
517
6.30k
        ht--;
518
6.30k
    }
519
520
    /* Processing is done on the intermediate buffer and the output is written to the source buffer */
521
36.5k
    {
522
701k
        for(row = 0; row < ht; row++)
523
664k
        {
524
28.5M
            for(col = 0; col < wd; col++)
525
27.8M
            {
526
27.8M
                WORD32 edge_idx;
527
27.8M
                WORD8 *pi1_sao_offset;
528
529
27.8M
                pi1_sao_offset = (0 == col % 2) ? pi1_sao_offset_u : pi1_sao_offset_v;
530
531
27.8M
                u1_sign_down = SIGN(pu1_src[col] - pu1_src[col + src_strd]);
532
27.8M
                edge_idx = 2 + au1_sign_up[col] + u1_sign_down;
533
27.8M
                au1_sign_up[col] = -u1_sign_down;
534
535
27.8M
                edge_idx = gi4_ihevc_table_edge_idx[edge_idx] & au1_mask[col >> 1];
536
537
27.8M
                if(0 != edge_idx)
538
3.99M
                {
539
3.99M
                    pu1_src[col] = CLIP3(pu1_src[col] + pi1_sao_offset[edge_idx], 0, (1 << bit_depth) - 1);
540
3.99M
                }
541
27.8M
            }
542
543
664k
            pu1_src += src_strd;
544
664k
        }
545
36.5k
    }
546
547
1.41M
    for(col = 0; col < wd; col++)
548
1.38M
    {
549
1.38M
        pu1_src_top[col] = au1_src_top_tmp[col];
550
1.38M
    }
551
552
36.5k
}
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
53.1k
{
569
53.1k
    WORD32 row, col;
570
53.1k
    UWORD8 au1_mask[MAX_CTB_SIZE];
571
53.1k
    UWORD8 au1_src_left_tmp[MAX_CTB_SIZE], au1_src_top_tmp[MAX_CTB_SIZE];
572
53.1k
    UWORD8 u1_src_top_left_tmp;
573
53.1k
    WORD8 au1_sign_up[MAX_CTB_SIZE + 1], au1_sign_up_tmp[MAX_CTB_SIZE + 1];
574
53.1k
    WORD8 u1_sign_down;
575
53.1k
    WORD8 *pu1_sign_up;
576
53.1k
    WORD8 *pu1_sign_up_tmp;
577
53.1k
    UWORD8 *pu1_src_left_cpy;
578
579
53.1k
    WORD32 bit_depth;
580
53.1k
    UWORD8 u1_pos_0_0_tmp;
581
53.1k
    UWORD8 u1_pos_wd_ht_tmp;
582
53.1k
    UNUSED(pu1_src_top_right);
583
53.1k
    UNUSED(pu1_src_bot_left);
584
585
53.1k
    bit_depth = BIT_DEPTH_LUMA;
586
53.1k
    pu1_sign_up = au1_sign_up;
587
53.1k
    pu1_sign_up_tmp = au1_sign_up_tmp;
588
53.1k
    pu1_src_left_cpy = pu1_src_left;
589
590
    /* Initialize the mask values */
591
53.1k
    memset(au1_mask, 0xFF, MAX_CTB_SIZE);
592
593
    /* Update left, top and top-left arrays */
594
53.1k
    u1_src_top_left_tmp = pu1_src_top[wd - 1];
595
2.11M
    for(row = 0; row < ht; row++)
596
2.06M
    {
597
2.06M
        au1_src_left_tmp[row] = pu1_src[row * src_strd + wd - 1];
598
2.06M
    }
599
2.18M
    for(col = 0; col < wd; col++)
600
2.12M
    {
601
2.12M
        au1_src_top_tmp[col] = pu1_src[(ht - 1) * src_strd + col];
602
2.12M
    }
603
604
605
    /* If top-left is available, process separately */
606
53.1k
    if(0 != pu1_avail[4])
607
32.4k
    {
608
32.4k
        WORD32 edge_idx;
609
610
32.4k
        edge_idx = 2 + SIGN(pu1_src[0] - pu1_src_top_left[0]) +
611
32.4k
                        SIGN(pu1_src[0] - pu1_src[1 + src_strd]);
612
613
32.4k
        edge_idx = gi4_ihevc_table_edge_idx[edge_idx];
614
615
32.4k
        if(0 != edge_idx)
616
11.0k
        {
617
11.0k
            u1_pos_0_0_tmp = CLIP3(pu1_src[0] + pi1_sao_offset[edge_idx], 0, (1 << bit_depth) - 1);
618
11.0k
        }
619
21.3k
        else
620
21.3k
        {
621
21.3k
            u1_pos_0_0_tmp = pu1_src[0];
622
21.3k
        }
623
32.4k
    }
624
20.7k
    else
625
20.7k
    {
626
20.7k
        u1_pos_0_0_tmp = pu1_src[0];
627
20.7k
    }
628
629
    /* If bottom-right is available, process separately */
630
53.1k
    if(0 != pu1_avail[7])
631
33.4k
    {
632
33.4k
        WORD32 edge_idx;
633
634
33.4k
        edge_idx = 2 + SIGN(pu1_src[wd - 1 + (ht - 1) * src_strd] - pu1_src[wd - 1 + (ht - 1) * src_strd - 1 - src_strd]) +
635
33.4k
                        SIGN(pu1_src[wd - 1 + (ht - 1) * src_strd] - pu1_src[wd - 1 + (ht - 1) * src_strd + 1 + src_strd]);
636
637
33.4k
        edge_idx = gi4_ihevc_table_edge_idx[edge_idx];
638
639
33.4k
        if(0 != edge_idx)
640
12.6k
        {
641
12.6k
            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
12.6k
        }
643
20.7k
        else
644
20.7k
        {
645
20.7k
            u1_pos_wd_ht_tmp = pu1_src[wd - 1 + (ht - 1) * src_strd];
646
20.7k
        }
647
33.4k
    }
648
19.7k
    else
649
19.7k
    {
650
19.7k
        u1_pos_wd_ht_tmp = pu1_src[wd - 1 + (ht - 1) * src_strd];
651
19.7k
    }
652
653
    /* If Left is not available */
654
53.1k
    if(0 == pu1_avail[0])
655
7.02k
    {
656
7.02k
        au1_mask[0] = 0;
657
7.02k
    }
658
659
    /* If Top is not available */
660
53.1k
    if(0 == pu1_avail[2])
661
16.5k
    {
662
16.5k
        pu1_src += src_strd;
663
16.5k
        ht--;
664
16.5k
        pu1_src_left_cpy += 1;
665
793k
        for(col = 1; col < wd; col++)
666
776k
        {
667
776k
            pu1_sign_up[col] = SIGN(pu1_src[col] - pu1_src[col - 1 - src_strd]);
668
776k
        }
669
16.5k
    }
670
36.6k
    else
671
36.6k
    {
672
1.33M
        for(col = 1; col < wd; col++)
673
1.29M
        {
674
1.29M
            pu1_sign_up[col] = SIGN(pu1_src[col] - pu1_src_top[col - 1]);
675
1.29M
        }
676
36.6k
    }
677
678
    /* If Right is not available */
679
53.1k
    if(0 == pu1_avail[1])
680
8.09k
    {
681
8.09k
        au1_mask[wd - 1] = 0;
682
8.09k
    }
683
684
    /* If Bottom is not available */
685
53.1k
    if(0 == pu1_avail[3])
686
14.6k
    {
687
14.6k
        ht--;
688
14.6k
    }
689
690
    /* Processing is done on the intermediate buffer and the output is written to the source buffer */
691
53.1k
    {
692
2.08M
        for(row = 0; row < ht; row++)
693
2.03M
        {
694
2.03M
            pu1_sign_up[0] = SIGN(pu1_src[0] - pu1_src_left_cpy[row - 1]);
695
99.7M
            for(col = 0; col < wd; col++)
696
97.6M
            {
697
97.6M
                WORD32 edge_idx;
698
699
97.6M
                u1_sign_down = SIGN(pu1_src[col] - pu1_src[col + 1 + src_strd]);
700
97.6M
                edge_idx = 2 + pu1_sign_up[col] + u1_sign_down;
701
97.6M
                pu1_sign_up_tmp[col + 1] = -u1_sign_down;
702
703
97.6M
                edge_idx = gi4_ihevc_table_edge_idx[edge_idx] & au1_mask[col];
704
705
97.6M
                if(0 != edge_idx)
706
26.1M
                {
707
26.1M
                    pu1_src[col] = CLIP3(pu1_src[col] + pi1_sao_offset[edge_idx], 0, (1 << bit_depth) - 1);
708
26.1M
                }
709
97.6M
            }
710
711
            /* Swapping pu1_sign_up_tmp and pu1_sign_up */
712
2.03M
            {
713
2.03M
                WORD8 *pu1_swap_tmp = pu1_sign_up;
714
2.03M
                pu1_sign_up = pu1_sign_up_tmp;
715
2.03M
                pu1_sign_up_tmp = pu1_swap_tmp;
716
2.03M
            }
717
718
2.03M
            pu1_src += src_strd;
719
2.03M
        }
720
721
53.1k
        pu1_src[-(pu1_avail[2] ? ht : ht + 1) * src_strd] = u1_pos_0_0_tmp;
722
53.1k
        pu1_src[(pu1_avail[3] ? wd - 1 - src_strd : wd - 1)] = u1_pos_wd_ht_tmp;
723
53.1k
    }
724
725
53.1k
    if(0 == pu1_avail[2])
726
16.5k
        ht++;
727
53.1k
    if(0 == pu1_avail[3])
728
14.6k
        ht++;
729
53.1k
    *pu1_src_top_left = u1_src_top_left_tmp;
730
2.11M
    for(row = 0; row < ht; row++)
731
2.06M
    {
732
2.06M
        pu1_src_left[row] = au1_src_left_tmp[row];
733
2.06M
    }
734
2.18M
    for(col = 0; col < wd; col++)
735
2.12M
    {
736
2.12M
        pu1_src_top[col] = au1_src_top_tmp[col];
737
2.12M
    }
738
739
53.1k
}
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
28.5k
{
758
28.5k
    WORD32 row, col;
759
28.5k
    UWORD8 au1_mask[MAX_CTB_SIZE];
760
28.5k
    UWORD8 au1_src_left_tmp[2 * MAX_CTB_SIZE], au1_src_top_tmp[MAX_CTB_SIZE];
761
28.5k
    UWORD8 au1_src_top_left_tmp[2];
762
28.5k
    WORD8 au1_sign_up[MAX_CTB_SIZE + 2], au1_sign_up_tmp[MAX_CTB_SIZE + 2];
763
28.5k
    WORD8 u1_sign_down;
764
28.5k
    WORD8 *pu1_sign_up;
765
28.5k
    WORD8 *pu1_sign_up_tmp;
766
28.5k
    UWORD8 *pu1_src_left_cpy;
767
768
28.5k
    WORD32 bit_depth;
769
770
28.5k
    UWORD8 u1_pos_0_0_tmp_u;
771
28.5k
    UWORD8 u1_pos_0_0_tmp_v;
772
28.5k
    UWORD8 u1_pos_wd_ht_tmp_u;
773
28.5k
    UWORD8 u1_pos_wd_ht_tmp_v;
774
28.5k
    UNUSED(pu1_src_top_right);
775
28.5k
    UNUSED(pu1_src_bot_left);
776
777
778
28.5k
    bit_depth = BIT_DEPTH_CHROMA;
779
28.5k
    pu1_sign_up = au1_sign_up;
780
28.5k
    pu1_sign_up_tmp = au1_sign_up_tmp;
781
28.5k
    pu1_src_left_cpy = pu1_src_left;
782
783
    /* Initialize the mask values */
784
28.5k
    memset(au1_mask, 0xFF, MAX_CTB_SIZE);
785
786
    /* Update left, top and top-left arrays */
787
28.5k
    au1_src_top_left_tmp[0] = pu1_src_top[wd - 2];
788
28.5k
    au1_src_top_left_tmp[1] = pu1_src_top[wd - 1];
789
509k
    for(row = 0; row < ht; row++)
790
480k
    {
791
480k
        au1_src_left_tmp[2 * row] = pu1_src[row * src_strd + wd - 2];
792
480k
        au1_src_left_tmp[2 * row + 1] = pu1_src[row * src_strd + wd - 1];
793
480k
    }
794
1.05M
    for(col = 0; col < wd; col++)
795
1.02M
    {
796
1.02M
        au1_src_top_tmp[col] = pu1_src[(ht - 1) * src_strd + col];
797
1.02M
    }
798
799
800
    /* If top-left is available, process separately */
801
28.5k
    if(0 != pu1_avail[4])
802
19.4k
    {
803
19.4k
        WORD32 edge_idx;
804
805
        /* U */
806
19.4k
        edge_idx = 2 + SIGN(pu1_src[0] - pu1_src_top_left[0]) +
807
19.4k
                        SIGN(pu1_src[0] - pu1_src[2 + src_strd]);
808
809
19.4k
        edge_idx = gi4_ihevc_table_edge_idx[edge_idx];
810
811
19.4k
        if(0 != edge_idx)
812
3.53k
        {
813
3.53k
            u1_pos_0_0_tmp_u = CLIP3(pu1_src[0] + pi1_sao_offset_u[edge_idx], 0, (1 << bit_depth) - 1);
814
3.53k
        }
815
15.9k
        else
816
15.9k
        {
817
15.9k
            u1_pos_0_0_tmp_u = pu1_src[0];
818
15.9k
        }
819
820
        /* V */
821
19.4k
        edge_idx = 2 + SIGN(pu1_src[1] - pu1_src_top_left[1]) +
822
19.4k
                        SIGN(pu1_src[1] - pu1_src[1 + 2 + src_strd]);
823
824
19.4k
        edge_idx = gi4_ihevc_table_edge_idx[edge_idx];
825
826
19.4k
        if(0 != edge_idx)
827
3.57k
        {
828
3.57k
            u1_pos_0_0_tmp_v = CLIP3(pu1_src[1] + pi1_sao_offset_v[edge_idx], 0, (1 << bit_depth) - 1);
829
3.57k
        }
830
15.9k
        else
831
15.9k
        {
832
15.9k
            u1_pos_0_0_tmp_v = pu1_src[1];
833
15.9k
        }
834
19.4k
    }
835
9.03k
    else
836
9.03k
    {
837
9.03k
        u1_pos_0_0_tmp_u = pu1_src[0];
838
9.03k
        u1_pos_0_0_tmp_v = pu1_src[1];
839
9.03k
    }
840
841
    /* If bottom-right is available, process separately */
842
28.5k
    if(0 != pu1_avail[7])
843
19.6k
    {
844
19.6k
        WORD32 edge_idx;
845
846
        /* U */
847
19.6k
        edge_idx = 2 + SIGN(pu1_src[wd - 2 + (ht - 1) * src_strd] - pu1_src[wd - 2 + (ht - 1) * src_strd - 2 - src_strd]) +
848
19.6k
                        SIGN(pu1_src[wd - 2 + (ht - 1) * src_strd] - pu1_src[wd - 2 + (ht - 1) * src_strd + 2 + src_strd]);
849
850
19.6k
        edge_idx = gi4_ihevc_table_edge_idx[edge_idx];
851
852
19.6k
        if(0 != edge_idx)
853
3.65k
        {
854
3.65k
            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
3.65k
        }
856
16.0k
        else
857
16.0k
        {
858
16.0k
            u1_pos_wd_ht_tmp_u = pu1_src[wd - 2 + (ht - 1) * src_strd];
859
16.0k
        }
860
861
        /* V */
862
19.6k
        edge_idx = 2 + SIGN(pu1_src[wd - 1 + (ht - 1) * src_strd] - pu1_src[wd - 1 + (ht - 1) * src_strd - 2 - src_strd]) +
863
19.6k
                        SIGN(pu1_src[wd - 1 + (ht - 1) * src_strd] - pu1_src[wd - 1 + (ht - 1) * src_strd + 2 + src_strd]);
864
865
19.6k
        edge_idx = gi4_ihevc_table_edge_idx[edge_idx];
866
867
19.6k
        if(0 != edge_idx)
868
3.69k
        {
869
3.69k
            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
3.69k
        }
871
16.0k
        else
872
16.0k
        {
873
16.0k
            u1_pos_wd_ht_tmp_v = pu1_src[wd - 1 + (ht - 1) * src_strd];
874
16.0k
        }
875
19.6k
    }
876
8.81k
    else
877
8.81k
    {
878
8.81k
        u1_pos_wd_ht_tmp_u = pu1_src[wd - 2 + (ht - 1) * src_strd];
879
8.81k
        u1_pos_wd_ht_tmp_v = pu1_src[wd - 1 + (ht - 1) * src_strd];
880
8.81k
    }
881
882
    /* If Left is not available */
883
28.5k
    if(0 == pu1_avail[0])
884
3.15k
    {
885
3.15k
        au1_mask[0] = 0;
886
3.15k
    }
887
888
    /* If Top is not available */
889
28.5k
    if(0 == pu1_avail[2])
890
6.51k
    {
891
6.51k
        pu1_src += src_strd;
892
6.51k
        pu1_src_left_cpy += 2;
893
6.51k
        ht--;
894
242k
        for(col = 2; col < wd; col++)
895
236k
        {
896
236k
            pu1_sign_up[col] = SIGN(pu1_src[col] - pu1_src[col - 2 - src_strd]);
897
236k
        }
898
6.51k
    }
899
21.9k
    else
900
21.9k
    {
901
752k
        for(col = 2; col < wd; col++)
902
730k
        {
903
730k
            pu1_sign_up[col] = SIGN(pu1_src[col] - pu1_src_top[col - 2]);
904
730k
        }
905
21.9k
    }
906
907
    /* If Right is not available */
908
28.5k
    if(0 == pu1_avail[1])
909
4.15k
    {
910
4.15k
        au1_mask[(wd - 1) >> 1] = 0;
911
4.15k
    }
912
913
    /* If Bottom is not available */
914
28.5k
    if(0 == pu1_avail[3])
915
5.55k
    {
916
5.55k
        ht--;
917
5.55k
    }
918
919
    /* Processing is done on the intermediate buffer and the output is written to the source buffer */
920
28.5k
    {
921
497k
        for(row = 0; row < ht; row++)
922
468k
        {
923
468k
            pu1_sign_up[0] = SIGN(pu1_src[0] - pu1_src_left_cpy[2 * (row - 1)]);
924
468k
            pu1_sign_up[1] = SIGN(pu1_src[1] - pu1_src_left_cpy[2 * (row - 1) + 1]);
925
18.1M
            for(col = 0; col < wd; col++)
926
17.7M
            {
927
17.7M
                WORD32 edge_idx;
928
17.7M
                WORD8 *pi1_sao_offset;
929
930
17.7M
                pi1_sao_offset = (0 == col % 2) ? pi1_sao_offset_u : pi1_sao_offset_v;
931
932
17.7M
                u1_sign_down = SIGN(pu1_src[col] - pu1_src[col + 2 + src_strd]);
933
17.7M
                edge_idx = 2 + pu1_sign_up[col] + u1_sign_down;
934
17.7M
                pu1_sign_up_tmp[col + 2] = -u1_sign_down;
935
936
17.7M
                edge_idx = gi4_ihevc_table_edge_idx[edge_idx] & au1_mask[col >> 1];
937
938
17.7M
                if(0 != edge_idx)
939
2.21M
                {
940
2.21M
                    pu1_src[col] = CLIP3(pu1_src[col] + pi1_sao_offset[edge_idx], 0, (1 << bit_depth) - 1);
941
2.21M
                }
942
17.7M
            }
943
944
            /* Swapping pu1_sign_up_tmp and pu1_sign_up */
945
468k
            {
946
468k
                WORD8 *pu1_swap_tmp = pu1_sign_up;
947
468k
                pu1_sign_up = pu1_sign_up_tmp;
948
468k
                pu1_sign_up_tmp = pu1_swap_tmp;
949
468k
            }
950
951
468k
            pu1_src += src_strd;
952
468k
        }
953
954
28.5k
        pu1_src[-(pu1_avail[2] ? ht : ht + 1) * src_strd] = u1_pos_0_0_tmp_u;
955
28.5k
        pu1_src[-(pu1_avail[2] ? ht : ht + 1) * src_strd + 1] = u1_pos_0_0_tmp_v;
956
28.5k
        pu1_src[(pu1_avail[3] ? wd - 2 - src_strd : wd - 2)] = u1_pos_wd_ht_tmp_u;
957
28.5k
        pu1_src[(pu1_avail[3] ? wd - 1 - src_strd : wd - 1)] = u1_pos_wd_ht_tmp_v;
958
28.5k
    }
959
960
28.5k
    if(0 == pu1_avail[2])
961
6.51k
        ht++;
962
28.5k
    if(0 == pu1_avail[3])
963
5.55k
        ht++;
964
28.5k
    pu1_src_top_left[0] = au1_src_top_left_tmp[0];
965
28.5k
    pu1_src_top_left[1] = au1_src_top_left_tmp[1];
966
990k
    for(row = 0; row < 2 * ht; row++)
967
961k
    {
968
961k
        pu1_src_left[row] = au1_src_left_tmp[row];
969
961k
    }
970
1.05M
    for(col = 0; col < wd; col++)
971
1.02M
    {
972
1.02M
        pu1_src_top[col] = au1_src_top_tmp[col];
973
1.02M
    }
974
975
28.5k
}
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
58.4k
{
993
58.4k
    WORD32 row, col;
994
58.4k
    UWORD8 au1_mask[MAX_CTB_SIZE];
995
58.4k
    UWORD8 au1_src_top_tmp[MAX_CTB_SIZE];
996
58.4k
    UWORD8 au1_src_left_tmp[MAX_CTB_SIZE];
997
58.4k
    UWORD8 u1_src_top_left_tmp;
998
58.4k
    WORD8 au1_sign_up[MAX_CTB_SIZE];
999
58.4k
    UWORD8 *pu1_src_left_cpy;
1000
58.4k
    WORD8 u1_sign_down;
1001
58.4k
    WORD32 bit_depth;
1002
1003
58.4k
    UWORD8 u1_pos_0_ht_tmp;
1004
58.4k
    UWORD8 u1_pos_wd_0_tmp;
1005
1006
58.4k
    bit_depth = BIT_DEPTH_LUMA;
1007
58.4k
    pu1_src_left_cpy = pu1_src_left;
1008
1009
    /* Initialize the mask values */
1010
58.4k
    memset(au1_mask, 0xFF, MAX_CTB_SIZE);
1011
1012
    /* Update left, top and top-left arrays */
1013
58.4k
    u1_src_top_left_tmp = pu1_src_top[wd - 1];
1014
2.26M
    for(row = 0; row < ht; row++)
1015
2.20M
    {
1016
2.20M
        au1_src_left_tmp[row] = pu1_src[row * src_strd + wd - 1];
1017
2.20M
    }
1018
2.32M
    for(col = 0; col < wd; col++)
1019
2.26M
    {
1020
2.26M
        au1_src_top_tmp[col] = pu1_src[(ht - 1) * src_strd + col];
1021
2.26M
    }
1022
1023
    /* If top-right is available, process separately */
1024
58.4k
    if(0 != pu1_avail[5])
1025
35.1k
    {
1026
35.1k
        WORD32 edge_idx;
1027
1028
35.1k
        edge_idx = 2 + SIGN(pu1_src[wd - 1] - pu1_src_top_right[0]) +
1029
35.1k
                        SIGN(pu1_src[wd - 1] - pu1_src[wd - 1 - 1 + src_strd]);
1030
1031
35.1k
        edge_idx = gi4_ihevc_table_edge_idx[edge_idx];
1032
1033
35.1k
        if(0 != edge_idx)
1034
11.8k
        {
1035
11.8k
            u1_pos_wd_0_tmp = CLIP3(pu1_src[wd - 1] + pi1_sao_offset[edge_idx], 0, (1 << bit_depth) - 1);
1036
11.8k
        }
1037
23.3k
        else
1038
23.3k
        {
1039
23.3k
            u1_pos_wd_0_tmp = pu1_src[wd - 1];
1040
23.3k
        }
1041
35.1k
    }
1042
23.2k
    else
1043
23.2k
    {
1044
23.2k
        u1_pos_wd_0_tmp = pu1_src[wd - 1];
1045
23.2k
    }
1046
1047
    /* If bottom-left is available, process separately */
1048
58.4k
    if(0 != pu1_avail[6])
1049
38.5k
    {
1050
38.5k
        WORD32 edge_idx;
1051
1052
38.5k
        edge_idx = 2 + SIGN(pu1_src[(ht - 1) * src_strd] - pu1_src[(ht - 1) * src_strd + 1 - src_strd]) +
1053
38.5k
                        SIGN(pu1_src[(ht - 1) * src_strd] - pu1_src_bot_left[0]);
1054
1055
38.5k
        edge_idx = gi4_ihevc_table_edge_idx[edge_idx];
1056
1057
38.5k
        if(0 != edge_idx)
1058
13.6k
        {
1059
13.6k
            u1_pos_0_ht_tmp = CLIP3(pu1_src[(ht - 1) * src_strd] + pi1_sao_offset[edge_idx], 0, (1 << bit_depth) - 1);
1060
13.6k
        }
1061
24.8k
        else
1062
24.8k
        {
1063
24.8k
            u1_pos_0_ht_tmp = pu1_src[(ht - 1) * src_strd];
1064
24.8k
        }
1065
38.5k
    }
1066
19.9k
    else
1067
19.9k
    {
1068
19.9k
        u1_pos_0_ht_tmp = pu1_src[(ht - 1) * src_strd];
1069
19.9k
    }
1070
1071
    /* If Left is not available */
1072
58.4k
    if(0 == pu1_avail[0])
1073
7.71k
    {
1074
7.71k
        au1_mask[0] = 0;
1075
7.71k
    }
1076
1077
    /* If Top is not available */
1078
58.4k
    if(0 == pu1_avail[2])
1079
17.6k
    {
1080
17.6k
        pu1_src += src_strd;
1081
17.6k
        ht--;
1082
17.6k
        pu1_src_left_cpy += 1;
1083
806k
        for(col = 0; col < wd - 1; col++)
1084
788k
        {
1085
788k
            au1_sign_up[col] = SIGN(pu1_src[col] - pu1_src[col + 1 - src_strd]);
1086
788k
        }
1087
17.6k
    }
1088
40.8k
    else
1089
40.8k
    {
1090
1.45M
        for(col = 0; col < wd - 1; col++)
1091
1.41M
        {
1092
1.41M
            au1_sign_up[col] = SIGN(pu1_src[col] - pu1_src_top[col + 1]);
1093
1.41M
        }
1094
40.8k
    }
1095
1096
    /* If Right is not available */
1097
58.4k
    if(0 == pu1_avail[1])
1098
8.53k
    {
1099
8.53k
        au1_mask[wd - 1] = 0;
1100
8.53k
    }
1101
1102
    /* If Bottom is not available */
1103
58.4k
    if(0 == pu1_avail[3])
1104
15.1k
    {
1105
15.1k
        ht--;
1106
15.1k
    }
1107
1108
    /* Processing is done on the intermediate buffer and the output is written to the source buffer */
1109
58.4k
    {
1110
2.22M
        for(row = 0; row < ht; row++)
1111
2.16M
        {
1112
2.16M
            au1_sign_up[wd - 1] = SIGN(pu1_src[wd - 1] - pu1_src[wd - 1 + 1 - src_strd]);
1113
103M
            for(col = 0; col < wd; col++)
1114
101M
            {
1115
101M
                WORD32 edge_idx;
1116
1117
101M
                u1_sign_down = SIGN(pu1_src[col] - ((col == 0) ? pu1_src_left_cpy[row + 1] :
1118
101M
                                                                 pu1_src[col - 1 + src_strd]));
1119
101M
                edge_idx = 2 + au1_sign_up[col] + u1_sign_down;
1120
101M
                if(col > 0)
1121
99.2M
                    au1_sign_up[col - 1] = -u1_sign_down;
1122
1123
101M
                edge_idx = gi4_ihevc_table_edge_idx[edge_idx] & au1_mask[col];
1124
1125
101M
                if(0 != edge_idx)
1126
26.1M
                {
1127
26.1M
                    pu1_src[col] = CLIP3(pu1_src[col] + pi1_sao_offset[edge_idx], 0, (1 << bit_depth) - 1);
1128
26.1M
                }
1129
101M
            }
1130
1131
2.16M
            pu1_src += src_strd;
1132
2.16M
        }
1133
1134
58.4k
        pu1_src[-(pu1_avail[2] ? ht : ht + 1) * src_strd + wd - 1] = u1_pos_wd_0_tmp;
1135
58.4k
        pu1_src[(pu1_avail[3] ?  (-src_strd) : 0)] = u1_pos_0_ht_tmp;
1136
58.4k
    }
1137
1138
58.4k
    if(0 == pu1_avail[2])
1139
17.6k
        ht++;
1140
58.4k
    if(0 == pu1_avail[3])
1141
15.1k
        ht++;
1142
58.4k
    *pu1_src_top_left = u1_src_top_left_tmp;
1143
2.26M
    for(row = 0; row < ht; row++)
1144
2.20M
    {
1145
2.20M
        pu1_src_left[row] = au1_src_left_tmp[row];
1146
2.20M
    }
1147
2.32M
    for(col = 0; col < wd; col++)
1148
2.26M
    {
1149
2.26M
        pu1_src_top[col] = au1_src_top_tmp[col];
1150
2.26M
    }
1151
1152
58.4k
}
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
30.9k
{
1170
30.9k
    WORD32 row, col;
1171
30.9k
    UWORD8 au1_mask[MAX_CTB_SIZE];
1172
30.9k
    UWORD8 au1_src_left_tmp[2 * MAX_CTB_SIZE], au1_src_top_tmp[MAX_CTB_SIZE];
1173
30.9k
    UWORD8 au1_src_top_left_tmp[2];
1174
30.9k
    WORD8 au1_sign_up[MAX_CTB_SIZE];
1175
30.9k
    UWORD8 *pu1_src_left_cpy;
1176
30.9k
    WORD8 u1_sign_down;
1177
30.9k
    WORD32 bit_depth;
1178
1179
30.9k
    UWORD8 u1_pos_wd_0_tmp_u;
1180
30.9k
    UWORD8 u1_pos_wd_0_tmp_v;
1181
30.9k
    UWORD8 u1_pos_0_ht_tmp_u;
1182
30.9k
    UWORD8 u1_pos_0_ht_tmp_v;
1183
1184
30.9k
    bit_depth = BIT_DEPTH_CHROMA;
1185
30.9k
    pu1_src_left_cpy = pu1_src_left;
1186
1187
    /* Initialize the mask values */
1188
30.9k
    memset(au1_mask, 0xFF, MAX_CTB_SIZE);
1189
1190
    /* Update left, top and top-left arrays */
1191
30.9k
    au1_src_top_left_tmp[0] = pu1_src_top[wd - 2];
1192
30.9k
    au1_src_top_left_tmp[1] = pu1_src_top[wd - 1];
1193
541k
    for(row = 0; row < ht; row++)
1194
510k
    {
1195
510k
        au1_src_left_tmp[2 * row] = pu1_src[row * src_strd + wd - 2];
1196
510k
        au1_src_left_tmp[2 * row + 1] = pu1_src[row * src_strd + wd - 1];
1197
510k
    }
1198
1.06M
    for(col = 0; col < wd; col++)
1199
1.03M
    {
1200
1.03M
        au1_src_top_tmp[col] = pu1_src[(ht - 1) * src_strd + col];
1201
1.03M
    }
1202
1203
1204
    /* If top-right is available, process separately */
1205
30.9k
    if(0 != pu1_avail[5])
1206
23.1k
    {
1207
23.1k
        WORD32 edge_idx;
1208
1209
        /* U */
1210
23.1k
        edge_idx = 2 + SIGN(pu1_src[wd - 2] - pu1_src_top_right[0]) +
1211
23.1k
                        SIGN(pu1_src[wd - 2] - pu1_src[wd - 2 - 2 + src_strd]);
1212
1213
23.1k
        edge_idx = gi4_ihevc_table_edge_idx[edge_idx];
1214
1215
23.1k
        if(0 != edge_idx)
1216
4.23k
        {
1217
4.23k
            u1_pos_wd_0_tmp_u = CLIP3(pu1_src[wd - 2] + pi1_sao_offset_u[edge_idx], 0, (1 << bit_depth) - 1);
1218
4.23k
        }
1219
18.8k
        else
1220
18.8k
        {
1221
18.8k
            u1_pos_wd_0_tmp_u = pu1_src[wd - 2];
1222
18.8k
        }
1223
1224
        /* V */
1225
23.1k
        edge_idx = 2 + SIGN(pu1_src[wd - 1] - pu1_src_top_right[1]) +
1226
23.1k
                        SIGN(pu1_src[wd - 1] - pu1_src[wd - 1 - 2 + src_strd]);
1227
1228
23.1k
        edge_idx = gi4_ihevc_table_edge_idx[edge_idx];
1229
1230
23.1k
        if(0 != edge_idx)
1231
4.00k
        {
1232
4.00k
            u1_pos_wd_0_tmp_v = CLIP3(pu1_src[wd - 1] + pi1_sao_offset_v[edge_idx], 0, (1 << bit_depth) - 1);
1233
4.00k
        }
1234
19.1k
        else
1235
19.1k
        {
1236
19.1k
            u1_pos_wd_0_tmp_v = pu1_src[wd - 1];
1237
19.1k
        }
1238
23.1k
    }
1239
7.80k
    else
1240
7.80k
    {
1241
7.80k
        u1_pos_wd_0_tmp_u = pu1_src[wd - 2];
1242
7.80k
        u1_pos_wd_0_tmp_v = pu1_src[wd - 1];
1243
7.80k
    }
1244
1245
    /* If bottom-left is available, process separately */
1246
30.9k
    if(0 != pu1_avail[6])
1247
23.1k
    {
1248
23.1k
        WORD32 edge_idx;
1249
1250
        /* U */
1251
23.1k
        edge_idx = 2 + SIGN(pu1_src[(ht - 1) * src_strd] - pu1_src[(ht - 1) * src_strd + 2 - src_strd]) +
1252
23.1k
                        SIGN(pu1_src[(ht - 1) * src_strd] - pu1_src_bot_left[0]);
1253
1254
23.1k
        edge_idx = gi4_ihevc_table_edge_idx[edge_idx];
1255
1256
23.1k
        if(0 != edge_idx)
1257
4.74k
        {
1258
4.74k
            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
4.74k
        }
1260
18.4k
        else
1261
18.4k
        {
1262
18.4k
            u1_pos_0_ht_tmp_u = pu1_src[(ht - 1) * src_strd];
1263
18.4k
        }
1264
1265
        /* V */
1266
23.1k
        edge_idx = 2 + SIGN(pu1_src[(ht - 1) * src_strd + 1] - pu1_src[(ht - 1) * src_strd + 1 + 2 - src_strd]) +
1267
23.1k
                        SIGN(pu1_src[(ht - 1) * src_strd + 1] - pu1_src_bot_left[1]);
1268
1269
23.1k
        edge_idx = gi4_ihevc_table_edge_idx[edge_idx];
1270
1271
23.1k
        if(0 != edge_idx)
1272
4.41k
        {
1273
4.41k
            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
4.41k
        }
1275
18.7k
        else
1276
18.7k
        {
1277
18.7k
            u1_pos_0_ht_tmp_v = pu1_src[(ht - 1) * src_strd + 1];
1278
18.7k
        }
1279
23.1k
    }
1280
7.76k
    else
1281
7.76k
    {
1282
7.76k
        u1_pos_0_ht_tmp_u = pu1_src[(ht - 1) * src_strd];
1283
7.76k
        u1_pos_0_ht_tmp_v = pu1_src[(ht - 1) * src_strd + 1];
1284
7.76k
    }
1285
1286
    /* If Left is not available */
1287
30.9k
    if(0 == pu1_avail[0])
1288
3.00k
    {
1289
3.00k
        au1_mask[0] = 0;
1290
3.00k
    }
1291
1292
    /* If Top is not available */
1293
30.9k
    if(0 == pu1_avail[2])
1294
6.13k
    {
1295
6.13k
        pu1_src += src_strd;
1296
6.13k
        ht--;
1297
6.13k
        pu1_src_left_cpy += 2;
1298
205k
        for(col = 0; col < wd - 2; col++)
1299
199k
        {
1300
199k
            au1_sign_up[col] = SIGN(pu1_src[col] - pu1_src[col + 2 - src_strd]);
1301
199k
        }
1302
6.13k
    }
1303
24.7k
    else
1304
24.7k
    {
1305
797k
        for(col = 0; col < wd - 2; col++)
1306
772k
        {
1307
772k
            au1_sign_up[col] = SIGN(pu1_src[col] - pu1_src_top[col + 2]);
1308
772k
        }
1309
24.7k
    }
1310
1311
    /* If Right is not available */
1312
30.9k
    if(0 == pu1_avail[1])
1313
2.46k
    {
1314
2.46k
        au1_mask[(wd - 1) >> 1] = 0;
1315
2.46k
    }
1316
1317
    /* If Bottom is not available */
1318
30.9k
    if(0 == pu1_avail[3])
1319
5.32k
    {
1320
5.32k
        ht--;
1321
5.32k
    }
1322
1323
    /* Processing is done on the intermediate buffer and the output is written to the source buffer */
1324
30.9k
    {
1325
530k
        for(row = 0; row < ht; row++)
1326
499k
        {
1327
499k
            au1_sign_up[wd - 2] = SIGN(pu1_src[wd - 2] - pu1_src[wd - 2 + 2 - src_strd]);
1328
499k
            au1_sign_up[wd - 1] = SIGN(pu1_src[wd - 1] - pu1_src[wd - 1 + 2 - src_strd]);
1329
18.2M
            for(col = 0; col < wd; col++)
1330
17.7M
            {
1331
17.7M
                WORD32 edge_idx;
1332
17.7M
                WORD8 *pi1_sao_offset;
1333
1334
17.7M
                pi1_sao_offset = (0 == col % 2) ? pi1_sao_offset_u : pi1_sao_offset_v;
1335
1336
17.7M
                u1_sign_down = SIGN(pu1_src[col] - ((col < 2) ? pu1_src_left_cpy[2 * (row + 1) + col] :
1337
17.7M
                                                                pu1_src[col - 2 + src_strd]));
1338
17.7M
                edge_idx = 2 + au1_sign_up[col] + u1_sign_down;
1339
17.7M
                if(col > 1)
1340
16.7M
                    au1_sign_up[col - 2] = -u1_sign_down;
1341
1342
17.7M
                edge_idx = gi4_ihevc_table_edge_idx[edge_idx] & au1_mask[col >> 1];
1343
1344
17.7M
                if(0 != edge_idx)
1345
2.57M
                {
1346
2.57M
                    pu1_src[col] = CLIP3(pu1_src[col] + pi1_sao_offset[edge_idx], 0, (1 << bit_depth) - 1);
1347
2.57M
                }
1348
17.7M
            }
1349
1350
499k
            pu1_src += src_strd;
1351
499k
        }
1352
1353
30.9k
        pu1_src[-(pu1_avail[2] ? ht : ht + 1) * src_strd + wd - 2] = u1_pos_wd_0_tmp_u;
1354
30.9k
        pu1_src[-(pu1_avail[2] ? ht : ht + 1) * src_strd + wd - 1] = u1_pos_wd_0_tmp_v;
1355
30.9k
        pu1_src[(pu1_avail[3] ?  (-src_strd) : 0)] = u1_pos_0_ht_tmp_u;
1356
30.9k
        pu1_src[(pu1_avail[3] ?  (-src_strd) : 0) + 1] = u1_pos_0_ht_tmp_v;
1357
30.9k
    }
1358
1359
30.9k
    if(0 == pu1_avail[2])
1360
6.13k
        ht++;
1361
30.9k
    if(0 == pu1_avail[3])
1362
5.32k
        ht++;
1363
30.9k
    pu1_src_top_left[0] = au1_src_top_left_tmp[0];
1364
30.9k
    pu1_src_top_left[1] = au1_src_top_left_tmp[1];
1365
1.05M
    for(row = 0; row < 2 * ht; row++)
1366
1.02M
    {
1367
1.02M
        pu1_src_left[row] = au1_src_left_tmp[row];
1368
1.02M
    }
1369
1.06M
    for(col = 0; col < wd; col++)
1370
1.03M
    {
1371
1.03M
        pu1_src_top[col] = au1_src_top_tmp[col];
1372
1.03M
    }
1373
1374
30.9k
}