m2.enlarge-your-data/src/rle2/eydrle2_compress.cpp
2005-10-30 23:23:23 +00:00

58 lines
1.4 KiB
C++

#include "eydrle.hh"
namespace EydTools {
void EydRle::compress(){
EydLib::BitGroup data;
EydLib::BitReader bitread(_cellsize, 256);
bitread.open(_input_file);
EydLib::BitWriter bitwrite(_cellsize,256);
bitwrite.open(_output_file);
unsigned char c = (unsigned char)_cellsize;
bitwrite.writeDirect(&c, 1);
EydLib::BitCompressor compressor(_cellsize);
printf("File opened\n");
bool done=false;
std::vector<EydLib::BitGroup> record;
while(!done){
try{
data = bitread.read();
compressor.append(data);
if (compressor.hasContent()){
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 (EydLib::eBitReaderEndOfFile& e) {
done = true;
// 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");
}
}
printf("compression done\n");
bitread.close();
bitwrite.close();
printf("file closed\n");
}
}