[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 1646, Fri Oct 7 15:02:28 2005 UTC revision 1882, Tue Mar 9 09:20:05 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.22 2005-10-07 15:02:28 suxen_drol Exp $   * $Id: xvid_decraw.c,v 1.27 2010-03-09 09:20:05 Isibaar Exp $
24   *   *
25   ****************************************************************************/   ****************************************************************************/
26    
# Line 56  Line 56 
56    
57  #define USE_PNM 0  #define USE_PNM 0
58  #define USE_TGA 1  #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;
# Line 65  Line 66 
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;
# Line 87  Line 89 
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);
96    
97  const char * type2str(int type)  const char * type2str(int type)
98  {  {
# Line 120  Line 123 
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];
# Line 130  Line 133 
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
# Line 138  Line 141 
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) {
# Line 170  Line 173 
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) {
184                                  FORMAT = USE_TGA;                                  FORMAT = USE_TGA;
185                            } else if (strcmp(argv[i], "yuv") == 0) {
186                                    FORMAT = USE_YUV;
187                          } else {                          } else {
188                                  FORMAT = USE_PNM;                                  FORMAT = USE_PNM;
189                          }                          }
# Line 212  Line 222 
222          if (BPP != 1 && BPP != 3 && FORMAT == USE_PNM) {          if (BPP != 1 && BPP != 3 && FORMAT == USE_PNM) {
223                  FORMAT = USE_TGA;                  FORMAT = USE_TGA;
224          }          }
225            if (BPP != 1 && FORMAT == USE_YUV) {
226                    FORMAT = USE_TGA;
227            }
228    
229  /*****************************************************************************  /*****************************************************************************
230   *        Memory allocation   *        Memory allocation
# Line 224  Line 237 
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);
# Line 267  Line 280 
280                          mp4_ptr = mp4_buffer;                          mp4_ptr = mp4_buffer;
281    
282                          /* read new data */                          /* read new data */
283              if(feof(in_file))              if(!feof(in_file)) {
                                 break;  
   
284                          useful_bytes += fread(mp4_buffer + already_in_buffer,                          useful_bytes += fread(mp4_buffer + already_in_buffer,
285                                                                    1, BUFFER_SIZE - already_in_buffer,                                                                    1, BUFFER_SIZE - already_in_buffer,
286                                                                    in_file);                                                                    in_file);
287                            }
288                  }                  }
289    
290    
# Line 370  Line 381 
381    
382                  /* Save output frame if required */                  /* Save output frame if required */
383                  if (ARG_SAVEDECOUTPUT) {                  if (ARG_SAVEDECOUTPUT) {
384                          sprintf(filename, "%sdec%05d", filepath, filenr);                          sprintf(filename, "%sdec", filepath);
385                          if(write_image(filename, out_buffer)) {  
386                            if(write_image(filename, out_buffer, filenr)) {
387                                  fprintf(stderr,                                  fprintf(stderr,
388                                                  "Error writing decoded frame %s\n",                                                  "Error writing decoded frame %s\n",
389                                                  filename);                                                  filename);
# Line 418  Line 430 
430    
431                  /* Save output frame if required */                  /* Save output frame if required */
432                  if (ARG_SAVEDECOUTPUT) {                  if (ARG_SAVEDECOUTPUT) {
433                          sprintf(filename, "%sdec%05d", filepath, filenr);                          sprintf(filename, "%sdec", filepath);
434                          if(write_image(filename, out_buffer)) {  
435                            if(write_image(filename, out_buffer, filenr)) {
436                                  fprintf(stderr,                                  fprintf(stderr,
437                                                  "Error writing decoded frame %s\n",                                                  "Error writing decoded frame %s\n",
438                                                  filename);                                                  filename);
# Line 444  Line 457 
457          }          }
458    
459  /*****************************************************************************  /*****************************************************************************
460   *      XviD PART  Stop   *      Xvid PART  Stop
461   ****************************************************************************/   ****************************************************************************/
462    
463   release_all:   release_all:
# Line 470  Line 483 
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)\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");
# Line 505  Line 519 
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;
# Line 515  Line 529 
529                  ext = "pgm";                  ext = "pgm";
530          } else if (FORMAT == USE_PNM && BPP == 3) {          } else if (FORMAT == USE_PNM && BPP == 3) {
531                  ext = "pnm";                  ext = "pnm";
532            } else if (FORMAT == USE_YUV) {
533                    ext = "yuv";
534          } else if (FORMAT == USE_TGA) {          } else if (FORMAT == USE_TGA) {
535                  ext = "tga";                  ext = "tga";
536          } else {          } else {
# Line 522  Line 538 
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) {
554                    ret = write_yuv(filename, image);
555          } else {          } else {
556                  ret = write_tga(filename, image);                  ret = write_tga(filename, image);
557          }          }
# Line 625  Line 651 
651    
652          if (BPP == 1) {          if (BPP == 1) {
653                  int i;                  int i;
654                  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);
655    
656                  fwrite(image, 1, XDIM*YDIM, f);                  fwrite(image, 1, XDIM*YDIM, f);
657    
# Line 654  Line 680 
680          return 0;          return 0;
681  }  }
682    
683    static int write_yuv(char *filename, unsigned char *image)
684    {
685            FILE * f;
686    
687            f = fopen(filename, "ab+");
688            if ( f == NULL) {
689                    return -1;
690            }
691    
692            fwrite(image, 1, 3*XDIM*YDIM/2, f);
693    
694            fclose(f);
695    
696            return 0;
697    }
698    
699  /*****************************************************************************  /*****************************************************************************
700   * Routines for decoding: init decoder, use, and stop decoder   * Routines for decoding: init decoder, use, and stop decoder
701   ****************************************************************************/   ****************************************************************************/
# Line 672  Line 714 
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 */
# Line 693  Line 735 
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 */
# Line 734  Line 776 
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 */

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

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