-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdefinitions.c
134 lines (98 loc) · 1.9 KB
/
definitions.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
128
129
130
131
132
133
134
#include <malloc.h>
#include "definitions.h"
jpeg_t *initJpeg()
{
jpeg_t *jpeg = malloc(sizeof(jpeg_t));
if (!jpeg)
return NULL;
jpeg->jfif = NULL;
jpeg->com = NULL;
jpeg->sof0 = NULL;
jpeg->sof2 = NULL;
jpeg->sos = NULL;
jpeg->scan = NULL;
jpeg->dhtN = 0;
jpeg->dhtLength = NULL;
jpeg->dht = NULL;
jpeg->dqtN = 0;
jpeg->dqtLength = NULL;
jpeg->dqt = NULL;
return jpeg;
}
int freeJpeg(jpeg_t *jpeg)
{
if(!jpeg)
return 1;
if (jpeg->jfif)
free(jpeg->jfif);
if (jpeg->com)
free(jpeg->com);
if (jpeg->dhtLength)
free(jpeg->dhtLength);
for (uint16_t i = 0; i < jpeg->dhtN; ++i)
{
if (jpeg->dht[i])
free(jpeg->dht[i]);
}
if (jpeg->dht)
free(jpeg->dht);
if (jpeg->dqtLength)
free(jpeg->dqtLength);
for (uint16_t i = 0; i < jpeg->dqtN; ++i)
{
if (jpeg->dqt[i])
free(jpeg->dqt[i]);
}
if (jpeg->dqt)
free(jpeg->dqt);
if (jpeg->sof0)
free(jpeg->sof0);
if (jpeg->sof2)
free(jpeg->sof2);
if (jpeg->sos)
free(jpeg->sos);
if (jpeg->scan)
free(jpeg->scan);
free(jpeg);
return 0;
}
node_t *treeSearch(node_t *node, uint8_t data)
{
if (!node)
return NULL;
if ( data == (node->value) )
return node;
else if (data < node->value )
return treeSearch((node->l), data);
else
return treeSearch((node->r), data);
return NULL;
}
void treeInsert(node_t **node, uint8_t data)
{
if (!*node)
{
*node = malloc(sizeof(node_t));
if (!*node)
return;
(*node)->l = NULL;
(*node)->r = NULL;
(*node)->value = data;
}
else if (data < (*node)->value)
treeInsert(&(*node)->l, data);
else if (data > (*node)->value)
treeInsert(&(*node)->r, data);
return;
}
void treeFree(node_t *node)
{
if (!node)
return;
if (node->l)
treeFree(node->l);
if (node->r)
treeFree(node->r);
free(node);
return;
}