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