So after being stuck on this pset for overlooking tiny typos I have finally gotten it to compile but I received more errors then I would like to have. If anyone could tell me where I can find the issues so I can figure out a way to fix them that would be great. The only function that works properly is sepia. Here is my code:
#include "helpers.h"
#include <math.h>
// Convert image to grayscale
void grayscale(int height, int width, RGBTRIPLE image[height][width])
{
float gray;
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
float red = image[i][j].rgbtRed;
float green = image[i][j].rgbtGreen;
float blue = image[i][j].rgbtBlue;
gray = round((red + green + blue) /3);
image[i][j].rgbtRed = gray;
image[i][j].rgbtGreen = gray;
image[i][j].rgbtBlue = gray;
}
}
return;
}
// Convert image to sepia
void sepia(int height, int width, RGBTRIPLE image[height][width])
{
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j ++)
{
float red = image[i][j].rgbtRed;
float green = image[i][j].rgbtGreen;
float blue = image[i][j].rgbtBlue;
float sepiaRed = round(.393 * red + .769 * green + .189 * blue);
if (sepiaRed > 255)
{
sepiaRed = 255;
}
float sepiaGreen = round(.349 * red + .686 * green + .168 * blue);
if (sepiaGreen > 255)
{
sepiaGreen = 255;
}
float sepiaBlue = round(.272 * red + .534 * green + .131 * blue);
if (sepiaBlue > 255)
{
sepiaBlue = 255;
}
image[i][j].rgbtRed = sepiaRed;
image[i][j].rgbtGreen = sepiaGreen;
image[i][j].rgbtBlue =sepiaBlue;
}
}
return;
}
// Reflect image horizontally
void reflect(int height, int width, RGBTRIPLE image[height][width])
{
void swap(int *a, int *b);
int temp[6];
int s = 1;
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width / 2; j++)
{
temp[0] = image[i][j].rgbtRed;
temp[1] = image[i][j].rgbtGreen;
temp[2] = image[i][j].rgbtBlue;
temp[3] = image[i][width - s].rgbtRed;
temp[4] = image[i][width - s].rgbtGreen;
temp[5] = image[i][width - s].rgbtBlue;
swap(&temp[0], &temp[3]);
swap(&temp[1], &temp[4]);
swap(&temp[2], &temp[5]);
s++;
}
}
return;
}
void swap(int *a, int *b)
{
int tempB = *a;
*a = *b;
*b = tempB;
}
// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
//initiazlizes a temporary variable to store original colors
RGBTRIPLE temp[height][width];
//iterates through the pixels
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
float counter = 0.00;
int red = 0;
int green = 0;
int blue = 0;
//iterates through the pixels surrounding the pixel your on in the i/j loop
for (int k = -1; k < 2; k++)
{
for (int l = -1; l < 2; l++)
{
//checks to see if the pixels around the current pixel exist and ups the counter for each one
if ((i + k >= 0) && (j + l >= 0) && (i + k <= height - 1) && (j + l <= width -1))
{
red += image[i + k][j + l].rgbtRed;
green += image[i + k][j + l].rgbtGreen;
blue += image[i + k][j + l].rgbtBlue;
counter++;
}
}
}
temp[i][j].rgbtRed = round((red) / counter);
temp[i][j].rgbtBlue = round((blue) / counter);
temp[i][j].rgbtGreen = round((green) / counter);
}
}
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
image[i][j] = temp[i][j];
}
}
return;
}
The errors I am receiving are:
:( reflect correctly filters 1x2 image expected "0 0 255\n255 0...", not "255 0 0\n0 0 2..."
:( reflect correctly filters 1x3 image expected "0 0 255\n0 255...", not "255 0 0\n0 255..."
:( reflect correctly filters 3x3 image expected "70 80 90\n40 5...", not "10 20 30\n40 5..."
:( reflect correctly filters 4x4 image expected "100 110 120\n7...", not "10 20 30\n40 5..."