gdk-pixdata.h 6.5 KB

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