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 gdkpixbuf.c.functions;
29 public  import gdkpixbuf.c.types;
30 private import glib.ErrorG;
31 private import glib.GException;
32 private import glib.MemorySlice;
33 private import glib.Str;
34 private import glib.StringG;
35 private import gtkd.Loader;
36 
37 
38 /**
39  * A pixel buffer suitable for serialization and streaming.
40  * 
41  * Using `GdkPixdata`, images can be compiled into an application,
42  * making it unnecessary to refer to external image files at runtime.
43  * 
44  * `GdkPixbuf` includes a utility named `gdk-pixbuf-csource`, which
45  * can be used to convert image files into `GdkPixdata` structures suitable
46  * for inclusion in C sources. To convert the `GdkPixdata` structures back
47  * into a `GdkPixbuf`, use `gdk_pixbuf_from_pixdata()`.
48  * 
49  * Deprecated: `GdkPixdata` should not be used any more. `GResource`
50  * should be used to save the original compressed images inside the
51  * program's binary
52  */
53 public final class Pixdata
54 {
55 	/** the main Gtk struct */
56 	protected GdkPixdata* gdkPixdata;
57 	protected bool ownedRef;
58 
59 	/** Get the main Gtk struct */
60 	public GdkPixdata* getPixdataStruct(bool transferOwnership = false)
61 	{
62 		if (transferOwnership)
63 			ownedRef = false;
64 		return gdkPixdata;
65 	}
66 
67 	/** the main Gtk struct as a void* */
68 	protected void* getStruct()
69 	{
70 		return cast(void*)gdkPixdata;
71 	}
72 
73 	/**
74 	 * Sets our main struct and passes it to the parent class.
75 	 */
76 	public this (GdkPixdata* gdkPixdata, bool ownedRef = false)
77 	{
78 		this.gdkPixdata = gdkPixdata;
79 		this.ownedRef = ownedRef;
80 	}
81 
82 	~this ()
83 	{
84 		if ( Linker.isLoaded(LIBRARY_GDKPIXBUF) && ownedRef )
85 			sliceFree(gdkPixdata);
86 	}
87 
88 	/**
89 	 * Converts a `GdkPixbuf` to a `GdkPixdata`.
90 	 *
91 	 * If `use_rle` is `TRUE`, the pixel data is run-length encoded into
92 	 * newly-allocated memory and a pointer to that memory is returned.
93 	 *
94 	 * Deprecated: Use #GResource instead.
95 	 *
96 	 * Params:
97 	 *     pixbuf = the data to fill `pixdata` with.
98 	 *     useRle = whether to use run-length encoding for the pixel data.
99 	 *
100 	 * Returns: If `use_rle` is
101 	 *     `TRUE`, a pointer to the newly-allocated memory for the run-length
102 	 *     encoded pixel data, otherwise `NULL`.
103 	 */
104 	public ubyte[] fromPixbuf(Pixbuf pixbuf, bool useRle)
105 	{
106 		auto __p = gdk_pixdata_from_pixbuf(gdkPixdata, (pixbuf is null) ? null : pixbuf.getPixbufStruct(), useRle);
107 
108 		return cast(ubyte[])__p[0 .. getArrayLength(cast(ubyte *)__p)];
109 	}
110 
111 	/**
112 	 */
113 
114 	/**
115 	 * magic number. A valid `GdkPixdata` structure must have
116 	 * `GDK_PIXBUF_MAGIC_NUMBER` here
117 	 */
118 	public @property uint magic()
119 	{
120 		return gdkPixdata.magic;
121 	}
122 
123 	/** Ditto */
124 	public @property void magic(uint value)
125 	{
126 		gdkPixdata.magic = value;
127 	}
128 
129 	/**
130 	 * less than 1 to disable length checks, otherwise
131 	 * `GDK_PIXDATA_HEADER_LENGTH` plus the length of `pixel_data`
132 	 */
133 	public @property int length()
134 	{
135 		return gdkPixdata.length;
136 	}
137 
138 	/** Ditto */
139 	public @property void length(int value)
140 	{
141 		gdkPixdata.length = value;
142 	}
143 
144 	/**
145 	 * information about colorspace, sample width and
146 	 * encoding, in a `GdkPixdataType`
147 	 */
148 	public @property uint pixdataType()
149 	{
150 		return gdkPixdata.pixdataType;
151 	}
152 
153 	/** Ditto */
154 	public @property void pixdataType(uint value)
155 	{
156 		gdkPixdata.pixdataType = value;
157 	}
158 
159 	/**
160 	 * Distance in bytes between rows
161 	 */
162 	public @property uint rowstride()
163 	{
164 		return gdkPixdata.rowstride;
165 	}
166 
167 	/** Ditto */
168 	public @property void rowstride(uint value)
169 	{
170 		gdkPixdata.rowstride = value;
171 	}
172 
173 	/**
174 	 * Width of the image in pixels
175 	 */
176 	public @property uint width()
177 	{
178 		return gdkPixdata.width;
179 	}
180 
181 	/** Ditto */
182 	public @property void width(uint value)
183 	{
184 		gdkPixdata.width = value;
185 	}
186 
187 	/**
188 	 * Height of the image in pixels
189 	 */
190 	public @property uint height()
191 	{
192 		return gdkPixdata.height;
193 	}
194 
195 	/** Ditto */
196 	public @property void height(uint value)
197 	{
198 		gdkPixdata.height = value;
199 	}
200 
201 
202 	/**
203 	 * Deserializes (reconstruct) a #GdkPixdata structure from a byte stream.
204 	 *
205 	 * The byte stream consists of a straightforward writeout of the
206 	 * `GdkPixdata` fields in network byte order, plus the `pixel_data`
207 	 * bytes the structure points to.
208 	 *
209 	 * The `pixdata` contents are reconstructed byte by byte and are checked
210 	 * for validity.
211 	 *
212 	 * This function may fail with `GDK_PIXBUF_ERROR_CORRUPT_IMAGE`
213 	 * or `GDK_PIXBUF_ERROR_UNKNOWN_TYPE`.
214 	 *
215 	 * Deprecated: Use `GResource` instead.
216 	 *
217 	 * Params:
218 	 *     stream = stream of bytes containing a
219 	 *         serialized #GdkPixdata structure.
220 	 *
221 	 * Returns: Upon successful deserialization `TRUE` is returned,
222 	 *     `FALSE` otherwise.
223 	 *
224 	 * Throws: GException on failure.
225 	 */
226 	public bool deserialize(ubyte[] stream)
227 	{
228 		GError* err = null;
229 
230 		auto __p = gdk_pixdata_deserialize(gdkPixdata, cast(uint)stream.length, stream.ptr, &err) != 0;
231 
232 		if (err !is null)
233 		{
234 			throw new GException( new ErrorG(err) );
235 		}
236 
237 		return __p;
238 	}
239 
240 	/**
241 	 * Serializes a #GdkPixdata structure into a byte stream.
242 	 * The byte stream consists of a straightforward writeout of the
243 	 * #GdkPixdata fields in network byte order, plus the @pixel_data
244 	 * bytes the structure points to.
245 	 *
246 	 * Deprecated: Use #GResource instead.
247 	 *
248 	 * Returns: A
249 	 *     newly-allocated string containing the serialized #GdkPixdata
250 	 *     structure.
251 	 */
252 	public ubyte[] serialize()
253 	{
254 		uint streamLengthP;
255 
256 		auto __p = gdk_pixdata_serialize(gdkPixdata, &streamLengthP);
257 
258 		return __p[0 .. streamLengthP];
259 	}
260 
261 	/**
262 	 * Generates C source code suitable for compiling images directly
263 	 * into programs.
264 	 *
265 	 * GdkPixbuf ships with a program called `gdk-pixbuf-csource`, which offers
266 	 * a command line interface to this function.
267 	 *
268 	 * Deprecated: Use #GResource instead.
269 	 *
270 	 * Params:
271 	 *     name = used for naming generated data structures or macros
272 	 *     dumpType = the kind of C source to be generated
273 	 *
274 	 * Returns: a newly-allocated string buffer containing
275 	 *     the C source form of `pixdata`.
276 	 */
277 	public StringG toCsource(string name, GdkPixdataDumpType dumpType)
278 	{
279 		auto __p = gdk_pixdata_to_csource(gdkPixdata, Str.toStringz(name), dumpType);
280 
281 		if(__p is null)
282 		{
283 			return null;
284 		}
285 
286 		return new StringG(cast(GString*) __p, true);
287 	}
288 }