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