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

57 lines
1.5 KiB
C++
Raw Normal View History

2005-10-31 07:34:44 +00:00
#include "eydrle2.hh"
2005-10-30 23:23:23 +00:00
namespace EydTools {
2005-10-31 07:34:44 +00:00
void EydRle2::compress(){
2005-10-30 23:23:23 +00:00
EydLib::BitGroup data;
2005-10-31 17:54:08 +00:00
EydLib::BitReader bitread(_cellsize, 256); // on lit bit <20> bit expres
2005-10-30 23:23:23 +00:00
bitread.open(_input_file);
2005-10-31 17:54:08 +00:00
EydLib::BitWriter bitwrite(_cellsize,256);
2005-10-30 23:23:23 +00:00
bitwrite.open(_output_file);
unsigned char c = (unsigned char)_cellsize;
bitwrite.writeDirect(&c, 1);
2005-10-31 17:54:08 +00:00
EydLib::BitCompressorRle2 compressor(_cellsize);
2005-10-30 23:23:23 +00:00
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
2005-10-31 17:54:08 +00:00
compressor.forceFlush();
2005-10-30 23:23:23 +00:00
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
}
}
}
printf("compression done\n");
bitread.close();
bitwrite.close();
printf("file closed\n");
2005-10-31 17:54:08 +00:00
printf("Compression ratio : %f\n", compressor.getRatio());
2005-10-30 23:23:23 +00:00
}
}