-
Notifications
You must be signed in to change notification settings - Fork 0
/
lect_img.c~
127 lines (108 loc) · 2.52 KB
/
lect_img.c~
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <dirent.h>
#include <fcntl.h>
#include "lect_img.h"
list acqui_info(char * path) {
DIR * d;
struct dirent *dir;
d = opendir(path);
list * desc_img = malloc(sizeof(list));
(*desc_img).nb_elt = 0;
if (d) {
while ((dir = readdir(d)) != NULL) {
if (strlen(dir->d_name) > 4) {
char * ff = "";
ff = malloc(sizeof(char[100]));
strcat(ff, path);
strcat(ff, dir->d_name);
add_node(ff, desc_img);
}
}
closedir(d);
}
return *desc_img;
}
void add_node(char * addr, list * data) {
FILE * f_tga;
targa_header * f_header = malloc(sizeof(targa_header));
f_tga = fopen(addr, "r");
fread(f_header, sizeof(targa_header), 1, f_tga);
fclose(f_tga);
struct node * nw_node = malloc(sizeof(struct node));
(*nw_node).name_file = addr;
(*nw_node).hauteur = (*f_header).height;
(*nw_node).largeur = (*f_header).width;
if ((*data).nb_elt == 0) {
(*data).rac = *nw_node;
} else {
struct node * cur = &(*data).rac;
int i;
for (i = 1; i < (*data).nb_elt; i++) {
cur = (*cur).next;
}
(*cur).next = nw_node;
}
(*data).nb_elt += 1;
}
int calcsize(int a) {
if (a < 10)
return 1;
else if (a > 10 && a < 100)
return 2;
else if (a > 100 && a < 1000)
return 3;
else if (a > 1000 && a < 10000)
return 4;
else if (a > 10000 && a < 100000)
return 5;
else if (a > 100000 && a < 1000000)
return 6;
else if (a > 1000000 && a < 10000000)
return 7;
else if (a > 10000000 && a < 100000000)
return 8;
else if (a > 100000000 && a < 1000000000)
return 9;
else if (a > 1000000000 && a < 10000000000)
return 10;
}
void print_espace(int sizecompare, int size) {
int espace;
int i;
espace = sizecompare - size;
for (i = 0; i < espace; i++) {
printf(" ");
}
}
/*void print_list(list data) {
struct node cur = data.rac;
int i;
int fd;
for (i = 0 ; i < data.nb_elt ; i++) {
fd = open(cur.name_file, O_RDONLY);
long img_size = lseek(fd, 0L, SEEK_END);
lseek(fd, 0L, SEEK_SET);
close(fd);
printf("Chemin : C%s\n", cur.name_file);
printf("hauteur : %i\n", cur.hauteur);
printf("largeur : %i\n", cur.largeur);
printf("taille de l'image : %ld octets\n\n", img_size);
if (i + 1 < data.nb_elt) {
cur = *cur.next;
}
}
}*/
<<<<<<< HEAD
int main2() {
=======
/*int main() {
>>>>>>> d63d1275f14fafa875dc68f213106c5aeb02620f
char * path = "./images-test/";
list * data = malloc(sizeof(list));
*data = acqui_info(path);
print_list(*data);
return 1;
}*/