From ffb486b0b9a97df9bf77107bdf5fa0a74a40bef8 Mon Sep 17 00:00:00 2001 From: Lauchmelder Date: Sat, 22 Jan 2022 13:59:44 +0100 Subject: [PATCH] cleaned up code slightly --- include/bild.hpp | 21 +++++++++++++++++++++ src/bild.cpp | 20 +++++++++----------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/include/bild.hpp b/include/bild.hpp index a0d5469..8fb5006 100644 --- a/include/bild.hpp +++ b/include/bild.hpp @@ -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 * diff --git a/src/bild.cpp b/src/bild.cpp index 5704d7d..4c37518 100644 --- a/src/bild.cpp +++ b/src/bild.cpp @@ -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++)