Visuals

Visuals — Low-level display hardware information

Synopsis


#include <gdk/gdk.h>


            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);
#define     gdk_visual_ref                  (v)
#define     gdk_visual_unref                (v)
GdkScreen*  gdk_visual_get_screen           (GdkVisual *visual);


Description

A GdkVisual describes a particular video hardware display format. 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. For example, a piece of display hardware might support 24-bit color, 16-bit color, or 8-bit color; meaning 24/16/8-bit pixel sizes. For a given pixel size, pixels can be in different formats; for example the "red" element of an RGB pixel may be in the top 8 bits of the pixel, or may be in the lower 4 bits.

Usually you can avoid thinking about visuals in GTK+. Visuals are useful to interpret the contents of a GdkImage, but you should avoid GdkImage precisely because its contents depend on the display hardware; use GdkPixbuf instead, for all but the most low-level purposes. Also, anytime you provide a GdkColormap, the visual is implied as part of the colormap (gdk_colormap_get_visual()), so you won't have to provide a visual in addition.

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

GdkVisual

typedef struct {
  GObject parent_instance;
  
  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;
} GdkVisual;

The GdkVisual structure contains information about a particular visual.

Example 5. 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);
}

GObject parent_instance; inherited portion from GObject
GdkVisualType type; The type of this visual.
gint depth; The number of bits per pixel.
GdkByteOrder byte_order; The byte-order for this visual.
gint 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.
gint 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())
guint32 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.
gint red_shift; 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 bits starting at bit number red_shift. For example, Example 5, “Constructing a pixel value from components” shows constructing a pixel value out of three 16 bit color values.
gint red_prec; See above.
guint32 green_mask; A mask giving the bits in a pixel value that correspond to the green field.
gint green_shift; The green_shift and green_prec give an alternate presentation of the information in green_mask.
gint green_prec; See above.
guint32 blue_mask; A mask giving the bits in a pixel value that correspond to the blue field.
gint blue_shift; The blue_shift and blue_prec give an alternate presentation of the information in blue_mask.
gint blue_prec; See above.

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_VISUAL_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_VISUAL_DIRECT_COLOR Each pixel value contains red, green, and blue components as for GDK_VISUAL_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 most-significant byte first. For instance, the 32-bit value 0xffeecc would be stored in memory as 0x00, 0xcc, 0xee, 0xff.

gdk_query_depths ()

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

This function returns the available bit depths for the default screen. It's equivalent to listing the visuals (gdk_list_visuals()) and then looking at the depth field in each visual, removing duplicates.

The array returned by this function should not be freed.

depths : return location for available depths
count : return location for number of available depths

gdk_query_visual_types ()

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

This function returns the available visual types for the default screen. It's equivalent to listing the visuals (gdk_list_visuals()) and then looking at the type field in each visual, removing duplicates.

The array returned by this function should not be freed.

visual_types : return location for the available visual types
count : return location for the number of available visual types

gdk_list_visuals ()

GList*      gdk_list_visuals                (void);

Lists the available visuals for the default screen. (See gdk_screen_list_visuals()) A visual describes a hardware image data format. For example, a visual might support 24-bit color, or 8-bit color, and might expect pixels to be in a certain format.

Call g_list_free() on the return value when you're finished with it.

Returns : a list of visuals; the list must be freed, but not its contents

gdk_visual_get_best_depth ()

gint        gdk_visual_get_best_depth       (void);

Get the best available depth for the default GDK screen. "Best" means "largest," i.e. 32 preferred over 24 preferred over 8 bits per pixel.

Returns : best available depth

gdk_visual_get_best_type ()

GdkVisualType gdk_visual_get_best_type      (void);

Return the best available visual type for the default GDK screen.

Returns : best visual type

gdk_visual_get_system ()

GdkVisual*  gdk_visual_get_system           (void);

Get the system'sdefault visual for the default GDK screen. This is the visual for the root window of the display. The return value should not be freed.

Returns : system visual

gdk_visual_get_best ()

GdkVisual*  gdk_visual_get_best             (void);

Get the visual with the most available colors for the default GDK screen. The return value should not be freed.

Returns : best visual

gdk_visual_get_best_with_depth ()

GdkVisual*  gdk_visual_get_best_with_depth  (gint depth);

Get the best visual with depth depth for the default GDK screen. Color visuals and visuals with mutable colormaps are preferred over grayscale or fixed-colormap visuals. The return value should not be freed. NULL may be returned if no visual supports depth.

depth : a bit depth
Returns : best visual for the given depth

gdk_visual_get_best_with_type ()

GdkVisual*  gdk_visual_get_best_with_type   (GdkVisualType visual_type);

Get the best visual of the given visual_type for the default GDK screen. Visuals with higher color depths are considered better. The return value should not be freed. NULL may be returned if no visual has type visual_type.

visual_type : a visual type
Returns : best visual of the given type

gdk_visual_get_best_with_both ()

GdkVisual*  gdk_visual_get_best_with_both   (gint depth,
                                             GdkVisualType visual_type);

Combines gdk_visual_get_best_with_depth() and gdk_visual_get_best_with_type().

depth : a bit depth
visual_type : a visual type
Returns : best visual with both depth and visual_type, or NULL if none

gdk_visual_ref()

#define gdk_visual_ref(v) g_object_ref(v)

Warning

gdk_visual_ref is deprecated and should not be used in newly-written code.

Deprecated equivalent of g_object_ref().

v : a GdkVisual
Returns : the same visual

gdk_visual_unref()

#define gdk_visual_unref(v) g_object_unref(v)

Warning

gdk_visual_unref is deprecated and should not be used in newly-written code.

Deprecated equivalent of g_object_unref().

v : a GdkVisual

gdk_visual_get_screen ()

GdkScreen*  gdk_visual_get_screen           (GdkVisual *visual);

Gets the screen to which this visual belongs

visual : a GdkVisual
Returns : the screen to which this visual belongs.

Since 2.2

See Also

GdkImage, GdkColormap, GdkRGB