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

📄 ezw.h

📁 介绍小波的函数
💻 H
字号:


#ifndef EZW_H
#define EZW_H


struct EZWHDR {
        char hdr[4];                //'EZW1'
        unsigned int poffset;       //offset to coeffs vals
};

// [EZW] [positions bits] [coeffs]


class EZW      //3 wavelet level EZT compression
{
public:

        //compress gray spectra, unsigned char version 128 is 0
        unsigned int compress(unsigned char* dest, const unsigned char* sour, unsigned int w, unsigned int h);            //0 - ERR, size - OK
        unsigned int decompress(unsigned char* dest, unsigned char* sour, unsigned int w, unsigned int h);                //non-const sour due to RW pointers in private section

        //compress gray spectra, signed char version
        unsigned int compress(char* dest, const char* sour, unsigned int w, unsigned int h);                              //0 - ERR, size - OK
        unsigned int decompress(char* dest, char* sour, unsigned int w, unsigned int h);


private:
        unsigned char* positions;              //RW pointer to FWT coeffs position bits
        unsigned char* coeffs;                 //RW pointer to FWT coeffs
        unsigned int posnum, cffnum;           //number of bytes for [positions bits], [coeffs]
        unsigned char pbits, cffval;           //bits stream; 1/0 value from this stream

        unsigned char* psour;                  //sour EZT buffer pointer
        unsigned char* pdest;                  //dest EZT buffer pointer
        unsigned int width;                    //LL band width
        unsigned int height;                   //LL band height
        unsigned int width8;                   //3 FWT spectra stride


        inline bool checkBband(const unsigned char* b0, const unsigned char* b1) const;
        inline bool checkBband(const char* b0, const char* b1) const;

        inline void setbits(unsigned char i);
        inline void setcoeffs(unsigned char i);
        inline void setcoeffs(char i);
        inline unsigned char getbits();
        inline unsigned char getcoeffs();

        void mmxmemset(unsigned char* dest, unsigned int size, unsigned char c) const;                        //mmx set routine
        void mmxmemcpy(unsigned char* dest, const unsigned char* sour, unsigned int size) const;              //mmx copy routine

        void storeLband(const unsigned char* sour);                                                           //mmx store LL band sour -> pdest
        void storeHband(const unsigned char* a, const unsigned char* b, const unsigned char* c);              //store HH band
        void storeHband(const char* a, const char* b, const char* c);                                         //store HH band

        void readLband(unsigned char* dest);                                                                  //mmx read LL band psour -> dest
        void readHband(unsigned char* a, unsigned char* b, unsigned char* c);                                 //read HH band
        void readHband(char* a, char* b, char* c);                                                            //read HH band



};


/*
    unsigned (128 is zero) and signed FWT spec versions

  usage:
    EZW ezw;
     int size = ezw.compress(dest, sour, width, height);    //width,height original image
     size = ezw.decompress(dest, sour, width, height);      //compressed size = decompressed return size

*/




inline bool EZW::checkBband(const unsigned char* b0, const unsigned char* b1) const
{
        if (*b0 != 128)
                return true;
        else if (*(b0 + 1) != 128)
                return true;
        else if (*b1 != 128)
                return true;
        else if (*(b1 + 1) != 128)
                return true;
        else
                return false;
}
inline bool EZW::checkBband(const char* b0, const char* b1) const
{
        if (*b0 != 0)
                return true;
        else if (*(b0 + 1) != 0)
                return true;
        else if (*b1 != 0)
                return true;
        else if (*(b1 + 1) != 0)
                return true;
        else
                return false;
}

inline void EZW::setbits(unsigned char i)
{
        *positions |= (unsigned char)(i << (7 - pbits++));
        posnum++;

        if (pbits == 8) {
                *(++positions) = 0;
                pbits = 0;
        }
}
inline void EZW::setcoeffs(unsigned char i)
{
        *coeffs++ = i;
        cffnum++;
}
inline void EZW::setcoeffs(char i)
{
        *coeffs++ = (unsigned char)i;
        cffnum++;
}
inline unsigned char EZW::getbits()
{
        cffval = *positions & (1 << (7 - pbits++));

        if (pbits == 8) {
                *positions++;
                pbits = 0;
        }

        return cffval;
}

inline unsigned char EZW::getcoeffs()
{
        return *coeffs++;
}



#endif

⌨️ 快捷键说明

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