This commit is contained in:
parent
6459a49010
commit
63b23d605b
10 changed files with 233 additions and 6 deletions
|
@ -1,2 +1,3 @@
|
|||
SUBDIRS = lib rle1 rle2 #rleGolomb
|
||||
SUBDIRS = lib rle1 rle2
|
||||
#rleGolomb
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
SUBDIRS = .
|
||||
|
||||
bin_PROGRAMS = eydrle
|
||||
bin_PROGRAMS = eydrle2
|
||||
|
||||
#eyd_SOURCES += parser.hh \
|
||||
# source_lexer.hh
|
||||
|
@ -18,10 +18,10 @@ INCLUDES= -I../lib/ -I./ @GLIB2_CFLAGS@ @TARGET_READLINE_INC@
|
|||
#eyd_INCLUDE =
|
||||
|
||||
|
||||
eydrle_SOURCES = eydrle.cpp eydrle_init.cpp eydrle_main.cpp eydrle_compress.cpp eydrle_uncompress.cpp
|
||||
eydrle_SOURCES += eydrle.hh
|
||||
eydrle_LDADD = -leyd
|
||||
eydrle_LDFLAGS = @LDFLAGS@ -L../lib -L../lib/.libs
|
||||
eydrle2_SOURCES = eydrle2.cpp eydrle2_init.cpp eydrle2_main.cpp eydrle2_compress.cpp eydrle2_uncompress.cpp
|
||||
eydrle2_SOURCES += eydrle2.hh
|
||||
eydrle2_LDADD = -leyd
|
||||
eydrle2_LDFLAGS = @LDFLAGS@ -L../lib -L../lib/.libs
|
||||
|
||||
#bitcopy_SOURCES = bitcopy.cpp
|
||||
#bitcopy_LDADD = -leyd
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
#include "eydrle.hh"
|
||||
|
||||
namespace EydTools {
|
||||
EydRle::EydRle(){
|
||||
_mode_compress = EYDRLE_MODE_UNDEF;
|
||||
_input_file.clear();
|
||||
_output_file.clear();
|
||||
_cellsize = 8; // one octet each time (by default);
|
||||
}
|
||||
|
||||
void EydRle::run(){
|
||||
if (_mode_compress == EYDRLE_MODE_COMPRESS){
|
||||
this->compress();
|
||||
} else {
|
||||
this->uncompress();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
#include "eydrle.hh"
|
||||
|
||||
namespace EydTools {
|
||||
void EydRle::compress(){
|
||||
EydLib::BitGroup data;
|
||||
|
||||
EydLib::BitReader bitread(_cellsize, 256);
|
||||
bitread.open(_input_file);
|
||||
|
||||
EydLib::BitWriter bitwrite(_cellsize,256);
|
||||
bitwrite.open(_output_file);
|
||||
unsigned char c = (unsigned char)_cellsize;
|
||||
bitwrite.writeDirect(&c, 1);
|
||||
|
||||
EydLib::BitCompressor compressor(_cellsize);
|
||||
|
||||
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
|
||||
compressor.flushRleData();
|
||||
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 (std::exception& e){
|
||||
printf("ERROR\n");
|
||||
}
|
||||
}
|
||||
printf("compression done\n");
|
||||
|
||||
bitread.close();
|
||||
bitwrite.close();
|
||||
|
||||
printf("file closed\n");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
#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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
#include "eydrle.hh"
|
||||
|
||||
using namespace std;
|
||||
using namespace EydTools;
|
||||
|
||||
int main(int argc, char **argv){
|
||||
bool ready;
|
||||
EydRle eydrle;
|
||||
ready = eydrle.init(argc, argv);
|
||||
if (ready) {
|
||||
eydrle.run();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
#include "eydrle.hh"
|
||||
|
||||
namespace EydTools {
|
||||
void EydRle::uncompress(){
|
||||
EydLib::BitGroup data;
|
||||
|
||||
EydLib::BitReader bitread(_cellsize, 256);
|
||||
bitread.open(_input_file);
|
||||
|
||||
unsigned char c;
|
||||
bitread.readDirect(&c, 1);
|
||||
//TODO: fixer cell_size en fonction de "c";
|
||||
|
||||
if (c != _cellsize){
|
||||
printf("WARNING : File cellsize is %d, but uncompressing with %d\n",c, _cellsize);
|
||||
}
|
||||
|
||||
EydLib::BitWriter bitwrite(_cellsize,256);
|
||||
bitwrite.open(_output_file);
|
||||
|
||||
EydLib::BitUncompressor uncompressor(_cellsize);
|
||||
|
||||
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
|
||||
// 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");
|
||||
}
|
||||
}
|
BIN
src/tests/exemple2.bmp
Normal file
BIN
src/tests/exemple2.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.9 KiB |
BIN
src/tests/exemple2.pcx
Normal file
BIN
src/tests/exemple2.pcx
Normal file
Binary file not shown.
BIN
src/tests/exemple2.ppm
Normal file
BIN
src/tests/exemple2.ppm
Normal file
Binary file not shown.
Loading…
Reference in a new issue