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 /*
19 ------------------------------------------------------------------------------
20  INPUT AND OUTPUT DEFINITIONS
21 
22  Inputs:
23     [input_variable_name] = [description of the input to module, its type
24                  definition, and length (when applicable)]
25 
26  Local Stores/Buffers/Pointers Needed:
27     [local_store_name] = [description of the local store, its type
28                   definition, and length (when applicable)]
29     [local_buffer_name] = [description of the local buffer, its type
30                    definition, and length (when applicable)]
31     [local_ptr_name] = [description of the local pointer, its type
32                 definition, and length (when applicable)]
33 
34  Global Stores/Buffers/Pointers Needed:
35     [global_store_name] = [description of the global store, its type
36                    definition, and length (when applicable)]
37     [global_buffer_name] = [description of the global buffer, its type
38                 definition, and length (when applicable)]
39     [global_ptr_name] = [description of the global pointer, its type
40                  definition, and length (when applicable)]
41 
42  Outputs:
43     [return_variable_name] = [description of data/pointer returned
44                   by module, its type definition, and length
45                   (when applicable)]
46 
47  Pointers and Buffers Modified:
48     [variable_bfr_ptr] points to the [describe where the
49       variable_bfr_ptr points to, its type definition, and length
50       (when applicable)]
51     [variable_bfr] contents are [describe the new contents of
52       variable_bfr]
53 
54  Local Stores Modified:
55     [local_store_name] = [describe new contents, its type
56                   definition, and length (when applicable)]
57 
58  Global Stores Modified:
59     [global_store_name] = [describe new contents, its type
60                    definition, and length (when applicable)]
61 
62 ------------------------------------------------------------------------------
63  FUNCTION DESCRIPTION
64 
65  This module calculates the DC quantization scale according
66  to the incoming Q and type.
67 
68 ------------------------------------------------------------------------------
69  REQUIREMENTS
70 
71  [List requirements to be satisfied by this module.]
72 
73 ------------------------------------------------------------------------------
74  REFERENCES
75 
76  [List all references used in designing this module.]
77 
78 ------------------------------------------------------------------------------
79  PSEUDO-CODE
80 
81 ------------------------------------------------------------------------------
82  RESOURCES USED
83    When the code is written for a specific target processor the
84      the resources used should be documented below.
85 
86  STACK USAGE: [stack count for this module] + [variable to represent
87           stack usage for each subroutine called]
88 
89      where: [stack usage variable] = stack usage for [subroutine
90          name] (see [filename].ext)
91 
92  DATA MEMORY USED: x words
93 
94  PROGRAM MEMORY USED: x words
95 
96  CLOCK CYCLES: [cycle count equation for this module] + [variable
97            used to represent cycle count for each subroutine
98            called]
99 
100      where: [cycle count variable] = cycle count for [subroutine
101         name] (see [filename].ext)
102 
103 ------------------------------------------------------------------------------
104 */
105 
106 
107 /*----------------------------------------------------------------------------
108 ; INCLUDES
109 ----------------------------------------------------------------------------*/
110 #include    "mp4dec_lib.h"
111 #include    "vlc_decode.h"
112 #include    "bitstream.h"
113 #include    "zigzag.h"
114 
115 /*----------------------------------------------------------------------------
116 ; MACROS
117 ; Define module specific macros here
118 ----------------------------------------------------------------------------*/
119 
120 
121 /*----------------------------------------------------------------------------
122 ; DEFINES
123 ; Include all pre-processor statements here. Include conditional
124 ; compile variables also.
125 ----------------------------------------------------------------------------*/
126 
127 /*----------------------------------------------------------------------------
128 ; LOCAL FUNCTION DEFINITIONS
129 ; Function Prototype declaration
130 ----------------------------------------------------------------------------*/
131 
132 /*----------------------------------------------------------------------------
133 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
134 ; Variable declaration - defined here and used outside this module
135 ----------------------------------------------------------------------------*/
136 
137 /*----------------------------------------------------------------------------
138 ; EXTERNAL FUNCTION REFERENCES
139 ; Declare functions defined elsewhere and referenced in this module
140 ----------------------------------------------------------------------------*/
141 
142 /*----------------------------------------------------------------------------
143 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
144 ; Declare variables used in this module but defined elsewhere
145 ----------------------------------------------------------------------------*/
146 
147 /*----------------------------------------------------------------------------
148 ; FUNCTION CODE
149 ----------------------------------------------------------------------------*/
cal_dc_scaler(int QP,int type)150 int cal_dc_scaler(
151     int QP,
152     int type)
153 {
154 
155     /*----------------------------------------------------------------------------
156     ; Define all local variables
157     ----------------------------------------------------------------------------*/
158     int dc_scaler;
159 
160     /*----------------------------------------------------------------------------
161     ; Function body here
162     ----------------------------------------------------------------------------*/
163     if (type == LUMINANCE_DC_TYPE)
164     {
165         if (QP > 0 && QP < 5) dc_scaler = 8;
166         else if (QP > 4 && QP < 9) dc_scaler = 2 * QP;
167         else if (QP > 8 && QP < 25) dc_scaler = QP + 8;
168         else dc_scaler = 2 * QP - 16;
169     }
170     else /* if (type == CHROMINANCE_DC_TYPE), there is no other types.  */
171     {
172         if (QP > 0 && QP < 5) dc_scaler = 8;
173         else if (QP > 4 && QP < 25) dc_scaler = (QP + 13) >> 1;
174         else dc_scaler = QP - 6;
175     }
176 
177     /*----------------------------------------------------------------------------
178     ; Return nothing or data or data pointer
179     ----------------------------------------------------------------------------*/
180     return dc_scaler;
181 }
182 
183