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
15 changes: 7 additions & 8 deletions C_image_processing/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ dkms.conf
# Executables

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
*.vscode
#!.vscode/c_cpp_properties.json
#!.vscode/settings.json # user Specific
#!.vscode/tasks.json
#!.vscode/launch.json # user Specific
#!.vscode/extensions.json
#!.vscode/*.code-snippets

# Local History for Visual Studio Code
.history/
Expand Down Expand Up @@ -120,7 +121,5 @@ $RECYCLE.BIN/
# Windows shortcuts
*.lnk

# End of https://www.toptal.com/developers/gitignore/api/windows,visualstudiocode,c,c++

# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
output.bmp
25 changes: 25 additions & 0 deletions C_image_processing/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:/msys64/mingw64/include/gtk-4.0",
"C:/msys64/mingw64/include/glib-2.0",
"C:/msys64/mingw64/include/**",
"C:/msys64/mingw64/lib/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.22000.0",
"compilerPath": "C:/msys64/mingw64/bin/gcc.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
61 changes: 61 additions & 0 deletions C_image_processing/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe build active file",
"command": "C:/msys64/mingw64/bin/gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"-IC:/msys64/mingw64/include/gtk-4.0",
"-IC:/msys64/mingw64/include/pango-1.0",
"-IC:/msys64/mingw64/include",
"-IC:/msys64/mingw64/include/glib-2.0",
"-IC:/msys64/mingw64/lib/glib-2.0/include",
"-IC:/msys64/mingw64/include/harfbuzz",
"-IC:/msys64/mingw64/include/freetype2",
"-IC:/msys64/mingw64/include/libpng16",
"-IC:/msys64/mingw64/include/fribidi",
"-IC:/msys64/mingw64/include/cairo",
"-IC:/msys64/mingw64/include/pixman-1",
"-IC:/msys64/mingw64/include/gdk-pixbuf-2.0",
"-IC:/msys64/mingw64/include/webp",
"-DLIBDEFLATE_DLL",
"-IC:/msys64/mingw64/include/graphene-1.0",
"-IC:/msys64/mingw64/lib/graphene-1.0/include",
"-mfpmath=sse",
"-msse",
"-msse2",

"${file}",

"-LC:/msys64/mingw64/lib",
"-lgtk-4",
"-lpangowin32-1.0",
"-lpangocairo-1.0",
"-lpango-1.0",
"-lharfbuzz",
"-lgdk_pixbuf-2.0",
"-lcairo-gobject",
"-lcairo",
"-lgraphene-1.0",
"-lgio-2.0",
"-lgobject-2.0",
"-lglib-2.0",
"-lintl",

"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:/msys64/mingw64/bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "compiler: C:/msys64/mingw64/bin/gcc.exe"
}
]
}
46 changes: 22 additions & 24 deletions C_image_processing/filters/black_and_white_filter.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdio.h>

#define THRESHOLD 128 // define value of threshold for black and white
#define WHITE 255
#define BLACK 0
Expand All @@ -16,48 +17,45 @@ int black_and_white_filter(const char *inputFile, const char *outputFile) {
return 1;
}

int i;
unsigned char byte[54];
unsigned char headerInfo[54];
unsigned char colorTable[1024];

// read header info of image
for(i = 0; i < 54; i++) {
byte[i] = getc(fileIn);
// Read header info of image
for(int i = 0; i < 54; i++) {
headerInfo[i] = getc(fileIn);
}

// write header info to output file
fwrite(byte, sizeof(unsigned char), 54, fileOut);
// Write header info to output file
fwrite(headerInfo, sizeof(unsigned char), 54, fileOut);

// extract height, width and bitDepth of image from the header information
int height = *(int*)&byte[18];
int width = *(int*)&byte[22];
int bitDepth = *(int*)&byte[28];
// Extract.. of image from the header information
int height = *(int*)&headerInfo[18];
int width = *(int*)&headerInfo[22];
int bitDepth = *(int*)&headerInfo[28];
int size = height * width;

// check if the image has a color table
// Check if the image has a color table
if(bitDepth <= 8) {
// read, and then write the color table from the input file
fread(colorTable, sizeof(unsigned char), 1024, fileIn);
fwrite(colorTable, sizeof(unsigned char), 1024, fileOut);
}

unsigned char chunkBuffer[CHUNK_SIZE];

// array to store the image data in chunks
unsigned char buffer[CHUNK_SIZE];

// read and write the image data in chunks until the end of the file is reached
// Read & write the image data in chunks until the end of file is reached
while(!feof(fileIn)) {

// read a chunk of image data from the input file
size_t bytesRead = fread(buffer, sizeof(unsigned char), CHUNK_SIZE, fileIn);
// Read a chunk of image data from input file
size_t bytesRead = fread(chunkBuffer, sizeof(unsigned char), CHUNK_SIZE, fileIn);

// apply the threshold to each pixel in the chunk
for(i = 0; i < bytesRead; i++) {
buffer[i] = (buffer[i] > THRESHOLD)
// Apply threshold to each pixel in the chunk
for(int i = 0; i < bytesRead; i++) {
chunkBuffer[i] = (chunkBuffer[i] > THRESHOLD)
? WHITE
: BLACK;
}
// write the thresholded image data to the output file
fwrite(buffer, sizeof(unsigned char), bytesRead, fileOut);
// Write the thresholded image data to the output file
fwrite(chunkBuffer, sizeof(unsigned char), bytesRead, fileOut);
}

fclose(fileIn);
Expand Down
58 changes: 26 additions & 32 deletions C_image_processing/filters/bright_filter.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>

#define MAX_COLOR 255
#define BRIGHTNESS 25
#define CHUNK_SIZE 1024 // define size of the chunks to read and write
Expand All @@ -17,54 +18,47 @@ int bright_filter(inputFile, outputFile) {
return 1;
}

int i;
unsigned char byte[54]; // store header info of image
unsigned char colorTable[1024]; // store color table of image

// read the header info of image
for(i = 0; i < 54; i++) {
byte[i] = getc(fileIn);
unsigned char headerInfo[54];
unsigned char colorTable[1024];

for(int i = 0; i < 54; i++) {
headerInfo[i] = getc(fileIn);
}

// write header info to output file
fwrite(byte, sizeof(unsigned char), 54, fileOut);
fwrite(headerInfo, sizeof(unsigned char), 54, fileOut);

// extract height, width and bitDepth of image from header info
int height = *(int*)&byte[18];
int width = *(int*)&byte[22];
int bitDepth = *(int*)&byte[28];
// Extract.. of image from header info
int height = *(int*)&headerInfo[18];
int width = *(int*)&headerInfo[22];
int bitDepth = *(int*)&headerInfo[28];
int pixelsInImage = height * width;

// calculate size of image in pixels
int size = height * width;

// check if image has a color table
// Check if image has a color table
if(bitDepth <= 8) {
// read, then write color table from the input file
fread(colorTable, sizeof(unsigned char), 1024, fileIn);
fwrite(colorTable, sizeof(unsigned char), 1024, fileOut);
}

// array to store image data in chunks
unsigned char buffer[CHUNK_SIZE];
unsigned char chunkBuffer[CHUNK_SIZE];

// read & write image data in chunks until the end of file is reached
// Read & write image data in chunks until the end of file is reached
while(!feof(fileIn)) {

// read a chunk of image data from input file
size_t bytesRead = fread(buffer, sizeof(unsigned char), CHUNK_SIZE, fileIn);

// apply brightness factor to each pixel in the chunk
for (i = 0; i < bytesRead; i++) {
buffer[i] = buffer[i] + BRIGHTNESS;
buffer[i] = (buffer[i] > THRESHOLD) ? MAX_COLOR : buffer[i];
// Read a chunk of image data from the input file
size_t bytesRead = fread(chunkBuffer, sizeof(unsigned char), CHUNK_SIZE, fileIn);

// Apply brightness factor to each pixel in the chunk
for (int i = 0; i < bytesRead; i++) {
chunkBuffer[i] = chunkBuffer[i] + BRIGHTNESS;
chunkBuffer[i] = (chunkBuffer[i] > THRESHOLD) ? MAX_COLOR : chunkBuffer[i];
}

// write thresholded image data to the output file
fwrite(buffer, sizeof(unsigned char), bytesRead, fileOut);
// Write thresholded image data to output file
fwrite(chunkBuffer, sizeof(unsigned char), bytesRead, fileOut);
}

// write thresholded image data to the output file
fwrite(buffer, sizeof(unsigned char), size, fileOut);
// Write thresholded image data to output file
fwrite(chunkBuffer, sizeof(unsigned char), pixelsInImage, fileOut);

fClose(fileIn);
fclose(fileOut);
Expand Down
50 changes: 23 additions & 27 deletions C_image_processing/filters/dark_filter.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdio.h>

#define MAX_COLOR 255
#define THRESHOLD 40 // define threshold value for darkness
#define CHUNK_SIZE 1024 // define size of chunks to read and write
Expand All @@ -15,53 +16,48 @@ int dark_filter(inputFile, outputFile) {
return 1;
}

int i;
unsigned char byte[54]; // store header info of image
unsigned char colorTable[1024]; // store color table of image
unsigned char headerInfo[54];
unsigned char colorTable[1024];

// read header information of image
for(i = 0; i < 54; i++) {
byte[i] = getc(fileIn);
// Read header info of image
for(int i = 0; i < 54; i++) {
headerInfo[i] = getc(fileIn);
}

// write header info to output file
fwrite(byte, sizeof(unsigned char), 54, fileOut);

// extract height, width and bitDepth of the image from header information
int height = *(int*)&byte[18];
int width = *(int*)&byte[22];
int bitDepth = *(int*)&byte[28];
// Write header info to output file
fwrite(headerInfo, sizeof(unsigned char), 54, fileOut);

// calculate size of image in pixels
int size = height * width;
// Extract.. of the image from header info
int height = *(int*)&headerInfo[18];
int width = *(int*)&headerInfo[22];
int bitDepth = *(int*)&headerInfo[28];
int pixelsInImage = height * width;

// check if image has a color table
// Check if image has a color table
if(bitDepth <= 8) {
// read, then write the color table from input file
fread(colorTable, sizeof(unsigned char), 1024, fileIn);
fwrite(colorTable, sizeof(unsigned char), 1024, fileOut);
}

// array to store image data in chunks
unsigned char buffer[CHUNK_SIZE];
unsigned char chunkBuffer[CHUNK_SIZE];

// read & write image data in chunks until end of the file reached
// Read & write image data in chunks until end of file reached
while(!feof(fileIn)) {

// read a chunk of image data from input file
size_t bytesRead = fread(buffer, sizeof(unsigned char), CHUNK_SIZE, fileIn);
size_t bytesRead = fread(chunkBuffer, sizeof(unsigned char), CHUNK_SIZE, fileIn);

// apply darkness threshold to each pixel in chunk
for (i = 0; i < bytesRead; i++) {
buffer[i] = buffer[i] + THRESHOLD;
buffer[i] = (buffer[i] > THRESHOLD) ? MAX_COLOR : buffer[i];
for (int i = 0; i < bytesRead; i++) {
chunkBuffer[i] = chunkBuffer[i] + THRESHOLD;
chunkBuffer[i] = (chunkBuffer[i] > THRESHOLD) ? MAX_COLOR : chunkBuffer[i];
}
// write thresholded image data to the output file
fwrite(buffer, sizeof(unsigned char), bytesRead, fileOut);
fwrite(chunkBuffer, sizeof(unsigned char), bytesRead, fileOut);
}

// write thresholded image data to the output file
fwrite(buffer, sizeof(unsigned char), size, fileOut);
// Write thresholded image data to output file
fwrite(chunkBuffer, sizeof(unsigned char), pixelsInImage, fileOut);

fClose(fileIn);
fclose(fileOut);
Expand Down
Loading