quantize.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:2k
- #include "Includesysdefs.h"
- #ifdef SUPPORT_CAPTURE_LOGO
- CONST char quant_mat[8][8]={
- { 8, 16, 19, 22, 26, 27, 29, 34},
- {16, 16, 22, 24, 27, 29, 34, 37},
- {19, 22, 26, 27, 29, 34, 34, 38},
- {22, 22, 26, 27, 29, 34, 37, 40},
- {22, 26, 27, 29, 32, 35, 40, 48},
- {26, 27, 29, 32, 35, 40, 48, 58},
- {26, 27, 29, 34, 38, 46, 56, 69},
- {27, 29, 35, 38, 46, 56, 69, 83}
- };
- void quant_intra(short src[8][8],int dc_prec,int mquant)
- {
-
- long x, d;
- x = (long)src[0][0];
- d = 8>>dc_prec; /* intra_dc_mult */
- src[0][0] = (short)((x>=0) ? (x+(d>>1))/d : -((-x+(d>>1))/d)); /* round(x/d) */
- #if 0
- for (k=1; k<64; k++)
- {
- i=k/8;
- j=k&7;
- x = (long)src[i][j];
- d = (long)quant_mat[i][j];
- y = (32*(x>=0 ? x : -x) + (d>>1))/d; /* round(32*x/quant_mat) */
- d = (3*mquant+2)>>2;
- y = (y+d)/(2*mquant); /* (y+0.75*mquant) / (2*mquant) */
- /* clip to syntax limits */
- if (y > 2047)
- {
- y = 2047;
- }
- src[i][j] = (short)((x>=0) ? y : -y);
- }
- #endif
- /*
- ax - x,y
- bx - sign of x
- cx - d
- dx - mquant
- es:di - quant_mat
- ds:si - src
- */
- asm{
- lds si,src
- add si,2
- mov ax,seg quant_mat
- mov es,ax
- mov di,1
- loop_k:
- mov ax,[si] // x = src[i][j];
- xor bx,bx
- cmp ax,0
- jg no_neg
- neg ax
- mov bx,1
- no_neg: // x = abs(x); bx = sign(x)
- mov cl,byte ptr es:quant_mat[di] // d = quant_mat[i][j];
- xor ch,ch
- shl ax,5 // the following lines do: ((32*x)/(d>>1)+1)>>1
- shr cx,1
- xor dx,dx
- div cx
- inc ax
- shr ax,1
- mov dx,[mquant]
- mov cx,dx // d*=3
- shl cx,1
- add cx,dx
- add cx,2
- shr cx,1 // d>>=2
- shr cx,1
- add ax,dx // y+d
- mov cx,dx
- shl cx,1
- xor dx,dx
- div cx
- cmp ax,2047 // if( y>2047 )
- jl no_overflow
- mov ax,2047
- no_overflow:
- cmp bx,1 // ((x>=0) ? y : -y);
- jne no_neg1
- neg ax
- no_neg1:
- mov [si],ax
- add si,2
- add di,1
- cmp di,64
- jne loop_k
- }
- }
- #endif