📄 mpeg2ply.c
字号:
lpCmdLine; // This will prevent 'unused formal parameter' warnings}//// display initialization///* Note: this was already defined in global.h, so I commented it out -- Chad *//* extern int convmat[][4]; /* defined in display.c */static void init_display(void){ pbmi = (PBITMAPINFO)malloc(sizeof(BITMAPINFOHEADER) + 240 * sizeof(RGBQUAD)); pbmi->bmiHeader.biSize = (LONG)sizeof(BITMAPINFOHEADER); pbmi->bmiHeader.biPlanes = 1; pbmi->bmiHeader.biCompression = 0l; pbmi->bmiHeader.biSizeImage = 0l; pbmi->bmiHeader.biXPelsPerMeter = 0l; pbmi->bmiHeader.biYPelsPerMeter = 0l; pbmi->bmiHeader.biClrUsed = 240; pbmi->bmiHeader.biClrImportant = 240; pbmi->bmiHeader.biBitCount = nDitherType; pbmi->bmiHeader.biWidth = coded_picture_width ; pbmi->bmiHeader.biHeight= coded_picture_height; if ( pbmi->bmiHeader.biBitCount==8 ) { // for 8 BPP, build the color palette LOGPALETTE *plgpl; short *pPalIndex; int crv, cbu, cgu, cgv; int y, u, v; int i; plgpl = (LOGPALETTE*) malloc(sizeof(LOGPALETTE) + 240 * sizeof(PALETTEENTRY)); plgpl->palNumEntries = 240; plgpl->palVersion = 0x300; pPalIndex=(short *)pbmi->bmiColors; /* matrix coefficients */ crv = convmat[matrix_coefficients][0]; cbu = convmat[matrix_coefficients][1]; cgu = convmat[matrix_coefficients][2]; cgv = convmat[matrix_coefficients][3]; for (i=16; i<240; i++) { /* color space conversion */ y = 16*((i>>4)&15) + 8; u = 32*((i>>2)&3) - 48; v = 32*(i&3) - 48; y = 76309 * (y - 16); /* (255/219)*65536 */ plgpl->palPalEntry[i].peRed = clp[(y + crv*v + 32768)>>16]; plgpl->palPalEntry[i].peGreen = clp[(y - cgu*u -cgv*v + 32768)>>16]; plgpl->palPalEntry[i].peBlue = clp[(y + cbu*u + 32786)>>16]; pPalIndex[i]=i; } hpal = CreatePalette(plgpl); free(plgpl); hPalPrev=SelectPalette(hDC,hpal,FALSE); RealizePalette(hDC); }}//// display clean-up//static void exit_display(){ if (pbmi) { free(pbmi); pbmi=NULL; } if (hPalPrev) { SelectPalette(hDC,hPalPrev,FALSE); DeleteObject(hpal); hPalPrev=NULL; }}//// display the image on the MS Windows screen//void display_image(dithered_image)unsigned char *dithered_image;{ /* display dithered image */ SetDIBitsToDevice(hDC,0,0,coded_picture_width,coded_picture_height, 0,0,0,coded_picture_height,dithered_image,pbmi,DIB_PAL_COLORS);}//// decode a file and store and/or display it//int play_movie(void){ int framenum, first; /* open MPEG input file(s) */ if ((base.infile=open(szFileName,O_RDONLY|O_BINARY))<0) { sprintf(errortext,"Input file %s not found\n",szFileName); error(errortext); } /* Look for Systems start code */ sysstream = 0;// if (base.infile != 0) { initbits(); startcode(); switch(showbits(32)) { case SEQ_START_CODE: break; case PACK_START_CODE: sysstream = 1; break; default: error("This not a valid MPEG system or video stream\n"); break; } lseek(base.infile,0l,0); initbits(); } first = 1; do { /* (re)set to begin of file */ ld = &base;// if (base.infile!=0) lseek(base.infile,0l,0); initbits();/* Enhancement currently commented out if (twostreams) { ld = &enhan; lseek(enhan.infile,0l,0); initbits(); ld = &base; } End of commented out section */ framenum = 0; while (getheader()) { if (first) { RECT wr,cr; int d; // size window to film size SetRect(&cr,0,0,horizontal_size,vertical_size); wr=cr; AdjustWindowRect(&wr,GetWindowLong(ghWnd,GWL_STYLE),TRUE); OffsetRect(&wr,-wr.left,-wr.top); SetWindowPos(ghWnd,HWND_TOP,0,0,wr.right,wr.bottom,SWP_NOMOVE); // for QSIF movies the menu will wrap around so we need // to increase the height of the window GetClientRect(ghWnd, &wr); d=cr.bottom-(wr.bottom-wr.top); if (d>0) { GetWindowRect(ghWnd, &wr); SetWindowPos(ghWnd,HWND_TOP,0,0,wr.right-wr.left,wr.bottom-wr.top+d,SWP_NOMOVE); } initdecoder(); if (outtype==T_X11) { init_dither(nDitherType); init_display(); } first = 0; } getpicture(framenum); if (!secondfield) { framenum++; } // give the user a chance to perform something myYield(); if (gusState==STOP) break; } if (framenum!=0) { /* put last frame */ putlast(framenum); } } while (loopflag);// if (base.infile!=0) close(base.infile); if (outtype==T_X11) exit_display(); return 0;}///////////////////////////////////////////////////////////////////////// MPEG related functions//// (portable)//static void initdecoder(){ int i, cc, size; static int blk_cnt_tab[3] = {6,8,12}; /* check scalability mode of enhancement layer */ if (twostreams && enhan.scalable_mode!=SC_SNR && !(base.scalable_mode==SC_DP && base.scalable_mode==SC_DP)) error("unsupported scalability mode\n"); /* clip table */ if (!(clp=(unsigned char *)malloc(1024))) error("malloc failed\n"); clp += 384; for (i=-384; i<640; i++) clp[i] = (i<0) ? 0 : ((i>255) ? 255 : i); /* force MPEG-1 parameters */ if (!base.mpeg2) { prog_seq = 1; prog_frame = 1; pict_struct = FRAME_PICTURE; frame_pred_dct = 1; chroma_format = CHROMA420; matrix_coefficients = 5; } /* round to nearest multiple of coded macroblocks */ mb_width = (horizontal_size+15)/16; mb_height = (base.mpeg2 && !prog_seq) ? 2*((vertical_size+31)/32) : (vertical_size+15)/16; coded_picture_width = 16*mb_width; coded_picture_height = 16*mb_height; chrom_width = (chroma_format==CHROMA444) ? coded_picture_width : coded_picture_width>>1; chrom_height = (chroma_format!=CHROMA420) ? coded_picture_height : coded_picture_height>>1; blk_cnt = blk_cnt_tab[chroma_format-1]; for (cc=0; cc<3; cc++) { if (cc==0) size = coded_picture_width*coded_picture_height; else size = chrom_width*chrom_height; if (!(refframe[cc] = (unsigned char *)malloc(size))) error("malloc failed\n"); if (!(oldrefframe[cc] = (unsigned char *)malloc(size))) error("malloc failed\n"); if (!(auxframe[cc] = (unsigned char *)malloc(size))) error("malloc failed\n"); if (base.scalable_mode==SC_SPAT) { /* this assumes lower layer is 4:2:0 */ if (!(llframe0[cc] = (unsigned char *)malloc((llw*llh)/(cc?4:1)))) error("malloc failed\n"); if (!(llframe1[cc] = (unsigned char *)malloc((llw*llh)/(cc?4:1)))) error("malloc failed\n"); } } if (base.scalable_mode==SC_SPAT) { if (!(lltmp = (short *)malloc(llw*((llh*vn)/vm)*sizeof(short)))) error("malloc failed\n"); } /* IDCT */ init_idct();}void error(text)char *text;{ fprintf(stderr,text); exit(1);}/* compliance warning messages to user, but don't exit() */void warning(text)char *text;{ if (!quiet) { fprintf(stderr,"%s\n",text); }}#ifdef TRACE/* trace output */void printbits(code,bits,len)int code,bits,len;{ int i; for (i=0; i<len; i++) printf("%d",(code>>(bits-1-i))&1);}#endif/* option processing *//*static void options(argcp,argvp)int *argcp;char **argvp[];{ outtype = T_X11; while (*argcp>1 && (*argvp)[1][0]=='-') { while ((*argvp)[1][1]) { switch (toupper((*argvp)[1][1])) { case 'V': verbose = getval(*argvp); break; case 'O': outtype = getval(*argvp); break; case 'L': loopflag = 1; break; case 'S': sflag = 1; break;#ifdef TRACE case 'T': trace = 1; break;#endif case 'Q': quiet = 1; break; default: fprintf(stderr,"undefined option -%c ignored\n",(*argvp)[1][1]); } (*argvp)[1]++; } (*argvp)++; (*argcp)--; } if (sflag) { /* input file for spatial prediction *//* llinputname = (*argvp)[1]; (*argvp)++; (*argcp)--; }#if 0 if (*argcp!=2 && *argcp!=3) { printf("\n%s, %s\n",version,author); printf("Usage: mpeg2play {options} input.m2v {upper.m2v}\n\Options: -vn verbose output (n: level)\n\ -on output format (0: X11 (default), 1: none\n\ -l loop sequence\n\ -q quiet (no error output)\n\ -s infile spatial scalable sequence\n"); exit(0); }#endif}*/static int getval(argv)char *argv[];{ int val; if (sscanf(argv[1]+2,"%d",&val)!=1) return 0; while (isdigit(argv[1][2])) argv[1]++; return val;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -