/* Search for an appropriate visual. Promote where necessary. Check to make sure that ENOUGH colormap entries are writeable. basePixel was determined when XAllocColorCells() contiguously allocated enough entries. basePixel is used below in GetTIFFImage.  */
Boolean SearchVisualList(int image_depth, int visual_class, Visual **visual)
/* Search for an appropriate visual. Promote where necessary. Check to make sure that ENOUGH colormap entries are writeable. basePixel was determined when XAllocColorCells() contiguously allocated enough entries. basePixel is used below in GetTIFFImage.  */
Boolean SearchVisualList(int image_depth, int visual_class, Visual **visual)
{
    XVisualInfo template_visual, *visual_list, *vl;
    int i, n_visuals;
    template_visual.screen = xScreen;
    vl = visual_list = XGetVisualInfo(xDisplay, VisualScreenMask,
        &template_visual, &n_visuals);
    if (n_visuals == 0) {
        fprintf(stderr, "xtiff: visual list not available\n");
        exit(0);
    }
    for (i = 0; i < n_visuals; vl++, i++) {
        if ((vl->class == visual_class) && (vl->depth >= image_depth)
            && (vl->visual->map_entries >= (1 << vl->depth))) {
            *visual = vl->visual;
            xImageDepth = vl->depth;
            xRedMask = vl->red_mask;
            xGreenMask = vl->green_mask;
            xBlueMask = vl->blue_mask;
            XFree((char *) visual_list);
            return True;
        }
    }
    XFree((char *) visual_list);
    return False;
}