cleaned up code slightly

This commit is contained in:
Lauchmelder 2022-01-22 13:59:44 +01:00
parent 02fd658ae4
commit ffb486b0b9
2 changed files with 30 additions and 11 deletions

View file

@ -25,6 +25,27 @@ public:
*/
Bild() = default;
/**
* @brief Construct a new empty picture with meta data
*
* The pixel buffer will be empty, but the meta data (width, height, description)
* will be set, and the pixel buffer will be resized to match the dimensions
*
* @param width Width of the image
* @param height Height of the image
* @param description Description of the image
*/
Bild(uint32_t width, uint32_t height, const std::string& description);
/**
* @brief Copy an image
*
* The copy will copy the image data from the original image to a new buffer
*
* @param other The image to copy from
*/
Bild(const Bild& other) = default;
/**
* @brief Load an image
*

View file

@ -5,6 +5,12 @@
const std::string Bild::asciiBrightnessMap = ".'`^\",:;Il!i><~+_-?][}{1)(|\\/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$";
Bild::Bild(uint32_t width, uint32_t height, const std::string& description) :
width(width), height(height), description(description)
{
pixels.resize(width * height);
}
std::ifstream& operator>>(std::ifstream& file, Bild& image)
{
std::string lineContent;
@ -111,12 +117,8 @@ std::ostream& operator<<(std::ostream& os, const Bild& image)
Bild Bild::Geglaettet() const
{
// Create new image and copy metadata
Bild smoothedImage;
smoothedImage.width = width;
smoothedImage.height = height;
smoothedImage.description = description + " smoothed";
smoothedImage.pixels.resize(pixels.size()); // Resize the pixel array to match the image dimensions
// Create new image with same dimensions
Bild smoothedImage(width, height, description + " smoothed");
// Apply smoothing
for(uint32_t y = 0; y < smoothedImage.height; y++)
@ -148,11 +150,7 @@ Bild Bild::Geglaettet() const
Bild Bild::Kantenbild() const
{
// Create new image and copy metadata
Bild modifiedImage;
modifiedImage.width = width;
modifiedImage.height = height;
modifiedImage.description = description + " edged";
modifiedImage.pixels.resize(pixels.size()); // Resize the pixel array to match the image dimensions
Bild modifiedImage(width, height, description + " edged");
// Apply edge detection
for(uint32_t y = 0; y < modifiedImage.height; y++)