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 * Conversion parameters: 26 * inFile = gdk-pixbuf-Inline-data.html 27 * outPack = gdkpixbuf 28 * outFile = Pixdata 29 * strct = GdkPixdata 30 * realStrct= 31 * ctorStrct= 32 * clss = Pixdata 33 * interf = 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - gdk_pixdata_ 41 * omit structs: 42 * omit prefixes: 43 * omit code: 44 * omit signals: 45 * imports: 46 * - gdk.Pixbuf 47 * - glib.ErrorG 48 * - glib.GException 49 * - glib.StringG 50 * - glib.Str 51 * structWrap: 52 * - GString* -> StringG 53 * - GdkPixbuf* -> Pixbuf 54 * module aliases: 55 * local aliases: 56 * overrides: 57 */ 58 59 module gdkpixbuf.Pixdata; 60 61 public import gtkc.gdkpixbuftypes; 62 63 private import gtkc.gdkpixbuf; 64 private import glib.ConstructionException; 65 private import gobject.ObjectG; 66 67 68 private import gdk.Pixbuf; 69 private import glib.ErrorG; 70 private import glib.GException; 71 private import glib.StringG; 72 private import glib.Str; 73 74 75 76 77 /** 78 * Using GdkPixdata, images can be compiled into an application, 79 * making it unnecessary to refer to external image files at runtime. 80 * GdkPixBuf includes a utility named gdk-pixbuf-csource, which 81 * can be used to convert image files into GdkPixdata structures suitable 82 * for inclusion in C sources. To convert the GdkPixdata structures back 83 * into GdkPixbufs, use gdk_pixbuf_from_pixdata. 84 */ 85 public class Pixdata 86 { 87 88 /** the main Gtk struct */ 89 protected GdkPixdata* gdkPixdata; 90 91 92 public GdkPixdata* getPixdataStruct() 93 { 94 return gdkPixdata; 95 } 96 97 98 /** the main Gtk struct as a void* */ 99 protected void* getStruct() 100 { 101 return cast(void*)gdkPixdata; 102 } 103 104 /** 105 * Sets our main struct and passes it to the parent class 106 */ 107 public this (GdkPixdata* gdkPixdata) 108 { 109 this.gdkPixdata = gdkPixdata; 110 } 111 112 /** 113 */ 114 115 /** 116 * Converts a GdkPixbuf to a GdkPixdata. If use_rle is TRUE, the 117 * pixel data is run-length encoded into newly-allocated memory and a 118 * pointer to that memory is returned. 119 * Params: 120 * pixbuf = the data to fill pixdata with. 121 * useRle = whether to use run-length encoding for the pixel data. 122 * Returns: If ure_rle is TRUE, a pointer to the newly-allocated memory for the run-length encoded pixel data, otherwise NULL. 123 */ 124 public void* fromPixbuf(Pixbuf pixbuf, int useRle) 125 { 126 // gpointer gdk_pixdata_from_pixbuf (GdkPixdata *pixdata, const GdkPixbuf *pixbuf, gboolean use_rle); 127 return gdk_pixdata_from_pixbuf(gdkPixdata, (pixbuf is null) ? null : pixbuf.getPixbufStruct(), useRle); 128 } 129 130 /** 131 * Converts a GdkPixdata to a GdkPixbuf. If copy_pixels is TRUE or 132 * if the pixel data is run-length-encoded, the pixel data is copied into 133 * newly-allocated memory; otherwise it is reused. 134 * Params: 135 * copyPixels = whether to copy raw pixel data; run-length encoded 136 * pixel data is always copied. 137 * Returns: a new GdkPixbuf. [transfer full] 138 * Throws: GException on failure. 139 */ 140 public Pixbuf gdkPixbufFromPixdata(int copyPixels) 141 { 142 // GdkPixbuf * gdk_pixbuf_from_pixdata (const GdkPixdata *pixdata, gboolean copy_pixels, GError **error); 143 GError* err = null; 144 145 auto p = gdk_pixbuf_from_pixdata(gdkPixdata, copyPixels, &err); 146 147 if (err !is null) 148 { 149 throw new GException( new ErrorG(err) ); 150 } 151 152 153 if(p is null) 154 { 155 return null; 156 } 157 158 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p); 159 } 160 161 /** 162 * Serializes a GdkPixdata structure into a byte stream. 163 * The byte stream consists of a straightforward writeout of the 164 * GdkPixdata fields in network byte order, plus the pixel_data 165 * bytes the structure points to. 166 * Returns: A newly-allocated string containing the serialized GdkPixdata structure. [array length=stream_length_p][transfer full] 167 */ 168 public ubyte[] serialize() 169 { 170 // guint8 * gdk_pixdata_serialize (const GdkPixdata *pixdata, guint *stream_length_p); 171 uint streamLengthP; 172 auto p = gdk_pixdata_serialize(gdkPixdata, &streamLengthP); 173 174 if(p is null) 175 { 176 return null; 177 } 178 179 return p[0 .. streamLengthP]; 180 } 181 182 /** 183 * Deserializes (reconstruct) a GdkPixdata structure from a byte stream. 184 * The byte stream consists of a straightforward writeout of the 185 * GdkPixdata fields in network byte order, plus the pixel_data 186 * bytes the structure points to. 187 * The pixdata contents are reconstructed byte by byte and are checked 188 * for validity. This function may fail with GDK_PIXBUF_ERROR_CORRUPT_IMAGE 189 * or GDK_PIXBUF_ERROR_UNKNOWN_TYPE. 190 * Params: 191 * stream = stream of bytes containing a 192 * serialized GdkPixdata structure. [array length=stream_length] 193 * Returns: Upon successful deserialization TRUE is returned, FALSE otherwise. 194 * Throws: GException on failure. 195 */ 196 public int deserialize(ubyte[] stream) 197 { 198 // gboolean gdk_pixdata_deserialize (GdkPixdata *pixdata, guint stream_length, const guint8 *stream, GError **error); 199 GError* err = null; 200 201 auto p = gdk_pixdata_deserialize(gdkPixdata, cast(int) stream.length, stream.ptr, &err); 202 203 if (err !is null) 204 { 205 throw new GException( new ErrorG(err) ); 206 } 207 208 return p; 209 } 210 211 /** 212 * Generates C source code suitable for compiling images directly 213 * into programs. 214 * gdk-pixbuf ships with a program called gdk-pixbuf-csource 215 * which offers a command line interface to this function. 216 * Params: 217 * name = used for naming generated data structures or macros. 218 * dumpType = a GdkPixdataDumpType determining the kind of C 219 * source to be generated. 220 * Returns: a newly-allocated string containing the C source form of pixdata. 221 */ 222 public StringG toCsource(string name, GdkPixdataDumpType dumpType) 223 { 224 // GString * gdk_pixdata_to_csource (GdkPixdata *pixdata, const gchar *name, GdkPixdataDumpType dump_type); 225 auto p = gdk_pixdata_to_csource(gdkPixdata, Str.toStringz(name), dumpType); 226 227 if(p is null) 228 { 229 return null; 230 } 231 232 return ObjectG.getDObject!(StringG)(cast(GString*) p); 233 } 234 }