0

my code works but the sky looks shiny blue, its like its working in all others pixels but not on the sky, i do not get what i am doing wrong.

void sepia(int height, int width, RGBTRIPLE image[height][width])
{

    BYTE red, auxred;
    BYTE blue, auxblue;
    BYTE green, auxgreen;
    for(int i = 0; i < height; i++)
    {
        for(int j = 0; j < width; j++)
        {
            red = image[i][j].rgbtRed;
            blue = image[i][j].rgbtBlue;
            green = image[i][j].rgbtGreen;

            auxred = round((float).393 * red + (float).769 * green + (float).189 * blue);
            if(auxred > 0xff)
            {
                image[i][j].rgbtRed = 0xff;
            }else
            {
                image[i][j].rgbtRed = auxred;
            }
            auxblue = round((float).272 * red + (float).534 * green + (float).131 * blue);
            if(auxblue > 0xff)
            {
                image[i][j].rgbtBlue = 0xff;
            }else
            {
                image[i][j].rgbtBlue = auxblue;
            }
            auxgreen = round((float).349 * red + (float).686 * green + (float).168 * blue);
            if(auxgreen > 0xff)
            {
                image[i][j].rgbtGreen = 0xff;
            }else
            {
                image[i][j].rgbtGreen = auxgreen;
            }
        }
    }

    return;
}

1 Answer 1

0

On a quick glance, one thing jumped out at me.

The calculations are putting the results into auxred, auxgreen and auxblue. The calculations can generate results over 255, but these are all of type BYTE (range 0 to 255), which will result in an overflow condition that won't trigger an error. It will just overflow the contents of these vars and lead to unpredictable results.

Try declaring these (and any other potential overflowing vars) as int and not BYTE.

This may not be the full solution but it certainly jumped off the screen at me. ;-)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

2
  • Thank you very much for your reply, now thanks to your comments i could fix the problem. As the structure for RGB is on BYTE i supposed that i had to declare the variables as BYTE too and work everything on hexadecimals. So now i will have to suppose that the variable BYTE can receive an INT and transform it to hexadecimal. Commented Apr 27, 2023 at 3:33
  • Not sure that's the best way to look at it. ALL data is ultimately stored as hex in a computer, whether int, float, bool, or char, etc. It's more important to be aware of it's capacity, especially when working with BYTE. It's really easy to have overflows when working with small capacity data types.
    – Cliff B
    Commented Apr 27, 2023 at 3:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .