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

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

?? jchuff.cpp

?? Windows 圖形編程 書籍
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
//-------------------------------------------------------------------------//
//          Windows Graphics Programming: Win32 GDI and DirectDraw         //
//                        ISBN  0-13-086985-6                              //
//                                                                         //
//  Modified by: Yuan, Feng                             www.fengyuan.com   //
//  Changes    : C++, exception, in-memory source, BGR byte order          //
//  Version    : 1.00.000, May 31, 2000                                    //
//-------------------------------------------------------------------------//

/*
 * jchuff.c
 *
 * Copyright (C) 1991-1997, Thomas G. Lane.
 * This file is part of the Independent JPEG Group's software.
 * For conditions of distribution and use, see the accompanying README file.
 *
 * This file contains Huffman entropy encoding routines.
 *
 * Much of the complexity here has to do with supporting output suspension.
 * If the data destination module demands suspension, we want to be able to
 * back up to the start of the current MCU.  To do this, we copy state
 * variables into local working storage, and update them back to the
 * permanent JPEG objects only upon successful completion of an MCU.
 */

#define JPEG_INTERNALS
#include "jinclude.h"
#include "jpeglib.h"
#include "jchuff.h"		/* Declarations shared with jcphuff.c */


/* Expanded entropy encoder object for Huffman encoding.
 *
 * The savable_state subrecord contains fields that change within an MCU,
 * but must not be updated permanently until we complete the MCU.
 */

typedef struct {
  long put_buffer;		/* current bit-accumulation buffer */
  int  put_bits;			/* # of bits now in it */
  int  last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
} savable_state;

/* This macro is to work around compilers with missing or broken
 * structure assignment.  You'll need to fix this code if you have
 * such a compiler and you change MAX_COMPS_IN_SCAN.
 */

#ifndef NO_STRUCT_ASSIGN
#define ASSIGN_STATE(dest,src)  ((dest) = (src))
#else
#if MAX_COMPS_IN_SCAN == 4
#define ASSIGN_STATE(dest,src)  \
	((dest).put_buffer = (src).put_buffer, \
	 (dest).put_bits = (src).put_bits, \
	 (dest).last_dc_val[0] = (src).last_dc_val[0], \
	 (dest).last_dc_val[1] = (src).last_dc_val[1], \
	 (dest).last_dc_val[2] = (src).last_dc_val[2], \
	 (dest).last_dc_val[3] = (src).last_dc_val[3])
#endif
#endif


typedef struct {
  struct jpeg_entropy_encoder pub; /* public fields */

  savable_state saved;		/* Bit buffer & DC state at start of MCU */

  /* These fields are NOT loaded into local working state. */
  unsigned int restarts_to_go;	/* MCUs left in this restart interval */
  int next_restart_num;		/* next restart number to write (0-7) */

  /* Pointers to derived tables (these workspaces have image lifespan) */
  c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];

#ifdef ENTROPY_OPT_SUPPORTED	/* Statistics tables for optimization */
  long * dc_count_ptrs[NUM_HUFF_TBLS];
  long * ac_count_ptrs[NUM_HUFF_TBLS];
#endif
} huff_entropy_encoder;

typedef huff_entropy_encoder * huff_entropy_ptr;

/* Working state while writing an MCU.
 * This struct contains all the fields that are needed by subroutines.
 */

typedef struct {
  JOCTET * next_output_byte;	/* => next byte to write in buffer */
  size_t free_in_buffer;	/* # of byte spaces remaining in buffer */
  savable_state cur;		/* Current bit buffer & DC state */
  j_compress_ptr cinfo;		/* dump_buffer needs access to this */
} working_state;


/* Forward declarations */
boolean encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data);
void    finish_pass_huff (j_compress_ptr cinfo);

#ifdef ENTROPY_OPT_SUPPORTED
boolean encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data);
void    finish_pass_gather (j_compress_ptr cinfo);
#endif


/*
 * Initialize for a Huffman-compressed scan.
 * If gather_statistics is TRUE, we do not output anything during the scan,
 * just count the Huffman symbols used and generate Huffman code tables.
 */

