-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
95 lines (77 loc) · 4.06 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* CSCI 200: Final Project - CLI Wallpaper Generator
*
* Author: Micah Bird
*
* Resources used:
* [1] R. Tanck, “Roy Tanck’s Wallpaper Generator Algorithm,” Github. [Online]. Available: https://github.com/roytanck/wallpaper-generator
*
* [2] “LodePNG.” Accessed: Dec. 02, 2023. [Online]. Available: https://lodev.org/lodepng/
*
* [3] CLIUtils, “CLI11: Command line parser for C++11,” Github. [Online]. Available: https://github.com/CLIUtils/CLI11
*
* [4] “Bresenham’s line algorithm,” Wikipedia. Nov. 23, 2023. Accessed: Dec. 02, 2023. [Online]. Available: https://en.wikipedia.org/w/index.php?title=Bresenham%27s_line_algorithm&oldid=1186441766
*
* [5] “HSL and HSV,” Wikipedia. Nov. 18, 2023. Accessed: Dec. 02, 2023. [Online]. Available: https://en.wikipedia.org/w/index.php?title=HSL_and_HSV&oldid=1185698752
*
* [6] “LodePNG Example,” LodePNG. [Online]. Available: https://raw.githubusercontent.com/lvandeve/lodepng/master/examples/example_4bit_palette.cpp
*
* [7] M. James, “placekitten,” placekitten. Accessed: Dec. 02, 2023. [Online]. Available: http://placekitten.com
*
* Run the program with the -h flag to see the help menu.
*/
#include "CLI11.hpp"
#include "Wallpaper.h"
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char** argv) {
CLI::App app{"Wallpaper Generator CLI - Generate a random wallpaper in the command line"};
// Define the CLI options
string outputFilename;
// Mark the option as required
app.add_option("-o,--output", outputFilename, "Path of output file as a png (Ex: ./my-epic-wallpaper.png)") -> required();
string resolution = "1920x1080";
app.add_option("-r,--resolution", resolution, "The resolution of the image in the format WIDTHxHEIGHT (Default: 1920x1080)");
string embedImageLocation;
app.add_option("-e,--embed", embedImageLocation, "Path of embed PNG image (Ex: ./my-embed-image.png)");
string embedPosition = "lowerright";
app.add_option("-p,--embedPosition", embedPosition, "Position of the embedded image in wallpaper in the format WIDTHxHEIGHT|lowerright|upperleft (Default: lowerright)");
// Set the help menu
app.footer("Examples:\n # Generates a 1920x1080 PNG wallpaper in ~/Pictures\n $ wallpaper-generator-cli -o ~/Pictures/my-epic-wallpaper.png\n\n # Generates a 1920x1080 wallpaper with a placeholder kitten embedded in the upper left\n $ wallpaper-generator-cli -e kitten.png -p upperleft -o ./my-epic-embedded-wallpaper.png\n\n # Generates a 4K wallpaper in the current directory \n $ wallpaper-generator-cli -r 3840x2160 -o ./my-epic-wallpaper.png\n");
CLI11_PARSE(app, argc, argv);
// Parse the resolution and check if it's valid
unsigned int width, height;
size_t pos = resolution.find("x");
if(pos == string::npos) {
cerr << "Error: Invalid resolution format. Please use the format WIDTHxHEIGHT (Ex: 1920x1080)" << endl;
return 1;
}
width = stoi(resolution.substr(0, pos));
height = stoi(resolution.substr(pos + 1));
// Check if the width and height are valid
if(width <= 0 || height <= 0) {
cerr << "Error: Invalid resolution. Please use positive integers for the width and height." << endl;
return 1;
} else if (width > 10000 || height > 10000) {
cerr << "Error: Invalid resolution. Please use a width and height less than 10000." << endl;
return 1;
}
// Check output filename to see if it ends with .png
if(outputFilename.substr(outputFilename.length() - 4) != ".png") {
outputFilename += ".png";
}
// Create a Wallpaper object
Wallpaper wallpaper;
// Set the resolution
wallpaper.setResolution(width, height);
// Generate the wallpaper
wallpaper.generateWallpaper();
// Embed the image if the user specified an image
if(!embedImageLocation.empty()) {
// Embed the image
wallpaper.embedImage(embedImageLocation, embedPosition);
}
// Write the image to disk
wallpaper.writeImagetoDisk(outputFilename);
return 0;
}