m2.enlarge-your-data/src/tools/bitcompress.cpp
2005-10-29 23:24:52 +00:00

67 lines
1.4 KiB
C++

#include <stdio.h>
#include <stdlib.h>
#include <eyd.hh>
#include <exception>
#include <vector>
void usage(){
printf("usage : bitcopy <int> <file>\n");
}
int main(int argc, char ** argv){
EydLib::BitGroup data;
int cell_size;
std::string original;
std::string copy;
if (argc<2){ usage(); exit(-1); }
cell_size = atoi(argv[1]);
original = argv[2];
copy = original + ".rl1";
EydLib::BitReader bitread(cell_size, 256);
bitread.open(original);
EydLib::BitWriter bitwrite(cell_size,256);
bitwrite.open(copy);
unsigned char c = (unsigned char)cell_size;
bitwrite.writeDirect(&c, 1);
EydLib::BitCompressor compressor;
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;
// TODO: on flushe le contenu de record
compressor.flushRleData();
std::list<EydLib::BitGroup> compressedData = compressor.flush();
} catch (std::exception& e){
printf("ERROR\n");
}
}
printf("compression done\n");
bitread.close();
bitwrite.close();
printf("file closed\n");
}