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

📄 io.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 "globals.h"

/*PUBLIC*/

extern void MakeIob_en();
extern void GlobalMC_en();
extern void SubOverlay_en();
extern void AddOverlay_en();
extern void SubCompensate_en();
extern void AddCompensate_en();
extern void HalfSubCompensate_en();
extern void HalfAddCompensate_en();
extern void LoadFilterMatrix_en();
extern void SubFCompensate_en();
extern void AddFCompensate_en();
extern void HalfSubFCompensate_en();
extern void HalfAddFCompensate_en();
//extern void ClearIob();
//extern void CopyIob2FS();
extern void ClearFS_en();
//extern int ParityFS();
extern void InitFS_en();
extern void ReadIob_en();
extern void InstallIob_en();
extern void InstallFS_en();
//extern void WriteIob();
extern void MoveTo_en();
extern int Bpos_en();
extern void ReadBlock_en();
extern void WriteBlock_en();
//extern void PrintIob();

/*PRIVATE*/

extern IMAGE *CImage;
extern FRAME *CFrame;
extern FSTORE *CFS;

extern int MVDH;
extern int MVDV;

extern int Loud;
extern int ImageType;

IOBUF *Iob=NULL;
int BlockWidth = BLOCKWIDTH;
int BlockHeight = BLOCKHEIGHT;

/*START*/

/*BFUNC

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

EFUNC*/

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

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

/*BFUNC

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

EFUNC*/

void GlobalMC_en()
{
  BEGIN("GlobalMC_en");
  BruteMotionEstimation_en(Iob->mem,CFrame->Iob[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 = (Iob->vpos * Iob->width * BlockHeight) + (Iob->hpos * BlockWidth)
    + Iob->mem->data;
  for(i=0;i<BlockHeight;i++)
    {
      for(j=0;j<BlockWidth;j++)
	{
	  *(matrix) =  *(matrix) - *memloc;
	  matrix++;
	  memloc++;
	}
      memloc = memloc-BlockWidth+Iob->width;
    }
}

/*BFUNC

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

EFUNC*/

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

  memloc = (Iob->vpos * Iob->width * BlockHeight) + (Iob->hpos * BlockWidth)
    + Iob->mem->data;

  for(i=0;i<BlockHeight;i++)
    {
      for(j=0;j<BlockWidth;j++)
	{
	  *(matrix) =  *(matrix) + *memloc;
	  matrix++;
	  memloc++;
	}
      memloc = memloc - BlockWidth + Iob->width;
    }
}

/*BFUNC

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

EFUNC*/

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

  memloc = (((Iob->vpos *  BlockHeight) + MVDV)*Iob->width)
    + (Iob->hpos * BlockWidth) + MVDH
      + Iob->mem->data;
  for(i=0;i<BlockHeight;i++)
    {
      for(j=0;j<BlockWidth;j++)
	{
	  *(matrix) =  *(matrix) - *memloc;
	  matrix++;
	  memloc++;
	}
      memloc = memloc - BlockWidth + Iob->width;
    }
}

/*BFUNC

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

EFUNC*/

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

  memloc = (((Iob->vpos *  BlockHeight) + MVDV)*Iob->width)
    + (Iob->hpos * BlockWidth) + MVDH
      + Iob->mem->data;

  for(i=0;i<BlockHeight;i++)
    {
      for(j=0;j<BlockWidth;j++)
	{
	  *(matrix) =  *(matrix) + *memloc;
	  matrix++;
	  memloc++;
	}
      memloc = memloc - BlockWidth + Iob->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 = (((Iob->vpos *  BlockHeight) + (MVDV/2))*Iob->width)
    + (Iob->hpos * BlockWidth) + (MVDH/2)
      + Iob->mem->data;

  for(i=0;i<BlockHeight;i++)
    {
      for(j=0;j<BlockWidth;j++)
	{
	  *(matrix) =  *(matrix) - *memloc;
	  matrix++;
	  memloc++;
	}
      memloc = memloc - BlockWidth + Iob->width;
    }
}

/*BFUNC

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

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

  memloc = (((Iob->vpos *  BlockHeight) + (MVDV/2))*Iob->width)
    + (Iob->hpos * BlockWidth) + (MVDH/2)
      + Iob->mem->data;

  for(i=0;i<BlockHeight;i++)
    {
      for(j=0;j<BlockWidth;j++)
	{
	  *(matrix) =  *(matrix) + *memloc;
	  matrix++;
	  memloc++;
	}
      memloc = memloc - BlockWidth + Iob->width;
    }
}

/*BFUNC

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

EFUNC*/

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

  for(ptr=temp,i=0;i<BlockHeight;i++)
    {
      *(ptr++)=(*(memloc)<<2);
      for(j=1;j<BlockWidth-1;j++,ptr++)
	{
	  *(ptr) =  *(memloc++);
	  *(ptr) +=  (*(memloc++) << 1);
	  *(ptr) +=  *(memloc--);
	}
      memloc++;
      *(ptr++) = (*(memloc++)<<2);
      memloc = memloc-BlockWidth+Iob->width;
    }
  for(ptr=output,ptr1=temp,ptr2=temp,ptr3=temp+(BlockWidth<<1),i=0;
      i<BlockHeight;i++)
    {
      if ((i==0)||(i==7))
	{
	  for(j=0;j<BlockWidth;j++) {*(ptr++) = *(ptr2++);}
	}
      else
	{
	  for(j=0;j<BlockWidth;j++)
	    {
	      *(ptr) = (*(ptr2++)<<1);
	      *(ptr) +=  *(ptr1++);
	      *(ptr) +=  *(ptr3++);
	      *ptr = (*ptr>>2);
	      ptr++;
	    }
	}
    }
  for(ptr=output,i=0;i<BlockHeight;i++)
    {
      for(j=0;j<BlockWidth;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 = (((Iob->vpos *  BlockHeight) + MVDV)*Iob->width)
    + (Iob->hpos * BlockWidth) + MVDH
      + Iob->mem->data;
  LoadFilterMatrix_en(memloc,temp);
  for(ptr=temp,i=0;i<BlockHeight;i++)
    {
      for(j=0;j<BlockWidth;j++)
	{
	  *(matrix) =  *(matrix) - *(ptr++);
	  matrix++;
	}
    }
}


/*BFUNC

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

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

  memloc = (((Iob->vpos *  BlockHeight) + MVDV)*Iob->width)
    + (Iob->hpos * BlockWidth) + MVDH
      + Iob->mem->data;
  LoadFilterMatrix_en(memloc,temp);
  for(ptr=temp,i=0;i<BlockHeight;i++)
    {
      for(j=0;j<BlockWidth;j++)
	{
	  *(matrix) =  *(matrix) + *(ptr++);
	  matrix++;
	}
    }
}

⌨️ 快捷键说明

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