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 = gdk-Pixbufs.html 27 * outPack = gdk 28 * outFile = Pixbuf 29 * strct = GdkPixbuf 30 * realStrct= 31 * ctorStrct= 32 * clss = Pixbuf 33 * interf = 34 * class Code: Yes 35 * interface Code: No 36 * template for: 37 * extend = GObject 38 * implements: 39 * prefixes: 40 * - gdk_pixbuf_ 41 * omit structs: 42 * omit prefixes: 43 * - gdk_pixbuf_ref 44 * - gdk_pixbuf_unref 45 * omit code: 46 * - gdk_pixbuf_get_from_drawable 47 * omit signals: 48 * imports: 49 * - glib.Str 50 * - glib.ErrorG 51 * - glib.GException 52 * - gdkpixbuf.PixbufFormat 53 * - gdk.Drawable 54 * - gdk.Bitmap 55 * - gdk.GC 56 * - gdk.Colormap 57 * - gdk.ImageGdk 58 * - gio.Cancellable 59 * - gio.InputStream 60 * structWrap: 61 * - GCancellable* -> Cancellable 62 * - GInputStream* -> InputStream 63 * - GdkBitmap* -> Bitmap 64 * - GdkColormap* -> Colormap 65 * - GdkDrawable* -> Drawable 66 * - GdkGC* -> GC 67 * - GdkImage* -> ImageGdk 68 * - GdkPixbuf* -> Pixbuf 69 * - GdkPixbufFormat* -> PixbufFormat 70 * module aliases: 71 * local aliases: 72 * overrides: 73 */ 74 75 module gdk.Pixbuf; 76 77 public import gtkc.gdktypes; 78 79 private import gtkc.gdk; 80 private import glib.ConstructionException; 81 private import gobject.ObjectG; 82 83 84 private import glib.Str; 85 private import glib.ErrorG; 86 private import glib.GException; 87 private import gdkpixbuf.PixbufFormat; 88 private import gdk.Drawable; 89 private import gdk.Bitmap; 90 private import gdk.GC; 91 private import gdk.Colormap; 92 private import gdk.ImageGdk; 93 private import gio.Cancellable; 94 private import gio.InputStream; 95 96 97 98 private import gobject.ObjectG; 99 100 /** 101 * Description 102 * These functions allow to render pixbufs on drawables. Pixbufs are 103 * client-side images. For details on how to create and manipulate 104 * pixbufs, see the GdkPixbuf API documentation. 105 */ 106 public class Pixbuf : ObjectG 107 { 108 109 /** the main Gtk struct */ 110 protected GdkPixbuf* gdkPixbuf; 111 112 113 public GdkPixbuf* getPixbufStruct() 114 { 115 return gdkPixbuf; 116 } 117 118 119 /** the main Gtk struct as a void* */ 120 protected override void* getStruct() 121 { 122 return cast(void*)gdkPixbuf; 123 } 124 125 /** 126 * Sets our main struct and passes it to the parent class 127 */ 128 public this (GdkPixbuf* gdkPixbuf) 129 { 130 super(cast(GObject*)gdkPixbuf); 131 this.gdkPixbuf = gdkPixbuf; 132 } 133 134 protected override void setStruct(GObject* obj) 135 { 136 super.setStruct(obj); 137 gdkPixbuf = cast(GdkPixbuf*)obj; 138 } 139 140 /** 141 * Transfers image data from a GdkDrawable and converts it to an RGB(A) 142 * representation inside a GdkPixbuf. In other words, copies 143 * image data from a server-side drawable to a client-side RGB(A) buffer. 144 * This allows you to efficiently read individual pixels on the client side. 145 * If the drawable src has no colormap (gdk_drawable_get_colormap() 146 * returns NULL), then a suitable colormap must be specified. 147 * Typically a GdkWindow or a pixmap created by passing a GdkWindow 148 * to gdk_pixmap_new() will already have a colormap associated with 149 * it. If the drawable has a colormap, the cmap argument will be 150 * ignored. If the drawable is a bitmap (1 bit per pixel pixmap), 151 * then a colormap is not required; pixels with a value of 1 are 152 * assumed to be white, and pixels with a value of 0 are assumed to be 153 * black. For taking screenshots, gdk_colormap_get_system() returns 154 * the correct colormap to use. 155 * If the specified destination pixbuf dest is NULL, then this 156 * function will create an RGB pixbuf with 8 bits per channel and no 157 * alpha, with the same size specified by the width and height 158 * arguments. In this case, the dest_x and dest_y arguments must be 159 * specified as 0. If the specified destination pixbuf is not NULL 160 * and it contains alpha information, then the filled pixels will be 161 * set to full opacity (alpha = 255). 162 * If the specified drawable is a pixmap, then the requested source 163 * rectangle must be completely contained within the pixmap, otherwise 164 * the function will return NULL. For pixmaps only (not for windows) 165 * passing -1 for width or height is allowed to mean the full width 166 * or height of the pixmap. 167 * If the specified drawable is a window, and the window is off the 168 * screen, then there is no image data in the obscured/offscreen 169 * regions to be placed in the pixbuf. The contents of portions of the 170 * pixbuf corresponding to the offscreen region are undefined. 171 * If the window you're obtaining data from is partially obscured by 172 * other windows, then the contents of the pixbuf areas corresponding 173 * to the obscured regions are undefined. 174 * If the target drawable is not mapped (typically because it's 175 * iconified/minimized or not on the current workspace), then NULL 176 * will be returned. 177 * If memory can't be allocated for the return value, NULL will be returned 178 * instead. 179 * (In short, there are several ways this function can fail, and if it fails 180 * it returns NULL; so check the return value.) 181 * This function calls gdk_drawable_get_image() internally and 182 * converts the resulting image to a GdkPixbuf, so the 183 * documentation for gdk_drawable_get_image() may also be relevant. 184 * Params: 185 * src = Source drawable. 186 * cmap = A colormap if src doesn't have one set. 187 * srcX = Source X coordinate within drawable. 188 * srcY = Source Y coordinate within drawable. 189 * destX = Destination X coordinate in pixbuf, or 0 if dest is NULL. 190 * destY = Destination Y coordinate in pixbuf, or 0 if dest is NULL. 191 * width = Width in pixels of region to get. 192 * height = Height in pixels of region to get. 193 * Returns: 194 * The same pixbuf as dest if it was non-NULL, or a newly-created 195 * pixbuf with a reference count of 1 if no destination pixbuf was specified, or NULL on error 196 */ 197 public static Pixbuf getFromDrawable(Drawable src, Colormap cmap, int srcX, int srcY, int destX, int destY, int width, int height) 198 { 199 // GdkPixbuf* gdk_pixbuf_get_from_drawable (GdkPixbuf *dest, GdkDrawable *src, GdkColormap *cmap, int src_x, int src_y, int dest_x, int dest_y, int width, int height); 200 auto p = gdk_pixbuf_get_from_drawable(null, (src is null) ? null : src.getDrawableStruct(), (cmap is null) ? null : cmap.getColormapStruct(), srcX, srcY, destX, destY, width, height); 201 202 if ( p is null ) 203 { 204 return null; 205 } 206 207 return ObjectG.getDObject!(Pixbuf)( p ); 208 } 209 210 /** 211 * SetFromDrawable is different from GetFrom Drawable as it doesn't create a new pixbuf 212 */ 213 public void setFromDrawable(Drawable src, int srcX, int srcY, int width, int height) 214 { 215 gdk_pixbuf_get_from_drawable( 216 gdkPixbuf, // gdkPixbuf 217 src.getDrawableStruct(), 218 null, // colormap 219 srcX, srcY, 220 0, 0, // destination x and y 221 width, height); 222 } 223 224 /** 225 * Creates a new Pixbuf from a drawable. 226 * this is a simplyfied GetFromDrawable 227 */ 228 this(Drawable src, int srcX, int srcY, int width, int height) 229 { 230 GdkPixbuf* pb = gdk_pixbuf_get_from_drawable( 231 null, // gdkPixbuf 232 src.getDrawableStruct(), 233 null, // colormap 234 srcX, srcY, 235 0, 0, // destination x and y 236 width, height); 237 this(pb); 238 } 239 240 /** 241 * Saves pixbuf to a new buffer in format type, which is currently "jpeg", 242 * "tiff", "png", "ico" or "bmp". See gdk_pixbuf_save_to_buffer() for more details. 243 * Since 2.4 244 * Params: 245 * buffer = location to receive a pointer to the new buffer. 246 * type = name of file format. 247 * optionKeys = name of options to set, NULL-terminated 248 * optionValues = values for named options 249 * Returns: whether an error was set 250 * Throws: GException on failure. 251 */ 252 public int saveToBufferv(out char[] buffer, string type, string[] optionKeys, string[] optionValues) 253 { 254 gchar* outbuffer = null; 255 gsize bufferSize; 256 GError* err = null; 257 258 // gboolean gdk_pixbuf_save_to_bufferv (GdkPixbuf *pixbuf, gchar **buffer, gsize *buffer_size, const char *type, char **option_keys, char **option_values, GError **error); 259 auto p = gdk_pixbuf_save_to_bufferv(gdkPixbuf, &outbuffer, &bufferSize, Str.toStringz(type), Str.toStringzArray(optionKeys), Str.toStringzArray(optionValues), &err); 260 261 if (err !is null) 262 { 263 throw new GException( new ErrorG(err) ); 264 } 265 266 buffer = outbuffer[0 .. bufferSize]; 267 return p; 268 } 269 270 /** 271 * Description 272 * The most basic way to create a pixbuf is to wrap an existing pixel 273 * buffer with a GdkPixbuf structure. You can use the 274 * gdk_pixbuf_new_from_data() function to do this You need to specify 275 * the destroy notification function that will be called when the 276 * data buffer needs to be freed; this will happen when a GdkPixbuf 277 * is finalized by the reference counting functions If you have a 278 * chunk of static data compiled into your application, you can pass 279 * in NULL as the destroy notification function so that the data 280 * will not be freed. 281 * The gdk_pixbuf_new() function can be used as a convenience to 282 * create a pixbuf with an empty buffer. This is equivalent to 283 * allocating a data buffer using malloc() and 284 * then wrapping it with gdk_pixbuf_new_from_data(). The gdk_pixbuf_new() 285 * function will compute an optimal rowstride so that rendering can be 286 * performed with an efficient algorithm. 287 * As a special case, you can use the gdk_pixbuf_new_from_xpm_data() 288 * function to create a pixbuf from inline XPM image data. 289 * You can also copy an existing pixbuf with the gdk_pixbuf_copy() 290 * function. This is not the same as just doing a g_object_ref() 291 * on the old pixbuf; the copy function will actually duplicate the 292 * pixel data in memory and create a new GdkPixbuf structure for it. 293 */ 294 295 /** 296 * Description 297 * The GdkPixbuf structure contains 298 * information that describes an image in memory. 299 * Image Data 300 * Image data in a pixbuf is stored in memory in uncompressed, 301 * packed format. Rows in the image are stored top to bottom, and 302 * in each row pixels are stored from left to right. There may be 303 * padding at the end of a row. The "rowstride" value of a pixbuf, 304 * as returned by gdk_pixbuf_get_rowstride(), indicates the number 305 * of bytes between rows. 306 * $(DDOC_COMMENT example) 307 * Note 308 * If you are doing memcpy() of raw pixbuf data, note that the 309 * last row in the pixbuf may not be as wide as the full 310 * rowstride, but rather just as wide as the pixel data needs to 311 * be. That is, it is unsafe to do memcpy (dest, 312 * pixels, rowstride * height) to copy a whole pixbuf. 313 * Use gdk_pixbuf_copy() instead, or compute the width in bytes 314 * of the last row as width * ((n_channels * 315 * bits_per_sample + 7) / 8). 316 */ 317 318 /** 319 * Description 320 * GdkPixbuf structures are reference counted. This means that an 321 * application can share a single pixbuf among many parts of the 322 * code. When a piece of the program needs to keep a pointer to a 323 * pixbuf, it should add a reference to it by calling g_object_ref(). 324 * When it no longer needs the pixbuf, it should subtract a reference 325 * by calling g_object_unref(). The pixbuf will be destroyed when 326 * its reference count drops to zero. Newly-created GdkPixbuf 327 * structures start with a reference count of one. 328 * Note 329 * As GdkPixbuf is derived from GObject now, gdk_pixbuf_ref() and 330 * gdk_pixbuf_unref() are deprecated in favour of g_object_ref() 331 * and g_object_unref() resp. 332 * Finalizing a pixbuf means to free its pixel 333 * data and to free the GdkPixbuf structure itself. Most of the 334 * library functions that create GdkPixbuf structures create the 335 * pixel data by themselves and define the way it should be freed; 336 * you do not need to worry about those. The only function that lets 337 * you specify how to free the pixel data is 338 * gdk_pixbuf_new_from_data(). Since you pass it a pre-allocated 339 * pixel buffer, you must also specify a way to free that data. This 340 * is done with a function of type GdkPixbufDestroyNotify. When a 341 * pixbuf created with gdk_pixbuf_new_from_data() is finalized, your 342 * destroy notification function will be called, and it is its 343 * responsibility to free the pixel array. 344 */ 345 346 /** 347 * Description 348 * The gdk-pixbuf; library provides a simple mechanism for loading 349 * an image from a file in synchronous fashion. This means that the 350 * library takes control of the application while the file is being 351 * loaded; from the user's point of view, the application will block 352 * until the image is done loading. 353 * This interface can be used by applications in which blocking is 354 * acceptable while an image is being loaded. It can also be used to 355 * load small images in general. Applications that need progressive 356 * loading can use the GdkPixbufLoader functionality instead. 357 */ 358 359 /** 360 * Description 361 * These functions allow to save a GdkPixbuf in a number of 362 * file formats. The formatted data can be written to a file 363 * or to a memory buffer. gdk-pixbuf; can also call a user-defined 364 * callback on the data, which allows to e.g. write the image 365 * to a socket or store it in a database. 366 */ 367 368 /** 369 * Description 370 * The gdk-pixbuf; contains functions to scale pixbufs, to scale 371 * pixbufs and composite against an existing image, and to scale 372 * pixbufs and composite against a solid color or checkerboard. 373 * Compositing a checkerboard is a common way to show an image with 374 * an alpha channel in image-viewing and editing software. 375 * Since the full-featured functions (gdk_pixbuf_scale(), 376 * gdk_pixbuf_composite(), and gdk_pixbuf_composite_color()) are 377 * rather complex to use and have many arguments, two simple 378 * convenience functions are provided, gdk_pixbuf_scale_simple() and 379 * gdk_pixbuf_composite_color_simple() which create a new pixbuf of a 380 * given size, scale an original image to fit, and then return the 381 * new pixbuf. 382 * Scaling and compositing functions take advantage of MMX hardware 383 * acceleration on systems where MMX is supported. If gdk-pixbuf is built 384 * with the Sun mediaLib library, these functions are instead accelerated 385 * using mediaLib, which provides hardware acceleration on Intel, AMD, 386 * and Sparc chipsets. If desired, mediaLib support can be turned off by 387 * setting the GDK_DISABLE_MEDIALIB environment variable. 388 * The following example demonstrates handling an expose event by 389 * rendering the appropriate area of a source image (which is scaled 390 * to fit the widget) onto the widget's window. The source image is 391 * rendered against a checkerboard, which provides a visual 392 * representation of the alpha channel if the image has one. If the 393 * image doesn't have an alpha channel, calling 394 * gdk_pixbuf_composite_color() function has exactly the same effect 395 * as calling gdk_pixbuf_scale(). 396 * $(DDOC_COMMENT example) 397 */ 398 399 /** 400 * Description 401 * These functions provide miscellaneous utilities for manipulating 402 * pixbufs. The pixel data in pixbufs may of course be manipulated 403 * directly by applications, but several common operations can be 404 * performed by these functions instead. 405 */ 406 407 /** 408 * Takes the opacity values in a rectangular portion of a pixbuf and thresholds 409 * them to produce a bi-level alpha mask that can be used as a clipping mask for 410 * a drawable. 411 * Params: 412 * bitmap = Bitmap where the bilevel mask will be painted to. 413 * srcX = Source X coordinate. 414 * srcY = source Y coordinate. 415 * destX = Destination X coordinate. 416 * destY = Destination Y coordinate. 417 * width = Width of region to threshold, or -1 to use pixbuf width 418 * height = Height of region to threshold, or -1 to use pixbuf height 419 * alphaThreshold = Opacity values below this will be painted as zero; all 420 * other values will be painted as one. 421 */ 422 public void renderThresholdAlpha(Bitmap bitmap, int srcX, int srcY, int destX, int destY, int width, int height, int alphaThreshold) 423 { 424 // void gdk_pixbuf_render_threshold_alpha (GdkPixbuf *pixbuf, GdkBitmap *bitmap, int src_x, int src_y, int dest_x, int dest_y, int width, int height, int alpha_threshold); 425 gdk_pixbuf_render_threshold_alpha(gdkPixbuf, (bitmap is null) ? null : bitmap.getBitmapStruct(), srcX, srcY, destX, destY, width, height, alphaThreshold); 426 } 427 428 /** 429 * Warning 430 * gdk_pixbuf_render_to_drawable has been deprecated since version 2.4 and should not be used in newly-written code. This function is obsolete. Use gdk_draw_pixbuf() instead. 431 * Renders a rectangular portion of a pixbuf to a drawable while using the 432 * specified GC. This is done using GdkRGB, so the specified drawable must have 433 * the GdkRGB visual and colormap. Note that this function will ignore the 434 * opacity information for images with an alpha channel; the GC must already 435 * have the clipping mask set if you want transparent regions to show through. 436 * For an explanation of dither offsets, see the GdkRGB documentation. In 437 * brief, the dither offset is important when re-rendering partial regions of an 438 * image to a rendered version of the full image, or for when the offsets to a 439 * base position change, as in scrolling. The dither matrix has to be shifted 440 * for consistent visual results. If you do not have any of these cases, the 441 * dither offsets can be both zero. 442 * Params: 443 * drawable = Destination drawable. 444 * gc = GC used for rendering. 445 * srcX = Source X coordinate within pixbuf. 446 * srcY = Source Y coordinate within pixbuf. 447 * destX = Destination X coordinate within drawable. 448 * destY = Destination Y coordinate within drawable. 449 * width = Width of region to render, in pixels, or -1 to use pixbuf width 450 * height = Height of region to render, in pixels, or -1 to use pixbuf height 451 * dither = Dithering mode for GdkRGB. 452 * xDither = X offset for dither. 453 * yDither = Y offset for dither. 454 */ 455 public void renderToDrawable(Drawable drawable, GC gc, int srcX, int srcY, int destX, int destY, int width, int height, GdkRgbDither dither, int xDither, int yDither) 456 { 457 // void gdk_pixbuf_render_to_drawable (GdkPixbuf *pixbuf, GdkDrawable *drawable, GdkGC *gc, int src_x, int src_y, int dest_x, int dest_y, int width, int height, GdkRgbDither dither, int x_dither, int y_dither); 458 gdk_pixbuf_render_to_drawable(gdkPixbuf, (drawable is null) ? null : drawable.getDrawableStruct(), (gc is null) ? null : gc.getGCStruct(), srcX, srcY, destX, destY, width, height, dither, xDither, yDither); 459 } 460 461 /** 462 * Warning 463 * gdk_pixbuf_render_to_drawable_alpha has been deprecated since version 2.4 and should not be used in newly-written code. This function is obsolete. Use gdk_draw_pixbuf() instead. 464 * Renders a rectangular portion of a pixbuf to a drawable. The destination 465 * drawable must have a colormap. All windows have a colormap, however, pixmaps 466 * only have colormap by default if they were created with a non-NULL window argument. 467 * Otherwise a colormap must be set on them with gdk_drawable_set_colormap. 468 * On older X servers, rendering pixbufs with an alpha channel involves round trips 469 * to the X server, and may be somewhat slow. 470 * Params: 471 * drawable = Destination drawable. 472 * srcX = Source X coordinate within pixbuf. 473 * srcY = Source Y coordinates within pixbuf. 474 * destX = Destination X coordinate within drawable. 475 * destY = Destination Y coordinate within drawable. 476 * width = Width of region to render, in pixels, or -1 to use pixbuf width. 477 * height = Height of region to render, in pixels, or -1 to use pixbuf height. 478 * alphaMode = Ignored. Present for backwards compatibility. 479 * alphaThreshold = Ignored. Present for backwards compatibility 480 * dither = Dithering mode for GdkRGB. 481 * xDither = X offset for dither. 482 * yDither = Y offset for dither. 483 */ 484 public void renderToDrawableAlpha(Drawable drawable, int srcX, int srcY, int destX, int destY, int width, int height, GdkPixbufAlphaMode alphaMode, int alphaThreshold, GdkRgbDither dither, int xDither, int yDither) 485 { 486 // void gdk_pixbuf_render_to_drawable_alpha (GdkPixbuf *pixbuf, GdkDrawable *drawable, int src_x, int src_y, int dest_x, int dest_y, int width, int height, GdkPixbufAlphaMode alpha_mode, int alpha_threshold, GdkRgbDither dither, int x_dither, int y_dither); 487 gdk_pixbuf_render_to_drawable_alpha(gdkPixbuf, (drawable is null) ? null : drawable.getDrawableStruct(), srcX, srcY, destX, destY, width, height, alphaMode, alphaThreshold, dither, xDither, yDither); 488 } 489 490 /** 491 * Creates a pixmap and a mask bitmap which are returned in the pixmap_return 492 * and mask_return arguments, respectively, and renders a pixbuf and its 493 * corresponding thresholded alpha mask to them. This is merely a convenience 494 * function; applications that need to render pixbufs with dither offsets or to 495 * given drawables should use gdk_draw_pixbuf() and gdk_pixbuf_render_threshold_alpha(). 496 * The pixmap that is created is created for the colormap returned 497 * by gdk_rgb_get_colormap(). You normally will want to instead use 498 * the actual colormap for a widget, and use 499 * gdk_pixbuf_render_pixmap_and_mask_for_colormap(). 500 * If the pixbuf does not have an alpha channel, then *mask_return will be set 501 * to NULL. 502 * Params: 503 * pixmapReturn = Location to store a pointer to the created pixmap, 504 * or NULL if the pixmap is not needed. 505 * maskReturn = Location to store a pointer to the created mask, 506 * or NULL if the mask is not needed. 507 * alphaThreshold = Threshold value for opacity values. 508 */ 509 public void renderPixmapAndMask(out GdkPixmap* pixmapReturn, out Bitmap maskReturn, int alphaThreshold) 510 { 511 // void gdk_pixbuf_render_pixmap_and_mask (GdkPixbuf *pixbuf, GdkPixmap **pixmap_return, GdkBitmap **mask_return, int alpha_threshold); 512 GdkBitmap* outmaskReturn = null; 513 514 gdk_pixbuf_render_pixmap_and_mask(gdkPixbuf, &pixmapReturn, &outmaskReturn, alphaThreshold); 515 516 maskReturn = ObjectG.getDObject!(Bitmap)(outmaskReturn); 517 } 518 519 /** 520 * Creates a pixmap and a mask bitmap which are returned in the pixmap_return 521 * and mask_return arguments, respectively, and renders a pixbuf and its 522 * corresponding tresholded alpha mask to them. This is merely a convenience 523 * function; applications that need to render pixbufs with dither offsets or to 524 * given drawables should use gdk_draw_pixbuf(), and gdk_pixbuf_render_threshold_alpha(). 525 * The pixmap that is created uses the GdkColormap specified by colormap. 526 * This colormap must match the colormap of the window where the pixmap 527 * will eventually be used or an error will result. 528 * If the pixbuf does not have an alpha channel, then *mask_return will be set 529 * to NULL. 530 * Params: 531 * colormap = A GdkColormap 532 * pixmapReturn = Location to store a pointer to the created pixmap, 533 * or NULL if the pixmap is not needed. 534 * maskReturn = Location to store a pointer to the created mask, 535 * or NULL if the mask is not needed. 536 * alphaThreshold = Threshold value for opacity values. 537 */ 538 public void renderPixmapAndMaskForColormap(Colormap colormap, out GdkPixmap* pixmapReturn, out Bitmap maskReturn, int alphaThreshold) 539 { 540 // void gdk_pixbuf_render_pixmap_and_mask_for_colormap (GdkPixbuf *pixbuf, GdkColormap *colormap, GdkPixmap **pixmap_return, GdkBitmap **mask_return, int alpha_threshold); 541 GdkBitmap* outmaskReturn = null; 542 543 gdk_pixbuf_render_pixmap_and_mask_for_colormap(gdkPixbuf, (colormap is null) ? null : colormap.getColormapStruct(), &pixmapReturn, &outmaskReturn, alphaThreshold); 544 545 maskReturn = ObjectG.getDObject!(Bitmap)(outmaskReturn); 546 } 547 548 /** 549 * Same as gdk_pixbuf_get_from_drawable() but gets the pixbuf from 550 * an image. 551 * Params: 552 * dest = Destination pixbuf, or NULL if a new pixbuf should be created. [allow-none] 553 * src = Source GdkImage. 554 * cmap = A colormap, or NULL to use the one for src. [allow-none] 555 * srcX = Source X coordinate within drawable. 556 * srcY = Source Y coordinate within drawable. 557 * destX = Destination X coordinate in pixbuf, or 0 if dest is NULL. 558 * destY = Destination Y coordinate in pixbuf, or 0 if dest is NULL. 559 * width = Width in pixels of region to get. 560 * height = Height in pixels of region to get. 561 * Returns: dest, newly-created pixbuf if dest was NULL, NULL on error 562 */ 563 public Pixbuf getFromImage(ImageGdk src, Colormap cmap, int srcX, int srcY, int destX, int destY, int width, int height) 564 { 565 // GdkPixbuf * gdk_pixbuf_get_from_image (GdkPixbuf *dest, GdkImage *src, GdkColormap *cmap, int src_x, int src_y, int dest_x, int dest_y, int width, int height); 566 auto p = gdk_pixbuf_get_from_image(gdkPixbuf, (src is null) ? null : src.getImageGdkStruct(), (cmap is null) ? null : cmap.getColormapStruct(), srcX, srcY, destX, destY, width, height); 567 568 if(p is null) 569 { 570 return null; 571 } 572 573 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p); 574 } 575 576 /** 577 */ 578 public static GType getType() 579 { 580 // GType gdk_pixbuf_get_type (); 581 return gdk_pixbuf_get_type(); 582 } 583 584 /** 585 * Creates a new GdkPixbuf structure and allocates a buffer for it. The 586 * buffer has an optimal rowstride. Note that the buffer is not cleared; 587 * you will have to fill it completely yourself. 588 * Params: 589 * colorspace = Color space for image 590 * hasAlpha = Whether the image should have transparency information 591 * bitsPerSample = Number of bits per color sample 592 * width = Width of image in pixels, must be > 0 593 * height = Height of image in pixels, must be > 0 594 * Throws: ConstructionException GTK+ fails to create the object. 595 */ 596 public this (GdkColorspace colorspace, int hasAlpha, int bitsPerSample, int width, int height) 597 { 598 // GdkPixbuf * gdk_pixbuf_new (GdkColorspace colorspace, gboolean has_alpha, int bits_per_sample, int width, int height); 599 auto p = gdk_pixbuf_new(colorspace, hasAlpha, bitsPerSample, width, height); 600 if(p is null) 601 { 602 throw new ConstructionException("null returned by gdk_pixbuf_new(colorspace, hasAlpha, bitsPerSample, width, height)"); 603 } 604 this(cast(GdkPixbuf*) p); 605 } 606 607 /** 608 * Creates a new GdkPixbuf out of in-memory image data. Currently only RGB 609 * images with 8 bits per sample are supported. 610 * Params: 611 * data = Image data in 8-bit/sample packed format. [array][element-type char] 612 * colorspace = Colorspace for the image data 613 * hasAlpha = Whether the data has an opacity channel 614 * bitsPerSample = Number of bits per sample 615 * width = Width of the image in pixels, must be > 0 616 * height = Height of the image in pixels, must be > 0 617 * rowstride = Distance in bytes between row starts 618 * destroyFn = Function used to free the data when the pixbuf's reference count 619 * drops to zero, or NULL if the data should not be freed. [scope async] 620 * destroyFnData = Closure data to pass to the destroy notification function. [closure] 621 * Throws: ConstructionException GTK+ fails to create the object. 622 */ 623 public this (char* data, GdkColorspace colorspace, int hasAlpha, int bitsPerSample, int width, int height, int rowstride, GdkPixbufDestroyNotify destroyFn, void* destroyFnData) 624 { 625 // GdkPixbuf * gdk_pixbuf_new_from_data (const guchar *data, GdkColorspace colorspace, gboolean has_alpha, int bits_per_sample, int width, int height, int rowstride, GdkPixbufDestroyNotify destroy_fn, gpointer destroy_fn_data); 626 auto p = gdk_pixbuf_new_from_data(data, colorspace, hasAlpha, bitsPerSample, width, height, rowstride, destroyFn, destroyFnData); 627 if(p is null) 628 { 629 throw new ConstructionException("null returned by gdk_pixbuf_new_from_data(data, colorspace, hasAlpha, bitsPerSample, width, height, rowstride, destroyFn, destroyFnData)"); 630 } 631 this(cast(GdkPixbuf*) p); 632 } 633 634 /** 635 * Creates a new pixbuf by parsing XPM data in memory. This data is commonly 636 * the result of including an XPM file into a program's C source. 637 * Params: 638 * data = Pointer to inline XPM data. 639 * Throws: ConstructionException GTK+ fails to create the object. 640 */ 641 public this (string[] data) 642 { 643 // GdkPixbuf * gdk_pixbuf_new_from_xpm_data (const char **data); 644 auto p = gdk_pixbuf_new_from_xpm_data(Str.toStringzArray(data)); 645 if(p is null) 646 { 647 throw new ConstructionException("null returned by gdk_pixbuf_new_from_xpm_data(Str.toStringzArray(data))"); 648 } 649 this(cast(GdkPixbuf*) p); 650 } 651 652 /** 653 * Create a GdkPixbuf from a flat representation that is suitable for 654 * storing as inline data in a program. This is useful if you want to 655 * ship a program with images, but don't want to depend on any 656 * external files. 657 * gdk-pixbuf ships with a program called gdk-pixbuf-csource 658 * which allows for conversion of GdkPixbufs into such a inline representation. 659 * In almost all cases, you should pass the --raw flag to 660 * Params: 661 * data = Byte data containing a serialized GdkPixdata structure 662 * copyPixels = Whether to copy the pixel data, or use direct pointers 663 * data for the resulting pixbuf 664 * Throws: GException on failure. 665 * Throws: ConstructionException GTK+ fails to create the object. 666 */ 667 public this (ubyte[] data, int copyPixels) 668 { 669 // GdkPixbuf * gdk_pixbuf_new_from_inline (gint data_length, const guint8 *data, gboolean copy_pixels, GError **error); 670 GError* err = null; 671 672 auto p = gdk_pixbuf_new_from_inline(cast(int) data.length, data.ptr, copyPixels, &err); 673 674 if (err !is null) 675 { 676 throw new GException( new ErrorG(err) ); 677 } 678 679 if(p is null) 680 { 681 throw new ConstructionException("null returned by gdk_pixbuf_new_from_inline(cast(int) data.length, data.ptr, copyPixels, &err)"); 682 } 683 this(cast(GdkPixbuf*) p); 684 } 685 686 /** 687 * Creates a new pixbuf which represents a sub-region of 688 * src_pixbuf. The new pixbuf shares its pixels with the 689 * original pixbuf, so writing to one affects both. 690 * The new pixbuf holds a reference to src_pixbuf, so 691 * src_pixbuf will not be finalized until the new pixbuf 692 * is finalized. 693 * Params: 694 * srcPixbuf = a GdkPixbuf 695 * srcX = X coord in src_pixbuf 696 * srcY = Y coord in src_pixbuf 697 * width = width of region in src_pixbuf 698 * height = height of region in src_pixbuf 699 * Throws: ConstructionException GTK+ fails to create the object. 700 */ 701 public this (Pixbuf srcPixbuf, int srcX, int srcY, int width, int height) 702 { 703 // GdkPixbuf * gdk_pixbuf_new_subpixbuf (GdkPixbuf *src_pixbuf, int src_x, int src_y, int width, int height); 704 auto p = gdk_pixbuf_new_subpixbuf((srcPixbuf is null) ? null : srcPixbuf.getPixbufStruct(), srcX, srcY, width, height); 705 if(p is null) 706 { 707 throw new ConstructionException("null returned by gdk_pixbuf_new_subpixbuf((srcPixbuf is null) ? null : srcPixbuf.getPixbufStruct(), srcX, srcY, width, height)"); 708 } 709 this(cast(GdkPixbuf*) p); 710 } 711 712 /** 713 * Creates a new GdkPixbuf with a copy of the information in the specified 714 * pixbuf. 715 * Returns: A newly-created pixbuf with a reference count of 1, or NULL if not enough memory could be allocated. [transfer full] 716 */ 717 public Pixbuf copy() 718 { 719 // GdkPixbuf * gdk_pixbuf_copy (const GdkPixbuf *pixbuf); 720 auto p = gdk_pixbuf_copy(gdkPixbuf); 721 722 if(p is null) 723 { 724 return null; 725 } 726 727 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p); 728 } 729 730 /** 731 * Queries the color space of a pixbuf. 732 * Returns: Color space. 733 */ 734 public GdkColorspace getColorspace() 735 { 736 // GdkColorspace gdk_pixbuf_get_colorspace (const GdkPixbuf *pixbuf); 737 return gdk_pixbuf_get_colorspace(gdkPixbuf); 738 } 739 740 /** 741 * Queries the number of channels of a pixbuf. 742 * Returns: Number of channels. 743 */ 744 public int getNChannels() 745 { 746 // int gdk_pixbuf_get_n_channels (const GdkPixbuf *pixbuf); 747 return gdk_pixbuf_get_n_channels(gdkPixbuf); 748 } 749 750 /** 751 * Queries whether a pixbuf has an alpha channel (opacity information). 752 * Returns: TRUE if it has an alpha channel, FALSE otherwise. 753 */ 754 public int getHasAlpha() 755 { 756 // gboolean gdk_pixbuf_get_has_alpha (const GdkPixbuf *pixbuf); 757 return gdk_pixbuf_get_has_alpha(gdkPixbuf); 758 } 759 760 /** 761 * Queries the number of bits per color sample in a pixbuf. 762 * Returns: Number of bits per color sample. 763 */ 764 public int getBitsPerSample() 765 { 766 // int gdk_pixbuf_get_bits_per_sample (const GdkPixbuf *pixbuf); 767 return gdk_pixbuf_get_bits_per_sample(gdkPixbuf); 768 } 769 770 /** 771 * Queries a pointer to the pixel data of a pixbuf. 772 * Returns: A pointer to the pixbuf's pixel data. Please see the section called “Image Data” for information about how the pixel data is stored in memory. 773 */ 774 public char* getPixels() 775 { 776 // guchar * gdk_pixbuf_get_pixels (const GdkPixbuf *pixbuf); 777 return gdk_pixbuf_get_pixels(gdkPixbuf); 778 } 779 780 /** 781 * Queries the width of a pixbuf. 782 * Returns: Width in pixels. 783 */ 784 public int getWidth() 785 { 786 // int gdk_pixbuf_get_width (const GdkPixbuf *pixbuf); 787 return gdk_pixbuf_get_width(gdkPixbuf); 788 } 789 790 /** 791 * Queries the height of a pixbuf. 792 * Returns: Height in pixels. 793 */ 794 public int getHeight() 795 { 796 // int gdk_pixbuf_get_height (const GdkPixbuf *pixbuf); 797 return gdk_pixbuf_get_height(gdkPixbuf); 798 } 799 800 /** 801 * Queries the rowstride of a pixbuf, which is the number of bytes between the start of a row 802 * and the start of the next row. 803 * Returns: Distance between row starts. 804 */ 805 public int getRowstride() 806 { 807 // int gdk_pixbuf_get_rowstride (const GdkPixbuf *pixbuf); 808 return gdk_pixbuf_get_rowstride(gdkPixbuf); 809 } 810 811 /** 812 * Looks up key in the list of options that may have been attached to the 813 * pixbuf when it was loaded, or that may have been attached by another 814 * function using gdk_pixbuf_set_option(). 815 * For instance, the ANI loader provides "Title" and "Artist" options. 816 * The ICO, XBM, and XPM loaders provide "x_hot" and "y_hot" hot-spot 817 * options for cursor definitions. The PNG loader provides the tEXt ancillary 818 * chunk key/value pairs as options. Since 2.12, the TIFF and JPEG loaders 819 * return an "orientation" option string that corresponds to the embedded 820 * TIFF/Exif orientation tag (if present). 821 * Params: 822 * key = a nul-terminated string. 823 * Returns: the value associated with key. This is a nul-terminated string that should not be freed or NULL if key was not found. 824 */ 825 public string getOption(string key) 826 { 827 // const gchar * gdk_pixbuf_get_option (GdkPixbuf *pixbuf, const gchar *key); 828 return Str.toString(gdk_pixbuf_get_option(gdkPixbuf, Str.toStringz(key))); 829 } 830 831 /** 832 * Creates a new pixbuf by loading an image from a file. The file format is 833 * detected automatically. If NULL is returned, then error will be set. 834 * Possible errors are in the GDK_PIXBUF_ERROR and G_FILE_ERROR domains. 835 * Params: 836 * filename = Name of file to load, in the GLib file name encoding 837 * Throws: GException on failure. 838 * Throws: ConstructionException GTK+ fails to create the object. 839 */ 840 public this (string filename) 841 { 842 // GdkPixbuf * gdk_pixbuf_new_from_file (const char *filename, GError **error); 843 GError* err = null; 844 845 auto p = gdk_pixbuf_new_from_file(Str.toStringz(filename), &err); 846 847 if (err !is null) 848 { 849 throw new GException( new ErrorG(err) ); 850 } 851 852 if(p is null) 853 { 854 throw new ConstructionException("null returned by gdk_pixbuf_new_from_file(Str.toStringz(filename), &err)"); 855 } 856 this(cast(GdkPixbuf*) p); 857 } 858 859 /** 860 * Creates a new pixbuf by loading an image from a file. 861 * The file format is detected automatically. If NULL is returned, then 862 * error will be set. Possible errors are in the GDK_PIXBUF_ERROR and 863 * G_FILE_ERROR domains. 864 * The image will be scaled to fit in the requested size, preserving 865 * the image's aspect ratio. Note that the returned pixbuf may be smaller 866 * than width x height, if the aspect ratio requires it. To load 867 * and image at the requested size, regardless of aspect ratio, use 868 * gdk_pixbuf_new_from_file_at_scale(). 869 * Since 2.4 870 * Params: 871 * filename = Name of file to load, in the GLib file name encoding 872 * width = The width the image should have or -1 to not constrain the width 873 * height = The height the image should have or -1 to not constrain the height 874 * Throws: GException on failure. 875 * Throws: ConstructionException GTK+ fails to create the object. 876 */ 877 public this (string filename, int width, int height) 878 { 879 // GdkPixbuf * gdk_pixbuf_new_from_file_at_size (const char *filename, int width, int height, GError **error); 880 GError* err = null; 881 882 auto p = gdk_pixbuf_new_from_file_at_size(Str.toStringz(filename), width, height, &err); 883 884 if (err !is null) 885 { 886 throw new GException( new ErrorG(err) ); 887 } 888 889 if(p is null) 890 { 891 throw new ConstructionException("null returned by gdk_pixbuf_new_from_file_at_size(Str.toStringz(filename), width, height, &err)"); 892 } 893 this(cast(GdkPixbuf*) p); 894 } 895 896 /** 897 * Creates a new pixbuf by loading an image from a file. The file format is 898 * detected automatically. If NULL is returned, then error will be set. 899 * Possible errors are in the GDK_PIXBUF_ERROR and G_FILE_ERROR domains. 900 * The image will be scaled to fit in the requested size, optionally preserving 901 * the image's aspect ratio. 902 * When preserving the aspect ratio, a width of -1 will cause the image 903 * to be scaled to the exact given height, and a height of -1 will cause 904 * the image to be scaled to the exact given width. When not preserving 905 * aspect ratio, a width or height of -1 means to not scale the image 906 * at all in that dimension. Negative values for width and height are 907 * allowed since 2.8. 908 * Since 2.6 909 * Params: 910 * filename = Name of file to load, in the GLib file name encoding 911 * width = The width the image should have or -1 to not constrain the width 912 * height = The height the image should have or -1 to not constrain the height 913 * preserveAspectRatio = TRUE to preserve the image's aspect ratio 914 * Throws: GException on failure. 915 * Throws: ConstructionException GTK+ fails to create the object. 916 */ 917 public this (string filename, int width, int height, int preserveAspectRatio) 918 { 919 // GdkPixbuf * gdk_pixbuf_new_from_file_at_scale (const char *filename, int width, int height, gboolean preserve_aspect_ratio, GError **error); 920 GError* err = null; 921 922 auto p = gdk_pixbuf_new_from_file_at_scale(Str.toStringz(filename), width, height, preserveAspectRatio, &err); 923 924 if (err !is null) 925 { 926 throw new GException( new ErrorG(err) ); 927 } 928 929 if(p is null) 930 { 931 throw new ConstructionException("null returned by gdk_pixbuf_new_from_file_at_scale(Str.toStringz(filename), width, height, preserveAspectRatio, &err)"); 932 } 933 this(cast(GdkPixbuf*) p); 934 } 935 936 /** 937 * Creates a new pixbuf by loading an image from an input stream. 938 * The file format is detected automatically. If NULL is returned, then 939 * error will be set. The cancellable can be used to abort the operation 940 * from another thread. If the operation was cancelled, the error 941 * GIO_ERROR_CANCELLED will be returned. Other possible errors are in 942 * the GDK_PIXBUF_ERROR and G_IO_ERROR domains. 943 * The stream is not closed. 944 * Since 2.14 945 * Params: 946 * stream = a GInputStream to load the pixbuf from 947 * cancellable = optional GCancellable object, NULL to ignore 948 * Throws: GException on failure. 949 * Throws: ConstructionException GTK+ fails to create the object. 950 */ 951 public this (InputStream stream, Cancellable cancellable) 952 { 953 // GdkPixbuf * gdk_pixbuf_new_from_stream (GInputStream *stream, GCancellable *cancellable, GError **error); 954 GError* err = null; 955 956 auto p = gdk_pixbuf_new_from_stream((stream is null) ? null : stream.getInputStreamStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 957 958 if (err !is null) 959 { 960 throw new GException( new ErrorG(err) ); 961 } 962 963 if(p is null) 964 { 965 throw new ConstructionException("null returned by gdk_pixbuf_new_from_stream((stream is null) ? null : stream.getInputStreamStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err)"); 966 } 967 this(cast(GdkPixbuf*) p); 968 } 969 970 /** 971 * Creates a new pixbuf by loading an image from an input stream. 972 * The file format is detected automatically. If NULL is returned, then 973 * error will be set. The cancellable can be used to abort the operation 974 * from another thread. If the operation was cancelled, the error 975 * GIO_ERROR_CANCELLED will be returned. Other possible errors are in 976 * the GDK_PIXBUF_ERROR and G_IO_ERROR domains. 977 * The image will be scaled to fit in the requested size, optionally 978 * preserving the image's aspect ratio. When preserving the aspect ratio, 979 * a width of -1 will cause the image to be scaled to the exact given 980 * height, and a height of -1 will cause the image to be scaled to the 981 * exact given width. When not preserving aspect ratio, a width or 982 * height of -1 means to not scale the image at all in that dimension. 983 * The stream is not closed. 984 * Since 2.14 985 * Params: 986 * stream = a GInputStream to load the pixbuf from 987 * width = The width the image should have or -1 to not constrain the width 988 * height = The height the image should have or -1 to not constrain the height 989 * preserveAspectRatio = TRUE to preserve the image's aspect ratio 990 * cancellable = optional GCancellable object, NULL to ignore 991 * Throws: GException on failure. 992 * Throws: ConstructionException GTK+ fails to create the object. 993 */ 994 public this (InputStream stream, int width, int height, int preserveAspectRatio, Cancellable cancellable) 995 { 996 // GdkPixbuf * gdk_pixbuf_new_from_stream_at_scale (GInputStream *stream, gint width, gint height, gboolean preserve_aspect_ratio, GCancellable *cancellable, GError **error); 997 GError* err = null; 998 999 auto p = gdk_pixbuf_new_from_stream_at_scale((stream is null) ? null : stream.getInputStreamStruct(), width, height, preserveAspectRatio, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 1000 1001 if (err !is null) 1002 { 1003 throw new GException( new ErrorG(err) ); 1004 } 1005 1006 if(p is null) 1007 { 1008 throw new ConstructionException("null returned by gdk_pixbuf_new_from_stream_at_scale((stream is null) ? null : stream.getInputStreamStruct(), width, height, preserveAspectRatio, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err)"); 1009 } 1010 this(cast(GdkPixbuf*) p); 1011 } 1012 1013 /** 1014 * Saves pixbuf to a file in type, which is currently "jpeg", "png", "tiff", "ico" or "bmp". 1015 * If error is set, FALSE will be returned. 1016 * See gdk_pixbuf_save() for more details. 1017 * Params: 1018 * filename = name of file to save. 1019 * type = name of file format. 1020 * optionKeys = name of options to set, NULL-terminated. [array zero-terminated=1] 1021 * optionValues = values for named options. [array zero-terminated=1] 1022 * Returns: whether an error was set 1023 * Throws: GException on failure. 1024 */ 1025 public int savev(string filename, string type, string[] optionKeys, string[] optionValues) 1026 { 1027 // gboolean gdk_pixbuf_savev (GdkPixbuf *pixbuf, const char *filename, const char *type, char **option_keys, char **option_values, GError **error); 1028 GError* err = null; 1029 1030 auto p = gdk_pixbuf_savev(gdkPixbuf, Str.toStringz(filename), Str.toStringz(type), Str.toStringzArray(optionKeys), Str.toStringzArray(optionValues), &err); 1031 1032 if (err !is null) 1033 { 1034 throw new GException( new ErrorG(err) ); 1035 } 1036 1037 return p; 1038 } 1039 1040 /** 1041 * Saves pixbuf to a callback in format type, which is currently "jpeg", 1042 * "png", "tiff", "ico" or "bmp". If error is set, FALSE will be returned. See 1043 * gdk_pixbuf_save_to_callback() for more details. 1044 * Since 2.4 1045 * Params: 1046 * saveFunc = a function that is called to save each block of data that 1047 * the save routine generates. [scope call] 1048 * userData = user data to pass to the save function. [closure save_func] 1049 * type = name of file format. 1050 * optionKeys = name of options to set, NULL-terminated. [array zero-terminated=1][element-type utf8] 1051 * optionValues = values for named options. [array zero-terminated=1][element-type utf8] 1052 * Returns: whether an error was set 1053 * Throws: GException on failure. 1054 */ 1055 public int saveToCallbackv(GdkPixbufSaveFunc saveFunc, void* userData, string type, string[] optionKeys, string[] optionValues) 1056 { 1057 // gboolean gdk_pixbuf_save_to_callbackv (GdkPixbuf *pixbuf, GdkPixbufSaveFunc save_func, gpointer user_data, const char *type, char **option_keys, char **option_values, GError **error); 1058 GError* err = null; 1059 1060 auto p = gdk_pixbuf_save_to_callbackv(gdkPixbuf, saveFunc, userData, Str.toStringz(type), Str.toStringzArray(optionKeys), Str.toStringzArray(optionValues), &err); 1061 1062 if (err !is null) 1063 { 1064 throw new GException( new ErrorG(err) ); 1065 } 1066 1067 return p; 1068 } 1069 1070 /** 1071 * Create a new GdkPixbuf containing a copy of src scaled to 1072 * dest_width x dest_height. Leaves src unaffected. interp_type 1073 * should be GDK_INTERP_NEAREST if you want maximum speed (but when 1074 * scaling down GDK_INTERP_NEAREST is usually unusably ugly). The 1075 * default interp_type should be GDK_INTERP_BILINEAR which offers 1076 * reasonable quality and speed. 1077 * You can scale a sub-portion of src by creating a sub-pixbuf 1078 * pointing into src; see gdk_pixbuf_new_subpixbuf(). 1079 * For more complicated scaling/compositing see gdk_pixbuf_scale() 1080 * and gdk_pixbuf_composite(). 1081 * Params: 1082 * destWidth = the width of destination image 1083 * destHeight = the height of destination image 1084 * interpType = the interpolation type for the transformation. 1085 * Returns: the new GdkPixbuf, or NULL if not enough memory could be allocated for it. [transfer full] 1086 */ 1087 public Pixbuf scaleSimple(int destWidth, int destHeight, GdkInterpType interpType) 1088 { 1089 // GdkPixbuf * gdk_pixbuf_scale_simple (const GdkPixbuf *src, int dest_width, int dest_height, GdkInterpType interp_type); 1090 auto p = gdk_pixbuf_scale_simple(gdkPixbuf, destWidth, destHeight, interpType); 1091 1092 if(p is null) 1093 { 1094 return null; 1095 } 1096 1097 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p); 1098 } 1099 1100 /** 1101 * Creates a transformation of the source image src by scaling by 1102 * scale_x and scale_y then translating by offset_x and offset_y, 1103 * then renders the rectangle (dest_x, dest_y, dest_width, 1104 * dest_height) of the resulting image onto the destination image 1105 * replacing the previous contents. 1106 * Try to use gdk_pixbuf_scale_simple() first, this function is 1107 * the industrial-strength power tool you can fall back to if 1108 * gdk_pixbuf_scale_simple() isn't powerful enough. 1109 * If the source rectangle overlaps the destination rectangle on the 1110 * same pixbuf, it will be overwritten during the scaling which 1111 * results in rendering artifacts. 1112 * Params: 1113 * dest = the GdkPixbuf into which to render the results 1114 * destX = the left coordinate for region to render 1115 * destY = the top coordinate for region to render 1116 * destWidth = the width of the region to render 1117 * destHeight = the height of the region to render 1118 * offsetX = the offset in the X direction (currently rounded to an integer) 1119 * offsetY = the offset in the Y direction (currently rounded to an integer) 1120 * scaleX = the scale factor in the X direction 1121 * scaleY = the scale factor in the Y direction 1122 * interpType = the interpolation type for the transformation. 1123 */ 1124 public void scale(Pixbuf dest, int destX, int destY, int destWidth, int destHeight, double offsetX, double offsetY, double scaleX, double scaleY, GdkInterpType interpType) 1125 { 1126 // void gdk_pixbuf_scale (const GdkPixbuf *src, GdkPixbuf *dest, int dest_x, int dest_y, int dest_width, int dest_height, double offset_x, double offset_y, double scale_x, double scale_y, GdkInterpType interp_type); 1127 gdk_pixbuf_scale(gdkPixbuf, (dest is null) ? null : dest.getPixbufStruct(), destX, destY, destWidth, destHeight, offsetX, offsetY, scaleX, scaleY, interpType); 1128 } 1129 1130 /** 1131 * Creates a new GdkPixbuf by scaling src to dest_width x 1132 * dest_height and compositing the result with a checkboard of colors 1133 * color1 and color2. 1134 * Params: 1135 * destWidth = the width of destination image 1136 * destHeight = the height of destination image 1137 * interpType = the interpolation type for the transformation. 1138 * overallAlpha = overall alpha for source image (0..255) 1139 * checkSize = the size of checks in the checkboard (must be a power of two) 1140 * color1 = the color of check at upper left 1141 * color2 = the color of the other check 1142 * Returns: the new GdkPixbuf, or NULL if not enough memory could be allocated for it. [transfer full] 1143 */ 1144 public Pixbuf compositeColorSimple(int destWidth, int destHeight, GdkInterpType interpType, int overallAlpha, int checkSize, uint color1, uint color2) 1145 { 1146 // GdkPixbuf * gdk_pixbuf_composite_color_simple (const GdkPixbuf *src, int dest_width, int dest_height, GdkInterpType interp_type, int overall_alpha, int check_size, guint32 color1, guint32 color2); 1147 auto p = gdk_pixbuf_composite_color_simple(gdkPixbuf, destWidth, destHeight, interpType, overallAlpha, checkSize, color1, color2); 1148 1149 if(p is null) 1150 { 1151 return null; 1152 } 1153 1154 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p); 1155 } 1156 1157 /** 1158 * Creates a transformation of the source image src by scaling by 1159 * scale_x and scale_y then translating by offset_x and offset_y. 1160 * This gives an image in the coordinates of the destination pixbuf. 1161 * The rectangle (dest_x, dest_y, dest_width, dest_height) 1162 * is then composited onto the corresponding rectangle of the 1163 * original destination image. 1164 * When the destination rectangle contains parts not in the source 1165 * image, the data at the edges of the source image is replicated 1166 * to infinity. 1167 * Figure 1. Compositing of pixbufs 1168 * Params: 1169 * dest = the GdkPixbuf into which to render the results 1170 * destX = the left coordinate for region to render 1171 * destY = the top coordinate for region to render 1172 * destWidth = the width of the region to render 1173 * destHeight = the height of the region to render 1174 * offsetX = the offset in the X direction (currently rounded to an integer) 1175 * offsetY = the offset in the Y direction (currently rounded to an integer) 1176 * scaleX = the scale factor in the X direction 1177 * scaleY = the scale factor in the Y direction 1178 * interpType = the interpolation type for the transformation. 1179 * overallAlpha = overall alpha for source image (0..255) 1180 */ 1181 public void composite(Pixbuf dest, int destX, int destY, int destWidth, int destHeight, double offsetX, double offsetY, double scaleX, double scaleY, GdkInterpType interpType, int overallAlpha) 1182 { 1183 // void gdk_pixbuf_composite (const GdkPixbuf *src, GdkPixbuf *dest, int dest_x, int dest_y, int dest_width, int dest_height, double offset_x, double offset_y, double scale_x, double scale_y, GdkInterpType interp_type, int overall_alpha); 1184 gdk_pixbuf_composite(gdkPixbuf, (dest is null) ? null : dest.getPixbufStruct(), destX, destY, destWidth, destHeight, offsetX, offsetY, scaleX, scaleY, interpType, overallAlpha); 1185 } 1186 1187 /** 1188 * Creates a transformation of the source image src by scaling by 1189 * scale_x and scale_y then translating by offset_x and offset_y, 1190 * then composites the rectangle (dest_x ,dest_y, dest_width, 1191 * dest_height) of the resulting image with a checkboard of the 1192 * colors color1 and color2 and renders it onto the destination 1193 * image. 1194 * See gdk_pixbuf_composite_color_simple() for a simpler variant of this 1195 * function suitable for many tasks. 1196 * Params: 1197 * dest = the GdkPixbuf into which to render the results 1198 * destX = the left coordinate for region to render 1199 * destY = the top coordinate for region to render 1200 * destWidth = the width of the region to render 1201 * destHeight = the height of the region to render 1202 * offsetX = the offset in the X direction (currently rounded to an integer) 1203 * offsetY = the offset in the Y direction (currently rounded to an integer) 1204 * scaleX = the scale factor in the X direction 1205 * scaleY = the scale factor in the Y direction 1206 * interpType = the interpolation type for the transformation. 1207 * overallAlpha = overall alpha for source image (0..255) 1208 * checkX = the X offset for the checkboard (origin of checkboard is at -check_x, -check_y) 1209 * checkY = the Y offset for the checkboard 1210 * checkSize = the size of checks in the checkboard (must be a power of two) 1211 * color1 = the color of check at upper left 1212 * color2 = the color of the other check 1213 */ 1214 public void compositeColor(Pixbuf dest, int destX, int destY, int destWidth, int destHeight, double offsetX, double offsetY, double scaleX, double scaleY, GdkInterpType interpType, int overallAlpha, int checkX, int checkY, int checkSize, uint color1, uint color2) 1215 { 1216 // void gdk_pixbuf_composite_color (const GdkPixbuf *src, GdkPixbuf *dest, int dest_x, int dest_y, int dest_width, int dest_height, double offset_x, double offset_y, double scale_x, double scale_y, GdkInterpType interp_type, int overall_alpha, int check_x, int check_y, int check_size, guint32 color1, guint32 color2); 1217 gdk_pixbuf_composite_color(gdkPixbuf, (dest is null) ? null : dest.getPixbufStruct(), destX, destY, destWidth, destHeight, offsetX, offsetY, scaleX, scaleY, interpType, overallAlpha, checkX, checkY, checkSize, color1, color2); 1218 } 1219 1220 /** 1221 * Rotates a pixbuf by a multiple of 90 degrees, and returns the 1222 * result in a new pixbuf. 1223 * Since 2.6 1224 * Params: 1225 * angle = the angle to rotate by 1226 * Returns: the new GdkPixbuf, or NULL if not enough memory could be allocated for it. [transfer full] 1227 */ 1228 public Pixbuf rotateSimple(GdkPixbufRotation angle) 1229 { 1230 // GdkPixbuf * gdk_pixbuf_rotate_simple (const GdkPixbuf *src, GdkPixbufRotation angle); 1231 auto p = gdk_pixbuf_rotate_simple(gdkPixbuf, angle); 1232 1233 if(p is null) 1234 { 1235 return null; 1236 } 1237 1238 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p); 1239 } 1240 1241 /** 1242 * Flips a pixbuf horizontally or vertically and returns the 1243 * result in a new pixbuf. 1244 * Since 2.6 1245 * Params: 1246 * horizontal = TRUE to flip horizontally, FALSE to flip vertically 1247 * Returns: the new GdkPixbuf, or NULL if not enough memory could be allocated for it. [transfer full] 1248 */ 1249 public Pixbuf flip(int horizontal) 1250 { 1251 // GdkPixbuf * gdk_pixbuf_flip (const GdkPixbuf *src, gboolean horizontal); 1252 auto p = gdk_pixbuf_flip(gdkPixbuf, horizontal); 1253 1254 if(p is null) 1255 { 1256 return null; 1257 } 1258 1259 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p); 1260 } 1261 1262 /** 1263 * Takes an existing pixbuf and adds an alpha channel to it. 1264 * If the existing pixbuf already had an alpha channel, the channel 1265 * values are copied from the original; otherwise, the alpha channel 1266 * is initialized to 255 (full opacity). 1267 * If substitute_color is TRUE, then the color specified by (r, g, b) will be 1268 * assigned zero opacity. That is, if you pass (255, 255, 255) for the 1269 * substitute color, all white pixels will become fully transparent. 1270 * Params: 1271 * substituteColor = Whether to set a color to zero opacity. If this 1272 * is FALSE, then the (r, g, b) arguments will be ignored. 1273 * r = Red value to substitute. 1274 * g = Green value to substitute. 1275 * b = Blue value to substitute. 1276 * Returns: A newly-created pixbuf with a reference count of 1. [transfer full] 1277 */ 1278 public Pixbuf addAlpha(int substituteColor, char r, char g, char b) 1279 { 1280 // GdkPixbuf * gdk_pixbuf_add_alpha (const GdkPixbuf *pixbuf, gboolean substitute_color, guchar r, guchar g, guchar b); 1281 auto p = gdk_pixbuf_add_alpha(gdkPixbuf, substituteColor, r, g, b); 1282 1283 if(p is null) 1284 { 1285 return null; 1286 } 1287 1288 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p); 1289 } 1290 1291 /** 1292 * Copies a rectangular area from src_pixbuf to dest_pixbuf. Conversion of 1293 * pixbuf formats is done automatically. 1294 * If the source rectangle overlaps the destination rectangle on the 1295 * same pixbuf, it will be overwritten during the copy operation. 1296 * Therefore, you can not use this function to scroll a pixbuf. 1297 * Params: 1298 * srcX = Source X coordinate within src_pixbuf. 1299 * srcY = Source Y coordinate within src_pixbuf. 1300 * width = Width of the area to copy. 1301 * height = Height of the area to copy. 1302 * destPixbuf = Destination pixbuf. 1303 * destX = X coordinate within dest_pixbuf. 1304 * destY = Y coordinate within dest_pixbuf. 1305 */ 1306 public void copyArea(int srcX, int srcY, int width, int height, Pixbuf destPixbuf, int destX, int destY) 1307 { 1308 // void gdk_pixbuf_copy_area (const GdkPixbuf *src_pixbuf, int src_x, int src_y, int width, int height, GdkPixbuf *dest_pixbuf, int dest_x, int dest_y); 1309 gdk_pixbuf_copy_area(gdkPixbuf, srcX, srcY, width, height, (destPixbuf is null) ? null : destPixbuf.getPixbufStruct(), destX, destY); 1310 } 1311 1312 /** 1313 * Modifies saturation and optionally pixelates src, placing the result in 1314 * dest. src and dest may be the same pixbuf with no ill effects. If 1315 * saturation is 1.0 then saturation is not changed. If it's less than 1.0, 1316 * saturation is reduced (the image turns toward grayscale); if greater than 1317 * 1.0, saturation is increased (the image gets more vivid colors). If pixelate 1318 * is TRUE, then pixels are faded in a checkerboard pattern to create a 1319 * pixelated image. src and dest must have the same image format, size, and 1320 * rowstride. 1321 * Params: 1322 * dest = place to write modified version of src 1323 * saturation = saturation factor 1324 * pixelate = whether to pixelate 1325 */ 1326 public void saturateAndPixelate(Pixbuf dest, float saturation, int pixelate) 1327 { 1328 // void gdk_pixbuf_saturate_and_pixelate (const GdkPixbuf *src, GdkPixbuf *dest, gfloat saturation, gboolean pixelate); 1329 gdk_pixbuf_saturate_and_pixelate(gdkPixbuf, (dest is null) ? null : dest.getPixbufStruct(), saturation, pixelate); 1330 } 1331 1332 /** 1333 * Takes an existing pixbuf and checks for the presence of an 1334 * associated "orientation" option, which may be provided by the 1335 * jpeg loader (which reads the exif orientation tag) or the 1336 * tiff loader (which reads the tiff orientation tag, and 1337 * compensates it for the partial transforms performed by 1338 * libtiff). If an orientation option/tag is present, the 1339 * appropriate transform will be performed so that the pixbuf 1340 * is oriented correctly. 1341 * Since 2.12 1342 * Returns: A newly-created pixbuf, or a reference to the input pixbuf (with an increased reference count). [transfer full] 1343 */ 1344 public Pixbuf applyEmbeddedOrientation() 1345 { 1346 // GdkPixbuf * gdk_pixbuf_apply_embedded_orientation (GdkPixbuf *src); 1347 auto p = gdk_pixbuf_apply_embedded_orientation(gdkPixbuf); 1348 1349 if(p is null) 1350 { 1351 return null; 1352 } 1353 1354 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p); 1355 } 1356 1357 /** 1358 * Clears a pixbuf to the given RGBA value, converting the RGBA value into 1359 * the pixbuf's pixel format. The alpha will be ignored if the pixbuf 1360 * doesn't have an alpha channel. 1361 * Params: 1362 * pixel = RGBA pixel to clear to 1363 * (0xffffffff is opaque white, 0x00000000 transparent black) 1364 */ 1365 public void fill(uint pixel) 1366 { 1367 // void gdk_pixbuf_fill (GdkPixbuf *pixbuf, guint32 pixel); 1368 gdk_pixbuf_fill(gdkPixbuf, pixel); 1369 } 1370 }