This commit is contained in:
glenux 2005-10-31 07:35:01 +00:00
parent aacad4200d
commit dac71a8592
4 changed files with 231 additions and 0 deletions

View file

@ -0,0 +1,58 @@
#include "eyd_compressor_rle2.hh"
namespace EydLib {
/*
class BitCompressorRle2 {
private:
BitGroup _last_group;
int _last_count;
std::list<BitGroup> _compressed;
public:
BitCompressorRle2();
void clear();
void append(BitGroup bg);
std::list<BitGroup> flush();
bool hasContent();
};
*/
BitCompressorRle2::BitCompressorRle2() {
_last_count = 0;
_compressed.clear();
}
void BitCompressorRle2::clear(){
// we clear everything
_last_count = 0;
_compressed.clear();
}
void BitCompressorRle2::appendBit(bool bit){
}
void BitCompressorRle2::append(BitGroup data){
// take the data and make it smaller...
// foreach bit of data, append it...
for (int i=0; i<data.size(); i++){
this->appendBit(data.getBitAt(i));
}
}
std::list<BitGroup> BitCompressorRle2::flush(){
// we add the data from _last* to the outlist
std::list<BitGroup> result;
result = _compressed;
_compressed.clear();
return result;
}
bool BitCompressorRle2::hasContent(){
return (!_compressed.empty());
}
}

View file

@ -0,0 +1,42 @@
#ifndef _EYD_BITCOMPRESSOR_RLE2_HH
#define _EYD_BITCOMPRESSOR_RLE2_HH
#include <string>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <exception>
#include "eyd_bitgroup.hh"
#include "eyd_global.hh"
#include "eyd_iface.hh"
namespace EydLib {
class BitCompressorRle2 {
private:
BitGroup _rle;
BitGroup _last_group;
int _last_count;
int _group_size;
std::list<BitGroup> _compressed;
void BitCompressorRle2::appendBit(bool bit);
public:
BitCompressorRle2::BitCompressorRle2();
void clear();
void append(BitGroup bg);
std::list<BitGroup> flush();
bool hasContent();
void flushRleData();
void flushRawData();
};
}
#endif

View file

@ -0,0 +1,86 @@
#include "eyd_uncompressor_rle2.hh"
namespace EydLib {
/*
class BitUncompressorRle2 {
private:
BitGroup _last_group;
int _last_count;
std::list<BitGroup> _uncompressed;
public:
BitUncompressorRle2();
void clear();
void append(BitGroup bg);
std::list<BitGroup> flush();
bool hasContent();
};
*/
BitUncompressorRle2::BitUncompressorRle2() {
_last_count = 0;
_status = UNCOMPRESSOR_RLE2_STATUS_NORMAL;
}
void BitUncompressorRle2::clear(){
// we clear everything
_last_count = 0;
_uncompressed.clear();
}
void BitUncompressorRle2::append(BitGroup data){
switch (_status){
case UNCOMPRESSOR_RLE2_STATUS_NORMAL:
printf("STATUS NORMAL : %s\n", data.toString().c_str());
if (data == _rle){
// on change le status et on n'écrit rien
_status = UNCOMPRESSOR_RLE2_STATUS_GOTRLE;
} else {
// on écrit directement le resultat non décompressé
_uncompressed.push_back(data);
}
break;
case UNCOMPRESSOR_RLE2_STATUS_GOTRLE:
printf("STATUS GOT RLE : %s\n", data.toString().c_str() );
if (data == _rle){
// deux RLE c'est 1 RLE
// on écrit juste un RLE
_uncompressed.push_back(data);
_status = UNCOMPRESSOR_RLE2_STATUS_NORMAL;
} else {
// un RLE et un différent c'est une longueur
// sauf si égal à 1 ou 2
_status = UNCOMPRESSOR_RLE2_STATUS_GOTLEN; // sauf si égal à RLE
_last_count = data.getValue(); // on stocke la value
}
break;
case UNCOMPRESSOR_RLE2_STATUS_GOTLEN:
printf("STATUS GOT LEN : %s\n", data.toString().c_str() );
// ce qu'on lit est la valeur
// on écrit donc _last_count fois data
for (int i=0; i<_last_count; i++){
_uncompressed.push_back(data);
}
_status = UNCOMPRESSOR_RLE2_STATUS_NORMAL;
_last_count = 0;
break;
}
}
std::list<BitGroup> BitUncompressorRle2::flush(){
// we add the data from _last* to the outlist
std::list<BitGroup> result;
result = _uncompressed;
_uncompressed.clear();
return result;
}
bool BitUncompressorRle2::hasContent(){
return (!_uncompressed.empty());
}
}

View file

@ -0,0 +1,45 @@
#ifndef _EYD_BITUNCOMPRESSOR_RLE2_HH
#define _EYD_BITUNCOMPRESSOR_RLE2_HH
#include <string>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <exception>
#include "eyd_bitgroup.hh"
#include "eyd_global.hh"
#include "eyd_iface.hh"
namespace EydLib {
typedef enum {
UNCOMPRESSOR_RLE2_STATUS_NORMAL,
UNCOMPRESSOR_RLE2_STATUS_GOTLEN,
UNCOMPRESSOR_RLE2_STATUS_GOTRLE}
uncompressorRle2_status_t;
class BitUncompressorRle2 {
private:
BitGroup _rle;
int _last_count;
int _group_size;
std::list<BitGroup> _uncompressed;
uncompressorRle2_status_t _status;
public:
BitUncompressorRle2::BitUncompressorRle2();
void clear();
void append(BitGroup bg);
std::list<BitGroup> flush();
bool hasContent();
void flushRleData();
void flushRawData();
};
}
#endif