-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain.c
More file actions
123 lines (121 loc) · 3.35 KB
/
Copy pathmain.c
File metadata and controls
123 lines (121 loc) · 3.35 KB
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
/**
* @file main.c
*
* Copyright (c) 2015 大前良介 (OHMAE Ryosuke)
*
* This software is released under the MIT License.
* http://opensource.org/licenses/MIT
*
* @brief テスト用メイン関数
* @author <a href="mailto:ryo@mm2d.net">大前良介 (OHMAE Ryosuke)</a>
* @date 2015/02/08
*/
#include <stdio.h>
#include <string.h>
#include "image.h"
static char *get_extension(char *name) {
int i;
for (i = strlen(name) - 1; i >= 0; i--) {
if (name[i] == '.') {
return &name[i + 1];
}
}
return NULL;
}
int main(int argc, char**argv) {
int i;
char *name;
char *ext;
char outname[64];
image_t *img = NULL;
image_t *b = NULL;
for (i = 1; i < argc; i++) {
name = argv[i];
ext = get_extension(name);
if (ext == NULL) {
continue;
}
if (strcmp("bmp", ext) == 0) {
img = read_bmp_file(name);
} else if (strcmp("jpg", ext) == 0 || strcmp("jpeg", ext) == 0) {
img = read_jpeg_file(name);
} else if (strcmp("png", ext) == 0) {
img = read_png_file(name);
} else if (strcmp("ppm", ext) == 0 || strcmp("pbm", ext) == 0
|| strcmp("pgm", ext) == 0) {
img = read_pnm_file(name);
}
if (img != NULL) {
LOG("%s", name);
dump_image_info(img);
strcpy(outname, "out/0-");
strcat(outname, name);
strcat(outname, ".a.pbm");
write_pnm_file(outname, img, 1);
strcpy(outname, "out/0-");
strcat(outname, name);
strcat(outname, ".a.pgm");
write_pnm_file(outname, img, 2);
strcpy(outname, "out/0-");
strcat(outname, name);
strcat(outname, ".a.ppm");
write_pnm_file(outname, img, 3);
strcpy(outname, "out/0-");
strcat(outname, name);
strcat(outname, ".b.pbm");
write_pnm_file(outname, img, 4);
strcpy(outname, "out/0-");
strcat(outname, name);
strcat(outname, ".b.pgm");
write_pnm_file(outname, img, 5);
strcpy(outname, "out/0-");
strcat(outname, name);
strcat(outname, ".b.ppm");
write_pnm_file(outname, img, 6);
img = image_to_rgba(img);
strcpy(outname, "out/a-");
strcat(outname, name);
strcat(outname, ".png");
write_png_file(outname, img);
img = image_to_rgb(img);
strcpy(outname, "out/b-");
strcat(outname, name);
strcat(outname, ".png");
write_png_file(outname, img);
strcpy(outname, "out/b-");
strcat(outname, name);
strcat(outname, ".jpg");
write_jpeg_file(outname, img);
strcpy(outname, "out/b-");
strcat(outname, name);
strcat(outname, ".bmp");
write_bmp_file(outname, img, FALSE);
strcpy(outname, "out/simple-");
strcat(outname, name);
strcat(outname, ".bmp");
write_bmp_simple_file(outname, img);
b = img;
img = image_to_index(img);
if (img != NULL) {
strcpy(outname, "out/c-");
strcat(outname, name);
strcat(outname, ".png");
write_png_file(outname, img);
strcpy(outname, "out/c-");
strcat(outname, name);
strcat(outname, ".bmp");
write_bmp_file(outname, img, FALSE);
}
img = image_to_gray(b);
strcpy(outname, "out/d-");
strcat(outname, name);
strcat(outname, ".png");
write_png_file(outname, img);
free_image(img);
img = NULL;
} else {
printf("read fail %s\n", name);
}
}
return 0;
}