-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc_code_en.html
1067 lines (979 loc) · 33 KB
/
c_code_en.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<!-- <meta http-equiv="refresh" content="10" /> -->
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2"
crossorigin="anonymous"
/>
<script
src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
crossorigin="anonymous"
></script>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx"
crossorigin="anonymous"
></script>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"
/>
<link href="./assets/styles/styles.css" rel="stylesheet" />
<link
href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/themes/prism.min.css"
rel="stylesheet"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="./assets/main_img/coding.svg"
/>
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
/>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css"
/>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function () {
window.onscroll = function () {
myFunction();
};
var navbar = document.getElementById("navbar");
var sticky = navbar.offsetTop;
function myFunction() {
if (window.pageYOffset >= sticky) {
navbar.classList.add("sticky");
} else {
navbar.classList.remove("sticky");
}
}
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/prism.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/components/prism-c.min.js"></script>
<!-- <script src="./assets/js/app.js"></script> -->
<title>C code</title>
</head>
<body>
<div class="header">
<h1></h1>
<p></p>
<a href="project_en.html" class="button" style="background-color: #42cc8c"
>Back to my projects</a
>
</div>
<div id="navbar">
<div class="menu-container">
<div class="hamburger-menu">
<div></div>
<div></div>
<div></div>
</div>
<span class="menu-label">Menu</span>
</div>
<div class="navbar-links">
<!-- <a href="index.html">Home</a> -->
<a href="portfolio_en.html">Home</a>
<a class="active" href="project_en.html">Projects</a>
<!-- <a href="resume.html">Resume</a> -->
<a href="course_path_en.html">Study & Resources</a>
<!-- <a href="contact.html">Contact</a> -->
<a href="https://github.com/Jer-B/" target="_blank">Github</a>
</div>
</div>
<section class="hero" id="about">
<img
src="./assets/pages_img/projects.svg"
alt=""
loading="lazy"
class="hero-img"
/>
<div class="bio animate__animated animate__shakeX">
<h2 class="bio-title">C Project</h2>
<p class="bio-text">「Photo Filter」</p>
</div>
</section>
<section class="projects" id="projects">
<div class="card-code">
<h3 class="grid-title">C・Photo Filter</h3>
<div class="details-container">
<div class="c-content">
<h3>Content</h3>
<p>
This program allows you to edit the photo itself by entering the
photo name, path, filter type as parameters.<br />
Examples: changing the color of the photo, applying blur, and
mirror effects.<br /><br />
Language: C<br />
I have posted the code below for testing.<br />
</p>
<ol>
<li>
Create the files filter.c, helpers.c, bmp.h, and helpers.h in
the same folder.
</li>
<li>Parameters for filter effects:</li>
<ul>
<li>-b (Blur)</li>
<li>-g (Grayscale)</li>
<li>-r (Reflection)</li>
<li>-s (Sepia)</li>
<li>-e (Edge)</li>
</ul>
<li>Compile.</li>
<li>
Run the program with the command which is in the "How to use"
section. The parameter is set to -g.
</li>
</ol>
<h3>How to use</h3>
<p>Execute the following command to run the program:</p>
<p>./filter -g images/yard.bmp out.bmp</p>
</div>
</div>
<div class="grid-container">
<!-- Image and link 1 -->
<div class="photo-code">
<p class="photo-name">「Original」</p>
<img
class="img-code"
src="./assets/code_img/c/yard.bmp"
alt="Original"
/>
<a href="./assets/code_img/c/yard.bmp" target="_blank"
>View original size</a
>
</div>
<div class="photo-code">
<p class="photo-name">「Blur」</p>
<img
class="img-code"
src="./assets/code_img/c/blur.JPG"
alt="Original"
/>
<a href="./assets/code_img/c/blur.JPG" target="_blank"
>View original size</a
>
</div>
<div class="photo-code">
<p class="photo-name">「Grayscale」</p>
<img
class="img-code"
src="./assets/code_img/c/grayscale.JPG"
alt="Original"
/>
<a href="./assets/code_img/c/grayscale.JPG" target="_blank"
>View original size</a
>
</div>
<div class="photo-code">
<p class="photo-name">「Reflection」</p>
<img
class="img-code"
src="./assets/code_img/c/reflect.JPG"
alt="Original"
/>
<a href="./assets/code_img/c/reflect.JPG" target="_blank"
>View original size</a
>
</div>
<div class="photo-code">
<p class="photo-name">「Sepia」</p>
<img
class="img-code"
src="./assets/code_img/c/Sepia.JPG"
alt="Original"
/>
<a href="./assets/code_img/c/Sepia.JPG" target="_blank"
>View original size</a
>
</div>
<div class="photo-code">
<p class="photo-name">「Blur blue_sum=green」</p>
<img
class="img-code"
src="./assets/code_img/c/blur_blue_sum=green.JPG"
alt="Original"
/>
<a
href="./assets/code_img/c/blur_blue_sum=green.JPG"
target="_blank"
>View original size</a
>
</div>
<div class="photo-code">
<p class="photo-name">「Edge」</p>
<img
class="img-code"
src="./assets/code_img/c/Edge_out.bmp"
alt="Original"
/>
<a href="./assets/code_img/c/Edge_out.bmp" target="_blank"
>View original size</a
>
</div>
<!-- Details Container -->
</div>
<!-- <section class="skills2" id="skills">
<h4 class="skill-header">言語</h4>
<div class="skills-wrapper">
<div class="first-set animate__animated animate__pulse">
<img
src="./assets/skill_icons/c.svg"
alt=""
loading="lazy"
class="icon2 icon-card"
/>
</div>
</div>
</section> -->
<div class="c-content">
<a
href="project_en.html"
class="project-link, button"
style="background-color: #99e9c4"
>Back to my projects</a
>
<!-- <button class="btn-card btn--block card__btn"><a class="btn-link" href="https://portofolio-finance.herokuapp.com/" target="_blank" class="project-link">Check it Out</a></button> -->
</div>
</div>
<!-- C photo filter -->
<!-- <div class="card-code">
<div class="row-code">
<div class="avatar-container-code">
<div class="photo-code">
<p class="photo-name">
「Original」
<a href="./assets/code_img/c/yard.bmp" target="_blank"
>元サイズの写真へ</a
>
</p>
<img class="img-code" src="./assets/code_img/c/yard.bmp" />
<p class="photo-name">
「Blur」
<a href="./assets/code_img/c/blur.JPG" target="_blank"
>元サイズの写真へ</a
>
</p>
<img class="img-code" src="./assets/code_img/c/blur.JPG" />
<p class="photo-name">
「Grayscale」
<a href="./assets/code_img/c/grayscale.JPG" target="_blank"
>元サイズの写真へ</a
>
</p>
<img class="img-code" src="./assets/code_img/c/grayscale.JPG" />
<p class="photo-name">
「Reflection」
<a href="./assets/code_img/c/reflect.JPG" target="_blank"
>元サイズの写真へ</a
>
</p>
<img class="img-code" src="./assets/code_img/c/reflect.JPG" />
<p class="photo-name">
「Sepia」
<a href="./assets/code_img/c/Sepia.JPG" target="_blank"
>元サイズの写真へ</a
>
</p>
<img class="img-code" src="./assets/code_img/c/Sepia.JPG" />
<p>
「Blur + blue_sum=green」<br />
<a
href="./assets/code_img/c/blur_blue_sum=green.JPG"
target="_blank"
>元サイズの写真へ</a
>
</p>
<img
class="img-code"
src="./assets/code_img/c/blur_blue_sum=green.JPG"
/>
<p class="photo-name">
「Edge」
<a href="./assets/code_img/c/Edge_out.bmp" target="_blank"
>元サイズの写真へ</a
>
</p>
<img class="img-code" src="./assets/code_img/c/Edge_out.bmp" />
</div>
</div>
<div class="details-container">
<div class="c-content">
<h3>写真フィルター・プログラム</h3>
<p>
プログラムにパラメーターとして写真名とパスを入れて、写真自体を編集する事が出来るプログラムです。<br />
例:写真の色を変えたり、ぼかし加工、ミラーエフェクトなど。<br /><br />
言語: C<br />
テストのため下にコードを載せました。<br />
</p>
<ol>
<li>
同じフォルダーにfilter.c、helpers.c、bmp.h、helpers.h、のファイルを作成する。
</li>
<li>フィルターエフェクトのパラメーター:</li>
<ul>
<li>-b (Blur)</li>
<li>-g (Grayscale)</li>
<li>-r (Reflection)</li>
<li>-s (Sepia)</li>
<li>-e (Edge)</li>
</ul>
<li>コンパイルする。</li>
<li>
このコマンドでプログラムを実行する。パラメーターは-gとなっています。
</li>
</ol>
<p>./filter -g images/yard.bmp out.bmp</p>
<a
href="project.html"
class="project-link, button"
style="background-color: #99e9c4"
>プロジェクト・ページへ戻る</a
>
</div>
</div>
</div>
<section class="skills2" id="skills">
<h4 class="skill-header">ツール</h4>
<div class="skills-wrapper">
<div class="first-set animate__animated animate__pulse">
<img
src="./assets/skill_icons/c.svg"
alt=""
loading="lazy"
class="icon2 icon-card"
/>
</div>
</div>
</section>
</div> -->
<!-- filter.c -->
<div class="card">
<div class="row">
<div class="details-container">
<div class="content">
<h3 class="h3code">
filter.c<button class="copy-btn">
<i class="fas fa-copy"></i>
</button>
</h3>
<figcaption>
<pre><code class="language-c">
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include "helpers.h"
int main(int argc, char *argv[])
{
// Define allowable filters
char *filters = "bgrs";
// Get filter flag and check validity
char filter = getopt(argc, argv, filters);
if (filter == '?')
{
fprintf(stderr, "Invalid filter.\n");
return 1;
}
// Ensure only one filter
if (getopt(argc, argv, filters) != -1)
{
fprintf(stderr, "Only one filter allowed.\n");
return 2;
}
// Ensure proper usage
if (argc != optind + 2)
{
fprintf(stderr, "Usage: filter [flag] infile outfile\n");
return 3;
}
// Remember filenames
char *infile = argv[optind];
char *outfile = argv[optind + 1];
// Open input file
FILE *inptr = fopen(infile, "r");
if (inptr == NULL)
{
fprintf(stderr, "Could not open %s.\n", infile);
return 4;
}
// Open output file
FILE *outptr = fopen(outfile, "w");
if (outptr == NULL)
{
fclose(inptr);
fprintf(stderr, "Could not create %s.\n", outfile);
return 5;
}
// Read infile's BITMAPFILEHEADER
BITMAPFILEHEADER bf;
fread(&bf, sizeof(BITMAPFILEHEADER), 1, inptr);
// Read infile's BITMAPINFOHEADER
BITMAPINFOHEADER bi;
fread(&bi, sizeof(BITMAPINFOHEADER), 1, inptr);
// Ensure infile is (likely) a 24-bit uncompressed BMP 4.0
if (bf.bfType != 0x4d42 || bf.bfOffBits != 54 || bi.biSize != 40 ||
bi.biBitCount != 24 || bi.biCompression != 0)
{
fclose(outptr);
fclose(inptr);
fprintf(stderr, "Unsupported file format.\n");
return 6;
}
int height = abs(bi.biHeight);
int width = bi.biWidth;
// Allocate memory for image
RGBTRIPLE(*image)[width] = calloc(height, width * sizeof(RGBTRIPLE));
if (image == NULL)
{
fprintf(stderr, "Not enough memory to store image.\n");
fclose(outptr);
fclose(inptr);
return 7;
}
// Determine padding for scanlines
int padding = (4 - (width * sizeof(RGBTRIPLE)) % 4) % 4;
// Iterate over infile's scanlines
for (int i = 0; i < height; i++)
{
// Read row into pixel array
fread(image[i], sizeof(RGBTRIPLE), width, inptr);
// Skip over padding
fseek(inptr, padding, SEEK_CUR);
}
// Filter image
switch (filter)
{
// Blur
case 'b':
blur(height, width, image);
break;
// Grayscale
case 'g':
grayscale(height, width, image);
break;
// Reflection
case 'r':
reflect(height, width, image);
break;
// Edges
case 'e':
edges(height, width, image);
break;
// Sepia
case 's':
sepia(height, width, image);
break;
}
// Write outfile's BITMAPFILEHEADER
fwrite(&bf, sizeof(BITMAPFILEHEADER), 1, outptr);
// Write outfile's BITMAPINFOHEADER
fwrite(&bi, sizeof(BITMAPINFOHEADER), 1, outptr);
// Write new pixels to outfile
for (int i = 0; i < height; i++)
{
// Write row to outfile
fwrite(image[i], sizeof(RGBTRIPLE), width, outptr);
// Write padding at end of row
for (int k = 0; k < padding; k++)
{
fputc(0x00, outptr);
}
}
// Free memory for image
free(image);
// Close infile
fclose(inptr);
// Close outfile
fclose(outptr);
return 0;
}
</code></pre>
</figcaption>
</div>
</div>
</div>
</div>
<!-- Bmp.h -->
<div class="card">
<div class="row">
<div class="details-container">
<div class="content">
<h3 class="h3code">
bmp.h<button class="copy-btn">
<i class="fas fa-copy"></i>
</button>
</h3>
<pre><code class="language-c">
// BMP-related data types based on Microsoft's own
#include <stdint.h>
/**
* Common Data Types
*
* The data types in this section are essentially aliases for C/C++
* primitive data types.
*
* Adapted from http://msdn.microsoft.com/en-us/library/cc230309.aspx.
* See http://en.wikipedia.org/wiki/Stdint.h for more on stdint.h.
*/
typedef uint8_t BYTE;
typedef uint32_t DWORD;
typedef int32_t LONG;
typedef uint16_t WORD;
/**
* BITMAPFILEHEADER
*
* The BITMAPFILEHEADER structure contains information about the type, size,
* and layout of a file that contains a DIB [device-independent bitmap].
*
* Adapted from http://msdn.microsoft.com/en-us/library/dd183374(VS.85).aspx.
*/
typedef struct
{
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
} __attribute__((__packed__))
BITMAPFILEHEADER;
/**
* BITMAPINFOHEADER
*
* The BITMAPINFOHEADER structure contains information about the
* dimensions and color format of a DIB [device-independent bitmap].
*
* Adapted from http://msdn.microsoft.com/en-us/library/dd183376(VS.85).aspx.
*/
typedef struct
{
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} __attribute__((__packed__))
BITMAPINFOHEADER;
/**
* RGBTRIPLE
*
* This structure describes a color consisting of relative intensities of
* red, green, and blue.
*
* Adapted from http://msdn.microsoft.com/en-us/library/aa922590.aspx.
*/
typedef struct
{
BYTE rgbtBlue;
BYTE rgbtGreen;
BYTE rgbtRed;
} __attribute__((__packed__))
RGBTRIPLE;
</code></pre>
</div>
</div>
</div>
</div>
<!-- helpers.h -->
<div class="card">
<div class="row">
<div class="details-container">
<div class="content">
<h3 class="h3code">
helpers.h<button class="copy-btn">
<i class="fas fa-copy"></i>
</button>
</h3>
<pre><code class="language-c">
#include "bmp.h"
// Convert image to grayscale
void grayscale(int height, int width, RGBTRIPLE image[height][width]);
// Convert image to sepia
void sepia(int height, int width, RGBTRIPLE image[height][width]);
// Reflect image horizontally
void reflect(int height, int width, RGBTRIPLE image[height][width]);
// Detect edges
void edges(int height, int width, RGBTRIPLE image[height][width]);
// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width]);
</code></pre>
</div>
</div>
</div>
</div>
<!-- helpers.c -->
<div class="card">
<div class="row">
<div class="details-container">
<div class="content">
<h3 class="h3code">
helpers.c<button class="copy-btn">
<i class="fas fa-copy"></i>
</button>
</h3>
<pre><code class="language-c">
/*
description: Photo filters: Grayscale, blur, reflect and sepia
@file filter.c
@author Jeremy B.
@version 1.0 3 Nov 2020
*/
#include "helpers.h"
#include <math.h>
// Convert image to grayscale
void grayscale(int height, int width, RGBTRIPLE image[height][width])
{
//2D arrays calculating color for each pixel and do an average of it to replace on the original
//divide sum of colors value by 3.0 for average being rounded
// row
for (int i = 0; i < height; i++)
{
// column
for (int j = 0; j < width; j++)
{
RGBTRIPLE pixel = image[i][j];
int avg = round((pixel.rgbtRed + pixel.rgbtGreen + pixel.rgbtBlue) / 3.0);
image[i][j].rgbtRed = image[i][j].rgbtGreen = image[i][j].rgbtBlue = avg;
}
}
return;
}
// Convert image to sepia
void sepia(int height, int width, RGBTRIPLE image[height][width])
{
//2D arrays calculating color for each pixel using cs50 - pset4 given formula for sepia pixel
//pixel value must not go over 255 and should be capped at 255 if over, value must be rounded
//row
for (int i = 0; i < height; i++)
{
//column
for (int j = 0; j < width; j++)
{
RGBTRIPLE pixel = image[i][j];
int sepiaRed = round(.393 * pixel.rgbtRed + .769 * pixel.rgbtGreen + .189 * pixel.rgbtBlue);
int sepiaGreen = round(.349 * pixel.rgbtRed + .686 * pixel.rgbtGreen + .168 * pixel.rgbtBlue);
int sepiaBlue = round(.272 * pixel.rgbtRed + .534 * pixel.rgbtGreen + .131 * pixel.rgbtBlue);
//if value over 255, capped at 255 and original value replacement
if (sepiaRed > 255)
{
sepiaRed = 255;
image[i][j].rgbtRed = sepiaRed;
}
else
{
image[i][j].rgbtRed = sepiaRed;
}
if (sepiaGreen > 255)
{
sepiaGreen = 255;
image[i][j].rgbtGreen = sepiaGreen;
}
else
{
image[i][j].rgbtGreen = sepiaGreen;
}
if (sepiaBlue > 255)
{
sepiaBlue = 255;
image[i][j].rgbtBlue = sepiaBlue;
}
else
{
image[i][j].rgbtBlue = sepiaBlue;
}
}
}
return;
}
// Reflect image horizontally
void reflect(int height, int width, RGBTRIPLE image[height][width])
{
//setting swap
RGBTRIPLE swap[height][width];
//2D array with an invert reading row and target pixel to swap
for (int i = 0; i < height; i++)
{
//target pixel to swap at first position in a row
int target = 0;
//reverse reading, target current pixel
for (int j = width - 1; j >= 0; j--, target++)
{
swap[i][target] = image[i][j];
}
}
//swap loop
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
image[i][j] = swap[i][j];
}
}
return;
}
// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
//set swap color
RGBTRIPLE swap[height][width];
//image row
for (int i = 0; i < height; i++)
{
//image column
for (int j = 0; j < width; j++)
{
//set sum RGB
float sum_red = 0;
float sum_blue = 0;
float sum_green = 0;
//set counter
int counter = 0;
//set 2 area array, row and column for looking around current pixel
int row_area[] = {i - 1, i, i + 1};
int col_area[] = {j - 1, j, j + 1};
//loop row area, up - current - down, around targeted pixel
for (int row = 0; row < 3; row++)
{
//loop column area, left side - current - right side, around targeted pixel
for (int col = 0; col < 3; col++)
{
//set current
int row_current = row_area[row];
int col_current = col_area[col];
if (row_current >= 0 && row_current < height && col_current >= 0 && col_current < width)
{
RGBTRIPLE pixel = image[row_current][col_current];
//sum total of current pixel iterations (and around area) for each colors
sum_red += pixel.rgbtRed;
sum_green += pixel.rgbtGreen;
sum_blue += pixel.rgbtBlue;
//counter++
counter++;
}
}
}
//determine value of total / count into swap
swap[i][j].rgbtRed = round(sum_red / counter);
swap[i][j].rgbtGreen = round(sum_green / counter);
swap[i][j].rgbtBlue = round(sum_blue / counter);
}
}
//swap loop
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
image[i][j] = swap[i][j];
}
}
return;
}
// Detect edges
void edges(int height, int width, RGBTRIPLE image[height][width])
{
//set swap
RGBTRIPLE swap[height][width];
//sobel operator algorithm
//Gx kernel 3x3
int Gx[3][3] =
{
{-1, 0, 1},
{-2, 0, 2},
{-1, 0, 1}
};
//Gy Kernel 3x3
int Gy[3][3] =
{
{-1, -2, -1},
{0, 0, 0},
{1, 2, 1}
};
//image row
for (int i = 0; i < height; i++)
{
//image column
for (int j = 0; j < width; j++)
{
//set Gx RGB
float Gx_red = 0;
float Gx_blue = 0;
float Gx_green = 0;
//set Gy RGB
float Gy_red = 0;
float Gy_blue = 0;
float Gy_green = 0;
//set 2 area array, row and column for looking around current pixel
int row_area[] = {i - 1, i, i + 1};
int col_area[] = {j - 1, j, j + 1};
//loop row area, up - current - down, around targeted pixel
for (int row = 0; row < 3; row++)
{
//loop column area, left side - current - right side, around targeted pixel
for (int col = 0; col < 3; col++)
{
//set current
int row_current = row_area[row];
int col_current = col_area[col];
if (row_current >= 0 && row_current < height && col_current >= 0 && col_current < width)
{
RGBTRIPLE pixel = image[row_current][col_current];
//sum total of current pixel / position iterations (and around area) for each colors * kernels Gx and Gy positions
Gx_red += Gx[row][col] * pixel.rgbtRed;
Gx_green += Gx[row][col] * pixel.rgbtGreen;
Gx_blue += Gx[row][col] * pixel.rgbtBlue;
Gy_red += Gy[row][col] * pixel.rgbtRed;
Gy_green += Gy[row][col] * pixel.rgbtGreen;
Gy_blue += Gy[row][col] * pixel.rgbtBlue;
}
}
}
//Gy and Gx square root caluculation
int GxGyRed = round(sqrt((Gx_red * Gx_red) + (Gy_red * Gy_red)));
int GxGyGreen = round(sqrt((Gx_green * Gx_green) + (Gy_green * Gy_green)));
int GxGyBlue = round(sqrt((Gx_blue * Gx_blue) + (Gy_blue * Gy_blue)));
//determine value to swap, if value over 255, value is capped at 255
if (GxGyRed > 255)
{
GxGyRed = 255;
swap[i][j].rgbtRed = GxGyRed;
}
else
{
swap[i][j].rgbtRed = GxGyRed;
}
if (GxGyGreen > 255)
{
GxGyGreen = 255;
swap[i][j].rgbtGreen = GxGyGreen;
}
else
{
swap[i][j].rgbtGreen = GxGyGreen;
}
if (GxGyBlue > 255)
{
GxGyBlue = 255;
swap[i][j].rgbtBlue = GxGyBlue;
}
else
{
swap[i][j].rgbtBlue = GxGyBlue;
}
}
}
//swap loop
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
image[i][j] = swap[i][j];
}
}
return;
}
</code></pre>
</div>
</div>
</div>
</div>
<!-- Side Images -->
<div class="socials">
<!-- <a href="https://github.com/Jer-B" target="_blank"
><img
src="./assets/side_img/github.svg"
alt="Github"
loading="lazy"
class="socicon"
/></a> -->
<!-- <a href="#" target="_blank"
><img
src="./assets/side_img/stackoverflow.svg"
alt="Stackoverflow"
loading="lazy"
class="socicon"
/></a> -->
<!-- <a href="https://githubgroupe.slack.com" target="_blank"
><img
src="./assets/side_img/slack-logo.svg"
alt="Slack"
loading="lazy"