87 lines
2.1 KiB
C++
87 lines
2.1 KiB
C++
|
|
#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());
|
|
}
|
|
}
|
|
|