66 |
static int CSP = XVID_CSP_I420; |
static int CSP = XVID_CSP_I420; |
67 |
static int BPP = 1; |
static int BPP = 1; |
68 |
static int FORMAT = USE_PNM; |
static int FORMAT = USE_PNM; |
69 |
|
static int POSTPROC = 0; |
70 |
|
|
71 |
static char filepath[256] = "./"; |
static char filepath[256] = "./"; |
72 |
static void *dec_handle = NULL; |
static void *dec_handle = NULL; |
89 |
xvid_dec_stats_t *xvid_dec_stats); |
xvid_dec_stats_t *xvid_dec_stats); |
90 |
static int dec_stop(); |
static int dec_stop(); |
91 |
static void usage(); |
static void usage(); |
92 |
static int write_image(char *prefix, unsigned char *image); |
static int write_image(char *prefix, unsigned char *image, int filenr); |
93 |
static int write_pnm(char *filename, unsigned char *image); |
static int write_pnm(char *filename, unsigned char *image); |
94 |
static int write_tga(char *filename, unsigned char *image); |
static int write_tga(char *filename, unsigned char *image); |
95 |
static int write_yuv(char *filename, unsigned char *image); |
static int write_yuv(char *filename, unsigned char *image); |
123 |
long totalsize; |
long totalsize; |
124 |
int status; |
int status; |
125 |
|
|
126 |
int use_assembler = 0; |
int use_assembler = 1; |
127 |
int debug_level = 0; |
int debug_level = 0; |
128 |
|
|
129 |
char filename[256]; |
char filename[256]; |
133 |
int i; |
int i; |
134 |
|
|
135 |
printf("xvid_decraw - raw mpeg4 bitstream decoder "); |
printf("xvid_decraw - raw mpeg4 bitstream decoder "); |
136 |
printf("written by Christoph Lampert 2002-2003\n\n"); |
printf("written by Christoph Lampert\n\n"); |
137 |
|
|
138 |
/***************************************************************************** |
/***************************************************************************** |
139 |
* Command line parsing |
* Command line parsing |
141 |
|
|
142 |
for (i=1; i< argc; i++) { |
for (i=1; i< argc; i++) { |
143 |
|
|
144 |
if (strcmp("-asm", argv[i]) == 0 ) { |
if (strcmp("-noasm", argv[i]) == 0 ) { |
145 |
use_assembler = 1; |
use_assembler = 0; |
146 |
} else if (strcmp("-debug", argv[i]) == 0 && i < argc - 1 ) { |
} else if (strcmp("-debug", argv[i]) == 0 && i < argc - 1 ) { |
147 |
i++; |
i++; |
148 |
if (sscanf(argv[i], "0x%x", &debug_level) != 1) { |
if (sscanf(argv[i], "0x%x", &debug_level) != 1) { |
173 |
CSP = XVID_CSP_I420; |
CSP = XVID_CSP_I420; |
174 |
BPP = 1; |
BPP = 1; |
175 |
} |
} |
176 |
|
} else if (strcmp("-postproc", argv[i]) == 0 && i < argc - 1 ) { |
177 |
|
i++; |
178 |
|
POSTPROC = atoi(argv[i]); |
179 |
|
if (POSTPROC < 0) POSTPROC = 0; |
180 |
|
if (POSTPROC > 2) POSTPROC = 2; |
181 |
} else if (strcmp("-f", argv[i]) == 0 && i < argc -1) { |
} else if (strcmp("-f", argv[i]) == 0 && i < argc -1) { |
182 |
i++; |
i++; |
183 |
if (strcmp(argv[i], "tga") == 0) { |
if (strcmp(argv[i], "tga") == 0) { |
237 |
goto free_all_memory; |
goto free_all_memory; |
238 |
|
|
239 |
/***************************************************************************** |
/***************************************************************************** |
240 |
* XviD PART Start |
* Xvid PART Start |
241 |
****************************************************************************/ |
****************************************************************************/ |
242 |
|
|
243 |
status = dec_init(use_assembler, debug_level); |
status = dec_init(use_assembler, debug_level); |
381 |
|
|
382 |
/* Save output frame if required */ |
/* Save output frame if required */ |
383 |
if (ARG_SAVEDECOUTPUT) { |
if (ARG_SAVEDECOUTPUT) { |
|
if (FORMAT == USE_YUV) { |
|
384 |
sprintf(filename, "%sdec", filepath); |
sprintf(filename, "%sdec", filepath); |
385 |
} |
|
386 |
else { |
if(write_image(filename, out_buffer, filenr)) { |
|
sprintf(filename, "%sdec%05d", filepath, filenr); |
|
|
} |
|
|
if(write_image(filename, out_buffer)) { |
|
387 |
fprintf(stderr, |
fprintf(stderr, |
388 |
"Error writing decoded frame %s\n", |
"Error writing decoded frame %s\n", |
389 |
filename); |
filename); |
430 |
|
|
431 |
/* Save output frame if required */ |
/* Save output frame if required */ |
432 |
if (ARG_SAVEDECOUTPUT) { |
if (ARG_SAVEDECOUTPUT) { |
|
if (FORMAT == USE_YUV) { |
|
433 |
sprintf(filename, "%sdec", filepath); |
sprintf(filename, "%sdec", filepath); |
434 |
} |
|
435 |
else { |
if(write_image(filename, out_buffer, filenr)) { |
|
sprintf(filename, "%sdec%05d", filepath, filenr); |
|
|
} |
|
|
if(write_image(filename, out_buffer)) { |
|
436 |
fprintf(stderr, |
fprintf(stderr, |
437 |
"Error writing decoded frame %s\n", |
"Error writing decoded frame %s\n", |
438 |
filename); |
filename); |
457 |
} |
} |
458 |
|
|
459 |
/***************************************************************************** |
/***************************************************************************** |
460 |
* XviD PART Stop |
* Xvid PART Stop |
461 |
****************************************************************************/ |
****************************************************************************/ |
462 |
|
|
463 |
release_all: |
release_all: |
483 |
|
|
484 |
fprintf(stderr, "Usage : xvid_decraw [OPTIONS]\n"); |
fprintf(stderr, "Usage : xvid_decraw [OPTIONS]\n"); |
485 |
fprintf(stderr, "Options :\n"); |
fprintf(stderr, "Options :\n"); |
486 |
fprintf(stderr, " -asm : use assembly optimizations (default=disabled)\n"); |
fprintf(stderr, " -noasm : don't use assembly optimizations (default=enabled)\n"); |
487 |
fprintf(stderr, " -debug : debug level (debug=0)\n"); |
fprintf(stderr, " -debug : debug level (debug=0)\n"); |
488 |
fprintf(stderr, " -i string : input filename (default=stdin)\n"); |
fprintf(stderr, " -i string : input filename (default=stdin)\n"); |
489 |
fprintf(stderr, " -d : save decoder output\n"); |
fprintf(stderr, " -d : save decoder output\n"); |
490 |
fprintf(stderr, " -c csp : choose colorspace output (rgb16, rgb24, rgb32, yv12, i420)\n"); |
fprintf(stderr, " -c csp : choose colorspace output (rgb16, rgb24, rgb32, yv12, i420)\n"); |
491 |
fprintf(stderr, " -f format : choose output file format (tga, pnm, pgm, yuv)\n"); |
fprintf(stderr, " -f format : choose output file format (tga, pnm, pgm, yuv)\n"); |
492 |
|
fprintf(stderr, " -postproc : postprocessing level (0=off, 1=deblock, 2=deblock+dering)\n"); |
493 |
fprintf(stderr, " -m : save mpeg4 raw stream to individual files\n"); |
fprintf(stderr, " -m : save mpeg4 raw stream to individual files\n"); |
494 |
fprintf(stderr, " -help : This help message\n"); |
fprintf(stderr, " -help : This help message\n"); |
495 |
fprintf(stderr, " (* means default)\n"); |
fprintf(stderr, " (* means default)\n"); |
519 |
* output functions |
* output functions |
520 |
****************************************************************************/ |
****************************************************************************/ |
521 |
|
|
522 |
static int write_image(char *prefix, unsigned char *image) |
static int write_image(char *prefix, unsigned char *image, int filenr) |
523 |
{ |
{ |
524 |
char filename[1024]; |
char filename[1024]; |
525 |
char *ext; |
char *ext; |
538 |
exit(-1); |
exit(-1); |
539 |
} |
} |
540 |
|
|
541 |
|
if (FORMAT == USE_YUV) { |
542 |
sprintf(filename, "%s.%s", prefix, ext); |
sprintf(filename, "%s.%s", prefix, ext); |
543 |
|
|
544 |
|
if (!filenr) { |
545 |
|
FILE *fp = fopen(filename, "wb"); |
546 |
|
fclose(fp); |
547 |
|
} |
548 |
|
} else |
549 |
|
sprintf(filename, "%s%05d.%s", prefix, filenr, ext); |
550 |
|
|
551 |
if (FORMAT == USE_PNM) { |
if (FORMAT == USE_PNM) { |
552 |
ret = write_pnm(filename, image); |
ret = write_pnm(filename, image); |
553 |
} else if (FORMAT == USE_YUV) { |
} else if (FORMAT == USE_YUV) { |
689 |
return -1; |
return -1; |
690 |
} |
} |
691 |
|
|
692 |
if (BPP == 1) { |
fwrite(image, 1, 3*XDIM*YDIM/2, f); |
|
int i; |
|
|
|
|
|
fwrite(image, 1, XDIM*YDIM, f); |
|
|
|
|
|
for (i=0; i<YDIM/2;i++) { |
|
|
fwrite(image+XDIM*YDIM + i*XDIM/2, 1, XDIM/2, f); |
|
|
fwrite(image+5*XDIM*YDIM/4 + i*XDIM/2, 1, XDIM/2, f); |
|
|
} |
|
|
} |
|
693 |
|
|
694 |
fclose(f); |
fclose(f); |
695 |
|
|
714 |
memset(&xvid_dec_create, 0, sizeof(xvid_dec_create_t)); |
memset(&xvid_dec_create, 0, sizeof(xvid_dec_create_t)); |
715 |
|
|
716 |
/*------------------------------------------------------------------------ |
/*------------------------------------------------------------------------ |
717 |
* XviD core initialization |
* Xvid core initialization |
718 |
*----------------------------------------------------------------------*/ |
*----------------------------------------------------------------------*/ |
719 |
|
|
720 |
/* Version */ |
/* Version */ |
735 |
xvid_global(NULL, 0, &xvid_gbl_init, NULL); |
xvid_global(NULL, 0, &xvid_gbl_init, NULL); |
736 |
|
|
737 |
/*------------------------------------------------------------------------ |
/*------------------------------------------------------------------------ |
738 |
* XviD encoder initialization |
* Xvid decoder initialization |
739 |
*----------------------------------------------------------------------*/ |
*----------------------------------------------------------------------*/ |
740 |
|
|
741 |
/* Version */ |
/* Version */ |
776 |
xvid_dec_stats->version = XVID_VERSION; |
xvid_dec_stats->version = XVID_VERSION; |
777 |
|
|
778 |
/* No general flags to set */ |
/* No general flags to set */ |
779 |
|
if (POSTPROC == 1) |
780 |
|
xvid_dec_frame.general = XVID_DEBLOCKY | XVID_DEBLOCKUV; |
781 |
|
else if (POSTPROC==2) |
782 |
|
xvid_dec_frame.general = XVID_DEBLOCKY | XVID_DEBLOCKUV | XVID_DERINGY | XVID_DERINGUV; |
783 |
|
else |
784 |
xvid_dec_frame.general = 0; |
xvid_dec_frame.general = 0; |
785 |
|
|
786 |
/* Input stream */ |
/* Input stream */ |