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

📄 clr.c

📁 linux下建立JAVA虚拟机的源码KAFFE
💻 C
📖 第 1 页 / 共 2 页
字号:
  int      nRed, nGreen, nBlue;  int      iRed, iGreen, iBlue;  int      n;  Rgb2True *map = 0;  if ( (v->blue_mask == 0xff) && (v->green_mask == 0xff00) && (v->red_mask == 0xff0000) ){	/*	 * This is our favourite case - a direct 8-8-8 native rgb. It could be handled as	 * a 0,0 TrueColor conversion, but (esp. for image manipulations) we can save a lot	 * of computation by a special TrueColor mode	 */	DBG( AWT_CLR, printf("AWT color mode: CM_TRUE_888\n"));	X->colorMode = CM_TRUE_888;  }  else {	/*	 * There is either a rearrangement or a non-8 bit color component involved,	 * get start index and length of each color component. Note that the Rgb2True	 * struct is used to compute pixelvalues from Java rgbs, i.e. the mask and shift	 * values are relative to the Java 8-8-8 RGB.	 */	map = (Rgb2True*) AWT_MALLOC( sizeof( Rgb2True));	for ( iBlue=0, m=v->blue_mask; (m & 1) == 0; iBlue++, m >>= 1);	for ( nBlue=0; m; nBlue++, m >>= 1 );	for ( iGreen=0, m=v->green_mask; (m & 1) == 0; iGreen++, m >>= 1);	for ( nGreen=0; m; nGreen++, m >>= 1 );	for ( iRed=0, m=v->red_mask; (m & 1) == 0; iRed++, m >>= 1);	for ( nRed=0; m; nRed++, m >>= 1 );	map->blueShift = 8 - (iBlue + nBlue);	if ( nBlue < 8 ){  /* color reduction */	  n = 8 - nBlue;	  map->blueMask = (0xff >> n) << n;	}	else {             /* color expansion */	  map->blueMask = 0xff;	}	map->greenShift = 16 - (iGreen + nGreen);	if ( nGreen < 8 ){ /* color reduction */	  n = 8 + (8 - nGreen);	  map->greenMask = (0xff00 >> n) << n;	}	else {             /* color expansion */	  map->greenMask = 0xff00;	}	map->redShift = 24 - (iRed + nRed);	if ( nRed < 8 ){  /* color reduction */	  n = 16 + (8 - nRed);	  map->redMask = (0xff0000 >> n) << n;	}	else {            /* color expansion */	  map->redMask = 0xff0000;	}	X->colorMode = CM_TRUE;	DBG( AWT_CLR, printf("AWT color mode: CM_TRUE\n"));	DBG( AWT_CLR, printf("    red:   %8x, %d\n", map->redMask, map->redShift));	DBG( AWT_CLR, printf("    green: %8x, %d\n", map->greenMask, map->greenShift));	DBG( AWT_CLR, printf("    blue:  %8x, %d\n", map->blueMask, map->blueShift));  }  return map;}/******************************************************************************** * DirectColor (RGB) visual: each pixel value is composed of three, non-overlapping * colormap indices. * Again, our policy is to go with the default colormap, and not to swap it (so that * we don't disturb other desktop citizens). * This rather simple implementation does not allocate cells for mismatches yet * * We could save some space in case we have a DirectColor visual with a depth < 24, * but that would complicate pixelValue() and probably is rather unusual, anyway * (since DirectVisual is a expensive beast to be found on high-end HW) * * However, we do make some assumptions here which might be a bit too optimistic * (black being at index 0, free cells being concentracted at the end of the cmap, * with a 0-value) */static void fillUpPartMap ( unsigned char* pix, unsigned char* val ){  int i, j, k, i2;  for ( i=1, k=0; i < N_DIRECT; i++ ) {	if ( pix[i] == 0 ) {	  for ( j=i+1; (j < N_DIRECT) && (pix[j] == 0); j++ );	  if ( j == N_DIRECT ) { /* last one, fill up rest */		for ( ; i < j; i++ ) {		  pix[i] = pix[k];		  val[ pix[i] ] = k;		}			  }	  else {		i2 = (i + j) / 2;		for ( ; i < i2; i++ ){		  pix[i] = pix[k];		  val[ pix[i] ] = k;		}		for ( ; i < j; i++ ) {		  pix[i] = pix[j];		  val[ pix[i] ] = j;		  k = j;		}	  }	}	else {	  k = i;	}  }}static void setPartMapFromDMap ( Toolkit *X, Colormap dcm,						  int component, int nIdx, int idxShift,						  unsigned char* pix, unsigned char* val ){  XColor          xclr;  int             i, idx;  unsigned short  *v;  if ( component == 0 )      /* red */	v = &xclr.red;  else if ( component == 1 ) /* green */	v = &xclr.green;  else                       /* blue */	v = &xclr.blue;  for ( i=0; i < nIdx; i++ ) {	xclr.pixel = i << idxShift;	XQueryColor( X->dsp, dcm, &xclr);	if ( i && !*v )	  break;       /* skip free cells (assuming 0: black) */	idx = ROUND_SHORT2CHAR( *v);	pix[idx] = i;	val[i] = idx;  }}static Rgb2Direct*initRgb2Direct ( JNIEnv* env UNUSED, jclass clazz UNUSED, Toolkit* tk ){  Visual      *v = DefaultVisualOfScreen( DefaultScreenOfDisplay( tk->dsp));  Rgb2Direct  *map = (Rgb2Direct*) AWT_MALLOC( sizeof( Rgb2Direct));  Colormap    dcm = DefaultColormapOfScreen( DefaultScreenOfDisplay( tk->dsp));  int         iBlue, nBlue, iGreen, nGreen, iRed, nRed;  int         i, m;  for ( i=0; i<N_DIRECT; i++ ) {	map->bluePix[i] = map->greenPix[i] = map->redPix[i] = 0;  }  for ( iBlue=0, m=v->blue_mask; (m & 1) == 0; iBlue++, m >>= 1);  for ( nBlue=0; m; nBlue++, m >>= 1 );  for ( iGreen=0, m=v->green_mask; (m & 1) == 0; iGreen++, m >>= 1);  for ( nGreen=0; m; nGreen++, m >>= 1 );  for ( iRed=0, m=v->red_mask; (m & 1) == 0; iRed++, m >>= 1);  for ( nRed=0; m; nRed++, m >>= 1 );  /* we simply get the sizes of component colormaps from the visual masks */  map->nBlue  = v->blue_mask  >> iBlue;  map->nGreen = v->green_mask >> iGreen;  map->nRed   = v->red_mask   >> iRed;  /* the shifts are to convert component indices into a compound pixelvalue */  map->blueShift  = iBlue;  map->greenShift = iGreen;  map->redShift   = iRed;  /*   * phase 1: start to populate our component maps (R/G/B -> index) from dcm   */  setPartMapFromDMap( tk, dcm, 0, map->nRed, map->redShift, map->redPix, map->red);  setPartMapFromDMap( tk, dcm, 1, map->nGreen, map->greenShift, map->greenPix, map->green);  setPartMapFromDMap( tk, dcm, 2, map->nBlue, map->blueShift, map->bluePix, map->blue);  /*   * phase 2: fill up missing entries   * (based on the somewhat optimistic assumption that free cells are at the upper end)   */  fillUpPartMap( map->bluePix, map->blue);  fillUpPartMap( map->greenPix, map->green);  fillUpPartMap( map->redPix, map->red);#ifdef NEVER  for ( i = 0; i<N_DIRECT; i++ ) {	printf( "%2x :   %3d,%2x  %3d,%2x  %3d,%2x\n", i,			map->redPix[i], map->red[ map->redPix[i] ],			map->greenPix[i], map->green[ map->greenPix[i] ],			map->bluePix[i], map->blue[ map->bluePix[i] ]);  }#endif  tk->colorMode = CM_DIRECT;  return map;}/******************************************************************************** * common funcs */voidinitColorMapping ( JNIEnv* env, jclass clazz,  Toolkit* tk ){  Visual *v = DefaultVisualOfScreen( DefaultScreenOfDisplay( tk->dsp));  DBG( AWT_CLR, printf("X visual:\n"));  DBG( AWT_CLR, printf("  id:          %ld\n", v->visualid));  DBG( AWT_CLR, printf("  class:       %d\n", v->class));  DBG( AWT_CLR, printf("  red_mask     %lx\n", v->red_mask));  DBG( AWT_CLR, printf("  green_mask   %lx\n", v->green_mask));  DBG( AWT_CLR, printf("  blue_mask    %lx\n", v->blue_mask));  DBG( AWT_CLR, printf("  bits_per_rgb %x\n", v->bits_per_rgb));  DBG( AWT_CLR, printf("  map_entries  %d\n", v->map_entries));  /* check for directly supported color modes / visuals */  switch ( v->class ) {  case DirectColor:	X->dclr = initRgb2Direct( env, clazz, tk);	break;  case TrueColor:	X->tclr = initRgb2True( env, clazz, tk);	break;  case PseudoColor:  	X->pclr = initRgb2Pseudo( env, clazz, tk); 	break;  default:	X->colorMode = CM_GENERIC;  }  DBG( AWT_CLR, printf("colorMode: %d\n", tk->colorMode));}/******************************************************************************** * exported functions */jintJava_java_awt_Toolkit_clrGetPixelValue ( JNIEnv* env, jclass clazz, jint rgb ){  jint pix;  /*   * We do this deferred to avoid class init problems with Defaults<->Color   * (the notorious DefaultsRGB workaround)   */  if ( !X->colorMode )	initColorMapping( env, clazz, X);  pix = pixelValue( X, rgb);  DBG( AWT_CLR, printf("clrGetPixelValue: %8x -> %x (%d)\n", rgb, pix, pix));  return pix;}voidJava_java_awt_Toolkit_clrSetSystemColors ( JNIEnv* env UNUSED, jclass clazz UNUSED, jintArray sysClrs UNUSED ){#ifdef NEVER /* maybe this could be initialized via X resources */  jboolean isCopy;  jint *rgbs = (*env)->GetIntArrayElements( env, sysClrs, &isCopy);  int  len = (*env)->GetArrayLength( env, sysClrs);  rgbs[ 0] = 0;  /* desktop */  rgbs[ 1] = 0;  /* active_caption */  rgbs[ 2] = 0;  /* active_caption_text */  rgbs[ 3] = 0;  /* active_caption_border */  rgbs[ 4] = 0;  /* inactive_caption */  rgbs[ 5] = 0;  /* inactive_caption_text */  rgbs[ 6] = 0;  /* inactive_caption_border */  rgbs[ 7] = 0;  /* window */  rgbs[ 8] = 0;  /* window_border */  rgbs[ 9] = 0;  /* window_text */  rgbs[10] = 0;  /* menu */  rgbs[11] = 0;  /* menu_text */  rgbs[12] = 0;  /* text */  rgbs[13] = 0;  /* text_text */  rgbs[14] = 0;  /* text_highlight */  rgbs[15] = 0;  /* text_highlight_text */  rgbs[16] = 0;  /* text_inactive_text */  rgbs[17] = 0;  /* control */  rgbs[18] = 0;  /* control_text */  rgbs[19] = 0;  /* control_highlight */  rgbs[20] = 0;  /* control_lt_highlight */  rgbs[21] = 0;  /* control_shadow */  rgbs[22] = 0;  /* control_dk_shadow */  rgbs[23] = 0;  /* scrollbar */  rgbs[24] = 0;  /* info */  rgbs[25] = 0;  /* info_text */  (*env)->ReleaseIntArrayElements( env, sysClrs, rgbs, 0);#endif}/* * we need to implement brighter / darker in the native layer because the usual * arithmetic Rgb brightening/darkening isn't really useful if it comes to * limited PseudoColor visuals (e.g. a primitive 16 color VGA wouldn't produce any * usable results). Even 256 colormaps suffer from that */jlongJava_java_awt_Toolkit_clrBright ( JNIEnv* env UNUSED, jclass clazz UNUSED, jint rgb ){  unsigned int r, g, b;  jint     modRgb, modPix;  r = JRED( rgb);  g = JGREEN( rgb);  b = JBLUE( rgb);  r = (r * 4) / 3;  g = (g * 4) / 3;  b = (b * 4) / 3;	  if ( r > 0xff ) r = 0xff;  if ( g > 0xff ) g = 0xff;  if ( b > 0xff ) b = 0xff;  modRgb = JRGB( r, g, b);  modPix = pixelValue( X, modRgb);  return (((jlong)modPix << 32) | modRgb);}jlongJava_java_awt_Toolkit_clrDark ( JNIEnv* env UNUSED, jclass clazz UNUSED, jint rgb ){  unsigned int r, g, b;  jint     modRgb, modPix;  r = JRED( rgb);  g = JGREEN( rgb);  b = JBLUE( rgb);  r = (r * 2) / 3;  g = (g * 2) / 3;  b = (b * 2) / 3;	  modRgb = JRGB( r, g, b);  modPix = pixelValue( X, modRgb);  return (((jlong)modPix << 32) | modRgb);}jobjectJava_java_awt_Toolkit_clrGetColorModel ( JNIEnv* env, jclass clazz ){  jobject    cm = 0;  jclass     cmClazz;  jmethodID  cmCtorId;  Visual     *v = DefaultVisualOfScreen( DefaultScreenOfDisplay( X->dsp));  if ( !X->colorMode )	initColorMapping( env, clazz, X);  switch ( v->class ) {  case DirectColor:	break;  case TrueColor:	cmClazz = (*env)->FindClass( env, "java/awt/image/DirectColorModel");	cmCtorId = (*env)->GetMethodID( env, cmClazz, "<init>", "(IIIII)V");	cm = (*env)->NewObject( env, cmClazz, cmCtorId,							v->bits_per_rgb, v->red_mask, v->green_mask, v->blue_mask, 0);	break;  case PseudoColor:  	cmClazz = (*env)->FindClass( env, "java/awt/IndexColorModel");	cmCtorId = (*env)->GetMethodID( env, cmClazz, "<init>", "(I[II)V");	/* rgbs = (*env)->NewIntArray( env, 256, 0);	 * cm = (*env)->NewObject( env, cmClazz, cmCtorId, 8, rgbs, 0);	 */	break;  }  return cm;}

⌨️ 快捷键说明

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