1 /* GdkPixbuf library - GdkPixdata - functions for inlined pixbuf handling
2 * Copyright (C) 1999, 2001 Tim Janik
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.
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.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
19 #ifndef __GDK_PIXDATA_H__
20 #define __GDK_PIXDATA_H__
22 #include <gdk-pixbuf/gdk-pixbuf.h>
27 * GDK_PIXBUF_MAGIC_NUMBER:
29 * Magic number for #GdkPixdata structures.
31 #define GDK_PIXBUF_MAGIC_NUMBER (0x47646b50) /* 'GdkP' */
35 * @GDK_PIXDATA_COLOR_TYPE_RGB: each pixel has red, green and blue samples.
36 * @GDK_PIXDATA_COLOR_TYPE_RGBA: each pixel has red, green and blue samples
38 * @GDK_PIXDATA_COLOR_TYPE_MASK: mask for the colortype flags of the enum.
39 * @GDK_PIXDATA_SAMPLE_WIDTH_8: each sample has 8 bits.
40 * @GDK_PIXDATA_SAMPLE_WIDTH_MASK: mask for the sample width flags of the enum.
41 * @GDK_PIXDATA_ENCODING_RAW: the pixel data is in raw form.
42 * @GDK_PIXDATA_ENCODING_RLE: the pixel data is run-length encoded. Runs may
43 * be up to 127 bytes long; their length is stored in a single byte
44 * preceding the pixel data for the run. If a run is constant, its length
45 * byte has the high bit set and the pixel data consists of a single pixel
46 * which must be repeated.
47 * @GDK_PIXDATA_ENCODING_MASK: mask for the encoding flags of the enum.
49 * An enumeration containing three sets of flags for a #GdkPixdata struct:
50 * one for the used colorspace, one for the width of the samples and one
51 * for the encoding of the pixel data.
55 /* colorspace + alpha */
56 GDK_PIXDATA_COLOR_TYPE_RGB = 0x01,
57 GDK_PIXDATA_COLOR_TYPE_RGBA = 0x02,
58 GDK_PIXDATA_COLOR_TYPE_MASK = 0xff,
59 /* width, support 8bits only currently */
60 GDK_PIXDATA_SAMPLE_WIDTH_8 = 0x01 << 16,
61 GDK_PIXDATA_SAMPLE_WIDTH_MASK = 0x0f << 16,
63 GDK_PIXDATA_ENCODING_RAW = 0x01 << 24,
64 GDK_PIXDATA_ENCODING_RLE = 0x02 << 24,
65 GDK_PIXDATA_ENCODING_MASK = 0x0f << 24
70 * @magic: magic number. A valid #GdkPixdata structure must have
71 * #GDK_PIXBUF_MAGIC_NUMBER here.
72 * @length: less than 1 to disable length checks, otherwise
73 * #GDK_PIXDATA_HEADER_LENGTH + length of @pixel_data.
74 * @pixdata_type: information about colorspace, sample width and
75 * encoding, in a #GdkPixdataType.
76 * @rowstride: Distance in bytes between rows.
77 * @width: Width of the image in pixels.
78 * @height: Height of the image in pixels.
79 * @pixel_data: @width x @height pixels, encoded according to @pixdata_type
82 * A #GdkPixdata contains pixbuf information in a form suitable for
83 * serialization and streaming.
85 typedef struct _GdkPixdata GdkPixdata;
88 guint32 magic; /* GDK_PIXBUF_MAGIC_NUMBER */
89 gint32 length; /* <1 to disable length checks, otherwise:
90 * GDK_PIXDATA_HEADER_LENGTH + pixel_data length
92 guint32 pixdata_type; /* GdkPixdataType */
100 * GDK_PIXDATA_HEADER_LENGTH:
102 * The length of a #GdkPixdata structure without the @pixel_data pointer.
104 #define GDK_PIXDATA_HEADER_LENGTH (4 + 4 + 4 + 4 + 4 + 4)
106 /* the returned stream is plain htonl of GdkPixdata members + pixel_data */
107 guint8* gdk_pixdata_serialize (const GdkPixdata *pixdata,
108 guint *stream_length_p);
109 gboolean gdk_pixdata_deserialize (GdkPixdata *pixdata,
111 const guint8 *stream,
113 gpointer gdk_pixdata_from_pixbuf (GdkPixdata *pixdata,
114 const GdkPixbuf *pixbuf,
116 GdkPixbuf* gdk_pixbuf_from_pixdata (const GdkPixdata *pixdata,
117 gboolean copy_pixels,
120 * GdkPixdataDumpType:
121 * @GDK_PIXDATA_DUMP_PIXDATA_STREAM: Generate pixbuf data stream (a single
122 * string containing a serialized #GdkPixdata structure in network byte
124 * @GDK_PIXDATA_DUMP_PIXDATA_STRUCT: Generate #GdkPixdata structure (needs
125 * the #GdkPixdata structure definition from gdk-pixdata.h).
126 * @GDK_PIXDATA_DUMP_MACROS: Generate <function>*_ROWSTRIDE</function>,
127 * <function>*_WIDTH</function>, <function>*_HEIGHT</function>,
128 * <function>*_BYTES_PER_PIXEL</function> and
129 * <function>*_RLE_PIXEL_DATA</function> or <function>*_PIXEL_DATA</function>
130 * macro definitions for the image.
131 * @GDK_PIXDATA_DUMP_GTYPES: Generate GLib data types instead of
132 * standard C data types.
133 * @GDK_PIXDATA_DUMP_CTYPES: Generate standard C data types instead of
135 * @GDK_PIXDATA_DUMP_STATIC: Generate static symbols.
136 * @GDK_PIXDATA_DUMP_CONST: Generate const symbols.
137 * @GDK_PIXDATA_DUMP_RLE_DECODER: Provide a <function>*_RUN_LENGTH_DECODE(image_buf, rle_data, size, bpp)</function>
138 * macro definition to decode run-length encoded image data.
140 * An enumeration which is used by gdk_pixdata_to_csource() to
141 * determine the form of C source to be generated. The three values
142 * @GDK_PIXDATA_DUMP_PIXDATA_STREAM, @GDK_PIXDATA_DUMP_PIXDATA_STRUCT
143 * and @GDK_PIXDATA_DUMP_MACROS are mutually exclusive, as are
144 * @GDK_PIXBUF_DUMP_GTYPES and @GDK_PIXBUF_DUMP_CTYPES. The remaining
145 * elements are optional flags that can be freely added.
149 /* type of source to save */
150 GDK_PIXDATA_DUMP_PIXDATA_STREAM = 0,
151 GDK_PIXDATA_DUMP_PIXDATA_STRUCT = 1,
152 GDK_PIXDATA_DUMP_MACROS = 2,
153 /* type of variables to use */
154 GDK_PIXDATA_DUMP_GTYPES = 0,
155 GDK_PIXDATA_DUMP_CTYPES = 1 << 8,
156 GDK_PIXDATA_DUMP_STATIC = 1 << 9,
157 GDK_PIXDATA_DUMP_CONST = 1 << 10,
158 /* save RLE decoder macro? */
159 GDK_PIXDATA_DUMP_RLE_DECODER = 1 << 16
160 } GdkPixdataDumpType;
163 GString* gdk_pixdata_to_csource (GdkPixdata *pixdata,
165 GdkPixdataDumpType dump_type);
170 #endif /* __GDK_PIXDATA_H__ */