[svn] / branches / dev-api-4 / xvidcore / examples / xvid_stat.c Repository:
ViewVC logotype

Diff of /branches/dev-api-4/xvidcore/examples/xvid_stat.c

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

revision 483, Sat Sep 14 23:54:17 2002 UTC revision 728, Wed Dec 18 20:48:25 2002 UTC
# Line 19  Line 19 
19   *  along with this program; if not, write to the Free Software   *  along with this program; if not, write to the Free Software
20   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21   *   *
22   * $Id: xvid_stat.c,v 1.6 2002-09-14 23:54:17 edgomez Exp $   * $Id: xvid_stat.c,v 1.17 2002-12-18 20:48:25 edgomez Exp $
23   *   *
24   ****************************************************************************/   ****************************************************************************/
25    
# Line 44  Line 44 
44   *  -q integer     : quality ([0..5])   *  -q integer     : quality ([0..5])
45   *  -d boolean     : save decoder output (0 False*, !=0 True)   *  -d boolean     : save decoder output (0 False*, !=0 True)
46   *  -m boolean     : save mpeg4 raw stream (0 False*, !=0 True)   *  -m boolean     : save mpeg4 raw stream (0 False*, !=0 True)
47   *  -h, -help      : prints this help message   *  -mv integer    : Hinted Motion Estimation (0 none, 1 get hints, 2 set hints)
48     *  -help          : prints this help message
49   *  -quant integer : fixed quantizer (disables -b setting)   *  -quant integer : fixed quantizer (disables -b setting)
50   *  (* means default)   *  (* means default)
51   *   *
# Line 65  Line 66 
66  #include <stdlib.h>  #include <stdlib.h>
67  #include <string.h>  #include <string.h>
68  #include <math.h>  #include <math.h>
69    #ifndef _MSC_VER
70    #include <sys/time.h>
71    #else
72  #include <time.h>  #include <time.h>
73    #endif
74    
75  #include "../src/xvid.h"  #include "xvid.h"
76    
77  /****************************************************************************  /****************************************************************************
78   *                               Prototypes   *                               Prototypes
# Line 95  Line 100 
100  static int enc_init(int use_assembler);  static int enc_init(int use_assembler);
101  static int enc_stop();  static int enc_stop();
102  static int enc_main(unsigned char* image, unsigned char* bitstream,  static int enc_main(unsigned char* image, unsigned char* bitstream,
103                                          int *streamlength, int* frametype);                                          unsigned char* hints_buffer,
104                                            long *streamlength, long* frametype, long* hints_size);
105    
106  /* Decoder related functions */  /* Decoder related functions */
107  static int dec_stop();  static int dec_stop();
# Line 108  Line 114 
114   ****************************************************************************/   ****************************************************************************/
115    
116  static int const motion_presets[7] = {  static int const motion_presets[7] = {
117          0,                                                        // Q 0          0,                                                        /* Q 0 */
118          PMV_EARLYSTOP16,                                          // Q 1          PMV_EARLYSTOP16,                                          /* Q 1 */
119          PMV_EARLYSTOP16,                                          // Q 2          PMV_EARLYSTOP16,                                          /* Q 2 */
120          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16,                    // Q 3          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16,                    /* Q 3 */
121          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16,                    // Q 4          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16,                    /* Q 4 */
122          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 |  // Q 5          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 |  /* Q 5 */
123          PMV_HALFPELREFINE8,          PMV_HALFPELREFINE8,
124          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | // Q 6          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | /* Q 6 */
125          PMV_USESQUARES16 | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8          PMV_USESQUARES16 | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8
126  };  };
127    
128  static int const general_presets[7] = {  static int const general_presets[7] = {
129          XVID_H263QUANT,                               // Q 0          XVID_H263QUANT,                               /* Q 0 */
130          XVID_MPEGQUANT,                               // Q 1          XVID_MPEGQUANT,                               /* Q 1 */
131          XVID_H263QUANT,                               // Q 2          XVID_H263QUANT,                               /* Q 2 */
132          XVID_H263QUANT | XVID_HALFPEL,                // Q 3          XVID_H263QUANT | XVID_HALFPEL,                /* Q 3 */
133          XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, // Q 4          XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, /* Q 4 */
134          XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, // Q 5          XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, /* Q 5 */
135          XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V  // Q 6          XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V  /* Q 6 */
136  };  };
137    
138    
# Line 137  Line 143 
143  /* Maximum number of frames to encode */  /* Maximum number of frames to encode */
144  #define ABS_MAXFRAMENR 9999  #define ABS_MAXFRAMENR 9999
145    
146    /* HINTMODEs */
147    #define HINT_MODE_NONE 0
148    #define HINT_MODE_GET  1
149    #define HINT_MODE_SET  2
150    #define HINT_FILE "hints.mv"
151    
152  static int   ARG_BITRATE = 900;  static int   ARG_BITRATE = 900;
153  static int   ARG_QUANTI = 0;  static int   ARG_QUANTI = 0;
154  static int   ARG_QUALITY = 6;  static int   ARG_QUALITY = 6;
# Line 148  Line 160 
160  static int   ARG_INPUTTYPE = 0;  static int   ARG_INPUTTYPE = 0;
161  static int   ARG_SAVEDECOUTPUT = 0;  static int   ARG_SAVEDECOUTPUT = 0;
162  static int   ARG_SAVEMPEGSTREAM = 0;  static int   ARG_SAVEMPEGSTREAM = 0;
163    static int   ARG_HINTMODE = HINT_MODE_NONE;
164  static int   XDIM = 0;  static int   XDIM = 0;
165  static int   YDIM = 0;  static int   YDIM = 0;
166    #define IMAGE_SIZE(x,y) ((x)*(y)*3/2)
167    
168  #define MAX(A,B) ( ((A)>(B)) ? (A) : (B) )  #define MAX(A,B) ( ((A)>(B)) ? (A) : (B) )
169  #define SMALL_EPS 1e-10  #define SMALL_EPS 1e-10
170    
171    #define LONG_PACK(a,b,c,d) ((long) (((long)(a))<<24) | (((long)(b))<<16) | \
172                                       (((long)(c))<<8)  |((long)(d)))
173    
174    #define SWAP(a) ( (((a)&0x000000ff)<<24) | (((a)&0x0000ff00)<<8) | \
175                      (((a)&0x00ff0000)>>8)  | (((a)&0xff000000)>>24) )
176    
177  /****************************************************************************  /****************************************************************************
178   *                     Nasty global vars ;-)   *                     Nasty global vars ;-)
179   ***************************************************************************/   ***************************************************************************/
# Line 178  Line 198 
198          unsigned char *divx_buffer = NULL;          unsigned char *divx_buffer = NULL;
199          unsigned char *in_buffer = NULL;          unsigned char *in_buffer = NULL;
200          unsigned char *out_buffer = NULL;          unsigned char *out_buffer = NULL;
201            unsigned char *hints_buffer = NULL;
202    
203          double enctime,dectime;          double enctime,dectime;
204          double totalenctime=0.;          double totalenctime=0.;
205          double totaldectime=0.;          double totaldectime=0.;
206    
207          long totalsize=0;          long totalsize=0;
208            long hints_size;
209          int status;          int status;
210            int bigendian;
211    
212          int m4v_size;          long m4v_size;
213          int frame_type[ABS_MAXFRAMENR];          long frame_type[ABS_MAXFRAMENR];
214          int Iframes=0, Pframes=0, use_assembler=0;          int Iframes=0, Pframes=0, use_assembler=0;
215          double framepsnr[ABS_MAXFRAMENR];          double framepsnr[ABS_MAXFRAMENR];
216    
217          double Ipsnr=0.,Imaxpsnr=0.,Iminpsnr=999.,Ivarpsnr=0.;          double Ipsnr=0.,Imaxpsnr=0.,Iminpsnr=999.,Ivarpsnr=0.;
218          double Ppsnr=0.,Pmaxpsnr=0.,Pminpsnr=999.,Pvarpsnr=0.;          double Ppsnr=0.,Pmaxpsnr=0.,Pminpsnr=999.,Pvarpsnr=0.;
         double Bpsnr=0.,Bmaxpsnr=0.,Bminpsnr=999.,Bvarpsnr=0.;  
