1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 #include "mp4dec_lib.h"
19 #include "vlc_decode.h"
20 #include "bitstream.h"
21 #include "zigzag.h"
22 
PV_DecodePredictedIntraDC(int compnum,BitstreamDecVideo * stream,int16 * INTRADC_delta)23 PV_STATUS PV_DecodePredictedIntraDC(
24     int compnum,
25     BitstreamDecVideo *stream,
26     int16 *INTRADC_delta)
27 {
28 
29     /*----------------------------------------------------------------------------
30     ; Define all local variables
31     ----------------------------------------------------------------------------*/
32     PV_STATUS status = PV_SUCCESS;
33     uint DC_size;
34     uint code;
35     int first_bit;
36 
37     /*----------------------------------------------------------------------------
38     ; Function body here
39     ----------------------------------------------------------------------------*/
40     /* read DC size 2 - 8 bits */
41     status = PV_VlcDecIntraDCPredSize(stream, compnum, &DC_size);
42 
43     if (status == PV_SUCCESS)
44     {
45         if (DC_size == 0)
46         {
47             *INTRADC_delta = 0;
48         }
49         else
50         {
51             /* read delta DC 0 - 8 bits */
52             code = (int) BitstreamReadBits16_INLINE(stream, DC_size);
53 
54             first_bit = code >> (DC_size - 1);
55 
56             if (first_bit == 0)
57             {
58                 /* negative delta INTRA DC */
59                 *INTRADC_delta = code ^((1 << DC_size) - 1);
60                 *INTRADC_delta = -(*INTRADC_delta);
61             }
62             else
63             { /* positive delta INTRA DC */
64                 *INTRADC_delta = code;
65             }
66             if (DC_size > 8) BitstreamRead1Bits_INLINE(stream);
67         }
68     }
69 
70     /*----------------------------------------------------------------------------
71     ; Return nothing or data or data pointer
72     ----------------------------------------------------------------------------*/
73     return status;
74 }
75 
76