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

📄 ebcot_arith_decoder.c

📁 JPEG2000 EBCOT算法源码
💻 C
字号:
/*****************************************************************************/
/* File name: "ebcot_arith_decoder.c"                                        */
/* Author: David Taubman                                                     */
/* Copyright 1998, Hewlett-Packard Company                                   */
/* All rights reserved                                                       */
/*****************************************************************************/
#include <assert.h>
#include <stdio.h>
#include "ebcot_arith_decoder.h"

/* ========================================================================= */
/* ------------------------- External Functions ---------------------------- */
/* ========================================================================= */

/*****************************************************************************/
/* EXTERN               ebcot_arith_coder__initialize                        */
/*****************************************************************************/

void
  ebcot_arith_coder__initialize(arith_state_ptr state, heap_unit_ptr heap,
                                int code_bytes)
{
  int n;
  std_int word;

  state->available_bytes = code_bytes;
  state->heap = heap;
  state->next_heap_pos = 0;
  word = ebcot_arith_coder__input_word(state);
  state->A = (-1)^((-1)<<W_BITS);
  state->C = (word >> 1) & ~(1<<31);
  state->word = word << 31;
  state->available_bits = 1;
  for (n=0; n < TOTAL_CONTEXTS; n++)
    state->contexts[n] = 2 + (1<<S_BITS); /* S=2 and N=1 */
}

/*****************************************************************************/
/* EXTERN               ebcot_arith_coder__renormalize                       */
/*****************************************************************************/

void
  ebcot_arith_coder__renormalize(arith_state_ptr state)
{
  context_state_ptr csp;
  context_state cs;
  int n;

  csp = state->contexts + ZC_OFFSET;
  for (n=ZC_CONTEXTS; n > 0; n--, csp++)
    {
      cs = *csp;
      while (((cs >> S_BITS) > 2) && ((cs & S_MASK) > 32))
        cs = (cs>>1) & ~S_MSB;
      *csp = cs;
    }
}

/*****************************************************************************/
/* EXTERN               ebcot_arith_coder__input_word                        */
/*****************************************************************************/

std_int
  ebcot_arith_coder__input_word(arith_state_ptr state)
{
  std_int result;

  if (state->available_bytes <= 0)
    return((std_int) -1);
  state->available_bytes -= 4;
  result = state->heap->words[state->next_heap_pos++];
  if (state->next_heap_pos == HEAP_WORDS)
    { state->heap = state->heap->next; state->next_heap_pos = 0; }
  if (state->available_bytes < 0)
    { /* Pad missing locations with 1's. */
      std_int pad;

      pad = -state->available_bytes;
      pad <<= 3; /* Convert to bits. */
      pad = ~(((std_int)(-1)) << pad);
      result |= pad;
    }
  return(result);
}

/*****************************************************************************/
/* EXTERN            ebcot_arith_coder__check_logged_symbol                  */
/*****************************************************************************/

#ifdef LOG_SYMBOLS
void
  ebcot_arith_coder__check_logged_symbol(arith_state_ptr state,
                                         context_state_ptr ctxt,
                                         std_short symbol)
{
  int val, check_val;

  if (ctxt == NULL)
    val = 255;
  else
    val = ctxt - state->contexts;
  check_val = getc(state->symbol_log);
  assert(val == check_val);
  val = (symbol)?1:0;
  check_val = getc(state->symbol_log);
  assert(val == check_val);
}
#endif /* LOG_SYMBOLS */

⌨️ 快捷键说明

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