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

📄 jpdini.c

📁 基于ti c55x序列dsp的jpeg算法中的哈夫解码的实现
💻 C
字号:
/*****************************************************************************
 PROJECT:     TI DSC P-2 Software Library
 MODULE:      jpgd_ini.c
 DESCRIPTION: JPEG decoder initialization utility
              (formerly jpgd_tbc.c and renamed on 1/19/2000 to include
			  more functions in this module)
 CREATED BY:  Youngjun Francis Yoo (1/2000)
 COPYRIGHT by TEXAS INSTRUMENTS, Inc. 2000
 ---------------------------------------------------------------------------
 VERSION:     $Id: jpgd_ini.c,v 1.6 2000/03/14 21:32:27 yoo Exp $
 HISTORY:
 $Log: jpgd_ini.c,v $
 Revision 1.6  2000/03/14 21:32:27  yoo
 Editorial change only.

 Revision 1.5  2000/03/03 21:41:43  yoo
 Changed function interface and variables. No functionality change.

 Revision 1.4  2000/02/21 19:27:48  yoo
 Removed all global variables. And made minor changes for variable names.

 Revision 1.3  2000/02/15 16:46:40  yoo
 Changed dequant table variable from QtabY and QtabUV to Qtab[3] to
 use 3 tables, one for each of Y, U, and V

 Revision 1.2  2000/02/08 21:21:40  yoo
 No major change except minor code size reduction

 Revision 1.1  2000/02/03 19:04:03  yoo
 Initial revision

*****************************************************************************/
//#include "jpegdec.h"
//#include "vld.h"
#include"VLD_structure.h"
/*struct vlccode {
  unsigned int len;
  unsigned int word;
  unsigned int pattern;
};

struct control {
  unsigned int th_lower;
  int shift;
  int offset;
};
*/
/* external function prototypes */
//extern int f_getcurbyte(int **, int *);

/* local function prototypes */
int InstallUvldTable(struct vlccode *, int, int, int *, int *);

/* global variable declarations */
//extern int unzigzag[];               /* jpgd_fun.c */



/* 
   InstallUvldTable(): Huffman table conversion utility for Universal VLD
   -- based on Minhua's read_cod_table()
*/
int InstallUvldTable(
  struct vlccode * ctable,  /* codebook structure */
  int nb_codes,                /* # codewords */
  int sign,                    /* polarity of leading cword bit */
  int *vldtab_p,               /* pointer to (output) UVLD table */
  int *ctltab_p)               /* pointer to (output) UVLD control table */
{
  int i, j;
  unsigned int len_max, len_max0;
  int num[12] = {1,2,4,8,16,32,64,128,256,512,1024,2048}; 
  struct control codectl[18]; /* codectl[40] */
  unsigned int i_min, i_max, pattern_num, interval;
  long Thred;
  unsigned int utemp;
  int temp;

  /* find the maximum codeword length */
  len_max=ctable[nb_codes-1].len;

  /* left-align the codeword and invert the bits */
  for (i=0;i<nb_codes;i++) {  /* BUG in the original code!!! (Yoo, 012300) */
	if (sign)
	  ctable[i].word = (1<<ctable[i].len) - ctable[i].word - 1;
    ctable[i].word = (ctable[i].word<<(len_max-ctable[i].len));
  } 

  /* sort ctable[] such that codewords are in increasing order */
  for (i=0;i<nb_codes;i++) {   /* other more efficient sorting routine? */
	i_min = i;
	for (j=i+1;j<nb_codes;j++) 
	  if (ctable[i].word > ctable[j].word)
		i_min = j;
	if (i_min != i) {
	  utemp = ctable[i].word;
	  ctable[i].word = ctable[i_min].word;
	  ctable[i_min].word = utemp;
	  utemp = ctable[i].len;
	  ctable[i].len = ctable[i_min].len;
	  ctable[i_min].len = utemp;
	  utemp = ctable[i].pattern;
	  ctable[i].pattern = ctable[i_min].pattern;
	  ctable[i_min].pattern = utemp;
	}
  }

  /* make VLD table and control table */
  i_min=0;i_max=0; 
  codectl[0].offset=0;
  codectl[0].th_lower=0;
  codectl[0].shift =0;
  interval =0;
  
  Thred=1;
  while (Thred<ctable[0].word) {
    interval++; 
    codectl[interval].offset=Thred;
    codectl[interval].shift=0;
    codectl[interval].th_lower=Thred;
    Thred <<=1; 
  } 

  if (Thred == ctable[0].word) {
    interval++;
    codectl[interval].offset=Thred;
    Thred <<=1; 
  } 

  do {
    while ((ctable[i_max].word<Thred)&&(i_max<nb_codes)) i_max++;
    codectl[interval].th_lower = Thred>>1;
    
    len_max0=0;
    for (i=i_min;i<i_max;i++)
      if (ctable[i].len>len_max0) len_max0 = ctable[i].len; 

    codectl[interval].shift = len_max-len_max0;

    pattern_num=0;
    for (i=i_min;i<i_max;i++) {
      if (i==0)
		for (j=0;j<codectl[interval].th_lower;j++)
		  *vldtab_p++ = 0;

      if (i==i_min) {
		temp = (ctable[i].word-codectl[interval].th_lower);
		temp >>= codectl[interval].shift;
        for (j=0;j<temp;j++) {
		  *vldtab_p++ = 0;
		  pattern_num++;
		}
	  }

	  temp = num[len_max-ctable[i].len-codectl[interval].shift];
      for (j=0;j<temp;j++) {
		*vldtab_p++ = (ctable[i].len<<11) | ctable[i].pattern;
		pattern_num++;
      } 
	  
      if (i<i_max-1) {
		temp = ((ctable[i+1].word-ctable[i].word)>>codectl[interval].shift)
		  - num[len_max-ctable[i].len-codectl[interval].shift];
		for (j=0;j<temp;j++) {
		  *vldtab_p++ = 0;
		  pattern_num++;
		}
      }
      if (i==i_max-1) {
		temp = ((Thred-ctable[i].word)>>codectl[interval].shift)
		  - num[len_max-ctable[i].len-codectl[interval].shift];
        for (j=0;j<temp;j++) {
		  *vldtab_p++ = 0;
		  pattern_num++;
		}
	  }
    }
	
    i_min = i_max;
	Thred <<= 1;
    interval++;
	codectl[interval].offset = codectl[interval-1].offset + pattern_num;
  } while (i_max<nb_codes);
 
  for (i=0;i<interval;i++) 
    codectl[i].offset -= codectl[i].th_lower >> codectl[i].shift;

  /* install VLD code control table */
  for (i=0;i<interval;i++)
	*ctltab_p++ = (codectl[i].shift<<11) | codectl[i].offset;

  return(len_max); /* return max codeword size */
} /* end of void InstallHuffmanDec() */

⌨️ 快捷键说明

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