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 * Description 79 * Using GdkPixdata, images can be compiled into an application, 80 * making it unnecessary to refer to external image files at runtime. 81 * gdk-pixbuf; includes a utility named gdk-pixbuf-csource, which 82 * can be used to convert image files into GdkPixdata structures suitable 83 * for inclusion in C sources. To convert the GdkPixdata structures back 84 * into GdkPixbufs, use gdk_pixbuf_from_pixdata. 85 */ 86 public class Pixdata 87 { 88 89 /** the main Gtk struct */ 90 protected GdkPixdata* gdkPixdata; 91 92 93 public GdkPixdata* getPixdataStruct() 94 { 95 return gdkPixdata; 96 } 97 98 99 /** the main Gtk struct as a void* */ 100 protected void* getStruct() 101 { 102 return cast(void*)gdkPixdata; 103 } 104 105 /** 106 * Sets our main struct and passes it to the parent class 107 */ 108 public this (GdkPixdata* gdkPixdata) 109 { 110 this.gdkPixdata = gdkPixdata; 111 } 112 113 /** 114 */ 115 116 /** 117 * Converts a GdkPixbuf to a GdkPixdata. If use_rle is TRUE, the 118 * pixel data is run-length encoded into newly-allocated memory and a 119 * pointer to that memory is returned. 120 * Params: 121 * pixbuf = the data to fill pixdata with. 122 * useRle = whether to use run-length encoding for the pixel data. 123 * Returns: If ure_rle is TRUE, a pointer to the newly-allocated memory for the run-length encoded pixel data, otherwise NULL. 124 */ 125 public void* fromPixbuf(Pixbuf pixbuf, int useRle) 126 { 127 // gpointer gdk_pixdata_from_pixbuf (GdkPixdata *pixdata, const GdkPixbuf *pixbuf, gboolean use_rle); 128 return gdk_pixdata_from_pixbuf(gdkPixdata, (pixbuf is null) ? null : pixbuf.getPixbufStruct(), useRle); 129 } 130 131 /** 132 * Converts a GdkPixdata to a GdkPixbuf. If copy_pixels is TRUE or 133 * if the pixel data is run-length-encoded, the pixel data is copied into 134 * newly-allocated memory; otherwise it is reused. 135 * Params: 136 * copyPixels = whether to copy raw pixel data; run-length encoded 137 * pixel data is always copied. 138 * Returns: a new GdkPixbuf. 139 * Throws: GException on failure. 140 */ 141 public Pixbuf gdkPixbufFromPixdata(int copyPixels) 142 { 143 // GdkPixbuf * gdk_pixbuf_from_pixdata (const GdkPixdata *pixdata, gboolean copy_pixels, GError **error); 144 GError* err = null; 145 146 auto p = gdk_pixbuf_from_pixdata(gdkPixdata, copyPixels, &err); 147 148 if (err !is null) 149 { 150 throw new GException( new ErrorG(err) ); 151 } 152 153 154 if(p is null) 155 { 156 return null; 157 } 158 159 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p); 160 } 161 162 /** 163 * Serializes a GdkPixdata structure into a byte stream. 164 * The byte stream consists of a straightforward writeout of the 165 * GdkPixdata fields in network byte order, plus the pixel_data 166 * bytes the structure points to. 167 * Returns: A newly-allocated string containing the serialized GdkPixdata structure. 168 */ 169 public ubyte[] serialize() 170 { 171 // guint8 * gdk_pixdata_serialize (const GdkPixdata *pixdata, guint *stream_length_p); 172 uint streamLengthP; 173 auto p = gdk_pixdata_serialize(gdkPixdata, &streamLengthP); 174 175 if(p is null) 176 { 177 return null; 178 } 179 180 return p[0 .. streamLengthP]; 181 } 182 183 /** 184 * Deserializes (reconstruct) a GdkPixdata structure from a byte stream. 185 * The byte stream consists of a straightforward writeout of the 186 * GdkPixdata fields in network byte order, plus the pixel_data 187 * bytes the structure points to. 188 * The pixdata contents are reconstructed byte by byte and are checked 189 * for validity. This function may fail with GDK_PIXBUF_CORRUPT_IMAGE 190 * or GDK_PIXBUF_ERROR_UNKNOWN_TYPE. 191 * Params: 192 * stream = stream of bytes containing a serialized GdkPixdata structure. 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 }