亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? jchuff.c

?? EVM板JPEG實現,Texas Instruments TMS320C54x EVM JPEG
?? C
?? 第 1 頁 / 共 2 頁
字號:




/*
 * Huffman coding optimization.
 *
 * This actually is optimization, in the sense that we find the best possible
 * Huffman table(s) for the given data.  We first scan the supplied data and
 * count the number of uses of each symbol that is to be Huffman-coded.
 * (This process must agree with the code above.)  Then we build an
 * optimal Huffman coding tree for the observed counts.
 */

#ifdef ENTROPY_OPT_SUPPORTED


/* These are static so htest_one_block can find 'em */
static long * dc_count_ptrs[NUM_HUFF_TBLS];
static long * ac_count_ptrs[NUM_HUFF_TBLS];


LOCAL void
gen_huff_coding (compress_info_ptr cinfo, HUFF_TBL *htbl, long freq[])
/* Generate the optimal coding for the given counts */
{
#define MAX_CLEN 32     /* assumed maximum initial code length */
  UINT8 bits[MAX_CLEN+1];   /* bits[k] = # of symbols with code length k */
  short codesize[257];      /* codesize[k] = code length of symbol k */
  short others[257];        /* next symbol in current branch of tree */
  int c1, c2;
  int p, i, j;
  long v;

  /* This algorithm is explained in section K.2 of the JPEG standard */

  MEMZERO(bits, SIZEOF(bits));
  MEMZERO(codesize, SIZEOF(codesize));
  for (i = 0; i < 257; i++)
	others[i] = -1;     /* init links to empty */
  
  freq[256] = 1;        /* make sure there is a nonzero count */
  /* including the pseudo-symbol 256 in the Huffman procedure guarantees
   * that no real symbol is given code-value of all ones, because 256
   * will be placed in the largest codeword category.
   */

  /* Huffman's basic algorithm to assign optimal code lengths to symbols */

  for (;;) {
	/* Find the smallest nonzero frequency, set c1 = its symbol */
	/* In case of ties, take the larger symbol number */
	c1 = -1;
	v = 1000000000L;
	for (i = 0; i <= 256; i++) {
	  if (freq[i] && freq[i] <= v) {
	v = freq[i];
	c1 = i;
	  }
	}

	/* Find the next smallest nonzero frequency, set c2 = its symbol */
	/* In case of ties, take the larger symbol number */
	c2 = -1;
	v = 1000000000L;
	for (i = 0; i <= 256; i++) {
	  if (freq[i] && freq[i] <= v && i != c1) {
	v = freq[i];
	c2 = i;
	  }
	}

	/* Done if we've merged everything into one frequency */
	if (c2 < 0)
	  break;
	
	/* Else merge the two counts/trees */
	freq[c1] += freq[c2];
	freq[c2] = 0;

	/* Increment the codesize of everything in c1's tree branch */
	codesize[c1]++;
	while (others[c1] >= 0) {
	  c1 = others[c1];
	  codesize[c1]++;
	}
	
	others[c1] = c2;        /* chain c2 onto c1's tree branch */
	
	/* Increment the codesize of everything in c2's tree branch */
	codesize[c2]++;
	while (others[c2] >= 0) {
	  c2 = others[c2];
	  codesize[c2]++;
	}
  }

  /* Now count the number of symbols of each code length */
  for (i = 0; i <= 256; i++) {
	if (codesize[i]) {
	  /* The JPEG standard seems to think that this can't happen, */
	  /* but I'm paranoid... */
	  if (codesize[i] > MAX_CLEN)
	ERREXIT(cinfo->emethods);
	/*(cinfo->emethods, "Huffman code size table overflow");*/

	  bits[codesize[i]]++;
	}
  }

  /* JPEG doesn't allow symbols with code lengths over 16 bits, so if the pure
   * Huffman procedure assigned any such lengths, we must adjust the coding.
   * Here is what the JPEG spec says about how this next bit works:
   * Since symbols are paired for the longest Huffman code, the symbols are
   * removed from this length category two at a time.  The prefix for the pair
   * (which is one bit shorter) is allocated to one of the pair; then,
   * skipping the BITS entry for that prefix length, a code word from the next
   * shortest nonzero BITS entry is converted into a prefix for two code words
   * one bit longer.
   */
  
  for (i = MAX_CLEN; i > 16; i--) {
	while (bits[i] > 0) {
	  j = i - 2;        /* find length of new prefix to be used */
	  while (bits[j] == 0)
	j--;
	  
	  bits[i] -= 2;     /* remove two symbols */
	  bits[i-1]++;      /* one goes in this length */
	  bits[j+1] += 2;       /* two new symbols in this length */
	  bits[j]--;        /* symbol of this length is now a prefix */
	}
  }

  /* Remove the count for the pseudo-symbol 256 from the largest codelength */
  while (bits[i] == 0)      /* find largest codelength still in use */
	i--;
  bits[i]--;
  
  /* Return final symbol counts (only for lengths 0..16) */
  MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
  
  /* Return a list of the symbols sorted by code length */
  /* It's not real clear to me why we don't need to consider the codelength
   * changes made above, but the JPEG spec seems to think this works.
   */
  p = 0;
  for (i = 1; i <= MAX_CLEN; i++) {
	for (j = 0; j <= 255; j++) {
	  if (codesize[j] == i) {
	htbl->huffval[p] = (UINT8) j;
	p++;
	  }
	}
  }
}


/* Process a single block's worth of coefficients */
/* Note that the DC coefficient has already been converted to a difference */

LOCAL void
htest_one_block (JBLOCK block, JCOEF block0,
		 long dc_counts[], long ac_counts[])
{
  register INT32 temp;
  register int nbits;
  register int k, r;
  
  /* Encode the DC coefficient difference per section F.1.2.1 */
  
  /* Find the number of bits needed for the magnitude of the coefficient */
  temp = block0;
  if (temp < 0) temp = -temp;
  
  for (nbits = 0; temp; nbits++)
	temp >>= 1;
  
  /* Count the Huffman symbol for the number of bits */
  dc_counts[nbits]++;
  
  /* Encode the AC coefficients per section F.1.2.2 */
  
  r = 0;            /* r = run length of zeros */
  
  for (k = 1; k < DCTSIZE2; k++) {
	if ((temp = block[k]) == 0) {
	  r++;
	} else {
	  /* if run length > 15, must emit special run-length-16 codes (0xF0) */
	  while (r > 15) {
	ac_counts[0xF0]++;
	r -= 16;
	  }
	  
	  /* Find the number of bits needed for the magnitude of the coefficient */
	  if (temp < 0) temp = -temp;
	  
	  for (nbits = 0; temp; nbits++)
	temp >>= 1;
	  
	  /* Count Huffman symbol for run length / number of bits */
	  ac_counts[(r << 4) + nbits]++;
	  
	  r = 0;
	}
  }

  /* If the last coef(s) were zero, emit an end-of-block code */
  if (r > 0)
	ac_counts[0]++;
}



/*
 * Trial-encode one MCU's worth of Huffman-compressed coefficients.
 */

LOCAL void
htest_encode (compress_info_ptr cinfo, JBLOCK *MCU_data)
{
  short blkn, ci;
  jpeg_component_info * compptr;

  /* Take care of restart intervals if needed */
  if (cinfo->restart_interval) {
	if (cinfo->restarts_to_go == 0) {
	  /* Re-initialize DC predictions to 0 */
	  for (ci = 0; ci < cinfo->comps_in_scan; ci++)
	cinfo->last_dc_val[ci] = 0;
	  /* Update restart state */
	  cinfo->restarts_to_go = cinfo->restart_interval;
	}
	cinfo->restarts_to_go--;
  }

  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
	ci = cinfo->MCU_membership[blkn];
	compptr = cinfo->cur_comp_info[ci];
	/* NB: unlike the real entropy encoder, we may not change the input data */
	htest_one_block(MCU_data[blkn],
			(JCOEF) (MCU_data[blkn][0] - cinfo->last_dc_val[ci]),
			dc_count_ptrs[compptr->dc_tbl_no],
			ac_count_ptrs[compptr->ac_tbl_no]);
	cinfo->last_dc_val[ci] = MCU_data[blkn][0];
  }
}



