Skip to content

Commit 6bbefd2

Browse files
committed
Change tab to space
1 parent 4b58f46 commit 6bbefd2

File tree

3 files changed

+87
-87
lines changed

3 files changed

+87
-87
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
bin/*
22
obj/*
33
build/*
4+
compile_commands.json

src/main.c

Lines changed: 79 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -6,97 +6,96 @@
66
#include "read_write.h"
77

88

9-
int main(int argc, char **argv)
9+
int main(int argc, char **argv)
1010
{
11-
char *input = NULL, *output = NULL; // input and output file
12-
double angle = 0.0; // the angle used for pixelsorting
13-
int threshold_value = 20;
11+
char *input = NULL, *output = NULL; // input and output file
12+
double angle = 0.0; // the angle used for pixelsorting
13+
int threshold_value = 20;
1414

15-
int c;
16-
opterr = 0;
15+
int c;
16+
opterr = 0;
1717

18-
// Argument parsing
19-
while ((c = getopt (argc, argv, "i:o:a:t:")) != -1) {
20-
switch (c) {
21-
case 'a':
22-
angle = atof(optarg);
23-
break;
24-
case 'i':
25-
input = optarg;
26-
break;
27-
case 'o':
28-
output = optarg;
29-
break;
30-
case 't':
31-
threshold_value = (int)(atof(optarg));
32-
break;
33-
case '?':
34-
if (optopt == 'i' || optopt == 'o') {
35-
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
36-
} else if (isprint (optopt)) {
37-
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
38-
} else {
39-
fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt);
40-
return 1;
41-
}
42-
abort();
43-
default:
44-
abort();
45-
}
46-
}
18+
// Argument parsing
19+
while ((c = getopt (argc, argv, "i:o:a:t:")) != -1) {
20+
switch (c) {
21+
case 'a':
22+
angle = atof(optarg);
23+
break;
24+
case 'i':
25+
input = optarg;
26+
break;
27+
case 'o':
28+
output = optarg;
29+
break;
30+
case 't':
31+
threshold_value = (int)(atof(optarg));
32+
break;
33+
case '?':
34+
if (optopt == 'i' || optopt == 'o') {
35+
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
36+
} else if (isprint (optopt)) {
37+
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
38+
} else {
39+
fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt);
40+
return 1;
41+
}
42+
abort();
43+
default:
44+
abort();
45+
}
46+
}
4747

48-
49-
int is_jpg = 0;
50-
int is_png = 0;
5148

52-
// Get filename
53-
const char *dot = strrchr(input, '.');
49+
int is_jpg = 0;
50+
int is_png = 0;
51+
52+
// Get filename
53+
const char *dot = strrchr(input, '.');
5454
if(!dot || dot == input) abort();
5555
const char *ext = dot + 1;
56-
if (strcmp(ext, "jpeg") == 0
57-
|| strcmp(ext, "jpg") == 0) {
58-
is_jpg = 1;
59-
}
60-
if (strcmp(ext, "png") == 0) {
61-
is_png = 1;
62-
}
56+
if (strcmp(ext, "jpeg") == 0
57+
|| strcmp(ext, "jpg") == 0) {
58+
is_jpg = 1;
59+
}
60+
if (strcmp(ext, "png") == 0) {
61+
is_png = 1;
62+
}
63+
64+
if (!(is_png || is_jpg)) {
65+
abort();
66+
}
6367

64-
if (!(is_png || is_jpg)) {
65-
abort();
66-
}
6768

68-
69-
char *tmp = ".tmp.png";
70-
if (is_jpg) {
71-
printf("Converting JPG to PNG…\n");
72-
char cmd[512];
73-
strcpy(cmd, "convert ");
74-
strcat(cmd, input);
75-
strcat(cmd, " ");
76-
strcat(cmd, tmp);
77-
system(cmd);
78-
}
69+
char *tmp = ".tmp.png";
70+
if (is_jpg) {
71+
printf("Converting JPG to PNG…\n");
72+
char cmd[512];
73+
strcpy(cmd, "convert ");
74+
strcat(cmd, input);
75+
strcat(cmd, " ");
76+
strcat(cmd, tmp);
77+
system(cmd);
78+
}
7979

80-
// If input and output are given
81-
if (input && output) {
82-
if(is_jpg) {
83-
read_png_file(tmp);
84-
} else if (is_png) {
85-
read_png_file(input);
86-
}
87-
process_png_file(threshold_value);
88-
// pixel_sort();
89-
write_png_file(output);
90-
}
80+
// If input and output are given
81+
if (input && output) {
82+
if(is_jpg) {
83+
read_png_file(tmp);
84+
} else if (is_png) {
85+
read_png_file(input);
86+
}
87+
process_png_file(threshold_value);
88+
// pixel_sort();
89+
write_png_file(output);
90+
}
9191

92-
if (is_jpg) {
93-
char *cmd[512];
94-
strcpy(cmd, "rm ");
95-
strcat(cmd, tmp);
96-
system(cmd);
97-
}
92+
if (is_jpg) {
93+
char *cmd[512];
94+
strcpy(cmd, "rm ");
95+
strcat(cmd, tmp);
96+
system(cmd);
97+
}
9898

99-
10099

101-
return 0;
100+
return 0;
102101
}

src/read_write.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ png_byte bit_depth;
1111
png_bytep *row_pointers;
1212

1313

14-
void read_png_file(char *filename)
14+
void read_png_file(char *filename)
1515
{
1616
FILE *fp = fopen(filename, "rb");
1717

@@ -70,7 +70,7 @@ void read_png_file(char *filename)
7070
fclose(fp);
7171
}
7272

73-
void write_png_file(char *filename)
73+
void write_png_file(char *filename)
7474
{
7575
int y;
7676
FILE *fp = fopen(filename, "wb");
@@ -123,22 +123,22 @@ int convert_grayscale(const png_bytep px)
123123
}
124124

125125

126-
int compare_light(const void *p, const void *q)
126+
int compare_light(const void *p, const void *q)
127127
{
128128
int x = convert_grayscale(p);
129129
int y = convert_grayscale(q);
130130

131131
/* Avoid return x - y, which can cause undefined behaviour
132132
because of signed integer overflow. */
133133
if (x < y)
134-
return -1; // Return -1 if you want ascending, 1 if you want descending order.
134+
return -1; // Return -1 if you want ascending, 1 if you want descending order.
135135
else if (x > y)
136-
return 1; // Return 1 if you want ascending, -1 if you want descending order.
136+
return 1; // Return 1 if you want ascending, -1 if you want descending order.
137137

138138
return 0;
139139
}
140140

141-
int threshold(png_bytep px, int value)
141+
int threshold(png_bytep px, int value)
142142
{
143143
return convert_grayscale(px) < value;
144144
}
@@ -182,4 +182,4 @@ void process_png_file(threshold_value)
182182
}
183183

184184

185-
#endif
185+
#endif

0 commit comments

Comments
 (0)