This commit is contained in:
glenux 2005-10-29 22:51:22 +00:00
parent 3c3149cd5f
commit 6e6bebe89f
7 changed files with 143 additions and 2 deletions

View file

@ -6,9 +6,11 @@ lib_LTLIBRARIES = libeyd.la
libeyd_la_SOURCES = eyd_bitreader.cpp \
eyd_bitwriter.cpp \
eyd_bitgroup.cpp
eyd_bitgroup.cpp \
eyd_compressor.cpp
libeyd_la_CFLAGS = -DTRACE -static
libeyd_la_CFLAGS = -DTRACE
#-static
libeyd_la_LDFLAGS = -version-info 3:12:1
#INCLUDES= SQLITE3_CFLAGS@ \

View file

@ -60,6 +60,10 @@ namespace EydLib {
return reader;
}
ssize_t BitReader::readDirect(void *buf, size_t count){
return ::read(this->_file_desc, buf, count);
}
BitGroup BitReader::read(){
int i;
bool bitValue;

View file

@ -36,6 +36,7 @@ namespace EydLib {
void open(std::string filename);
/* BitGroup * BitReader::read(int size); */
BitGroup BitReader::read();
ssize_t readDirect(void *buf, size_t count);
void close();
};
}

View file

@ -33,6 +33,10 @@ namespace EydLib {
this->_ready = true;
}
ssize_t BitWriter::writeDirect(void *buf, size_t count){
return ::write(this->_file_desc, buf, count);
}
void BitWriter::setBitAt(int position, bool value){
// on attrappe la bonne case du tableau

View file

@ -35,6 +35,7 @@ namespace EydLib {
void init(int size);
void open(std::string filename);
void write(BitGroup data);
ssize_t writeDirect(void *buf, size_t count);
void flush();
void close();
};

View file

@ -0,0 +1,91 @@
#include "eyd_compressor.hh"
namespace EydLib {
/*
class BitCompressor {
private:
BitGroup _last_group;
int _last_count;
std::list<BitGroup> _compressed;
public:
BitCompressor();
void clear();
void append(BitGroup bg);
std::list<BitGroup> flush();
bool hasContent();
};
*/
BitCompressor::BitCompressor(){
}
void BitCompressor::clear(){
// we clear everything
_last_count = 0;
_compressed.clear();
}
void BitCompressor::flushRleData(){
BitGroup len;
_compressed.push_back(_rle);
len.setValue(_last_count);
_compressed.push_back(len);
_compressed.push_back(_last_group);
_last_count = 0;
}
void BitCompressor::flushRawData(){
int i;
for (i=0; i<_last_count; i++){
// FIXME: on duplique les RLE trouvés
_compressed.push_back(_last_group);
}
_last_count = 0;
}
void BitCompressor::append(BitGroup data){
// take the data and make it smaller...
if (_last_count > 0) {
// there are data in the compressor
if (data != _last_group){
// we have to empty the compressed list
if (_last_count < 4){
// not efficient
if ((_last_count > 1) && (_last_group == _rle)) {
// 1 RLE gives 2 RLE
// 2 RLE gives 4 RLE... let compress it...
this->flushRleData();
} else {
this->flushRawData();
}
} else {
// efficient ! lets compress it !
this->flushRleData();
}
} else {
// nothing to do... wait for another different data...
}
} else {
// it is the first bitgroup
}
_last_group = data;
_last_count++;
}
std::list<BitGroup> BitCompressor::flush(){
// we add the data from _last* to the outlist
std::list<BitGroup> result;
result = _compressed;
_compressed.clear();
return result;
}
bool BitCompressor::hasContent(){
return (!_compressed.empty());
}
}

38
src/lib/eyd_compressor.hh Normal file
View file

@ -0,0 +1,38 @@
#ifndef _EYD_BITCOMPRESSOR_HH
#define _EYD_BITCOMPRESSOR_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 BitCompressor {
private:
BitGroup _rle;
BitGroup _last_group;
int _last_count;
std::list<BitGroup> _compressed;
void flushRleData();
void flushRawData();
public:
BitCompressor();
void clear();
void append(BitGroup bg);
std::list<BitGroup> flush();
bool hasContent();
};
}
#endif