void start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
{
  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  int ci, dctbl, actbl;
  jpeg_component_info * compptr;

  if (gather_statistics) {
#ifdef ENTROPY_OPT_SUPPORTED
    entropy->pub.encode_mcu = encode_mcu_gather;
    entropy->pub.finish_pass = finish_pass_gather;
#else
    cinfo->ERREXIT(JERR_NOT_COMPILED);
#endif
  } else {
    entropy->pub.encode_mcu = encode_mcu_huff;
    entropy->pub.finish_pass = finish_pass_huff;
  }

  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
    compptr = cinfo->cur_comp_info[ci];
    dctbl = compptr->dc_tbl_no;
    actbl = compptr->ac_tbl_no;
    if (gather_statistics) {
#ifdef ENTROPY_OPT_SUPPORTED
      /* Check for invalid table indexes */
      /* (make_c_derived_tbl does this in the other path) */
      if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
	cinfo->ERREXIT1(JERR_NO_HUFF_TABLE, dctbl);
      if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
	cinfo->ERREXIT1(JERR_NO_HUFF_TABLE, actbl);
      /* Allocate and zero the statistics tables */
      /* Note that jpeg_gen_optimal_table expects 257 entries in each table! */
      if (entropy->dc_count_ptrs[dctbl] == NULL)
	entropy->dc_count_ptrs[dctbl] = (long *)
	  cinfo->mem->alloc_small (JPOOL_IMAGE, 257 * sizeof(long));
      memset(entropy->dc_count_ptrs[dctbl], 0, 257 * sizeof(long));
      if (entropy->ac_count_ptrs[actbl] == NULL)
	entropy->ac_count_ptrs[actbl] = (long *)
	  cinfo->mem->alloc_small (JPOOL_IMAGE,
				      257 * sizeof(long));
      memset(entropy->ac_count_ptrs[actbl], 0, 257 * sizeof(long));
#endif
    } else {
      /* Compute derived values for Huffman tables */
      /* We may do this more than once for a table, but it's not expensive */
      jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
			      & entropy->dc_derived_tbls[dctbl]);
      jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
			      & entropy->ac_derived_tbls[actbl]);
    }
    /* Initialize DC predictions to 0 */
    entropy->saved.last_dc_val[ci] = 0;
  }

  /* Initialize bit buffer to empty */
  entropy->saved.put_buffer = 0;
  entropy->saved.put_bits = 0;

  /* Initialize restart stuff */
  entropy->restarts_to_go = cinfo->restart_interval;
  entropy->next_restart_num = 0;
}


/*
 * Compute the derived values for a Huffman table.
 * This routine also performs some validation checks on the table.
 *
 * Note this is also used by jcphuff.c.
 */

GLOBAL(void)
jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
			 c_derived_tbl ** pdtbl)
{
  JHUFF_TBL *htbl;
  c_derived_tbl *dtbl;
  int p, i, l, lastp, si, maxsymbol;
  char huffsize[257];
  unsigned int huffcode[257];
  unsigned int code;

  /* Note that huffsize[] and huffcode[] are filled in code-length order,
   * paralleling the order of the symbols themselves in htbl->huffval[].
   */

  /* Find the input Huffman table */
  if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
    cinfo->ERREXIT1(JERR_NO_HUFF_TABLE, tblno);
  htbl =
    isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  if (htbl == NULL)
    cinfo->ERREXIT1(JERR_NO_HUFF_TABLE, tblno);

  /* Allocate a workspace if we haven't already done so. */
	if (*pdtbl == NULL)
		*pdtbl = (c_derived_tbl *)
						cinfo->mem->alloc_small (JPOOL_IMAGE, sizeof(c_derived_tbl));
	dtbl = *pdtbl;
  
  /* Figure C.1: make table of Huffman code length for each symbol */

  p = 0;
  for (l = 1; l <= 16; l++) {
    i = (int) htbl->bits[l];
    if (i < 0 || p + i > 256)	/* protect against table overrun */
      cinfo->ERREXIT(JERR_BAD_HUFF_TABLE);
    while (i--)
      huffsize[p++] = (char) l;
  }
  huffsize[p] = 0;
  lastp = p;
  
  /* Figure C.2: generate the codes themselves */
  /* We also validate that the counts represent a legal Huffman code tree. */

  code = 0;
  si = huffsize[0];
  p = 0;
  while (huffsize[p]) {
    while (((int) huffsize[p]) == si) {
      huffcode[p++] = code;
      code++;
    }
    /* code is now 1 more than the last code used for codelength si; but
     * it must still fit in si bits, since no code is allowed to be all ones.
     */
    if (((long) code) >= (((long) 1) << si))
      cinfo->ERREXIT(JERR_BAD_HUFF_TABLE);
    code <<= 1;
    si++;
  }
  
  /* Figure C.3: generate encoding tables */
  /* These are code and size indexed by symbol value */

  /* Set all codeless symbols to have code length 0;
   * this lets us detect duplicate VAL entries here, and later
   * allows emit_bits to detect any attempt to emit such symbols.
   */
	memset(dtbl->ehufsi, 0, sizeof(dtbl->ehufsi));

  /* This is also a convenient place to check for out-of-range
   * and duplicated VAL entries.  We allow 0..255 for AC symbols
   * but only 0..15 for DC.  (We could constrain them further
   * based on data depth and mode, but this seems enough.)
   */
  maxsymbol = isDC ? 15 : 255;

  for (p = 0; p < lastp; p++) {
    i = htbl->huffval[p];
    if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
      cinfo->ERREXIT(JERR_BAD_HUFF_TABLE);
    dtbl->ehufco[i] = huffcode[p];
    dtbl->ehufsi[i] = huffsize[p];
  }
}


