GDK Reference Manual
<<< Previous Page | Home | Up | Next Page >>>

# Visuals

## Name

Visuals -- manipulation of visuals.

## Synopsis

    #include <gdk/gdk.h>

    struct      GdkVisual;
    enum        GdkVisualType;
    enum        GdkByteOrder;
    void        gdk_query_depths                (gint **depths,
                                                 gint *count);
    void        gdk_query_visual_types          (GdkVisualType **visual_types,
                                                 gint *count);
    GList*      gdk_list_visuals                (void);
    gint        gdk_visual_get_best_depth       (void);
    GdkVisualType gdk_visual_get_best_type      (void);
    GdkVisual*  gdk_visual_get_system           (void);
    GdkVisual*  gdk_visual_get_best             (void);
    GdkVisual*  gdk_visual_get_best_with_depth  (gint depth);
    GdkVisual*  gdk_visual_get_best_with_type   (GdkVisualType visual_type);
    GdkVisual*  gdk_visual_get_best_with_both   (gint depth,
                                                 GdkVisualType visual_type);
    GdkVisual*  gdk_visual_ref                  (GdkVisual *visual);
    void        gdk_visual_unref                (GdkVisual *visual);

## Description

The way that the data stored on the screen is stored in memory can vary considerably between different X servers; some X servers even support multiple formats used simultaneously. An X visual represents a particular format for screen data. It includes information about the number of bits used for each color, the way the bits are translated into an RGB value for display, and the way the bits are stored in memory.

There are several standard visuals. The visual returned by gdk_visual_get_system() is the system's default visual. gdk_rgb_get_visual() return the visual most suited to displaying full-color image data. If you use the calls in GdkRGB, you should create your windows using this visual (and the colormap returned by gdk_rgb_get_colormap()).

A number of functions are provided for determining the "best" available visual. For the purposes of making this determination, higher bit depths are considered better, and for visuals of the same bit depth, `GDK_VISUAL_PSEUDO_COLOR` is preferred at 8bpp, otherwise, the visual types are ranked in the order of (highest to lowest) `GDK_VISUAL_DIRECT_COLOR`, `GDK_VISUAL_TRUE_COLOR`, `GDK_VISUAL_PSEUDO_COLOR`, `GDK_VISUAL_STATIC_COLOR`, `GDK_VISUAL_GRAYSCALE`, then `GDK_VISUAL_STATIC_GRAY`.

## Details

### struct GdkVisual

    struct GdkVisual
    {
      GdkVisualType type;
      gint depth;
      GdkByteOrder byte_order;
      gint colormap_size;
      gint bits_per_rgb;

      guint32 red_mask;
      gint red_shift;
      gint red_prec;

      guint32 green_mask;
      gint green_shift;
      gint green_prec;

      guint32 blue_mask;
      gint blue_shift;
      gint blue_prec;
    };

The GdkVisual structure contains information about a particular visual. It contains the following public fields.

`type` | The type of this visual.
`depth` | The number of bits per pixel.
`byte_order` | The byte-order for this visual.
`colormap_size` | The number of entries in the colormap, for visuals of type GDK_VISUAL_PSEUDO_COLOR or GDK_VISUAL_GRAY_SCALE. For other visual types, it is the number of possible levels per color component. If the visual has different numbers of levels for different components, the value of this field is undefined.
`bits_per_rgb` | The number of significant bits per red, green, or blue when specifying colors for this visual. (For instance, for gdk_colormap_alloc_color())
`red_mask` | A mask giving the bits in a pixel value that correspond to the red field. Significant only for `GDK_VISUAL_PSEUDOCOLOR` and `GDK_VISUAL_DIRECTCOLOR`.
`red_shift, red_prec` | The `red_shift` and `red_prec` give an alternate presentation of the information in `red_mask`. `red_mask` is a contiguous sequence of `red_prec` starting at bit number `red_shift`. For example, Figure 1 shows constructing a pixel value out of three 16 bit color values.
`green_mask` | A mask giving the bits in a pixel value that correspond to the green field.
`green_shift, green_prec` | The `green_shift` and `green_prec` give an alternate presentation of the information in `green_mask`.
`blue_mask` | A mask giving the bits in a pixel value that correspond to the blue field.
`blue_shift, blue_prec` | The `blue_shift` and `blue_prec` give an alternate presentation of the information in `blue_mask`.

Figure 1. Constructing a pixel value from components

    guint
    pixel_from_rgb (GdkVisual *visual,
                    guchar r, guchar b, guchar g)
    {
      return ((r >> (16 - visual->red_prec))   << visual->red_shift) |
             ((g >> (16 - visual->green_prec)) << visual->green_shift) |
             ((r >> (16 - visual->blue_prec))  << visual->blue_shift);
    }

