⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 io2.c

📁 h261协议的h261编码码,lib_261.h里面提供了详细的接口和说明.
💻 C
📖 第 1 页 / 共 2 页
字号:
/*************************************************************
Copyright (C) 1990, 1991, 1993 Andy C. Hung, all rights reserved.
PUBLIC DOMAIN LICENSE: Stanford University Portable Video Research
Group. If you use this software, you agree to the following: This
program package is purely experimental, and is licensed "as is".
Permission is granted to use, modify, and distribute this program
without charge for any purpose, provided this license/ disclaimer
notice appears in the copies.  No warranty or maintenance is given,
either expressed or implied.  In no event shall the author(s) be
liable to you or a third party for any special, incidental,
consequential, or other damages, arising out of the use or inability
to use the program for any purpose (or the loss of data), even if we
have been advised of such possibilities.  Any public reference or
advertisement of this source code should refer to it as the Portable
Video Research Group (PVRG) code, and not by any author(s) (or
Stanford University) name.
*************************************************************/
/*
************************************************************
io.c

************************************************************
*/

/*LABEL io.c */

#include <stdio.h>
#include <memory.h>
#include <stdlib.h>
#include "globals2.h"

/*PUBLIC*/

extern void MakeIob2();
//extern void GlobalMC_en();
//extern void SubOverlay_en();
extern void AddOverlay2();
//extern void SubCompensate_en();
extern void AddCompensate2();
//extern void HalfSubCompensate_en();
extern void HalfAddCompensate2();
extern void LoadFilterMatrix2();
//extern void SubFCompensate_en();
extern void AddFCompensate2();
//extern void HalfSubFCompensate_en();
extern void HalfAddFCompensate2();
//extern void ClearIob();
extern void CopyIob2FS2();
extern void ClearFS2();
//extern int ParityFS();
extern void InitFS2();
//extern void ReadIob_en();
extern void InstallIob2();
extern void InstallFS2();
extern void WriteIob2();
extern void MoveTo2();
//extern int Bpos_en();
//extern void ReadBlock_en();
extern void WriteBlock2();
//extern void PrintIob();

/*PRIVATE*/

extern IMAGE *CImage2;
extern FRAME *CFrame2;
extern FSTORE *CFS2;

extern int MVDH2;
extern int MVDV2;

extern int Loud2;
extern int ImageType2;

IOBUF *Iob2=NULL;
int BlockWidth2 = BLOCKWIDTH;
int BlockH2eight2 = BLOCKHEIGHT;

/*START*/

/*BFUNC

MakeIob2() constructs an IO structure and assorted book-keeping
instructions for all components of the frame.

EFUNC*/

void MakeIob2(int flag)
{
  BEGIN("MakeIob2");
  int i;

  for(i=0;i<CFrame2->NumberComponents;i++)
    {
		if (!(CFrame2->Iob2[i]=MakeStructure(IOBUF)))
		{
			WHEREAMI();
			printf("Cannot make IO structure\n");
			exit(ERROR_MEMORY);
		}
		CFrame2->Iob2[i]->flag = flag;
		CFrame2->Iob2[i]->hpos = 0;
		CFrame2->Iob2[i]->vpos = 0;
		CFrame2->Iob2[i]->hor = CFrame2->hf[i];
		CFrame2->Iob2[i]->ver = CFrame2->vf[i];
		CFrame2->Iob2[i]->width = CFrame2->Width[i];
		CFrame2->Iob2[i]->height = CFrame2->Height[i];
		CFrame2->Iob2[i]->mem = MakeMem2(CFrame2->Width[i],CFrame2->Height[i]);
	}
}

/*BFUNC

GlobalMC_en() does the motion estimation for the entire buffer.

EFUNC*/

//void GlobalMC_en()
//{
//  BEGIN("GlobalMC_en");
//  BruteMotionEstimation_en(Iob2->mem,CFrame2->Iob2[0]->mem);
//}

/*BFUNC

SubOverlay_en() does a subtractive mask of the current matrix with a
corresponding portion of the memory in the IO buffer.

EFUNC*/

//void SubOverlay_en(matrix)
//     int *matrix;
//void SubOverlay_en(int *matrix)
//{
//  BEGIN("SubOverlay_en");
//  int i,j;
//  unsigned char *memloc;
//
//  memloc = (Iob2->vpos * Iob2->width * BlockH2eight2) + (Iob2->hpos * BlockWidth2)
//    + Iob2->mem->data;
//  for(i=0;i<BlockH2eight2;i++)
//    {
//      for(j=0;j<BlockWidth2;j++)
//	{
//	  *(matrix) =  *(matrix) - *memloc;
//	  matrix++;
//	  memloc++;
//	}
//      memloc = memloc-BlockWidth2+Iob2->width;
//    }
//}

/*BFUNC

AddOverlay2() adds the corresponding portion of the top-level IO
structure to the matrix.

EFUNC*/

//void AddOverlay2(matrix)
//     int *matrix;
void AddOverlay2(int *matrix)
{
  BEGIN("AddOverlay2");
  int i,j;
  unsigned char *memloc;

  memloc = (Iob2->vpos * Iob2->width * BlockH2eight2) + (Iob2->hpos * BlockWidth2)
    + Iob2->mem->data;

  for(i=0;i<BlockH2eight2;i++)
    {
      for(j=0;j<BlockWidth2;j++)
	{
	  *(matrix) =  *(matrix) + *memloc;
	  matrix++;
	  memloc++;
	}
      memloc = memloc - BlockWidth2 + Iob2->width;
    }
}

/*BFUNC

SubCompensate_en() does a subtractive motion compensation of the input
matrix based on the locations given by the global variables of MVDH2
and MVDV2.

EFUNC*/

//void SubCompensate_en(matrix)
//     int *matrix;
//void SubCompensate_en(int *matrix)
//{
//  BEGIN("SubCompensate_en");
//  int i,j;
//  unsigned char *memloc;
//
//  memloc = (((Iob2->vpos *  BlockH2eight2) + MVDV2)*Iob2->width)
//    + (Iob2->hpos * BlockWidth2) + MVDH2
//      + Iob2->mem->data;
//  for(i=0;i<BlockH2eight2;i++)
//    {
//      for(j=0;j<BlockWidth2;j++)
//	{
//	  *(matrix) =  *(matrix) - *memloc;
//	  matrix++;
//	  memloc++;
//	}
//      memloc = memloc - BlockWidth2 + Iob2->width;
//    }
//}

/*BFUNC

AddCompensate2() does an additive motion compensation of the input
matrix from the installed IO structure based on the locations given by
the global variables of MVDH2 and MVDV2.

EFUNC*/

//void AddCompensate2(matrix)
//     int *matrix;
void AddCompensate2(int *matrix)
{
  BEGIN("AddCompensate2");
  int i,j;
  unsigned char *memloc;

  memloc = (((Iob2->vpos *  BlockH2eight2) + MVDV2)*Iob2->width)
    + (Iob2->hpos * BlockWidth2) + MVDH2
      + Iob2->mem->data;

  for(i=0;i<BlockH2eight2;i++)
    {
      for(j=0;j<BlockWidth2;j++)
	{
	  *(matrix) =  *(matrix) + *memloc;
	  matrix++;
	  memloc++;
	}
      memloc = memloc - BlockWidth2 + Iob2->width;
    }
}

/*BFUNC

HalfSubCompensate_en() does a motion compensated subtraction from the
input matrix from the installed IO structure, but divides the
compensation variable in half.

EFUNC*/

//void HalfSubCompensate_en(matrix)
//     int *matrix;
//void HalfSubCompensate_en(int *matrix)
//{
//  BEGIN("HalfSubCompensate_en");
//  int i,j;
//  unsigned char *memloc;
//
//  memloc = (((Iob2->vpos *  BlockH2eight2) + (MVDV2/2))*Iob2->width)
//    + (Iob2->hpos * BlockWidth2) + (MVDH2/2)
//      + Iob2->mem->data;
//
//  for(i=0;i<BlockH2eight2;i++)
//    {
//      for(j=0;j<BlockWidth2;j++)
//	{
//	  *(matrix) =  *(matrix) - *memloc;
//	  matrix++;
//	  memloc++;
//	}
//      memloc = memloc - BlockWidth2 + Iob2->width;
//    }
//}
//
/*BFUNC

HalfAddCompensate2() does a motion compensated addition to the input
matrix from the installed IO structure. It divides the MVDV2 and MVDH2
global input varaible vector in half.

EFUNC*/
//
//void HalfAddCompensate2(matrix)
//     int *matrix;
void HalfAddCompensate2(int *matrix)
{
  BEGIN("HalfAddCompensate2");
  int i,j;
  unsigned char *memloc;

  memloc = (((Iob2->vpos *  BlockH2eight2) + (MVDV2/2))*Iob2->width)
    + (Iob2->hpos * BlockWidth2) + (MVDH2/2)
      + Iob2->mem->data;

  for(i=0;i<BlockH2eight2;i++)
    {
      for(j=0;j<BlockWidth2;j++)
	{
	  *(matrix) =  *(matrix) + *memloc;
	  matrix++;
	  memloc++;
	}
      memloc = memloc - BlockWidth2 + Iob2->width;
    }
}

