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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? arithmetic_codec.cpp

?? 算術(shù)編碼程序源代碼
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//                                                                           -
//                       ****************************                        -
//                        ARITHMETIC CODING EXAMPLES                         -
//                       ****************************                        -
//                                                                           -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//                                                                           -
// Fast arithmetic coding implementation                                     -
// -> 32-bit variables, 64-bit product, periodic updates, table decoding     -
//                                                                           -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//                                                                           -
// Version 1.00  -  April 25, 2004                                           -
//                                                                           -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//                                                                           -
//                                  WARNING                                  -
//                                 =========                                 -
//                                                                           -
// The only purpose of this program is to demonstrate the basic principles   -
// of arithmetic coding. It is provided as is, without any express or        -
// implied warranty, without even the warranty of fitness for any particular -
// purpose, or that the implementations are correct.                         -
//                                                                           -
// Permission to copy and redistribute this code is hereby granted, provided -
// that this warning and copyright notices are not removed or altered.       -
//                                                                           -
// Copyright (c) 2004 by Amir Said (said@ieee.org) &                         -
//                       William A. Pearlman (pearlw@ecse.rpi.edu)           -
//                                                                           -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//                                                                           -
// A description of the arithmetic coding method used here is available in   -
//                                                                           -
// Lossless Compression Handbook, ed. K. Sayood                              -
// Chapter 5: Arithmetic Coding (A. Said), pp. 101-152, Academic Press, 2003 -
//                                                                           -
// A. Said, Introduction to Arithetic Coding Theory and Practice             -
// HP Labs report HPL-2004-76  -  http://www.hpl.hp.com/techreports/         -
//                                                                           -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


// - - Inclusion - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

#include <stdlib.h>
#include "arithmetic_codec.h"


// - - Constants - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

const unsigned AC__MinLength = 0x01000000U;   // threshold for renormalization
const unsigned AC__MaxLength = 0xFFFFFFFFU;      // maximum AC interval length

const unsigned AC__LengthShift = 32;          // bit shift to scale the length 
const double   AC__ProbScaling = 1.0 + double(0xFFFFFFFFU);

                                  // Maximum symbol counts for adaptive models
const unsigned BM__MaxCount = 1 << 14;                       // for bit models
const unsigned DM__MaxCount = 1 << 17;                      // for data models


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - Static functions  - - - - - - - - - - - - - - - - - - - - - - - - - - -
                                   // upper 32-bit result of 32x32-bit product
inline unsigned Product_64(unsigned l, unsigned c)
{
  _asm {
    mov eax,l
    mul c
    mov eax,edx
  }
}                                              // return value in register EAX

                      // division of 64-bit (after scaling) by a 32-bit number
inline unsigned Division_64(unsigned dvh, unsigned dvr)
{
  _asm {
    xor eax,eax
    not eax
    mov edx,dvh
    div dvr
  }
}                                              // return value in register EAX

