|
#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
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Highly skilled Engineer with 14 years of experience in academia, R&D and commercial product development supporting full software life-cycle from idea to implementation and further support. During my academic career I was able to succeed in MIT Computers in Cardiology 2006 international challenge, as a R&D and SW engineer gain CodeProject MVP, find algorithmic solutions to quickly resolve tough customer problems to pass product requirements in tight deadlines. My key areas of expertise involve Object-Oriented
Analysis and Design OOAD, OOP, machine learning, natural language processing, face recognition, computer vision and image processing, wavelet analysis, digital signal processing in cardiology.