Skip to content

Commit df72e07

Browse files
authored
Merge pull request #2 from VerzatileDev/main
Refactored Codebase 2
2 parents 950e046 + 3f590c1 commit df72e07

File tree

10 files changed

+230
-160
lines changed

10 files changed

+230
-160
lines changed

C_image_processing/.gitignore

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@ dkms.conf
7676
# Executables
7777

7878
### VisualStudioCode ###
79-
.vscode/*
80-
!.vscode/settings.json
81-
!.vscode/tasks.json
82-
!.vscode/launch.json
83-
!.vscode/extensions.json
84-
!.vscode/*.code-snippets
79+
*.vscode
80+
#!.vscode/c_cpp_properties.json
81+
#!.vscode/settings.json # user Specific
82+
#!.vscode/tasks.json
83+
#!.vscode/launch.json # user Specific
84+
#!.vscode/extensions.json
85+
#!.vscode/*.code-snippets
8586

8687
# Local History for Visual Studio Code
8788
.history/
@@ -120,7 +121,5 @@ $RECYCLE.BIN/
120121
# Windows shortcuts
121122
*.lnk
122123

123-
# End of https://www.toptal.com/developers/gitignore/api/windows,visualstudiocode,c,c++
124-
125124
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
126125
output.bmp
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Win32",
5+
"includePath": [
6+
"${workspaceFolder}/**",
7+
"C:/msys64/mingw64/include/gtk-4.0",
8+
"C:/msys64/mingw64/include/glib-2.0",
9+
"C:/msys64/mingw64/include/**",
10+
"C:/msys64/mingw64/lib/**"
11+
],
12+
"defines": [
13+
"_DEBUG",
14+
"UNICODE",
15+
"_UNICODE"
16+
],
17+
"windowsSdkVersion": "10.0.22000.0",
18+
"compilerPath": "C:/msys64/mingw64/bin/gcc.exe",
19+
"cStandard": "c17",
20+
"cppStandard": "c++17",
21+
"intelliSenseMode": "windows-gcc-x64"
22+
}
23+
],
24+
"version": 4
25+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "cppbuild",
6+
"label": "C/C++: gcc.exe build active file",
7+
"command": "C:/msys64/mingw64/bin/gcc.exe",
8+
"args": [
9+
"-fdiagnostics-color=always",
10+
"-g",
11+
"-IC:/msys64/mingw64/include/gtk-4.0",
12+
"-IC:/msys64/mingw64/include/pango-1.0",
13+
"-IC:/msys64/mingw64/include",
14+
"-IC:/msys64/mingw64/include/glib-2.0",
15+
"-IC:/msys64/mingw64/lib/glib-2.0/include",
16+
"-IC:/msys64/mingw64/include/harfbuzz",
17+
"-IC:/msys64/mingw64/include/freetype2",
18+
"-IC:/msys64/mingw64/include/libpng16",
19+
"-IC:/msys64/mingw64/include/fribidi",
20+
"-IC:/msys64/mingw64/include/cairo",
21+
"-IC:/msys64/mingw64/include/pixman-1",
22+
"-IC:/msys64/mingw64/include/gdk-pixbuf-2.0",
23+
"-IC:/msys64/mingw64/include/webp",
24+
"-DLIBDEFLATE_DLL",
25+
"-IC:/msys64/mingw64/include/graphene-1.0",
26+
"-IC:/msys64/mingw64/lib/graphene-1.0/include",
27+
"-mfpmath=sse",
28+
"-msse",
29+
"-msse2",
30+
31+
"${file}",
32+
33+
"-LC:/msys64/mingw64/lib",
34+
"-lgtk-4",
35+
"-lpangowin32-1.0",
36+
"-lpangocairo-1.0",
37+
"-lpango-1.0",
38+
"-lharfbuzz",
39+
"-lgdk_pixbuf-2.0",
40+
"-lcairo-gobject",
41+
"-lcairo",
42+
"-lgraphene-1.0",
43+
"-lgio-2.0",
44+
"-lgobject-2.0",
45+
"-lglib-2.0",
46+
"-lintl",
47+
48+
"-o",
49+
"${fileDirname}\\${fileBasenameNoExtension}.exe"
50+
],
51+
"options": {
52+
"cwd": "C:/msys64/mingw64/bin"
53+
},
54+
"problemMatcher": [
55+
"$gcc"
56+
],
57+
"group": "build",
58+
"detail": "compiler: C:/msys64/mingw64/bin/gcc.exe"
59+
}
60+
]
61+
}

C_image_processing/filters/black_and_white_filter.c

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <stdio.h>
2+
23
#define THRESHOLD 128 // define value of threshold for black and white
34
#define WHITE 255
45
#define BLACK 0
@@ -16,48 +17,45 @@ int black_and_white_filter(const char *inputFile, const char *outputFile) {
1617
return 1;
1718
}
1819

19-
int i;
20-
unsigned char byte[54];
20+
unsigned char headerInfo[54];
2121
unsigned char colorTable[1024];
2222

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

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

31-
// extract height, width and bitDepth of image from the header information
32-
int height = *(int*)&byte[18];
33-
int width = *(int*)&byte[22];
34-
int bitDepth = *(int*)&byte[28];
31+
// Extract.. of image from the header information
32+
int height = *(int*)&headerInfo[18];
33+
int width = *(int*)&headerInfo[22];
34+
int bitDepth = *(int*)&headerInfo[28];
3535
int size = height * width;
3636

37-
// check if the image has a color table
37+
// Check if the image has a color table
3838
if(bitDepth <= 8) {
39-
// read, and then write the color table from the input file
4039
fread(colorTable, sizeof(unsigned char), 1024, fileIn);
4140
fwrite(colorTable, sizeof(unsigned char), 1024, fileOut);
4241
}
42+
43+
unsigned char chunkBuffer[CHUNK_SIZE];
4344

44-
// array to store the image data in chunks
45-
unsigned char buffer[CHUNK_SIZE];
46-
47-
// read and write the image data in chunks until the end of the file is reached
45+
// Read & write the image data in chunks until the end of file is reached
4846
while(!feof(fileIn)) {
4947

50-
// read a chunk of image data from the input file
51-
size_t bytesRead = fread(buffer, sizeof(unsigned char), CHUNK_SIZE, fileIn);
48+
// Read a chunk of image data from input file
49+
size_t bytesRead = fread(chunkBuffer, sizeof(unsigned char), CHUNK_SIZE, fileIn);
5250

53-
// apply the threshold to each pixel in the chunk
54-
for(i = 0; i < bytesRead; i++) {
55-
buffer[i] = (buffer[i] > THRESHOLD)
51+
// Apply threshold to each pixel in the chunk
52+
for(int i = 0; i < bytesRead; i++) {
53+
chunkBuffer[i] = (chunkBuffer[i] > THRESHOLD)
5654
? WHITE
5755
: BLACK;
5856
}
59-
// write the thresholded image data to the output file
60-
fwrite(buffer, sizeof(unsigned char), bytesRead, fileOut);
57+
// Write the thresholded image data to the output file
58+
fwrite(chunkBuffer, sizeof(unsigned char), bytesRead, fileOut);
6159
}
6260

6361
fclose(fileIn);

C_image_processing/filters/bright_filter.c

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <stdio.h>
22
#include <stdlib.h>
3+
34
#define MAX_COLOR 255
45
#define BRIGHTNESS 25
56
#define CHUNK_SIZE 1024 // define size of the chunks to read and write
@@ -17,54 +18,47 @@ int bright_filter(inputFile, outputFile) {
1718
return 1;
1819
}
1920

20-
int i;
21-
unsigned char byte[54]; // store header info of image
22-
unsigned char colorTable[1024]; // store color table of image
23-
24-
// read the header info of image
25-
for(i = 0; i < 54; i++) {
26-
byte[i] = getc(fileIn);
21+
unsigned char headerInfo[54];
22+
unsigned char colorTable[1024];
23+
24+
for(int i = 0; i < 54; i++) {
25+
headerInfo[i] = getc(fileIn);
2726
}
2827

29-
// write header info to output file
30-
fwrite(byte, sizeof(unsigned char), 54, fileOut);
28+
fwrite(headerInfo, sizeof(unsigned char), 54, fileOut);
3129

32-
// extract height, width and bitDepth of image from header info
33-
int height = *(int*)&byte[18];
34-
int width = *(int*)&byte[22];
35-
int bitDepth = *(int*)&byte[28];
30+
// Extract.. of image from header info
31+
int height = *(int*)&headerInfo[18];
32+
int width = *(int*)&headerInfo[22];
33+
int bitDepth = *(int*)&headerInfo[28];
34+
int pixelsInImage = height * width;
3635

37-
// calculate size of image in pixels
38-
int size = height * width;
39-
40-
// check if image has a color table
36+
// Check if image has a color table
4137
if(bitDepth <= 8) {
42-
// read, then write color table from the input file
4338
fread(colorTable, sizeof(unsigned char), 1024, fileIn);
4439
fwrite(colorTable, sizeof(unsigned char), 1024, fileOut);
4540
}
4641

47-
// array to store image data in chunks
48-
unsigned char buffer[CHUNK_SIZE];
42+
unsigned char chunkBuffer[CHUNK_SIZE];
4943

50-
// read & write image data in chunks until the end of file is reached
44+
// Read & write image data in chunks until the end of file is reached
5145
while(!feof(fileIn)) {
52-
53-
// read a chunk of image data from input file
54-
size_t bytesRead = fread(buffer, sizeof(unsigned char), CHUNK_SIZE, fileIn);
5546

56-
// apply brightness factor to each pixel in the chunk
57-
for (i = 0; i < bytesRead; i++) {
58-
buffer[i] = buffer[i] + BRIGHTNESS;
59-
buffer[i] = (buffer[i] > THRESHOLD) ? MAX_COLOR : buffer[i];
47+
// Read a chunk of image data from the input file
48+
size_t bytesRead = fread(chunkBuffer, sizeof(unsigned char), CHUNK_SIZE, fileIn);
49+
50+
// Apply brightness factor to each pixel in the chunk
51+
for (int i = 0; i < bytesRead; i++) {
52+
chunkBuffer[i] = chunkBuffer[i] + BRIGHTNESS;
53+
chunkBuffer[i] = (chunkBuffer[i] > THRESHOLD) ? MAX_COLOR : chunkBuffer[i];
6054
}
6155

62-
// write thresholded image data to the output file
63-
fwrite(buffer, sizeof(unsigned char), bytesRead, fileOut);
56+
// Write thresholded image data to output file
57+
fwrite(chunkBuffer, sizeof(unsigned char), bytesRead, fileOut);
6458
}
6559

66-
// write thresholded image data to the output file
67-
fwrite(buffer, sizeof(unsigned char), size, fileOut);
60+
// Write thresholded image data to output file
61+
fwrite(chunkBuffer, sizeof(unsigned char), pixelsInImage, fileOut);
6862

6963
fClose(fileIn);
7064
fclose(fileOut);

C_image_processing/filters/dark_filter.c

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <stdio.h>
2+
23
#define MAX_COLOR 255
34
#define THRESHOLD 40 // define threshold value for darkness
45
#define CHUNK_SIZE 1024 // define size of chunks to read and write
@@ -15,53 +16,48 @@ int dark_filter(inputFile, outputFile) {
1516
return 1;
1617
}
1718

18-
int i;
19-
unsigned char byte[54]; // store header info of image
20-
unsigned char colorTable[1024]; // store color table of image
19+
unsigned char headerInfo[54];
20+
unsigned char colorTable[1024];
2121

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

27-
// write header info to output file
28-
fwrite(byte, sizeof(unsigned char), 54, fileOut);
29-
30-
// extract height, width and bitDepth of the image from header information
31-
int height = *(int*)&byte[18];
32-
int width = *(int*)&byte[22];
33-
int bitDepth = *(int*)&byte[28];
27+
// Write header info to output file
28+
fwrite(headerInfo, sizeof(unsigned char), 54, fileOut);
3429

35-
// calculate size of image in pixels
36-
int size = height * width;
30+
// Extract.. of the image from header info
31+
int height = *(int*)&headerInfo[18];
32+
int width = *(int*)&headerInfo[22];
33+
int bitDepth = *(int*)&headerInfo[28];
34+
int pixelsInImage = height * width;
3735

38-
// check if image has a color table
36+
// Check if image has a color table
3937
if(bitDepth <= 8) {
40-
// read, then write the color table from input file
4138
fread(colorTable, sizeof(unsigned char), 1024, fileIn);
4239
fwrite(colorTable, sizeof(unsigned char), 1024, fileOut);
4340
}
4441

45-
// array to store image data in chunks
46-
unsigned char buffer[CHUNK_SIZE];
42+
unsigned char chunkBuffer[CHUNK_SIZE];
4743

48-
// read & write image data in chunks until end of the file reached
44+
// Read & write image data in chunks until end of file reached
4945
while(!feof(fileIn)) {
5046

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

5450
// apply darkness threshold to each pixel in chunk
55-
for (i = 0; i < bytesRead; i++) {
56-
buffer[i] = buffer[i] + THRESHOLD;
57-
buffer[i] = (buffer[i] > THRESHOLD) ? MAX_COLOR : buffer[i];
51+
for (int i = 0; i < bytesRead; i++) {
52+
chunkBuffer[i] = chunkBuffer[i] + THRESHOLD;
53+
chunkBuffer[i] = (chunkBuffer[i] > THRESHOLD) ? MAX_COLOR : chunkBuffer[i];
5854
}
5955
// write thresholded image data to the output file
60-
fwrite(buffer, sizeof(unsigned char), bytesRead, fileOut);
56+
fwrite(chunkBuffer, sizeof(unsigned char), bytesRead, fileOut);
6157
}
6258

63-
// write thresholded image data to the output file
64-
fwrite(buffer, sizeof(unsigned char), size, fileOut);
59+
// Write thresholded image data to output file
60+
fwrite(chunkBuffer, sizeof(unsigned char), pixelsInImage, fileOut);
6561

6662
fClose(fileIn);
6763
fclose(fileOut);

0 commit comments

Comments
 (0)