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 cairo.c.types;
59 
60 private import cairo.c.functions;
61 private import glib.ConstructionException;
62 
63 private import glib.Str;
64 
65 
66 private import cairo.Surface;
67 
68 /**
69  * Image surfaces provide the ability to render to memory buffers
70  * either allocated by cairo or by the calling code. The supported
71  * image formats are those defined in cairo_format_t.
72  */
73 public class ImageSurface : Surface
74 {
75 	
76 	/** the main Gtk struct */
77 	protected cairo_surface_t* cairo_surface;
78 	
79 	
80 	/** Get the main Gtk struct */
81 	public cairo_surface_t* getImageSurfaceStruct()
82 	{
83 		return cairo_surface;
84 	}
85 	
86 	
87 	/** the main Gtk struct as a void* */
88 	protected override void* getStruct()
89 	{
90 		return cast(void*)cairo_surface;
91 	}
92 	
93 	/**
94 	 * Sets our main struct and passes it to the parent class
95 	 */
96 	public this (cairo_surface_t* cairo_surface)
97 	{
98 		super(cast(cairo_surface_t*)cairo_surface);
99 		this.cairo_surface = cairo_surface;
100 	}
101 	
102 	/**
103 	 * The PNG functions allow reading PNG images into image surfaces, and writing
104 	 * any surface to a PNG file.
105 	 *
106 	 * It is a toy API. It only offers very simple support for reading and
107 	 * writing PNG files, which is sufficient for testing and
108 	 * demonstration purposes. Applications which need more control over
109 	 * the generated PNG file should access the pixel data directly, using
110 	 * cairo_image_surface_get_data() or a backend-specific access
111 	 * function, and process it with another library, e.g. gdk-pixbuf or
112 	 * libpng.
113 	 */
114 	
115 	/**
116 	 * This function provides a stride value that will respect all
117 	 * alignment requirements of the accelerated image-rendering code
118 	 * Since 1.6
119 	 * Params:
120 	 * format = A cairo_format_t value
121 	 * width = The desired width of an image surface to be created.
122 	 * 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.
123 	 */
124 	public static int formatStrideForWidth(cairo_format_t format, int width)
125 	{
126 		// int cairo_format_stride_for_width (cairo_format_t format,  int width);
127 		return cairo_format_stride_for_width(format, width);
128 	}
129 	
130 	/**
131 	 * Creates an image surface of the specified format and
132 	 * dimensions. Initially the surface contents are all
133 	 * 0. (Specifically, within each pixel, each color or alpha channel
134 	 * belonging to format will be 0. The contents of bits within a pixel,
135 	 * but not belonging to the given format are undefined).
136 	 * Since 1.0
137 	 * Params:
138 	 * format = format of pixels in the surface to create
139 	 * width = width of the surface, in pixels
140 	 * height = height of the surface, in pixels
141 	 * 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.
142 	 */
143 	public static ImageSurface create(cairo_format_t format, int width, int height)
144 	{
145 		// cairo_surface_t * cairo_image_surface_create (cairo_format_t format,  int width,  int height);
146 		auto p = cairo_image_surface_create(format, width, height);
147 		
148 		if(p is null)
149 		{
150 			return null;
151 		}
152 		
153 		return new ImageSurface(cast(cairo_surface_t*) p);
154 	}
155 	
156 	/**
157 	 * Creates an image surface for the provided pixel data. The output
158 	 * buffer must be kept around until the cairo_surface_t is destroyed
159 	 * or cairo_surface_finish() is called on the surface. The initial
160 	 * contents of data will be used as the initial image contents; you
161 	 * must explicitly clear the buffer, using, for example,
162 	 * cairo_rectangle() and cairo_fill() if you want it cleared.
163 	 * Note that the stride may be larger than
164 	 * width*bytes_per_pixel to provide proper alignment for each pixel
165 	 * and row. This alignment is required to allow high-performance rendering
166 	 * within cairo. The correct way to obtain a legal stride value is to
167 	 * call cairo_format_stride_for_width() with the desired format and
168 	 * maximum image width value, and then use the resulting stride value
169 	 * to allocate the data and to create the image surface. See
170 	 * cairo_format_stride_for_width() for example code.
171 	 * Since 1.0
172 	 * Params:
173 	 * data = a pointer to a buffer supplied by the application in which
174 	 * to write contents. This pointer must be suitably aligned for any
175 	 * kind of variable, (for example, a pointer returned by malloc).
176 	 * format = the format of pixels in the buffer
177 	 * width = the width of the image to be stored in the buffer
178 	 * height = the height of the image to be stored in the buffer
179 	 * stride = the number of bytes between the start of rows in the
180 	 * buffer as allocated. This value should always be computed by
181 	 * cairo_format_stride_for_width() before allocating the data
182 	 * buffer.
183 	 * 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.
184 	 */
185 	public static ImageSurface createForData(ubyte* data, cairo_format_t format, int width, int height, int stride)
186 	{
187 		// cairo_surface_t * cairo_image_surface_create_for_data (unsigned char *data,  cairo_format_t format,  int width,  int height,  int stride);
188 		auto p = cairo_image_surface_create_for_data(data, format, width, height, stride);
189 		
190 		if(p is null)
191 		{
192 			return null;
193 		}
194 		
195 		return new ImageSurface(cast(cairo_surface_t*) p);
196 	}
197 	
198 	/**
199 	 * Get a pointer to the data of the image surface, for direct
200 	 * inspection or modification.
201 	 * A call to cairo_surface_flush() is required before accessing the
202 	 * pixel data to ensure that all pending drawing operations are
203 	 * finished. A call to cairo_surface_mark_dirty() is required after
204 	 * the data is modified.
205 	 * Since 1.2
206 	 * 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.
207 	 */
208 	public ubyte* getData()
209 	{
210 		// unsigned char * cairo_image_surface_get_data (cairo_surface_t *surface);
211 		return cairo_image_surface_get_data(cairo_surface);
212 	}
213 	
214 	/**
215 	 * Get the format of the surface.
216 	 * Since 1.2
217 	 * Returns: the format of the surface
218 	 */
219 	public cairo_format_t getFormat()
220 	{
221 		// cairo_format_t cairo_image_surface_get_format (cairo_surface_t *surface);
222 		return cairo_image_surface_get_format(cairo_surface);
223 	}
224 	
225 	/**
226 	 * Get the width of the image surface in pixels.
227 	 * Since 1.0
228 	 * Returns: the width of the surface in pixels.
229 	 */
230 	public int getWidth()
231 	{
232 		// int cairo_image_surface_get_width (cairo_surface_t *surface);
233 		return cairo_image_surface_get_width(cairo_surface);
234 	}
235 	
236 	/**
237 	 * Get the height of the image surface in pixels.
238 	 * Since 1.0
239 	 * Returns: the height of the surface in pixels.
240 	 */
241 	public int getHeight()
242 	{
243 		// int cairo_image_surface_get_height (cairo_surface_t *surface);
244 		return cairo_image_surface_get_height(cairo_surface);
245 	}
246 	
247 	/**
248 	 * Get the stride of the image surface in bytes
249 	 * Since 1.2
250 	 * 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.
251 	 */
252 	public int getStride()
253 	{
254 		// int cairo_image_surface_get_stride (cairo_surface_t *surface);
255 		return cairo_image_surface_get_stride(cairo_surface);
256 	}
257 	
258 	/**
259 	 * Creates a new image surface and initializes the contents to the
260 	 * given PNG file.
261 	 * Since 1.0
262 	 * Params:
263 	 * filename = name of PNG file to load
264 	 * 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
265 	 */
266 	public static ImageSurface createFromPng(string filename)
267 	{
268 		// cairo_surface_t * cairo_image_surface_create_from_png (const char *filename);
269 		auto p = cairo_image_surface_create_from_png(Str.toStringz(filename));
270 		
271 		if(p is null)
272 		{
273 			return null;
274 		}
275 		
276 		return new ImageSurface(cast(cairo_surface_t*) p);
277 	}
278 	
279 	/**
280 	 * Creates a new image surface from PNG data read incrementally
281 	 * via the read_func function.
282 	 * Since 1.0
283 	 * Params:
284 	 * readFunc = function called to read the data of the file
285 	 * closure = data to pass to read_func.
286 	 * 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
287 	 */
288 	public static ImageSurface createFromPngStream(cairo_read_func_t readFunc, void* closure)
289 	{
290 		// cairo_surface_t * cairo_image_surface_create_from_png_stream  (cairo_read_func_t read_func,  void *closure);
291 		auto p = cairo_image_surface_create_from_png_stream(readFunc, closure);
292 		
293 		if(p is null)
294 		{
295 			return null;
296 		}
297 		
298 		return new ImageSurface(cast(cairo_surface_t*) p);
299 	}
300 	
301 	/**
302 	 * Writes the contents of surface to a new file filename as a PNG
303 	 * image.
304 	 * Since 1.0
305 	 * Params:
306 	 * filename = the name of a file to write to
307 	 * 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.
308 	 */
309 	public cairo_status_t writeToPng(string filename)
310 	{
311 		// cairo_status_t cairo_surface_write_to_png (cairo_surface_t *surface,  const char *filename);
312 		return cairo_surface_write_to_png(cairo_surface, Str.toStringz(filename));
313 	}
314 	
315 	/**
316 	 * Writes the image surface to the write function.
317 	 * Since 1.0
318 	 * Params:
319 	 * writeFunc = a cairo_write_func_t
320 	 * closure = closure data for the write function
321 	 * 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.
322 	 */
323 	public cairo_status_t writeToPngStream(cairo_write_func_t writeFunc, void* closure)
324 	{
325 		// cairo_status_t cairo_surface_write_to_png_stream (cairo_surface_t *surface,  cairo_write_func_t write_func,  void *closure);
326 		return cairo_surface_write_to_png_stream(cairo_surface, writeFunc, closure);
327 	}
328 }