This commit is contained in:
parent
35180f6379
commit
aceaba7f24
4 changed files with 64 additions and 68 deletions
|
@ -23,6 +23,7 @@ namespace EydLib {
|
|||
BitUncompressor::BitUncompressor(int size) : _rle(size) {
|
||||
_group_size = size;
|
||||
_last_count = 0;
|
||||
_status = UNCOMPRESSOR_STATUS_NORMAL;
|
||||
}
|
||||
|
||||
void BitUncompressor::clear(){
|
||||
|
@ -31,60 +32,44 @@ namespace EydLib {
|
|||
_uncompressed.clear();
|
||||
}
|
||||
|
||||
void BitUncompressor::flushRleData(){
|
||||
BitGroup len(_group_size);
|
||||
_uncompressed.push_back(_rle);
|
||||
printf("Last count %d\n", _last_count);
|
||||
printf("Max cellsize %d\n", len.maxValue());
|
||||
len.setValue(_last_count);
|
||||
_uncompressed.push_back(len);
|
||||
_uncompressed.push_back(_last_group);
|
||||
_last_count = 0;
|
||||
}
|
||||
|
||||
void BitUncompressor::flushRawData(){
|
||||
int i;
|
||||
for (i=0; i<_last_count; i++){
|
||||
// on duplique les RLE trouvés
|
||||
if (_last_group == _rle) {
|
||||
_uncompressed.push_back(_last_group);
|
||||
}
|
||||
_uncompressed.push_back(_last_group);
|
||||
}
|
||||
_last_count = 0;
|
||||
}
|
||||
|
||||
void BitUncompressor::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();
|
||||
switch (_status){
|
||||
case UNCOMPRESSOR_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_STATUS_GOTRLE;
|
||||
} else {
|
||||
this->flushRawData();
|
||||
// on écrit directement le resultat non décompressé
|
||||
_uncompressed.push_back(data);
|
||||
}
|
||||
break;
|
||||
case UNCOMPRESSOR_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_STATUS_NORMAL;
|
||||
} else {
|
||||
// efficient ! lets compress it !
|
||||
this->flushRleData();
|
||||
// un RLE et un différent c'est une longueur
|
||||
// sauf si égal à 1 ou 2
|
||||
_status = UNCOMPRESSOR_STATUS_GOTLEN; // sauf si égal à RLE
|
||||
_last_count = data.getValue(); // on stocke la value
|
||||
}
|
||||
} else {
|
||||
// nothing to do... wait for another different data...
|
||||
// maybe the count is bigger than the len-cell can store ?
|
||||
if (_last_count >= _rle.maxValue()){
|
||||
this->flushRleData();
|
||||
break;
|
||||
case UNCOMPRESSOR_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_STATUS_NORMAL;
|
||||
_last_count = 0;
|
||||
break;
|
||||
|
||||
}
|
||||
} else {
|
||||
// it is the first bitgroup
|
||||
}
|
||||
_last_group = data;
|
||||
_last_count++;
|
||||
}
|
||||
|
||||
std::list<BitGroup> BitUncompressor::flush(){
|
||||
|
|
|
@ -14,15 +14,15 @@
|
|||
|
||||
|
||||
namespace EydLib {
|
||||
typedef enum {UNCOMPRESSOR_STATUS_NORMAL, UNCOMPRESSOR_STATUS_GOTLEN, UNCOMPRESSOR_STATUS_GOTRLE} uncompressor_status_t;
|
||||
|
||||
class BitUncompressor {
|
||||
private:
|
||||
BitGroup _rle;
|
||||
BitGroup _last_group;
|
||||
int _last_count;
|
||||
int _group_size;
|
||||
std::list<BitGroup> _uncompressed;
|
||||
|
||||
uncompressor_status_t _status;
|
||||
|
||||
public:
|
||||
BitUncompressor::BitUncompressor(int size);
|
||||
|
|
|
@ -53,7 +53,12 @@ int main(int argc, char ** argv){
|
|||
// TODO: on flushe le contenu de record
|
||||
compressor.flushRleData();
|
||||
std::list<EydLib::BitGroup> compressedData = compressor.flush();
|
||||
|
||||
std::list<EydLib::BitGroup>::iterator cmpDataIt;
|
||||
for(cmpDataIt = compressedData.begin();
|
||||
cmpDataIt != compressedData.end();
|
||||
cmpDataIt++){
|
||||
bitwrite.write((*cmpDataIt)); // cellule
|
||||
}
|
||||
} catch (std::exception& e){
|
||||
printf("ERROR\n");
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ int main(int argc, char ** argv){
|
|||
cell_size = atoi(argv[1]);
|
||||
original = argv[2];
|
||||
|
||||
copy = original + ".rl1";
|
||||
copy = original + ".rl2";
|
||||
|
||||
EydLib::BitReader bitread(cell_size, 256);
|
||||
bitread.open(original);
|
||||
|
@ -53,9 +53,15 @@ int main(int argc, char ** argv){
|
|||
} catch (EydLib::eBitReaderEndOfFile& e) {
|
||||
done = true;
|
||||
// on flushe le contenu de record
|
||||
uncompressor.flushRleData();
|
||||
// FIXME: trouver un moyen de flusher la fin du fichier
|
||||
// uncompressor.flushRleData();
|
||||
std::list<EydLib::BitGroup> uncompressedData = uncompressor.flush();
|
||||
|
||||
std::list<EydLib::BitGroup>::iterator uncmpDataIt;
|
||||
for(uncmpDataIt = uncompressedData.begin();
|
||||
uncmpDataIt != uncompressedData.end();
|
||||
uncmpDataIt++){
|
||||
bitwrite.write((*uncmpDataIt)); // cellule
|
||||
}
|
||||
} catch (std::exception& e){
|
||||
printf("ERROR\n");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue