<refentry id="gdk-Visuals">
<refmeta>
<refentrytitle>Visuals</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>GDK Library</refmiscinfo>
</refmeta>

<refnamediv>
<refname>Visuals</refname><refpurpose>
Low-level display hardware information</refpurpose>
</refnamediv>

<refsynopsisdiv><title>Synopsis</title>
<synopsis>

#include &lt;gdk/gdk.h&gt;


struct      <link linkend="GdkVisual">GdkVisual</link>;
enum        <link linkend="GdkVisualType">GdkVisualType</link>;
enum        <link linkend="GdkByteOrder">GdkByteOrder</link>;
void        <link linkend="gdk-query-depths">gdk_query_depths</link>                (<link linkend="gint">gint</link> **depths,
                                             <link linkend="gint">gint</link> *count);
void        <link linkend="gdk-query-visual-types">gdk_query_visual_types</link>          (<link linkend="GdkVisualType">GdkVisualType</link> **visual_types,
                                             <link linkend="gint">gint</link> *count);
<link linkend="GList">GList</link>*      <link linkend="gdk-list-visuals">gdk_list_visuals</link>                (void);
<link linkend="gint">gint</link>        <link linkend="gdk-visual-get-best-depth">gdk_visual_get_best_depth</link>       (void);
<link linkend="GdkVisualType">GdkVisualType</link> <link linkend="gdk-visual-get-best-type">gdk_visual_get_best_type</link>      (void);
<link linkend="GdkVisual">GdkVisual</link>*  <link linkend="gdk-visual-get-system">gdk_visual_get_system</link>           (void);
<link linkend="GdkVisual">GdkVisual</link>*  <link linkend="gdk-visual-get-best">gdk_visual_get_best</link>             (void);
<link linkend="GdkVisual">GdkVisual</link>*  <link linkend="gdk-visual-get-best-with-depth">gdk_visual_get_best_with_depth</link>  (<link linkend="gint">gint</link> depth);
<link linkend="GdkVisual">GdkVisual</link>*  <link linkend="gdk-visual-get-best-with-type">gdk_visual_get_best_with_type</link>   (<link linkend="GdkVisualType">GdkVisualType</link> visual_type);
<link linkend="GdkVisual">GdkVisual</link>*  <link linkend="gdk-visual-get-best-with-both">gdk_visual_get_best_with_both</link>   (<link linkend="gint">gint</link> depth,
                                             <link linkend="GdkVisualType">GdkVisualType</link> visual_type);
#define     <link linkend="gdk-visual-ref">gdk_visual_ref</link>                  (v)
#define     <link linkend="gdk-visual-unref">gdk_visual_unref</link>                (v)


</synopsis>
</refsynopsisdiv>





<refsect1>
<title>Description</title>
<para>
A <link linkend="GdkVisual">GdkVisual</link> 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.
</para>
<para>
Usually you can avoid thinking about visuals in GTK+. Visuals are useful to
interpret the contents of a <link linkend="GdkImage">GdkImage</link>, but you should avoid <link linkend="GdkImage">GdkImage</link> precisely
because its contents depend on the display hardware; use <link linkend="GdkPixbuf">GdkPixbuf</link> instead, for
all but the most low-level purposes. Also, anytime you provide a <link linkend="GdkColormap">GdkColormap</link>,
the visual is implied as part of the colormap (<link linkend="gdk-colormap-get-visual">gdk_colormap_get_visual</link>()), so
you won't have to provide a visual in addition.
</para>
<para>
There are several standard visuals. The visual returned
by <link linkend="gdk-visual-get-system">gdk_visual_get_system</link>() is the system's default
visual. <link linkend="gdk-rgb-get-visual">gdk_rgb_get_visual</link>() return the visual most
suited to displaying full-color image data. If you
use the calls in <link linkend="GdkRGB">GdkRGB</link>, you should create your windows
using this visual (and the colormap returned by
<link linkend="gdk-rgb-get-colormap">gdk_rgb_get_colormap</link>()).
</para>
<para>
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, <literal>GDK_VISUAL_PSEUDO_COLOR</literal> is preferred at
8bpp, otherwise, the visual types are ranked in the
order of (highest to lowest) <literal>GDK_VISUAL_DIRECT_COLOR</literal>,
<literal>GDK_VISUAL_TRUE_COLOR</literal>, <literal>GDK_VISUAL_PSEUDO_COLOR</literal>,
<literal>GDK_VISUAL_STATIC_COLOR</literal>, <literal>GDK_VISUAL_GRAYSCALE</literal>,
then <literal>GDK_VISUAL_STATIC_GRAY</literal>.
</para>
</refsect1>