### enum GdkVisualType

    typedef enum
    {
      GDK_VISUAL_STATIC_GRAY,
      GDK_VISUAL_GRAYSCALE,
      GDK_VISUAL_STATIC_COLOR,
      GDK_VISUAL_PSEUDO_COLOR,
      GDK_VISUAL_TRUE_COLOR,
      GDK_VISUAL_DIRECT_COLOR
    } GdkVisualType;

A set of values that describe the manner in which the pixel values for a visual are converted into RGB values for display.

GDK_VISUAL_STATIC_GRAY | Each pixel value indexes a grayscale value directly.
GDK_VISUAL_GRAYSCALE | Each pixel is an index into a color map that maps pixel values into grayscale values. The color map can be changed by an application.
GDK_VISUAL_STATIC_COLOR | Each pixel value is an index into a predefined, unmodifiable color map that maps pixel values into rgb values.
GDK_VISUAL_PSEUDO_COLOR | Each pixel is an index into a color map that maps pixel values into rgb values. The color map can be changed by an application.
GDK_TRUE_COLOR | Each pixel value directly contains red, green, and blue components. The `red_mask`, `green_mask`, and `blue_mask` fields of the GdkVisual structure describe how the components are assembled into a pixel value. .
GDK_DIRECT_COLOR | Each pixel value contains red, green, and blue components as for `GDK_TRUE_COLOR`, but the components are mapped via a color table into the final output table instead of being converted directly..

### enum GdkByteOrder

    typedef enum
    {
      GDK_LSB_FIRST,
      GDK_MSB_FIRST
    } GdkByteOrder;

A set of values describing the possible byte-orders for storing pixel values in memory.

GDK_LSB_FIRST | The values are stored with the least-significant byte first. For instance, the 32-bit value 0xffeecc would be stored in memory as 0xcc, 0xee, 0xff, 0x00.
GDK_MSB_FIRST | The values are stored with the least-significant byte first. For instance, the 32-bit value 0xffeecc would be stored in memory as 0xff, 0xee, 0xcc, 0x00.

### gdk_query_depths ()

    void        gdk_query_depths                (gint **depths,
                                                 gint *count);

Lists the available color depths. The returned values are pointers to static storage and should not be modified or freed.

`depths` : | a location to store a pointer to an array holding the available color depths.
`count` : | a location to store the number of values in `depths`.

### gdk_query_visual_types ()

    void        gdk_query_visual_types          (GdkVisualType **visual_types,
                                                 gint *count);

Lists the available visual types. The returned values are pointers to static storage and should not be modified or freed.

`visual_types` : | a location to store a pointer to an array holding the available visual types.
`count` : | a location to store the number of values in `visual` types.

### gdk_list_visuals ()

    GList*      gdk_list_visuals                (void);

Lists the available visuals.

Returns : | A GList of the available visuals. The list should be freed this list with g_list_free().

### gdk_visual_get_best_depth ()

    gint        gdk_visual_get_best_depth       (void);

Returns the best available color depth.

Returns : | the best available color depth.

### gdk_visual_get_best_type ()

    GdkVisualType gdk_visual_get_best_type      (void);

Returns the best available visual type.

Returns : | the best available visual type.

### gdk_visual_get_system ()

    GdkVisual*  gdk_visual_get_system           (void);

Returns the system's default visual.

Returns : | the system's default visual.

### gdk_visual_get_best ()

    GdkVisual*  gdk_visual_get_best             (void);

Returns the best available visual.

Returns : | the best available visual.

### gdk_visual_get_best_with_depth ()

    GdkVisual*  gdk_visual_get_best_with_depth  (gint depth);

Returns the best available visual with a certain depth.

`depth` : | the desired color depth
Returns : | the best available visual with `depth` bits per pixel or `NULL` if no visuals with that type are available.

### gdk_visual_get_best_with_type ()

    GdkVisual*  gdk_visual_get_best_with_type   (GdkVisualType visual_type);

Returns the best available visual of a certain visual type.

`visual_type` : | the desired visual type.
Returns : | the visual of the given type with the highest depth or `NULL` if no visuals of that type are available.

### gdk_visual_get_best_with_both ()

    GdkVisual*  gdk_visual_get_best_with_both   (gint depth,
                                                 GdkVisualType visual_type);

Returns the best available visual

`depth` : | the desired visual type.
`visual_type` : | the desired depth.
Returns : | the best available visual with the given depth and visual type, or `NULL` if no matching visuals are available.

### gdk_visual_ref ()

    GdkVisual*  gdk_visual_ref                  (GdkVisual *visual);

In theory, increases the reference count of a visual. However, the set of visuals is determined statically when GTK+ is initialized, so this operation does nothing.

`visual` : | a GdkVisual.
Returns : | `visual`.

### gdk_visual_unref ()

    void        gdk_visual_unref                (GdkVisual *visual);

In theory, decreases the reference count of a visual. Like gdk_visual_ref(), this operation does nothing.

`visual` : | a GdkVisual.

<<< Previous Page | Home | Up | Next Page >>>
Color Contexts | Fonts