m2.enlarge-your-data/src/rle2/eydrle2_uncompress.cpp

64 lines
1.6 KiB
C++
Raw Normal View History

2005-10-30 23:23:23 +00:00
#include "eydrle.hh"
namespace EydTools {
void EydRle::uncompress(){
EydLib::BitGroup data;
EydLib::BitReader bitread(_cellsize, 256);
bitread.open(_input_file);
unsigned char c;
bitread.readDirect(&c, 1);
//TODO: fixer cell_size en fonction de "c";
if (c != _cellsize){
printf("WARNING : File cellsize is %d, but uncompressing with %d\n",c, _cellsize);
}
EydLib::BitWriter bitwrite(_cellsize,256);
bitwrite.open(_output_file);
EydLib::BitUncompressor uncompressor(_cellsize);
printf("File opened\n");
bool done=false;
std::vector<EydLib::BitGroup> record;
while(!done){
try{
data = bitread.read();
uncompressor.append(data);
if (uncompressor.hasContent()){
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 (EydLib::eBitReaderEndOfFile& e) {
done = true;
// on flushe le contenu de record
// 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");
}
}
printf("uncompression done\n");
bitread.close();
bitwrite.close();
printf("file closed\n");
}
}