You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

171 lines
6.4 KiB

  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, write to the
  16. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  17. * Boston, MA 02111-1307, USA.
  18. */
  19. #ifndef __GDK_PIXDATA_H__
  20. #define __GDK_PIXDATA_H__
  21. #include <gdk-pixbuf/gdk-pixbuf.h>
  22. G_BEGIN_DECLS
  23. /**
  24. * GDK_PIXBUF_MAGIC_NUMBER:
  25. *
  26. * Magic number for #GdkPixdata structures.
  27. **/
  28. #define GDK_PIXBUF_MAGIC_NUMBER (0x47646b50) /* 'GdkP' */
  29. /**
  30. * GdkPixdataType:
  31. * @GDK_PIXDATA_COLOR_TYPE_RGB: each pixel has red, green and blue samples.
  32. * @GDK_PIXDATA_COLOR_TYPE_RGBA: each pixel has red, green and blue samples
  33. * and an alpha value.
  34. * @GDK_PIXDATA_COLOR_TYPE_MASK: mask for the colortype flags of the enum.
  35. * @GDK_PIXDATA_SAMPLE_WIDTH_8: each sample has 8 bits.
  36. * @GDK_PIXDATA_SAMPLE_WIDTH_MASK: mask for the sample width flags of the enum.
  37. * @GDK_PIXDATA_ENCODING_RAW: the pixel data is in raw form.
  38. * @GDK_PIXDATA_ENCODING_RLE: the pixel data is run-length encoded. Runs may
  39. * be up to 127 bytes long; their length is stored in a single byte
  40. * preceding the pixel data for the run. If a run is constant, its length
  41. * byte has the high bit set and the pixel data consists of a single pixel
  42. * which must be repeated.
  43. * @GDK_PIXDATA_ENCODING_MASK: mask for the encoding flags of the enum.
  44. *
  45. * An enumeration containing three sets of flags for a #GdkPixdata struct:
  46. * one for the used colorspace, one for the width of the samples and one
  47. * for the encoding of the pixel data.
  48. **/
  49. typedef enum
  50. {
  51. /* colorspace + alpha */
  52. GDK_PIXDATA_COLOR_TYPE_RGB = 0x01,
  53. GDK_PIXDATA_COLOR_TYPE_RGBA = 0x02,
  54. GDK_PIXDATA_COLOR_TYPE_MASK = 0xff,
  55. /* width, support 8bits only currently */
  56. GDK_PIXDATA_SAMPLE_WIDTH_8 = 0x01 << 16,
  57. GDK_PIXDATA_SAMPLE_WIDTH_MASK = 0x0f << 16,
  58. /* encoding */
  59. GDK_PIXDATA_ENCODING_RAW = 0x01 << 24,
  60. GDK_PIXDATA_ENCODING_RLE = 0x02 << 24,
  61. GDK_PIXDATA_ENCODING_MASK = 0x0f << 24
  62. } GdkPixdataType;
  63. /**
  64. * GdkPixdata:
  65. * @magic: magic number. A valid #GdkPixdata structure must have
  66. * #GDK_PIXBUF_MAGIC_NUMBER here.
  67. * @length: less than 1 to disable length checks, otherwise
  68. * #GDK_PIXDATA_HEADER_LENGTH + length of @pixel_data.
  69. * @pixdata_type: information about colorspace, sample width and
  70. * encoding, in a #GdkPixdataType.
  71. * @rowstride: Distance in bytes between rows.
  72. * @width: Width of the image in pixels.
  73. * @height: Height of the image in pixels.
  74. * @pixel_data: @width x @height pixels, encoded according to @pixdata_type
  75. * and @rowstride.
  76. *
  77. * A #GdkPixdata contains pixbuf information in a form suitable for
  78. * serialization and streaming.
  79. **/
  80. typedef struct _GdkPixdata GdkPixdata;
  81. struct _GdkPixdata
  82. {
  83. guint32 magic; /* GDK_PIXBUF_MAGIC_NUMBER */
  84. gint32 length; /* <1 to disable length checks, otherwise:
  85. * GDK_PIXDATA_HEADER_LENGTH + pixel_data length
  86. */
  87. guint32 pixdata_type; /* GdkPixdataType */
  88. guint32 rowstride;
  89. guint32 width;
  90. guint32 height;
  91. guint8 *pixel_data;
  92. };
  93. /**
  94. * GDK_PIXDATA_HEADER_LENGTH:
  95. *
  96. * The length of a #GdkPixdata structure without the @pixel_data pointer.
  97. **/
  98. #define GDK_PIXDATA_HEADER_LENGTH (4 + 4 + 4 + 4 + 4 + 4)
  99. /* the returned stream is plain htonl of GdkPixdata members + pixel_data */
  100. guint8* gdk_pixdata_serialize (const GdkPixdata *pixdata,
  101. guint *stream_length_p);
  102. gboolean gdk_pixdata_deserialize (GdkPixdata *pixdata,
  103. guint stream_length,
  104. const guint8 *stream,
  105. GError **error);
  106. gpointer gdk_pixdata_from_pixbuf (GdkPixdata *pixdata,
  107. const GdkPixbuf *pixbuf,
  108. gboolean use_rle);
  109. GdkPixbuf* gdk_pixbuf_from_pixdata (const GdkPixdata *pixdata,
  110. gboolean copy_pixels,
  111. GError **error);
  112. /**
  113. * GdkPixdataDumpType:
  114. * @GDK_PIXDATA_DUMP_PIXDATA_STREAM: Generate pixbuf data stream (a single
  115. * string containing a serialized #GdkPixdata structure in network byte
  116. * order).
  117. * @GDK_PIXDATA_DUMP_PIXDATA_STRUCT: Generate #GdkPixdata structure (needs
  118. * the #GdkPixdata structure definition from gdk-pixdata.h).
  119. * @GDK_PIXDATA_DUMP_MACROS: Generate <function>*_ROWSTRIDE</function>,
  120. * <function>*_WIDTH</function>, <function>*_HEIGHT</function>,
  121. * <function>*_BYTES_PER_PIXEL</function> and
  122. * <function>*_RLE_PIXEL_DATA</function> or <function>*_PIXEL_DATA</function>
  123. * macro definitions for the image.
  124. * @GDK_PIXDATA_DUMP_GTYPES: Generate GLib data types instead of
  125. * standard C data types.
  126. * @GDK_PIXDATA_DUMP_CTYPES: Generate standard C data types instead of
  127. * GLib data types.
  128. * @GDK_PIXDATA_DUMP_STATIC: Generate static symbols.
  129. * @GDK_PIXDATA_DUMP_CONST: Generate const symbols.
  130. * @GDK_PIXDATA_DUMP_RLE_DECODER: Provide a <function>*_RUN_LENGTH_DECODE(image_buf, rle_data, size, bpp)</function>
  131. * macro definition to decode run-length encoded image data.
  132. *
  133. * An enumeration which is used by gdk_pixdata_to_csource() to
  134. * determine the form of C source to be generated. The three values
  135. * @GDK_PIXDATA_DUMP_PIXDATA_STREAM, @GDK_PIXDATA_DUMP_PIXDATA_STRUCT
  136. * and @GDK_PIXDATA_DUMP_MACROS are mutually exclusive, as are
  137. * @GDK_PIXBUF_DUMP_GTYPES and @GDK_PIXBUF_DUMP_CTYPES. The remaining
  138. * elements are optional flags that can be freely added.
  139. **/
  140. typedef enum
  141. {
  142. /* type of source to save */
  143. GDK_PIXDATA_DUMP_PIXDATA_STREAM = 0,
  144. GDK_PIXDATA_DUMP_PIXDATA_STRUCT = 1,
  145. GDK_PIXDATA_DUMP_MACROS = 2,
  146. /* type of variables to use */
  147. GDK_PIXDATA_DUMP_GTYPES = 0,
  148. GDK_PIXDATA_DUMP_CTYPES = 1 << 8,
  149. GDK_PIXDATA_DUMP_STATIC = 1 << 9,
  150. GDK_PIXDATA_DUMP_CONST = 1 << 10,
  151. /* save RLE decoder macro? */
  152. GDK_PIXDATA_DUMP_RLE_DECODER = 1 << 16
  153. } GdkPixdataDumpType;
  154. GString* gdk_pixdata_to_csource (GdkPixdata *pixdata,
  155. const gchar *name,
  156. GdkPixdataDumpType dump_type);
  157. G_END_DECLS
  158. #endif /* __GDK_PIXDATA_H__ */