--- xvid_decraw.c 2005/10/07 15:02:28 1.22 +++ xvid_decraw.c 2010/01/05 09:25:19 1.25 @@ -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.22 2005/10/07 15:02:28 suxen_drol Exp $ + * $Id: xvid_decraw.c,v 1.25 2010/01/05 09:25:19 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; @@ -90,6 +91,7 @@ static int write_image(char *prefix, unsigned char *image); 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,7 +375,12 @@ /* Save output frame if required */ if (ARG_SAVEDECOUTPUT) { - sprintf(filename, "%sdec%05d", filepath, filenr); + if (FORMAT == USE_YUV) { + sprintf(filename, "%sdec", filepath); + } + else { + sprintf(filename, "%sdec%05d", filepath, filenr); + } if(write_image(filename, out_buffer)) { fprintf(stderr, "Error writing decoded frame %s\n", @@ -418,7 +428,12 @@ /* Save output frame if required */ if (ARG_SAVEDECOUTPUT) { - sprintf(filename, "%sdec%05d", filepath, filenr); + if (FORMAT == USE_YUV) { + sprintf(filename, "%sdec", filepath); + } + else { + sprintf(filename, "%sdec%05d", filepath, filenr); + } if(write_image(filename, out_buffer)) { fprintf(stderr, "Error writing decoded frame %s\n", @@ -475,7 +490,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"); @@ -515,6 +530,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 { @@ -526,6 +543,8 @@ 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,31 @@ return 0; } +static int write_yuv(char *filename, unsigned char *image) +{ + FILE * f; + + f = fopen(filename, "ab+"); + if ( f == NULL) { + return -1; + } + + if (BPP == 1) { + int i; + + fwrite(image, 1, XDIM*YDIM, f); + + for (i=0; i