This commit is contained in:
glenux 2005-10-30 23:34:21 +00:00
parent 4432a41a53
commit 869eac01a9
8 changed files with 64 additions and 33 deletions

View file

@ -7,8 +7,8 @@ lib_LTLIBRARIES = libeyd.la
libeyd_la_SOURCES = eyd_bitreader.cpp \ libeyd_la_SOURCES = eyd_bitreader.cpp \
eyd_bitwriter.cpp \ eyd_bitwriter.cpp \
eyd_bitgroup.cpp \ eyd_bitgroup.cpp \
eyd_compressor.cpp \ eyd_compressor_rle1.cpp \
eyd_uncompressor.cpp eyd_uncompressor_rle1.cpp
libeyd_la_CFLAGS = -DTRACE libeyd_la_CFLAGS = -DTRACE
#-static #-static

View file

@ -11,8 +11,8 @@
#include "eyd_bitgroup.hh" #include "eyd_bitgroup.hh"
#include "eyd_bitreader.hh" #include "eyd_bitreader.hh"
#include "eyd_bitwriter.hh" #include "eyd_bitwriter.hh"
#include "eyd_compressor.hh" #include "eyd_compressor_rle1.hh"
#include "eyd_uncompressor.hh" #include "eyd_uncompressor_rle1.hh"
#endif #endif

View file

