-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdpvdecoder.c
114 lines (103 loc) · 2.66 KB
/
dpvdecoder.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
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include "dpvdecode.h"
#include "tgafile.h"
void Error (char *message, ...)
{
va_list argptr;
puts("ERROR: ");
va_start (argptr,message);
vprintf (message,argptr);
va_end (argptr);
putchar('\n');
#if _DEBUG && WIN32
printf ("press a key\n");
getchar();
#endif
exit (1);
}
void StripExtension(char *in, char *out)
{
char *dot;
dot = strrchr(in, '.');
if (dot)
{
if (dot < strrchr(in, '/'))
dot = NULL;
if (dot < strrchr(in, '\\'))
dot = NULL;
if (dot < strrchr(in, ':'))
dot = NULL;
}
if (dot == NULL)
dot = in + strlen(in);
while (in < dot)
*out++ = *in++;
*out++ = 0;
}
void usage(void)
{
printf(
"usage: dpvdecoder <name>\n"
"example:\n"
"dpvdecoder test\n"
"would save out all the frames of test.dpv as test00000.tga, test00001.tga\n"
"and so on, and save out the sound as test.wav\n"
);
}
int main(int argc, char **argv)
{
int errornum;
int width, height/*, soundbufferlength, soundlength*/, framenum;
void *imagedata;
//short *sounddata;
char *errormessage;
void *stream;
char *basename;
char filename[1024];
char framename[1024];
char wavname[1024];
if (argc != 2)
{
usage();
return 1;
}
basename = argv[1];
sprintf(filename, "%s.dpv", basename);
stream = dpvdecode_open(filename, &errormessage);
if (stream == NULL)
{
printf("unable to open stream file \"%s\", file does not exist or is not a valid stream\ndpvdecode_error reported: %s\n", filename, errormessage);
strcpy(filename, basename);
StripExtension(basename, basename);
stream = dpvdecode_open(filename, &errormessage);
if (stream == NULL)
{
printf("unable to open stream file \"%s\", file does not exist or is not a valid stream\ndpvdecode_error reported: %s\n", filename, errormessage);
return 1;
}
}
sprintf(wavname, "%s.wav", basename);
// FIXME: write wav save code
errornum = 0;
width = dpvdecode_getwidth(stream);
height = dpvdecode_getheight(stream);
//soundbufferlength = dpvdecode_getneededsoundbufferlength(stream);
imagedata = malloc(width * height * 4);
//sounddata = malloc(soundlength * sizeof(short[2]));
for (framenum = 0;;framenum++)
{
//dpvdecode_frame(stream, framenum, imagedata, 0xFF0000, 0x00FF00, 0x0000FF, 4, width * 4, sounddata, soundbufferlength, &soundlength);
dpvdecode_video(stream, framenum, imagedata, 0xFF0000, 0x00FF00, 0x0000FF, 4, width * 4);
if (dpvdecode_error(stream, &errormessage))
break;
sprintf(framename, "%s%04d.tga", basename, framenum);
savetga_rgb32_topdown(framename, imagedata, width, height);
}
if (errornum)
printf("error while decoding stream: %s\n", errormessage);
dpvdecode_close(stream);
return 0;
}