How to convert pixels to RGBA for characters?

0

Having access to the pixels of any image through the SFML library, my goal is to capture them and convert them to characters by placing them in a new array (image) and then displaying it. For this I checked the size of the image:

sf::Vector2u tam = imagem.getSize();
int largura = tam.x;
int altura  = tam.y;

To capture the RGB format, use the following code:

// O ponteiro dos pixel originais em RGBA.
const sf::Uint8* pixels = imagem.getPixelsPtr();

Pixel* rgba = (Pixel*) pixels;
// Vetor que armazenará os pixels.
sf::Uint8* saida = new sf::Uint8[4 * largura * altura];

int tamanho = 4 * largura * altura;

for (int i = 0; i < tamanho; i++)
{
saida[i] = pixels[i];
}

What I'm doing is creating a vector that is receiving RGBA, but still no conversion to characters, and this is one of my doubts how is a vector how will I control when it should break the line to form the correct image? Home Would not it be better to do with an array?
My other question is how do I convert these pixels into characters?

I tried this way, but to no avail:

for (int i = 0; i < tamanho; i++)
{
if (atriz[i][j]>=9,4*8)
saida[i] = '@';
}
    
asked by anonymous 13.05.2014 / 23:28

1 answer

1

If you want a one-character-per-pixel relationship, you should break the line every%% of characters, where x is the width of the image. Consider inserting into the vector a line break at multiple indexes of x . Or, as you yourself say, use an array.

Already to convert a pixel directly to a character - in this case, you may end up getting bizarre images that do not look anything like the original, depending on the details. As far as I know, programs that transform an animated video or GIF into an animated ASCII art use shape analysis to transform regions of the image into specific sets of characters, ie: a black pixel surrounded on the left by three white pixels 0 pair and 1 for black because I could not draw with HTML):

00
01

It can turn into something like:

| --- | | - ||||

Or

/ - |
| - |||

Depending on the filter used.

    
13.05.2014 / 23:44