20 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
21 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
22 |
* |
* |
23 |
* $Id: xvid_decraw.c,v 1.10 2004-03-22 22:36:23 edgomez Exp $ |
* $Id: xvid_decraw.c,v 1.10.2.1 2004-04-07 22:02:56 edgomez Exp $ |
24 |
* |
* |
25 |
****************************************************************************/ |
****************************************************************************/ |
26 |
|
|
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; |
140 |
ARG_INPUTFILE = argv[i]; |
ARG_INPUTFILE = argv[i]; |
141 |
} else if (strcmp("-m", argv[i]) == 0) { |
} else if (strcmp("-m", argv[i]) == 0) { |
142 |
ARG_SAVEMPEGSTREAM = 1; |
ARG_SAVEMPEGSTREAM = 1; |
143 |
|
} else if (strcmp("-c", argv[i]) == 0 && i < argc - 1 ) { |
144 |
|
i++; |
145 |
|
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]) == 0) { |
} else if (strcmp("-help", argv[i]) == 0) { |
162 |
usage(); |
usage(); |
163 |
return(0); |
return(0); |
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); |
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); |
411 |
fprintf(stderr, " -asm : use assembly optimizations (default=disabled)\n"); |
fprintf(stderr, " -asm : use assembly optimizations (default=disabled)\n"); |
412 |
fprintf(stderr, " -i string : input filename (default=stdin)\n"); |
fprintf(stderr, " -i string : input filename (default=stdin)\n"); |
413 |
fprintf(stderr, " -d : save decoder output\n"); |
fprintf(stderr, " -d : save decoder output\n"); |
414 |
|
fprintf(stderr, " -c csp : choose colorspace output (csp can be one of rgb16, rgb24, rgb32, yv12, i420)\n"); |
415 |
fprintf(stderr, " -m : save mpeg4 raw stream to individual files\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"); |
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 |
|
} |
453 |
FILE *filehandle; |
|
454 |
filehandle=fopen(filename,"w+b"); |
hdr[0] = 0; /* ID length */ |
455 |
if (filehandle) { |
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 header */ |
/* Write header */ |
479 |
fprintf(filehandle,"P5\n\n%d %d 255\n", XDIM,YDIM*3/2); |
fwrite(hdr, 1, sizeof(hdr), f); |
|
|
|
|
/* Write Y data */ |
|
|
fwrite(y, 1, XDIM*YDIM, filehandle); |
|
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 |
|
|
518 |
/* Close file */ |
|
519 |
fclose(filehandle); |
/* Close the file */ |
520 |
|
fclose(f); |
521 |
|
|
522 |
return(0); |
return(0); |
523 |
} |
} |
|
else |
|
|
return(1); |
|
|
} |
|
524 |
|
|
525 |
/***************************************************************************** |
/***************************************************************************** |
526 |
* Routines for decoding: init decoder, use, and stop decoder |
* Routines for decoding: init decoder, use, and stop decoder |
600 |
|
|
601 |
/* Output frame structure */ |
/* Output frame structure */ |
602 |
xvid_dec_frame.output.plane[0] = ostream; |
xvid_dec_frame.output.plane[0] = ostream; |
603 |
xvid_dec_frame.output.stride[0] = XDIM; |
xvid_dec_frame.output.stride[0] = XDIM*BPP; |
604 |
xvid_dec_frame.output.csp = XVID_CSP_I420; |
xvid_dec_frame.output.csp = CSP; |
605 |
|
|
606 |
ret = xvid_decore(dec_handle, XVID_DEC_DECODE, &xvid_dec_frame, xvid_dec_stats); |
ret = xvid_decore(dec_handle, XVID_DEC_DECODE, &xvid_dec_frame, xvid_dec_stats); |
607 |
|
|