⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gdith.c

📁 MPEG2 PLAYER in linux
💻 C
📖 第 1 页 / 共 3 页
字号:
  MakeWindow(name,xinfo);  display=xinfo->display;  xgcv.background = BlackPixel(display, DefaultScreen(display));  xgcv.foreground = WhitePixel(display, DefaultScreen(display));  xinfo->gc = XCreateGC(display, xinfo->window,			GCForeground | GCBackground,			&xgcv);  xinfo->ximage = NULL;}#endif/* *-------------------------------------------------------------- * * InitColorDisplay -- * *	Initialized display for full color output. * * Results: *      None. * * Side effects: *      None. * *-------------------------------------------------------------- */voidInitColorDisplay(name, xinfo)char *name;XInfo *xinfo;{  XWindowAttributes winattr;#ifndef DISABLE_DITHER  if ((xinfo->ditherType == NO_DITHER) || (xinfo->ditherType == PPM_DITHER))     return;#endif  if ((noDisplayFlag) || (xinfo==NULL)) return;  MakeWindow(name,xinfo);  if (xinfo->gc==0) {    xinfo->gc = XCreateGC(xinfo->display, xinfo->window, 0, 0);  }  xinfo->ximage = NULL;  XGetWindowAttributes(xinfo->display, xinfo->window, &winattr);  /*   * Misuse of wpixel    */  wpixel[0] = winattr.visual->red_mask;  wpixel[1] = winattr.visual->green_mask;  wpixel[2] = winattr.visual->blue_mask;}/* *-------------------------------------------------------------- * * ExecuteDisplay -- * *	Actually displays display plane in previously created window. * * Results: *	None. * * Side effects: *	None. * *-------------------------------------------------------------- */void#ifndef NOCONTROLSExecuteDisplay(vid_stream,frame_increment,xinfo)     VidStream *vid_stream;     int frame_increment;     XInfo *xinfo;#elseExecuteDisplay(vid_stream, xinfo)     VidStream *vid_stream;     XInfo *xinfo;#endif{  char dummy;  Visual *FindFullColorVisual();  Visual *fc_visual;  int depth, result;  static int rate_deal = -1;  static int one_frame_time;  static struct timeval tftarget, tfnow;  register int usec, sec;#ifndef NOCONTROLS  XEvent xev;#endif  Display *display;    if (xinfo!=NULL) display=xinfo->display;#ifndef NOCONTROLS  vid_stream->totNumFrames+=frame_increment;#else  vid_stream->totNumFrames++;#endif  if (partialFlag) {    if ((endFrame != -1) && (vid_stream->totNumFrames > endFrame)) {#ifdef ANALYSIS      PrintAllStats(vid_stream);#endif      PrintTimeInfo(vid_stream);      vid_stream->film_has_ended=TRUE;#ifndef NOCONTROLS      if ((frame_increment != 0) && (ControlShow != CTRLBAR_NONE))        UpdateFrameTotal(xinfo->display);      return;#else      if (loopFlag) {              clear_data_stream(vid_stream);      } else DestroyVidStream(vid_stream, xinfo);      return;#endif    }    if (vid_stream->totNumFrames < startFrame) {      return;    }  }  /* Do frame rate control */  switch (rate_deal) {  case 0:    break;  default:    gettimeofday(&tfnow, (struct timezone *)NULL);    usec = tftarget.tv_usec - tfnow.tv_usec;    sec  = tftarget.tv_sec - tfnow.tv_sec;    if (usec < 0) {      usec += 1000000;      sec--;    }        /* If we're not behind, wait a bit */    if ((sec >= 0)  &&  usec > 0) {      tfnow.tv_sec = sec;      tfnow.tv_usec = usec;      select(0, NULL, NULL, NULL ,&tfnow);       gettimeofday(&tfnow, (struct timezone *)NULL);    }    /* Setup target for next frame */    tftarget.tv_usec = tfnow.tv_usec + one_frame_time;    if (tftarget.tv_usec >= 1000000) {      tftarget.tv_usec -= 1000000;      tftarget.tv_sec = tfnow.tv_sec + 1;    } else tftarget.tv_sec = tfnow.tv_sec;    break;  case -1:    switch (framerate) {    case -1: /* Go with stream Value */      rate_deal = VidRateNum[vid_stream->picture_rate];      gettimeofday(&tftarget, (struct timezone *)NULL);      one_frame_time = 1000000 / rate_deal;      break;    case 0: /* as fast as possible */      rate_deal = 0;      break;    default:      rate_deal = framerate;      gettimeofday(&tftarget, (struct timezone *)NULL);      one_frame_time = 1000000 / rate_deal;      break;    }    break;  }#ifndef NOCONTROLS   if (frame_increment > 0) {    TotalFrameCount++;    if ((endFrame != -1) && (vid_stream->totNumFrames >= endFrame)) {      vid_stream->film_has_ended=TRUE;    }    if (!quietFlag && ControlShow == CTRLBAR_NONE)      fprintf(stderr, "%d\r", vid_stream->totNumFrames);  }#else#ifndef NOFRAMECOUNT  if (!quietFlag) {    fprintf (stderr, "%d\r", vid_stream->totNumFrames);  }#endif#endif#ifndef DISABLE_DITHER  if (vid_stream->ditherType == NO_DITHER) return;  if (vid_stream->ditherType == PPM_DITHER) {    ExecutePPM(vid_stream);    return;  }#endif  if (xinfo==NULL) return;  if (!noDisplayFlag) {  if (xinfo->ximage == NULL) {    int pixels_per_mb = 16;#ifndef DISABLE_DITHER    if(IS_2x2_DITHER(xinfo->ditherType)) pixels_per_mb = 32;        if ((xinfo->ditherType == FULL_COLOR_DITHER) ||	(xinfo->ditherType == FULL_COLOR2_DITHER)) {#endif      int w, h;            w = vid_stream->mb_width  * pixels_per_mb;      h = vid_stream->mb_height * pixels_per_mb;            fc_visual = FindFullColorVisual(display, &depth);      xinfo->ximage = XCreateImage (display,			     fc_visual, depth, ZPixmap,			     0, &dummy, w, h, 32, 0);      #ifndef DISABLE_DITHER    } else if (xinfo->ditherType == MONO_DITHER	    || xinfo->ditherType == MONO_THRESHOLD) {      xinfo->ximage = XCreateImage (display,			     None, xinfo->depth, XYBitmap, 0, &dummy,			     vid_stream->mb_width * pixels_per_mb,			     vid_stream->mb_height * pixels_per_mb, 8, 0);      xinfo->ximage->byte_order = MSBFirst;      xinfo->ximage->bitmap_bit_order = MSBFirst;    } else {      xinfo->ximage = XCreateImage(display,		       None, xinfo->depth, ZPixmap, 0, &dummy,			    vid_stream->mb_width * pixels_per_mb,			    vid_stream->mb_height * pixels_per_mb, 8, 0);    }#endif  }/*  * Always work in native bit and byte order. This tells Xlib to reverse * bit and byte order if necessary when crossing a network. Frankly, this * part of XImages is somewhat underdocumented, so this may not be exactly * correct. */ #ifdef LITTLE_ENDIAN_ARCHITECTURE    xinfo->ximage->byte_order = LSBFirst;    xinfo->ximage->bitmap_bit_order = LSBFirst;#else    xinfo->ximage->byte_order = MSBFirst;    xinfo->ximage->bitmap_bit_order = MSBFirst;#endif  #ifdef SH_MEM    if (shmemFlag) {           XShmPutImage(display,			xinfo->window,			xinfo->gc, vid_stream->current->ximage,                         0, 0, 0, 0,                        vid_stream->current->ximage->width,                         vid_stream->current->ximage->height, True);           XFlush(display);      #ifndef NOCONTROLS      /* Wait for it _without_ removing other events from queue */      XIfEvent(display, &xev, IfEventType, (char *) (&CompletionType));#else      while(1) {        XEvent xev;	        XNextEvent(display, &xev);        if (xev.type == CompletionType) {          break;        }      }#endif    }    else #endif            {        xinfo->ximage->data = (char *) vid_stream->current->display; 	        result=XPutImage(display, xinfo->window, xinfo->gc, xinfo->ximage,		  0, 0, 0, 0,		  xinfo->ximage->width,		  xinfo->ximage->height);      }  }#ifndef NOCONTROLS      if ((frame_increment != 0) && (ControlShow != CTRLBAR_NONE)) {        UpdateFrameTotal(xinfo->display);      }#endif  if (requireKeypressFlag) {    char foo;    printf("Press return (%d) ", vid_stream->totNumFrames);        while ((foo = getchar()) != '\n')      ;  }}#ifndef DISABLE_DITHERextern char *strrchr();#define PPM_BITS 8/* *-------------------------------------------------------------- * * ExecutePPM -- * *	Write out a display plane as a PPM file. * * Results: *	None. * * Side effects: *	None. * *-------------------------------------------------------------- */voidExecutePPM(vid_stream)     VidStream *vid_stream;{  static int munged = 0;  static char mungedInputName[300];  char fileName[300], cmd[400];  FILE *file;  int n;  unsigned int *p;  unsigned int r, g, b;  if (!munged) {    char *cp;    cp = strrchr(vid_stream->filename, '/');    if (cp != NULL)      ++cp;    else      cp = vid_stream->filename;    strcpy(mungedInputName, cp);    cp = strrchr(mungedInputName, '.');    if (cp != NULL)	*cp = '\0';    munged = 1;  }  sprintf(fileName, "%s_%05d.ppm", mungedInputName, vid_stream->totNumFrames);  file = fopen(fileName, "w");  if (vid_stream->ppm_width != -1 && vid_stream->ppm_height != -1) {    if ((vid_stream->ppm_modulus != -1) &&	((vid_stream->totNumFrames-1) % vid_stream->ppm_modulus != 0)) {      return;    } else {      extern FILE *popen(const char *, const char *);            sprintf(cmd, "pnmscale -xysize %d %d > %s", 	      vid_stream->ppm_width, vid_stream->ppm_height, fileName);      file = popen(cmd, "w");    }  } else {    file = fopen(fileName, "w");  }  if (file == NULL) {    perror(fileName);    exit(1);  }  fprintf(file, "P6\n");  fprintf(file, "%d %d\n", vid_stream->h_size, vid_stream->v_size);  fprintf(file, "255\n");  p = (unsigned int *) vid_stream->current->display;  n = vid_stream->h_size * vid_stream->v_size;  while (n > 0) {    r = *p & 0xff;    g = (*p >> PPM_BITS) & 0xff;    b = (*p >> (2*PPM_BITS)) & 0xff;    putc(r, file);    putc(g, file);    putc(b, file);    ++p;    --n;  }  if (vid_stream->ppm_width != -1 && vid_stream->ppm_height != -1) {    pclose(file);  } else {    fclose(file);  }}#endif#ifdef NO_GETTIMEOFDAY/* raw approximation */int gettimeofday (struct timeval * retval, void * unused){	timeb_t tm;	ftime (&tm);	retval->tv_sec=  tm.time;	retval->tv_usec= tm.millitm*1000;	return 0;}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -