Solid Fluid System Solutions  
Home Software About Hardware Firmware
Document Icon LibGIF
Document Icon LibGif Header
Document Icon LibGif Source
Current Document Icon ToGIF / FromGIF Common
Document Icon ToGIF
Document Icon FromGIF

Declarations common to the ToGIF and FromGIF Functions

#include "ImgGIF.h"
#include "ImgAlloc.h"
#include ".\GIF\Gif.h"

#define TABLE_8BIT	0
#define TABLE_4BIT	1
#define TABLE_2BIT	2
#define TABLE_1BIT	3

unsigned char MaskTable[4][8] = 
{
	{0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
	{0xF0,0x0F,0x00,0x00,0x00,0x00,0x00,0x00},
	{0xC0,0x30,0x0C,0x03,0x00,0x00,0x00,0x00},
	{0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}
};

unsigned char ShiftTable[4][8] = 
{
	{0,0,0,0,0,0,0,0},
	{4,0,0,0,0,0,0,0},
	{6,4,2,0,0,0,0,0},
	{7,6,5,4,3,2,1,0}
};

unsigned long AddressMaskTable[4] =
{
	0,1,3,7
};

unsigned char AddressShiftTable[4] =
{
	0,1,2,3
};

unsigned long PaletteSize[4] = 
{
	256,16,4,2
};

char PixelDivisor[4] = 
{
	1,2,4,8
};

char BitCount[4] = 
{
	8,4,2,1
};

bool GetTrns(Gif* pGif,unsigned long Block,unsigned char& TrnsIdx)
{
	bool RetVal = false;

	if(Block > 0)
	{
		if(pGif->blocks[Block-1]->ext != NULL)
		{
			GifExtension* pExt = pGif->blocks[Block-1]->ext;
			
			if((pExt->marker == 0xF9) && (pExt->data_count == 1))
			{
				GifData* pData = pExt->data[0];

				if(pData->byte_count == 4)
				{
					if((pData->bytes[0] & 0x01) != 0)
					{
						TrnsIdx = pData->bytes[3];
						RetVal = true;
					}
				}
			}
		}
	}

	return RetVal;
}

bool SelectPicture(Gif* pGif,GifPicture*& pGP,GifPalette*& pGL,bool& Trns,unsigned char& TrnsIdx)
{
	Trns = false;

	pGP = NULL;
	pGL = NULL;

	unsigned long i,Count;
	Count = pGif->block_count;
	for(i=0;i<Count;i++)
	{
		if(pGif->blocks[i]->pic != NULL)
		{
			if(pGif->blocks[i]->pic->has_cmap != 0)
			{
				pGP = pGif->blocks[i]->pic;
				pGL = pGif->blocks[i]->pic->cmap;

				Trns = GetTrns(pGif,i,TrnsIdx);

				i = Count;
			}
		}
	}

	if(pGP == NULL)
	{
		if(pGif->screen->has_cmap != 0)
		{
			pGL = pGif->screen->cmap;

			for(i=0;i<Count;i++)
			{
				if(pGif->blocks[i]->pic != NULL)
				{
					pGP = pGif->blocks[i]->pic;

					Trns = GetTrns(pGif,i,TrnsIdx);

					i = Count;
				}
			}
		}
	}

	return ((pGP != NULL) && (pGL != NULL));
}
Copyright © Solid Fluid 2007-2015
Last modified: SolFlu  Sun, 14 Jun 2009 10:01:53 GMT