[svn] / branches / release-1_0-branch / xvidcore / examples / xvid_decraw.c Repository:
ViewVC logotype

Diff of /branches/release-1_0-branch/xvidcore/examples/xvid_decraw.c

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

trunk/xvidcore/examples/xvid_decraw.c revision 851, Sat Feb 15 15:22:19 2003 UTC branches/release-1_0-branch/xvidcore/examples/xvid_decraw.c revision 1414, Wed Apr 7 22:02:56 2004 UTC
# Line 4  Line 4 
4   *  - Console based decoding test application  -   *  - Console based decoding test application  -
5   *   *
6   *  Copyright(C) 2002-2003 Christoph Lampert   *  Copyright(C) 2002-2003 Christoph Lampert
7     *               2002-2003 Edouard Gomez <ed.gomez@free.fr>
8   *   *
9   *  This program is free software; you can redistribute it and/or modify   *  This program is free software; you can redistribute it and/or modify
10   *  it under the terms of the GNU General Public License as published by   *  it under the terms of the GNU General Public License as published by
# Line 19  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.6 2003-02-15 15:22:17 edgomez Exp $   * $Id: xvid_decraw.c,v 1.10.2.1 2004-04-07 22:02:56 edgomez Exp $
24   *   *
25   ****************************************************************************/   ****************************************************************************/
26    
# Line 31  Line 32 
32   *  the speed for this is measured.   *  the speed for this is measured.
33   *   *
34   *  The program is plain C and needs no libraries except for libxvidcore,   *  The program is plain C and needs no libraries except for libxvidcore,
35   *  and maths-lib, so with UN*X you simply compile by   *  and maths-lib.
36   *   *
37   *   gcc xvid_decraw.c -lxvidcore -lm -o xvid_decraw   *  Use ./xvid_decraw -help for a list of options
  *  
  *  You have to specify the image dimensions (until the add the feature  
  *  to read this from the bitstream)  
  *  
  * Usage : xvid_decraw <-w width> <-h height> [OPTIONS]  
  * Options :  
  *  -asm           : use assembly optimizations (default=disabled)  
  *  -w integer     : frame width ([1.2048])  
  *  -h integer     : frame height ([1.2048])  
  *  -i string      : input filename (default=stdin)  
  *  -t integer     : input data type (raw=0, mp4u=1)  
  *  -d boolean     : save decoder output (0 False*, !=0 True)  
  *  -m boolean     : save mpeg4 raw stream to single files (0 False*, !=0 True)  
  *  -help          : This help message  
  * (* means default)  
38   *   *
39   ****************************************************************************/   ****************************************************************************/
40    
# Line 76  Line 62 
62  static int ARG_SAVEDECOUTPUT = 0;  static int ARG_SAVEDECOUTPUT = 0;
63  static int ARG_SAVEMPEGSTREAM = 0;  static int ARG_SAVEMPEGSTREAM = 0;
64  static char *ARG_INPUTFILE = NULL;  static char *ARG_INPUTFILE = NULL;
65    static int CSP = XVID_CSP_I420;
66    static int BPP = 1;
67    
68  static char filepath[256] = "./";  static char filepath[256] = "./";
69  static void *dec_handle = NULL;  static void *dec_handle = NULL;
70    
71  # define BUFFER_SIZE 10*XDIM*YDIM  #define BUFFER_SIZE (2*1024*1024)
72    
73  /*****************************************************************************  /*****************************************************************************
74   *               Local prototypes   *               Local prototypes
# Line 94  Line 81 
81  static int dec_main(unsigned char *istream,  static int dec_main(unsigned char *istream,
82                                          unsigned char *ostream,                                          unsigned char *ostream,
83                                          int istream_size,                                          int istream_size,
84                                          int *ostream_size,                                          xvid_dec_stats_t *xvid_dec_stats);
                                         int *isframe);  
85  static int dec_stop();  static int dec_stop();
86  static void usage();  static void usage();
87    
88    
89    const char * type2str(int type)
90    {
91        if (type==XVID_TYPE_IVOP)
92            return "I";
93        if (type==XVID_TYPE_PVOP)
94            return "P";
95        if (type==XVID_TYPE_BVOP)
96            return "B";
97        return "S";
98    }
99    
100  /*****************************************************************************  /*****************************************************************************
101   *        Main program   *        Main program
102   ****************************************************************************/   ****************************************************************************/
# Line 108  Line 106 
106          unsigned char *mp4_buffer = NULL;          unsigned char *mp4_buffer = NULL;
107          unsigned char *mp4_ptr    = NULL;          unsigned char *mp4_ptr    = NULL;
108          unsigned char *out_buffer = NULL;          unsigned char *out_buffer = NULL;
109          int bigendian = 0;          int useful_bytes;
110          int still_left_in_buffer;          xvid_dec_stats_t xvid_dec_stats;
         int delayed_frames;  
