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