/* Outputting bytes to the file */

/* Emit a byte, taking 'action' if must suspend. */
#define emit_byte(state,val,action)  \
	{ *(state)->next_output_byte++ = (JOCTET) (val);  \
	  if (--(state)->free_in_buffer == 0)  \
	    if (! dump_buffer(state))  \
	      { action; } }


LOCAL(boolean)
dump_buffer (working_state * state)
/* Empty the output buffer; return TRUE if successful, FALSE if must suspend */
{
  struct jpeg_destination_mgr * dest = state->cinfo->dest;

  if (! (*dest->empty_output_buffer) (state->cinfo))
    return FALSE;
  /* After a successful buffer dump, must reset buffer pointers */
  state->next_output_byte = dest->next_output_byte;
  state->free_in_buffer = dest->free_in_buffer;
  return TRUE;
}


/* Outputting bits to the file */

/* Only the right 24 bits of put_buffer are used; the valid bits are
 * left-justified in this part.  At most 16 bits can be passed to emit_bits
 * in one call, and we never retain more than 7 bits in put_buffer
 * between calls, so 24 bits are sufficient.
 */

INLINE
LOCAL(boolean)
emit_bits (working_state * state, unsigned int code, int size)
/* Emit some bits; return TRUE if successful, FALSE if must suspend */
{
  /* This routine is heavily used, so it's worth coding tightly. */
  register long put_buffer = (long) code;
  register int put_bits = state->cur.put_bits;

  /* if size is 0, caller used an invalid Huffman table entry */
  if (size == 0)
    state->cinfo->ERREXIT(JERR_HUFF_MISSING_CODE);

  put_buffer &= (((long) 1)<<size) - 1; /* mask off any extra bits in code */
  
  put_bits += size;		/* new number of bits in buffer */
  
  put_buffer <<= 24 - put_bits; /* align incoming bits */

  put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
  
  while (put_bits >= 8) {
    int c = (int) ((put_buffer >> 16) & 0xFF);
    
    emit_byte(state, c, return FALSE);
    if (c == 0xFF) {		/* need to stuff a zero byte? */
      emit_byte(state, 0, return FALSE);
    }
    put_buffer <<= 8;
    put_bits -= 8;
  }

  state->cur.put_buffer = put_buffer; /* update state variables */
  state->cur.put_bits = put_bits;

  return TRUE;
}


LOCAL(boolean)
flush_bits (working_state * state)
{
  if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
    return FALSE;
  state->cur.put_buffer = 0;	/* and reset bit-buffer to empty */
  state->cur.put_bits = 0;
  return TRUE;
}


/* Encode a single block's worth of coefficients */

