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

📄 gdith.c

📁 MPEG2 PLAYER in linux
💻 C
📖 第 1 页 / 共 3 页
字号:
	if (xinfo->ditherType != GRAY_DITHER &&	    xinfo->ditherType != GRAY2_DITHER &&	    xinfo->ditherType != GRAY256_DITHER &&	    xinfo->ditherType != GRAY2562_DITHER) {	  fprintf(stderr, "specified dither requires 8 bit display\n");	  return 0;	} else if (!XMatchVisualInfo(display, screen, xinfo->depth = 32,			GrayScale, &vinfo) &&	           !XMatchVisualInfo(display, screen, xinfo->depth = 24,			GrayScale, &vinfo) &&	           !XMatchVisualInfo(display, screen, xinfo->depth = 16,			GrayScale, &vinfo) &&	           !XMatchVisualInfo(display, screen, xinfo->depth = 8,			GrayScale, &vinfo) &&	           !XMatchVisualInfo(display, screen, xinfo->depth = 32,			TrueColor, &vinfo) &&	           !XMatchVisualInfo(display, screen, xinfo->depth = 24,			TrueColor, &vinfo) &&	           !XMatchVisualInfo(display, screen, xinfo->depth = 16,			TrueColor, &vinfo)) {	  fprintf(stderr, "- -dither gray requires at least 8 bit display\n");	  exit(-1);	}      }            vis = vinfo.visual;      if (XDefaultDepthOfScreen(XDefaultScreenOfDisplay(display)) != 8) {	attrib_flags |= CWColormap;	attrib.colormap = XCreateColormap(display, DefaultRootWindow(display),					  vis, AllocNone);	xinfo->owncmFlag = TRUE;       }            attrib.background_pixel = bg;      attrib.border_pixel = fg;      attrib.backing_store = NotUseful;      attrib.save_under = False;      attrib.background_pixel = bg;      attrib.border_pixel = bg;      attrib_flags |= CWBackPixel | CWBorderPixel | CWBackingStore | CWSaveUnder;      xinfo->window = XCreateWindow (display,			      DefaultRootWindow (display),			      xinfo->hints.x, xinfo->hints.y,			      xinfo->hints.width, xinfo->hints.height, 4,			      xinfo->depth, InputOutput, vis,			      attrib_flags, &attrib);    }}#endif   XSelectInput(display, xinfo->window, StructureNotifyMask);  /* Tell other applications about this window */  XSetStandardProperties (display, xinfo->window, hello,			  hello, None, NULL, 0, &xinfo->hints);  /* Map window. */    XMapWindow(display, xinfo->window);  /* Wait for map. */  while (TRUE) {    XEvent	xev;        XNextEvent(display, &xev);    if (xev.type == MapNotify && xev.xmap.event == xinfo->window) {      break;    }  }  #ifndef NOCONTROLS  XSelectInput(display, xinfo->window, ExposureMask | ButtonPressMask );#else  XSelectInput(display, xinfo->window, NoEventMask);#endif  return TRUE;}  /* *-------------------------------------------------------------- * * InitDisplay -- * *	Initialized display, sets up colormap, etc. * * Results: *      None. * * Side effects: *      None. * *-------------------------------------------------------------- */voidInitDisplay(name, xinfo)char *name;XInfo *xinfo;{  int ncolors = LUM_RANGE*CB_RANGE*CR_RANGE;  XColor xcolor;  int i, lum_num, cr_num, cb_num;  unsigned char r, g, b;  Colormap dcmap;  Display *display;  #ifndef DISABLE_DITHER  if ((xinfo->ditherType == NO_DITHER) || (xinfo->ditherType == PPM_DITHER))     return;#endif  if ((noDisplayFlag) || (xinfo==NULL)) return;  if (!MakeWindow(name, xinfo)) {    /* Could not do that dither.  Try again if can */#ifndef DISABLE_DITHER    switch (xinfo->ditherType) {    case HYBRID_DITHER:    case HYBRID2_DITHER:    case FS4_DITHER:    case FS2_DITHER:    case FS2FAST_DITHER:    case Twox2_DITHER:    case ORDERED_DITHER:    case ORDERED2_DITHER:    case MBORDERED_DITHER:      fprintf(stderr, "trying -dither color\n");      xinfo->ditherType = FULL_COLOR_DITHER;      InitColorDisplay(name,xinfo);      InitColorDither(xinfo->depth == 32);      return;    case GRAY_DITHER:    case GRAY2_DITHER:    case GRAY256_DITHER:    case GRAY2562_DITHER:    case FULL_COLOR_DITHER:    case FULL_COLOR2_DITHER:    case MONO_DITHER:    case MONO_THRESHOLD:    default:      /* cant do anything */      exit(-1);  }#else    exit(-1);#endif  }  if (xinfo != NULL) {    display = xinfo->display;    xinfo->gc = XCreateGC(display, xinfo->window, 0, 0);        dcmap = xinfo->cmap = XDefaultColormap(display, DefaultScreen(display));        xcolor.flags = DoRed | DoGreen | DoBlue;        if (xinfo->owncmFlag) goto create_map;  }    retry_alloc_colors:  for (i=0; i<ncolors; i++) {    lum_num = (i / (CR_RANGE*CB_RANGE))%LUM_RANGE;    cr_num = (i / CB_RANGE)%CR_RANGE;    cb_num = i % CB_RANGE;    ConvertColor(lum_num, cr_num, cb_num, &r, &g, &b);    xcolor.red = r * 256;    xcolor.green = g * 256;    xcolor.blue = b * 256;    if ((xinfo != NULL) && (XAllocColor(display, xinfo->cmap, &xcolor) == 0 	&& xinfo->cmap == dcmap)) {      int j;      unsigned long tmp_pixel;      XWindowAttributes xwa;      if (!quietFlag) {        fprintf(stderr, "Using private colormap.\n");      }      /* Free colors. */      for (j = 0; j < i; j ++) {        tmp_pixel = wpixel[j];        XFreeColors(display, xinfo->cmap, &tmp_pixel, 1, 0);      }      create_map:      XGetWindowAttributes(display, xinfo->window, &xwa);      xinfo->cmap = XCreateColormap(display, xinfo->window,				    xwa.visual, AllocNone);      XSetWindowColormap(display, xinfo->window, xinfo->cmap);      goto retry_alloc_colors;    }    pixel[i] = xcolor.pixel;    wpixel[i] = xcolor.pixel;  }  xinfo->ximage = NULL;}#ifndef DISABLE_DITHER/* *-------------------------------------------------------------- * * InitGrayDisplay -- * *	Initialized display for gray scale dither. * * Results: *      None. * * Side effects: *      None. * *-------------------------------------------------------------- */void InitGrayDisplay(name,xinfo)char *name;XInfo *xinfo;{  int ncolors = 128;  XColor xcolor;  int i;  Colormap dcmap;  unsigned long tmp_pixels[256];  Window window;  Display *display;  if (noDisplayFlag) return;  MakeWindow(name,xinfo);  display=xinfo->display;  window=xinfo->window;  xinfo->gc = XCreateGC(display, window, 0, 0);  dcmap = xinfo->cmap = XDefaultColormap(display, DefaultScreen(display));  xcolor.flags = DoRed | DoGreen | DoBlue;  if (xinfo->owncmFlag) goto create_map;  retry_alloc_grays:  for (i=0; i<ncolors; i++) {    xcolor.red = xcolor.green = xcolor.blue = GAMMA_CORRECTION(i*2) * 256;    if(XAllocColor(display, xinfo->cmap, &xcolor) == 0 		   && xinfo->cmap == dcmap) {      int j;      XWindowAttributes xwa;      if (!quietFlag) {        fprintf(stderr, "Using private colormap.\n");      }      /* Free colors. */      for(j = 0; j < i; j ++) {        unsigned long tmp_pixel;        tmp_pixel = tmp_pixels[j*2];        XFreeColors(display, xinfo->cmap, &tmp_pixel, 1, 0);      }      create_map:      XGetWindowAttributes(display, window, &xwa);      xinfo->cmap = XCreateColormap(display, window, xwa.visual, AllocNone);      XSetWindowColormap(display, window, xinfo->cmap);      goto retry_alloc_grays;    }    tmp_pixels[i*2] = pixel[i*2] = xcolor.pixel;    tmp_pixels[(i*2)+1] = pixel[(i*2)+1] = xcolor.pixel;    wpixel[(i*2)] = xcolor.pixel;    wpixel[(i*2)+1] = xcolor.pixel;    if(xinfo->depth == 8) {      wpixel[i*2] |= wpixel[i*2] << 8;      wpixel[i*2+1] |= wpixel[i*2+1] << 8;    }    if(xinfo->depth == 8 || xinfo->depth == 16) {      wpixel[i*2] |= wpixel[i*2] << 16;      wpixel[i*2+1] |= wpixel[i*2+1] << 16;    }#ifdef SIXTYFOUR_BIT    if(xinfo->depth == 8 || xinfo->depth == 16 || xinfo->depth == 24 ||       xinfo->depth == 32) {      wpixel[i*2] |= wpixel[i*2] << 32;      wpixel[i*2+1] |= wpixel[i*2+1] << 32;    }#endif  }  xinfo->ximage = NULL;}/* *-------------------------------------------------------------- * * InitGray256Display -- * *	Initialized display for gray scale dither with 256 levels * * Results: *      None. * * Side effects: *      None. * *-------------------------------------------------------------- */void InitGray256Display(name, xinfo)char *name;XInfo *xinfo;{  int ncolors = 256;  XColor xcolor;  int i;  Colormap dcmap;  int result;  XWindowAttributes xwa;  unsigned long tmp_pixels[256];  Display *display;  if (noDisplayFlag) return;  MakeWindow(name,xinfo);  display=xinfo->display;  xinfo->gc = XCreateGC(display, xinfo->window, 0, 0);  dcmap = xinfo->cmap = XDefaultColormap(display, DefaultScreen(display));  xcolor.flags = DoRed | DoGreen | DoBlue;  if (xinfo->owncmFlag) {    XGetWindowAttributes(display, xinfo->window, &xwa);    xinfo->cmap=XCreateColormap(display, xinfo->window, xwa.visual, AllocNone);    XSetWindowColormap(display, xinfo->window, xinfo->cmap);  }  retry_alloc_grays:  for (i = 0;  i < ncolors;  i++) {    xcolor.red = xcolor.green = xcolor.blue = GAMMA_CORRECTION(i) * 256;    if ((result = XAllocColor(display, xinfo->cmap, &xcolor)) == 0	 && xinfo->cmap == dcmap) {      int j;      unsigned long tmp_pixel;      if (!quietFlag) {        fprintf(stderr, "Using private colormap.\n");      }      /* Free colors. */      for (j = 0; j < i; j ++) {        tmp_pixel = tmp_pixels[j];        XFreeColors(display, xinfo->cmap, &tmp_pixel, 1, 0);      }      XGetWindowAttributes(display, xinfo->window, &xwa);      xinfo->cmap = XCreateColormap(display, xinfo->window, xwa.visual,				    AllocNone);      XSetWindowColormap(display, xinfo->window, xinfo->cmap);      goto retry_alloc_grays;    }    tmp_pixels[i] = pixel[i] = xcolor.pixel;    wpixel[i] = xcolor.pixel;#ifndef DISABLE_DITHER    if(xinfo->depth == 8)#endif      wpixel[i] |= wpixel[i] << 8;#ifndef DISABLE_DITHER    if(xinfo->depth == 8 || xinfo->depth == 16) {#endif      wpixel[i] |= wpixel[i] << 16;#ifndef DISABLE_DITHER    }#endif#ifdef SIXTYFOUR_BIT    if(xinfo->depth == 8 || xinfo->depth == 16 || xinfo->depth == 24        || xinfo->depth == 32) {      wpixel[i] |= wpixel[i] << 32;    }#endif  }  xinfo->ximage = NULL;}/* *-------------------------------------------------------------- * * InitMonoDisplay -- * *	Initialized display for monochrome dither. * * Results: *      None. * * Side effects: *      None. * *-------------------------------------------------------------- */void InitMonoDisplay(name, xinfo)char *name;XInfo *xinfo;{  XGCValues xgcv;  Display *display;  if (noDisplayFlag) return;

⌨️ 快捷键说明

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