/*
 * Find the best coding parameters for a Huffman-coded scan.
 * When called, the scan data has already been converted to a sequence of
 * MCU groups of quantized coefficients, which are stored in a "big" array.
 * The source_method knows how to iterate through that array.
 * On return, the MCU data is unmodified, but the Huffman tables referenced
 * by the scan components may have been altered.
 */

METHODDEF void
huff_optimize (compress_info_ptr cinfo, MCU_output_caller_ptr source_method)
/* Optimize Huffman-coding parameters (Huffman symbol table) */
{
  int i, tbl;
  HUFF_TBL **htblptr;

  /* Allocate and zero the count tables */
  /* Note that gen_huff_coding expects 257 entries in each table! */

  for (i = 0; i < NUM_HUFF_TBLS; i++) {
	dc_count_ptrs[i] = NULL;
	ac_count_ptrs[i] = NULL;
  }

  for (i = 0; i < cinfo->comps_in_scan; i++) {
	/* Create DC table */
	tbl = cinfo->cur_comp_info[i]->dc_tbl_no;
	if (dc_count_ptrs[tbl] == NULL) {
	  dc_count_ptrs[tbl] = (long *) (*cinfo->emethods->alloc_small)
					(257 * SIZEOF(long));
	  MEMZERO(dc_count_ptrs[tbl], 257 * SIZEOF(long));
	}
	/* Create AC table */
	tbl = cinfo->cur_comp_info[i]->ac_tbl_no;
	if (ac_count_ptrs[tbl] == NULL) {
	  ac_count_ptrs[tbl] = (long *) (*cinfo->emethods->alloc_small)
					(257 * SIZEOF(long));
	  MEMZERO(ac_count_ptrs[tbl], 257 * SIZEOF(long));
	}
  }

  /* Initialize DC predictions to 0 */
  for (i = 0; i < cinfo->comps_in_scan; i++) {
	cinfo->last_dc_val[i] = 0;
  }
  /* Initialize restart stuff */
  cinfo->restarts_to_go = cinfo->restart_interval;

  /* Scan the MCU data, count symbol uses */
  (*source_method) (cinfo, htest_encode);

  /* Now generate optimal Huffman tables */
  for (tbl = 0; tbl < NUM_HUFF_TBLS; tbl++) {
	if (dc_count_ptrs[tbl] != NULL) {
	  htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
	  if (*htblptr == NULL)
	*htblptr = (HUFF_TBL *) (*cinfo->emethods->alloc_small) (SIZEOF(HUFF_TBL));
	  /* Set sent_table FALSE so updated table will be written to JPEG file. */
	  (*htblptr)->sent_table = FALSE;
	  /* Compute the optimal Huffman encoding */
	  gen_huff_coding(cinfo, *htblptr, dc_count_ptrs[tbl]);
	  /* Release the count table */
	  (*cinfo->emethods->free_small) ((void *) dc_count_ptrs[tbl]);
	}
	if (ac_count_ptrs[tbl] != NULL) {
	  htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
	  if (*htblptr == NULL)
	*htblptr = (HUFF_TBL *) (*cinfo->emethods->alloc_small) (SIZEOF(HUFF_TBL));
	  /* Set sent_table FALSE so updated table will be written to JPEG file. */
	  (*htblptr)->sent_table = FALSE;
	  /* Compute the optimal Huffman encoding */
	  gen_huff_coding(cinfo, *htblptr, ac_count_ptrs[tbl]);
	  /* Release the count table */
	  (*cinfo->emethods->free_small) ((void *) ac_count_ptrs[tbl]);
	}
  }
}


#endif /* ENTROPY_OPT_SUPPORTED */


/*
 * The method selection routine for Huffman entropy encoding.
 */

GLOBAL void
jselchuffman (compress_info_ptr cinfo)
{
  if (! cinfo->arith_code) {
	cinfo->methods->entropy_encode_init = huff_init;
	cinfo->methods->entropy_encode = huff_encode;
	cinfo->methods->entropy_encode_term = huff_term;
#ifdef ENTROPY_OPT_SUPPORTED
	cinfo->methods->entropy_optimize = huff_optimize;
	/* The standard Huffman tables are only valid for 8-bit data precision.
	 * If the precision is higher, force optimization on so that usable
	 * tables will be computed.  This test can be removed if default tables
	 * are supplied that are valid for the desired precision.
	 */
	if (cinfo->data_precision > 8)
	  cinfo->optimize_coding = TRUE;
	if (cinfo->optimize_coding)
	  cinfo->total_passes++;    /* one pass needed for entropy optimization */
#endif
  }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲欧洲国产日本综合| 久久久亚洲精品石原莉奈| 国产suv精品一区二区6| 免费看欧美女人艹b| 美女视频黄a大片欧美| 亚洲成人一区二区| 亚洲午夜久久久| 亚瑟在线精品视频| 亚洲欧美另类久久久精品| 亚洲人快播电影网| 亚洲男人的天堂一区二区| 亚洲精品欧美二区三区中文字幕| 一区二区三区在线观看网站| 亚洲va韩国va欧美va| 精品影视av免费| 国产成人一区在线| 91香蕉视频mp4| 欧美色中文字幕| 精品少妇一区二区| 国产精品国产自产拍高清av| 一区二区三区在线观看网站| 日产国产高清一区二区三区 | 99久久免费精品| 91在线观看污| 在线91免费看| 亚洲国产精品成人久久综合一区| 亚洲精品国久久99热| 亚洲大片在线观看| 国产乱码一区二区三区| 色婷婷久久久久swag精品| 91精品国产美女浴室洗澡无遮挡| 久久久久久久久久久电影| 一区二区三区在线看| 久久国产精品99久久久久久老狼 | 国产成人午夜精品影院观看视频| 欧美视频在线一区| 欧美一二三四区在线| 国产精品色哟哟网站| 日韩精品一二三四| 成人av在线资源网| 日韩视频免费观看高清完整版在线观看 | 欧美高清激情brazzers| 久久久久久电影| 亚洲福利视频一区二区| 一区二区三区在线视频观看| 一区二区在线观看不卡| 亚洲国产精品久久艾草纯爱| 国产精品一区二区男女羞羞无遮挡 | 日韩免费在线观看| 亚洲欧美日韩在线| 国产高清无密码一区二区三区| 日本韩国精品一区二区在线观看| 久久免费电影网| 日韩电影在线一区| 99riav久久精品riav| 丁香五精品蜜臀久久久久99网站| 日韩欧美中文一区二区| 亚洲精品久久7777| 99国产精品99久久久久久| 久久精品人人做| 精品制服美女久久| 91精品国产品国语在线不卡| 一区二区三区久久| 91猫先生在线| 中文字幕亚洲电影| 成人午夜视频在线| 中文无字幕一区二区三区| 国内精品视频一区二区三区八戒| 欧美日韩1234| 午夜日韩在线电影| 欧美巨大另类极品videosbest | 色噜噜夜夜夜综合网| 久久久久久久久久看片| 精品一区二区在线视频| 日韩免费性生活视频播放| 日本中文一区二区三区| 51久久夜色精品国产麻豆| 日韩影院在线观看| 日韩小视频在线观看专区| 精品一区二区三区久久久| 精品国产污网站| 国产999精品久久| 中文字幕va一区二区三区| 97久久精品人人澡人人爽| 最新国产精品久久精品| 91首页免费视频| 亚洲大尺度视频在线观看| 在线不卡欧美精品一区二区三区| 日韩精品成人一区二区在线| 欧美大胆人体bbbb| 高清不卡一区二区在线| 中文字幕亚洲一区二区av在线 | 3d动漫精品啪啪一区二区竹菊| 日韩中文字幕av电影| 亚洲精品一区二区精华| 国产精品自拍在线| 亚洲欧洲精品一区二区三区| 欧美私模裸体表演在线观看| 麻豆精品新av中文字幕| 久久精品免视看| 在线看国产一区| 麻豆91在线观看| 国产精品每日更新在线播放网址 | 日韩电影在线观看网站| 久久综合国产精品| 91福利视频网站| 久久99精品国产.久久久久| 久久精品一区二区三区不卡牛牛| 日本韩国一区二区三区视频| 日韩黄色片在线观看| 国产欧美一区二区精品仙草咪| 在线免费观看一区| 国内精品免费**视频| 亚洲日本中文字幕区| 欧美va日韩va| 欧洲国内综合视频| 高清av一区二区| 日本午夜精品视频在线观看| 亚洲欧洲在线观看av| 日韩欧美国产麻豆| 色吧成人激情小说| 成人中文字幕合集| 九九国产精品视频| 亚洲一区二区三区影院| 国产欧美一区二区精品婷婷| 911精品国产一区二区在线| 91小视频在线观看| 国产激情视频一区二区三区欧美| 首页综合国产亚洲丝袜| 亚洲视频在线一区观看| 国产视频一区二区在线观看| 69久久99精品久久久久婷婷| 91福利视频网站| 92国产精品观看| 成人国产在线观看| 国产美女精品在线| 经典三级视频一区| 免费看欧美美女黄的网站| 视频在线在亚洲| 亚洲高清在线视频| 一区二区三区日韩欧美精品| 亚洲欧美一区二区在线观看| 久久先锋影音av| 日韩一卡二卡三卡四卡| 91精品国产综合久久久久久漫画 | 久久嫩草精品久久久久| 日韩视频在线一区二区| 欧美日本一道本| 欧美日韩高清一区二区不卡 | 国产高清在线精品| 高清日韩电视剧大全免费| 韩国女主播成人在线观看| 男女男精品视频网| 美日韩一区二区| 久久成人av少妇免费| 久久97超碰色| 国产.欧美.日韩| 91在线视频免费观看| 99九九99九九九视频精品| 99久久久精品免费观看国产蜜| 播五月开心婷婷综合| 97精品电影院| 欧美日韩精品三区| 欧美成人免费网站| 国产亚洲欧美一区在线观看| 国产精品久久久久久久久动漫| 国产精品日日摸夜夜摸av| 亚洲精品少妇30p| 亚洲成人av电影| 黄色成人免费在线| 成人自拍视频在线| 欧美优质美女网站| 日韩三级在线观看| 国产欧美日韩精品在线| 亚洲欧美成aⅴ人在线观看| 亚洲mv大片欧洲mv大片精品| 激情综合色丁香一区二区| 国产a精品视频| 欧美亚男人的天堂| 精品久久久久久综合日本欧美| 亚洲国产精品黑人久久久| 一二三四社区欧美黄| 欧美a级一区二区| 成人av午夜影院| 欧美日韩国产乱码电影| 国产欧美日本一区二区三区| 亚洲欧美日韩一区二区三区在线观看| 亚洲高清免费观看| 国产成人久久精品77777最新版本| av高清久久久| 欧美xxxx老人做受| 亚洲综合男人的天堂| 极品美女销魂一区二区三区 | 一区二区三国产精华液| 精品无人区卡一卡二卡三乱码免费卡| 99久久精品免费看国产免费软件| 欧美一级免费观看| 亚洲精品欧美激情| 成人精品视频一区二区三区尤物| 91精品国产麻豆|