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