Inline data

Name

Inline data -- Functions for inlined pixbuf handling.

Synopsis


#include <gdk-pixbuf/gdk-pixbuf.h>


struct      GdkPixdata;
enum        GdkPixdataType;
enum        GdkPixdataDumpType;
#define     GDK_PIXBUF_MAGIC_NUMBER
#define     GDK_PIXDATA_HEADER_LENGTH
gpointer    gdk_pixdata_from_pixbuf         (GdkPixdata *pixdata,
                                             const GdkPixbuf *pixbuf,
                                             gboolean use_rle);
GdkPixbuf*  gdk_pixbuf_from_pixdata         (const GdkPixdata *pixdata,
                                             gboolean copy_pixels,
                                             GError **error);
guint8*     gdk_pixdata_serialize           (const GdkPixdata *pixdata,
                                             guint *stream_length_p);
gboolean    gdk_pixdata_deserialize         (GdkPixdata *pixdata,
                                             guint stream_length,
                                             const guint8 *stream,
                                             GError **error);
GString*    gdk_pixdata_to_csource          (GdkPixdata *pixdata,
                                             const gchar *name,
                                             GdkPixdataDumpType dump_type);

Description

Details

struct GdkPixdata

struct GdkPixdata
{
  guint32 magic;        /* GDK_PIXBUF_MAGIC_NUMBER */
  gint32  length;       /* <1 to disable length checks, otherwise:
			 * GDK_PIXDATA_HEADER_LENGTH + pixel_data length
			 */
  guint32 pixdata_type; /* GdkPixdataType */
  guint32 rowstride;    /* maybe 0 to indicate non-padded data */
  guint32 width;
  guint32 height;
  guint8 *pixel_data;
};

A GdkPixdata contains pixbuf information in a form suitable for serialization and streaming.


enum GdkPixdataType

typedef enum
{
  /* colorspace + alpha */
  GDK_PIXDATA_COLOR_TYPE_RGB    = 0x01,
  GDK_PIXDATA_COLOR_TYPE_RGBA   = 0x02,
  GDK_PIXDATA_COLOR_TYPE_MASK   = 0xff,
  /* width, support 8bits only currently */
  GDK_PIXDATA_SAMPLE_WIDTH_8    = 0x01 << 16,
  GDK_PIXDATA_SAMPLE_WIDTH_MASK = 0x0f << 16,
  /* encoding */
  GDK_PIXDATA_ENCODING_RAW      = 0x01 << 24,
  GDK_PIXDATA_ENCODING_RLE      = 0x02 << 24,
  GDK_PIXDATA_ENCODING_MASK     = 0x0f << 24
} GdkPixdataType;

An enumeration containing three sets of flags for a GdkPixdata struct: one for the used colorspace, one for the width of the samples and one for the encoding of the pixel data.


enum GdkPixdataDumpType

typedef enum
{
  /* type of source to save */
  GDK_PIXDATA_DUMP_PIXDATA_STREAM	= 0,
  GDK_PIXDATA_DUMP_PIXDATA_STRUCT	= 1,
  GDK_PIXDATA_DUMP_MACROS		= 2,
  /* type of variables to use */
  GDK_PIXDATA_DUMP_GTYPES		= 0,
  GDK_PIXDATA_DUMP_CTYPES		= 1 << 8,
  GDK_PIXDATA_DUMP_STATIC		= 1 << 9,
  GDK_PIXDATA_DUMP_CONST		= 1 << 10,
  /* save RLE decoder macro? */
  GDK_PIXDATA_DUMP_RLE_DECODER		= 1 << 16
} GdkPixdataDumpType;

An enumeration which is used by gdk_pixdata_to_csource() to determine the form of C source to be generated. The three values GDK_PIXDATA_DUMP_PIXDATA_STREAM, GDK_PIXDATA_DUMP_PIXDATA_STRUCT and GDK_PIXDATA_DUMP_MACROS are mutually exclusive, as are GDK_PIXBUF_DUMP_GTYPES and GDK_PIXBUF_DUMP_CTYPES. The remaining elements are optional flags that can be freely added.


GDK_PIXBUF_MAGIC_NUMBER

#define GDK_PIXBUF_MAGIC_NUMBER (0x47646b50)    /* 'GdkP' */

Magic number for GdkPixdata structures.


GDK_PIXDATA_HEADER_LENGTH

#define	GDK_PIXDATA_HEADER_LENGTH	(4 + 4 + 4 + 4 + 4 + 4)

The length of a GdkPixdata structure without the pixel_data pointer.


gdk_pixdata_from_pixbuf ()

gpointer    gdk_pixdata_from_pixbuf         (GdkPixdata *pixdata,
                                             const GdkPixbuf *pixbuf,
                                             gboolean use_rle);

Converts a GdkPixbuf to a GdkPixdata. If use_rle is TRUE, the pixel data is run-length encoded into newly-allocated memory and a pointer to that memory is returned.


gdk_pixbuf_from_pixdata ()

GdkPixbuf*  gdk_pixbuf_from_pixdata         (const GdkPixdata *pixdata,
                                             gboolean copy_pixels,
                                             GError **error);

Converts a GdkPixdata to a GdkPixbuf. If copy_pixels is TRUE or if the pixel data is run-length-encoded, the pixel data is copied into newly-allocated memory; otherwise it is reused.


gdk_pixdata_serialize ()

guint8*     gdk_pixdata_serialize           (const GdkPixdata *pixdata,
                                             guint *stream_length_p);

Serializes a GdkPixdata structure into a byte stream. The byte stream consists of a straightforward writeout of the GdkPixdata fields in network byte order, plus the pixel_data bytes the structure points to.


gdk_pixdata_deserialize ()

gboolean    gdk_pixdata_deserialize         (GdkPixdata *pixdata,
                                             guint stream_length,
                                             const guint8 *stream,
                                             GError **error);

Deserializes (reconstruct) a GdkPixdata structure from a byte stream. The byte stream consists of a straightforward writeout of the GdkPixdata fields in network byte order, plus the pixel_data bytes the structure points to. The pixdata contents are reconstructed byte by byte and are checked for validity. This function may fail with GDK_PIXBUF_CORRUPT_IMAGE or GDK_PIXBUF_ERROR_UNKNOWN_TYPE.


gdk_pixdata_to_csource ()

GString*    gdk_pixdata_to_csource          (GdkPixdata *pixdata,
                                             const gchar *name,
                                             GdkPixdataDumpType dump_type);

Generates C source code suitable for compiling images directly into programs.

GTK+ ships with a program called gdk-pixbuf-csource which offers a cmdline interface to this functions.