LOCAL(boolean)
encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
		  c_derived_tbl *dctbl, c_derived_tbl *actbl)
{
  register int temp, temp2;
  register int nbits;
  register int k, r, i;
  
  /* Encode the DC coefficient difference per section F.1.2.1 */
  
  temp = temp2 = block[0] - last_dc_val;

  if (temp < 0) {
    temp = -temp;		/* temp is abs value of input */
    /* For a negative input, want temp2 = bitwise complement of abs(input) */
    /* This code assumes we are on a two's complement machine */
    temp2--;
  }
  
  /* Find the number of bits needed for the magnitude of the coefficient */
  nbits = 0;
  while (temp) {
    nbits++;
    temp >>= 1;
  }
  /* Check for out-of-range coefficient values.
   * Since we're encoding a difference, the range limit is twice as much.
   */
  if (nbits > MAX_COEF_BITS+1)
    state->cinfo->ERREXIT(JERR_BAD_DCT_COEF);
  
  /* Emit the Huffman-coded symbol for the number of bits */
  if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
    return FALSE;

  /* Emit that number of bits of the value, if positive, */
  /* or the complement of its magnitude, if negative. */
  if (nbits)			/* emit_bits rejects calls with size 0 */
    if (! emit_bits(state, (unsigned int) temp2, nbits))
      return FALSE;

  /* 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[jpeg_natural_order[k]]) == 0) {
      r++;
    } else {
      /* if run length > 15, must emit special run-length-16 codes (0xF0) */
      while (r > 15) {
	if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
	  return FALSE;
	r -= 16;
      }

      temp2 = temp;
      if (temp < 0) {
	temp = -temp;		/* temp is abs value of input */
	/* This code assumes we are on a two's complement machine */
	temp2--;
      }
      
      /* Find the number of bits needed for the magnitude of the coefficient */
      nbits = 1;		/* there must be at least one 1 bit */
      while ((temp >>= 1))
	nbits++;
      /* Check for out-of-range coefficient values */
      if (nbits > MAX_COEF_BITS)
	state->cinfo->ERREXIT(JERR_BAD_DCT_COEF);
      
      /* Emit Huffman symbol for run length / number of bits */
      i = (r << 4) + nbits;
      if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
	return FALSE;

      /* Emit that number of bits of the value, if positive, */
      /* or the complement of its magnitude, if negative. */
      if (! emit_bits(state, (unsigned int) temp2, nbits))
	return FALSE;
      
      r = 0;
    }
  }

  /* If the last coef(s) were zero, emit an end-of-block code */
  if (r > 0)
    if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
      return FALSE;

  return TRUE;
}


/*
 * Emit a restart marker & resynchronize predictions.
 */

