handle->red_shift   = xxlib_get_shift_from_mask(handle, handle->x_visual_info->red_mask); handle->red_prec    = xxlib_get_prec_from_mask(handle, handle->x_visual_info->red_mask); handle->green_shift = xxlib_get_shift_from_mask(handle, handle->x_visual_info->green_mask); handle->green_prec  = xxlib_get_prec_from_mask(handle, handle->x_visual_info->green_mask); handle->blue_shift  = xxlib_get_shift_from_mask(handle, handle->x_visual_info->blue_mask); handle->blue_prec   = xxlib_get_prec_from_mask(handle, handle->x_visual_info->blue_mask);
handle->red_shift   = xxlib_get_shift_from_mask(handle->x_visual_info->red_mask); handle->red_prec    = xxlib_get_prec_from_mask(handle->x_visual_info->red_mask); handle->green_shift = xxlib_get_shift_from_mask(handle->x_visual_info->green_mask); handle->green_prec  = xxlib_get_prec_from_mask(handle->x_visual_info->green_mask); handle->blue_shift  = xxlib_get_shift_from_mask(handle->x_visual_info->blue_mask); handle->blue_prec   = xxlib_get_prec_from_mask(handle->x_visual_info->blue_mask);
xxlib_rgb_choose_visual_for_xprint (XlibRgbHandle *handle, int aDepth){  XVisualInfo *visuals;  XVisualInfo *visual;  XVisualInfo *best_visual;  XVisualInfo *final_visual;  XVisualInfo template;  int num_visuals;  uint32 score;  int cur_visual = 1;  int i;  XWindowAttributes win_att;  Status ret_stat;  Visual      *root_visual;  ret_stat = XGetWindowAttributes(handle->display,                                   XRootWindow(handle->display, handle->screen_num),                                  &win_att);  root_visual = win_att.visual;  template.screen = handle->screen_num;  template.depth  = aDepth;  visuals = XGetVisualInfo(handle->display,                            VisualScreenMask | ((aDepth!=-1)?(VisualDepthMask):(0)),                           &template, &num_visuals);   /* depth not found ? try again - without it... */  if (!visuals && aDepth!=-1)  {    xxlib_rgb_choose_visual_for_xprint(handle, -1);    return;  }    best_visual = visuals;  if (best_visual->visual != root_visual) {     for (i = cur_visual; i < num_visuals; i++) {        visual = &visuals[i];        if (visual->visual == root_visual) {           best_visual = visual;           break;        }      }   }  /* make a copy of the visual so that we can free     the allocated visual list above. */  final_visual = malloc(sizeof(XVisualInfo));  memcpy(final_visual, best_visual, sizeof(XVisualInfo));  handle->x_visual_info = final_visual;  XFree(visuals);  /* set up the shift and the precision for the red, green and blue.     this only applies to cool visuals like true color and direct color. */  if (handle->x_visual_info->class == TrueColor ||      handle->x_visual_info->class == DirectColor) {    handle->red_shift   = xxlib_get_shift_from_mask(handle, handle->x_visual_info->red_mask);    handle->red_prec    = xxlib_get_prec_from_mask(handle, handle->x_visual_info->red_mask);    handle->green_shift = xxlib_get_shift_from_mask(handle, handle->x_visual_info->green_mask);    handle->green_prec  = xxlib_get_prec_from_mask(handle, handle->x_visual_info->green_mask);    handle->blue_shift  = xxlib_get_shift_from_mask(handle, handle->x_visual_info->blue_mask);    handle->blue_prec   = xxlib_get_prec_from_mask(handle, handle->x_visual_info->blue_mask);  }}