How to read txt with color palette to apply to another txt with characters?

Asked

Viewed 30 times

0

I need to read the color palette file, something like:

. 0 0 64

x 255 255 0

0 0 0

where each symbol in the first column represents the image in another txt file. Where it has ". x o" need to be replaced by the RGB that exists next door to generate a PPM image.

int image::palheta(string nome, int height, int width){

int i, j;
int dado[i][j];
int red,green,blue;
ifstream iFile(nome); 
string str;
if(iFile)
{
    ostringstream ss;
    ss << iFile.rdbuf();
    str = ss.str();
}
    

for(int j=0; j<height; j++)
{
    for (int i = 0; i < width; ++i)
    {
        if(dado[i][j] == '.'){
            iFile >> red;
            iFile >> green;
            iFile >> blue;
            set(i,j,red,green,blue);
            cout << getred(i,j) << " " << getgreen(i,j) << " " << getblue(i,j) << " ";
        }

        if(dado[i][j] == 'x'){
            iFile >> red;
            iFile >> green;
            iFile >> blue;
            set(i,j,red,green,blue);        
            cout << getred(i,j) << " " << getgreen(i,j) << " " << getblue(i,j) << " ";
        }

        if(dado[i][j] == '0'){
            iFile >> red;
            iFile >> green;
            iFile >> blue;
            set(i,j, red,green,blue);       
            cout << getred(i,j) << " " << getgreen(i,j) << " " << getblue(i,j) << " ";
        }
    }
        
}
   cout<<str;
   iFile.close();  
}

I am developing in C++, I have created a method to read the color palette but I am not able to save only the rgb values. Could someone help me?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.