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

📄 gif_read.c

📁 ucOS 模拟环境
💻 C
字号:
//----------------------------------------------------------------------
// File Name :		gifread.c
// Project   :		gsm_gprs		
// Module    :
// Memo      :
//                Author       Date       Description
//              -----------------------------------------------
//				  dts			  2004.3.10
//               
//----------------------------------------------------------------------

#include "gif_read.h"
#include "typedef.h"
#include "gif_error.h"

extern decompress_info_ptr cinfo;
extern int* input_code_size;	/* codesize given in GIF file */
extern  int* clear_code,*end_code; /* values for Clear and End codes */
#ifdef PCVER
	extern FILE *FileError; 
#endif

extern char dd;
//====================================================================================
// Function Name:	int ReadByte ()
// Purpose      :	read a data from data buffer
// Parameter    :	
// Return       :	return data		
// Remarks      :	Read next byte from GIF data
// Change Log   :	
//                Author       Date       Description	
//              -----------------------------------------------	
//=====================================================================================

extern  unsigned long GetCurrDataPointer(void);
extern  Bool SeekCurrDataPointer(unsigned long ulPointer);
extern  unsigned long ReadData(unsigned char *ucDataBuf, unsigned long ulDataLen);

ulong GetDataBufferCur(void)
{
	return GetCurrDataPointer();
}

Bool SetBufferCur(ulong ulPointer)
{
	return SeekCurrDataPointer(ulPointer);
}

int ReadByte ()
{
	int c;
	uchar buffer[2];
	if(ReadData(buffer,1) != 1)
	{
	#ifdef PCVER
		WriteToErrorFile("ReadByte",ERROR_READ_BYTE_ERROR,FileError);
	#endif
		InsertError(ERROR_READ_BYTE_ERROR);
		return EOF;
	}else
	{
		c = buffer[0];
	}
	return c;
}
//====================================================================================
// Function Name:	Bool readFromBuffer(int len, uchar* DestBuffer)
// Purpose      :	read a block of data form buffer
// Parameter    :	
// Return       :	return data		
// Remarks      :	
// Change Log   :	
//                Author       Date       Description	
//              -----------------------------------------------	
//=====================================================================================
Bool readFromBuffer(int len, uchar* DestBuffer)
{
	int count = 0;
	if(ReadData(DestBuffer,len) != len)
	{
	#ifdef PCVER
		WriteToErrorFile("readFromBuffer",ERROR_READ_BYTE_ERROR,FileError);
	#endif
		InsertError(ERROR_READ_BYTE_ERROR);
		return FALSE;
	}else
	{
		return TRUE;
	}
	dd = 0;
   
}
//====================================================================================
// Function Name:	int GetDataBlock (char *buf)
// Purpose      :	Read a GIF data block, which has a leading count byte
//                A zero-length block marks the end of a data block sequence
// Parameter    :	
// Return       :	return data		
// Remarks      :	
// Change Log   :	
//                Author       Date       Description	
//              -----------------------------------------------	
//=====================================================================================
int GetDataBlock (char *buf)
{
   int count;

   count = ReadByte();
   if (count > 0) 
   {
      if (!readFromBuffer(count,buf))
	   {
         #ifdef PCVER
		      WriteToErrorFile("GetDataBlock",ERROR_NOT_GIF_FILE ,FileError);
         #endif
		   InsertError(ERROR_NOT_GIF_FILE	);
		   return FALSE;
	   }
   }
   else
   {
	  return FALSE;
   }
   return count;
}

//====================================================================================
// Function Name:	Bool skipFrame()
// Purpose      :	
// Parameter    :	
// Return       :		
// Remarks      :	
// Change Log   :	
//                Author       Date       Description	
//              -----------------------------------------------	
//=====================================================================================
Bool skipFrame()
{
   char hdrbuf[10];		/* workspace for reading control blocks */
	int colormaplen;
	if (! readFromBuffer(9, hdrbuf))
	{
      #ifdef PCVER
		   WriteToErrorFile("GetDataBlock",ERROR_NOT_GIF_FILE ,FileError);
      #endif
		InsertError(ERROR_NOT_GIF_FILE	);
	}

	if (BitSet(hdrbuf[8], COLORMAPFLAG)) 
	{
		colormaplen = 2 << (hdrbuf[8] & 0x07);
		if(!SetBufferCur(GetDataBufferCur() + colormaplen*3))
			return FALSE;

	}
   /* we ignore top/left position info, also sort flag */
   /* Read local colormap if header indicates it is present */
   /* Note: if we wanted to support skipping images, */
   /* we'd need to skip rather than read colormap for ignored images */
   *input_code_size = ReadByte(); 
	*clear_code = 1 << *input_code_size; /* compute special code values */
	*end_code = *clear_code + 1;	/* note that these do not change */
   if (*input_code_size < 2 || *input_code_size >= MAX_LZW_BITS)
   {
		InsertError( ERROR_BOGUS_CODE_SIZE );
		return FALSE;
	}
	SkipDataBlocks ();
	
	return TRUE;
}
//====================================================================================
// Function Name:	void SkipDataBlocks ()
// Purpose      :	Skip a series of data blocks, until a block terminator is found
// Parameter    :	
// Return       :		
// Remarks      :	
// Change Log   :	
//                Author       Date       Description	
//              -----------------------------------------------	
//=====================================================================================
void SkipDataBlocks ()
{
	char buf[256];
	while (GetDataBlock(buf) > 0)
   {
      ;
   }
}




⌨️ 快捷键说明

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