--- trunk/xvidcore/examples/xvid_decraw.c 2005/09/20 11:19:34 1637 +++ trunk/xvidcore/examples/xvid_decraw.c 2010/01/08 10:03:09 1881 @@ -20,7 +20,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: xvid_decraw.c,v 1.21 2005-09-20 11:19:34 suxen_drol Exp $ + * $Id: xvid_decraw.c,v 1.26 2010-01-08 10:03:09 Isibaar Exp $ * ****************************************************************************/ @@ -56,6 +56,7 @@ #define USE_PNM 0 #define USE_TGA 1 +#define USE_YUV 2 static int XDIM = 0; static int YDIM = 0; @@ -87,9 +88,10 @@ xvid_dec_stats_t *xvid_dec_stats); static int dec_stop(); static void usage(); -static int write_image(char *prefix, unsigned char *image); +static int write_image(char *prefix, unsigned char *image, int filenr); static int write_pnm(char *filename, unsigned char *image); static int write_tga(char *filename, unsigned char *image); +static int write_yuv(char *filename, unsigned char *image); const char * type2str(int type) { @@ -174,6 +176,8 @@ i++; if (strcmp(argv[i], "tga") == 0) { FORMAT = USE_TGA; + } else if (strcmp(argv[i], "yuv") == 0) { + FORMAT = USE_YUV; } else { FORMAT = USE_PNM; } @@ -212,6 +216,9 @@ if (BPP != 1 && BPP != 3 && FORMAT == USE_PNM) { FORMAT = USE_TGA; } + if (BPP != 1 && FORMAT == USE_YUV) { + FORMAT = USE_TGA; + } /***************************************************************************** * Memory allocation @@ -267,13 +274,11 @@ mp4_ptr = mp4_buffer; /* read new data */ - if(feof(in_file)) - break; - - useful_bytes += fread(mp4_buffer + already_in_buffer, - 1, BUFFER_SIZE - already_in_buffer, - in_file); - + if(!feof(in_file)) { + useful_bytes += fread(mp4_buffer + already_in_buffer, + 1, BUFFER_SIZE - already_in_buffer, + in_file); + } } @@ -370,8 +375,9 @@ /* Save output frame if required */ if (ARG_SAVEDECOUTPUT) { - sprintf(filename, "%sdec%05d", filepath, filenr); - if(write_image(filename, out_buffer)) { + sprintf(filename, "%sdec", filepath); + + if(write_image(filename, out_buffer, filenr)) { fprintf(stderr, "Error writing decoded frame %s\n", filename); @@ -418,8 +424,9 @@ /* Save output frame if required */ if (ARG_SAVEDECOUTPUT) { - sprintf(filename, "%sdec%05d", filepath, filenr); - if(write_image(filename, out_buffer)) { + sprintf(filename, "%sdec", filepath); + + if(write_image(filename, out_buffer, filenr)) { fprintf(stderr, "Error writing decoded frame %s\n", filename); @@ -475,7 +482,7 @@ fprintf(stderr, " -i string : input filename (default=stdin)\n"); fprintf(stderr, " -d : save decoder output\n"); fprintf(stderr, " -c csp : choose colorspace output (rgb16, rgb24, rgb32, yv12, i420)\n"); - fprintf(stderr, " -f format : choose output file format (tga, pnm, pgm)\n"); + fprintf(stderr, " -f format : choose output file format (tga, pnm, pgm, yuv)\n"); fprintf(stderr, " -m : save mpeg4 raw stream to individual files\n"); fprintf(stderr, " -help : This help message\n"); fprintf(stderr, " (* means default)\n"); @@ -497,7 +504,7 @@ #else clock_t clk; clk = clock(); - return(clk * 1000 / CLOCKS_PER_SEC); + return(clk * 1000.0 / CLOCKS_PER_SEC); #endif } @@ -505,7 +512,7 @@ * output functions ****************************************************************************/ -static int write_image(char *prefix, unsigned char *image) +static int write_image(char *prefix, unsigned char *image, int filenr) { char filename[1024]; char *ext; @@ -515,6 +522,8 @@ ext = "pgm"; } else if (FORMAT == USE_PNM && BPP == 3) { ext = "pnm"; + } else if (FORMAT == USE_YUV) { + ext = "yuv"; } else if (FORMAT == USE_TGA) { ext = "tga"; } else { @@ -522,10 +531,20 @@ exit(-1); } - sprintf(filename, "%s.%s", prefix, ext); + if (FORMAT == USE_YUV) { + sprintf(filename, "%s.%s", prefix, ext); + + if (!filenr) { + FILE *fp = fopen(filename, "wb"); + fclose(fp); + } + } else + sprintf(filename, "%s%05d.%s", prefix, filenr, ext); if (FORMAT == USE_PNM) { ret = write_pnm(filename, image); + } else if (FORMAT == USE_YUV) { + ret = write_yuv(filename, image); } else { ret = write_tga(filename, image); } @@ -625,7 +644,7 @@ if (BPP == 1) { int i; - fprintf(f, "P5\n#xvid\n%i %i\n255\n", XDIM, YDIM*3/2); + fprintf(f, "P5\n%i %i\n255\n", XDIM, YDIM*3/2); fwrite(image, 1, XDIM*YDIM, f); @@ -654,6 +673,22 @@ return 0; } +static int write_yuv(char *filename, unsigned char *image) +{ + FILE * f; + + f = fopen(filename, "ab+"); + if ( f == NULL) { + return -1; + } + + fwrite(image, 1, 3*XDIM*YDIM/2, f); + + fclose(f); + + return 0; +} + /***************************************************************************** * Routines for decoding: init decoder, use, and stop decoder ****************************************************************************/