Ejemplo n.º 1
0
int load_huff_tables()
{
	char aux;
	int size, hclass, id, max;
	int LeavesN, LeavesT, i;
	int AuxCode;

	size = get_size();	/* this is the tables' size */

	size -= 2;   //120 007A

	while (size > 0) {

		aux =FGETC();
		hclass = first_quad(aux);	/* AC or DC */
		id = second_quad(aux);	/* table no */
		if (id > 1) {
			//fprintf(stderr, "\tERROR:\tBad HTable identity %d!\n", id);
			return -1;
		}
		id = HUFF_ID(hclass, id);
		if (verbose);
			//fprintf(stderr, "\tINFO:\tLoading Table %d\n", id);
		size--;

		LeavesT = 0;
		AuxCode = 0;

		for (i = 0; i < 16; i++) {
			LeavesN = FGETC();

			ValPtr[id][i] = LeavesT;
			MinCode[id][i] = AuxCode * 2;
			AuxCode = MinCode[id][i] + LeavesN;

			MaxCode[id][i] = (LeavesN) ? (AuxCode - 1) : (-1);
			LeavesT += LeavesN;
		}
		size -= 16;

		if (LeavesT > MAX_SIZE(hclass)) {
			max = MAX_SIZE(hclass);
			//fprintf(stderr, "\tWARNING:\tTruncating Table by %d symbols\n", LeavesT - max);
		} else
			max = LeavesT;

		for (i = 0; i < max; i++)
			HTable[id][i] = FGETC();	/* load in raw order */

		for (i = max; i < LeavesT; i++)
			//fgetc(fi);	/* skip if we don't load */
			FGETC();
		size -= LeavesT;

		if (verbose);
			//fprintf(stderr, "\tINFO:\tUsing %d words of table memory\n", LeavesT);

	}			/* loop on tables */
	return 0;
}
Ejemplo n.º 2
0
int load_huff_tables()
{
	char aux;
	int size, hclass, id, max;
	int LeavesN, LeavesT, i;
	int AuxCode;

	size = get_size();	/* this is the tables' size */

	size -= 2;   //120 007A

	while (size > 0) {

		aux =FGETC();
		hclass = first_quad(aux);	/* AC or DC */
		id = second_quad(aux);	/* table no */
		if (id > 1) {
			//fprintf(stderr, "\tERROR:\tBad HTable identity %d!\n", id);
			return -1;
		}
		id = HUFF_ID(hclass, id);
		size--;

		LeavesT = 0;
		AuxCode = 0;

		for (i = 0; i < 16; i++) {
			LeavesN = FGETC();

			ValPtr[id][i] = LeavesT;
			MinCode[id][i] = AuxCode * 2;
			AuxCode = MinCode[id][i] + LeavesN;

			MaxCode[id][i] = (LeavesN) ? (AuxCode - 1) : (-1);
			LeavesT += LeavesN;
		}
		size -= 16;

		if (LeavesT > MAX_SIZE(hclass)) {
			max = MAX_SIZE(hclass);
		} else
			max = LeavesT;

		for (i = 0; i < max; i++)
			HTable[id][i] = FGETC();	/* load in raw order */

		for (i = max; i < LeavesT; i++)
			FGETC();
		size -= LeavesT;

	}			/* loop on tables */
	return 0;
}
Ejemplo n.º 3
0
unsigned char get_symbol(int select) {
  long code = 0;
  int length;
  int index;

  for (length = 0; length < 16; length++) {
    code = (2 * code) | get_one_bit();
    if (code <= MaxCode[select][length]) { break; }
  }
  index = ValPtr[select][length] + code - MinCode[select][length];

  if (index < MAX_SIZE(select / 2)) { return HTable[select][index]; }
  ERR("%ld:\tWARNING:\tOverflowing symbol table !\n", FTELL());
  return 0;
}
Ejemplo n.º 4
0
unsigned char get_symbol( int select)
{
	long code = 0;
	int length;
	int index;

	for (length = 0; length < 16; length++) {
		code = (2 * code) | get_one_bit();
		if (code <= MaxCode[select][length])
			break;
	}

	index = ValPtr[select][length] + code - MinCode[select][length];

	if (index < MAX_SIZE(select / 2))
		return HTable[select][index];

	//fprintf(stderr, "%ld:\tWARNING:\tOverflowing symbol table !\n", ftell(fi));
	return 0;
}
Ejemplo n.º 5
0
/*-----------------------------------------*/

#include "jpeg.h"

/*--------------------------------------*/
/* private huffman.c defines and macros */
/*--------------------------------------*/

