0

Very new to coding, so please bear with me!

I've been trying to wrap my head around pointers/ addresses since Lecture 4 but I haven't been able to solve the following issue. I can make the following function work without using pointers but I wanted to see if I could use pointers here (clearly I couldn't).

I can't really figure out why my code isn't working - I've followed along with debug50 step by step but the function outputs an image that is identical to the input rather than a "sepia-fied" image. When I follow the steps through, I can see each value changing (*nb, *ng, *nr) and I can't figure out what's going wrong.

Any tips or suggestions would be much appreciated!

void sepia(int height, int width, RGBTRIPLE image[height][width])
{
  for (int i = 0; i < height; i++)
  {
    for (int j = 0; j < width; j++)
    {
      int temp_blue = image[i][j].rgbtBlue;
      int temp_green = image[i][j].rgbtGreen;
      int temp_red = image[i][j].rgbtRed;

      int new_blue = round(0.272 * temp_red
                          +0.534 * temp_green
                          +0.131 * temp_blue);

      int new_green = round(0.349 * temp_red
                           +0.686 * temp_green
                           +0.168 * temp_blue);

      int new_red = round(0.393 * temp_red
                         +0.769 * temp_green
                         +0.189 * temp_blue);

      int *nb, *ng, *nr;

      nb = &new_blue;
      ng = &new_green;
      nr = &new_red;

      int *new_colors[] = {nb, ng, nr};

      for(i=0; i<2; i++)
      {
        if(*new_colors[i] > 255)
        {
          *new_colors[i] = 255;
          return;
        }
      }

      image[i][j].rgbtBlue = *nb;
      image[i][j].rgbtGreen = *ng;
      image[i][j].rgbtRed = *nr;
    }
  }

    return;
}

You must log in to answer this question.

Browse other questions tagged .