xxlib_rgb_create_handle_with_depth (Display *display, Screen *screen, int prefDepth)
xxlib_rgb_create_handle_with_depth (const char *name, Display *display, Screen *screen, int prefDepth)
xxlib_rgb_create_handle_with_depth (Display *display, Screen *screen, int prefDepth){  XlibRgbHandle *handle = NULL;  int i;  static const int byte_order[1] = { 1 };  /* check endian sanity */#if G_BYTE_ORDER == G_BIG_ENDIAN  if (((char *)byte_order)[0] == 1) {    fprintf (stderr, "xxlib_rgb_create_handle_with_depth: "             "compiled for big endian, but this is a little endian machine.\n\n");    abort();  }#else  if (((char *)byte_order)[0] != 1) {    fprintf (stderr, "xxlib_rgb_create_handle_with_depth: "             "compiled for little endian, but this is a big endian machine.\n\n");    abort();  }#endif /* G_BYTE_ORDER == G_BIG_ENDIAN */        handle = malloc(sizeof(XlibRgbHandle));        if(!handle)      return NULL;          memset(handle, 0, sizeof(XlibRgbHandle));    handle->display = display;    handle->screen = screen;    handle->screen_num = XScreenNumberOfScreen(screen);    handle->x_visual_info = NULL;    handle->cmap = 0;    handle->default_visualid = XDefaultVisual(display, handle->screen_num);    handle->default_colormap = XDefaultColormap(display, handle->screen_num);    handle->color_pixels = NULL;    handle->gray_pixels = NULL;    handle->reserved_pixels = NULL;    handle->nred_shades = 6;    handle->ngreen_shades = 6;    handle->nblue_shades = 4;    handle->ngray_shades = 24;    handle->nreserved = 0;    handle->bpp = 0;    handle->cmap_alloced = FALSE;    handle->gamma_val = 1.0;    handle->stage_buf = NULL;    handle->own_gc = 0;        handle->red_shift = 0;    handle->red_prec = 0;    handle->green_shift = 0;    handle->green_prec = 0;    handle->blue_shift = 0;    handle->blue_prec = 0;    handle->xlib_rgb_min_colors = 5 * 5 * 5;    handle->horiz_y = IMAGE_HEIGHT;    handle->vert_x  = IMAGE_WIDTH;    handle->tile_x  = IMAGE_WIDTH;    handle->tile_y1 = IMAGE_HEIGHT;    handle->tile_y2 = IMAGE_HEIGHT;    if (prefDepth != -1)      xxlib_rgb_choose_visual_for_xprint (handle, prefDepth);    else      xxlib_rgb_choose_visual (handle);    if ((handle->x_visual_info->class == PseudoColor ||         handle->x_visual_info->class == StaticColor) &&        handle->x_visual_info->depth < 8 &&        handle->x_visual_info->depth >= 3)    {      handle->cmap = handle->default_colormap;      xxlib_rgb_colorcube_222 (handle);    }    else if (handle->x_visual_info->class == PseudoColor)    {      if (handle->xlib_rgb_install_cmap ||          handle->x_visual_info->visualid != handle->default_visualid->visualid)      {        handle->cmap = XCreateColormap(handle->display,                                       XRootWindow(handle->display, handle->screen_num),                                       handle->x_visual_info->visual,                                       AllocNone);        handle->cmap_alloced = TRUE;      }      if (!xxlib_rgb_do_colormaps (handle))      {        handle->cmap = XCreateColormap(handle->display,                                       XRootWindow(handle->display, handle->screen_num),                                       handle->x_visual_info->visual,                                       AllocNone);        handle->cmap_alloced = TRUE;        xxlib_rgb_do_colormaps (handle);      }      if (handle->xlib_rgb_verbose)        printf ("color cube: %d x %d x %d\n",                handle->nred_shades,                handle->ngreen_shades,                handle->nblue_shades);      if (!handle->cmap_alloced)        handle->cmap = handle->default_colormap;     }#ifdef ENABLE_GRAYSCALE    else if (handle->x_visual_info->class == GrayScale)    {      handle->cmap = XCreateColormap(handle->display,                                     XRootWindow(handle->display, handle->screen_num),                                     handle->x_visual_info->visual,                                     AllocNone);      xxlib_rgb_set_gray_cmap (handle, handle->cmap);      handle->cmap_alloced = TRUE;    }#endif /* ENABLE_GRAYSCALE */    else    {      /* Always install colormap in direct color. */      if (handle->x_visual_info->class != DirectColor &&           handle->x_visual_info->visualid == handle->default_visualid->visualid)        handle->cmap = handle->default_colormap;      else        {          handle->cmap = XCreateColormap(handle->display,                                             XRootWindow(handle->display, handle->screen_num),                                             handle->x_visual_info->visual,                                             AllocNone);          handle->cmap_alloced = TRUE;        }    }    handle->bitmap = (handle->x_visual_info->depth == 1);    for (i = 0; i < N_IMAGES; i++) {      if (handle->bitmap) {        /* Use malloc() instead of g_malloc since X will free() this mem */        handle->static_image[i] = XCreateImage(handle->display,                                       handle->x_visual_info->visual,                                       1,                                       XYBitmap,                                       0, 0, IMAGE_WIDTH, IMAGE_HEIGHT,                                       8,                                       0);        handle->static_image[i]->data = malloc(IMAGE_WIDTH * IMAGE_HEIGHT >> 3);        handle->static_image[i]->bitmap_bit_order = MSBFirst;        handle->static_image[i]->byte_order = MSBFirst;      }      else {        handle->static_image[i] = XCreateImage(handle->display,                                       handle->x_visual_info->visual,                                       (unsigned int)handle->x_visual_info->depth,                                       ZPixmap,                                       0, 0,                                       IMAGE_WIDTH,                                       IMAGE_HEIGHT,                                       32, 0);        /* remove this when we are using shared memory.. */        handle->static_image[i]->data = malloc((size_t)IMAGE_WIDTH * IMAGE_HEIGHT * handle->x_visual_info->depth);        handle->static_image[i]->bitmap_bit_order = MSBFirst;        handle->static_image[i]->byte_order = MSBFirst;      }    }    /* ok, so apparently, handle->bpp is actually       BYTES per pixel.  What fun! */    switch (handle->static_image[0]->bits_per_pixel) {    case 1:    case 8:      handle->bpp = 1;      break;    case 16:      handle->bpp = 2;      break;    case 24:      handle->bpp = 3;      break;    case 32:      handle->bpp = 4;      break;    }    xxlib_rgb_select_conv (handle, handle->static_image[0], MSB_FIRST);        return handle;}