Reads a PPM image, then saves a copy with an ASCII message encoded in the least significant bit (LSB) of it's pixels.
- Parameters
-
Stores the message that will be stored inside the image.
Stores the image by the parameters of the Image class.
Stores in a string the contents of the PPM image.
Tests if the file is in fact a P3/PPM file by looking at it's extension.
Tests if the ReadPPM() function was successful, stops the encoding process otherwise.
The message is inputed.
The message is encoded.
Tests if the a file with the same name already exists inside the source folder.
Stores the choice to overwrite. The answer is 'no' by default.
Tests if the answer was 'no', then stops the encoding process if true.
Tests if the file is open, if true, creates the PPM file and stores the modified content in it.
14{
15 if (argc != 3)
16 {
17 cout << "Uso: " << argv[0] << " <nome_do_arquivo>" <<" " <<"nome_do_arquivo_resultante" << endl;
18 return 1;
19 }
20
21
22
23 string img_name = argv[1];
24 string file_name = argv[2];
25 string msg;
27 ofstream file;
28 string img_content;
30
32 {
33 cout << "\033[1;31mTipo de arquivo de leitura inválido.: "+img_name +"\033[0m\n";
34 return 1;
35 }
37 {
38 cout << "\033[1;31mTipo de arquivo de saida inválido.: "+file_name +"\033[0m\n";
39 return 1;
40 }
43 {
45 getline(cin, msg);
48 }
49 else
50 {
51 cout << "\033[1;31mArquivo original não existe.\033[0m\n";
52 return 1;
53 }
54
56 if (fs::exists(file_name))
57 {
58 char overwrite = 'n';
60 cout << "O arquivo " << file_name << " já existe. Deseja sobrescrevê-lo? (s/n): ";
61 cin >> overwrite;
62
64 if (overwrite != 's' && overwrite != 'S')
65 {
66 std::cout << "\033[1;31mArquivo resultante já existe. Operação cancelada.\033[0m\n";
67 return 1;
68 }
69 }
70
72
74 file.open(file_name);
75 if (file.is_open())
76 {
77 file << img_content;
78 file.close();
79 cout << "\033[1;32mImagem gerada com sucesso: " << file_name << "\033[0m" << endl;
80
81 }
82 else
83 {
84 cout << "Erro ao criar o arquivo." << endl;
85 }
86
87 return 0;
88}
Defines a dinamically allocated PPM image and provides various methods to manipulate and access the i...
Definition Image.h:30
bool ReadPPM(const string &file_name)
Reads and dynamically stores the content of an image from a valid PPM file.
Definition Image.h:194
string CreatePPM() const
Function that creates a string containing all the data of a PPM image.
Definition Image.h:169
void CodeMsg(string msg)
Main function used in encrypting and hiding an ASCII message inside the least significant bits (LSB) ...
Definition Image.h:288
bool ExtensionCheck(const string &input_text, const string &file_type)
Function that checks if a string ends with the valid substring.
Definition Image.h:127