Coverage Report

Created: 2026-10-28 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libmpeg2/decoder/impeg2d_d_pic.c
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
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
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
#include <string.h>
21
#include "iv_datatypedef.h"
22
#include "impeg2_defs.h"
23
#include "impeg2_globals.h"
24
#include "impeg2_platform_macros.h"
25
#include "impeg2_inter_pred.h"
26
#include "impeg2_idct.h"
27
#include "impeg2_format_conv.h"
28
#include "impeg2_disp_mgr.h"
29
#include "impeg2_buf_mgr.h"
30
31
#include "impeg2d.h"
32
#include "impeg2d_bitstream.h"
33
#include "impeg2d_structs.h"
34
#include "impeg2d_vld.h"
35
#include "impeg2d_vld_tables.h"
36
37
4.35G
#define BLK_SIZE 8
38
#define LUMA_BLK_SIZE (2 * (BLK_SIZE))
39
#define CHROMA_BLK_SIZE (BLK_SIZE)
40
/*****************************************************************************/
41
/*                                                                           */
42
/*  Function Name : impeg2d_get_luma_dc_diff                                         */
43
/*                                                                           */
44
/*  Description   : Decode the DC differential value from the bitstream for  */
45
/*                  luma block                                               */
46
/*                                                                           */
47
/*  Inputs        : stream - Input stream                                    */
48
/*                                                                           */
49
/*  Globals       : None                                                     */
50
/*                                                                           */
51
/*  Processing    : Decode the vlc for dc_diff                               */
52
/*                                                                           */
53
/*  Outputs       : dc_diff - dc differential used in dc prediction          */
54
/*                                                                           */
55
/*  Returns       : dc_diff - dc differential used in dc prediction          */
56
/*                                                                           */
57
/*  Issues        : None                                                     */
58
/*                                                                           */
59
/*  Revision History:                                                        */
60
/*                                                                           */
61
/*         DD MM YYYY   Author(s)       Changes                              */
62
/*         14 09 2005   Harish M        First Version                        */
63
/*                                                                           */
64
/*****************************************************************************/
65
WORD16  impeg2d_get_luma_dc_diff(stream_t *ps_stream)
66
322M
{
67
322M
    UWORD16 u2_dc_size;
68
322M
    WORD16  i2_dc_diff;
69
70
322M
    u2_dc_size = impeg2d_dec_vld_symbol(ps_stream,gai2_impeg2d_dct_dc_size[0],
71
322M
                        MPEG2_DCT_DC_LUMA_SIZE_LEN) +
72
322M
                        MPEG2_DCT_DC_SIZE_OFFSET;
73
322M
    if (u2_dc_size != 0)
74
291M
    {
75
291M
        i2_dc_diff = impeg2d_bit_stream_get(ps_stream,u2_dc_size);
76
291M
        if ((i2_dc_diff & (1 << (u2_dc_size - 1))) == 0)
77
225M
            i2_dc_diff -= (1 << u2_dc_size) - 1;
78
291M
    }
79
30.6M
    else
80
30.6M
    {
81
30.6M
        i2_dc_diff = 0;
82
30.6M
    }
83
322M
    return i2_dc_diff;
84
322M
}
85
86
/*****************************************************************************/
87
/*                                                                           */
88
/*  Function Name : impeg2d_get_chroma_dc_diff                                       */
89
/*                                                                           */
90
/*  Description   : Decode the DC differential value from the bitstream for  */
91
/*                  chroma block                                             */
92
/*                                                                           */
93
/*  Inputs        : stream - Input stream                                    */
94
/*                                                                           */
95
/*  Globals       : None                                                     */
96
/*                                                                           */
97
/*  Processing    : Decode the vlc for dc_diff                               */
98
/*                                                                           */
99
/*  Outputs       : dc_diff - dc differential used in dc prediction          */
100
/*                                                                           */
101
/*  Returns       : dc_diff - dc differential used in dc prediction          */
102
/*                                                                           */
103
/*  Issues        : None                                                     */
104
/*                                                                           */
105
/*  Revision History:                                                        */
106
/*                                                                           */
107
/*         DD MM YYYY   Author(s)       Changes                              */
108
/*         14 09 2005   Harish M        First Version                        */
109
/*                                                                           */
110
/*****************************************************************************/
111
WORD16  impeg2d_get_chroma_dc_diff(stream_t *ps_stream)
112
161M
{
113
161M
    UWORD16 u2_dc_size;
114
161M
    WORD16  i2_dc_diff;
115
161M
    u2_dc_size = impeg2d_dec_vld_symbol(ps_stream,gai2_impeg2d_dct_dc_size[1],
116
161M
                        MPEG2_DCT_DC_CHROMA_SIZE_LEN) +
117
161M
                        MPEG2_DCT_DC_SIZE_OFFSET;
118
161M
    if (u2_dc_size != 0)
119
75.3M
    {
120
75.3M
        i2_dc_diff = impeg2d_bit_stream_get(ps_stream,u2_dc_size);
121
75.3M
        if ((i2_dc_diff & (1 << (u2_dc_size - 1))) == 0)
122
43.9M
            i2_dc_diff -= (1 << u2_dc_size) - 1;
123
75.3M
    }
124
85.7M
    else
125
85.7M
    {
126
85.7M
        i2_dc_diff = 0;
127
85.7M
    }
128
161M
    return i2_dc_diff;
129
161M
}
130
/*******************************************************************************
131
*  Function Name   : impeg2d_dec_d_slice
132
*
133
*  Description     : Decodes I slice
134
*
135
*  Arguments       :
136
*  dec             : Decoder state
137
*
138
*  Values Returned : None
139
*******************************************************************************/
140
IMPEG2D_ERROR_CODES_T impeg2d_dec_d_slice(dec_state_t *ps_dec)
141
7.58M
{
142
7.58M
    UWORD32 i;
143
7.58M
    yuv_buf_t *ps_cur_frm_buf  = &ps_dec->s_cur_frm_buf;
144
145
7.58M
    stream_t   *ps_stream       = &ps_dec->s_bit_stream;
146
7.58M
    UWORD8   *pu1_vld_buf;
147
148
7.58M
    WORD16 i2_dc_diff;
149
7.58M
    WORD32 row;
150
7.58M
    UWORD32 u4_frame_width = ps_dec->u2_frame_width;
151
7.58M
    UWORD32 u4_frm_offset = 0;
152
7.58M
    if(ps_dec->u2_picture_structure != FRAME_PICTURE)
153
2.58k
    {
154
2.58k
        u4_frame_width <<= 1;
155
2.58k
        if(ps_dec->u2_picture_structure == BOTTOM_FIELD)
156
2.35k
        {
157
2.35k
            u4_frm_offset = ps_dec->u2_frame_width;
158
2.35k
        }
159
2.58k
    }
160
161
7.58M
    do
162
80.5M
    {
163
164
80.5M
        UWORD32 u4_x_offset, u4_y_offset;
165
80.5M
        UWORD32 u4_blk_pos;
166
80.5M
        WORD16 i2_dc_val;
167
168
80.5M
        UWORD32 u4_dst_x_offset     = u4_frm_offset + (ps_dec->u2_mb_x << 4);
169
80.5M
        UWORD32 u4_dst_y_offset     = (ps_dec->u2_mb_y << 4) * u4_frame_width;
170
80.5M
        UWORD8 *pu1_vld_buf8        = ps_cur_frm_buf->pu1_y + u4_dst_x_offset + u4_dst_y_offset;
171
80.5M
        UWORD32 u4_dst_wd           = u4_frame_width;
172
        /*------------------------------------------------------------------*/
173
        /* Discard the Macroblock stuffing in case of MPEG-1 stream         */
174
        /*------------------------------------------------------------------*/
175
82.3M
        while(impeg2d_bit_stream_nxt(ps_stream,MB_STUFFING_CODE_LEN) == MB_STUFFING_CODE &&
176
1.82M
                ps_stream->u4_offset < ps_stream->u4_max_offset)
177
1.82M
            impeg2d_bit_stream_flush(ps_stream,MB_STUFFING_CODE_LEN);
178
179
        /*------------------------------------------------------------------*/
180
        /* Flush 2 bits from bitstream [MB_Type and MacroBlockAddrIncrement]*/
181
        /*------------------------------------------------------------------*/
182
80.5M
        impeg2d_bit_stream_flush(ps_stream,1);
183
184
80.5M
        if(impeg2d_bit_stream_get(ps_stream, 1) != 0x01)
185
57.4M
        {
186
            /* Ignore and continue decoding. */
187
57.4M
        }
188
189
        /* Process LUMA blocks of the MB */
190
402M
        for(i = 0; i < NUM_LUMA_BLKS; ++i)
191
322M
        {
192
193
322M
            u4_x_offset    = gai2_impeg2_blk_x_off[i];
194
322M
            u4_y_offset    = gai2_impeg2_blk_y_off_frm[i] ;
195
322M
            u4_blk_pos     = (u4_y_offset * u4_dst_wd) + u4_x_offset;
196
322M
            pu1_vld_buf     = pu1_vld_buf8 + u4_blk_pos;
197
198
322M
            i2_dc_diff = impeg2d_get_luma_dc_diff(ps_stream);
199
322M
            i2_dc_val = ps_dec->u2_def_dc_pred[Y_LUMA] + i2_dc_diff;
200
322M
            ps_dec->u2_def_dc_pred[Y_LUMA] = i2_dc_val;
201
322M
            i2_dc_val = CLIP_U8(i2_dc_val);
202
203
2.90G
            for(row = BLK_SIZE; row > 0; row--)
204
2.57G
            {
205
2.57G
                memset(pu1_vld_buf, i2_dc_val, BLK_SIZE);
206
2.57G
                pu1_vld_buf += u4_dst_wd;
207
2.57G
            }
208
322M
        }
209
210
211
212
        /* Process U block of the MB */
213
214
80.5M
        u4_dst_x_offset                >>= 1;
215
80.5M
        u4_dst_y_offset                >>= 2;
216
80.5M
        u4_dst_wd                      >>= 1;
217
80.5M
        pu1_vld_buf                     = ps_cur_frm_buf->pu1_u + u4_dst_x_offset + u4_dst_y_offset;
218
80.5M
        i2_dc_diff                     = impeg2d_get_chroma_dc_diff(ps_stream);
219
80.5M
        i2_dc_val                      = ps_dec->u2_def_dc_pred[U_CHROMA] + i2_dc_diff;
220
80.5M
        ps_dec->u2_def_dc_pred[U_CHROMA]    = i2_dc_val;
221
80.5M
        i2_dc_val = CLIP_U8(i2_dc_val);
222
725M
        for(row = BLK_SIZE; row > 0; row--)
223
644M
        {
224
644M
            memset(pu1_vld_buf, i2_dc_val, BLK_SIZE);
225
644M
            pu1_vld_buf += u4_dst_wd;
226
644M
        }
227
228
229
        /* Process V block of the MB */
230
231
80.5M
        pu1_vld_buf                     = ps_cur_frm_buf->pu1_v + u4_dst_x_offset + u4_dst_y_offset;
232
80.5M
        i2_dc_diff                     = impeg2d_get_chroma_dc_diff(ps_stream);
233
80.5M
        i2_dc_val                      = ps_dec->u2_def_dc_pred[V_CHROMA] + i2_dc_diff;
234
80.5M
        ps_dec->u2_def_dc_pred[V_CHROMA]    = i2_dc_val;
235
80.5M
        i2_dc_val = CLIP_U8(i2_dc_val);
236
725M
        for(row = BLK_SIZE; row > 0; row--)
237
644M
        {
238
644M
            memset(pu1_vld_buf, i2_dc_val, BLK_SIZE);
239
644M
            pu1_vld_buf += u4_dst_wd;
240
644M
        }
241
242
        /* Common MB processing Steps */
243
244
245
80.5M
        ps_dec->u2_num_mbs_left--;
246
80.5M
        ps_dec->u2_mb_x++;
247
248
80.5M
        if(ps_dec->s_bit_stream.u4_offset > ps_dec->s_bit_stream.u4_max_offset)
249
3.70k
        {
250
3.70k
            return IMPEG2D_BITSTREAM_BUFF_EXCEEDED_ERR;
251
3.70k
        }
252
80.5M
        else if (ps_dec->u2_mb_x == ps_dec->u2_num_horiz_mb)
253
992k
        {
254
992k
            ps_dec->u2_mb_x = 0;
255
992k
            ps_dec->u2_mb_y++;
256
257
992k
        }
258
259
        /* Flush end of macro block */
260
80.5M
        impeg2d_bit_stream_flush(ps_stream,1);
261
80.5M
    }
262
80.5M
    while(ps_dec->u2_num_mbs_left != 0 && impeg2d_bit_stream_nxt(&ps_dec->s_bit_stream,23) != 0x0);
263
7.58M
    return (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE;
264
7.58M
}/* End of impeg2d_dec_d_slice() */