<refsect1>
<title>Details</title>
<refsect2>
<title><anchor id="GdkVisual">struct GdkVisual</title>
<programlisting>struct GdkVisual
{
  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;
};
</programlisting>
<para>
The <type>GdkVisual</type> structure contains information about
a particular visual.
</para>

<example id="rgbmask">
<title>Constructing a pixel value from components</title>
<programlisting>
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);
}
</programlisting>
</example><informaltable pgwide="1" frame="none" role="struct">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row>
<entry><link linkend="GObject">GObject</link> <structfield>parent_instance</structfield></entry>
<entry>inherited portion from <link linkend="GObject">GObject</link>
</entry>
</row>
<row>
<entry><link linkend="GdkVisualType">GdkVisualType</link> <structfield>type</structfield></entry>
<entry>The type of this visual.
</entry>
</row>
<row>
<entry><link linkend="gint">gint</link> <structfield>depth</structfield></entry>
<entry>The number of bits per pixel.
</entry>
</row>
<row>
<entry><link linkend="GdkByteOrder">GdkByteOrder</link> <structfield>byte_order</structfield></entry>
<entry>The byte-order for this visual.
</entry>
</row>
<row>
<entry><link linkend="gint">gint</link> <structfield>colormap_size</structfield></entry>
<entry>The number of entries in the colormap, for
    visuals of type <literal>GDK_VISUAL_PSEUDO_COLOR</literal> or
    <literal>GDK_VISUAL_GRAY_SCALE</literal>. 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.
</entry>
</row>
<row>
<entry><link linkend="gint">gint</link> <structfield>bits_per_rgb</structfield></entry>
<entry>The number of significant bits per red, green, or blue
    when specifying colors for this visual. (For instance, for 
    <link linkend="gdk-colormap-alloc-color">gdk_colormap_alloc_color</link>())
</entry>
</row>
<row>
<entry><link linkend="guint32">guint32</link> <structfield>red_mask</structfield></entry>
<entry>A mask giving the bits in a pixel value that
    correspond to the red field. Significant only for
    <literal>GDK_VISUAL_PSEUDOCOLOR</literal> and <literal>GDK_VISUAL_DIRECTCOLOR</literal>.
</entry>
</row>
<row>
<entry><link linkend="gint">gint</link> <structfield>red_shift</structfield></entry>
<entry>The <structfield>red_shift</structfield> and
    <structfield>red_prec</structfield> give an alternate presentation
    of the information in <structfield>red_mask</structfield>.
    <structfield>red_mask</structfield> is a contiguous sequence
    of <structfield>red_prec</structfield> bits starting at bit
    number <structfield>red_shift</structfield>. For example,
    <xref linkend="rgbmask"> shows constructing a pixel value
    out of three 16 bit color values.
</entry>
</row>
<row>
<entry><link linkend="gint">gint</link> <structfield>red_prec</structfield></entry>
<entry>See above.
</entry>
</row>
<row>
<entry><link linkend="guint32">guint32</link> <structfield>green_mask</structfield></entry>
<entry>A mask giving the bits in a pixel value that
    correspond to the green field.
</entry>
</row>
<row>
<entry><link linkend="gint">gint</link> <structfield>green_shift</structfield></entry>
<entry>The <structfield>green_shift</structfield> and
    <structfield>green_prec</structfield> give an alternate presentation
    of the information in <structfield>green_mask</structfield>.
</entry>
</row>
<row>
<entry><link linkend="gint">gint</link> <structfield>green_prec</structfield></entry>
<entry>See above.
</entry>
</row>
<row>
<entry><link linkend="guint32">guint32</link> <structfield>blue_mask</structfield></entry>
<entry>A mask giving the bits in a pixel value that
    correspond to the blue field.
</entry>
</row>
<row>
<entry><link linkend="gint">gint</link> <structfield>blue_shift</structfield></entry>
<entry>The <structfield>blue_shift</structfield> and
    <structfield>blue_prec</structfield> give an alternate presentation
    of the information in <structfield>blue_mask</structfield>.
</entry>
</row>
<row>
<entry><link linkend="gint">gint</link> <structfield>blue_prec</structfield></entry>
<entry>See above.

