[svn] / trunk / xvidcore / examples / xvid_decraw.c Repository:
ViewVC logotype

Diff of /trunk/xvidcore/examples/xvid_decraw.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1382, Mon Mar 22 22:36:25 2004 UTC revision 1928, Tue Dec 28 19:19:57 2010 UTC
# Line 20  Line 20 
20   *  along with this program; if not, write to the Free Software   *  along with this program; if not, write to the Free Software
21   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22   *   *
23   * $Id: xvid_decraw.c,v 1.10 2004-03-22 22:36:23 edgomez Exp $   * $Id: xvid_decraw.c,v 1.29 2010-12-28 19:19:43 Isibaar Exp $
24   *   *
25   ****************************************************************************/   ****************************************************************************/
26    
# Line 54  Line 54 
54   *               Global vars in module and constants   *               Global vars in module and constants
55   ****************************************************************************/   ****************************************************************************/
56    
57  /* max number of frames */  #define USE_PNM 0
58  #define ABS_MAXFRAMENR 9999  #define USE_TGA 1
59    #define USE_YUV 2
60    
61  static int XDIM = 0;  static int XDIM = 0;
62  static int YDIM = 0;  static int YDIM = 0;
63  static int ARG_SAVEDECOUTPUT = 0;  static int ARG_SAVEDECOUTPUT = 0;
64  static int ARG_SAVEMPEGSTREAM = 0;  static int ARG_SAVEMPEGSTREAM = 0;
65  static char *ARG_INPUTFILE = NULL;  static char *ARG_INPUTFILE = NULL;
66    static int CSP = XVID_CSP_I420;
67    static int BPP = 1;
68    static int FORMAT = USE_PNM;
69    static int POSTPROC = 0;
70    static  int ARG_THREADS = 0;
71    
72  static char filepath[256] = "./";  static char filepath[256] = "./";
73  static void *dec_handle = NULL;  static void *dec_handle = NULL;
74    
75  #define BUFFER_SIZE (2*1024*1024)  #define BUFFER_SIZE (2*1024*1024)
76    
77    static const int display_buffer_bytes = 0;
78    
79    #define MIN_USEFUL_BYTES 1
80    
81  /*****************************************************************************  /*****************************************************************************
82   *               Local prototypes   *               Local prototypes
83   ****************************************************************************/   ****************************************************************************/
84    
85  static double msecond();  static double msecond();
86  static int write_pgm(char *filename,  static int dec_init(int use_assembler, int debug_level);
                                          unsigned char *image);  
 static int dec_init(int use_assembler);  
