Made ASCII map static
This commit is contained in:
parent
3da237a46b
commit
914bb670dd
|
@ -13,6 +13,10 @@
|
||||||
*/
|
*/
|
||||||
class Bild
|
class Bild
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
// ASCII characters used when printing the image to stdcout
|
||||||
|
static const std::string asciiBrightnessMap;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Creates a new empty picture.
|
* @brief Creates a new empty picture.
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
const std::string Bild::asciiBrightnessMap = ".'`^\",:;Il!i><~+_-?][}{1)(|\\/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$";
|
||||||
|
|
||||||
std::ifstream& operator>>(std::ifstream& file, Bild& image)
|
std::ifstream& operator>>(std::ifstream& file, Bild& image)
|
||||||
{
|
{
|
||||||
std::string lineContent;
|
std::string lineContent;
|
||||||
|
@ -85,7 +87,7 @@ std::ofstream& operator<<(std::ofstream& file, const Bild& image)
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const Bild& image)
|
std::ostream& operator<<(std::ostream& os, const Bild& image)
|
||||||
{
|
{
|
||||||
std::string asciiBrightnessMap(".'`^\",:;Il!i><~+_-?][}{1)(|\\/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$");
|
|
||||||
|
|
||||||
for(uint16_t y = 0; y < image.height; y++)
|
for(uint16_t y = 0; y < image.height; y++)
|
||||||
{
|
{
|
||||||
|
@ -95,8 +97,8 @@ std::ostream& operator<<(std::ostream& os, const Bild& image)
|
||||||
uint8_t brightness = image.pixels[y * image.width + x];
|
uint8_t brightness = image.pixels[y * image.width + x];
|
||||||
|
|
||||||
// Map the pixel brightness (which is in the interval [0, 255]) to the ascii chart length
|
// Map the pixel brightness (which is in the interval [0, 255]) to the ascii chart length
|
||||||
uint8_t asciiMapIndex = static_cast<uint8_t>(brightness * (asciiBrightnessMap.length() - 1) / 255);
|
uint8_t asciiMapIndex = static_cast<uint8_t>(brightness * (Bild::asciiBrightnessMap.length() - 1) / 255);
|
||||||
lineBuffer << asciiBrightnessMap[asciiMapIndex];
|
lineBuffer << Bild::asciiBrightnessMap[asciiMapIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << lineBuffer.str() << std::endl;
|
std::cout << lineBuffer.str() << std::endl;
|
||||||
|
|
Loading…
Reference in a new issue