</entry>
</row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="GdkVisualType">enum GdkVisualType</title>
<programlisting>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;
</programlisting>
<para>
A set of values that describe the manner in which the
pixel values for a visual are converted into RGB
values for display.
</para><informaltable pgwide="1" frame="none" role="enum">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row>
<entry><literal>GDK_VISUAL_STATIC_GRAY</literal></entry>
<entry>Each pixel value indexes a grayscale value directly.
</entry>
</row>
<row>
<entry><literal>GDK_VISUAL_GRAYSCALE</literal></entry>
<entry>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.
</entry>
</row>
<row>
<entry><literal>GDK_VISUAL_STATIC_COLOR</literal></entry>
<entry>Each pixel value is an index into a predefined,
   unmodifiable color map that maps pixel values into RGB values.
</entry>
</row>
<row>
<entry><literal>GDK_VISUAL_PSEUDO_COLOR</literal></entry>
<entry>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.
</entry>
</row>
<row>
<entry><literal>GDK_VISUAL_TRUE_COLOR</literal></entry>
<entry>Each pixel value directly contains red, green,
   and blue components. The <structfield>red_mask</structfield>,
   <structfield>green_mask</structfield>, and 
   <structfield>blue_mask</structfield> fields of the <link linkend="GdkVisual">GdkVisual</link>
   structure describe how the components are assembled into a pixel value.
</entry>
</row>
<row>
<entry><literal>GDK_VISUAL_DIRECT_COLOR</literal></entry>
<entry>Each pixel value contains red, green, and blue
   components as for <literal>GDK_TRUE_COLOR</literal>, but the components are mapped via a 
   color table into the final output table instead of being converted directly.

</entry>
</row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="GdkByteOrder">enum GdkByteOrder</title>
<programlisting>typedef enum
{
  GDK_LSB_FIRST,
  GDK_MSB_FIRST
} GdkByteOrder;
</programlisting>
<para>
A set of values describing the possible byte-orders
for storing pixel values in memory.
</para><informaltable pgwide="1" frame="none" role="enum">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row>
<entry><literal>GDK_LSB_FIRST</literal></entry>
<entry>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.
</entry>
</row>
<row>
<entry><literal>GDK_MSB_FIRST</literal></entry>
<entry>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.

</entry>
</row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="gdk-query-depths">gdk_query_depths ()</title>
<programlisting>void        gdk_query_depths                (<link linkend="gint">gint</link> **depths,
                                             <link linkend="gint">gint</link> *count);</programlisting>
<para>
This function returns the available bit depths for the default
display. It's equivalent to listing the visuals
(<link linkend="gdk-list-visuals">gdk_list_visuals</link>()) and then looking at the depth field in each
visual, removing duplicates.
</para>
<para>
The array returned by this function should not be freed.</para>
<para>

</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>depths</parameter>&nbsp;:</entry>
<entry> return location for available depths 
</entry></row>
<row><entry align="right"><parameter>count</parameter>&nbsp;:</entry>
<entry> return location for number of available depths
</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="gdk-query-visual-types">gdk_query_visual_types ()</title>
<programlisting>void        gdk_query_visual_types          (<link linkend="GdkVisualType">GdkVisualType</link> **visual_types,
                                             <link linkend="gint">gint</link> *count);</programlisting>
<para>
This function returns the available visual types for the default
display. It's equivalent to listing the visuals
(<link linkend="gdk-list-visuals">gdk_list_visuals</link>()) and then looking at the type field in each
visual, removing duplicates.
</para>
<para>
The array returned by this function should not be freed.</para>
<para>

</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>visual_types</parameter>&nbsp;:</entry>
<entry> return location for the available visual types
</entry></row>
<row><entry align="right"><parameter>count</parameter>&nbsp;:</entry>
<entry> return location for the number of available visual types
</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="gdk-list-visuals">gdk_list_visuals ()</title>
<programlisting><link linkend="GList">GList</link>*      gdk_list_visuals                (void);</programlisting>
<para>
Lists the available visuals for the default display.
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.
</para>
<para>
Call <link linkend="g-list-free">g_list_free</link>() on the return value when you're finished with it.</para>
<para>

</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> a list of visuals; the list must be freed, but not its contents
</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="gdk-visual-get-best-depth">gdk_visual_get_best_depth ()</title>
<programlisting><link linkend="gint">gint</link>        gdk_visual_get_best_depth       (void);</programlisting>
<para>
Get the best available depth for the default GDK display.  "Best"
means "largest," i.e. 32 preferred over 24 preferred over 8 bits
per pixel.</para>
<para>

