1 /* GDK - The GIMP Drawing Kit
2  * gdkvisual.c
3  *
4  * Copyright 2001 Sun Microsystems Inc.
5  *
6  * Erwann Chenede <erwann.chenede@sun.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
24 #include "config.h"
25 #include "gdkvisual.h"
26 #include "gdkscreen.h"
27 #include "gdkalias.h"
28 
29 /**
30  * gdk_list_visuals:
31  *
32  * Lists the available visuals for the default screen.
33  * (See gdk_screen_list_visuals())
34  * A visual describes a hardware image data format.
35  * For example, a visual might support 24-bit color, or 8-bit color,
36  * and might expect pixels to be in a certain format.
37  *
38  * Call g_list_free() on the return value when you're finished with it.
39  *
40  * Return value: (transfer container) (element-type GdkVisual):
41  *     a list of visuals; the list must be freed, but not its contents
42  **/
43 GList*
gdk_list_visuals(void)44 gdk_list_visuals (void)
45 {
46   return gdk_screen_list_visuals (gdk_screen_get_default ());
47 }
48 
49 /**
50  * gdk_visual_get_system:
51  *
52  * Get the system's default visual for the default GDK screen.
53  * This is the visual for the root window of the display.
54  * The return value should not be freed.
55  *
56  * Return value: (transfer none): system visual
57  **/
58 GdkVisual*
gdk_visual_get_system(void)59 gdk_visual_get_system (void)
60 {
61   return gdk_screen_get_system_visual (gdk_screen_get_default());
62 }
63 
64 /**
65  * gdk_visual_get_visual_type:
66  * @visual: A #GdkVisual.
67  *
68  * Returns the type of visual this is (PseudoColor, TrueColor, etc).
69  *
70  * Return value: A #GdkVisualType stating the type of @visual.
71  *
72  * Since: 2.22
73  */
74 GdkVisualType
gdk_visual_get_visual_type(GdkVisual * visual)75 gdk_visual_get_visual_type (GdkVisual *visual)
76 {
77   g_return_val_if_fail (GDK_IS_VISUAL (visual), 0);
78 
79   return visual->type;
80 }
81 
82 /**
83  * gdk_visual_get_depth:
84  * @visual: A #GdkVisual.
85  *
86  * Returns the bit depth of this visual.
87  *
88  * Return value: The bit depth of this visual.
89  *
90  * Since: 2.22
91  */
92 gint
gdk_visual_get_depth(GdkVisual * visual)93 gdk_visual_get_depth (GdkVisual *visual)
94 {
95   g_return_val_if_fail (GDK_IS_VISUAL (visual), 0);
96 
97   return visual->depth;
98 }
99 
100 /**
101  * gdk_visual_get_byte_order:
102  * @visual: A #GdkVisual.
103  *
104  * Returns the byte order of this visual.
105  *
106  * Return value: A #GdkByteOrder stating the byte order of @visual.
107  *
108  * Since: 2.22
109  */
110 GdkByteOrder
gdk_visual_get_byte_order(GdkVisual * visual)111 gdk_visual_get_byte_order (GdkVisual *visual)
112 {
113   g_return_val_if_fail (GDK_IS_VISUAL (visual), 0);
114 
115   return visual->byte_order;
116 }
117 
118 /**
119  * gdk_visual_get_colormap_size:
120  * @visual: A #GdkVisual.
121  *
122  * Returns the size of a colormap for this visual.
123  *
124  * Return value: The size of a colormap that is suitable for @visual.
125  *
126  * Since: 2.22
127  */
128 gint
gdk_visual_get_colormap_size(GdkVisual * visual)129 gdk_visual_get_colormap_size (GdkVisual *visual)
130 {
131   g_return_val_if_fail (GDK_IS_VISUAL (visual), 0);
132 
133   return visual->colormap_size;
134 }
135 
136 /**
137  * gdk_visual_get_bits_per_rgb:
138  * @visual: a #GdkVisual
139  *
140  * Returns the number of significant bits per red, green and blue value.
141  *
142  * Return value: The number of significant bits per color value for @visual.
143  *
144  * Since: 2.22
145  */
146 gint
gdk_visual_get_bits_per_rgb(GdkVisual * visual)147 gdk_visual_get_bits_per_rgb (GdkVisual *visual)
148 {
149   g_return_val_if_fail (GDK_IS_VISUAL (visual), 0);
150 
151   return visual->bits_per_rgb;
152 }
153 
154 /**
155  * gdk_visual_get_red_pixel_details:
156  * @visual: A #GdkVisual.
157  * @mask: (out) (allow-none): A pointer to a #guint32 to be filled in, or %NULL.
158  * @shift: (out) (allow-none): A pointer to a #gint to be filled in, or %NULL.
159  * @precision: (out) (allow-none): A pointer to a #gint to be filled in, or %NULL.
160  *
161  * Obtains values that are needed to calculate red pixel values in TrueColor
162  * and DirectColor.  The "mask" is the significant bits within the pixel.
163  * The "shift" is the number of bits left we must shift a primary for it
164  * to be in position (according to the "mask").  Finally, "precision" refers
165  * to how much precision the pixel value contains for a particular primary.
166  *
167  * Since: 2.22
168  */
169 void
gdk_visual_get_red_pixel_details(GdkVisual * visual,guint32 * mask,gint * shift,gint * precision)170 gdk_visual_get_red_pixel_details (GdkVisual *visual,
171                                   guint32   *mask,
172                                   gint      *shift,
173                                   gint      *precision)
174 {
175   g_return_if_fail (GDK_IS_VISUAL (visual));
176 
177   if (mask)
178     *mask = visual->red_mask;
179 
180   if (shift)
181     *shift = visual->red_shift;
182 
183   if (precision)
184     *precision = visual->red_prec;
185 }
186 
187 /**
188  * gdk_visual_get_green_pixel_details:
189  * @visual: a #GdkVisual
190  * @mask: (out) (allow-none): A pointer to a #guint32 to be filled in, or %NULL.
191  * @shift: (out) (allow-none): A pointer to a #gint to be filled in, or %NULL.
192  * @precision: (out) (allow-none): A pointer to a #gint to be filled in, or %NULL.
193  *
194  * Obtains values that are needed to calculate green pixel values in TrueColor
195  * and DirectColor.  The "mask" is the significant bits within the pixel.
196  * The "shift" is the number of bits left we must shift a primary for it
197  * to be in position (according to the "mask").  Finally, "precision" refers
198  * to how much precision the pixel value contains for a particular primary.
199  *
200  * Since: 2.22
201  */
202 void
gdk_visual_get_green_pixel_details(GdkVisual * visual,guint32 * mask,gint * shift,gint * precision)203 gdk_visual_get_green_pixel_details (GdkVisual *visual,
204                                     guint32   *mask,
205                                     gint      *shift,
206                                     gint      *precision)
207 {
208   g_return_if_fail (GDK_IS_VISUAL (visual));
209 
210   if (mask)
211     *mask = visual->green_mask;
212 
213   if (shift)
214     *shift = visual->green_shift;
215 
216   if (precision)
217     *precision = visual->green_prec;
218 }
219 
220 /**
221  * gdk_visual_get_blue_pixel_details:
222  * @visual: a #GdkVisual
223  * @mask: (out) (allow-none): A pointer to a #guint32 to be filled in, or %NULL.
224  * @shift: (out) (allow-none): A pointer to a #gint to be filled in, or %NULL.
225  * @precision: (out) (allow-none): A pointer to a #gint to be filled in, or %NULL.
226  *
227  * Obtains values that are needed to calculate blue pixel values in TrueColor
228  * and DirectColor.  The "mask" is the significant bits within the pixel.
229  * The "shift" is the number of bits left we must shift a primary for it
230  * to be in position (according to the "mask").  Finally, "precision" refers
231  * to how much precision the pixel value contains for a particular primary.
232  *
233  * Since: 2.22
234  */
235 void
gdk_visual_get_blue_pixel_details(GdkVisual * visual,guint32 * mask,gint * shift,gint * precision)236 gdk_visual_get_blue_pixel_details (GdkVisual *visual,
237                                    guint32   *mask,
238                                    gint      *shift,
239                                    gint      *precision)
240 {
241   g_return_if_fail (GDK_IS_VISUAL (visual));
242 
243   if (mask)
244     *mask = visual->blue_mask;
245 
246   if (shift)
247     *shift = visual->blue_shift;
248 
249   if (precision)
250     *precision = visual->blue_prec;
251 }
252 
253 #define __GDK_VISUAL_C__
254 #include "gdkaliasdef.c"
255