#Rob asked me to showcase of what I have cooked

23 messages · Page 1 of 1 (latest)

ember elm
#
void sepia(int height, int width, RGBTRIPLE image[height][width])
{
    RGBTRIPLE pixel;
    BYTE red, green, blue, sepiaRed, sepiaGreen, sepiaBlue;
    double d_sepiaRed, d_sepiaGreen, d_sepiaBlue;

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

            d_sepiaRed = round(red * 0.393 + green * 0.769 + blue * 0.189);
            d_sepiaGreen = round(red * 0.349 + green * 0.686 + blue * 0.168);
            d_sepiaBlue = round(red * 0.272 + green * 0.534 + blue * 0.131);

            if( d_sepiaRed > 0xFF)
            {
                sepiaRed = 0xFF;
            }
            else
                sepiaRed = (BYTE) d_sepiaRed;


            if( d_sepiaGreen > 0xFF)
            {
                sepiaGreen = 0xFF;
            }
            else
                sepiaGreen = (BYTE) d_sepiaGreen;

            sepiaBlue = (BYTE) d_sepiaBlue;

            image[i][j].rgbtRed = sepiaRed;
            image[i][j].rgbtGreen = sepiaGreen;
            image[i][j].rgbtBlue = sepiaBlue;
        }
    }
}```
```// Convert image to grayscale
void grayscale(int height, int width, RGBTRIPLE image[height][width])
{
    WORD word_average;
    BYTE average;
    RGBTRIPLE pixel;
    for ( int i = 0; i < height; i++)
    {
        for ( int j = 0; j < width; j++ )
        {
            pixel = image[i][j];
            word_average = ((WORD) pixel.rgbtBlue + pixel.rgbtGreen + pixel.rgbtRed) / 3;
            if (word_average > 0xFF)
            {
                average = 0xFF;
            }
            else
                average = (BYTE) word_average;

            image[i][j].rgbtBlue = average;
            image[i][j].rgbtGreen = average;
            image[i][j].rgbtRed = average;
        }
    }
}```
steep mauve
#

Any reason to use BYTE and WORD in there?

ember elm
#

now I see that I have made a mistake converting

next basalt
#

Isn’t this cs50

#

I think

hexed egret
#

Very cool!!!

next basalt
#

Yea cool indeed

ember elm
#

here

shell lodgeBOT
next basalt
#

lol u deserved it tbh

#

Tho what are the bytes used for @hexed egret

#

Just for seeing who has the most ?

ember elm
#

and i did this acrobatics to handle overflow

steep mauve
#

Yes but why not just use the uints

ember elm
#

wanted to confuse ppl

#

idk they defined it

steep mauve
#

valid

ember elm
#

so why tf no t

#

I was googling what kind of data type round() returns and it didnt give me an answer then I googled how much of number of a type float is the exponent, and it was 8bits which wouldnt help me and then I made a mistake and compiler told me that return type is double >:) and I learn a lot ^^

steep mauve
#

double it and give it to the next

ember elm
shell lodgeBOT