1 |
|
/***************************************************************************** |
2 |
|
* |
3 |
|
* XVID MPEG-4 VIDEO CODEC |
4 |
|
* - Adaptive quantization functions - |
5 |
|
* |
6 |
|
* Copyright(C) 2002 Peter Ross <pross@xvid.org> |
7 |
|
* |
8 |
|
* This program is an implementation of a part of one or more MPEG-4 |
9 |
|
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
10 |
|
* to use this software module in hardware or software products are |
11 |
|
* advised that its use may infringe existing patents or copyrights, and |
12 |
|
* any such use would be at such party's own risk. The original |
13 |
|
* developer of this software module and his/her company, and subsequent |
14 |
|
* editors and their companies, will have no liability for use of this |
15 |
|
* software or modifications or derivatives thereof. |
16 |
|
* |
17 |
|
* This program is free software ; you can redistribute it and/or modify |
18 |
|
* it under the terms of the GNU General Public License as published by |
19 |
|
* the Free Software Foundation ; either version 2 of the License, or |
20 |
|
* (at your option) any later version. |
21 |
|
* |
22 |
|
* This program is distributed in the hope that it will be useful, |
23 |
|
* but WITHOUT ANY WARRANTY ; without even the implied warranty of |
24 |
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
25 |
|
* GNU General Public License for more details. |
26 |
|
* |
27 |
|
* You should have received a copy of the GNU General Public License |
28 |
|
* along with this program ; if not, write to the Free Software |
29 |
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
30 |
|
* |
31 |
|
* $Id: adapt_quant.c,v 1.10 2002-09-21 03:07:56 suxen_drol Exp $ |
32 |
|
* |
33 |
|
****************************************************************************/ |
34 |
|
|
35 |
#include "../portab.h" |
#include "../portab.h" |
36 |
#include "adapt_quant.h" |
#include "adapt_quant.h" |
37 |
|
|
40 |
#define MAX(a,b) (((a) > (b)) ? (a) : (b)) |
#define MAX(a,b) (((a) > (b)) ? (a) : (b)) |
41 |
#define RDIFF(a,b) ((int)(a+0.5)-(int)(b+0.5)) |
#define RDIFF(a,b) ((int)(a+0.5)-(int)(b+0.5)) |
42 |
|
|
43 |
|
/***************************************************************************** |
44 |
|
* Functions |
45 |
|
****************************************************************************/ |
46 |
|
|
47 |
int |
int |
48 |
normalize_quantizer_field(float *in, |
normalize_quantizer_field(float *in, |
49 |
int *out, |
int *out, |
103 |
{ |
{ |
104 |
int i, j, k, l; |
int i, j, k, l; |
105 |
|
|
106 |
static float *quant; |
float *quant; |
107 |
unsigned char *ptr; |
unsigned char *ptr; |
108 |
float *val; |
float *val; |
109 |
float global = 0.; |
float global = 0.; |
122 |
const float LowerLimit = 25; |
const float LowerLimit = 25; |
123 |
|
|
124 |
|
|
|
if (!quant) |
|
125 |
if (!(quant = (float *) malloc(mb_width * mb_height * sizeof(float)))) |
if (!(quant = (float *) malloc(mb_width * mb_height * sizeof(float)))) |
126 |
return -1; |
return(-1); |
127 |
|
|
128 |
val = (float *) malloc(mb_width * mb_height * sizeof(float)); |
if(!(val = (float *) malloc(mb_width * mb_height * sizeof(float)))) { |
129 |
|
free(quant); |
130 |
|
return(-1); |
131 |
|
} |
132 |
|
|
133 |
for (k = 0; k < mb_height; k++) { |
for (k = 0; k < mb_height; k++) { |
134 |
for (l = 0; l < mb_width; l++) // do this for all macroblocks individually |
for (l = 0; l < mb_width; l++) // do this for all macroblocks individually |
170 |
} |
} |
171 |
} |
} |
172 |
} |
} |
173 |
free(val); |
|
174 |
return normalize_quantizer_field(quant, intquant, mb_width * mb_height, |
i = normalize_quantizer_field(quant, intquant, |
175 |
|
mb_width * mb_height, |
176 |
min_quant, max_quant); |
min_quant, max_quant); |
177 |
|
|
178 |
|
free(val); |
179 |
|
free(quant); |
180 |
|
|
181 |
|
return(i); |
182 |
|
|
183 |
} |
} |