From 02fd658ae43bc15f5567265d82e0d0b428fe720e Mon Sep 17 00:00:00 2001 From: Lauchmelder Date: Sat, 22 Jan 2022 13:48:17 +0100 Subject: [PATCH] added more comments --- include/bild.hpp | 4 ++-- src/bild.cpp | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/bild.hpp b/include/bild.hpp index 764559a..a0d5469 100644 --- a/include/bild.hpp +++ b/include/bild.hpp @@ -14,7 +14,7 @@ class Bild { public: - // ASCII characters used when printing the image to stdcout + // ASCII characters used when printing the image to stdout static const std::string asciiBrightnessMap; public: @@ -51,7 +51,7 @@ public: * @brief Renders the image to the console * * Draws the image in the console using ascii characters. - * Das war zwar in der Aufgabe nicht verlangt aber ich wollt schon gern die Bilder sehen + * Das war zwar in der Aufgabe nicht verlangt aber ich wollte gern die Bilder sehen * * @param os Output stream to draw to * @param image Image to draw diff --git a/src/bild.cpp b/src/bild.cpp index ec8b6ba..5704d7d 100644 --- a/src/bild.cpp +++ b/src/bild.cpp @@ -71,6 +71,8 @@ std::ofstream& operator<<(std::ofstream& file, const Bild& image) for(uint8_t pixel : image.pixels) { uint32_t value = static_cast(pixel); + // If the current line would become longer than 70 characters, write the line to + // the file, insert a newline and clear the line if(line.size() + std::to_string(value).length() > 70) { file << line << std::endl; @@ -80,6 +82,7 @@ std::ofstream& operator<<(std::ofstream& file, const Bild& image) line += std::to_string(value) + " "; } + // Write remaining lines to file file << line << std::endl; return file; @@ -87,8 +90,7 @@ std::ofstream& operator<<(std::ofstream& file, const Bild& image) std::ostream& operator<<(std::ostream& os, const Bild& image) { - - + // Loop over pixels in image for(uint16_t y = 0; y < image.height; y++) { std::stringstream lineBuffer; @@ -100,7 +102,7 @@ std::ostream& operator<<(std::ostream& os, const Bild& image) uint8_t asciiMapIndex = static_cast(brightness * (Bild::asciiBrightnessMap.length() - 1) / 255); lineBuffer << Bild::asciiBrightnessMap[asciiMapIndex]; } - + std::cout << lineBuffer.str() << std::endl; }