|
| 1 | + |
| 2 | +#include <stdlib.h> |
| 3 | +#include <stdio.h> |
| 4 | +#include <stdarg.h> |
| 5 | +#include <string.h> |
| 6 | +#include "dpvdecode.h" |
| 7 | +#include "tgafile.h" |
| 8 | + |
| 9 | +void Error (char *message, ...) |
| 10 | +{ |
| 11 | + va_list argptr; |
| 12 | + |
| 13 | + puts("ERROR: "); |
| 14 | + |
| 15 | + va_start (argptr,message); |
| 16 | + vprintf (message,argptr); |
| 17 | + va_end (argptr); |
| 18 | + putchar('\n'); |
| 19 | +#if _DEBUG && WIN32 |
| 20 | + printf ("press a key\n"); |
| 21 | + getchar(); |
| 22 | +#endif |
| 23 | + exit (1); |
| 24 | +} |
| 25 | + |
| 26 | +void StripExtension(char *in, char *out) |
| 27 | +{ |
| 28 | + char *dot; |
| 29 | + dot = strrchr(in, '.'); |
| 30 | + if (dot) |
| 31 | + { |
| 32 | + if (dot < strrchr(in, '/')) |
| 33 | + dot = NULL; |
| 34 | + if (dot < strrchr(in, '\\')) |
| 35 | + dot = NULL; |
| 36 | + if (dot < strrchr(in, ':')) |
| 37 | + dot = NULL; |
| 38 | + } |
| 39 | + if (dot == NULL) |
| 40 | + dot = in + strlen(in); |
| 41 | + while (in < dot) |
| 42 | + *out++ = *in++; |
| 43 | + *out++ = 0; |
| 44 | +} |
| 45 | + |
| 46 | + |
| 47 | +void usage(void) |
| 48 | +{ |
| 49 | + printf( |
| 50 | +"usage: dpvdecoder <name>\n" |
| 51 | +"example:\n" |
| 52 | +"dpvdecoder test\n" |
| 53 | +"would save out all the frames of test.dpv as test00000.tga, test00001.tga\n" |
| 54 | +"and so on, and save out the sound as test.wav\n" |
| 55 | + ); |
| 56 | +} |
| 57 | + |
| 58 | +int main(int argc, char **argv) |
| 59 | +{ |
| 60 | + int errornum; |
| 61 | + int width, height/*, soundbufferlength, soundlength*/, framenum; |
| 62 | + void *imagedata; |
| 63 | + //short *sounddata; |
| 64 | + char *errormessage; |
| 65 | + void *stream; |
| 66 | + char *basename; |
| 67 | + char filename[1024]; |
| 68 | + char framename[1024]; |
| 69 | + char wavname[1024]; |
| 70 | + if (argc != 2) |
| 71 | + { |
| 72 | + usage(); |
| 73 | + return 1; |
| 74 | + } |
| 75 | + basename = argv[1]; |
| 76 | + |
| 77 | + sprintf(filename, "%s.dpv", basename); |
| 78 | + stream = dpvdecode_open(filename, &errormessage); |
| 79 | + if (stream == NULL) |
| 80 | + { |
| 81 | + printf("unable to open stream file \"%s\", file does not exist or is not a valid stream\ndpvdecode_error reported: %s\n", filename, errormessage); |
| 82 | + |
| 83 | + strcpy(filename, basename); |
| 84 | + StripExtension(basename, basename); |
| 85 | + stream = dpvdecode_open(filename, &errormessage); |
| 86 | + if (stream == NULL) |
| 87 | + { |
| 88 | + printf("unable to open stream file \"%s\", file does not exist or is not a valid stream\ndpvdecode_error reported: %s\n", filename, errormessage); |
| 89 | + return 1; |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + sprintf(wavname, "%s.wav", basename); |
| 94 | + // FIXME: write wav save code |
| 95 | + errornum = 0; |
| 96 | + width = dpvdecode_getwidth(stream); |
| 97 | + height = dpvdecode_getheight(stream); |
| 98 | + //soundbufferlength = dpvdecode_getneededsoundbufferlength(stream); |
| 99 | + imagedata = malloc(width * height * 4); |
| 100 | + //sounddata = malloc(soundlength * sizeof(short[2])); |
| 101 | + for (framenum = 0;;framenum++) |
| 102 | + { |
| 103 | + //dpvdecode_frame(stream, framenum, imagedata, 0xFF0000, 0x00FF00, 0x0000FF, 4, width * 4, sounddata, soundbufferlength, &soundlength); |
| 104 | + dpvdecode_video(stream, framenum, imagedata, 0xFF0000, 0x00FF00, 0x0000FF, 4, width * 4); |
| 105 | + if (dpvdecode_error(stream, &errormessage)) |
| 106 | + break; |
| 107 | + sprintf(framename, "%s%04d.tga", basename, framenum); |
| 108 | + savetga_rgb32_topdown(framename, imagedata, width, height); |
| 109 | + } |
| 110 | + if (errornum) |
| 111 | + printf("error while decoding stream: %s\n", errormessage); |
| 112 | + dpvdecode_close(stream); |
| 113 | + return 0; |
| 114 | +} |
0 commit comments