m2.enlarge-your-data/src/tools/bitcompress.cpp

68 lines
1.4 KiB
C++
Raw Normal View History

2005-10-29 22:52:01 +00:00
#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){
2005-10-29 23:24:52 +00:00
EydLib::BitGroup data;
2005-10-29 22:52:01 +00:00
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);
2005-10-29 23:24:52 +00:00
EydLib::BitCompressor compressor;
2005-10-29 22:52:01 +00:00
printf("File opened\n");
bool done=false;
std::vector<EydLib::BitGroup> record;
while(!done){
try{
2005-10-29 23:24:52 +00:00
data = bitread.read();
compressor.append(data);
2005-10-29 22:52:01 +00:00
2005-10-29 23:24:52 +00:00
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
2005-10-29 22:52:01 +00:00
}
}
} catch (EydLib::eBitReaderEndOfFile& e) {
done = true;
// TODO: on flushe le contenu de record
2005-10-29 23:24:52 +00:00
compressor.flushRleData();
std::list<EydLib::BitGroup> compressedData = compressor.flush();
2005-10-29 22:52:01 +00:00
} catch (std::exception& e){
printf("ERROR\n");
}
}
printf("compression done\n");
bitread.close();
bitwrite.close();
printf("file closed\n");
}