</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> best available depth
</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="gdk-visual-get-best-type">gdk_visual_get_best_type ()</title>
<programlisting><link linkend="GdkVisualType">GdkVisualType</link> gdk_visual_get_best_type      (void);</programlisting>
<para>
Return the best available visual type (the one with the most
colors) for the default GDK display.</para>
<para>

</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> best visual type
</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="gdk-visual-get-system">gdk_visual_get_system ()</title>
<programlisting><link linkend="GdkVisual">GdkVisual</link>*  gdk_visual_get_system           (void);</programlisting>
<para>
Get the default or system visual for the default GDK display.
This is the visual for the root window of the display.
The return value should not be freed.</para>
<para>

</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> system visual
</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="gdk-visual-get-best">gdk_visual_get_best ()</title>
<programlisting><link linkend="GdkVisual">GdkVisual</link>*  gdk_visual_get_best             (void);</programlisting>
<para>
Get the visual with the most available colors for the default
GDK display. The return value should not be freed.</para>
<para>

</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> best visual
</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="gdk-visual-get-best-with-depth">gdk_visual_get_best_with_depth ()</title>
<programlisting><link linkend="GdkVisual">GdkVisual</link>*  gdk_visual_get_best_with_depth  (<link linkend="gint">gint</link> depth);</programlisting>
<para>
Get the best visual with depth <parameter>depth</parameter> for the default GDK display.
Color visuals and visuals with mutable colormaps are preferred
over grayscale or fixed-colormap visuals. The return value should not
be freed. <literal>NULL</literal> may be returned if no visual supports <parameter>depth</parameter>.</para>
<para>

</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>depth</parameter>&nbsp;:</entry>
<entry> a bit depth
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> best visual for the given depth
</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="gdk-visual-get-best-with-type">gdk_visual_get_best_with_type ()</title>
<programlisting><link linkend="GdkVisual">GdkVisual</link>*  gdk_visual_get_best_with_type   (<link linkend="GdkVisualType">GdkVisualType</link> visual_type);</programlisting>
<para>
Get the best visual of the given <parameter>visual_type</parameter> for the default GDK display.
Visuals with higher color depths are considered better. The return value
should not be freed. <literal>NULL</literal> may be returned if no visual has type
<parameter>visual_type</parameter>.</para>
<para>

</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>visual_type</parameter>&nbsp;:</entry>
<entry> a visual type
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> best visual of the given type
</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="gdk-visual-get-best-with-both">gdk_visual_get_best_with_both ()</title>
<programlisting><link linkend="GdkVisual">GdkVisual</link>*  gdk_visual_get_best_with_both   (<link linkend="gint">gint</link> depth,
                                             <link linkend="GdkVisualType">GdkVisualType</link> visual_type);</programlisting>
<para>
Combines <link linkend="gdk-visual-get-best-with-depth">gdk_visual_get_best_with_depth</link>() and <link linkend="gdk-visual-get-best-with-type">gdk_visual_get_best_with_type</link>().</para>
<para>

</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>depth</parameter>&nbsp;:</entry>
<entry> a bit depth
</entry></row>
<row><entry align="right"><parameter>visual_type</parameter>&nbsp;:</entry>
<entry> a visual type
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> best visual with both <parameter>depth</parameter> and <parameter>visual_type</parameter>, or <literal>NULL</literal> if none
</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="gdk-visual-ref">gdk_visual_ref()</title>
<programlisting>#define gdk_visual_ref(v) g_object_ref(v)
</programlisting>
<warning>
<para>
<literal>gdk_visual_ref</literal> is deprecated and should not be used in newly-written code.
</para>
</warning>
<para>
Deprecated equivalent of <link linkend="g-object-ref">g_object_ref</link>().
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>v</parameter>&nbsp;:</entry>
<entry>
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>


</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="gdk-visual-unref">gdk_visual_unref()</title>
<programlisting>#define gdk_visual_unref(v) g_object_unref(v)
</programlisting>
<warning>
<para>
<literal>gdk_visual_unref</literal> is deprecated and should not be used in newly-written code.
</para>
</warning>
<para>
Deprecated equivalent of <link linkend="g-object-unref">g_object_unref</link>().
</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>v</parameter>&nbsp;:</entry>
<entry>


</entry></row>
</tbody></tgroup></informaltable></refsect2>

</refsect1>



<refsect1>
<title>See Also</title>
<para>
<link linkend="GdkImage">GdkImage</link>, <link linkend="GdkColormap">GdkColormap</link>, <link linkend="GdkRGB">GdkRGB</link>
</para>
</refsect1>

</refentry>