111    
112          double totaldectime;          double totaldectime;
113    
# Line 136  Line 133 
133    
134                  if (strcmp("-asm", argv[i]) == 0 ) {                  if (strcmp("-asm", argv[i]) == 0 ) {
135                          use_assembler = 1;                          use_assembler = 1;
136                  }                  } else if (strcmp("-d", argv[i]) == 0) {
137                  else if (strcmp("-w", argv[i]) == 0 && i < argc - 1 ) {                          ARG_SAVEDECOUTPUT = 1;
138                          i++;                  } else if (strcmp("-i", argv[i]) == 0 && i < argc - 1 ) {
                         XDIM = atoi(argv[i]);  
                 }  
                 else if (strcmp("-h", argv[i]) == 0 && i < argc - 1 ) {  
                         i++;  
                         YDIM = atoi(argv[i]);  
                 }  
                 else if (strcmp("-d", argv[i]) == 0 && i < argc - 1 ) {  
                         i++;  
                         ARG_SAVEDECOUTPUT = atoi(argv[i]);  
                 }  
                 else if (strcmp("-i", argv[i]) == 0 && i < argc - 1 ) {  
139                          i++;                          i++;
140                          ARG_INPUTFILE = argv[i];                          ARG_INPUTFILE = argv[i];
141                  }                  } else if (strcmp("-m", argv[i]) == 0) {
142                  else if (strcmp("-m", argv[i]) == 0 && i < argc - 1 ) {                          ARG_SAVEMPEGSTREAM = 1;
143                    } else if (strcmp("-c", argv[i]) == 0  && i < argc - 1 ) {
144                          i++;                          i++;
145                          ARG_SAVEMPEGSTREAM = atoi(argv[i]);                          if (strcmp(argv[i], "rgb16") == 0) {
146                                    CSP = XVID_CSP_RGB555;
147                                    BPP = 2;
148                            } else if (strcmp(argv[i], "rgb24") == 0) {
149                                    CSP = XVID_CSP_BGR;
150                                    BPP = 3;
151                            } else if (strcmp(argv[i], "rgb32") == 0) {
152                                    CSP = XVID_CSP_BGRA;
153                                    BPP = 4;
154                            } else if (strcmp(argv[i], "yv12") == 0) {
155                                    CSP = XVID_CSP_YV12;
156                                    BPP = 1;
157                            } else {
158                                    CSP = XVID_CSP_I420;
159                                    BPP = 1;
160                  }                  }
161                  else if (strcmp("-help", argv[i])) {                  } else if (strcmp("-help", argv[i]) == 0) {
162                          usage();                          usage();
163                          return(0);                          return(0);
164                  }                  } else {
                 else {  
165                          usage();                          usage();
166                          exit(-1);                          exit(-1);
167                  }                  }
   
168          }          }
169    
170  /*****************************************************************************  /*****************************************************************************
171   * Values checking   * Values checking
172   ****************************************************************************/   ****************************************************************************/
173    
         if(XDIM <= 0 || XDIM > 2048 || YDIM <= 0 || YDIM > 2048) {  
                 usage();  
                 return -1;  
         }  
   
174          if ( ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) {          if ( ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) {
175                  in_file = stdin;                  in_file = stdin;
176          }          }
# Line 185  Line 179 
179                  in_file = fopen(ARG_INPUTFILE, "rb");                  in_file = fopen(ARG_INPUTFILE, "rb");
180                  if (in_file == NULL) {                  if (in_file == NULL) {
181                          fprintf(stderr, "Error opening input file %s\n", ARG_INPUTFILE);                          fprintf(stderr, "Error opening input file %s\n", ARG_INPUTFILE);
182                          return -1;                          return(-1);
183                  }                  }
184          }          }
185    
# Line 199  Line 193 
193          if (!mp4_buffer)          if (!mp4_buffer)
194                  goto free_all_memory;                  goto free_all_memory;
195    
         /* Memory for frame output */  
         out_buffer = (unsigned char *) malloc(XDIM*YDIM*4);  
         if (!out_buffer)  
                 goto free_all_memory;  
   
   
