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