Skip to content

Commit

Permalink
Added cli option to encode and decode, added usage
Browse files Browse the repository at this point in the history
  • Loading branch information
ImTheCurse committed Nov 20, 2023
1 parent acf65f3 commit b945595
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 22 deletions.
Binary file modified HIPS
Binary file not shown.
Binary file added enc_file.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed enc_lena.png
Binary file not shown.
87 changes: 65 additions & 22 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,82 @@
#include "src/Decode.hpp"


class InputParser{
public:
InputParser (int &argc, char **argv){
for (int i=1; i < argc; ++i)
this->tokens.push_back(std::string(argv[i]));
}
/// @author iain
const std::string& getCmdOption(const std::string &option) const{
std::vector<std::string>::const_iterator itr;
itr = std::find(this->tokens.begin(), this->tokens.end(), option);
if (itr != this->tokens.end() && ++itr != this->tokens.end()){
return *itr;
}
static const std::string empty_string("");
return empty_string;
}
/// @author iain
bool cmdOptionExists(const std::string &option) const{
return std::find(this->tokens.begin(), this->tokens.end(), option)
!= this->tokens.end();
}
private:
std::vector <std::string> tokens;
};


int main(int argc, char** argv )
{
if ( argc < 3 )
{
printf("usage: DisplayImage.out <Image_Path>\n");
return -1;
}

bool gotEncDecFlag = false;
bool gotInputFlag = false;
bool gotFileFlag = false;
std::stringstream buffer;
std::string newBuff;
cv::Mat image;
image = cv::imread( argv[1], cv::IMREAD_COLOR);
if ( !image.data )
{

InputParser input(argc,argv);
if(input.cmdOptionExists("-i")){
const std::string &filePath = input.getCmdOption("-i");
image = cv::imread(filePath,cv::IMREAD_COLOR);
if ( !image.data ){
printf("No image data \n");
return -1;
}
}
gotInputFlag = true;

/*
Flags:
-i : image path
-e : encode image
-d : decode image
-t : file path to read
}

*/
if(input.cmdOptionExists("-f")){
std::ifstream t(input.getCmdOption("-f"));
buffer << t.rdbuf();
newBuff = buffer.str();
gotFileFlag = true;

//Encode enc(image,"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum","lena.png");
}

if(input.cmdOptionExists("-m")){
newBuff = input.getCmdOption("-m");
gotFileFlag = true;
}

if(input.cmdOptionExists("-e") && gotInputFlag){
Encode enc(image,newBuff,"file.png");
gotEncDecFlag = true;
}

if(input.cmdOptionExists("-d") && !gotEncDecFlag){
Decode dec(image);
//Decode dec(enc.getImage());
}


if(input.cmdOptionExists("-h")){
std::cout<<"usage:\n-i <image_path> : relative PNG image path(with name and extension)\n-e : encode image(write after all the flags)\n-d : decode image(write after all the flags)\n-m <message> : CLI message\n-f <file_path> : relative file path to encode(with name and extension)\n\n";
return 0;
}


//namedWindow("Display Image", WINDOW_AUTOSIZE );
//imshow("Display Image", image);
std::cout<<"Finished."<<std::endl;
cv::waitKey(0);
return 0;
}
1 change: 1 addition & 0 deletions test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
what is love? baby don't hurt me

0 comments on commit b945595

Please sign in to comment.