-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageList.c
More file actions
196 lines (185 loc) · 4.5 KB
/
ImageList.c
File metadata and controls
196 lines (185 loc) · 4.5 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
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
/* ImageList.c */
/* William Scotten's code */
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "Image.h"
#include "ImageList.h"
/* Create a new image list */
ILIST *CreateImageList(void)
{
/* Ilist */
ILIST *list;
list = malloc(sizeof(ILIST));
if (! list)
{ perror("Out of memomry! Aborting...");
exit(10);}
list->Length = 0;
list->First = NULL;
list->Last = NULL;
assert(list);
return list;
}
/* Delete an image list (and all entries) */
void DeleteImageList(ILIST *list)
{
IENTRY *x, *y;
assert(list);
assert(list->Length);
assert(list->First);
assert(list->Last);
x = list->First;
while(x){
y = x->Next;
if (x->RGBImage)
DeleteImage(x->RGBImage);
else {
assert(x->YUVImage);
DeleteYUVImage(x->YUVImage);
}
free(x);
x = y;
}
list->Length = 0;
list->First = NULL;
list->Last = NULL;
free(list);
}
/* Insert a RGB image to the image list at the end */
void AppendRGBImage(ILIST *list, IMAGE *RGBimage)
{
IENTRY *ientryRGB = NULL;
assert(list);
assert(RGBimage);
ientryRGB=malloc(sizeof(IENTRY));
if (! ientryRGB)
{ perror("Out of memory! Aborting...");
exit(10); }
ientryRGB->List = NULL;
ientryRGB->Next = NULL;
ientryRGB->Prev = NULL;
ientryRGB->RGBImage=RGBimage;
ientryRGB->YUVImage=NULL;
if (list->Last)
{
ientryRGB->List = list;
ientryRGB->Next = list->First;
ientryRGB->Prev = list->Last;
list->Last->Next = ientryRGB;
list->Last = ientryRGB;
}
else
{
ientryRGB->List = list;
ientryRGB->Next = NULL;
ientryRGB->Prev = NULL;
list->First = ientryRGB;
list->Last = ientryRGB;
}
list->Length++;
}
/* Insert a YUV image to the image list at the end */
void AppendYUVImage(ILIST *list, YUVIMAGE *YUVimage)
{
IENTRY *ientryYUV = NULL;
assert(list);
assert(YUVimage);
ientryYUV = malloc(sizeof(IENTRY));
if (! ientryYUV)
{ perror("Out of memory! Aborting...");
exit(10); }
ientryYUV->List = NULL;
ientryYUV->Next = NULL;
ientryYUV->Prev = NULL;
ientryYUV->YUVImage=YUVimage;
ientryYUV->RGBImage=NULL;
if (list->Last)
{
ientryYUV->List = list;
ientryYUV->Next = NULL;
ientryYUV->Prev = list->Last;
list->Last->Next = ientryYUV;
list->Last = ientryYUV;
}
else
{
ientryYUV->List = list;
ientryYUV->Next = NULL;
ientryYUV->Prev = NULL;
list->First = ientryYUV;
list->Last = ientryYUV;
}
list->Length++;
}
/* Crop an image list */
void CropImageList(ILIST *list, unsigned int start, unsigned int end)
{
assert(list);
int i, temp;
temp = list->Length - 1 - end;
for (i = 0; i < start; i++){
list->First = list->First->Next;
list->Length--;
}
for (i = 0; i < temp; i++) {
list->Last = list->Last->Prev;
list->Length--;
}
list->Last->Next = NULL;
i = end-start+1;
printf("Operation Crop is done! New number of frames is %d\n", list->Length);
}
/* Fast forward an image list */
void FastImageList(ILIST *list, unsigned int factor)
{
assert(list);
ILIST *listtemp;
listtemp = CreateImageList();
int i, ii;
listtemp->First = list->First;
listtemp->Length = list->Length;
if (factor > 1)
{
for (i = 0; i < listtemp->Length/(factor); i++){
for (ii = 0; ii < (factor-1); ii++){
if (list->First->Next->Next){
list->First->Next = list->First->Next->Next;
list->Length--;
}
else {
break;
}
}
list->First = list->First->Next;
}
}
list->First = listtemp->First;
free(listtemp);
printf("Operation Fast Forward is done! New number of frames is %d\n", list->Length);
}
/* Reverse an image list */
void ReverseImageList(ILIST *list)
{
assert(list);
int i;
ILIST *listtemp;
listtemp = CreateImageList();
listtemp->First = list->First;
listtemp->First->Next = list->First->Next;
listtemp->Last = list->Last;
listtemp->Length = list->Length;
list->First = list->Last;
list->First->Next = list->First->Prev;
list->First->Prev = NULL;
list->Last = listtemp->First;
list->Last->Prev = list->Last->Next;
list->Last->Next = NULL;
list->First = list->First->Next;
for (i = 0; i < list->Length-2; i++){
list->First->Next = list->First->Prev;
list->First = list->First->Next;
}
list->First = listtemp->Last;
free(listtemp);
printf("Operation Reverse is done!\n");
}