0

The grayscale function works fine, but when i try the sepia and reflect the new image is un changed from the old one. (code below)

#include "helpers.h"
#include <math.h>
// Convert image to grayscale
void grayscale(int height, int width, RGBTRIPLE image[height][width])
{
    //iterate through the pixeles
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
          double average = round((image[i][j].rgbtRed + image[i][j].rgbtGreen + image[i][j].rgbtBlue) / 3);
          image[i][j].rgbtRed = average;
          image[i][j].rgbtGreen = average;
          image[i][j].rgbtBlue = average;
        }
    }

    // calculate the average value for RGB to set all chanels to that
    return;
}

// Convert image to sepia
void sepia(int height, int width, RGBTRIPLE image[height][width])
{
    const int highest = 255;
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
          int sepiaRed = round((image[i][j].rgbtRed * 0.393) + (image[i][j].rgbtGreen * 0.769) + (image[i][j].rgbtBlue * 0.189));
          int sepiaGreen = round((image[i][j].rgbtRed * 0.349) + (image[i][j].rgbtGreen * 0.686) + (image[i][j].rgbtBlue * 0.168));
          int sepiaBlue = round((image[i][j].rgbtRed * 0.272) + (image[i][j].rgbtGreen * 0.534) + (image[i][j].rgbtBlue * 0.131));

          image[i][j].rgbtRed = (sepiaRed > highest) ? highest : sepiaRed;
          image[i][j].rgbtGreen = (sepiaGreen > highest) ? highest : sepiaGreen;
          image[i][j].rgbtBlue = (sepiaBlue > highest) ? highest : sepiaBlue;

        }
    }
    return;
}

// Reflect image horizontally
void reflect(int height, int width, RGBTRIPLE image[height][width])
{
    for (int i = 0; i < height; i++)
    {
        for (int j = width; j >= 0; j--)
        {
            int invertedRed, invertedGreen, invertedBlue;
            int k = 0;
            invertedRed = image[i][j].rgbtRed;
            invertedGreen = image[i][j].rgbtGreen;
            invertedBlue = image[i][j].rgbtBlue;

            image[i][k].rgbtRed = invertedRed;
            image[i][k].rgbtGreen = invertedGreen;
            image[i][k].rgbtBlue = invertedBlue;

            k++;
        }
    }
    return;
}

// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
    return;
}
0

I'll have to look more at your sepia function to see what is happening there. I don't see anything jumping out as obviously wrong, though I'll have to look more at it. My "off-the-top-of-my-head" guess is something to do with those ternary operators--I didn't use those in mine (the only difference) and I am not as familiar with their behavior in C as in Java (if there is a difference).

But, for reflection, you are moving down the whole width, effectively moving the pixels back to where they started with the second half of the pass. Remember, you only need to work on one half of the axis of reflection.

Edit: I've gone through your sepia function and cannot find an error--it works for me.

1
  • Thanks for the input. i keep on working to correct some errors from check50. Jan 7 at 17:15

You must log in to answer this question.

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