196  /*****************************************************************************  /*****************************************************************************
197   *        XviD PART  Start   *        XviD PART  Start
198   ****************************************************************************/   ****************************************************************************/
# Line 222  Line 210 
210   ****************************************************************************/   ****************************************************************************/
211    
212          /* Fill the buffer */          /* Fill the buffer */
213          still_left_in_buffer = fread(mp4_buffer, 1, BUFFER_SIZE, in_file);          useful_bytes = fread(mp4_buffer, 1, BUFFER_SIZE, in_file);
214    
215          totaldectime = 0;          totaldectime = 0;
216          totalsize = 0;          totalsize = 0;
217          filenr = 0;          filenr = 0;
         delayed_frames = 0;  
218          mp4_ptr = mp4_buffer;          mp4_ptr = mp4_buffer;
219    
220          do {          do {
   
                 int mp4_size = (mp4_buffer + BUFFER_SIZE - mp4_ptr);  
221                  int used_bytes = 0;                  int used_bytes = 0;
222                  double dectime;                  double dectime;
                 int notification;  
223    
224                  /*                  /*
225                   * If the buffer is half empty or there are no more bytes in it                   * If the buffer is half empty or there are no more bytes in it
226                   * then fill it.                   * then fill it.
227                   */                   */
228                  if (mp4_ptr > mp4_buffer + BUFFER_SIZE/2 ||                  if (mp4_ptr > mp4_buffer + BUFFER_SIZE/2) {
229                          still_left_in_buffer <= 0) {                          int already_in_buffer = (mp4_buffer + BUFFER_SIZE - mp4_ptr);
                         int rest = (mp4_buffer + BUFFER_SIZE - mp4_ptr);  
230    
231                          /* Move data if needed */                          /* Move data if needed */
232                          if (rest)                          if (already_in_buffer > 0)
233                                  memcpy(mp4_buffer, mp4_ptr, rest);                                  memcpy(mp4_buffer, mp4_ptr, already_in_buffer);
234    
235                          /* Update mp4_ptr */                          /* Update mp4_ptr */
236                          mp4_ptr = mp4_buffer;                          mp4_ptr = mp4_buffer;
# Line 256  Line 239 
239                          if(feof(in_file))                          if(feof(in_file))
240                                  break;                                  break;
241    
242                          still_left_in_buffer = fread(mp4_buffer + rest,                          useful_bytes += fread(mp4_buffer + already_in_buffer,
243                                                                                   1,                                                                    1, BUFFER_SIZE - already_in_buffer,
                                                                                  BUFFER_SIZE - rest,  
244                                                                                   in_file);                                                                                   in_file);
245    
246                  }                  }
247    
248    
249                  /* This loop flushes N_VOPS (with vop_coded bit set to 0) */                  /* This loop is needed to handle VOL/NVOP reading */
250                  do {                  do {
251    
252                          /* Decode frame */                          /* Decode frame */
253                          dectime = msecond();                          dectime = msecond();
254                          status = dec_main(mp4_ptr, out_buffer, mp4_size, &used_bytes, &notification);                          used_bytes = dec_main(mp4_ptr, out_buffer, useful_bytes, &xvid_dec_stats);
255                          dectime = msecond() - dectime;                          dectime = msecond() - dectime;
256    
257                          if (status) {                          /* Resize image buffer if needed */
258                                  break;                          if(xvid_dec_stats.type == XVID_TYPE_VOL) {
259    
260                                    /* Check if old buffer is smaller */
261                                    if(XDIM*YDIM < xvid_dec_stats.data.vol.width*xvid_dec_stats.data.vol.height) {
262    
263                                            /* Copy new witdh and new height from the vol structure */
264                                            XDIM = xvid_dec_stats.data.vol.width;
265                                            YDIM = xvid_dec_stats.data.vol.height;
266    
267                                            /* Free old output buffer*/
268                                            if(out_buffer) free(out_buffer);
269    
270                                            /* Allocate the new buffer */
271                                            out_buffer = (unsigned char*)malloc(XDIM*YDIM*4);
272                                            if(out_buffer == NULL)
273                                                    goto free_all_memory;
274    
275                                            fprintf(stderr, "Resized frame buffer to %dx%d\n", XDIM, YDIM);
276                                    }
277                          }                          }
278    
279                          /* Update buffer pointers */                          /* Update buffer pointers */
280                            if(used_bytes > 0) {
281                          mp4_ptr += used_bytes;                          mp4_ptr += used_bytes;
282                          still_left_in_buffer -= used_bytes;                                  useful_bytes -= used_bytes;
283    
284                          /* Total size */                          /* Total size */
285                          totalsize += used_bytes;                          totalsize += used_bytes;
286                            }
287    
288                  }while(used_bytes <= 7 && still_left_in_buffer > 0); /* <= 7 bytes is a NVOPS */                  }while(xvid_dec_stats.type <= 0 && useful_bytes > 0);
   
                 /* Negative buffer would mean we went too far */  
                 if(still_left_in_buffer < 0) break;  
289    
290                  /* Skip when decoder is buffering images or decoding VOL information */                  /* Check if there is a negative number of useful bytes left in buffer
291                  if(notification != XVID_DEC_VOP) {                   * This means we went too far */
292                          /* It's a delay only if it notifies NOTHING */          if(useful_bytes < 0)
293                          if(notification == XVID_DEC_NOTHING)              break;
                                 delayed_frames++;  
                         continue;  
                 }  
294    
295                  /* Updated data - Count only usefull decode time */                  /* Updated data - Count only usefull decode time */
296                  totaldectime += dectime;                  totaldectime += dectime;
297    
298                  /* Prints some decoding stats */  
299                  printf("Frame %5d: dectime(ms) =%6.1f, length(bytes) =%7d\n",          printf("Frame %5d: type = %s, dectime(ms) =%6.1f, length(bytes) =%7d\n",
300                             filenr, dectime, used_bytes);                             filenr, type2str(xvid_dec_stats.type), dectime, used_bytes);
301    
302                  /* Save individual mpeg4 stream if required */                  /* Save individual mpeg4 stream if required */
303                  if (ARG_SAVEMPEGSTREAM) {                  if (ARG_SAVEMPEGSTREAM) {
# Line 315  Line 311 
311                                                  filename);                                                  filename);
312                          }                          }
313                          else {                          else {
314                                  fwrite(mp4_buffer, 1, used_bytes, filehandle);                                  fwrite(mp4_ptr-used_bytes, 1, used_bytes, filehandle);
315                                  fclose(filehandle);                                  fclose(filehandle);
316                          }                          }
317                  }                  }
318    
319                  /* Save output frame if required */                  /* Save output frame if required */
320                  if (ARG_SAVEDECOUTPUT) {                  if (ARG_SAVEDECOUTPUT) {
321                          sprintf(filename, "%sdec%05d.pgm", filepath, filenr);                          sprintf(filename, "%sdec%05d.tga", filepath, filenr);
322                          if(write_pgm(filename,out_buffer)) {                          if(write_tga(filename,out_buffer)) {
323                                  fprintf(stderr,                                  fprintf(stderr,
324                                                  "Error writing decoded PGM frame %s\n",                                                  "Error writing decoded PGM frame %s\n",
325                                                  filename);                                                  filename);
# Line 337  Line 333 
333  /*****************************************************************************  /*****************************************************************************
334   *     Flush decoder buffers   *     Flush decoder buffers
335   ****************************************************************************/   ****************************************************************************/
336          while(delayed_frames--) {  
337            do {
338    
339                  /* Fake vars */                  /* Fake vars */
340                  int used_bytes, isframe;                  int used_bytes;
341                  double dectime;                  double dectime;
342    
343                  /* Decode frame */          do {
344                  dectime = msecond();                  dectime = msecond();
345                  status = dec_main(NULL, out_buffer, -1, &used_bytes, &isframe);                      used_bytes = dec_main(NULL, out_buffer, -1, &xvid_dec_stats);
346                  dectime = msecond() - dectime;                  dectime = msecond() - dectime;
347            }while(used_bytes>=0 && xvid_dec_stats.type <= 0);
348    
349                  if (status) {          if (used_bytes < 0) {   /* XVID_ERR_END */
350                          break;                          break;
351                  }                  }
352    
# Line 356  Line 354 
354                  totaldectime += dectime;                  totaldectime += dectime;
355    
356                  /* Prints some decoding stats */                  /* Prints some decoding stats */
357                  printf("Frame %5d: dectime(ms) =%6.1f, length(bytes) =%7d\n",          printf("Frame %5d: type = %s, dectime(ms) =%6.1f, length(bytes) =%7d\n",
358                             filenr, dectime, used_bytes);                             filenr, type2str(xvid_dec_stats.type), dectime, used_bytes);
359    
360                  /* Save output frame if required */                  /* Save output frame if required */
361                  if (ARG_SAVEDECOUTPUT) {                  if (ARG_SAVEDECOUTPUT) {
362                          sprintf(filename, "%sdec%05d.pgm", filepath, filenr);                          sprintf(filename, "%sdec%05d.tga", filepath, filenr);
363                          if(write_pgm(filename,out_buffer)) {                          if(write_tga(filename, out_buffer)) {
364                                  fprintf(stderr,                                  fprintf(stderr,
365                                                  "Error writing decoded PGM frame %s\n",                                                  "Error writing decoded PGM frame %s\n",
366                                                  filename);                                                  filename);
# Line 371  Line 369 
369    
370                  filenr++;                  filenr++;
371    
372          }          }while(1);
373    
374  /*****************************************************************************  /*****************************************************************************
375   *     Calculate totals and averages for output, print results   *     Calculate totals and averages for output, print results
# Line 398  Line 396 
396          free(out_buffer);          free(out_buffer);
397          free(mp4_buffer);          free(mp4_buffer);
398    
399          return 0;          return(0);
400  }  }
401    
402  /*****************************************************************************  /*****************************************************************************
# Line 408  Line 406 
406  static void usage()  static void usage()
407  {  {
408    
409          fprintf(stderr, "Usage : xvid_decraw <-w width> <-h height> [OPTIONS]\n");          fprintf(stderr, "Usage : xvid_decraw [OPTIONS]\n");
410          fprintf(stderr, "Options :\n");          fprintf(stderr, "Options :\n");
411          fprintf(stderr, " -asm           : use assembly optimizations (default=disabled)\n");          fprintf(stderr, " -asm           : use assembly optimizations (default=disabled)\n");
         fprintf(stderr, " -w integer     : frame width ([1.2048])\n");  
         fprintf(stderr, " -h integer     : frame height ([1.2048])\n");  
412          fprintf(stderr, " -i string      : input filename (default=stdin)\n");          fprintf(stderr, " -i string      : input filename (default=stdin)\n");
413          fprintf(stderr, " -t integer     : input data type (raw=0, mp4u=1)\n");          fprintf(stderr, " -d             : save decoder output\n");
414          fprintf(stderr, " -d boolean     : save decoder output (0 False*, !=0 True)\n");          fprintf(stderr, " -c csp         : choose colorspace output (csp can be one of rgb16, rgb24, rgb32, yv12, i420)\n");
415          fprintf(stderr, " -m boolean     : save mpeg4 raw stream to individual files (0 False*, !=0 True)\n");          fprintf(stderr, " -m             : save mpeg4 raw stream to individual files\n");
416          fprintf(stderr, " -help          : This help message\n");          fprintf(stderr, " -help          : This help message\n");
417          fprintf(stderr, " (* means default)\n");          fprintf(stderr, " (* means default)\n");
418    
# Line 433  Line 429 
429  #ifndef WIN32  #ifndef WIN32
430          struct timeval  tv;          struct timeval  tv;
431          gettimeofday(&tv, 0);          gettimeofday(&tv, 0);
432          return (double)tv.tv_sec*1.0e3 + (double)tv.tv_usec*1.0e-3;          return((double)tv.tv_sec*1.0e3 + (double)tv.tv_usec*1.0e-3);
433  #else  #else
434          clock_t clk;          clock_t clk;
435          clk = clock();          clk = clock();
436          return clk * 1000 / CLOCKS_PER_SEC;          return(clk * 1000 / CLOCKS_PER_SEC);
437  #endif  #endif
438  }  }
439    
# Line 445  Line 441 
441   *              output functions   *              output functions
442   ****************************************************************************/   ****************************************************************************/
443    
444  static int  int write_tga(char *filename, unsigned char *image)
 write_pgm(char *filename,  
           unsigned char *image)  
445  {  {
446          int loop;          FILE * f;
447            char hdr[18];
448    
449          unsigned char *y = image;          f = fopen(filename, "wb");
450          unsigned char *u = image + XDIM*YDIM;          if ( f == NULL) {
451          unsigned char *v = image + XDIM*YDIM + XDIM/2*YDIM/2;                  return -1;
452            }
         FILE *filehandle;  
         filehandle=fopen(filename,"w+b");  
         if (filehandle) {  
453    
454                  /* Write header */          hdr[0]  = 0; /* ID length */
455                  fprintf(filehandle,"P5\n\n%d %d 255\n", XDIM,YDIM*3/2);          hdr[1]  = 0; /* Color map type */
456            hdr[2]  = (BPP>1)?2:3; /* Uncompressed true color (2) or greymap (3) */
457            hdr[3]  = 0; /* Color map specification (not used) */
458            hdr[4]  = 0; /* Color map specification (not used) */
459            hdr[5]  = 0; /* Color map specification (not used) */
460            hdr[6]  = 0; /* Color map specification (not used) */
461            hdr[7]  = 0; /* Color map specification (not used) */
462            hdr[8]  = 0; /* LSB X origin */
463            hdr[9]  = 0; /* MSB X origin */
464            hdr[10] = 0; /* LSB Y origin */
465            hdr[11] = 0; /* MSB Y origin */
466            hdr[12] = (XDIM>>0)&0xff; /* LSB Width */
467            hdr[13] = (XDIM>>8)&0xff; /* MSB Width */
468            if (BPP > 1) {
469                    hdr[14] = (YDIM>>0)&0xff; /* LSB Height */
470                    hdr[15] = (YDIM>>8)&0xff; /* MSB Height */
471            } else {
472                    hdr[14] = ((YDIM*3)>>1)&0xff; /* LSB Height */
473                    hdr[15] = ((YDIM*3)>>9)&0xff; /* MSB Height */
474            }
475            hdr[16] = BPP*8;
476            hdr[17] = 0x00 | (1<<5) /* Up to down */ | (0<<4); /* Image descriptor */
477    
478                  /* Write Y data */          /* Write header */
479                  fwrite(y, 1, XDIM*YDIM, filehandle);          fwrite(hdr, 1, sizeof(hdr), f);
480    
481                  for(loop=0; loop<YDIM/2; loop++)  #ifdef ARCH_IS_LITTLE_ENDIAN
482            /* write first plane */
483            fwrite(image, 1, XDIM*YDIM*BPP, f);
484    #else
485                  {                  {
486                          /* Write U scanline */                  int i;
487                          fwrite(u, 1, XDIM/2, filehandle);                  for (i=0; i<width*height*BPP;i+=BPP) {
488                            if (BPP == 1) {
489                          /* Write V scanline */                                  fputc(image+i, f);
490                          fwrite(v, 1, XDIM/2, filehandle);                          } else if (BPP == 2) {
491                                    fputc(image+i+1, f);
492                                    fputc(image+i+0, f);
493                            } else if (BPP == 3) {
494                                    fputc(image+i+2, f);
495                                    fputc(image+i+1, f);
496                                    fputc(image+i+0, f);
497                            } else if (BPP == 4) {
498                                    fputc(image+i+3, f);
499                                    fputc(image+i+2, f);
500                                    fputc(image+i+1, f);
501                                    fputc(image+i+0, f);
502                            }
503                    }
504            }
505    #endif
506    
507                          /* Update pointers */          /* Write Y and V planes for YUV formats */
508                          u += XDIM/2;          if (BPP == 1) {
509                          v += XDIM/2;                  int i;
510    
511                    /* Write the two chrominance planes */
512                    for (i=0; i<YDIM/2; i++) {
513                            fwrite(image+XDIM*YDIM+XDIM/2*i, 1, XDIM/2, f);
514                            fwrite(image+5*XDIM*YDIM/4 + XDIM/2*i, 1, XDIM/2, f);
515                    }
516                  }                  }
517    
                 /* Close file */  
                 fclose(filehandle);  
518    
519                  return 0;          /* Close the file */
520          }          fclose(f);
521          else  
522                  return 1;          return(0);
523  }  }
524    
525  /*****************************************************************************  /*****************************************************************************
# Line 496  Line 530 
530  static int  static int
531  dec_init(int use_assembler)  dec_init(int use_assembler)
532  {  {
533          int xerr;          int ret;
534    
535            xvid_gbl_init_t   xvid_gbl_init;
536            xvid_dec_create_t xvid_dec_create;
537    
538            /*------------------------------------------------------------------------
539             * XviD core initialization
540             *----------------------------------------------------------------------*/
541    
542          XVID_INIT_PARAM xinit;          /* Version */
543          XVID_DEC_PARAM xparam;          xvid_gbl_init.version = XVID_VERSION;
544    
545            /* Assembly setting */
546                  if(use_assembler)                  if(use_assembler)
547  #ifdef ARCH_IA64  #ifdef ARCH_IS_IA64
548                          xinit.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64;                  xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64;
549  #else  #else
550                          xinit.cpu_flags = 0;          xvid_gbl_init.cpu_flags = 0;
551  #endif  #endif
552                  else                  else
553                          xinit.cpu_flags = XVID_CPU_FORCE;                  xvid_gbl_init.cpu_flags = XVID_CPU_FORCE;
554    
555            xvid_global(NULL, 0, &xvid_gbl_init, NULL);
556    
557            /*------------------------------------------------------------------------
558             * XviD encoder initialization
559             *----------------------------------------------------------------------*/
560    
561          xvid_init(NULL, 0, &xinit, NULL);          /* Version */
562          xparam.width = XDIM;          xvid_dec_create.version = XVID_VERSION;
         xparam.height = YDIM;  
563    
564          xerr = xvid_decore(NULL, XVID_DEC_CREATE, &xparam, NULL);          /*
565             * Image dimensions -- set to 0, xvidcore will resize when ever it is
566             * needed
567             */
568            xvid_dec_create.width = 0;
569            xvid_dec_create.height = 0;
570    
571            ret = xvid_decore(NULL, XVID_DEC_CREATE, &xvid_dec_create, NULL);
572    
573          dec_handle = xparam.handle;          dec_handle = xvid_dec_create.handle;
574    
575          return xerr;          return(ret);
576  }  }
577    
578  /* decode one frame  */  /* decode one frame  */
# Line 526  Line 580 
580  dec_main(unsigned char *istream,  dec_main(unsigned char *istream,
581                   unsigned char *ostream,                   unsigned char *ostream,
582                   int istream_size,                   int istream_size,
583                   int *ostream_size,                   xvid_dec_stats_t *xvid_dec_stats)
                  int *notification)  
584  {  {
585    
586          int xerr;          int ret;
587          XVID_DEC_FRAME xframe;  
588                  XVID_DEC_STATS xstats;          xvid_dec_frame_t xvid_dec_frame;
589    
590            /* Set version */
591            xvid_dec_frame.version = XVID_VERSION;
592            xvid_dec_stats->version = XVID_VERSION;
593    
594          xframe.general    = 0;          /* No general flags to set */
595                  xframe.bitstream  = istream;          xvid_dec_frame.general          = 0;
         xframe.length     = istream_size;  
                 xframe.image      = ostream;  
         xframe.stride     = XDIM;  
                 xframe.colorspace = XVID_CSP_YV12;  
596    
597                  xerr = xvid_decore(dec_handle, XVID_DEC_DECODE, &xframe, &xstats);          /* Input stream */
598            xvid_dec_frame.bitstream        = istream;
599            xvid_dec_frame.length           = istream_size;
600    
601                  *ostream_size = xframe.length;          /* Output frame structure */
602            xvid_dec_frame.output.plane[0]  = ostream;
603            xvid_dec_frame.output.stride[0] = XDIM*BPP;
604            xvid_dec_frame.output.csp = CSP;
605    
606                  *notification = xstats.notify;          ret = xvid_decore(dec_handle, XVID_DEC_DECODE, &xvid_dec_frame, xvid_dec_stats);
607    
608          return xerr;          return(ret);
609  }  }
610    
611  /* close decoder to release resources */  /* close decoder to release resources */
612  static int  static int
613  dec_stop()  dec_stop()
614  {  {
615          int xerr;          int ret;
616    
617          xerr = xvid_decore(dec_handle, XVID_DEC_DESTROY, NULL, NULL);          ret = xvid_decore(dec_handle, XVID_DEC_DESTROY, NULL, NULL);
618    
619          return xerr;          return(ret);
620  }  }

Legend:
Removed from v.851  
changed lines
  Added in v.1414

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