[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 1426, Tue Apr 13 21:20:45 2004 UTC revision 1646, Fri Oct 7 15:02:28 2005 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.13 2004-04-13 21:20:45 suxen_drol Exp $   * $Id: xvid_decraw.c,v 1.22 2005-10-07 15:02:28 suxen_drol Exp $
24   *   *
25   ****************************************************************************/   ****************************************************************************/
26    
# Line 54  Line 54 
54   *               Global vars in module and constants   *               Global vars in module and constants
55   ****************************************************************************/   ****************************************************************************/
56    
 /* max number of frames */  
 #define ABS_MAXFRAMENR 9999  
   
57  #define USE_PNM 0  #define USE_PNM 0
58  #define USE_TGA 1  #define USE_TGA 1
59    
# Line 74  Line 71 
71    
72  #define BUFFER_SIZE (2*1024*1024)  #define BUFFER_SIZE (2*1024*1024)
73    
74    static const int display_buffer_bytes = 0;
75    
76    #define MIN_USEFUL_BYTES 1
77    
78  /*****************************************************************************  /*****************************************************************************
79   *               Local prototypes   *               Local prototypes
80   ****************************************************************************/   ****************************************************************************/
# Line 87  Line 88 
88  static int dec_stop();  static int dec_stop();
89  static void usage();  static void usage();
90  static int write_image(char *prefix, unsigned char *image);  static int write_image(char *prefix, unsigned char *image);
 static int write_tga(char *filename, unsigned char *image);  
91  static int write_pnm(char *filename, unsigned char *image);  static int write_pnm(char *filename, unsigned char *image);
92    static int write_tga(char *filename, unsigned char *image);
93    
94  const char * type2str(int type)  const char * type2str(int type)
95  {  {
# Line 112  Line 112 
112          unsigned char *mp4_ptr    = NULL;          unsigned char *mp4_ptr    = NULL;
113          unsigned char *out_buffer = NULL;          unsigned char *out_buffer = NULL;
114          int useful_bytes;          int useful_bytes;
115            int chunk;
116          xvid_dec_stats_t xvid_dec_stats;          xvid_dec_stats_t xvid_dec_stats;
117    
118          double totaldectime;          double totaldectime;
# Line 187  Line 188 
188    
189  #if defined(_MSC_VER)  #if defined(_MSC_VER)
190          if (ARG_INPUTFILE==NULL) {          if (ARG_INPUTFILE==NULL) {
191                  fprintf(stderr, "Warning: MSVC build does not read correctly from stdin. Use the -i switch.\n\n");                  fprintf(stderr, "Warning: MSVC build does not read EOF correctly from stdin. Use the -i switch.\n\n");
192          }          }
193  #endif  #endif
194    
# Line 245  Line 246 
246          totalsize = 0;          totalsize = 0;
247          filenr = 0;          filenr = 0;
248          mp4_ptr = mp4_buffer;          mp4_ptr = mp4_buffer;
249            chunk = 0;
250    
251          do {          do {
252                  int used_bytes = 0;                  int used_bytes = 0;
# Line 303  Line 305 
305    
306                                          fprintf(stderr, "Resized frame buffer to %dx%d\n", XDIM, YDIM);                                          fprintf(stderr, "Resized frame buffer to %dx%d\n", XDIM, YDIM);
307                                  }                                  }
308    
309                                    /* Save individual mpeg4 stream if required */
310                                    if(ARG_SAVEMPEGSTREAM) {
311                                            FILE *filehandle = NULL;
312    
313                                            sprintf(filename, "%svolhdr.m4v", filepath);
314                                            filehandle = fopen(filename, "wb");
315                                            if(!filehandle) {
316                                                    fprintf(stderr,
317                                                                    "Error writing vol header mpeg4 stream to file %s\n",
318                                                                    filename);
319                                            } else {
320                                                    fwrite(mp4_ptr, 1, used_bytes, filehandle);
321                                                    fclose(filehandle);
322                                            }
323                                    }
324                          }                          }
325    
326                          /* Update buffer pointers */                          /* Update buffer pointers */
# Line 314  Line 332 
332                                  totalsize += used_bytes;                                  totalsize += used_bytes;
333                          }                          }
334    
335                  }while(xvid_dec_stats.type <= 0 && useful_bytes > 0);                          if (display_buffer_bytes) {
336                                    printf("Data chunk %d: %d bytes consumed, %d bytes in buffer\n", chunk++, used_bytes, useful_bytes);
337                            }
338                    } while (xvid_dec_stats.type <= 0 && useful_bytes > MIN_USEFUL_BYTES);
339    
340                  /* 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
341                   * This means we went too far */                   * This means we went too far */
# Line 325  Line 346 
346                  totaldectime += dectime;                  totaldectime += dectime;
347    
348    
349                    if (!display_buffer_bytes) {
350          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",
351                             filenr, type2str(xvid_dec_stats.type), dectime, used_bytes);                             filenr, type2str(xvid_dec_stats.type), dectime, used_bytes);
352                    }
353    
354                  /* Save individual mpeg4 stream if required */                  /* Save individual mpeg4 stream if required */
355                  if(ARG_SAVEMPEGSTREAM) {                  if(ARG_SAVEMPEGSTREAM) {
# Line 357  Line 380 
380    
381                  filenr++;                  filenr++;
382    
383          } while ( (status>=0) && (filenr<ABS_MAXFRAMENR));          } while (useful_bytes>MIN_USEFUL_BYTES || !feof(in_file));
384    
385            useful_bytes = 0; /* Empty buffer */
386    
387  /*****************************************************************************  /*****************************************************************************
388   *     Flush decoder buffers   *     Flush decoder buffers
# Line 373  Line 398 
398                      dectime = msecond();                      dectime = msecond();
399                      used_bytes = dec_main(NULL, out_buffer, -1, &xvid_dec_stats);                      used_bytes = dec_main(NULL, out_buffer, -1, &xvid_dec_stats);
400                      dectime = msecond() - dectime;                      dectime = msecond() - dectime;
401                            if (display_buffer_bytes) {
402                                    printf("Data chunk %d: %d bytes consumed, %d bytes in buffer\n", chunk++, used_bytes, useful_bytes);
403                            }
404          }while(used_bytes>=0 && xvid_dec_stats.type <= 0);          }while(used_bytes>=0 && xvid_dec_stats.type <= 0);
405    
406          if (used_bytes < 0) {   /* XVID_ERR_END */          if (used_bytes < 0) {   /* XVID_ERR_END */
# Line 383  Line 411 
411                  totaldectime += dectime;                  totaldectime += dectime;
412    
413                  /* Prints some decoding stats */                  /* Prints some decoding stats */
414                    if (!display_buffer_bytes) {
415          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",
416                             filenr, type2str(xvid_dec_stats.type), dectime, used_bytes);                             filenr, type2str(xvid_dec_stats.type), dectime, used_bytes);
417                    }
418    
419                  /* Save output frame if required */                  /* Save output frame if required */
420                  if (ARG_SAVEDECOUTPUT) {                  if (ARG_SAVEDECOUTPUT) {
# Line 413  Line 443 
443                  printf("Nothing was decoded!\n");                  printf("Nothing was decoded!\n");
444          }          }
445    
   
446  /*****************************************************************************  /*****************************************************************************
447   *      XviD PART  Stop   *      XviD PART  Stop
448   ****************************************************************************/   ****************************************************************************/
# Line 468  Line 497 
497  #else  #else
498          clock_t clk;          clock_t clk;
499          clk = clock();          clk = clock();
500          return(clk * 1000 / CLOCKS_PER_SEC);          return(clk * 1000.0 / CLOCKS_PER_SEC);
501  #endif  #endif
502  }  }
503    
# Line 547  Line 576 
576  #else  #else
577          {          {
578                  int i;                  int i;
579                  for (i=0; i<width*height*BPP;i+=BPP) {                  for (i=0; i<XDIM*YDIM*BPP;i+=BPP) {
580                          if (BPP == 1) {                          if (BPP == 1) {
581                                  fputc(image+i, f);                                  fputc(*(image+i), f);
582                          } else if (BPP == 2) {                          } else if (BPP == 2) {
583                                  fputc(image+i+1, f);                                  fputc(*(image+i+1), f);
584                                  fputc(image+i+0, f);                                  fputc(*(image+i+0), f);
585                          } else if (BPP == 3) {                          } else if (BPP == 3) {
586                                  fputc(image+i+2, f);                                  fputc(*(image+i+2), f);
587                                  fputc(image+i+1, f);                                  fputc(*(image+i+1), f);
588                                  fputc(image+i+0, f);                                  fputc(*(image+i+0), f);
589                          } else if (BPP == 4) {                          } else if (BPP == 4) {
590                                  fputc(image+i+3, f);                                  fputc(*(image+i+3), f);
591                                  fputc(image+i+2, f);                                  fputc(*(image+i+2), f);
592                                  fputc(image+i+1, f);                                  fputc(*(image+i+1), f);
593                                  fputc(image+i+0, f);                                  fputc(*(image+i+0), f);
594                          }                          }
595                  }                  }
596          }          }
# Line 585  Line 614 
614          return(0);          return(0);
615  }  }
616    
617  int write_pnm(char *filename, unsigned char *image)  static int write_pnm(char *filename, unsigned char *image)
618  {  {
619          FILE * f;          FILE * f;
620    
# Line 624  Line 653 
653    
654          return 0;          return 0;
655  }  }
656    
657  /*****************************************************************************  /*****************************************************************************
658   * Routines for decoding: init decoder, use, and stop decoder   * Routines for decoding: init decoder, use, and stop decoder
659   ****************************************************************************/   ****************************************************************************/
# Line 637  Line 667 
667          xvid_gbl_init_t   xvid_gbl_init;          xvid_gbl_init_t   xvid_gbl_init;
668          xvid_dec_create_t xvid_dec_create;          xvid_dec_create_t xvid_dec_create;
669    
670            /* Reset the structure with zeros */
671            memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init_t));
672            memset(&xvid_dec_create, 0, sizeof(xvid_dec_create_t));
673    
674          /*------------------------------------------------------------------------          /*------------------------------------------------------------------------
675           * XviD core initialization           * XviD core initialization
676           *----------------------------------------------------------------------*/           *----------------------------------------------------------------------*/
# Line 691  Line 725 
725    
726          xvid_dec_frame_t xvid_dec_frame;          xvid_dec_frame_t xvid_dec_frame;
727    
728            /* Reset all structures */
729            memset(&xvid_dec_frame, 0, sizeof(xvid_dec_frame_t));
730            memset(xvid_dec_stats, 0, sizeof(xvid_dec_stats_t));
731    
732          /* Set version */          /* Set version */
733          xvid_dec_frame.version = XVID_VERSION;          xvid_dec_frame.version = XVID_VERSION;
734          xvid_dec_stats->version = XVID_VERSION;          xvid_dec_stats->version = XVID_VERSION;

Legend:
Removed from v.1426  
changed lines
  Added in v.1646

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