1 |
/***************************************************************************** |
/************************************************************************** |
2 |
* |
* |
3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - Mpeg4 quantization/dequantization functions - |
* mpeg-4 quantization/dequantization |
|
* |
|
|
* Copyright(C) 2002 Peter Ross |
|
5 |
* |
* |
6 |
* This program is an implementation of a part of one or more MPEG-4 |
* This program is an implementation of a part of one or more MPEG-4 |
7 |
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
24 |
* |
* |
25 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
26 |
* along with this program ; if not, write to the Free Software |
* along with this program ; if not, write to the Free Software |
27 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
28 |
|
* |
29 |
|
*************************************************************************/ |
30 |
|
|
31 |
|
/************************************************************************** |
32 |
|
* |
33 |
|
* History: |
34 |
* |
* |
35 |
* $Id: quant_mpeg4.c,v 1.4 2002-09-07 11:21:10 edgomez Exp $ |
* 26.01.2002 fixed quant4_intra dcscalar signed/unsigned error |
36 |
|
* 20.01.2002 increased accuracy of >> divide |
37 |
|
* 26.12.2001 divide-by-multiplication optimization |
38 |
|
* 22.12.2001 [-127,127] clamping removed; minor tweaks |
39 |
|
* 19.11.2001 inital version <pross@cs.rmit.edu.au> |
40 |
* |
* |
41 |
****************************************************************************/ |
*************************************************************************/ |
42 |
|
|
43 |
|
#include "../global.h" |
44 |
#include "quant_mpeg4.h" |
#include "quant_mpeg4.h" |
45 |
#include "quant_matrix.h" |
#include "quant_matrix.h" |
46 |
|
|
47 |
/***************************************************************************** |
// function pointers |
|
* Function pointers |
|
|
****************************************************************************/ |
|
|
|
|
48 |
quant_intraFuncPtr quant4_intra; |
quant_intraFuncPtr quant4_intra; |
49 |
quant_intraFuncPtr dequant4_intra; |
quant_intraFuncPtr dequant4_intra; |
50 |
dequant_interFuncPtr dequant4_inter; |
dequant_interFuncPtr dequant4_inter; |
51 |
quant_interFuncPtr quant4_inter; |
quant_interFuncPtr quant4_inter; |
52 |
|
|
53 |
|
|
|
/***************************************************************************** |
|
|
* Local data |
|
|
****************************************************************************/ |
|
|
|
|
|
#define DIV_DIV(A,B) ( (A) > 0 ? ((A)+((B)>>1))/(B) : ((A)-((B)>>1))/(B) ) |
|
|
#define SIGN(A) ((A)>0?1:-1) |
|
54 |
#define VM18P 3 |
#define VM18P 3 |
55 |
#define VM18Q 4 |
#define VM18Q 4 |
56 |
|
|
57 |
|
|
58 |
/* |
// divide-by-multiply table |
59 |
* divide-by-multiply table |
// need 17 bit shift (16 causes slight errors when q > 19) |
|
* need 17 bit shift (16 causes slight errors when q > 19) |
|
|
*/ |
|
60 |
|
|
61 |
#define SCALEBITS 17 |
#define SCALEBITS 17 |
62 |
#define FIX(X) ((1UL << SCALEBITS) / (X) + 1) |
#define FIX(X) ((1UL << SCALEBITS) / (X) + 1) |
72 |
FIX(56), FIX(58), FIX(60), FIX(62) |
FIX(56), FIX(58), FIX(60), FIX(62) |
73 |
}; |
}; |
74 |
|
|
|
/***************************************************************************** |
|
|
* Functions |
|
|
****************************************************************************/ |
|
|
|
|
75 |
/* quantize intra-block |
/* quantize intra-block |
76 |
|
|
77 |
// const int32_t quantd = DIV_DIV(VM18P*quant, VM18Q); |
// const int32_t quantd = DIV_DIV(VM18P*quant, VM18Q); |