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

📄 gif_interface.c

📁 ucOS 模拟环境
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "gif_read.h"
#include "gif_error.h"
#include "gif_gray.h"
#include "gif_dither.h"
#include "gif_dither2.h"
extern  Bool* zoomflag ;
extern  ulong*         g_ZoomType;
extern  uchar*              is_interlaced;
extern decompress_info_ptr cinfo;
extern UINT16* width, *height;
extern int *width_record;
extern int *height_record;
#ifdef PCVER
	extern FILE *FileError; 
#endif

static void gif_buffer_exchange (uchar* DestBuffer, int width, int height);


//====================================================================================
// Function Name:	Bool gof_index_to_map(decompress_info_ptr cinfo,uchar* ouput_buf)
// Purpose      : INDEX COLOR TO MAP COLOR	
// Parameter    :	
// Return       :	
// Remarks      :	
// Change Log   :	
//                Author       Date       Description	
//              -----------------------------------------------	
//=====================================================================================
Bool gif_index_to_map(decompress_info_ptr cinfo,uchar* ouput_buf)
{
	ulong i,j;
	uchar index;
	uchar* pointer,*pointer1;
	if(cinfo->output_height == 0 || cinfo->output_width ==0)
		return FALSE;
	index = ouput_buf[0];
	pointer = ouput_buf + (cinfo->image_height * cinfo->image_width-1)* NUMCOLORS;
	pointer1 = ouput_buf + (cinfo->image_height * cinfo->image_width-1) ;
	for(i = 0 ;i < cinfo->output_height ; i++)
	{
		for(j=0; j < cinfo->output_width;j++ )
		{
			if(cinfo->out_color_space == GIF_RGB)
			{
				*(pointer+2) = cinfo->colormap[0][*pointer1];
				*(pointer +1) = cinfo->colormap[1][*pointer1];
				*(pointer) = cinfo->colormap[2][*pointer1];
			}else
			{
#if GRAY_TANSFER == 0
				*(pointer+2) = cinfo->colormap[0][*pointer1];
				*(pointer +1) = cinfo->colormap[0][*pointer1];
				*(pointer) = cinfo->colormap[0][*pointer1];
#else
				*(pointer+2) = cinfo->colormap[0][*pointer1];
				*(pointer +1) = cinfo->colormap[1][*pointer1];
				*(pointer) = cinfo->colormap[2][*pointer1];
#endif
			}

			if( (i== cinfo->output_height -1) && (j== cinfo->output_width -2))
			{
				return TRUE;
			}
			pointer -= 3;
			pointer1--;

		}
	}

	//start output the rgb data
	//
	return TRUE;

}
//====================================================================================
// Function Name:	Bool  gif_get_colormap(decompress_info_ptr cinfo,uchar* palBuf)
// Purpose      : 	
// Parameter    :	
// Return       :	
// Remarks      :	
// Change Log   :	
//                Author       Date       Description	
//              -----------------------------------------------	
//=====================================================================================
Bool  gif_get_colormap(decompress_info_ptr cinfo,uchar* palBuf)
{
	uint j,index;
	if(cinfo->desired_number_of_colors <= 0)
		return FALSE;
	index = 0;
	if(cinfo->out_color_space == GIF_RGB)
	{
		for(j = 0; j< (uint)(cinfo->desired_number_of_colors); j++)
		{
			palBuf[index++] = cinfo->colormap[2][j];
			palBuf[index++] = cinfo->colormap[1][j];
			palBuf[index++] = cinfo->colormap[0][j];
			
		}
	}else
	{
		for(j = 0; j< (uint)(cinfo->desired_number_of_colors); j++)
		{
#if GRAY_TANSFER == 0
			palBuf[index++] = cinfo->colormap[0][j];
			palBuf[index++] = cinfo->colormap[0][j];
			palBuf[index++] = cinfo->colormap[0][j];
#else
			palBuf[index++] = cinfo->colormap[2][j];
			palBuf[index++] = cinfo->colormap[1][j];
			palBuf[index++] = cinfo->colormap[0][j];
#endif
		}
	}

	return TRUE;
}
//====================================================================================
// Function Name:	Bool  gif_get_colormap_gray(decompress_info_ptr cinfo,uchar* palBuf)
// Purpose      : 	
// Parameter    :	
// Return       :	
// Remarks      :	
// Change Log   :	
//                Author       Date       Description	
//              -----------------------------------------------	
//=====================================================================================
Bool  gif_get_colormap_gray(decompress_info_ptr cinfo,uchar* palBuf)
{
	uint j,index;
	index = 0;
	if(cinfo->colormap == NULL)
		return FALSE;
	for(j = 0; j< 256; j++)
	{
		palBuf[index++] = cinfo->colormap[2][j];
		palBuf[index++] = cinfo->colormap[1][j];
		palBuf[index++] = cinfo->colormap[0][j];
		
	}
	return TRUE;
}

