76 lines
1.8 KiB
C++
76 lines
1.8 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 + ".rl2";
|
|
|
|
EydLib::BitReader bitread(cell_size, 256);
|
|
bitread.open(original);
|
|
|
|
unsigned char c;
|
|
bitread.readDirect(&c, 1);
|
|
//TODO: fixer cell_size en fonction de "c";
|
|
|
|
EydLib::BitWriter bitwrite(cell_size,256);
|
|
bitwrite.open(copy);
|
|
|
|
EydLib::BitUncompressor uncompressor(cell_size);
|
|
|
|
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
|
|
// FIXME: trouver un moyen de flusher la fin du fichier
|
|
// 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");
|
|
}
|