diff --git a/src/Makefile.am b/src/Makefile.am index 5ffd94c..a77fef1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,2 +1,3 @@ -SUBDIRS = lib rle1 rle2 #rleGolomb +SUBDIRS = lib rle1 rle2 +#rleGolomb diff --git a/src/rle2/Makefile.am b/src/rle2/Makefile.am index 5dff133..17cdfaf 100644 --- a/src/rle2/Makefile.am +++ b/src/rle2/Makefile.am @@ -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 diff --git a/src/rle2/eydrle2.cpp b/src/rle2/eydrle2.cpp index e69de29..f6cebc6 100644 --- a/src/rle2/eydrle2.cpp +++ b/src/rle2/eydrle2.cpp @@ -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(); + } + } + +} + diff --git a/src/rle2/eydrle2_compress.cpp b/src/rle2/eydrle2_compress.cpp index e69de29..6b11cfd 100644 --- a/src/rle2/eydrle2_compress.cpp +++ b/src/rle2/eydrle2_compress.cpp @@ -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 record; + while(!done){ + try{ + data = bitread.read(); + compressor.append(data); + + if (compressor.hasContent()){ + std::list compressedData = compressor.flush(); + std::list::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 compressedData = compressor.flush(); + std::list::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"); + } +} diff --git a/src/rle2/eydrle2_init.cpp b/src/rle2/eydrle2_init.cpp index e69de29..fab3347 100644 --- a/src/rle2/eydrle2_init.cpp +++ b/src/rle2/eydrle2_init.cpp @@ -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 \n", argv[0]); + printf("\nWhere options could be:\n"); + printf("-m, --mode (c|u) Compress or uncompress\n"); + printf("-i, --input File to compress | uncompress\n"); + printf("-o, --output Destination file\n"); + printf("-c, --cellsize 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; + } + +} diff --git a/src/rle2/eydrle2_main.cpp b/src/rle2/eydrle2_main.cpp index e69de29..c91b7ef 100644 --- a/src/rle2/eydrle2_main.cpp +++ b/src/rle2/eydrle2_main.cpp @@ -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; +} diff --git a/src/rle2/eydrle2_uncompress.cpp b/src/rle2/eydrle2_uncompress.cpp index e69de29..cd73346 100644 --- a/src/rle2/eydrle2_uncompress.cpp +++ b/src/rle2/eydrle2_uncompress.cpp @@ -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 record; + while(!done){ + try{ + data = bitread.read(); + uncompressor.append(data); + + if (uncompressor.hasContent()){ + std::list uncompressedData = uncompressor.flush(); + std::list::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 uncompressedData = uncompressor.flush(); + std::list::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"); + } +} diff --git a/src/tests/exemple2.bmp b/src/tests/exemple2.bmp new file mode 100644 index 0000000..7cc3d1b Binary files /dev/null and b/src/tests/exemple2.bmp differ diff --git a/src/tests/exemple2.pcx b/src/tests/exemple2.pcx new file mode 100644 index 0000000..45a39e4 Binary files /dev/null and b/src/tests/exemple2.pcx differ diff --git a/src/tests/exemple2.ppm b/src/tests/exemple2.ppm new file mode 100644 index 0000000..53ea6ef Binary files /dev/null and b/src/tests/exemple2.ppm differ