diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index bc519d1..86b86b1 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -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@ \ diff --git a/src/lib/eyd_bitreader.cpp b/src/lib/eyd_bitreader.cpp index 3a8cc27..983fd96 100644 --- a/src/lib/eyd_bitreader.cpp +++ b/src/lib/eyd_bitreader.cpp @@ -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; diff --git a/src/lib/eyd_bitreader.hh b/src/lib/eyd_bitreader.hh index 745c82a..ca16db9 100644 --- a/src/lib/eyd_bitreader.hh +++ b/src/lib/eyd_bitreader.hh @@ -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(); }; } diff --git a/src/lib/eyd_bitwriter.cpp b/src/lib/eyd_bitwriter.cpp index 9784950..fceeb54 100644 --- a/src/lib/eyd_bitwriter.cpp +++ b/src/lib/eyd_bitwriter.cpp @@ -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 diff --git a/src/lib/eyd_bitwriter.hh b/src/lib/eyd_bitwriter.hh index 1fe920e..7d1e097 100644 --- a/src/lib/eyd_bitwriter.hh +++ b/src/lib/eyd_bitwriter.hh @@ -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(); }; diff --git a/src/lib/eyd_compressor.cpp b/src/lib/eyd_compressor.cpp new file mode 100644 index 0000000..2756367 --- /dev/null +++ b/src/lib/eyd_compressor.cpp @@ -0,0 +1,91 @@ + +#include "eyd_compressor.hh" + +namespace EydLib { + + /* + class BitCompressor { + private: + BitGroup _last_group; + int _last_count; + std::list _compressed; + + public: + BitCompressor(); + + void clear(); + void append(BitGroup bg); + std::list 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 BitCompressor::flush(){ + // we add the data from _last* to the outlist + std::list result; + result = _compressed; + _compressed.clear(); + return result; + } + + bool BitCompressor::hasContent(){ + return (!_compressed.empty()); + } +} + diff --git a/src/lib/eyd_compressor.hh b/src/lib/eyd_compressor.hh new file mode 100644 index 0000000..88a430c --- /dev/null +++ b/src/lib/eyd_compressor.hh @@ -0,0 +1,38 @@ +#ifndef _EYD_BITCOMPRESSOR_HH +#define _EYD_BITCOMPRESSOR_HH + +#include +#include +#include +#include +#include + +#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 _compressed; + + void flushRleData(); + void flushRawData(); + + public: + BitCompressor(); + + void clear(); + void append(BitGroup bg); + std::list flush(); + bool hasContent(); + }; +} + +#endif