72 lines
1.7 KiB
C++
72 lines
1.7 KiB
C++
#include "eydrle.hh"
|
|
|
|
namespace EydTools {
|
|
|
|
bool EydRle::init(int argc, char ** argv){
|
|
_mode_compress = EYDRLE_MODE_UNDEF;
|
|
|
|
int i;
|
|
for (i = 1; i + 1 < argc; i = i + 2){
|
|
char * opt = argv[i]; //GOOD
|
|
char * val = argv[i+1]; //GOOD
|
|
if ( (strcmp(opt, "--mode") == 0) || (strcmp(opt,"-m") == 0) ){
|
|
switch(val[0]){
|
|
case 'c':
|
|
case 'C':
|
|
_mode_compress = EYDRLE_MODE_COMPRESS;
|
|
break;
|
|
case 'u':
|
|
case 'U':
|
|
_mode_compress = EYDRLE_MODE_UNCOMPRESS;
|
|
break;
|
|
default:
|
|
_mode_compress = EYDRLE_MODE_UNDEF;
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
|
|
if ( (strcmp(opt, "--input") == 0) || (strcmp(opt,"-i") == 0) ){
|
|
_input_file = val;
|
|
}
|
|
|
|
if ( (strcmp(opt, "--output") == 0) || (strcmp(opt,"-o") == 0) ){
|
|
_output_file = val;
|
|
}
|
|
|
|
if ( (strcmp(opt, "--cellsize") == 0) || (strcmp(opt,"-c") == 0) ){
|
|
_cellsize = atoi(val);
|
|
}
|
|
|
|
// printf("Option = %s, ",argv[i]);
|
|
// printf("value = %s\n",argv[i+1]);
|
|
}
|
|
|
|
if ((_mode_compress == EYDRLE_MODE_UNDEF) ||
|
|
(_input_file.length() == 0)) {
|
|
printf("\nUsage: %s <options>\n", argv[0]);
|
|
printf("\nWhere options could be:\n");
|
|
printf("-m, --mode (c|u) Compress or uncompress\n");
|
|
printf("-i, --input <file> File to compress | uncompress\n");
|
|
printf("-o, --output <file> Destination file\n");
|
|
printf("-c, --cellsize <file> Cell size (in bits)\n");
|
|
return false;
|
|
}
|
|
|
|
if (_output_file.length() == 0){
|
|
if (_mode_compress == EYDRLE_MODE_COMPRESS){
|
|
_output_file = _input_file + ".rl1";
|
|
} else {
|
|
_output_file = _input_file + ".rl1_orig";
|
|
}
|
|
}
|
|
|
|
// setting rle
|
|
EydLib::BitGroup rleFinal(_cellsize);
|
|
_rle = rleFinal;
|
|
|
|
return true;
|
|
}
|
|
|
|
}
|