Compare commits

..

No commits in common. "36627452359aef87b4fb765da1a162176ae8d2dc" and "e12dfebf581f1d3c0ba0e850e77714d19e4c4da5" have entirely different histories.

1 changed files with 19 additions and 17 deletions

View File

@ -1,5 +1,5 @@
#include "helpers.h"
#include <math.h>
#include "helpers.h"
// Convert image to grayscale
void grayscale(int height, int width, RGBTRIPLE image[height][width])
@ -8,8 +8,7 @@ void grayscale(int height, int width, RGBTRIPLE image[height][width])
{
for (int j = 0; j < width; j++)
{
int avg = round((image[i][j].rgbtBlue + image[i][j].rgbtGreen + image[i][j].rgbtRed) /
(float) 3);
int avg = round((image[i][j].rgbtBlue + image[i][j].rgbtGreen + image[i][j].rgbtRed) / (float) 3);
image[i][j].rgbtBlue = image[i][j].rgbtGreen = image[i][j].rgbtRed = avg;
}
}
@ -23,12 +22,9 @@ void sepia(int height, int width, RGBTRIPLE image[height][width])
{
for (int j = 0; j < width; j++)
{
int sepiaRed = round(.393 * image[i][j].rgbtRed + .769 * image[i][j].rgbtGreen +
.189 * image[i][j].rgbtBlue);
int sepiaGreen = round(.349 * image[i][j].rgbtRed + .686 * image[i][j].rgbtGreen +
.168 * image[i][j].rgbtBlue);
int sepiaBlue = round(.272 * image[i][j].rgbtRed + .534 * image[i][j].rgbtGreen +
.131 * image[i][j].rgbtBlue);
int sepiaRed = round(.393 * image[i][j].rgbtRed + .769 * image[i][j].rgbtGreen + .189 * image[i][j].rgbtBlue);
int sepiaGreen = round(.349 * image[i][j].rgbtRed + .686 * image[i][j].rgbtGreen + .168 * image[i][j].rgbtBlue);
int sepiaBlue = round(.272 * image[i][j].rgbtRed + .534 * image[i][j].rgbtGreen + .131 * image[i][j].rgbtBlue);
if (sepiaRed > 255)
{
@ -92,19 +88,25 @@ void blur(int height, int width, RGBTRIPLE image[height][width])
{
for (int j = 0; j < width; j++)
{
int sumRed = 0, sumGreen = 0, sumBlue = 0, count = 0;
float sumRed = 0, sumGreen = 0, sumBlue = 0;
int count = 0;
for (int k = (i - 1); k <= (i + 1); k++)
for (int k = -1; k < 2; k++)
{
for (int l = (j - 1); l <= (j + 1); l++)
for (int l = -1; l < 2; l++)
{
if ((k >= 0 && k <= (height - 1)) && (l >= 0 && l <= (width - 1)))
if (i + k <= 0 || i + k >= height)
{
sumRed += copy[k][l].rgbtRed;
sumGreen += copy[k][l].rgbtGreen;
sumBlue += copy[k][l].rgbtBlue;
count++;
continue;
}
if (j + l <= 0 || j + l >= width)
{
continue;
}
sumRed += copy[i + k][j + l].rgbtRed;
sumGreen += copy[i + k][j + l].rgbtGreen;
sumBlue += copy[i + k][j + l].rgbtBlue;
count++;
}
}
image[i][j].rgbtRed = round(sumRed / (float) count);