BMP convert to ASCII Art in Cuda

  ascii-art, c++, cuda, pixel, vector

I want convert a bitmap to ASCII art in cuda. I write the code to the CPU, but i don’t know, how can i convert is to cuda code. How can i do it, could you give me a tip?
First i read the bmp image, and convert it to a 2 dimension pixel vector. After it in the ascii converter method, i check the pixel red value, and give a ascii caracter to this color. I want write a kernel for this method.
I want split the 2d vector to blocks, and then I want to work with these blocks in the kernel.

Here is the color-ASCII caracter definition:

#define BLACK "@"
#define CHARCOAL "#"
#define DARKGRAY "8"
#define MEDIUMGRAY "&"
#define MEDIUM "o"
#define GRAY ":"
#define SLATEGRAY "*"
#define LIGHTGRAY "."
#define WHITE " "

And this is my code, what i want to rewrite to gpu:

void convertToASCIIArt(std::vector<std::vector<Pixel>>pixelVector)
{
    std::reverse(pixelVector.begin(), pixelVector.end());

    std::string txt = "";
    std::string eol = "rn";
    for (size_t i = 0; i < pixelVector.size(); i++)
    {
        for (size_t j = 0; j < pixelVector[i].size(); j++)
        {
            double targetVal = pixelVector[i][j].red;

            std::string asciival = " ";

            if (targetVal >= 230)
            {
                asciival = WHITE;
            }
            else if (targetVal >= 200)
            {
                asciival = LIGHTGRAY;
            }
            else if (targetVal >= 180)
            {
                asciival = SLATEGRAY;
            }
            else if (targetVal >= 160)
            {
                asciival = GRAY;
            }
            else if (targetVal >= 130)
            {
                asciival = MEDIUM;
            }
            else if (targetVal >= 100)
            {
                asciival = MEDIUMGRAY;
            }
            else if (targetVal >= 70)
            {
                asciival = DARKGRAY;
            }
            else if (targetVal >= 50)
            {
                asciival = CHARCOAL;
            }
            else
            {
                asciival = BLACK;
            }

            txt += asciival;
        }
        txt += eol;
    }
    std::cout << txt;

    std::ofstream writeTxt("output.txt");
    writeTxt << txt;
    writeTxt.close();
}

Thank you in advance for your help 🙂

Source: Windows Questions C++

LEAVE A COMMENT