Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
int main(int argc, char *argv[])
{
// Define allowable filters
char *filters = "bgrs";
char *filters = "bgrsi";

// Get filter flag and check validity
char filter = getopt(argc, argv, filters);
Expand Down Expand Up @@ -119,6 +119,12 @@ int main(int argc, char *argv[])
case 's':
sepia(height, width, image);
break;

//invert
case 'i':
invert(height,width,image);
break;

}

// Write outfile's BITMAPFILEHEADER
Expand Down
Binary file modified filter.exe
Binary file not shown.
44 changes: 42 additions & 2 deletions helpers.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,53 @@
#include "helpers.h"


int min(int a,int b){
if(a<b) return a;
return b;
}
int max(int a,int b){
if(a>b) return a;
return b;
}
void grayscale(int height, int width, RGBTRIPLE image[height][width]){

return;

// Convert image to grayscale

}

void invert(int height, int width, RGBTRIPLE image[height][width]){
for(int i = 0; i<height; i++){
for(int j = 0; j<width; j++){
//Original RGB
int red = image[i][j].rgbtRed;
int green = image[i][j].rgbtGreen;
int blue = image[i][j].rgbtBlue;

//Normal inversion
int invRed = 255 - red;
int invGreen = 255 - green;
int invBlue = 255 - blue;

//for maintain average brightness
int originalBrightness = 0.299*red + 0.587*green + 0.114*blue;
int invertedBrightness = 0.299*invRed + 0.587*invGreen + 0.114*invBlue;
int brightnessDiff = originalBrightness - invertedBrightness;

invRed = min(max(invRed + brightnessDiff, 0), 255);
invGreen = min(max(invGreen + brightnessDiff, 0), 255);
invBlue = min(max(invBlue + brightnessDiff, 0), 255);

//Assign
image[i][j].rgbtRed = invRed;
image[i][j].rgbtGreen = invGreen;
image[i][j].rgbtBlue = invBlue;
}
}
return;

// Convert image to grayscale

}
void sepia(int height, int width, RGBTRIPLE image[height][width]){

// Convert image to sepia
Expand Down
3 changes: 3 additions & 0 deletions helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
// Convert image to grayscale
void grayscale(int height, int width, RGBTRIPLE image[height][width]);

// invert image
void invert(int height, int width, RGBTRIPLE image[height][width]);

// Convert image to sepia
void sepia(int height, int width, RGBTRIPLE image[height][width]);

Expand Down
Binary file added output.bmp
Binary file not shown.
Loading