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 glib.ErrorG;
29 private import glib.GException;
30 private import glib.Str;
31 private import glib.StringG;
32 private import gtkc.gdkpixbuf;
33 public  import gtkc.gdkpixbuftypes;
34 
35 
36 /**
37  * A #GdkPixdata contains pixbuf information in a form suitable for
38  * serialization and streaming.
39  */
40 public class Pixdata
41 {
42 	/** the main Gtk struct */
43 	protected GdkPixdata* gdkPixdata;
44 	protected bool ownedRef;
45 
46 	/** Get the main Gtk struct */
47 	public GdkPixdata* getPixdataStruct(bool transferOwnership = false)
48 	{
49 		if (transferOwnership)
50 			ownedRef = false;
51 		return gdkPixdata;
52 	}
53 
54 	/** the main Gtk struct as a void* */
55 	protected void* getStruct()
56 	{
57 		return cast(void*)gdkPixdata;
58 	}
59 
60 	/**
61 	 * Sets our main struct and passes it to the parent class.
62 	 */
63 	public this (GdkPixdata* gdkPixdata, bool ownedRef = false)
64 	{
65 		this.gdkPixdata = gdkPixdata;
66 		this.ownedRef = ownedRef;
67 	}
68 
69 
70 	/**
71 	 * Deserializes (reconstruct) a #GdkPixdata structure from a byte stream.
72 	 * The byte stream consists of a straightforward writeout of the
73 	 * #GdkPixdata fields in network byte order, plus the @pixel_data
74 	 * bytes the structure points to.
75 	 * The @pixdata contents are reconstructed byte by byte and are checked
76 	 * for validity. This function may fail with %GDK_PIXBUF_ERROR_CORRUPT_IMAGE
77 	 * or %GDK_PIXBUF_ERROR_UNKNOWN_TYPE.
78 	 *
79 	 * Deprecated: Use #GResource instead.
80 	 *
81 	 * Params:
82 	 *     streamLength = length of the stream used for deserialization.
83 	 *     stream = stream of bytes containing a
84 	 *         serialized #GdkPixdata structure.
85 	 *
86 	 * Returns: Upon successful deserialization %TRUE is returned,
87 	 *     %FALSE otherwise.
88 	 *
89 	 * Throws: GException on failure.
90 	 */
91 	public bool deserialize(ubyte[] stream)
92 	{
93 		GError* err = null;
94 		
95 		auto p = gdk_pixdata_deserialize(gdkPixdata, cast(uint)stream.length, stream.ptr, &err) != 0;
96 		
97 		if (err !is null)
98 		{
99 			throw new GException( new ErrorG(err) );
100 		}
101 		
102 		return p;
103 	}
104 
105 	/**
106 	 * Converts a #GdkPixbuf to a #GdkPixdata. If @use_rle is %TRUE, the
107 	 * pixel data is run-length encoded into newly-allocated memory and a
108 	 * pointer to that memory is returned.
109 	 *
110 	 * Deprecated: Use #GResource instead.
111 	 *
112 	 * Params:
113 	 *     pixbuf = the data to fill @pixdata with.
114 	 *     useRle = whether to use run-length encoding for the pixel data.
115 	 *
116 	 * Returns: If @use_rle is %TRUE, a pointer to the
117 	 *     newly-allocated memory for the run-length encoded pixel data,
118 	 *     otherwise %NULL.
119 	 */
120 	public void* fromPixbuf(Pixbuf pixbuf, bool useRle)
121 	{
122 		return gdk_pixdata_from_pixbuf(gdkPixdata, (pixbuf is null) ? null : pixbuf.getPixbufStruct(), useRle);
123 	}
124 
125 	/**
126 	 * Serializes a #GdkPixdata structure into a byte stream.
127 	 * The byte stream consists of a straightforward writeout of the
128 	 * #GdkPixdata fields in network byte order, plus the @pixel_data
129 	 * bytes the structure points to.
130 	 *
131 	 * Deprecated: Use #GResource instead.
132 	 *
133 	 * Returns: A
134 	 *     newly-allocated string containing the serialized #GdkPixdata
135 	 *     structure.
136 	 */
137 	public ubyte[] serialize()
138 	{
139 		uint streamLengthP;
140 		
141 		auto p = gdk_pixdata_serialize(gdkPixdata, &streamLengthP);
142 		
143 		return p[0 .. streamLengthP];
144 	}
145 
146 	/**
147 	 * Generates C source code suitable for compiling images directly
148 	 * into programs.
149 	 *
150 	 * gdk-pixbuf ships with a program called
151 	 * [gdk-pixbuf-csource][gdk-pixbuf-csource], which offers a command
152 	 * line interface to this function.
153 	 *
154 	 * Deprecated: Use #GResource instead.
155 	 *
156 	 * Params:
157 	 *     name = used for naming generated data structures or macros.
158 	 *     dumpType = a #GdkPixdataDumpType determining the kind of C
159 	 *         source to be generated.
160 	 *
161 	 * Returns: a newly-allocated string containing the C source form
162 	 *     of @pixdata.
163 	 */
164 	public StringG toCsource(string name, GdkPixdataDumpType dumpType)
165 	{
166 		auto p = gdk_pixdata_to_csource(gdkPixdata, Str.toStringz(name), dumpType);
167 		
168 		if(p is null)
169 		{
170 			return null;
171 		}
172 		
173 		return new StringG(cast(GString*) p, true);
174 	}
175 }