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

📄 dst_arith_encoder.h

📁 JPEG2000实现的源码
💻 H
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************/
/* Copyright 1998, Hewlett-Packard Company                                   */
/* All rights reserved                                                       */
/* File: "dst_arith_encoder.h"                                               */
/* Description: Master include file for the arithmetic encoder.  This is the */
/*              only header file which need be included by clients.          */
/* Author: David Taubman                                                     */
/* Affiliation: Hewlett-Packard and                                          */
/*              The University of New South Wales, Australia                 */
/* Version: VM7.0                                                            */
/* Last Revised: 24 March, 2000                                              */
/*****************************************************************************/

/*****************************************************************************/
/* Modified to incorporate MQ-coder by Mitsubishi Electric Corp.             */
/* Copyright 1999, Mitsubishi Electric Corp.                                 */
/* All rights reserved for modified parts                                    */
/*****************************************************************************/

/*****************************************************************************/
/* Changes by HP:                                                            */
/* Some MQ-coder functions were in-lined.                                    */
/* Added code for speed-up mode of MQ coder.                                 */
/* Modified coder state structure to include some extra state necessary      */
/* for the line-based processing implementation.                             */
/* Copyright 1999, Hewlett-Packard Company                                   */
/* All rights reserved for modified parts                                    */
/*****************************************************************************/

/*****************************************************************************/
/* Modifications tagged with comment lines or delimiters involving the       */
/* string, "David T mod" or "mod by David T", have been made by David        */
/* Taubman; they are copyrighted by Hewlett-Packard Company with all rights  */
/* reserved for the modified parts.                                          */
/*****************************************************************************/

/*****************************************************************************/
/* Modified by David Taubman to support new termination methods and error    */
/* resilience.  Copyright 1999 by Hewlett-Packard Company with all           */
/* rights reserved for the modified parts.                                   */
/*****************************************************************************/

/*****************************************************************************/
/* Modified by David Taubman to avoid the need for byte stuffing when resync */
/* markers are in use.  This simplifies the code and substantially improves  */
/* the usefulness of the system for applications requiring error resilience. */
/* Changes are as follows: a) changed SOT marker to lie within intra-packet  */
/* marker range 0xFF90 through 0xFFFF; b) introduced an MQ-like bit-stuffing */
/* policy in packet heads; c) introduced an MQ-like bit-stuffing policy in   */
/* the raw bit-stream segments generated by the entropy coder in lazy mode;  */
/* d) modified error resilient termination policy for raw bit-stream         */
/* to fill unused bits with the simpler code 0101... instead of 1010...;     */
/* e) eliminated the use of byte-stuffing with resync markers.  In the new   */
/* code, none of the packet segments (packet head, MQ segments and raw       */
/* segments) may contain any two byte sequence in the range 0xFF90 through   */
/* 0xFFFF; moreover, no segment can terminate with a 0xFF, so that the       */
/* entire packet is guaranteed to be free of two byte sequences in the above */
/* range.  All delimiting markers from the codestream (i.e. SOT, RESYNC and  */
/* EOC) are guaranteed to lie within that range.                             */
/* Copyright 1999 by Hewlett-Packard Company with all                        */
/* rights reserved for the modified parts.                                   */
/*****************************************************************************/

#ifndef DST_ARITH_ENCODER_H
#define DST_ARITH_ENCODER_H
#include <ifc.h>
#include <stdio.h>
#include "dst_codeword_heap.h"
#include "dst_arith_coder_common.h"

/* ========================================================================= */
/* ----------------------------- Type Definitions -------------------------- */
/* ========================================================================= */

