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 
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 	 * 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 	 * Params:
107 	 *     pixbuf = the data to fill @pixdata with.
108 	 *     useRle = whether to use run-length encoding for the pixel data.
109 	 *
110 	 * Return: If @use_rle is %TRUE, a pointer to the
111 	 *     newly-allocated memory for the run-length encoded pixel data,
112 	 *     otherwise %NULL.
113 	 */
114 	public void* fromPixbuf(Pixbuf pixbuf, bool useRle)
115 	{
116 		return gdk_pixdata_from_pixbuf(gdkPixdata, (pixbuf is null) ? null : pixbuf.getPixbufStruct(), useRle);
117 	}
118 
119 	/**
120 	 * Serializes a #GdkPixdata structure into a byte stream.
121 	 * The byte stream consists of a straightforward writeout of the
122 	 * #GdkPixdata fields in network byte order, plus the @pixel_data
123 	 * bytes the structure points to.
124 	 *
125 	 * Params:
126 	 *     streamLengthP = location to store the resulting stream length in.
127 	 *
128 	 * Return: A
129 	 *     newly-allocated string containing the serialized #GdkPixdata
130 	 *     structure.
131 	 */
132 	public ubyte[] serialize()
133 	{
134 		uint streamLengthP;
135 		
136 		auto p = gdk_pixdata_serialize(gdkPixdata, &streamLengthP);
137 		
138 		return p[0 .. streamLengthP];
139 	}
140 
141 	/**
142 	 * Generates C source code suitable for compiling images directly
143 	 * into programs.
144 	 *
145 	 * gdk-pixbuf ships with a program called
146 	 * [gdk-pixbuf-csource][gdk-pixbuf-csource], which offers a command
147 	 * line interface to this function.
148 	 *
149 	 * Params:
150 	 *     name = used for naming generated data structures or macros.
151 	 *     dumpType = a #GdkPixdataDumpType determining the kind of C
152 	 *         source to be generated.
153 	 *
154 	 * Return: a newly-allocated string containing the C source form
155 	 *     of @pixdata.
156 	 */
157 	public StringG toCsource(string name, GdkPixdataDumpType dumpType)
158 	{
159 		auto p = gdk_pixdata_to_csource(gdkPixdata, Str.toStringz(name), dumpType);
160 		
161 		if(p is null)
162 		{
163 			return null;
164 		}
165 		
166 		return new StringG(cast(GString*) p);
167 	}
168 }