/*BFUNC

LoadFilterMatrix2() loads a p64 filtered portion of memory into a
matrix. The correct Iob2 must be installed before this function is
called.

EFUNC*/

//void LoadFilterMatrix2(memloc,output2)
//     unsigned char *memloc;
//     int *output2;
void LoadFilterMatrix2(unsigned char *memloc,int *output2)
{
  BEGIN("LoadFilterMatrix2");
  int i,j;
  int temp[64];
  int *ptr,*ptr1,*ptr2,*ptr3;

  for(ptr=temp,i=0;i<BlockH2eight2;i++)
    {
      *(ptr++)=(*(memloc)<<2);
      for(j=1;j<BlockWidth2-1;j++,ptr++)
	{
	  *(ptr) =  *(memloc++);
	  *(ptr) +=  (*(memloc++) << 1);
	  *(ptr) +=  *(memloc--);
	}
      memloc++;
      *(ptr++) = (*(memloc++)<<2);
      memloc = memloc-BlockWidth2+Iob2->width;
    }
  for(ptr=output2,ptr1=temp,ptr2=temp,ptr3=temp+(BlockWidth2<<1),i=0;
      i<BlockH2eight2;i++)
    {
      if ((i==0)||(i==7))
	{
	  for(j=0;j<BlockWidth2;j++) {*(ptr++) = *(ptr2++);}
	}
      else
	{
	  for(j=0;j<BlockWidth2;j++)
	    {
	      *(ptr) = (*(ptr2++)<<1);
	      *(ptr) +=  *(ptr1++);
	      *(ptr) +=  *(ptr3++);
	      *ptr = (*ptr>>2);
	      ptr++;
	    }
	}
    }
  for(ptr=output2,i=0;i<BlockH2eight2;i++)
    {
      for(j=0;j<BlockWidth2;j++,ptr++)
	{
	  if (*ptr & 2) {*ptr=(*ptr>>2)+1;}
	  else {*ptr=(*ptr>>2);}
	}
    }
}

/*BFUNC

SubFCompensate_en() does a subtractive motion compensation on a filtered
version of the input block.

EFUNC*/

//void SubFCompensate_en(matrix)
//     int *matrix;
//void SubFCompensate_en(int *matrix)
//{
//  BEGIN("SubFCompensate_en");
//  int i,j;
//  unsigned char *memloc;
//  int temp[64];
//  int *ptr;
//
//  memloc = (((Iob2->vpos *  BlockH2eight2) + MVDV2)*Iob2->width)
//    + (Iob2->hpos * BlockWidth2) + MVDH2
//      + Iob2->mem->data;
//  LoadFilterMatrix2(memloc,temp);
//  for(ptr=temp,i=0;i<BlockH2eight2;i++)
//    {
//      for(j=0;j<BlockWidth2;j++)
//	{
//	  *(matrix) =  *(matrix) - *(ptr++);
//	  matrix++;
//	}
//    }
//}
//

/*BFUNC

AddFCompensate2() does a additive motion compensation on a filtered
version of the input block.

EFUNC*/
//
//void AddFCompensate2(matrix)
//     int *matrix;
void AddFCompensate2(int *matrix)
{
  BEGIN("AddFCompensate2");
  int i,j;
  unsigned char *memloc;
  int temp[64];
  int *ptr;

  memloc = (((Iob2->vpos *  BlockH2eight2) + MVDV2)*Iob2->width)
    + (Iob2->hpos * BlockWidth2) + MVDH2
      + Iob2->mem->data;
  LoadFilterMatrix2(memloc,temp);
  for(ptr=temp,i=0;i<BlockH2eight2;i++)
    {
      for(j=0;j<BlockWidth2;j++)
	{
	  *(matrix) =  *(matrix) + *(ptr++);
	  matrix++;
	}
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -