mot_util.c
资源名称:VC++视频传输.rar [点击查看]
上传用户:hxb_1234
上传日期:2010-03-30
资源大小:8328k
文件大小:6k
源码类别:
VC书籍
开发平台:
Visual C++
- #include "mom_structs.h"
- #include "vm_common_defs.h"
- #include "mot_util.h"
- #define DIFF1(v1,v2,idx) (P_diff = (v1[idx]-v2[idx]), ABS(P_diff))
- Void
- InterpolateImage(
- Image *input_image,
- Image *output_image,
- Int rounding_control
- )
- {
- SInt *ii, *oo;
- UInt i, j;
- UInt width, height;
- width = input_image->x;
- height = input_image->y;
- ii = (SInt*)GetImageData(output_image);
- oo = (SInt*)GetImageData(input_image);
- for (j = 0; j < height-1; j++)
- {
- for (i = 0; i < width-1; i++)
- {
- *(ii + (i<<1)) = *(oo + i);
- *(ii + (i<<1)+1) = (*(oo + i) + *(oo + i + 1) + 1- rounding_control)>>1;
- *(ii + (i<<1)+(width<<1)) = (*(oo + i) + *(oo + i + width) + 1-
- rounding_control)>>1;
- *(ii + (i<<1)+1+(width<<1)) = (*(oo+i) + *(oo+i+1) +
- *(oo+i+width) + *(oo+i+1+width) + 2-
- rounding_control)>>2;
- }
- *(ii+ (width<<1) - 2) = *(oo + width - 1);
- *(ii+ (width<<1) - 1) = *(oo + width - 1);
- *(ii+ (width<<1)+ (width<<1)-2) = (*(oo+width-1)+*(oo+width+width-1)+1-
- rounding_control)>>1;
- *(ii+ (width<<1)+ (width<<1)-1) = (*(oo+width-1)+*(oo+width+width-1)+1-
- rounding_control)>>1;
- ii += (width<<2);
- oo += width;
- }
- for (i = 0; i < width-1; i++)
- {
- *(ii+ (i<<1)) = *(oo + i);
- *(ii+ (i<<1)+1) = (*(oo + i) + *(oo + i + 1) + 1- rounding_control)>>1;
- *(ii+ (width<<1)+ (i<<1)) = *(oo + i);
- *(ii+ (width<<1)+ (i<<1)+1) = (*(oo + i) + *(oo + i + 1) + 1-
- rounding_control)>>1;
- }
- *(ii + (width<<1) - 2) = *(oo + width -1);
- *(ii + (width<<1) - 1) = *(oo + width -1);
- *(ii + (width<<2) - 2) = *(oo + width -1);
- *(ii + (width<<2) - 1) = *(oo + width -1);
- return;
- }
- Int
- GetMotionImages(
- Image *imv16_w,
- Image *imv16_h,
- Image *imv8_w,
- Image *imv8_h,
- Image *imode16,
- Image **mv_x,
- Image **mv_y,
- Image **mode
- )
- {
- Int i, j;
- Int width, height, base;
- Float val_x, val_y;
- Float *data_x, *data_y,
- *mv16_w, *mv16_h,
- *mv8_w, *mv8_h;
- SInt *mode16, *data_mode;
- SInt modo;
- width = imode16->x; height = imode16->y;
- (*mode)=AllocImage(width,height,SHORT_TYPE);
- (*mv_x)=AllocImage(width*2,height*2,FLOAT_TYPE);
- (*mv_y)=AllocImage(width*2,height*2,FLOAT_TYPE);
- data_x = (Float*)GetImageData((*mv_x));
- data_y = (Float*)GetImageData((*mv_y));
- data_mode = (SInt*)GetImageData((*mode));
- mode16=(SInt*)GetImageData(imode16);
- mv16_w=(Float*)GetImageData(imv16_w);
- mv16_h=(Float*)GetImageData(imv16_h);
- mv8_w=(Float*)GetImageData(imv8_w);
- mv8_h=(Float*)GetImageData(imv8_h);
- for(j=0;j<height;j++)
- {
- for(i=0;i< width;i++)
- {
- modo=data_mode[j*width+i]=mode16[j*width+i];
- if ( modo==MBM_INTRA)
- {
- base=2*j*2*width+2*i;
- data_x[base]=0.0; data_x[base+1]=0.0;
- data_y[base]=0.0; data_y[base+1]=0.0;
- base+=width*2;
- data_x[base]=0.0; data_x[base+1]=0.0;
- data_y[base]=0.0; data_y[base+1]=0.0;
- }
- else if(modo==MBM_INTER16)
- {
- base=2*j*2*width+2*i;
- val_x=mv16_w[base];val_y=mv16_h[base];
- data_x[base]=val_x; data_x[base+1]=val_x;
- data_y[base]=val_y; data_y[base+1]=val_y;
- base+=width*2;
- data_x[base]=val_x; data_x[base+1]=val_x;
- data_y[base]=val_y; data_y[base+1]=val_y;
- }
- else if (modo==MBM_INTER8)
- {
- base=2*j*2*width+2*i;
- data_x[base] = mv8_w[base];
- data_y[base] = mv8_h[base];
- data_x[base+1] = mv8_w[base+1];
- data_y[base+1] = mv8_h[base+1];
- base+=width*2;
- data_x[base] = mv8_w[base];
- data_y[base] = mv8_h[base];
- data_x[base+1] = mv8_w[base+1];
- data_y[base+1] = mv8_h[base+1];
- }
- }
- }
- return(1);
- }
- Int
- ChooseMode(
- SInt *curr,
- Int x_pos,
- Int y_pos,
- Int min_SAD,
- UInt width
- )
- {
- Int i, j;
- Int MB_mean = 0, A = 0;
- Int y_off;
- for (j = 0; j < MB_SIZE; j++)
- {
- y_off = (y_pos + j) * width;
- for (i = 0; i < MB_SIZE; i++)
- {
- MB_mean += *(curr + x_pos + i + y_off);
- }
- }
- MB_mean /= 256;
- for (j = 0; j < MB_SIZE; j++)
- {
- y_off = (y_pos + j) * width;
- for (i = 0; i < MB_SIZE; i++)
- {
- A += abs( *(curr + x_pos + i + y_off) - MB_mean );
- }
- }
- if (A < (min_SAD - 2*256))
- return 0;
- else
- return 1;
- }
- Int
- SAD_Macroblock(
- SInt *ii,
- SInt *act_block,
- UInt h_length,
- Int Min_FRAME
- )
- {
- int i, j;
- int sad = 0;
- SInt *p1 = ii, *p2 = act_block;
- i = 16;
- while (i--) {
- j = 16;
- while (j --)
- sad += abs((int)*(p1++) - (int)*(p2++));
- if (sad > Min_FRAME)
- return MV_MAX_ERROR;
- p1 += h_length - 16;
- }
- return sad;
- }
- Int
- SAD_Block(
- SInt *ii,
- SInt *act_block,
- UInt h_length,
- Int min_sofar
- )
- {
- int i, j;
- int sad = 0;
- SInt *p1 = ii, *p2 = act_block;
- i = 8;
- while (i--) {
- j = 8;
- while (j --)
- sad += abs((int)*(p1++) - (int)*(p2++));
- if (sad > min_sofar)
- return INT_MAX;
- p1 += h_length - 8;
- p2 += 16 - 8;
- }
- return sad;
- }
- Void
- LoadArea(
- SInt *im,
- Int x,
- Int y,
- Int x_size,
- Int y_size,
- Int lx,
- SInt *block
- )
- {
- SInt *in;
- SInt *out;
- Int i = x_size;
- Int j = y_size;
- in = im + (y*lx) + x;
- out = block;
- while (j--)
- {
- while (i--)
- *out++ = *in++;
- i = x_size;
- in += lx - x_size;
- }
- return;
- }
- Void
- SetArea(
- SInt *block,
- Int x,
- Int y,
- Int x_size,
- Int y_size,
- Int lx,
- SInt *im
- )
- {
- SInt *in;
- SInt *out;
- Int i = x_size;
- Int j = y_size;
- in = block;
- out = im + (y*lx) + x;
- while (j--)
- {
- while (i--)
- *out++ = *in++;
- i = x_size;
- out += lx - x_size;
- }
- }