87  static int dec_main(unsigned char *istream,  static int dec_main(unsigned char *istream,
88                                          unsigned char *ostream,                                          unsigned char *ostream,
89                                          int istream_size,                                          int istream_size,
90                                          xvid_dec_stats_t *xvid_dec_stats);                                          xvid_dec_stats_t *xvid_dec_stats);
91  static int dec_stop();  static int dec_stop();
92  static void usage();  static void usage();
93    static int write_image(char *prefix, unsigned char *image, int filenr);
94    static int write_pnm(char *filename, unsigned char *image);
95    static int write_tga(char *filename, unsigned char *image);
96    static int write_yuv(char *filename, unsigned char *image);
97    
98  const char * type2str(int type)  const char * type2str(int type)
99  {  {
# Line 106  Line 116 
116          unsigned char *mp4_ptr    = NULL;          unsigned char *mp4_ptr    = NULL;
117          unsigned char *out_buffer = NULL;          unsigned char *out_buffer = NULL;
118          int useful_bytes;          int useful_bytes;
119            int chunk;
120          xvid_dec_stats_t xvid_dec_stats;          xvid_dec_stats_t xvid_dec_stats;
121    
122          double totaldectime;          double totaldectime;
# Line 113  Line 124 
124          long totalsize;          long totalsize;
125          int status;          int status;
126    
127          int use_assembler = 0;          int use_assembler = 1;
128            int debug_level = 0;
129    
130          char filename[256];          char filename[256];
131    
# Line 122  Line 134 
134          int i;          int i;
135    
136          printf("xvid_decraw - raw mpeg4 bitstream decoder ");          printf("xvid_decraw - raw mpeg4 bitstream decoder ");
137          printf("written by Christoph Lampert 2002-2003\n\n");          printf("written by Christoph Lampert\n\n");
138    
139  /*****************************************************************************  /*****************************************************************************
140   * Command line parsing   * Command line parsing
# Line 130  Line 142 
142    
143          for (i=1; i< argc; i++) {          for (i=1; i< argc; i++) {
144    
145                  if (strcmp("-asm", argv[i]) == 0 ) {                  if (strcmp("-noasm", argv[i]) == 0 ) {
146                          use_assembler = 1;                          use_assembler = 0;
147                    } else if (strcmp("-debug", argv[i]) == 0 && i < argc - 1 ) {
148                            i++;
149                            if (sscanf(argv[i], "0x%x", &debug_level) != 1) {
150                                    debug_level = atoi(argv[i]);
151                            }
152                  } else if (strcmp("-d", argv[i]) == 0) {                  } else if (strcmp("-d", argv[i]) == 0) {
153                          ARG_SAVEDECOUTPUT = 1;                          ARG_SAVEDECOUTPUT = 1;
154                  } else if (strcmp("-i", argv[i]) == 0 && i < argc - 1 ) {                  } else if (strcmp("-i", argv[i]) == 0 && i < argc - 1 ) {
# Line 139  Line 156 
156                          ARG_INPUTFILE = argv[i];                          ARG_INPUTFILE = argv[i];
157                  } else if (strcmp("-m", argv[i]) == 0) {                  } else if (strcmp("-m", argv[i]) == 0) {
158                          ARG_SAVEMPEGSTREAM = 1;                          ARG_SAVEMPEGSTREAM = 1;
159                    } else if (strcmp("-c", argv[i]) == 0  && i < argc - 1 ) {
160                            i++;
161                            if (strcmp(argv[i], "rgb16") == 0) {
162                                    CSP = XVID_CSP_RGB555;
163                                    BPP = 2;
164                            } else if (strcmp(argv[i], "rgb24") == 0) {
165                                    CSP = XVID_CSP_BGR;
166                                    BPP = 3;
167                            } else if (strcmp(argv[i], "rgb32") == 0) {
168                                    CSP = XVID_CSP_BGRA;
169                                    BPP = 4;
170                            } else if (strcmp(argv[i], "yv12") == 0) {
171                                    CSP = XVID_CSP_YV12;
172                                    BPP = 1;
173                            } else {
174                                    CSP = XVID_CSP_I420;
175                                    BPP = 1;
176                            }
177                    } else if (strcmp("-postproc", argv[i]) == 0 && i < argc - 1 ) {
178                            i++;
179                            POSTPROC = atoi(argv[i]);
180                            if (POSTPROC < 0) POSTPROC = 0;
181                            if (POSTPROC > 2) POSTPROC = 2;
182                    } else if (strcmp("-f", argv[i]) == 0 && i < argc -1) {
183                            i++;
184                            if (strcmp(argv[i], "tga") == 0) {
185                                    FORMAT = USE_TGA;
186                            } else if (strcmp(argv[i], "yuv") == 0) {
187                                    FORMAT = USE_YUV;
188                            } else {
189                                    FORMAT = USE_PNM;
190                            }
191                    } else if (strcmp("-threads", argv[i]) == 0 && i < argc -1) {
192                            i++;
193                            ARG_THREADS = atoi(argv[i]);
194                  } else if (strcmp("-help", argv[i]) == 0) {                  } else if (strcmp("-help", argv[i]) == 0) {
195                          usage();                          usage();
196                          return(0);                          return(0);
# Line 148  Line 200 
200                  }                  }
201          }          }
202    
203    #if defined(_MSC_VER)
204            if (ARG_INPUTFILE==NULL) {
205                    fprintf(stderr, "Warning: MSVC build does not read EOF correctly from stdin. Use the -i switch.\n\n");
206            }
207    #endif
208    
209  /*****************************************************************************  /*****************************************************************************
210   * Values checking   * Values checking
211   ****************************************************************************/   ****************************************************************************/
# Line 164  Line 222 
222                  }                  }
223          }          }
224    
225            /* PNM/PGM format can't handle 16/32 bit data */
226            if (BPP != 1 && BPP != 3 && FORMAT == USE_PNM) {
227                    FORMAT = USE_TGA;
228            }
229            if (BPP != 1 && FORMAT == USE_YUV) {
230                    FORMAT = USE_TGA;
231            }
232    
233  /*****************************************************************************  /*****************************************************************************
234   *        Memory allocation   *        Memory allocation
235   ****************************************************************************/   ****************************************************************************/
# Line 175  Line 241 
241                  goto free_all_memory;                  goto free_all_memory;
242    
243  /*****************************************************************************  /*****************************************************************************
244   *        XviD PART  Start   *        Xvid PART  Start
245   ****************************************************************************/   ****************************************************************************/
246    
247          status = dec_init(use_assembler);          status = dec_init(use_assembler, debug_level);
248          if (status) {          if (status) {
249                  fprintf(stderr,                  fprintf(stderr,
250                                  "Decore INIT problem, return value %d\n", status);                                  "Decore INIT problem, return value %d\n", status);
# Line 191  Line 257 
257   ****************************************************************************/   ****************************************************************************/
258    
259          /* Fill the buffer */          /* Fill the buffer */
260          useful_bytes = fread(mp4_buffer, 1, BUFFER_SIZE, in_file);          useful_bytes = (int) fread(mp4_buffer, 1, BUFFER_SIZE, in_file);
261    
262          totaldectime = 0;          totaldectime = 0;
263          totalsize = 0;          totalsize = 0;
264          filenr = 0;          filenr = 0;
265          mp4_ptr = mp4_buffer;          mp4_ptr = mp4_buffer;
266            chunk = 0;
267    
268          do {          do {
269                  int used_bytes = 0;                  int used_bytes = 0;
# Line 207  Line 274 
274                   * then fill it.                   * then fill it.
275                   */                   */
276                  if (mp4_ptr > mp4_buffer + BUFFER_SIZE/2) {                  if (mp4_ptr > mp4_buffer + BUFFER_SIZE/2) {
277                          int already_in_buffer = (mp4_buffer + BUFFER_SIZE - mp4_ptr);                          int already_in_buffer = (int)(mp4_buffer + BUFFER_SIZE - mp4_ptr);
278    
279                          /* Move data if needed */                          /* Move data if needed */
280                          if (already_in_buffer > 0)                          if (already_in_buffer > 0)
# Line 217  Line 284 
284                          mp4_ptr = mp4_buffer;                          mp4_ptr = mp4_buffer;
285    
286                          /* read new data */                          /* read new data */
287              if(feof(in_file))              if(!feof(in_file)) {
288                                  break;                                  useful_bytes += (int) fread(mp4_buffer + already_in_buffer,
   
                         useful_bytes += fread(mp4_buffer + already_in_buffer,  
289                                                                    1, BUFFER_SIZE - already_in_buffer,                                                                    1, BUFFER_SIZE - already_in_buffer,
290                                                                    in_file);                                                                    in_file);
291                            }
292                  }                  }
293    
294    
# Line 255  Line 320 
320    
321                                          fprintf(stderr, "Resized frame buffer to %dx%d\n", XDIM, YDIM);                                          fprintf(stderr, "Resized frame buffer to %dx%d\n", XDIM, YDIM);
322                                  }                                  }
323    
324                                    /* Save individual mpeg4 stream if required */
325                                    if(ARG_SAVEMPEGSTREAM) {
326                                            FILE *filehandle = NULL;
327    
328                                            sprintf(filename, "%svolhdr.m4v", filepath);
329                                            filehandle = fopen(filename, "wb");
330                                            if(!filehandle) {
331                                                    fprintf(stderr,
332                                                                    "Error writing vol header mpeg4 stream to file %s\n",
333                                                                    filename);
334                                            } else {
335                                                    fwrite(mp4_ptr, 1, used_bytes, filehandle);
336                                                    fclose(filehandle);
337                                            }
338                                    }
339                          }                          }
340    
341                          /* Update buffer pointers */                          /* Update buffer pointers */
# Line 266  Line 347 
347                                  totalsize += used_bytes;                                  totalsize += used_bytes;
348                          }                          }
349    
350                  }while(xvid_dec_stats.type <= 0 && useful_bytes > 0);                          if (display_buffer_bytes) {
351                                    printf("Data chunk %d: %d bytes consumed, %d bytes in buffer\n", chunk++, used_bytes, useful_bytes);
352                            }
353                    } while (xvid_dec_stats.type <= 0 && useful_bytes > MIN_USEFUL_BYTES);
354    
355                  /* Check if there is a negative number of useful bytes left in buffer                  /* Check if there is a negative number of useful bytes left in buffer
356                   * This means we went too far */                   * This means we went too far */
# Line 277  Line 361 
361                  totaldectime += dectime;                  totaldectime += dectime;
362    
363    
364                    if (!display_buffer_bytes) {
365          printf("Frame %5d: type = %s, dectime(ms) =%6.1f, length(bytes) =%7d\n",          printf("Frame %5d: type = %s, dectime(ms) =%6.1f, length(bytes) =%7d\n",
366                             filenr, type2str(xvid_dec_stats.type), dectime, used_bytes);                             filenr, type2str(xvid_dec_stats.type), dectime, used_bytes);
367                    }
368    
369                  /* Save individual mpeg4 stream if required */                  /* Save individual mpeg4 stream if required */
370                  if(ARG_SAVEMPEGSTREAM) {                  if(ARG_SAVEMPEGSTREAM) {
# Line 299  Line 385 
385    
386                  /* Save output frame if required */                  /* Save output frame if required */
387                  if (ARG_SAVEDECOUTPUT) {                  if (ARG_SAVEDECOUTPUT) {
388                          sprintf(filename, "%sdec%05d.pgm", filepath, filenr);                          sprintf(filename, "%sdec", filepath);
389                          if(write_pgm(filename,out_buffer)) {  
390                            if(write_image(filename, out_buffer, filenr)) {
391                                  fprintf(stderr,                                  fprintf(stderr,
392                                                  "Error writing decoded PGM frame %s\n",                                                  "Error writing decoded frame %s\n",
393                                                  filename);                                                  filename);
394                          }                          }
395                  }                  }
396    
397                  filenr++;                  filenr++;
398    
399          } while ( (status>=0) && (filenr<ABS_MAXFRAMENR));          } while (useful_bytes>MIN_USEFUL_BYTES || !feof(in_file));
400    
401            useful_bytes = 0; /* Empty buffer */
402    
403  /*****************************************************************************  /*****************************************************************************
404   *     Flush decoder buffers   *     Flush decoder buffers
# Line 325  Line 414 
414                      dectime = msecond();                      dectime = msecond();
415                      used_bytes = dec_main(NULL, out_buffer, -1, &xvid_dec_stats);                      used_bytes = dec_main(NULL, out_buffer, -1, &xvid_dec_stats);
416                      dectime = msecond() - dectime;                      dectime = msecond() - dectime;
417                            if (display_buffer_bytes) {
418                                    printf("Data chunk %d: %d bytes consumed, %d bytes in buffer\n", chunk++, used_bytes, useful_bytes);
419                            }
420          }while(used_bytes>=0 && xvid_dec_stats.type <= 0);          }while(used_bytes>=0 && xvid_dec_stats.type <= 0);
421    
422          if (used_bytes < 0) {   /* XVID_ERR_END */          if (used_bytes < 0) {   /* XVID_ERR_END */
# Line 335  Line 427 
427                  totaldectime += dectime;                  totaldectime += dectime;
428    
429                  /* Prints some decoding stats */                  /* Prints some decoding stats */
430                    if (!display_buffer_bytes) {
431          printf("Frame %5d: type = %s, dectime(ms) =%6.1f, length(bytes) =%7d\n",          printf("Frame %5d: type = %s, dectime(ms) =%6.1f, length(bytes) =%7d\n",
432                             filenr, type2str(xvid_dec_stats.type), dectime, used_bytes);                             filenr, type2str(xvid_dec_stats.type), dectime, used_bytes);
433                    }
434    
435                  /* Save output frame if required */                  /* Save output frame if required */
436                  if (ARG_SAVEDECOUTPUT) {                  if (ARG_SAVEDECOUTPUT) {
437                          sprintf(filename, "%sdec%05d.pgm", filepath, filenr);                          sprintf(filename, "%sdec", filepath);
438                          if(write_pgm(filename, out_buffer)) {  
439                            if(write_image(filename, out_buffer, filenr)) {
440                                  fprintf(stderr,                                  fprintf(stderr,
441                                                  "Error writing decoded PGM frame %s\n",                                                  "Error writing decoded frame %s\n",
442                                                  filename);                                                  filename);
443                          }                          }
444                  }                  }
# Line 356  Line 451 
451   *     Calculate totals and averages for output, print results   *     Calculate totals and averages for output, print results
452   ****************************************************************************/   ****************************************************************************/
453    
454            if (filenr>0) {
455          totalsize    /= filenr;          totalsize    /= filenr;
456          totaldectime /= filenr;          totaldectime /= filenr;
   
457          printf("Avg: dectime(ms) =%7.2f, fps =%7.2f, length(bytes) =%7d\n",          printf("Avg: dectime(ms) =%7.2f, fps =%7.2f, length(bytes) =%7d\n",
458                     totaldectime, 1000/totaldectime, (int)totalsize);                     totaldectime, 1000/totaldectime, (int)totalsize);
459            }else{
460                    printf("Nothing was decoded!\n");
461            }
462    
463  /*****************************************************************************  /*****************************************************************************
464   *      XviD PART  Stop   *      Xvid PART  Stop
465   ****************************************************************************/   ****************************************************************************/
466    
467   release_all:   release_all:
# Line 389  Line 487 
487    
488          fprintf(stderr, "Usage : xvid_decraw [OPTIONS]\n");          fprintf(stderr, "Usage : xvid_decraw [OPTIONS]\n");
489          fprintf(stderr, "Options :\n");          fprintf(stderr, "Options :\n");
490          fprintf(stderr, " -asm           : use assembly optimizations (default=disabled)\n");          fprintf(stderr, " -noasm         : don't use assembly optimizations (default=enabled)\n");
491            fprintf(stderr, " -debug         : debug level (debug=0)\n");
492          fprintf(stderr, " -i string      : input filename (default=stdin)\n");          fprintf(stderr, " -i string      : input filename (default=stdin)\n");
493          fprintf(stderr, " -d             : save decoder output\n");          fprintf(stderr, " -d             : save decoder output\n");
494            fprintf(stderr, " -c csp         : choose colorspace output (rgb16, rgb24, rgb32, yv12, i420)\n");
495            fprintf(stderr, " -f format      : choose output file format (tga, pnm, pgm, yuv)\n");
496            fprintf(stderr, " -postproc      : postprocessing level (0=off, 1=deblock, 2=deblock+dering)\n");
497            fprintf(stderr, " -threads int   : number of threads\n");
498          fprintf(stderr, " -m             : save mpeg4 raw stream to individual files\n");          fprintf(stderr, " -m             : save mpeg4 raw stream to individual files\n");
499          fprintf(stderr, " -help          : This help message\n");          fprintf(stderr, " -help          : This help message\n");
500          fprintf(stderr, " (* means default)\n");          fprintf(stderr, " (* means default)\n");
# Line 413  Line 516 
516  #else  #else
517          clock_t clk;          clock_t clk;
518          clk = clock();          clk = clock();
519          return(clk * 1000 / CLOCKS_PER_SEC);          return(clk * 1000.0 / CLOCKS_PER_SEC);
520  #endif  #endif
521  }  }
522    
# Line 421  Line 524 
524   *              output functions   *              output functions
525   ****************************************************************************/   ****************************************************************************/
526    
527  static int  static int write_image(char *prefix, unsigned char *image, int filenr)
 write_pgm(char *filename,  
                   unsigned char *image)  
