-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathraw.c
More file actions
78 lines (61 loc) · 1.36 KB
/
raw.c
File metadata and controls
78 lines (61 loc) · 1.36 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
#include <assert.h>
#include <fcntl.h>
#include <stdio.h>
#include "movies.h"
// Usage: usage: raw <anime> <min> <max>
// First frame is 1
int main(int argc, char *arg[])
{
if (argc != 4)
return 1;
struct movie *chosen = NULL;
for (int i = 0; i < N_MOVIE; i++)
if (!strcmp(argv[1], movies[i].id))
{
chosen = movies + i;
break;
}
if (!chosen)
return 2;
int min = atoi(argv[2]);
int max = atoi(argv[3]);
if (min <= 0)
return 3;
if (min > chosen->n_frame)
return 4;
min--;
if (0 == max)
return 5;
if (max < 0)
{
max += chosen->n_frame;
if (max < 1)
return 6;
}
else if (max > chosen->n_frame)
return 7;
max--;
if (min > max)
return 8;
if (-1 == setmode(fileno(stdout), O_BINARY))
{
perror(NULL);
return 9;
}
int total = chosen->width * chosen->height;
int pitch = chosen->width * 4;
static unsigned char buffer[1000 * 1000];
assert(sizeof (buffer) < total);
MOVIE_INIT(chosen);
for (int i = min; i < max; i++)
{
MOVIE_RENDER(chosen, buffer, pitch, i);
if (fwrite(buffer, 1, total, stdout) != total)
{
perror(NULL);
return 10;
}
}
MOVIE_FREE(chosen);
return 0;
}