/* Memory size of HTables; */
#define MAX_SIZE(hclass)		((hclass)?162:14)

/*--------------------------------------*/
/* some static structures for storage */
/*--------------------------------------*/

static unsigned char DC_Table0[MAX_SIZE(DC_CLASS)], DC_Table1[MAX_SIZE(DC_CLASS)];

static unsigned char AC_Table0[MAX_SIZE(AC_CLASS)], AC_Table1[MAX_SIZE(AC_CLASS)];

static unsigned char *HTable[4] = {
	&DC_Table0[0], &DC_Table1[0],
	&AC_Table0[0], &AC_Table1[0]
};

static int MinCode[4][16];
static int MaxCode[4][16];
static int ValPtr[4][16];

/*----------------------------------------------------------*/
/* Loading of Huffman table, with leaves drop ability	    */
/*----------------------------------------------------------*/
Ejemplo n.º 6
0
// Very simple menu with a heading and a scrolling banner as a footer
char plat_Menu(char **menuItems, char height, char *scroller)
{
	static char *prevScroller, *pScroller, *pEnd;
	int keyMask;
	char i, j, sx, sy, numMenuItems, timerInit = 0, maxLen = 0;

	// If the scroller message chages, cache the new one
	if(prevScroller != scroller)
	{
		prevScroller = scroller;
		pScroller = scroller;
		pEnd = scroller + strlen(scroller);
	}

	// Find the longest entry
	for(numMenuItems=0; menuItems[numMenuItems]; ++numMenuItems)
	{
		char len = strlen(menuItems[numMenuItems]);
		if(len > maxLen)
			maxLen = len;
	}
	
	// Centre on the screen
	sy = MAX_SIZE(0, (SCREEN_HEIGHT / 2) - (height / 2) - 1);
	sx = MAX_SIZE(0, (SCREEN_WIDTH / 2) - (maxLen / 2) - 1);
	maxLen = MIN_SIZE(SCREEN_WIDTH-2, maxLen);

	// Show the title
	textcolor(COLOR_GREEN);
	gotoxy(sx, sy);
	cprintf(" %.*s ",maxLen, menuItems[0]);
	
	// Leave a blank line
	textcolor(COLOR_BLACK);
	gotoxy(sx, ++sy);
	for(j=0; j<maxLen+2; ++j)
		cputc(' ');
	
	// Show all the menu items
	for(i=1; i<numMenuItems; ++i)
	{
		gotoxy(sx, sy+i);
		cprintf(" %.*s ",maxLen, menuItems[i]);
	}
	
	// Pad with blank lines to menu height
	for(;i<height;++i)
	{
		gotoxy(sx, sy+i);
		for(j=0; j<maxLen+2; ++j)
			cputc(' ');
	}

	// Select the first item
	i = 1;
	do
	{
		// Highlight the selected item
		gotoxy(sx, sy+i);
		textcolor(COLOR_WHITE);
		cprintf(">%.*s<",maxLen, menuItems[i]);
		textcolor(COLOR_BLACK);
		
		// Look for user input
		keyMask = plat_ReadKeys(0);
		
		if(keyMask & INPUT_MOTION)
		{
			// selection changes so de-highlight the selected item
			gotoxy(sx, sy+i);
			cprintf(" %.*s ",maxLen, menuItems[i]);
			
			// see if the selection goes up or down
			switch(keyMask & INPUT_MOTION)
			{
				case INPUT_UP:
					if(!--i)
						i = numMenuItems-1;
				break;
			
				case INPUT_DOWN:
					if(numMenuItems == ++i)
						i = 1;
				break;
			}
		}
		keyMask &= (INPUT_SELECT | INPUT_BACKUP);

		// Show the scroller
		gotoxy(sx,sy+height);
		textcolor(COLOR_CYAN);
		cprintf(" %.*s ",maxLen, pScroller);
		
		// Wrap the message if needed
		if((pEnd - pScroller) < maxLen-1)
		{
			gotoxy(sx+(pEnd-pScroller)+1,sy+height);
			cprintf(" %.*s ",maxLen-(pEnd - pScroller)-1, scroller);
		}

		// Only update the scrolling when needed
		if(plat_TimeExpired(SCROLL_SPEED, &timerInit))
		{
			++pScroller;
			if(!*pScroller)
				pScroller = scroller;
		}
	} while(keyMask != INPUT_SELECT && keyMask != INPUT_BACKUP);

	// if backing out of the menu, return 0
	if(keyMask & INPUT_BACKUP)
		return 0;
	
	// return the selection
	return i;
}