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

📄 aricoder.h

📁 this is source code for image compression following jpeg2000 staandard
💻 H
字号:
/*---------------------------------------------------------------------------*/
// Image Compression Toolbox v1.2
// written by
// Satish Kumar S
// satishkumr@lycos.com
//
// Copyright 1999 Satish Kumar S
//
// Permission is granted to use this software for research purposes as
// long as this notice stays attached to this software.
/*---------------------------------------------------------------------------*/
#ifndef _ARICODER_H
#define _ARICODER_H

#define onelog2     1.4426950408889634

//--------- Bitstream part.
class BitStream
{
private:
    unsigned char buf;
    int nBits;
    FILE *fp;
public:
    int  numBitsWritten;
    int  numBitsRead;
    BitStream(FILE *givenfp);
    ~BitStream();
    void WriteBit(unsigned int bit);
    void WriteBits(unsigned int bits,int n);
    void Flush();
    unsigned int ReadBit();
    unsigned int ReadBits(int n);
};

//-------- Arithmetic Encoder & Decoder part.

#define CodeValueBits   16		                // Number of bits in a code value

#define TopValue (((long)1<<CodeValueBits)-1)   // Largest code value

#define FirstQtr  (TopValue/4+1)	// Point after first quarter
#define Half	  (2*FirstQtr)		// Point after first half
#define ThirdQtr  (3*FirstQtr)		// Point after third quarter
#define MaxAllowedFreq  16383       // 2^14-1

class AdaptiveModel
{
    unsigned int *Tree;         // the cumulative freq tree.
    unsigned int numSyms;       // number of alphabets.
public:
    unsigned int totfreq;

    AdaptiveModel();
    ~AdaptiveModel();
    int SetNumSyms(int n);
    void Scaledown();
    int GetCumul(int Ix);
    int GetIndex(unsigned int Freq);
    void PutValue(int Val, int Ix);
    int GetFreq(int Ix);
};

class ArithEncoder
{
    unsigned int High, Low;
    unsigned int folw;      // 'follow with' counter.

    BitStream *bs;
public:
    AdaptiveModel SrcModel;

    ArithEncoder(BitStream *bitstream);
    ~ArithEncoder();
    int  SetNumSyms(int n);
    void InitEncode();
    unsigned int Encode(unsigned int symbol,int update=1);
    void Flush();
    inline void WriteBitPlusFollow(int bit)
    {
        bs->WriteBit(bit);
        bit = 1-bit;
        while(folw)
        {
            bs->WriteBit(bit);
            folw--;
        }
    }
    double EncodingCost(unsigned int symbol);
};

class ArithDecoder
{
    unsigned int High, Low;
    unsigned int folw;      // 'follow with' counter.
    unsigned int Value;         // value.

    AdaptiveModel SrcModel;
    BitStream *bs;
public:
    ArithDecoder(BitStream *bitstream);
    ~ArithDecoder();
    int  SetNumSyms(int n);
    void InitDecode();
    unsigned int Decode();
};

#endif

⌨️ 快捷键说明

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