Skip to content

Commit eba8e70

Browse files
Merge pull request #22 from ekanshgupta2046/added-sepia-function
feat: add sepia function in helpers.c
2 parents 78f6724 + 2453298 commit eba8e70

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

filter.exe

-49.2 KB
Binary file not shown.

helpers.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,30 @@ void invert(int height, int width, RGBTRIPLE image[height][width]){
6161
}
6262
void sepia(int height, int width, RGBTRIPLE image[height][width]){
6363

64-
// Convert image to sepia
64+
for (int i = 0; i < height; i++)
65+
{
66+
for (int j = 0; j < width; j++)
67+
{
68+
int originalRed = image[i][j].rgbtRed;
69+
int originalGreen = image[i][j].rgbtGreen;
70+
int originalBlue = image[i][j].rgbtBlue;
71+
72+
int sepiaRed = round(0.393 * originalRed + 0.769 * originalGreen + 0.189 * originalBlue);
73+
int sepiaGreen = round(0.349 * originalRed + 0.686 * originalGreen + 0.168 * originalBlue);
74+
int sepiaBlue = round(0.272 * originalRed + 0.534 * originalGreen + 0.131 * originalBlue);
75+
76+
if (sepiaRed > 255)
77+
sepiaRed = 255;
78+
if (sepiaGreen > 255)
79+
sepiaGreen = 255;
80+
if (sepiaBlue > 255)
81+
sepiaBlue = 255;
82+
83+
image[i][j].rgbtRed = sepiaRed;
84+
image[i][j].rgbtGreen = sepiaGreen;
85+
image[i][j].rgbtBlue = sepiaBlue;
86+
}
87+
}
6588

6689
}
6790

@@ -128,7 +151,7 @@ void blur(int height, int width, RGBTRIPLE image[height][width]){
128151

129152
// Blur image
130153

131-
}
154+
132155
void vignette(int height, int width, RGBTRIPLE image[height][width]){
133156
float cx = width / 2.0; // center of the image
134157
float cy= height / 2.0;

0 commit comments

Comments
 (0)