//====================================================================================
// Function Name:	static void gif_SelectColors( GIFParameter* ucGifParameter)
// Purpose      : select color space	
// Parameter    :	
// Return       :	none
// Remarks      :	
// Change Log   :	
//                Author       Date       Description	
//              -----------------------------------------------	
//=====================================================================================
static void gif_SelectColors( GIFParameter* ucGifParameter)
{
	if( cinfo->quantize_colors)
	{
		switch(ucGifParameter->ucOutColorResolution)
		{
		case 1:
			cinfo->desired_number_of_colors = 8;
			break;
		case 4:
			cinfo->desired_number_of_colors = 16;
			break;
		case 8:
			cinfo->desired_number_of_colors = 256;
			break;
		case 24:
			cinfo->desired_number_of_colors = 0;
			break;
		default:
			cinfo->desired_number_of_colors = 0;
			break;

		}
	}else
	{
		if(!ucGifParameter->ucOutGrayscale)
		{
			cinfo->desired_number_of_colors = 0;
		}
		else
		{
			switch(ucGifParameter->ucOutColorResolution)
			{
			case 1:
				cinfo->desired_number_of_colors = 8;
				break;
			case 4:
				cinfo->desired_number_of_colors = 16;
				break;
			case 8:
				cinfo->desired_number_of_colors = 256;
				break;
			case 24:
				cinfo->desired_number_of_colors = 0;
				break;
			default:
				cinfo->desired_number_of_colors = 0;
				break;
			}
		}

	}

}

//====================================================================================
// Function Name:	void init_gif_color_space(GIFParameter* ucGifParameter)
// Purpose      : elect color space,select dither mode,create color map and create 
//                 color index	
// Parameter    :	
// Return       :	sucessful return true otherwise return false
// Remarks      :	
// Change Log   :	
//                Author       Date       Description	
//              -----------------------------------------------	
//=====================================================================================
Bool init_gif_color_space(GIFParameter* ucGifParameter)
{
 
	if(ucGifParameter->ucOutGrayscale)
	{

		if(!gif_select_gray(ucGifParameter))
			return FALSE;
		cinfo->out_color_space = GIF_GRAYSCALE;
#if GRAY_TANSFER == 0
		cinfo->out_color_components = 1;
#else
		cinfo->out_color_components = NUMCOLORS;
#endif

		
	}
	else
	{
		gif_SelectColors(ucGifParameter);//select color space
		cinfo->out_color_space = GIF_RGB;
		cinfo->out_color_components = NUMCOLORS;

	}

	cinfo->dither_mode = ucGifParameter->ucDitherMethod;//select dither mode
	cinfo->colormap = NULL;
	return TRUE;
	
}

//====================================================================================
// Function Name:	DecompressGIF(uchar *ucSourceBuf, GIFParameter *ucGifParameter)
// Purpose      : decompress a picture form source buffer	
// Parameter    :	
// Return       :	TRUE  - if successful.
// Remarks      :	
// Change Log   :	
//                Author       Date       Description	
//              -----------------------------------------------	
//=====================================================================================
Bool DecompressGIF(GIFParameter *ucGifParameter)
{
	int row;
	uchar* ptr;
	int c,cur_col;
	uint count;
	ulong ZoomSize;
    uchar tempbuf[NUMCOLORS * MAXPELWIDTH  ];          
#ifdef FLOAT_SURPORT
	float scale;
#endif
	ZoomSize = ucGifParameter->ucScale & 0xffff;
	if(ucGifParameter== NULL)
		return FALSE;
#ifdef PCVER
	openErrorFile();
#endif
	if(!InitWorkingBuf(ucGifParameter))
	{	
		return FALSE;
	}
	//decompress point initization 
	InitErrorStack();

	cinfo->enable_2pass_quant = TRUE;
	*zoomflag = FALSE;
	SetBufferCur(0);
	*g_ZoomType = IMAGE_GEOMETRY_INTERPOLATE;
    cinfo->quantize_colors = FALSE;
	/*
   * If image is interlaced, we read it into a full-size sample array,
   * decompressing as we go; then get_input_row selects rows from the
   * sample array in the proper order.

⌨️ 快捷键说明

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