LOCAL(boolean)

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲欧美色综合| 性做久久久久久| 国产专区欧美精品| 日韩精品一区二区三区视频| 秋霞电影一区二区| 日韩精品中文字幕在线一区| 九九热在线视频观看这里只有精品| 欧美大白屁股肥臀xxxxxx| 裸体歌舞表演一区二区| 亚洲精品在线观看视频| 成人小视频免费在线观看| 亚洲国产高清aⅴ视频| 91香蕉视频污在线| 亚洲午夜一区二区| 日韩一区二区在线观看视频| 国产成人综合网站| 亚洲免费av高清| 欧美精品九九99久久| 精品一区二区三区久久| 国产精品久久久久久久岛一牛影视| 色综合天天综合在线视频| 天堂av在线一区| 国产亚洲一区二区三区四区| 91亚洲永久精品| 秋霞成人午夜伦在线观看| 中文字幕乱码久久午夜不卡| 欧美一a一片一级一片| 久久精品国产精品青草| 一区视频在线播放| 欧美一区二区三区电影| 国产成a人亚洲| 亚洲精选免费视频| 精品少妇一区二区三区在线视频| 91麻豆免费观看| 美女任你摸久久| 亚洲女子a中天字幕| 久久综合久久鬼色中文字| 一本到一区二区三区| 国产一区三区三区| 亚洲一区二区三区爽爽爽爽爽| 精品99一区二区三区| 91久久香蕉国产日韩欧美9色| 极品少妇xxxx精品少妇| 一区二区久久久| 国产日韩v精品一区二区| 欧美日韩在线亚洲一区蜜芽| 成人网男人的天堂| 蜜桃视频第一区免费观看| 亚洲欧美日韩国产一区二区三区| 日韩久久精品一区| 欧美日韩精品福利| 99在线精品一区二区三区| 激情五月激情综合网| 日韩精彩视频在线观看| 亚洲精品乱码久久久久久黑人| 久久综合久久综合久久| 欧美一区二区视频在线观看| 在线观看一区二区视频| 成人免费毛片片v| 国产一区二区三区在线观看免费视频 | 国产精品久久久久久久久免费相片| 欧美日韩高清不卡| 色综合视频在线观看| 大胆亚洲人体视频| 国产精品一品二品| 麻豆91精品91久久久的内涵| 日韩精品亚洲专区| 亚洲香蕉伊在人在线观| 一区二区三区日本| 国产精品麻豆视频| 国产日韩欧美不卡在线| 久久久精品影视| 久久综合五月天婷婷伊人| 久久色视频免费观看| 日韩一区二区三区免费看| 欧美精品一二三四| 欧美羞羞免费网站| 欧美久久免费观看| 欧美疯狂性受xxxxx喷水图片| 欧美日韩夫妻久久| 日韩一级二级三级| 欧美一区二区在线不卡| 日韩精品一区二区三区蜜臀| 欧美电视剧免费观看| 久久亚洲综合色一区二区三区| 国产不卡视频一区二区三区| 欧美国产精品v| 久久精品日产第一区二区三区高清版| 日韩欧美一区二区三区在线| 日韩亚洲国产中文字幕欧美| 欧美一二三区在线| 日韩亚洲欧美一区二区三区| 久久久精品免费观看| 国产欧美日韩另类视频免费观看| 欧美国产精品v| 亚洲色图在线视频| 亚洲精品伦理在线| 日韩影视精彩在线| 老色鬼精品视频在线观看播放| 黑人精品欧美一区二区蜜桃 | www.在线成人| 色噜噜狠狠成人中文综合| 欧美视频一区二区三区在线观看 | 欧美少妇一区二区| 99re视频精品| 日本一区二区高清| 18成人在线观看| 亚洲自拍偷拍九九九| 日韩精品欧美精品| 国产精品系列在线播放| av色综合久久天堂av综合| 色av成人天堂桃色av| 欧美一级片在线观看| 国产亚洲精品bt天堂精选| 一区二区高清免费观看影视大全| 免费久久99精品国产| 国产69精品久久99不卡| 欧美日韩一级片在线观看| 26uuu久久天堂性欧美| 1000部国产精品成人观看| 偷窥少妇高潮呻吟av久久免费| 国产麻豆精品theporn| 91黄视频在线观看| 精品国产露脸精彩对白| 亚洲精品乱码久久久久久| 经典三级一区二区| 日本久久一区二区| 久久奇米777| 五月天婷婷综合| eeuss国产一区二区三区| 欧美一区二区三区免费在线看| 国产精品不卡在线| 奇米一区二区三区| 欧美福利视频导航| 99久久久国产精品| 不卡的av网站| 日韩欧美一级片| 亚洲欧美日韩综合aⅴ视频| 韩国女主播一区二区三区| 欧美日韩一区国产| 国产精品久久久一本精品| 久久精品国产一区二区| 欧美怡红院视频| 中文字幕亚洲视频| 久久99精品一区二区三区 | 久久视频一区二区| 日韩激情视频网站| 色婷婷av一区二区三区软件 | 99久久免费精品高清特色大片| 日韩欧美一区二区免费| 亚洲h精品动漫在线观看| 99精品视频一区| 久久久91精品国产一区二区精品 | 毛片不卡一区二区| 欧美日韩mp4| 玉米视频成人免费看| eeuss鲁片一区二区三区在线观看 eeuss鲁片一区二区三区在线看 | 精品国产伦一区二区三区观看方式| 亚洲自拍偷拍综合| 色婷婷国产精品综合在线观看| 亚洲欧美在线另类| 国产精品77777竹菊影视小说| 欧美不卡激情三级在线观看| 日韩av二区在线播放| 欧美精品黑人性xxxx| 午夜免费欧美电影| 欧美高清www午色夜在线视频| 亚洲国产中文字幕| 欧美电影在线免费观看| 亚洲成人动漫在线免费观看| 欧美私人免费视频| 依依成人综合视频| 在线免费观看一区| 亚洲综合免费观看高清完整版在线| 97se狠狠狠综合亚洲狠狠| 亚洲精品国产第一综合99久久| 91网站视频在线观看| 一区二区三区四区五区视频在线观看| av资源网一区| 一区二区高清免费观看影视大全 | 亚洲天堂a在线| 91亚洲国产成人精品一区二区三| 最新高清无码专区| 91国偷自产一区二区使用方法| 一区二区三国产精华液| 欧美顶级少妇做爰| 久久99久久99小草精品免视看| 久久久综合视频| av在线不卡电影| 国产欧美日韩不卡免费| 中文字幕第一页久久| 亚洲欧美视频在线观看| 成人黄色片在线观看| 欧美韩国日本综合| 99麻豆久久久国产精品免费优播| 亚洲女女做受ⅹxx高潮| 欧美日本不卡视频| 久88久久88久久久| 国产精品第五页| 欧美男男青年gay1069videost|