1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gdkpixbuf.Pixdata; 26 27 private import gdkpixbuf.Pixbuf; 28 private import glib.ErrorG; 29 private import glib.GException; 30 private import glib.Str; 31 private import glib.StringG; 32 private import gtkc.gdkpixbuf; 33 public import gtkc.gdkpixbuftypes; 34 35 36 /** 37 * A #GdkPixdata contains pixbuf information in a form suitable for 38 * serialization and streaming. 39 */ 40 public class Pixdata 41 { 42 /** the main Gtk struct */ 43 protected GdkPixdata* gdkPixdata; 44 45 /** Get the main Gtk struct */ 46 public GdkPixdata* getPixdataStruct() 47 { 48 return gdkPixdata; 49 } 50 51 /** the main Gtk struct as a void* */ 52 protected void* getStruct() 53 { 54 return cast(void*)gdkPixdata; 55 } 56 57 /** 58 * Sets our main struct and passes it to the parent class. 59 */ 60 public this (GdkPixdata* gdkPixdata) 61 { 62 this.gdkPixdata = gdkPixdata; 63 } 64 65 /** 66 */ 67 68 /** 69 * Deserializes (reconstruct) a #GdkPixdata structure from a byte stream. 70 * The byte stream consists of a straightforward writeout of the 71 * #GdkPixdata fields in network byte order, plus the @pixel_data 72 * bytes the structure points to. 73 * The @pixdata contents are reconstructed byte by byte and are checked 74 * for validity. This function may fail with %GDK_PIXBUF_ERROR_CORRUPT_IMAGE 75 * or %GDK_PIXBUF_ERROR_UNKNOWN_TYPE. 76 * 77 * Deprecated: Use #GResource instead. 78 * 79 * Params: 80 * streamLength = length of the stream used for deserialization. 81 * stream = stream of bytes containing a 82 * serialized #GdkPixdata structure. 83 * 84 * Return: Upon successful deserialization %TRUE is returned, 85 * %FALSE otherwise. 86 * 87 * Throws: GException on failure. 88 */ 89 public bool deserialize(ubyte[] stream) 90 { 91 GError* err = null; 92 93 auto p = gdk_pixdata_deserialize(gdkPixdata, cast(uint)stream.length, stream.ptr, &err) != 0; 94 95 if (err !is null) 96 { 97 throw new GException( new ErrorG(err) ); 98 } 99 100 return p; 101 } 102 103 /** 104 * Converts a #GdkPixbuf to a #GdkPixdata. If @use_rle is %TRUE, the 105 * pixel data is run-length encoded into newly-allocated memory and a 106 * pointer to that memory is returned. 107 * 108 * Deprecated: Use #GResource instead. 109 * 110 * Params: 111 * pixbuf = the data to fill @pixdata with. 112 * useRle = whether to use run-length encoding for the pixel data. 113 * 114 * Return: If @use_rle is %TRUE, a pointer to the 115 * newly-allocated memory for the run-length encoded pixel data, 116 * otherwise %NULL. 117 */ 118 public void* fromPixbuf(Pixbuf pixbuf, bool useRle) 119 { 120 return gdk_pixdata_from_pixbuf(gdkPixdata, (pixbuf is null) ? null : pixbuf.getPixbufStruct(), useRle); 121 } 122 123 /** 124 * Serializes a #GdkPixdata structure into a byte stream. 125 * The byte stream consists of a straightforward writeout of the 126 * #GdkPixdata fields in network byte order, plus the @pixel_data 127 * bytes the structure points to. 128 * 129 * Deprecated: Use #GResource instead. 130 * 131 * Params: 132 * streamLengthP = location to store the resulting stream length in. 133 * 134 * Return: A 135 * newly-allocated string containing the serialized #GdkPixdata 136 * structure. 137 */ 138 public ubyte[] serialize() 139 { 140 uint streamLengthP; 141 142 auto p = gdk_pixdata_serialize(gdkPixdata, &streamLengthP); 143 144 return p[0 .. streamLengthP]; 145 } 146 147 /** 148 * Generates C source code suitable for compiling images directly 149 * into programs. 150 * 151 * gdk-pixbuf ships with a program called 152 * [gdk-pixbuf-csource][gdk-pixbuf-csource], which offers a command 153 * line interface to this function. 154 * 155 * Deprecated: Use #GResource instead. 156 * 157 * Params: 158 * name = used for naming generated data structures or macros. 159 * dumpType = a #GdkPixdataDumpType determining the kind of C 160 * source to be generated. 161 * 162 * Return: a newly-allocated string containing the C source form 163 * of @pixdata. 164 */ 165 public StringG toCsource(string name, GdkPixdataDumpType dumpType) 166 { 167 auto p = gdk_pixdata_to_csource(gdkPixdata, Str.toStringz(name), dumpType); 168 169 if(p is null) 170 { 171 return null; 172 } 173 174 return new StringG(cast(GString*) p); 175 } 176 }