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  * Conversion parameters:
26  * inFile  = cairo-Image-Surfaces.html
27  * outPack = cairo
28  * outFile = ImageSurface
29  * strct   = cairo_surface_t
30  * realStrct=
31  * ctorStrct=
32  * clss    = ImageSurface
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = cairo_surface_t
38  * implements:
39  * prefixes:
40  * 	- cairo_image_surface_
41  * 	- cairo_surface_
42  * 	- cairo_
43  * omit structs:
44  * omit prefixes:
45  * omit code:
46  * omit signals:
47  * imports:
48  * 	- glib.Str
49  * structWrap:
50  * 	- cairo_surface_t* -> ImageSurface
51  * module aliases:
52  * local aliases:
53  * overrides:
54  */
55 
56 module cairo.ImageSurface;
57 
58 public  import gtkc.cairotypes;
59 
60 private import gtkc.cairo;
61 private import glib.ConstructionException;
62 
63 
64 private import glib.Str;
65 
66 
67 
68 private import cairo.Surface;
69 
70 /**
71  * Description
72  * Image surfaces provide the ability to render to memory buffers
73  * either allocated by cairo or by the calling code. The supported
74  * image formats are those defined in cairo_format_t.
75  */
76 public class ImageSurface : Surface
77 {
78 	
79 	/** the main Gtk struct */
80 	protected cairo_surface_t* cairo_surface;
81 	
82 	
83 	public cairo_surface_t* getImageSurfaceStruct()
84 	{
85 		return cairo_surface;
86 	}
87 	
88 	
89 	/** the main Gtk struct as a void* */
90 	protected override void* getStruct()
91 	{
92 		return cast(void*)cairo_surface;
93 	}
94 	
95 	/**
96 	 * Sets our main struct and passes it to the parent class
97 	 */
98 	public this (cairo_surface_t* cairo_surface)
99 	{
100 		super(cast(cairo_surface_t*)cairo_surface);
101 		this.cairo_surface = cairo_surface;
102 	}
103 	
104 	/**
105 	 * Description
106 	 * The PNG functions allow reading PNG images into image surfaces, and writing
107 	 * any surface to a PNG file.
108 	 */
109 	
110 	/**
111 	 * This function provides a stride value that will respect all
112 	 * alignment requirements of the accelerated image-rendering code
113 	 * Since 1.6
114 	 * Params:
115 	 * format = A cairo_format_t value
116 	 * width = The desired width of an image surface to be created.
117 	 * Returns: the appropriate stride to use given the desired format and width, or -1 if either the format is invalid or the width too large.
118 	 */
119 	public static int formatStrideForWidth(cairo_format_t format, int width)
120 	{
121 		// int cairo_format_stride_for_width (cairo_format_t format,  int width);
122 		return cairo_format_stride_for_width(format, width);
123 	}
124 	
125 	/**
126 	 * Creates an image surface of the specified format and
127 	 * dimensions. Initially the surface contents are all
128 	 * 0. (Specifically, within each pixel, each color or alpha channel
129 	 * belonging to format will be 0. The contents of bits within a pixel,
130 	 * but not belonging to the given format are undefined).
131 	 * Params:
132 	 * format = format of pixels in the surface to create
133 	 * width = width of the surface, in pixels
134 	 * height = height of the surface, in pixels
135 	 * Returns: a pointer to the newly created surface. The caller owns the surface and should call cairo_surface_destroy() when done with it. This function always returns a valid pointer, but it will return a pointer to a "nil" surface if an error such as out of memory occurs. You can use cairo_surface_status() to check for this.
136 	 */
137 	public static ImageSurface create(cairo_format_t format, int width, int height)
138 	{
139 		// cairo_surface_t * cairo_image_surface_create (cairo_format_t format,  int width,  int height);
140 		auto p = cairo_image_surface_create(format, width, height);
141 		
142 		if(p is null)
143 		{
144 			return null;
145 		}
146 		
147 		return new ImageSurface(cast(cairo_surface_t*) p);
148 	}
149 	
150 	/**
151 	 * Creates an image surface for the provided pixel data. The output
152 	 * buffer must be kept around until the cairo_surface_t is destroyed
153 	 * or cairo_surface_finish() is called on the surface. The initial
154 	 * contents of data will be used as the initial image contents; you
155 	 * must explicitly clear the buffer, using, for example,
156 	 * cairo_rectangle() and cairo_fill() if you want it cleared.
157 	 * Note that the stride may be larger than
158 	 * width*bytes_per_pixel to provide proper alignment for each pixel
159 	 * and row. This alignment is required to allow high-performance rendering
160 	 * within cairo. The correct way to obtain a legal stride value is to
161 	 * call cairo_format_stride_for_width() with the desired format and
162 	 * maximum image width value, and then use the resulting stride value
163 	 * to allocate the data and to create the image surface. See
164 	 * cairo_format_stride_for_width() for example code.
165 	 * Params:
166 	 * data = a pointer to a buffer supplied by the application in which
167 	 *  to write contents. This pointer must be suitably aligned for any
168 	 *  kind of variable, (for example, a pointer returned by malloc).
169 	 * format = the format of pixels in the buffer
170 	 * width = the width of the image to be stored in the buffer
171 	 * height = the height of the image to be stored in the buffer
172 	 * stride = the number of bytes between the start of rows in the
173 	 *  buffer as allocated. This value should always be computed by
174 	 *  cairo_format_stride_for_width() before allocating the data
175 	 *  buffer.
176 	 * Returns: a pointer to the newly created surface. The caller owns the surface and should call cairo_surface_destroy() when done with it. This function always returns a valid pointer, but it will return a pointer to a "nil" surface in the case of an error such as out of memory or an invalid stride value. In case of invalid stride value the error status of the returned surface will be CAIRO_STATUS_INVALID_STRIDE. You can use cairo_surface_status() to check for this. See cairo_surface_set_user_data() for a means of attaching a destroy-notification fallback to the surface if necessary.
177 	 */
178 	public static ImageSurface createForData(ubyte* data, cairo_format_t format, int width, int height, int stride)
179 	{
180 		// cairo_surface_t * cairo_image_surface_create_for_data (unsigned char *data,  cairo_format_t format,  int width,  int height,  int stride);
181 		auto p = cairo_image_surface_create_for_data(data, format, width, height, stride);
182 		
183 		if(p is null)
184 		{
185 			return null;
186 		}
187 		
188 		return new ImageSurface(cast(cairo_surface_t*) p);
189 	}
190 	
191 	/**
192 	 * Get a pointer to the data of the image surface, for direct
193 	 * inspection or modification.
194 	 * Since 1.2
195 	 * Returns: a pointer to the image data of this surface or NULL if surface is not an image surface, or if cairo_surface_finish() has been called.
196 	 */
197 	public ubyte* getData()
198 	{
199 		// unsigned char * cairo_image_surface_get_data (cairo_surface_t *surface);
200 		return cairo_image_surface_get_data(cairo_surface);
201 	}
202 	
203 	/**
204 	 * Get the format of the surface.
205 	 * Since 1.2
206 	 * Returns: the format of the surface
207 	 */
208 	public cairo_format_t getFormat()
209 	{
210 		// cairo_format_t cairo_image_surface_get_format (cairo_surface_t *surface);
211 		return cairo_image_surface_get_format(cairo_surface);
212 	}
213 	
214 	/**
215 	 * Get the width of the image surface in pixels.
216 	 * Returns: the width of the surface in pixels.
217 	 */
218 	public int getWidth()
219 	{
220 		// int cairo_image_surface_get_width (cairo_surface_t *surface);
221 		return cairo_image_surface_get_width(cairo_surface);
222 	}
223 	
224 	/**
225 	 * Get the height of the image surface in pixels.
226 	 * Returns: the height of the surface in pixels.
227 	 */
228 	public int getHeight()
229 	{
230 		// int cairo_image_surface_get_height (cairo_surface_t *surface);
231 		return cairo_image_surface_get_height(cairo_surface);
232 	}
233 	
234 	/**
235 	 * Get the stride of the image surface in bytes
236 	 * Since 1.2
237 	 * Returns: the stride of the image surface in bytes (or 0 if surface is not an image surface). The stride is the distance in bytes from the beginning of one row of the image data to the beginning of the next row.
238 	 */
239 	public int getStride()
240 	{
241 		// int cairo_image_surface_get_stride (cairo_surface_t *surface);
242 		return cairo_image_surface_get_stride(cairo_surface);
243 	}
244 	
245 	/**
246 	 * Creates a new image surface and initializes the contents to the
247 	 * given PNG file.
248 	 * Params:
249 	 * filename = name of PNG file to load
250 	 * Returns: a new cairo_surface_t initialized with the contents of the PNG file, or a "nil" surface if any error occurred. A nil surface can be checked for with cairo_surface_status(surface) which
251 	 */
252 	public static ImageSurface createFromPng(string filename)
253 	{
254 		// cairo_surface_t * cairo_image_surface_create_from_png (const char *filename);
255 		auto p = cairo_image_surface_create_from_png(Str.toStringz(filename));
256 		
257 		if(p is null)
258 		{
259 			return null;
260 		}
261 		
262 		return new ImageSurface(cast(cairo_surface_t*) p);
263 	}
264 	
265 	/**
266 	 * Creates a new image surface from PNG data read incrementally
267 	 * via the read_func function.
268 	 * Params:
269 	 * readFunc = function called to read the data of the file
270 	 * closure = data to pass to read_func.
271 	 * Returns: a new cairo_surface_t initialized with the contents of the PNG file or a "nil" surface if the data read is not a valid PNG image or memory could not be allocated for the operation. A nil surface can be checked for with cairo_surface_status(surface) which
272 	 */
273 	public static ImageSurface createFromPngStream(cairo_read_func_t readFunc, void* closure)
274 	{
275 		// cairo_surface_t * cairo_image_surface_create_from_png_stream  (cairo_read_func_t read_func,  void *closure);
276 		auto p = cairo_image_surface_create_from_png_stream(readFunc, closure);
277 		
278 		if(p is null)
279 		{
280 			return null;
281 		}
282 		
283 		return new ImageSurface(cast(cairo_surface_t*) p);
284 	}
285 	
286 	/**
287 	 * Writes the contents of surface to a new file filename as a PNG
288 	 * image.
289 	 * Params:
290 	 * filename = the name of a file to write to
291 	 * Returns: CAIRO_STATUS_SUCCESS if the PNG file was written successfully. Otherwise, CAIRO_STATUS_NO_MEMORY if memory could not be allocated for the operation or CAIRO_STATUS_SURFACE_TYPE_MISMATCH if the surface does not have pixel contents, or CAIRO_STATUS_WRITE_ERROR if an I/O error occurs while attempting to write the file.
292 	 */
293 	public cairo_status_t writeToPng(string filename)
294 	{
295 		// cairo_status_t cairo_surface_write_to_png (cairo_surface_t *surface,  const char *filename);
296 		return cairo_surface_write_to_png(cairo_surface, Str.toStringz(filename));
297 	}
298 	
299 	/**
300 	 * Writes the image surface to the write function.
301 	 * Params:
302 	 * writeFunc = a cairo_write_func_t
303 	 * closure = closure data for the write function
304 	 * Returns: CAIRO_STATUS_SUCCESS if the PNG file was written successfully. Otherwise, CAIRO_STATUS_NO_MEMORY is returned if memory could not be allocated for the operation, CAIRO_STATUS_SURFACE_TYPE_MISMATCH if the surface does not have pixel contents.
305 	 */
306 	public cairo_status_t writeToPngStream(cairo_write_func_t writeFunc, void* closure)
307 	{
308 		// cairo_status_t cairo_surface_write_to_png_stream (cairo_surface_t *surface,  cairo_write_func_t write_func,  void *closure);
309 		return cairo_surface_write_to_png_stream(cairo_surface, writeFunc, closure);
310 	}
311 }