--- branches/dev-api-4/xvidcore/examples/xvid_encraw.c 2003/05/18 12:24:55 1034 +++ branches/dev-api-4/xvidcore/examples/xvid_encraw.c 2003/08/09 16:46:46 1118 @@ -3,7 +3,9 @@ * XVID MPEG-4 VIDEO CODEC * - Console based test application - * - * Copyright(C) 2002-2003 Christoph Lampert + * Copyright(C) 2002-2003 Christoph Lampert + * 2002-2003 Edouard Gomez + * 2003 Peter Ross * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,7 +21,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: xvid_encraw.c,v 1.11.2.26 2003-05-18 12:24:55 edgomez Exp $ + * $Id: xvid_encraw.c,v 1.11.2.33 2003-08-09 16:46:46 Isibaar Exp $ * ****************************************************************************/ @@ -31,6 +33,8 @@ * * The program is plain C and needs no libraries except for libxvidcore, * and maths-lib. + * + * Use ./xvid_encraw -help for a list of options * ************************************************************************/ @@ -46,11 +50,13 @@ #include "xvid.h" +#undef READ_PNM /***************************************************************************** * Quality presets ****************************************************************************/ -static xvid_motion_t const motion_presets[] = { + +static const int motion_presets[] = { /* quality 0 */ 0, @@ -67,22 +73,22 @@ /* quality 4 */ XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 | XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 | - XVID_ME_CHROMA16 | XVID_ME_CHROMA8, + XVID_ME_CHROMA_PVOP | XVID_ME_CHROMA_BVOP, /* quality 5 */ XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 | XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 | - XVID_ME_CHROMA16 | XVID_ME_CHROMA8, + XVID_ME_CHROMA_PVOP | XVID_ME_CHROMA_BVOP, /* quality 6 */ XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 | XVID_ME_EXTSEARCH16 | XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 | XVID_ME_EXTSEARCH8 | - XVID_ME_CHROMA16 | XVID_ME_CHROMA8 , + XVID_ME_CHROMA_PVOP | XVID_ME_CHROMA_BVOP, }; #define ME_ELEMENTS (sizeof(motion_presets)/sizeof(motion_presets[0])) -static xvid_vop_t const vop_presets[] = { +static const int vop_presets[] = { /* quality 0 */ 0, @@ -124,6 +130,7 @@ static int ARG_STATS = 0; static int ARG_DUMP = 0; static int ARG_LUMIMASKING = 0; +static int ARG_QUARTERPEL = 0; static int ARG_BITRATE = 0; static int ARG_SINGLE = 0; static char *ARG_PASS1 = 0; @@ -145,7 +152,11 @@ static int ARG_DEBUG = 0; static int ARG_VOPDEBUG = 0; +#ifndef READ_PNM #define IMAGE_SIZE(x,y) ((x)*(y)*3/2) +#else +#define IMAGE_SIZE(x,y) ((x)*(y)*3) +#endif #define MAX(A,B) ( ((A)>(B)) ? (A) : (B) ) #define SMALL_EPS (1e-10) @@ -176,9 +187,15 @@ static double msecond(); /* PGM related functions */ +#ifndef READ_PNM static int read_pgmheader(FILE * handle); static int read_pgmdata(FILE * handle, unsigned char *image); +#else +static int read_pnmheader(FILE * handle); +static int read_pnmdata(FILE * handle, + unsigned char *image); +#endif static int read_yuvdata(FILE * handle, unsigned char *image); @@ -305,6 +322,8 @@ ARG_DUMP = 1; } else if (strcmp("-lumimasking", argv[i]) == 0) { ARG_LUMIMASKING = 1; + } else if (strcmp("-quarterpel", argv[i]) == 0) { + ARG_QUARTERPEL = 1; } else if (strcmp("-type", argv[i]) == 0 && i < argc - 1) { i++; ARG_INPUTTYPE = atoi(argv[i]); @@ -369,7 +388,11 @@ } if (ARG_INPUTTYPE) { +#ifndef READ_PNM if (read_pgmheader(in_file)) { +#else + if (read_pnmheader(in_file)) { +#endif fprintf(stderr, "Wrong input format, I want YUV encapsulated in PGM\n"); return (-1); @@ -435,7 +458,11 @@ if (!result) { if (ARG_INPUTTYPE) { /* read PGM data (YUV-format) */ +#ifndef READ_PNM result = read_pgmdata(in_file, in_buffer); +#else + result = read_pnmdata(in_file, in_buffer); +#endif } else { /* read raw data (YUV-format) */ result = read_yuvdata(in_file, in_buffer); @@ -531,8 +558,11 @@ /* Read the header if it's pgm stream */ if (!result && ARG_INPUTTYPE) - result = read_pgmheader(in_file); - +#ifndef READ_PNM + result = read_pgmheader(in_file); +#else + result = read_pnmheader(in_file); +#endif } while (1); @@ -655,6 +685,7 @@ fprintf(stderr, "Other options\n"); fprintf(stderr, " -asm : use assembly optmized code\n"); fprintf(stderr, " -quality integer: quality ([0..%d])\n", ME_ELEMENTS - 1); + fprintf(stderr, " -quarterpel : use quarterpel refinement\n"); fprintf(stderr, " -packed : packed mode\n"); fprintf(stderr, " -lumimasking : use lumimasking algorithm\n"); fprintf(stderr, " -stats : print stats about encoded frames\n"); @@ -674,6 +705,7 @@ * *****************************************************************************/ +#ifndef READ_PNM static int read_pgmheader(FILE * handle) { @@ -729,6 +761,46 @@ return (0); } +#else +static int +read_pnmheader(FILE * handle) +{ + int bytes, xsize, ysize, depth; + char dummy[2]; + + bytes = fread(dummy, 1, 2, handle); + + if ((bytes < 2) || (dummy[0] != 'P') || (dummy[1] != '6')) + return (1); + + fscanf(handle, "%d %d %d", &xsize, &ysize, &depth); + if ((xsize > 1440) || (ysize > 2880) || (depth != 255)) { + fprintf(stderr, "%d %d %d\n", xsize, ysize, depth); + return (2); + } + + XDIM = xsize; + YDIM = ysize; + + return (0); +} + +static int +read_pnmdata(FILE * handle, + unsigned char *image) +{ + int i; + char dummy; + + /* read Y component of picture */ + fread(image, 1, XDIM * YDIM * 3, handle); + + /* I don't know why, but this seems needed */ + fread(&dummy, 1, 1, handle); + + return (0); +} +#endif static int read_yuvdata(FILE * handle, @@ -820,7 +892,7 @@ if (use_assembler) { #ifdef ARCH_IS_IA64 - xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64; + xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_ASM; #else xvid_gbl_init.cpu_flags = 0; #endif @@ -985,17 +1057,25 @@ /* Initialize input image fields */ if (image) { xvid_enc_frame.input.plane[0] = image; +#ifndef READ_PNM xvid_enc_frame.input.csp = XVID_CSP_I420; xvid_enc_frame.input.stride[0] = XDIM; +#else + xvid_enc_frame.input.csp = XVID_CSP_BGR; + xvid_enc_frame.input.stride[0] = XDIM*3; +#endif } else { xvid_enc_frame.input.csp = XVID_CSP_NULL; } /* Set up core's general features */ - xvid_enc_frame.vol_flags = 0; + xvid_enc_frame.vol_flags = XVID_VOL_GMC; if (ARG_STATS) xvid_enc_frame.vol_flags |= XVID_VOL_EXTRASTATS; + if (ARG_QUARTERPEL) + xvid_enc_frame.vol_flags |= XVID_VOL_QUARTERPEL; + /* Set up core's general features */ xvid_enc_frame.vop_flags = vop_presets[ARG_QUALITY]; if (ARG_VOPDEBUG) { @@ -1011,6 +1091,9 @@ /* Set up motion estimation flags */ xvid_enc_frame.motion = motion_presets[ARG_QUALITY]; + if (ARG_QUARTERPEL) + xvid_enc_frame.motion |= (XVID_ME_QUARTERPELREFINE16 | XVID_ME_QUARTERPELREFINE8); + /* We don't use special matrices */ xvid_enc_frame.quant_intra_matrix = NULL; xvid_enc_frame.quant_inter_matrix = NULL;