typedef /* Mitsubishi */
  struct mqe_var {
    std_int areg, creg, buffer, zc;
    std_short ct, io_enable;
    int active; /* Flag indicates that the MQ coder is in use. */
    int num_preceding_bytes;
    int have_unsent_ff;
  } mqe_var, *mqe_var_ptr;

  /* `num_preceding_bytes' identifies the number of bytes which have been
     written into the code stream prior to the commencement of the current
     arithmetic codeword generation process.  It is frequently 0, unless
     the code stream consists of multiple arithmetic codeword segments
     and/or raw data segments.
         `have_unsent_ff' is a flag which is true (non-zero) if the most
     recent byte pushed out of the `buffer' register was an FF, which has
     not yet been actually written into the code stream.  This behaviour
     enables the FF to be deleted if the MQ codeword generation process is
     terminated at this point. */

/*****************************************************************************/
/*                               dst_arith_state                             */
/*****************************************************************************/

typedef
  struct dst_arith_state {
    mqe_var mqe; /* Mitsubishi */
    int error_resilient_termination;
    std_int word;
    std_short current_lsb;
    int num_contexts;
    dst_context_state_ptr contexts;
    std_int saved_words;
    dst_heap_unit_ptr heap;
    int next_heap_pos;
    dst_codeword_heap_ref code_heap_mgr;
#ifdef DST_LOG_SYMBOLS
    FILE *symbol_log;
#endif /* DST_LOG_SYMBOLS */
  } dst_arith_state, *dst_arith_state_ptr;
  /* This structure manages fundamental state information for the arithmetic
     coding engine.
         `word' is a 32-bit word which is used to buffer code bits so as
     to avoid excessive access into the main bit-stream store.
         `current_lsb' holds the index of the last bit-position in `word'
     into which valid data was written.  A value of 32 means that `word'
     contains no data yet.  The field may equivalently be interpreted as
     the number of least significant bits in `word' which have not yet been
     filled with data.
         `contexts' points to the array of context states which is currently
     in use.  The array itself is managed externally, but it must be capable
     of storing `num_contexts'+DST_ARITH_MAX_CTXTS entries.
         `saved_words' holds the number of full words which have actually been
     saved to the heap store since the arithmetic coder was initialized, during
     normal encoding.
         `heap' points to the currently active `heap_unit' structure which is
     being used to store code words.
         `next_heap_pos' identifies the index of the next word within the
     `heap' structure into which the `word' register should be written once it
     is full.
         `code_heap_mgr' references the object which should be used to obtain
     additional heap units if necessary. */


#include "mq_encoder.h" /* Mitsubishi */

/* ========================================================================= */
/* ------------------------ Symbol Coding Macros --------------------------- */
/* ========================================================================= */

/*****************************************************************************/
/* MACRO                           renorme                                   */
/*****************************************************************************/

#define renorme(_areg_,_creg_,_ct_, _state_)                            \
  {                                                                     \
    do {                                                                \
      _creg_ <<= 1;                                                     \
      _areg_ <<= 1;                                                     \
      _ct_--;                                                           \
      if (!_ct_)                                                        \
        _creg_ = dst_arith_coder__byteout(_creg_,&(_ct_),_state_);      \
    } while(_areg_ < ENC_HALF);                                         \
  }

/*****************************************************************************/
/* MACRO                          trans_mps                                  */
/*****************************************************************************/

#define trans_mps(PST,ST,MPS)        \
  {                                  \
    *(PST)=(*(nmps+(ST))<<1)+(MPS);  \
  }

/*****************************************************************************/
/* MACRO                          trans_lps                                  */
/*****************************************************************************/

#define trans_lps(PST,ST,MPS)        \
  {                                  \
    if (*(swtch+(ST)))               \
      MPS = 1 - MPS;                 \
    *(PST)=(*(nlps+(ST))<<1)+(MPS);  \
  }

/*****************************************************************************/
/* MACRO                            mqenc                                    */
/*****************************************************************************/

#define   mqenc(_areg_,_creg_,_ct_, _state_, _pel_, _st_)       \
     /* dst_arith_state_ptr prm, mqe_var_ptr mqe, */            \
     /* ifc_int pel, dst_context_state_ptr st */                \
{                                                               \
  int n_st = *_st_ >> 1;                                        \
  int n_mps = *_st_ & 1;                                        \

⌨️ 快捷键说明

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