static void AC_Error(const char * msg)
{
  fprintf(stderr, "\n\n -> Arithmetic coding error: ");
  fputs(msg, stderr);
  fputs("\n Execution terminated!\n", stderr);
  exit(1);
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - Coding implementations  - - - - - - - - - - - - - - - - - - - - - - - -

inline void Arithmetic_Codec::propagate_carry(void)
{
  unsigned char * p;            // carry propagation on compressed data buffer
  for (p = ac_pointer - 1; *p == 0xFFU; p--) *p = 0;
  ++*p;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

inline void Arithmetic_Codec::renorm_enc_interval(void)
{
  do {                                          // output and discard top byte
    *ac_pointer++ = (unsigned char)(base >> 24);
    base <<= 8;
  } while ((length <<= 8) < AC__MinLength);        // length multiplied by 256
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

inline void Arithmetic_Codec::renorm_dec_interval(void)
{
  do {                                              // read least-signif. byte
    value = (value << 8) | unsigned(*++ac_pointer);
  } while ((length <<= 8) < AC__MinLength);        // length multiplied by 256
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

void Arithmetic_Codec::put_bit(unsigned bit)
{
#ifdef _DEBUG
  if (mode != 1) AC_Error("encoder not initialized");
#endif

  length >>= 1;                                              // halve interval
  if (bit) {
    unsigned init_base = base;
    base += length;                                               // move base
    if (init_base > base) propagate_carry();               // overflow = carry
  }

  if (length < AC__MinLength) renorm_enc_interval();        // renormalization
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

unsigned Arithmetic_Codec::get_bit(void)
{
#ifdef _DEBUG
  if (mode != 2) AC_Error("decoder not initialized");
#endif

  length >>= 1;                                              // halve interval
  unsigned bit = (value >= length);                              // decode bit
  if (bit) value -= length;                                       // move base

  if (length < AC__MinLength) renorm_dec_interval();        // renormalization

  return bit;                                         // return data bit value
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

void Arithmetic_Codec::put_bits(unsigned data, unsigned bits)
{
#ifdef _DEBUG
  if (mode != 1) AC_Error("encoder not initialized");
  if ((bits < 1) || (bits > 20)) AC_Error("invalid number of bits");
  if (data >= (1U << bits)) AC_Error("invalid data");
#endif

  unsigned init_base = base;
  base += data * (length >>= bits);            // new interval base and length

  if (init_base > base) propagate_carry();                 // overflow = carry
  if (length < AC__MinLength) renorm_enc_interval();        // renormalization
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

unsigned Arithmetic_Codec::get_bits(unsigned bits)
{
#ifdef _DEBUG
  if (mode != 2) AC_Error("decoder not initialized");
  if ((bits < 1) || (bits > 20)) AC_Error("invalid number of bits");
#endif

  unsigned s = value / (length >>= bits);      // decode symbol, change length

  value -= length * s;                                      // update interval
  if (length < AC__MinLength) renorm_dec_interval();        // renormalization

  return s;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

void Arithmetic_Codec::encode(unsigned bit,
                              Static_Bit_Model & M)
{
#ifdef _DEBUG
  if (mode != 1) AC_Error("encoder not initialized");
#endif

  unsigned x = Product_64(length, M.bit_0_prob);             // product l x p0
                                                            // update interval
  if (bit == 0)
    length  = x;
  else {
    unsigned init_base = base;
    base   += x;
    length -= x;
    if (init_base > base) propagate_carry();               // overflow = carry
  }

  if (length < AC__MinLength) renorm_enc_interval();        // renormalization
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

unsigned Arithmetic_Codec::decode(Static_Bit_Model & M)
{
#ifdef _DEBUG
  if (mode != 2) AC_Error("decoder not initialized");
#endif

  unsigned x = Product_64(length, M.bit_0_prob);             // product l x p0
  unsigned bit = (value >= x);                                     // decision
                                                    // update & shift interval
  if (bit == 0)
    length  = x;
  else {
    value  -= x;                                 // shifted interval base = 0
    length -= x;
  }

  if (length < AC__MinLength) renorm_dec_interval();        // renormalization

  return bit;                                         // return data bit value
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

void Arithmetic_Codec::encode(unsigned bit,
                              Adaptive_Bit_Model & M)
{
#ifdef _DEBUG
  if (mode != 1) AC_Error("encoder not initialized");
#endif

  unsigned x = Product_64(length, M.bit_0_prob);             // product l x p0
                                                            // update interval
  if (bit == 0) {
    length = x;
    ++M.bit_0_count;
  }
  else {
    unsigned init_base = base;
    base   += x;
    length -= x;
    if (init_base > base) propagate_carry();               // overflow = carry
  }

  if (length < AC__MinLength) renorm_enc_interval();        // renormalization

  if (--M.bits_until_update == 0) M.update();         // periodic model update
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

unsigned Arithmetic_Codec::decode(Adaptive_Bit_Model & M)
{
#ifdef _DEBUG
  if (mode != 2) AC_Error("decoder not initialized");
#endif

  unsigned x = Product_64(length, M.bit_0_prob);             // product l x p0
  unsigned bit = (value >= x);                                     // decision
                                                            // update interval
  if (bit == 0) {
    length = x;
    ++M.bit_0_count;
  }
  else {
    value  -= x;
    length -= x;
  }

  if (length < AC__MinLength) renorm_dec_interval();        // renormalization

  if (--M.bits_until_update == 0) M.update();         // periodic model update

  return bit;                                         // return data bit value
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

void Arithmetic_Codec::encode(unsigned data,
                              Static_Data_Model & M)
{
#ifdef _DEBUG
  if (mode != 1) AC_Error("encoder not initialized");
  if (data >= M.data_symbols) AC_Error("invalid data symbol");
#endif

  unsigned init_base = base;
  unsigned x = Product_64(length, M.distribution[data]);   // compute products
                                                          
  base  += x;                                               // update interval
  length = Product_64(length, M.distribution[data+1]) - x;

  if (init_base > base) propagate_carry();                 // overflow = carry

  if (length < AC__MinLength) renorm_enc_interval();        // renormalization
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

unsigned Arithmetic_Codec::decode(Static_Data_Model & M)
{
#ifdef _DEBUG
  if (mode != 2) AC_Error("decoder not initialized");
#endif

  unsigned n, s, x, y;

  if (M.decoder_table) {              // use table look-up for faster decoding

    unsigned dv = Division_64(value, length);
    unsigned t = dv >> M.table_shift;
  
    s = M.decoder_table[t];         // initial decision based on table look-up
    n = M.decoder_table[t+1] + 1;

    while (n > s + 1) {                        // finish with bisection search
      unsigned m = (s + n) >> 1;
      if (M.distribution[m] > dv) n = m; else s = m;
    }
                                                           // compute products
    x = Product_64(length, M.distribution[s]);
    y = Product_64(length, M.distribution[s+1]);
  }

  else {                                  // decode using only multiplications

    x = s = 0;
    y = length - 1;
    unsigned m = (n = M.data_symbols) >> 1;
                                                // decode via bisection search
    do {
      unsigned z = Product_64(length, M.distribution[m]);
      if (z > value) {
        n = m;
        y = z;                                             // value is smaller
      }
      else {
        s = m;
        x = z;                                     // value is larger or equal
      }
    } while ((m = (s + n) >> 1) != s);
  }

  value -= x;                                               // update interval
  length = y - x;

  if (length < AC__MinLength) renorm_dec_interval();        // renormalization

  return s;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

void Arithmetic_Codec::encode(unsigned data,
                              Adaptive_Data_Model & M)
{
#ifdef _DEBUG
  if (mode != 1) AC_Error("encoder not initialized");
  if (data >= M.data_symbols) AC_Error("invalid data symbol");
#endif

  unsigned init_base = base;
  unsigned x = Product_64(length, M.distribution[data]);   // compute products

  base  += x;                                               // update interval
  length = Product_64(length, M.distribution[data+1]) - x;

  if (init_base > base) propagate_carry();                 // overflow = carry

  if (length < AC__MinLength) renorm_enc_interval();        // renormalization

  ++M.symbol_count[data];
  if (--M.symbols_until_update == 0) M.update(true);  // periodic model update
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

unsigned Arithmetic_Codec::decode(Adaptive_Data_Model & M)
{
#ifdef _DEBUG
  if (mode != 2) AC_Error("decoder not initialized");
#endif

  unsigned n, s, x, y;

  if (M.decoder_table) {              // use table look-up for faster decoding

    unsigned dv = Division_64(value, length);
    unsigned t = dv >> M.table_shift;
  
    s = M.decoder_table[t];         // initial decision based on table look-up
    n = M.decoder_table[t+1] + 1;

    while (n > s + 1) {                        // finish with bisection search
      unsigned m = (s + n) >> 1;
      if (M.distribution[m] > dv) n = m; else s = m;
    }
                                                           // compute products
    x = Product_64(length, M.distribution[s]);
    y = Product_64(length, M.distribution[s+1]);
  }

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
免费在线观看一区二区三区| 99国产精品一区| 粗大黑人巨茎大战欧美成人| 在线观看精品一区| www成人在线观看| 亚洲一区二区视频| 成人午夜大片免费观看| 日韩免费高清av| 一区二区成人在线视频| 成人午夜电影久久影院| 精品成人一区二区三区| 午夜激情一区二区| 日本精品一区二区三区四区的功能| 日韩精品一区二区三区中文精品| 亚洲精品一二三| 成人久久18免费网站麻豆| 久久影院视频免费| 免费观看在线综合| 717成人午夜免费福利电影| 一片黄亚洲嫩模| 91免费视频观看| 国产精品久久免费看| 成人激情视频网站| 欧美国产精品久久| 国产成人超碰人人澡人人澡| 26uuu精品一区二区在线观看| 日精品一区二区三区| 欧美日韩精品系列| 日日摸夜夜添夜夜添国产精品 | 成人18精品视频| 国产精品免费视频一区| 成人不卡免费av| 亚洲天堂网中文字| 91麻豆免费观看| 一区二区在线观看免费视频播放| 成人激情黄色小说| 亚洲品质自拍视频网站| 在线视频一区二区三| 亚洲v日本v欧美v久久精品| 欧美日韩国产免费一区二区| 日韩av一区二区三区四区| 91麻豆精品久久久久蜜臀| 日本欧美肥老太交大片| 日韩精品一区二区三区在线| 国产一区二区三区免费| 国产精品美女久久久久久久| 色综合久久九月婷婷色综合| 亚洲国产日产av| 日韩一区二区免费高清| 九九国产精品视频| 日本一区二区在线不卡| 91蝌蚪porny九色| 日韩高清不卡一区| 国产日韩欧美激情| 91免费看片在线观看| 日韩黄色免费网站| 久久久99精品免费观看| 91女神在线视频| 蜜乳av一区二区三区| 国产日产欧美一区| 在线观看免费视频综合| 美国欧美日韩国产在线播放| 国产欧美日本一区二区三区| 色综合天天综合网国产成人综合天| 亚洲国产视频一区二区| 久久综合九色综合久久久精品综合| 99久久婷婷国产综合精品电影 | 一区二区三区日韩在线观看| 制服丝袜av成人在线看| 国产成人av电影在线观看| 亚洲精品日日夜夜| 精品国产第一区二区三区观看体验| 99精品视频在线免费观看| 麻豆精品一二三| 亚洲免费在线看| 久久久国产一区二区三区四区小说 | 婷婷中文字幕综合| 日本一区二区三级电影在线观看| 91国模大尺度私拍在线视频| 精品一区二区国语对白| 亚洲免费观看高清完整版在线| 日韩精品最新网址| 欧美无砖专区一中文字| 成人福利视频网站| 久草热8精品视频在线观看| 亚洲精品国产成人久久av盗摄 | 一卡二卡三卡日韩欧美| 国产拍欧美日韩视频二区| 3751色影院一区二区三区| 色哟哟亚洲精品| 国产成人一区在线| 精品午夜久久福利影院| 免费高清在线一区| 亚洲精选一二三| 国产精品网曝门| 精品国产百合女同互慰| 欧美一区二区三区四区视频| 99久久久国产精品免费蜜臀| 国产成人精品综合在线观看 | 天堂午夜影视日韩欧美一区二区| 亚洲日本一区二区| 国产精品色一区二区三区| 亚洲精品一区二区三区四区高清| 欧美日韩免费高清一区色橹橹| 北条麻妃一区二区三区| 国产精品1区2区| 国产成人av一区二区| 国产美女一区二区| 国模少妇一区二区三区| 极品美女销魂一区二区三区免费| 视频一区欧美精品| 男女男精品视频| 日韩av一区二区三区| 日本不卡视频在线观看| 日本免费新一区视频| 石原莉奈在线亚洲二区| 欧美aaa在线| 国产一区啦啦啦在线观看| 国产自产2019最新不卡| 国产麻豆视频一区二区| 国产 日韩 欧美大片| 国产福利精品一区| 成人av电影在线观看| 色综合久久88色综合天天6| 91豆麻精品91久久久久久| 欧美日韩成人在线一区| 欧美一区二区私人影院日本| 日韩精品在线一区| 久久久精品国产99久久精品芒果| 国产精品蜜臀av| 一区二区三区中文字幕精品精品| 亚洲h动漫在线| 蜜臀av国产精品久久久久| 国内欧美视频一区二区| voyeur盗摄精品| 欧美综合亚洲图片综合区| 欧美日韩国产a| 精品人在线二区三区| 国产日韩欧美激情| 亚洲午夜一区二区三区| 久久国产尿小便嘘嘘尿| 国产iv一区二区三区| 日本伦理一区二区| 精品国产电影一区二区| 《视频一区视频二区| 天涯成人国产亚洲精品一区av| 久久精品国产澳门| 99久久er热在这里只有精品66| 欧美探花视频资源| 久久日一线二线三线suv| 亚洲男女毛片无遮挡| 激情小说欧美图片| 色综合久久久久网| 26uuu国产一区二区三区| 自拍偷拍国产亚洲| 狠狠色丁香久久婷婷综合_中| 91尤物视频在线观看| 日韩欧美123| 亚洲一区二区在线免费看| 激情六月婷婷综合| 欧美日高清视频| 国产精品国产自产拍在线| 偷拍一区二区三区| 91小视频在线| 久久综合九色综合欧美就去吻 | caoporn国产一区二区| 日韩免费高清视频| 亚洲第一福利一区| av在线这里只有精品| 精品欧美一区二区三区精品久久| 亚洲综合区在线| 国产69精品一区二区亚洲孕妇| 欧美丰满美乳xxx高潮www| 中文字幕一区二区三区四区不卡| 久久99精品久久久久婷婷| 欧美视频第二页| 中文字幕在线不卡国产视频| 国内精品伊人久久久久av影院| 欧美日韩一二三| 亚洲日本免费电影| 成人中文字幕电影| 26uuu精品一区二区在线观看| 日韩av电影一区| 欧美老肥妇做.爰bbww| 一区二区三区产品免费精品久久75| 国产成人av自拍| 久久久久久9999| 精品一区二区三区免费视频| 欧美一区二区在线播放| 日韩av网站在线观看| 欧美猛男gaygay网站| 亚洲成人免费在线| 欧美午夜理伦三级在线观看| 一区二区三区中文字幕在线观看| 不卡的av电影| 中文字幕色av一区二区三区| caoporm超碰国产精品| 日韩理论片中文av| 色94色欧美sute亚洲线路一ni| 亚洲女人的天堂|