528  {  {
529          int loop;          char filename[1024];
530            char *ext;
531            int ret;
532    
533          unsigned char *y = image;          if (FORMAT == USE_PNM && BPP == 1) {
534          unsigned char *u = image + XDIM*YDIM;                  ext = "pgm";
535          unsigned char *v = image + XDIM*YDIM + XDIM/2*YDIM/2;          } else if (FORMAT == USE_PNM && BPP == 3) {
536                    ext = "pnm";
537          FILE *filehandle;          } else if (FORMAT == USE_YUV) {
538          filehandle=fopen(filename,"w+b");                  ext = "yuv";
539          if (filehandle) {          } else if (FORMAT == USE_TGA) {
540                    ext = "tga";
541            } else {
542                    fprintf(stderr, "Bug: should not reach this path code -- please report to xvid-devel@xvid.org with command line options used");
543                    exit(-1);
544            }
545    
546                  /* Write header */          if (FORMAT == USE_YUV) {
547                  fprintf(filehandle,"P5\n\n%d %d 255\n", XDIM,YDIM*3/2);                  sprintf(filename, "%s.%s", prefix, ext);
548    
549                  /* Write Y data */                  if (!filenr) {
550                  fwrite(y, 1, XDIM*YDIM, filehandle);                          FILE *fp = fopen(filename, "wb");
551                            fclose(fp);
552                    }
553            } else
554                    sprintf(filename, "%s%05d.%s", prefix, filenr, ext);
555    
556            if (FORMAT == USE_PNM) {
557                    ret = write_pnm(filename, image);
558            } else if (FORMAT == USE_YUV) {
559                    ret = write_yuv(filename, image);
560            } else {
561                    ret = write_tga(filename, image);
562            }
563    
564            return(ret);
565    }
566    
567                  for(loop=0; loop<YDIM/2; loop++)  static int write_tga(char *filename, unsigned char *image)
568                  {                  {
569                          /* Write U scanline */          FILE * f;
570                          fwrite(u, 1, XDIM/2, filehandle);          char hdr[18];
571    
572                          /* Write V scanline */          f = fopen(filename, "wb");
573                          fwrite(v, 1, XDIM/2, filehandle);          if ( f == NULL) {
574                    return -1;
575            }
576    
577            hdr[0]  = 0; /* ID length */
578            hdr[1]  = 0; /* Color map type */
579            hdr[2]  = (BPP>1)?2:3; /* Uncompressed true color (2) or greymap (3) */
580            hdr[3]  = 0; /* Color map specification (not used) */
581            hdr[4]  = 0; /* Color map specification (not used) */
582            hdr[5]  = 0; /* Color map specification (not used) */
583            hdr[6]  = 0; /* Color map specification (not used) */
584            hdr[7]  = 0; /* Color map specification (not used) */
585            hdr[8]  = 0; /* LSB X origin */
586            hdr[9]  = 0; /* MSB X origin */
587            hdr[10] = 0; /* LSB Y origin */
588            hdr[11] = 0; /* MSB Y origin */
589            hdr[12] = (XDIM>>0)&0xff; /* LSB Width */
590            hdr[13] = (XDIM>>8)&0xff; /* MSB Width */
591            if (BPP > 1) {
592                    hdr[14] = (YDIM>>0)&0xff; /* LSB Height */
593                    hdr[15] = (YDIM>>8)&0xff; /* MSB Height */
594            } else {
595                    hdr[14] = ((YDIM*3)>>1)&0xff; /* LSB Height */
596                    hdr[15] = ((YDIM*3)>>9)&0xff; /* MSB Height */
597            }
598            hdr[16] = BPP*8;
599            hdr[17] = 0x00 | (1<<5) /* Up to down */ | (0<<4); /* Image descriptor */
600    
601                          /* Update pointers */          /* Write header */
602                          u += XDIM/2;          fwrite(hdr, 1, sizeof(hdr), f);
                         v += XDIM/2;  
603    
604    #ifdef ARCH_IS_LITTLE_ENDIAN
605            /* write first plane */
606            fwrite(image, 1, XDIM*YDIM*BPP, f);
607    #else
608            {
609                    int i;
610                    for (i=0; i<XDIM*YDIM*BPP;i+=BPP) {
611                            if (BPP == 1) {
612                                    fputc(*(image+i), f);
613                            } else if (BPP == 2) {
614                                    fputc(*(image+i+1), f);
615                                    fputc(*(image+i+0), f);
616                            } else if (BPP == 3) {
617                                    fputc(*(image+i+2), f);
618                                    fputc(*(image+i+1), f);
619                                    fputc(*(image+i+0), f);
620                            } else if (BPP == 4) {
621                                    fputc(*(image+i+3), f);
622                                    fputc(*(image+i+2), f);
623                                    fputc(*(image+i+1), f);
624                                    fputc(*(image+i+0), f);
625                            }
626                  }                  }
627            }
628    #endif
629    
630                  /* Close file */          /* Write Y and V planes for YUV formats */
631                  fclose(filehandle);          if (BPP == 1) {
632                    int i;
633    
634                    /* Write the two chrominance planes */
635                    for (i=0; i<YDIM/2; i++) {
636                            fwrite(image+XDIM*YDIM + i*XDIM/2, 1, XDIM/2, f);
637                            fwrite(image+5*XDIM*YDIM/4 + i*XDIM/2, 1, XDIM/2, f);
638                    }
639            }
640    
641    
642            /* Close the file */
643            fclose(f);
644    
645                  return(0);                  return(0);
646          }          }
647          else  
648                  return(1);  static int write_pnm(char *filename, unsigned char *image)
649    {
650            FILE * f;
651    
652            f = fopen(filename, "wb");
653            if ( f == NULL) {
654                    return -1;
655            }
656    
657            if (BPP == 1) {
658                    int i;
659                    fprintf(f, "P5\n%i %i\n255\n", XDIM, YDIM*3/2);
660    
661                    fwrite(image, 1, XDIM*YDIM, f);
662    
663                    for (i=0; i<YDIM/2;i++) {
664                            fwrite(image+XDIM*YDIM + i*XDIM/2, 1, XDIM/2, f);
665                            fwrite(image+5*XDIM*YDIM/4 + i*XDIM/2, 1, XDIM/2, f);
666                    }
667            } else if (BPP == 3) {
668                    int i;
669                    fprintf(f, "P6\n#xvid\n%i %i\n255\n", XDIM, YDIM);
670                    for (i=0; i<XDIM*YDIM*3; i+=3) {
671    #ifdef ARCH_IS_LITTLE_ENDIAN
672                            fputc(image[i+2], f);
673                            fputc(image[i+1], f);
674                            fputc(image[i+0], f);
675    #else
676                            fputc(image[i+0], f);
677                            fputc(image[i+1], f);
678                            fputc(image[i+2], f);
679    #endif
680                    }
681            }
682    
683            fclose(f);
684    
685            return 0;
686    }
687    
688    static int write_yuv(char *filename, unsigned char *image)
689    {
690            FILE * f;
691    
692            f = fopen(filename, "ab+");
693            if ( f == NULL) {
694                    return -1;
695            }
696    
697            fwrite(image, 1, 3*XDIM*YDIM/2, f);
698    
699            fclose(f);
700    
701            return 0;
702  }  }
703    
704  /*****************************************************************************  /*****************************************************************************
# Line 470  Line 707 
707    
708  /* init decoder before first run */  /* init decoder before first run */
709  static int  static int
710  dec_init(int use_assembler)  dec_init(int use_assembler, int debug_level)
711  {  {
712          int ret;          int ret;
713    
714          xvid_gbl_init_t   xvid_gbl_init;          xvid_gbl_init_t   xvid_gbl_init;
715          xvid_dec_create_t xvid_dec_create;          xvid_dec_create_t xvid_dec_create;
716            xvid_gbl_info_t   xvid_gbl_info;
717    
718            /* Reset the structure with zeros */
719            memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init_t));
720            memset(&xvid_dec_create, 0, sizeof(xvid_dec_create_t));
721            memset(&xvid_gbl_info, 0, sizeof(xvid_gbl_info));
722    
723          /*------------------------------------------------------------------------          /*------------------------------------------------------------------------
724           * XviD core initialization           * Xvid core initialization
725           *----------------------------------------------------------------------*/           *----------------------------------------------------------------------*/
726    
727            xvid_gbl_info.version = XVID_VERSION;
728            xvid_global(NULL, XVID_GBL_INFO, &xvid_gbl_info, NULL);
729    
730            if (xvid_gbl_info.build != NULL) {
731                    fprintf(stderr, "xvidcore build version: %s\n", xvid_gbl_info.build);
732            }
733            fprintf(stderr, "Bitstream version: %d.%d.%d\n", XVID_VERSION_MAJOR(xvid_gbl_info.actual_version), XVID_VERSION_MINOR(xvid_gbl_info.actual_version), XVID_VERSION_PATCH(xvid_gbl_info.actual_version));
734            fprintf(stderr, "Detected CPU flags: ");
735            if (xvid_gbl_info.cpu_flags & XVID_CPU_ASM)
736                    fprintf(stderr, "ASM ");
737            if (xvid_gbl_info.cpu_flags & XVID_CPU_MMX)
738                    fprintf(stderr, "MMX ");
739            if (xvid_gbl_info.cpu_flags & XVID_CPU_MMXEXT)
740                    fprintf(stderr, "MMXEXT ");
741            if (xvid_gbl_info.cpu_flags & XVID_CPU_SSE)
742                    fprintf(stderr, "SSE ");
743            if (xvid_gbl_info.cpu_flags & XVID_CPU_SSE2)
744                    fprintf(stderr, "SSE2 ");
745            if (xvid_gbl_info.cpu_flags & XVID_CPU_SSE3)
746                    fprintf(stderr, "SSE3 ");
747            if (xvid_gbl_info.cpu_flags & XVID_CPU_SSE41)
748                    fprintf(stderr, "SSE41 ");
749        if (xvid_gbl_info.cpu_flags & XVID_CPU_3DNOW)
750                    fprintf(stderr, "3DNOW ");
751            if (xvid_gbl_info.cpu_flags & XVID_CPU_3DNOWEXT)
752                    fprintf(stderr, "3DNOWEXT ");
753            if (xvid_gbl_info.cpu_flags & XVID_CPU_TSC)
754                    fprintf(stderr, "TSC ");
755            fprintf(stderr, "\n");
756            fprintf(stderr, "Detected %d cpus,", xvid_gbl_info.num_threads);
757            if (!ARG_THREADS) ARG_THREADS = xvid_gbl_info.num_threads;
758            fprintf(stderr, " using %d threads.\n", ARG_THREADS);
759    
760          /* Version */          /* Version */
761          xvid_gbl_init.version = XVID_VERSION;          xvid_gbl_init.version = XVID_VERSION;
762    
# Line 494  Line 770 
770          else          else
771                  xvid_gbl_init.cpu_flags = XVID_CPU_FORCE;                  xvid_gbl_init.cpu_flags = XVID_CPU_FORCE;
772    
773            xvid_gbl_init.debug = debug_level;
774    
775          xvid_global(NULL, 0, &xvid_gbl_init, NULL);          xvid_global(NULL, 0, &xvid_gbl_init, NULL);
776    
777          /*------------------------------------------------------------------------          /*------------------------------------------------------------------------
778           * XviD encoder initialization           * Xvid decoder initialization
779           *----------------------------------------------------------------------*/           *----------------------------------------------------------------------*/
780    
781          /* Version */          /* Version */
# Line 510  Line 788 
788          xvid_dec_create.width = 0;          xvid_dec_create.width = 0;
789          xvid_dec_create.height = 0;          xvid_dec_create.height = 0;
790    
791            xvid_dec_create.num_threads = ARG_THREADS;
792    
793          ret = xvid_decore(NULL, XVID_DEC_CREATE, &xvid_dec_create, NULL);          ret = xvid_decore(NULL, XVID_DEC_CREATE, &xvid_dec_create, NULL);
794    
795          dec_handle = xvid_dec_create.handle;          dec_handle = xvid_dec_create.handle;
# Line 529  Line 809 
809    
810          xvid_dec_frame_t xvid_dec_frame;          xvid_dec_frame_t xvid_dec_frame;
811    
812            /* Reset all structures */
813            memset(&xvid_dec_frame, 0, sizeof(xvid_dec_frame_t));
814            memset(xvid_dec_stats, 0, sizeof(xvid_dec_stats_t));
815    
816          /* Set version */          /* Set version */
817          xvid_dec_frame.version = XVID_VERSION;          xvid_dec_frame.version = XVID_VERSION;
818          xvid_dec_stats->version = XVID_VERSION;          xvid_dec_stats->version = XVID_VERSION;
819    
820          /* No general flags to set */          /* No general flags to set */
821            if (POSTPROC == 1)
822                    xvid_dec_frame.general          = XVID_DEBLOCKY | XVID_DEBLOCKUV;
823            else if (POSTPROC==2)
824                    xvid_dec_frame.general          = XVID_DEBLOCKY | XVID_DEBLOCKUV | XVID_DERINGY | XVID_DERINGUV;
825            else
826          xvid_dec_frame.general          = 0;          xvid_dec_frame.general          = 0;
827    
828          /* Input stream */          /* Input stream */
# Line 542  Line 831 
831    
832          /* Output frame structure */          /* Output frame structure */
833          xvid_dec_frame.output.plane[0]  = ostream;          xvid_dec_frame.output.plane[0]  = ostream;
834          xvid_dec_frame.output.stride[0] = XDIM;          xvid_dec_frame.output.stride[0] = XDIM*BPP;
835          xvid_dec_frame.output.csp       = XVID_CSP_I420;          xvid_dec_frame.output.csp = CSP;
836    
837          ret = xvid_decore(dec_handle, XVID_DEC_DECODE, &xvid_dec_frame, xvid_dec_stats);          ret = xvid_decore(dec_handle, XVID_DEC_DECODE, &xvid_dec_frame, xvid_dec_stats);
838    

Legend:
Removed from v.1382  
changed lines
  Added in v.1928

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4