@ -12,7 +12,7 @@ namespace EydTools {
unsigned char c = (unsigned char)_cellsize; unsigned char c = (unsigned char)_cellsize;
bitwrite.writeDirect(&c, 1); bitwrite.writeDirect(&c, 1);
EydLib::BitCompressor compressor(_cellsize); EydLib::BitCompressorRle1 compressorRle1(_cellsize);
printf("File opened\n"); printf("File opened\n");
@ -21,10 +21,10 @@ namespace EydTools {
while(!done){ while(!done){
try{ try{
data = bitread.read(); data = bitread.read();
compressor.append(data); compressorRle1.append(data);
if (compressor.hasContent()){ if (compressorRle1.hasContent()){
std::list<EydLib::BitGroup> compressedData = compressor.flush(); std::list<EydLib::BitGroup> compressedData = compressorRle1.flush();
std::list<EydLib::BitGroup>::iterator cmpDataIt; std::list<EydLib::BitGroup>::iterator cmpDataIt;
for(cmpDataIt = compressedData.begin(); for(cmpDataIt = compressedData.begin();
cmpDataIt != compressedData.end(); cmpDataIt != compressedData.end();
@ -35,8 +35,8 @@ namespace EydTools {
} catch (EydLib::eBitReaderEndOfFile& e) { } catch (EydLib::eBitReaderEndOfFile& e) {
done = true; done = true;
// on flushe le contenu de record // on flushe le contenu de record
compressor.flushRleData(); compressorRle1.flushRleData();
std::list<EydLib::BitGroup> compressedData = compressor.flush(); std::list<EydLib::BitGroup> compressedData = compressorRle1.flush();
std::list<EydLib::BitGroup>::iterator cmpDataIt; std::list<EydLib::BitGroup>::iterator cmpDataIt;
for(cmpDataIt = compressedData.begin(); for(cmpDataIt = compressedData.begin();
cmpDataIt != compressedData.end(); cmpDataIt != compressedData.end();

View file

@ -18,7 +18,7 @@ namespace EydTools {
EydLib::BitWriter bitwrite(_cellsize,256); EydLib::BitWriter bitwrite(_cellsize,256);
bitwrite.open(_output_file); bitwrite.open(_output_file);
EydLib::BitUncompressor uncompressor(_cellsize); EydLib::BitUncompressorRle1 uncompressorRle1(_cellsize);
printf("File opened\n"); printf("File opened\n");
@ -27,10 +27,10 @@ namespace EydTools {
while(!done){ while(!done){
try{ try{
data = bitread.read(); data = bitread.read();
uncompressor.append(data); uncompressorRle1.append(data);
if (uncompressor.hasContent()){ if (uncompressorRle1.hasContent()){
std::list<EydLib::BitGroup> uncompressedData = uncompressor.flush(); std::list<EydLib::BitGroup> uncompressedData = uncompressorRle1.flush();
std::list<EydLib::BitGroup>::iterator uncmpDataIt; std::list<EydLib::BitGroup>::iterator uncmpDataIt;
for(uncmpDataIt = uncompressedData.begin(); for(uncmpDataIt = uncompressedData.begin();
uncmpDataIt != uncompressedData.end(); uncmpDataIt != uncompressedData.end();
@ -41,8 +41,8 @@ namespace EydTools {
} catch (EydLib::eBitReaderEndOfFile& e) { } catch (EydLib::eBitReaderEndOfFile& e) {
done = true; done = true;
// on flushe le contenu de record // on flushe le contenu de record
// uncompressor.flushRleData(); // uncompressorRle1.flushRleData();
std::list<EydLib::BitGroup> uncompressedData = uncompressor.flush(); std::list<EydLib::BitGroup> uncompressedData = uncompressorRle1.flush();
std::list<EydLib::BitGroup>::iterator uncmpDataIt; std::list<EydLib::BitGroup>::iterator uncmpDataIt;
for(uncmpDataIt = uncompressedData.begin(); for(uncmpDataIt = uncompressedData.begin();
uncmpDataIt != uncompressedData.end(); uncmpDataIt != uncompressedData.end();

View file

@ -1,15 +1,15 @@
#include "eydrle.hh" #include "eydrle2.hh"
namespace EydTools { namespace EydTools {
EydRle::EydRle(){ EydRle2::EydRle2(){
_mode_compress = EYDRLE_MODE_UNDEF; _mode_compress = EYDRLE2_MODE_UNDEF;
_input_file.clear(); _input_file.clear();
_output_file.clear(); _output_file.clear();
_cellsize = 8; // one octet each time (by default); _cellsize = 8; // one octet each time (by default);
} }
void EydRle::run(){ void EydRle2::run(){
if (_mode_compress == EYDRLE_MODE_COMPRESS){ if (_mode_compress == EYDRLE2_MODE_COMPRESS){
this->compress(); this->compress();
} else { } else {
this->uncompress(); this->uncompress();

View file

@ -0,0 +1,31 @@
#ifndef _EYDRLE2_HH
#define _EYDRLE2_HH
#include <stdio.h>
#include <stdlib.h>
#include <eyd.hh>
#include <exception>
#include <vector>
namespace EydTools {
typedef enum { EYDRLE2_MODE_COMPRESS, EYDRLE2_MODE_UNCOMPRESS, EYDRLE2_MODE_UNDEF } eydrle2_mode_t;
class EydRle2 {
private:
// la config
eydrle2_mode_t _mode_compress;
std::string _input_file;
std::string _output_file;
int _cellsize;
EydLib::BitGroup _rle;
public:
EydRle2();
bool init(int argc, char **argv);
void run();
void compress();
void uncompress();
};
}
#endif

View file

@ -1,9 +1,9 @@
#include "eydrle.hh" #include "eydrle2.hh"
namespace EydTools { namespace EydTools {
bool EydRle::init(int argc, char ** argv){ bool EydRle2::init(int argc, char ** argv){
_mode_compress = EYDRLE_MODE_UNDEF; _mode_compress = EYDRLE2_MODE_UNDEF;
int i; int i;
for (i = 1; i + 1 < argc; i = i + 2){ for (i = 1; i + 1 < argc; i = i + 2){
@ -13,14 +13,14 @@ namespace EydTools {
switch(val[0]){ switch(val[0]){
case 'c': case 'c':
case 'C': case 'C':
_mode_compress = EYDRLE_MODE_COMPRESS; _mode_compress = EYDRLE2_MODE_COMPRESS;
break; break;
case 'u': case 'u':
case 'U': case 'U':
_mode_compress = EYDRLE_MODE_UNCOMPRESS; _mode_compress = EYDRLE2_MODE_UNCOMPRESS;
break; break;
default: default:
_mode_compress = EYDRLE_MODE_UNDEF; _mode_compress = EYDRLE2_MODE_UNDEF;
break; break;
} }
continue; continue;
@ -42,7 +42,7 @@ namespace EydTools {
// printf("value = %s\n",argv[i+1]); // printf("value = %s\n",argv[i+1]);
} }
if ((_mode_compress == EYDRLE_MODE_UNDEF) || if ((_mode_compress == EYDRLE2_MODE_UNDEF) ||
(_input_file.length() == 0)) { (_input_file.length() == 0)) {
printf("\nUsage: %s <options>\n", argv[0]); printf("\nUsage: %s <options>\n", argv[0]);
printf("\nWhere options could be:\n"); printf("\nWhere options could be:\n");
@ -54,7 +54,7 @@ namespace EydTools {
} }
if (_output_file.length() == 0){ if (_output_file.length() == 0){
if (_mode_compress == EYDRLE_MODE_COMPRESS){ if (_mode_compress == EYDRLE2_MODE_COMPRESS){
_output_file = _input_file + ".rl1"; _output_file = _input_file + ".rl1";
} else { } else {
_output_file = _input_file + ".rl1_orig"; _output_file = _input_file + ".rl1_orig";

View file

@ -1,14 +1,14 @@
#include "eydrle.hh" #include "eydrle2.hh"
using namespace std; using namespace std;
using namespace EydTools; using namespace EydTools;
int main(int argc, char **argv){ int main(int argc, char **argv){
bool ready; bool ready;
EydRle eydrle; EydRle2 eydrle2;
ready = eydrle.init(argc, argv); ready = eydrle2.init(argc, argv);
if (ready) { if (ready) {
eydrle.run(); eydrle2.run();
} }
return 0; return 0;