1 /* GdkPixbuf library - GdkPixdata - functions for inlined pixbuf handling
2  * Copyright (C) 1999, 2001 Tim Janik
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
16  */
17 #ifndef __GDK_PIXDATA_H__
18 #define __GDK_PIXDATA_H__
19 
20 #ifndef GDK_PIXBUF_DISABLE_DEPRECATED
21 #include        <gdk-pixbuf/gdk-pixbuf.h>
22 
23 G_BEGIN_DECLS
24 
25 /**
26  * GDK_PIXBUF_MAGIC_NUMBER:
27  *
28  * Magic number for #GdkPixdata structures.
29  **/
30 #define GDK_PIXBUF_MAGIC_NUMBER (0x47646b50)    /* 'GdkP' */
31 
32 /**
33  * GdkPixdataType:
34  * @GDK_PIXDATA_COLOR_TYPE_RGB:  each pixel has red, green and blue samples.
35  * @GDK_PIXDATA_COLOR_TYPE_RGBA: each pixel has red, green and blue samples
36  *    and an alpha value.
37  * @GDK_PIXDATA_COLOR_TYPE_MASK: mask for the colortype flags of the enum.
38  * @GDK_PIXDATA_SAMPLE_WIDTH_8: each sample has 8 bits.
39  * @GDK_PIXDATA_SAMPLE_WIDTH_MASK: mask for the sample width flags of the enum.
40  * @GDK_PIXDATA_ENCODING_RAW: the pixel data is in raw form.
41  * @GDK_PIXDATA_ENCODING_RLE: the pixel data is run-length encoded. Runs may
42  *    be up to 127 bytes long; their length is stored in a single byte
43  *    preceding the pixel data for the run. If a run is constant, its length
44  *    byte has the high bit set and the pixel data consists of a single pixel
45  *    which must be repeated.
46  * @GDK_PIXDATA_ENCODING_MASK: mask for the encoding flags of the enum.
47  *
48  * An enumeration containing three sets of flags for a #GdkPixdata struct:
49  * one for the used colorspace, one for the width of the samples and one
50  * for the encoding of the pixel data.
51  **/
52 typedef enum
53 {
54   /* colorspace + alpha */
55   GDK_PIXDATA_COLOR_TYPE_RGB    = 0x01,
56   GDK_PIXDATA_COLOR_TYPE_RGBA   = 0x02,
57   GDK_PIXDATA_COLOR_TYPE_MASK   = 0xff,
58   /* width, support 8bits only currently */
59   GDK_PIXDATA_SAMPLE_WIDTH_8    = 0x01 << 16,
60   GDK_PIXDATA_SAMPLE_WIDTH_MASK = 0x0f << 16,
61   /* encoding */
62   GDK_PIXDATA_ENCODING_RAW      = 0x01 << 24,
63   GDK_PIXDATA_ENCODING_RLE      = 0x02 << 24,
64   GDK_PIXDATA_ENCODING_MASK     = 0x0f << 24
65 } GdkPixdataType;
66 
67 /**
68  * GdkPixdata:
69  * @magic: magic number. A valid #GdkPixdata structure must have
70  *    #GDK_PIXBUF_MAGIC_NUMBER here.
71  * @length: less than 1 to disable length checks, otherwise
72  *    #GDK_PIXDATA_HEADER_LENGTH + length of @pixel_data.
73  * @pixdata_type: information about colorspace, sample width and
74  *    encoding, in a #GdkPixdataType.
75  * @rowstride: Distance in bytes between rows.
76  * @width: Width of the image in pixels.
77  * @height: Height of the image in pixels.
78  * @pixel_data: (array) (element-type guint8): @width x @height pixels, encoded according to @pixdata_type
79  *   and @rowstride.
80  *
81  * A #GdkPixdata contains pixbuf information in a form suitable for
82  * serialization and streaming.
83  **/
84 typedef struct _GdkPixdata GdkPixdata;
85 struct _GdkPixdata
86 {
87   guint32 magic;        /* GDK_PIXBUF_MAGIC_NUMBER */
88   gint32  length;       /* <1 to disable length checks, otherwise:
89 			 * GDK_PIXDATA_HEADER_LENGTH + pixel_data length
90 			 */
91   guint32 pixdata_type; /* GdkPixdataType */
92   guint32 rowstride;
93   guint32 width;
94   guint32 height;
95   guint8 *pixel_data;
96 };
97 
98 /**
99  * GDK_PIXDATA_HEADER_LENGTH:
100  *
101  * The length of a #GdkPixdata structure without the @pixel_data pointer.
102  **/
103 #define	GDK_PIXDATA_HEADER_LENGTH	(4 + 4 + 4 + 4 + 4 + 4)
104 
105 /* the returned stream is plain htonl of GdkPixdata members + pixel_data */
106 GDK_PIXBUF_DEPRECATED_IN_2_32
107 guint8*		gdk_pixdata_serialize	(const GdkPixdata	*pixdata,
108 					 guint			*stream_length_p);
109 GDK_PIXBUF_DEPRECATED_IN_2_32
110 gboolean	gdk_pixdata_deserialize	(GdkPixdata		*pixdata,
111 					 guint			 stream_length,
112 					 const guint8		*stream,
113 					 GError		       **error);
114 GDK_PIXBUF_DEPRECATED_IN_2_32
115 gpointer	gdk_pixdata_from_pixbuf	(GdkPixdata		*pixdata,
116 					 const GdkPixbuf	*pixbuf,
117 					 gboolean		 use_rle);
118 GDK_PIXBUF_DEPRECATED_IN_2_32
119 GdkPixbuf*	gdk_pixbuf_from_pixdata	(const GdkPixdata	*pixdata,
120 					 gboolean		 copy_pixels,
121 					 GError		       **error);
122 /**
123  * GdkPixdataDumpType:
124  * @GDK_PIXDATA_DUMP_PIXDATA_STREAM: Generate pixbuf data stream (a single
125  *    string containing a serialized #GdkPixdata structure in network byte
126  *    order).
127  * @GDK_PIXDATA_DUMP_PIXDATA_STRUCT: Generate #GdkPixdata structure (needs
128  *    the #GdkPixdata structure definition from gdk-pixdata.h).
129  * @GDK_PIXDATA_DUMP_MACROS: Generate <function>*_ROWSTRIDE</function>,
130  *    <function>*_WIDTH</function>, <function>*_HEIGHT</function>,
131  *    <function>*_BYTES_PER_PIXEL</function> and
132  *    <function>*_RLE_PIXEL_DATA</function> or <function>*_PIXEL_DATA</function>
133  *    macro definitions for the image.
134  * @GDK_PIXDATA_DUMP_GTYPES: Generate GLib data types instead of
135  *    standard C data types.
136  * @GDK_PIXDATA_DUMP_CTYPES: Generate standard C data types instead of
137  *    GLib data types.
138  * @GDK_PIXDATA_DUMP_STATIC: Generate static symbols.
139  * @GDK_PIXDATA_DUMP_CONST: Generate const symbols.
140  * @GDK_PIXDATA_DUMP_RLE_DECODER: Provide a <function>*_RUN_LENGTH_DECODE(image_buf, rle_data, size, bpp)</function>
141  *    macro definition  to  decode  run-length encoded image data.
142  *
143  * An enumeration which is used by gdk_pixdata_to_csource() to
144  * determine the form of C source to be generated. The three values
145  * @GDK_PIXDATA_DUMP_PIXDATA_STREAM, @GDK_PIXDATA_DUMP_PIXDATA_STRUCT
146  * and @GDK_PIXDATA_DUMP_MACROS are mutually exclusive, as are
147  * @GDK_PIXBUF_DUMP_GTYPES and @GDK_PIXBUF_DUMP_CTYPES. The remaining
148  * elements are optional flags that can be freely added.
149  **/
150 typedef enum
151 {
152   /* type of source to save */
153   GDK_PIXDATA_DUMP_PIXDATA_STREAM	= 0,
154   GDK_PIXDATA_DUMP_PIXDATA_STRUCT	= 1,
155   GDK_PIXDATA_DUMP_MACROS		= 2,
156   /* type of variables to use */
157   GDK_PIXDATA_DUMP_GTYPES		= 0,
158   GDK_PIXDATA_DUMP_CTYPES		= 1 << 8,
159   GDK_PIXDATA_DUMP_STATIC		= 1 << 9,
160   GDK_PIXDATA_DUMP_CONST		= 1 << 10,
161   /* save RLE decoder macro? */
162   GDK_PIXDATA_DUMP_RLE_DECODER		= 1 << 16
163 } GdkPixdataDumpType;
164 
165 
166 GDK_PIXBUF_DEPRECATED_IN_2_32
167 GString*	gdk_pixdata_to_csource	(GdkPixdata		*pixdata,
168 					 const gchar		*name,
169 					 GdkPixdataDumpType	 dump_type);
170 
171 
172 G_END_DECLS
173 
174 #endif /* GDK_PIXBUF_DISABLE_DEPRECATED */
175 
176 #endif /* __GDK_PIXDATA_H__ */
177