219    
220          char filename[256];          char filename[256];
221    
222          FILE *filehandle;          FILE *filehandle;
223          FILE *in_file = stdin;          FILE *in_file = stdin;
224            FILE *hints_file = NULL;
225    
226          printf("xvid_stat - XviD core library test program ");          printf("xvid_stat - XviD core library test program ");
227          printf("written by Christoph Lampert 2002\n\n");          printf("written by Christoph Lampert 2002\n\n");
# Line 256  Line 279 
279                          i++;                          i++;
280                          ARG_SAVEMPEGSTREAM = atoi(argv[i]);                          ARG_SAVEMPEGSTREAM = atoi(argv[i]);
281                  }                  }
282                  else if (strcmp("-h", argv[i]) == 0 || strcmp("-help", argv[i])) {                  else if (strcmp("-mv", argv[i]) == 0 && i < argc - 1 ) {
283                            i++;
284                            ARG_HINTMODE = atoi(argv[i]);
285                    }
286                    else if (strcmp("-help", argv[i])) {
287                          usage();                          usage();
288                          return(0);                          return(0);
289                  }                  }
# Line 271  Line 298 
298   *                            Arguments checking   *                            Arguments checking
299   ****************************************************************************/   ****************************************************************************/
300    
301          if ( ARG_INPUTTYPE == 0 &&          if (XDIM <= 0 || XDIM >= 2048 || YDIM <=0 || YDIM >= 2048 ) {
302                   ((XDIM <= 0) || (XDIM >= 2048) || (YDIM <=0) || (YDIM >= 2048)) ) {                  fprintf(stderr, "Trying to retreive width and height from PGM header\n");
                 fprintf(stderr,  
                                 "Wrong frame sizes width=%d height=%d, trying PGM header infos\n",  
                                 XDIM,  
                                 YDIM);  
303                  ARG_INPUTTYPE = 1; /* pgm */                  ARG_INPUTTYPE = 1; /* pgm */
304          }          }
         else {  
                 YDIM = YDIM*3/2; /* YUV */  
         }  
305    
306          if ( ARG_QUALITY < 0 || ARG_QUALITY > 6) {          if ( ARG_QUALITY < 0 || ARG_QUALITY > 6) {
307                  fprintf(stderr,"Wrong Quality\n");                  fprintf(stderr,"Wrong Quality\n");
# Line 294  Line 314 
314          }          }
315    
316          if ( ARG_FRAMERATE <= 0) {          if ( ARG_FRAMERATE <= 0) {
317                  fprintf(stderr,"Wrong Fraterate %s \n",argv[5]);                  fprintf(stderr,"Wrong Framerate %s \n",argv[5]);
318                  return -1;                  return -1;
319          }          }
320    
# Line 303  Line 323 
323                  return -1;                  return -1;
324          }          }
325    
326            if ( ARG_HINTMODE != HINT_MODE_NONE &&
327                     ARG_HINTMODE != HINT_MODE_GET &&
328                     ARG_HINTMODE != HINT_MODE_SET)
329                    ARG_HINTMODE = HINT_MODE_NONE;
330    
331            if( ARG_HINTMODE != HINT_MODE_NONE) {
332                    char *rights = "rb";
333    
334                    /*
335                     * If we are getting hints from core, we will have to write them to
336                     * hint file
337                     */
338                    if(ARG_HINTMODE == HINT_MODE_GET)
339                            rights = "w+b";
340    
341                    /* Open the hint file */
342                    hints_file = fopen(HINT_FILE, rights);
343                    if(hints_file == NULL) {
344                            fprintf(stderr, "Error opening input file %s\n", HINT_FILE);
345                            return -1;
346                    }
347    
348                    /* Allocate hint memory space, we will be using rawhints */
349                    /* NB : Hope 1Mb is enough */
350                    if((hints_buffer = malloc(1024*1024)) == NULL) {
351                            fprintf(stderr, "Memory allocation error\n");
352                            return -1;
353                    }
354    
355            }
356    
357          if ( ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) {          if ( ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) {
358                  in_file = stdin;                  in_file = stdin;
359          }          }
# Line 318  Line 369 
369          if (ARG_INPUTTYPE) {          if (ARG_INPUTTYPE) {
370                  if (read_pgmheader(in_file)) {                  if (read_pgmheader(in_file)) {
371                          fprintf(stderr, "Wrong input format, I want YUV encapsulated in PGM\n");                          fprintf(stderr, "Wrong input format, I want YUV encapsulated in PGM\n");
372                          return -11;                          return -1;
373                  }                  }
374          }          }
375    
376          /* now we know the sizes, so allocate memory */          /* now we know the sizes, so allocate memory */
377    
378          in_buffer = (unsigned char *) malloc(XDIM*YDIM);          in_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM,YDIM));
379          if (!in_buffer)          if (!in_buffer)
380                  goto free_all_memory;                  goto free_all_memory;
381    
382          /* this should really be enough memory ! */          /* this should really be enough memory ! */
383          divx_buffer = (unsigned char *) malloc(XDIM*YDIM*2);          divx_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM,YDIM)*2);
384          if (!divx_buffer)          if (!divx_buffer)
385                  goto free_all_memory;                  goto free_all_memory;
386    
387          /* PGM is YUV 4:2:0 format, so real image height is *2/3 of PGM picture */          out_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM,YDIM)*4);
         YDIM = YDIM*2/3;  
   
         out_buffer = (unsigned char *) malloc(XDIM*YDIM*4);  
388          if (!out_buffer)          if (!out_buffer)
389                  goto free_all_memory;                  goto free_all_memory;
390    
# Line 360  Line 408 
408                  goto release_all;                  goto release_all;
409          }          }
410    
411            totalsize = LONG_PACK('M','P','4','U');
412            if(*((char *)(&totalsize)) == 'M')
413                    bigendian = 1;
414            else
415                    bigendian = 0;
416    
417  /*****************************************************************************  /*****************************************************************************
418   *                            Main loop   *                            Main loop
# Line 368  Line 421 
421          do {          do {
422    
423                  if (ARG_INPUTTYPE)                  if (ARG_INPUTTYPE)
424                          status = read_pgmdata(in_file, in_buffer);      // read PGM data (YUV-format)                          status = read_pgmdata(in_file, in_buffer);      /* read PGM data (YUV-format) */
425                  else                  else
426                          status = read_yuvdata(in_file, in_buffer);      // read raw data (YUV-format)                          status = read_yuvdata(in_file, in_buffer);      /* read raw data (YUV-format) */
427    
428                  if (status)                  if (status)
429                  {                  {
# Line 396  Line 449 
449   */   */
450    
451  /*****************************************************************************  /*****************************************************************************
452     *                       Read hints from file
453     ****************************************************************************/
454    
455                    if(ARG_HINTMODE == HINT_MODE_SET) {
456                            fread(&hints_size, 1, sizeof(long), hints_file);
457                            hints_size = (!bigendian)?SWAP(hints_size):hints_size;
458                            fread(hints_buffer, 1, hints_size, hints_file);
459                    }
460    
461    /*****************************************************************************
462   *                       Encode and decode this frame   *                       Encode and decode this frame
463   ****************************************************************************/   ****************************************************************************/
464    
465                  enctime = msecond();                  enctime = msecond();
466                  status = enc_main(in_buffer, divx_buffer, &m4v_size, &frame_type[filenr]);                  status = enc_main(in_buffer, divx_buffer, hints_buffer,
467                                                      &m4v_size, &frame_type[filenr], &hints_size);
468                  enctime = msecond() - enctime;                  enctime = msecond() - enctime;
469    
470                  totalenctime += enctime;                  totalenctime += enctime;
# Line 409  Line 473 
473                  printf("Frame %5d: intra %1d, enctime=%6.1f ms, size=%6d bytes ",                  printf("Frame %5d: intra %1d, enctime=%6.1f ms, size=%6d bytes ",
474                             (int)filenr, (int)frame_type[filenr], (float)enctime, (int)m4v_size);                             (int)filenr, (int)frame_type[filenr], (float)enctime, (int)m4v_size);
475    
476    /*****************************************************************************
477     *                       Save hints to file
478     ****************************************************************************/
479    
480                    if(ARG_HINTMODE == HINT_MODE_GET) {
481                            hints_size = (!bigendian)?SWAP(hints_size):hints_size;
482                            fwrite(&hints_size, 1, sizeof(long), hints_file);
483                            hints_size = (!bigendian)?SWAP(hints_size):hints_size;
484                            fwrite(hints_buffer, 1, hints_size, hints_file);
485                    }
486    
487    /*****************************************************************************
488     *                       Save stream to file
489     ****************************************************************************/
490    
491                  if (ARG_SAVEMPEGSTREAM)                  if (ARG_SAVEMPEGSTREAM)
492                  {                  {
493                          sprintf(filename, "%sframe%05d.m4v", filepath, filenr);                          sprintf(filename, "%sframe%05d.m4v", filepath, filenr);
# Line 428  Line 507 
507   *             Analyse the decoded frame and compare to original   *             Analyse the decoded frame and compare to original
508   ****************************************************************************/   ****************************************************************************/
509    
510                  framepsnr[filenr] = PSNR(XDIM,YDIM, in_buffer, XDIM, out_buffer, XDIM );                  framepsnr[filenr] = PSNR(XDIM,YDIM*3/2, in_buffer, XDIM, out_buffer, XDIM);
511    
512                  printf("dectime =%6.1f ms PSNR %5.2f\n",dectime, framepsnr[filenr]);                  printf("dectime =%6.1f ms PSNR %5.2f\n",dectime, framepsnr[filenr]);
513    
# Line 503  Line 582 
582    
583          /* Print all statistics */          /* Print all statistics */
584          printf("Avg. Q%1d %2s ",ARG_QUALITY, (ARG_QUANTI ? " q" : "br"));          printf("Avg. Q%1d %2s ",ARG_QUALITY, (ARG_QUANTI ? " q" : "br"));
585          printf("%04d ",MAX(ARG_QUANTI,ARG_BITRATE));          printf("%04d ",(ARG_QUANTI)?ARG_QUANTI:ARG_BITRATE);
586          printf("( %.2f bpp) ", (double)ARG_BITRATE*1000/XDIM/YDIM/ARG_FRAMERATE);          printf("( %.2f bpp) ", (double)ARG_BITRATE*1000/XDIM/YDIM/ARG_FRAMERATE);
587          printf("size %6d ",totalsize);          printf("size %6d ", (int)totalsize);
588          printf("( %4d kbps ",(int)(totalsize*8*ARG_FRAMERATE/1000));          printf("( %4d kbps ",(int)(totalsize*8*ARG_FRAMERATE/1000));
589          printf("/ %.2f bpp) ",(double)totalsize*8/XDIM/YDIM);          printf("/ %.2f bpp) ",(double)totalsize*8/XDIM/YDIM);
590          printf("enc: %6.1f fps, dec: %6.1f fps \n",1/totalenctime, 1/totaldectime);          printf("enc: %6.1f fps, dec: %6.1f fps \n",1000/totalenctime, 1000/totaldectime);
591          printf("PSNR P(%d): %5.2f ( %5.2f , %5.2f ; %5.4f ) ",Pframes,Ppsnr,Pminpsnr,Pmaxpsnr,sqrt(Pvarpsnr/filenr));          printf("PSNR P(%d): %5.2f ( %5.2f , %5.2f ; %5.4f ) ",Pframes,Ppsnr,Pminpsnr,Pmaxpsnr,sqrt(Pvarpsnr/filenr));
592          printf("I(%d): %5.2f ( %5.2f , %5.2f ; %5.4f ) ",Iframes,Ipsnr,Iminpsnr,Imaxpsnr,sqrt(Ivarpsnr/filenr));          printf("I(%d): %5.2f ( %5.2f , %5.2f ; %5.4f ) ",Iframes,Ipsnr,Iminpsnr,Imaxpsnr,sqrt(Ivarpsnr/filenr));
593          printf("\n");          printf("\n");
# Line 557  Line 636 
636  /* Return time elapsed time in miliseconds since the program started */  /* Return time elapsed time in miliseconds since the program started */
637  static double msecond()  static double msecond()
638  {  {
639    #ifndef _MSC_VER
640            struct timeval  tv;
641            gettimeofday(&tv, 0);
642            return tv.tv_sec*1.0e3 + tv.tv_usec * 1.0e-3;
643    #else
644          clock_t clk;          clock_t clk;
   
645          clk = clock();          clk = clock();
   
646          return clk * 1000 / CLOCKS_PER_SEC;          return clk * 1000 / CLOCKS_PER_SEC;
647    #endif
648  }  }
649    
650    
# Line 634  Line 716 
716          fprintf(stderr, " -q integer     : quality ([0..5])\n");          fprintf(stderr, " -q integer     : quality ([0..5])\n");
717          fprintf(stderr, " -d boolean     : save decoder output (0 False*, !=0 True)\n");          fprintf(stderr, " -d boolean     : save decoder output (0 False*, !=0 True)\n");
718          fprintf(stderr, " -m boolean     : save mpeg4 raw stream (0 False*, !=0 True)\n");          fprintf(stderr, " -m boolean     : save mpeg4 raw stream (0 False*, !=0 True)\n");
719          fprintf(stderr, " -h, -help      : prints this help message\n");          fprintf(stderr, " -help          : prints this help message\n");
720          fprintf(stderr, " -quant integer : fixed quantizer (disables -b setting)\n");          fprintf(stderr, " -quant integer : fixed quantizer (disables -b setting)\n");
721          fprintf(stderr, " (* means default)\n");          fprintf(stderr, " (* means default)\n");
722    
# Line 657  Line 739 
739    
740          if ( (bytes < 2) || (dummy[0] != 'P') || (dummy[1] != '5' ))          if ( (bytes < 2) || (dummy[0] != 'P') || (dummy[1] != '5' ))
741                  return 1;                  return 1;
742    
743          fscanf(handle,"%d %d %d",&xsize,&ysize,&depth);          fscanf(handle,"%d %d %d",&xsize,&ysize,&depth);
744          if ( (xsize > 1440) || (ysize > 2880 ) || (depth != 255) )          if ( (xsize > 1440) || (ysize > 2880 ) || (depth != 255) )
745          {          {
# Line 666  Line 749 
749          if ( (XDIM==0) || (YDIM==0) )          if ( (XDIM==0) || (YDIM==0) )
750          {          {
751                  XDIM=xsize;                  XDIM=xsize;
752                  YDIM=ysize;                  YDIM=ysize*2/3;
753          }          }
754    
755          return 0;          return 0;
# Line 677  Line 760 
760          int i;          int i;
761          char dummy;          char dummy;
762    
763          unsigned char* buff1_ptr2 = image + XDIM*YDIM;          unsigned char *y = image;
764          unsigned char* buff1_ptr3 = image + XDIM*YDIM + XDIM/2*YDIM/2;          unsigned char *u = image + XDIM*YDIM;
765            unsigned char *v = image + XDIM*YDIM + XDIM/2*YDIM/2;
766    
767          fread(image,XDIM*YDIM,1, handle);       // read Y component of picture          /* read Y component of picture */
768            fread(y, 1, XDIM*YDIM, handle);
769    
770          for (i=0;i<YDIM/2;i++)          for (i=0;i<YDIM/2;i++)
771          {          {
772                  fread(buff1_ptr2,XDIM/2,1,handle);        // read U                  /* read U */
773                  buff1_ptr2 += XDIM/2;                  fread(u, 1, XDIM/2, handle);
774                  fread(buff1_ptr3,XDIM/2,1,handle);               // read V  
775                  buff1_ptr3 += XDIM/2;                  /* read V */
776                    fread(v, 1, XDIM/2, handle);
777    
778                    /* Update pointers */
779                    u += XDIM/2;
780                    v += XDIM/2;
781          }          }
782          fread(&dummy,1,1,handle);       //  I don't know why, but this seems needed  
783        /*  I don't know why, but this seems needed */
784            fread(&dummy, 1, 1, handle);
785    
786          return 0;          return 0;
787  }  }
788    
789  static int read_yuvdata(FILE* handle, unsigned char *image)  static int read_yuvdata(FILE* handle, unsigned char *image)
790  {  {
791    
792          unsigned char* buff1_ptr2 = image + XDIM*YDIM;          if (fread(image, 1, IMAGE_SIZE(XDIM, YDIM), handle) != (unsigned int)IMAGE_SIZE(XDIM, YDIM))
         unsigned char* buff1_ptr3 = image + XDIM*YDIM + XDIM/2*YDIM/2;  
   
         if (fread(image,XDIM,YDIM*3/2,handle) != (unsigned int)YDIM*3/2)  
793                  return 1;                  return 1;
794          else          else
795                  return 0;                  return 0;
# Line 707  Line 797 
797    
798  static int write_pgm(char *filename, unsigned char *image)  static int write_pgm(char *filename, unsigned char *image)
799  {  {
800            int loop;
801    
802            unsigned char *y = image;
803            unsigned char *u = image + XDIM*YDIM;
804            unsigned char *v = image + XDIM*YDIM + XDIM/2*YDIM/2;
805    
806          FILE *filehandle;          FILE *filehandle;
807          filehandle=fopen(filename,"wb");          filehandle=fopen(filename,"w+b");
808          if (filehandle)          if (filehandle)
809          {          {
810                  fprintf(filehandle,"P5\n\n");           //                  /* Write header */
811                  fprintf(filehandle,"%d %d 255\n",XDIM,YDIM*3/2);                  fprintf(filehandle,"P5\n\n%d %d 255\n", XDIM,YDIM*3/2);
812                  fwrite(image, XDIM*YDIM*3/2, 1 ,filehandle);  
813                    /* Write Y data */
814                    fwrite(y, 1, XDIM*YDIM, filehandle);
815    
816                    for(loop=0; loop<YDIM/2; loop++)
817                    {
818                            /* Write U scanline */
819                            fwrite(u, 1, XDIM/2, filehandle);
820    
821                            /* Write V scanline */
822                            fwrite(v, 1, XDIM/2, filehandle);
823    
824                            /* Update pointers */
825                            u += XDIM/2;
826                            v += XDIM/2;
827    
828                    }
829    
830                    /* Close file */
831                  fclose(filehandle);                  fclose(filehandle);
832    
833                  return 0;                  return 0;
834          }          }
835          else          else
# Line 765  Line 880 
880      xparam.rc_averaging_period = 100;      xparam.rc_averaging_period = 100;
881      xparam.rc_buffer = 10;      xparam.rc_buffer = 10;
882          xparam.rc_bitrate = ARG_BITRATE*1000;          xparam.rc_bitrate = ARG_BITRATE*1000;
883          xparam.min_quantizer = 1;          xparam.min_quantizer = ARG_MINQUANT;
884          xparam.max_quantizer = 31;          xparam.max_quantizer = ARG_MAXQUANT;
885          xparam.max_key_interval = (int)ARG_FRAMERATE*10;          xparam.max_key_interval = (int)ARG_FRAMERATE*10;
886    
887          /* I use a small value here, since will not encode whole movies, but short clips */          /* I use a small value here, since will not encode whole movies, but short clips */
# Line 787  Line 902 
902  }  }
903    
904  static int enc_main(unsigned char* image, unsigned char* bitstream,  static int enc_main(unsigned char* image, unsigned char* bitstream,
905                                          int *streamlength, int* frametype)                                          unsigned char* hints_buffer,
906                                            long *streamlength, long* frametype, long* hints_size)
907  {  {
908          int xerr;          int xerr;
909    
# Line 795  Line 911 
911          XVID_ENC_STATS xstats;          XVID_ENC_STATS xstats;
912    
913          xframe.bitstream = bitstream;          xframe.bitstream = bitstream;
914          xframe.length = -1;     // this is written by the routine          xframe.length = -1;     /* this is written by the routine */
915    
916          xframe.image = image;          xframe.image = image;
917          xframe.colorspace = XVID_CSP_YV12;      // defined in <xvid.h>          xframe.colorspace = XVID_CSP_YV12;      /* defined in <xvid.h> */
918    
919          xframe.intra = -1; // let the codec decide between I-frame (1) and P-frame (0)          xframe.intra = -1; /* let the codec decide between I-frame (1) and P-frame (0) */
920    
921          xframe.quant = ARG_QUANTI;      // is quant != 0, use a fixed quant (and ignore bitrate)          xframe.quant = ARG_QUANTI;      /* is quant != 0, use a fixed quant (and ignore bitrate) */
922    
923          xframe.motion = motion_presets[ARG_QUALITY];          xframe.motion = motion_presets[ARG_QUALITY];
924          xframe.general = general_presets[ARG_QUALITY];          xframe.general = general_presets[ARG_QUALITY];
925          xframe.quant_intra_matrix = xframe.quant_inter_matrix = NULL;          xframe.quant_intra_matrix = xframe.quant_inter_matrix = NULL;
926    
927            xframe.hint.hintstream = hints_buffer;
928    
929            if(ARG_HINTMODE == HINT_MODE_SET) {
930                    xframe.hint.hintlength = *hints_size;
931                    xframe.hint.rawhints = 0;
932                    xframe.general |= XVID_HINTEDME_SET;
933            }
934    
935            if(ARG_HINTMODE == HINT_MODE_GET) {
936                    xframe.hint.rawhints = 0;
937                    xframe.general |= XVID_HINTEDME_GET;
938            }
939    
940          xerr = xvid_encore(enc_handle, XVID_ENC_ENCODE, &xframe, &xstats);          xerr = xvid_encore(enc_handle, XVID_ENC_ENCODE, &xframe, &xstats);
941    
942            if(ARG_HINTMODE == HINT_MODE_GET)
943                    *hints_size = xframe.hint.hintlength;
944    
945          /*          /*
946           * This is statictical data, e.g. for 2-pass. If you are not           * This is statictical data, e.g. for 2-pass. If you are not
947           * interested in any of this, you can use NULL instead of &xstats           * interested in any of this, you can use NULL instead of &xstats
# Line 864  Line 996 
996          xframe.length = m4v_size;          xframe.length = m4v_size;
997          xframe.image = out_buffer;          xframe.image = out_buffer;
998          xframe.stride = XDIM;          xframe.stride = XDIM;
999          xframe.colorspace = XVID_CSP_YV12;             // XVID_CSP_USER is fastest (no memcopy involved)          xframe.colorspace = XVID_CSP_YV12;             /* XVID_CSP_USER is fastest (no memcopy involved) */
1000    
1001          xerr = xvid_decore(dec_handle, XVID_DEC_DECODE, &xframe, NULL);          xerr = xvid_decore(dec_handle, XVID_DEC_DECODE, &xframe, NULL);
1002    

Legend:
Removed from v.483  
changed lines
  Added in v.728

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