1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gdkpixbuf.Pixbuf; 26 27 private import gdkpixbuf.PixbufFormat; 28 private import gdkpixbuf.c.functions; 29 public import gdkpixbuf.c.types; 30 private import gio.AsyncResultIF; 31 private import gio.Cancellable; 32 private import gio.IconIF; 33 private import gio.IconT; 34 private import gio.InputStream; 35 private import gio.LoadableIconIF; 36 private import gio.LoadableIconT; 37 private import gio.OutputStream; 38 private import glib.Bytes; 39 private import glib.ConstructionException; 40 private import glib.ErrorG; 41 private import glib.GException; 42 private import glib.HashTable; 43 private import glib.ListSG; 44 private import glib.Str; 45 private import glib.c.functions; 46 private import gobject.ObjectG; 47 48 49 /** 50 * A pixel buffer. 51 * 52 * `GdkPixbuf` contains information about an image's pixel data, 53 * its color space, bits per sample, width and height, and the 54 * rowstride (the number of bytes between the start of one row 55 * and the start of the next). 56 * 57 * ## Creating new `GdkPixbuf` 58 * 59 * The most basic way to create a pixbuf is to wrap an existing pixel 60 * buffer with a [class@GdkPixbuf.Pixbuf] instance. You can use the 61 * [`ctor@GdkPixbuf.Pixbuf.new_from_data`] function to do this. 62 * 63 * Every time you create a new `GdkPixbuf` instance for some data, you 64 * will need to specify the destroy notification function that will be 65 * called when the data buffer needs to be freed; this will happen when 66 * a `GdkPixbuf` is finalized by the reference counting functions. If 67 * you have a chunk of static data compiled into your application, you 68 * can pass in `NULL` as the destroy notification function so that the 69 * data will not be freed. 70 * 71 * The [`ctor@GdkPixbuf.Pixbuf.new`] constructor function can be used 72 * as a convenience to create a pixbuf with an empty buffer; this is 73 * equivalent to allocating a data buffer using `malloc()` and then 74 * wrapping it with `gdk_pixbuf_new_from_data()`. The `gdk_pixbuf_new()` 75 * function will compute an optimal rowstride so that rendering can be 76 * performed with an efficient algorithm. 77 * 78 * As a special case, you can use the [`ctor@GdkPixbuf.Pixbuf.new_from_xpm_data`] 79 * function to create a pixbuf from inline XPM image data. 80 * 81 * You can also copy an existing pixbuf with the [method@Pixbuf.copy] 82 * function. This is not the same as just acquiring a reference to 83 * the old pixbuf instance: the copy function will actually duplicate 84 * the pixel data in memory and create a new [class@Pixbuf] instance 85 * for it. 86 * 87 * ## Reference counting 88 * 89 * `GdkPixbuf` structures are reference counted. This means that an 90 * application can share a single pixbuf among many parts of the 91 * code. When a piece of the program needs to use a pixbuf, it should 92 * acquire a reference to it by calling `g_object_ref()`; when it no 93 * longer needs the pixbuf, it should release the reference it acquired 94 * by calling `g_object_unref()`. The resources associated with a 95 * `GdkPixbuf` will be freed when its reference count drops to zero. 96 * Newly-created `GdkPixbuf` instances start with a reference count 97 * of one. 98 * 99 * ## Image Data 100 * 101 * Image data in a pixbuf is stored in memory in an uncompressed, 102 * packed format. Rows in the image are stored top to bottom, and 103 * in each row pixels are stored from left to right. 104 * 105 * There may be padding at the end of a row. 106 * 107 * The "rowstride" value of a pixbuf, as returned by [`method@GdkPixbuf.Pixbuf.get_rowstride`], 108 * indicates the number of bytes between rows. 109 * 110 * **NOTE**: If you are copying raw pixbuf data with `memcpy()` note that the 111 * last row in the pixbuf may not be as wide as the full rowstride, but rather 112 * just as wide as the pixel data needs to be; that is: it is unsafe to do 113 * `memcpy (dest, pixels, rowstride * height)` to copy a whole pixbuf. Use 114 * [method@GdkPixbuf.Pixbuf.copy] instead, or compute the width in bytes of the 115 * last row as: 116 * 117 * ```c 118 * last_row = width * ((n_channels * bits_per_sample + 7) / 8); 119 * ``` 120 * 121 * The same rule applies when iterating over each row of a `GdkPixbuf` pixels 122 * array. 123 * 124 * The following code illustrates a simple `put_pixel()` 125 * function for RGB pixbufs with 8 bits per channel with an alpha 126 * channel. 127 * 128 * ```c 129 * static void 130 * put_pixel (GdkPixbuf *pixbuf, 131 * int x, 132 * int y, 133 * guchar red, 134 * guchar green, 135 * guchar blue, 136 * guchar alpha) 137 * { 138 * int n_channels = gdk_pixbuf_get_n_channels (pixbuf); 139 * 140 * // Ensure that the pixbuf is valid 141 * g_assert (gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB); 142 * g_assert (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8); 143 * g_assert (gdk_pixbuf_get_has_alpha (pixbuf)); 144 * g_assert (n_channels == 4); 145 * 146 * int width = gdk_pixbuf_get_width (pixbuf); 147 * int height = gdk_pixbuf_get_height (pixbuf); 148 * 149 * // Ensure that the coordinates are in a valid range 150 * g_assert (x >= 0 && x < width); 151 * g_assert (y >= 0 && y < height); 152 * 153 * int rowstride = gdk_pixbuf_get_rowstride (pixbuf); 154 * 155 * // The pixel buffer in the GdkPixbuf instance 156 * guchar *pixels = gdk_pixbuf_get_pixels (pixbuf); 157 * 158 * // The pixel we wish to modify 159 * guchar *p = pixels + y * rowstride + x * n_channels; 160 * p[0] = red; 161 * p[1] = green; 162 * p[2] = blue; 163 * p[3] = alpha; 164 * } 165 * ``` 166 * 167 * ## Loading images 168 * 169 * The `GdkPixBuf` class provides a simple mechanism for loading 170 * an image from a file in synchronous and asynchronous fashion. 171 * 172 * For GUI applications, it is recommended to use the asynchronous 173 * stream API to avoid blocking the control flow of the application. 174 * 175 * Additionally, `GdkPixbuf` provides the [class@GdkPixbuf.PixbufLoader`] 176 * API for progressive image loading. 177 * 178 * ## Saving images 179 * 180 * The `GdkPixbuf` class provides methods for saving image data in 181 * a number of file formats. The formatted data can be written to a 182 * file or to a memory buffer. `GdkPixbuf` can also call a user-defined 183 * callback on the data, which allows to e.g. write the image 184 * to a socket or store it in a database. 185 */ 186 public class Pixbuf : ObjectG, IconIF, LoadableIconIF 187 { 188 /** the main Gtk struct */ 189 protected GdkPixbuf* gdkPixbuf; 190 191 /** Get the main Gtk struct */ 192 public GdkPixbuf* getPixbufStruct(bool transferOwnership = false) 193 { 194 if (transferOwnership) 195 ownedRef = false; 196 return gdkPixbuf; 197 } 198 199 /** the main Gtk struct as a void* */ 200 protected override void* getStruct() 201 { 202 return cast(void*)gdkPixbuf; 203 } 204 205 /** 206 * Sets our main struct and passes it to the parent class. 207 */ 208 public this (GdkPixbuf* gdkPixbuf, bool ownedRef = false) 209 { 210 this.gdkPixbuf = gdkPixbuf; 211 super(cast(GObject*)gdkPixbuf, ownedRef); 212 } 213 214 // add the Icon capabilities 215 mixin IconT!(GdkPixbuf); 216 217 // add the LoadableIcon capabilities 218 mixin LoadableIconT!(GdkPixbuf); 219 220 /** 221 * Saves pixbuf to a new buffer in format @type, which is currently "jpeg", 222 * "tiff", "png", "ico" or "bmp". See gdk_pixbuf_save_to_buffer() 223 * for more details. 224 * 225 * Params: 226 * buffer = location to receive a pointer to the new buffer. 227 * bufferSize = location to receive the size of the new buffer. 228 * type = name of file format. 229 * optionKeys = name of options to set, %NULL-terminated 230 * optionValues = values for named options 231 * 232 * Return: whether an error was set 233 * 234 * Since: 2.4 235 * 236 * Throws: GException on failure. 237 */ 238 public bool saveToBuffer(out ubyte[] buffer, string type, string[] optionKeys, string[] optionValues) 239 { 240 char* outbuffer = null; 241 size_t bufferSize; 242 GError* err = null; 243 244 auto p = gdk_pixbuf_save_to_bufferv(gdkPixbuf, &outbuffer, &bufferSize, Str.toStringz(type), Str.toStringzArray(optionKeys), Str.toStringzArray(optionValues), &err) != 0; 245 246 if (err !is null) 247 { 248 throw new GException( new ErrorG(err) ); 249 } 250 251 buffer = (cast(ubyte*)outbuffer)[0 .. bufferSize]; 252 253 return p; 254 } 255 256 /** 257 * Creates a new pixbuf by loading an image from an resource. 258 * 259 * The file format is detected automatically. 260 * 261 * Params: 262 * resourcePath = the path of the resource file 263 * 264 * Return: A newly-created pixbuf, or null if any of several error 265 * conditions occurred: the file could not be opened, the image format is 266 * not supported, there was not enough memory to allocate the image buffer, 267 * the stream contained invalid data, or the operation was cancelled. 268 * 269 * Since: 2.26 270 * 271 * Throws: GException on failure. 272 */ 273 public static Pixbuf newFromResource(string resourcePath) 274 { 275 GError* err = null; 276 277 auto p = gdk_pixbuf_new_from_resource(Str.toStringz(resourcePath), &err); 278 279 if (err !is null) 280 { 281 throw new GException( new ErrorG(err) ); 282 } 283 284 return new Pixbuf(cast(GdkPixbuf*) p, true); 285 } 286 287 /** 288 * Creates a new pixbuf by loading an image from an resource. 289 * 290 * The file format is detected automatically. 291 * 292 * The image will be scaled to fit in the requested size, optionally 293 * preserving the image's aspect ratio. When preserving the aspect ratio, 294 * a width of -1 will cause the image to be scaled to the exact given 295 * height, and a height of -1 will cause the image to be scaled to the 296 * exact given width. When not preserving aspect ratio, a width or 297 * height of -1 means to not scale the image at all in that dimension. 298 * 299 * The stream is not closed. 300 * 301 * Params: 302 * resourcePath = the path of the resource file 303 * width = The width the image should have or -1 to not constrain the width 304 * height = The height the image should have or -1 to not constrain the height 305 * preserveAspectRatio = true to preserve the image's aspect ratio 306 * 307 * Return: A newly-created pixbuf, or null if any of several error 308 * conditions occurred: the file could not be opened, the image format is 309 * not supported, there was not enough memory to allocate the image buffer, 310 * the stream contained invalid data, or the operation was cancelled. 311 * 312 * Since: 2.26 313 * 314 * Throws: GException on failure. 315 */ 316 public static Pixbuf newFromResource(string resourcePath, int width, int height, bool preserveAspectRatio) 317 { 318 GError* err = null; 319 320 auto p = gdk_pixbuf_new_from_resource_at_scale(Str.toStringz(resourcePath), width, height, preserveAspectRatio, &err); 321 322 if (err !is null) 323 { 324 throw new GException( new ErrorG(err) ); 325 } 326 327 return new Pixbuf(cast(GdkPixbuf*) p, true); 328 } 329 330 /** 331 * Queries a pointer to the pixel data of a pixbuf. 332 * 333 * Return: A pointer to the pixbuf's pixel data. 334 * Please see the section on [image data](image-data) for information 335 * about how the pixel data is stored in memory. 336 * 337 * This function will cause an implicit copy of the pixbuf data if the 338 * pixbuf was created from read-only data. 339 */ 340 public char* getPixels() 341 { 342 return gdk_pixbuf_get_pixels(gdkPixbuf); 343 } 344 345 /** 346 */ 347 348 /** */ 349 public static GType getType() 350 { 351 return gdk_pixbuf_get_type(); 352 } 353 354 /** 355 * Creates a new `GdkPixbuf` structure and allocates a buffer for it. 356 * 357 * If the allocation of the buffer failed, this function will return `NULL`. 358 * 359 * The buffer has an optimal rowstride. Note that the buffer is not cleared; 360 * you will have to fill it completely yourself. 361 * 362 * Params: 363 * colorspace = Color space for image 364 * hasAlpha = Whether the image should have transparency information 365 * bitsPerSample = Number of bits per color sample 366 * width = Width of image in pixels, must be > 0 367 * height = Height of image in pixels, must be > 0 368 * 369 * Returns: A newly-created pixel buffer 370 * 371 * Throws: ConstructionException GTK+ fails to create the object. 372 */ 373 public this(GdkColorspace colorspace, bool hasAlpha, int bitsPerSample, int width, int height) 374 { 375 auto __p = gdk_pixbuf_new(colorspace, hasAlpha, bitsPerSample, width, height); 376 377 if(__p is null) 378 { 379 throw new ConstructionException("null returned by new"); 380 } 381 382 this(cast(GdkPixbuf*) __p, true); 383 } 384 385 /** 386 * Creates a new #GdkPixbuf out of in-memory readonly image data. 387 * 388 * Currently only RGB images with 8 bits per sample are supported. 389 * 390 * This is the `GBytes` variant of gdk_pixbuf_new_from_data(), useful 391 * for language bindings. 392 * 393 * Params: 394 * data = Image data in 8-bit/sample packed format inside a #GBytes 395 * colorspace = Colorspace for the image data 396 * hasAlpha = Whether the data has an opacity channel 397 * bitsPerSample = Number of bits per sample 398 * width = Width of the image in pixels, must be > 0 399 * height = Height of the image in pixels, must be > 0 400 * rowstride = Distance in bytes between row starts 401 * 402 * Returns: A newly-created pixbuf 403 * 404 * Since: 2.32 405 * 406 * Throws: ConstructionException GTK+ fails to create the object. 407 */ 408 public this(Bytes data, GdkColorspace colorspace, bool hasAlpha, int bitsPerSample, int width, int height, int rowstride) 409 { 410 auto __p = gdk_pixbuf_new_from_bytes((data is null) ? null : data.getBytesStruct(), colorspace, hasAlpha, bitsPerSample, width, height, rowstride); 411 412 if(__p is null) 413 { 414 throw new ConstructionException("null returned by new_from_bytes"); 415 } 416 417 this(cast(GdkPixbuf*) __p, true); 418 } 419 420 /** 421 * Creates a new #GdkPixbuf out of in-memory image data. 422 * 423 * Currently only RGB images with 8 bits per sample are supported. 424 * 425 * Since you are providing a pre-allocated pixel buffer, you must also 426 * specify a way to free that data. This is done with a function of 427 * type `GdkPixbufDestroyNotify`. When a pixbuf created with is 428 * finalized, your destroy notification function will be called, and 429 * it is its responsibility to free the pixel array. 430 * 431 * See also: [ctor@GdkPixbuf.Pixbuf.new_from_bytes] 432 * 433 * Params: 434 * data = Image data in 8-bit/sample packed format 435 * colorspace = Colorspace for the image data 436 * hasAlpha = Whether the data has an opacity channel 437 * bitsPerSample = Number of bits per sample 438 * width = Width of the image in pixels, must be > 0 439 * height = Height of the image in pixels, must be > 0 440 * rowstride = Distance in bytes between row starts 441 * destroyFn = Function used to free the data when the pixbuf's reference count 442 * drops to zero, or %NULL if the data should not be freed 443 * destroyFnData = Closure data to pass to the destroy notification function 444 * 445 * Returns: A newly-created pixbuf 446 * 447 * Throws: ConstructionException GTK+ fails to create the object. 448 */ 449 public this(char[] data, GdkColorspace colorspace, bool hasAlpha, int bitsPerSample, int width, int height, int rowstride, GdkPixbufDestroyNotify destroyFn, void* destroyFnData) 450 { 451 auto __p = gdk_pixbuf_new_from_data(data.ptr, colorspace, hasAlpha, bitsPerSample, width, height, rowstride, destroyFn, destroyFnData); 452 453 if(__p is null) 454 { 455 throw new ConstructionException("null returned by new_from_data"); 456 } 457 458 this(cast(GdkPixbuf*) __p, true); 459 } 460 461 /** 462 * Creates a new pixbuf by loading an image from a file. 463 * 464 * The file format is detected automatically. 465 * 466 * If `NULL` is returned, then @error will be set. Possible errors are: 467 * 468 * - the file could not be opened 469 * - there is no loader for the file's format 470 * - there is not enough memory to allocate the image buffer 471 * - the image buffer contains invalid data 472 * 473 * The error domains are `GDK_PIXBUF_ERROR` and `G_FILE_ERROR`. 474 * 475 * Params: 476 * filename = Name of file to load, in the GLib file 477 * name encoding 478 * 479 * Returns: A newly-created pixbuf 480 * 481 * Throws: GException on failure. 482 * Throws: ConstructionException GTK+ fails to create the object. 483 */ 484 public this(string filename) 485 { 486 GError* err = null; 487 488 auto __p = gdk_pixbuf_new_from_file(Str.toStringz(filename), &err); 489 490 if (err !is null) 491 { 492 throw new GException( new ErrorG(err) ); 493 } 494 495 if(__p is null) 496 { 497 throw new ConstructionException("null returned by new_from_file"); 498 } 499 500 this(cast(GdkPixbuf*) __p, true); 501 } 502 503 /** 504 * Creates a new pixbuf by loading an image from a file. 505 * 506 * The file format is detected automatically. 507 * 508 * If `NULL` is returned, then @error will be set. Possible errors are: 509 * 510 * - the file could not be opened 511 * - there is no loader for the file's format 512 * - there is not enough memory to allocate the image buffer 513 * - the image buffer contains invalid data 514 * 515 * The error domains are `GDK_PIXBUF_ERROR` and `G_FILE_ERROR`. 516 * 517 * The image will be scaled to fit in the requested size, optionally preserving 518 * the image's aspect ratio. 519 * 520 * When preserving the aspect ratio, a `width` of -1 will cause the image 521 * to be scaled to the exact given height, and a `height` of -1 will cause 522 * the image to be scaled to the exact given width. When not preserving 523 * aspect ratio, a `width` or `height` of -1 means to not scale the image 524 * at all in that dimension. Negative values for `width` and `height` are 525 * allowed since 2.8. 526 * 527 * Params: 528 * filename = Name of file to load, in the GLib file 529 * name encoding 530 * width = The width the image should have or -1 to not constrain the width 531 * height = The height the image should have or -1 to not constrain the height 532 * preserveAspectRatio = `TRUE` to preserve the image's aspect ratio 533 * 534 * Returns: A newly-created pixbuf 535 * 536 * Since: 2.6 537 * 538 * Throws: GException on failure. 539 * Throws: ConstructionException GTK+ fails to create the object. 540 */ 541 public this(string filename, int width, int height, bool preserveAspectRatio) 542 { 543 GError* err = null; 544 545 auto __p = gdk_pixbuf_new_from_file_at_scale(Str.toStringz(filename), width, height, preserveAspectRatio, &err); 546 547 if (err !is null) 548 { 549 throw new GException( new ErrorG(err) ); 550 } 551 552 if(__p is null) 553 { 554 throw new ConstructionException("null returned by new_from_file_at_scale"); 555 } 556 557 this(cast(GdkPixbuf*) __p, true); 558 } 559 560 /** 561 * Creates a new pixbuf by loading an image from a file. 562 * 563 * The file format is detected automatically. 564 * 565 * If `NULL` is returned, then @error will be set. Possible errors are: 566 * 567 * - the file could not be opened 568 * - there is no loader for the file's format 569 * - there is not enough memory to allocate the image buffer 570 * - the image buffer contains invalid data 571 * 572 * The error domains are `GDK_PIXBUF_ERROR` and `G_FILE_ERROR`. 573 * 574 * The image will be scaled to fit in the requested size, preserving 575 * the image's aspect ratio. Note that the returned pixbuf may be smaller 576 * than `width` x `height`, if the aspect ratio requires it. To load 577 * and image at the requested size, regardless of aspect ratio, use 578 * [ctor@GdkPixbuf.Pixbuf.new_from_file_at_scale]. 579 * 580 * Params: 581 * filename = Name of file to load, in the GLib file 582 * name encoding 583 * width = The width the image should have or -1 to not constrain the width 584 * height = The height the image should have or -1 to not constrain the height 585 * 586 * Returns: A newly-created pixbuf 587 * 588 * Since: 2.4 589 * 590 * Throws: GException on failure. 591 * Throws: ConstructionException GTK+ fails to create the object. 592 */ 593 public this(string filename, int width, int height) 594 { 595 GError* err = null; 596 597 auto __p = gdk_pixbuf_new_from_file_at_size(Str.toStringz(filename), width, height, &err); 598 599 if (err !is null) 600 { 601 throw new GException( new ErrorG(err) ); 602 } 603 604 if(__p is null) 605 { 606 throw new ConstructionException("null returned by new_from_file_at_size"); 607 } 608 609 this(cast(GdkPixbuf*) __p, true); 610 } 611 612 /** 613 * Creates a `GdkPixbuf` from a flat representation that is suitable for 614 * storing as inline data in a program. 615 * 616 * This is useful if you want to ship a program with images, but don't want 617 * to depend on any external files. 618 * 619 * GdkPixbuf ships with a program called `gdk-pixbuf-csource`, which allows 620 * for conversion of `GdkPixbuf`s into such a inline representation. 621 * 622 * In almost all cases, you should pass the `--raw` option to 623 * `gdk-pixbuf-csource`. A sample invocation would be: 624 * 625 * ``` 626 * gdk-pixbuf-csource --raw --name=myimage_inline myimage.png 627 * ``` 628 * 629 * For the typical case where the inline pixbuf is read-only static data, 630 * you don't need to copy the pixel data unless you intend to write to 631 * it, so you can pass `FALSE` for `copy_pixels`. If you pass `--rle` to 632 * `gdk-pixbuf-csource`, a copy will be made even if `copy_pixels` is `FALSE`, 633 * so using this option is generally a bad idea. 634 * 635 * If you create a pixbuf from const inline data compiled into your 636 * program, it's probably safe to ignore errors and disable length checks, 637 * since things will always succeed: 638 * 639 * ```c 640 * pixbuf = gdk_pixbuf_new_from_inline (-1, myimage_inline, FALSE, NULL); 641 * ``` 642 * 643 * For non-const inline data, you could get out of memory. For untrusted 644 * inline data located at runtime, you could have corrupt inline data in 645 * addition. 646 * 647 * Deprecated: Use `GResource` instead. 648 * 649 * Params: 650 * data = Byte data containing a 651 * serialized `GdkPixdata` structure 652 * copyPixels = Whether to copy the pixel data, or use direct pointers 653 * `data` for the resulting pixbuf 654 * 655 * Returns: A newly-created pixbuf 656 * 657 * Throws: GException on failure. 658 * Throws: ConstructionException GTK+ fails to create the object. 659 */ 660 public this(ubyte[] data, bool copyPixels) 661 { 662 GError* err = null; 663 664 auto __p = gdk_pixbuf_new_from_inline(cast(int)data.length, data.ptr, copyPixels, &err); 665 666 if (err !is null) 667 { 668 throw new GException( new ErrorG(err) ); 669 } 670 671 if(__p is null) 672 { 673 throw new ConstructionException("null returned by new_from_inline"); 674 } 675 676 this(cast(GdkPixbuf*) __p, true); 677 } 678 679 /** 680 * Creates a new pixbuf by loading an image from an input stream. 681 * 682 * The file format is detected automatically. 683 * 684 * If `NULL` is returned, then `error` will be set. 685 * 686 * The `cancellable` can be used to abort the operation from another thread. 687 * If the operation was cancelled, the error `G_IO_ERROR_CANCELLED` will be 688 * returned. Other possible errors are in the `GDK_PIXBUF_ERROR` and 689 * `G_IO_ERROR` domains. 690 * 691 * The stream is not closed. 692 * 693 * Params: 694 * stream = a `GInputStream` to load the pixbuf from 695 * cancellable = optional `GCancellable` object, `NULL` to ignore 696 * 697 * Returns: A newly-created pixbuf 698 * 699 * Since: 2.14 700 * 701 * Throws: GException on failure. 702 * Throws: ConstructionException GTK+ fails to create the object. 703 */ 704 public this(InputStream stream, Cancellable cancellable) 705 { 706 GError* err = null; 707 708 auto __p = gdk_pixbuf_new_from_stream((stream is null) ? null : stream.getInputStreamStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 709 710 if (err !is null) 711 { 712 throw new GException( new ErrorG(err) ); 713 } 714 715 if(__p is null) 716 { 717 throw new ConstructionException("null returned by new_from_stream"); 718 } 719 720 this(cast(GdkPixbuf*) __p, true); 721 } 722 723 /** 724 * Creates a new pixbuf by loading an image from an input stream. 725 * 726 * The file format is detected automatically. If `NULL` is returned, then 727 * @error will be set. The @cancellable can be used to abort the operation 728 * from another thread. If the operation was cancelled, the error 729 * `G_IO_ERROR_CANCELLED` will be returned. Other possible errors are in 730 * the `GDK_PIXBUF_ERROR` and `G_IO_ERROR` domains. 731 * 732 * The image will be scaled to fit in the requested size, optionally 733 * preserving the image's aspect ratio. 734 * 735 * When preserving the aspect ratio, a `width` of -1 will cause the image to be 736 * scaled to the exact given height, and a `height` of -1 will cause the image 737 * to be scaled to the exact given width. If both `width` and `height` are 738 * given, this function will behave as if the smaller of the two values 739 * is passed as -1. 740 * 741 * When not preserving aspect ratio, a `width` or `height` of -1 means to not 742 * scale the image at all in that dimension. 743 * 744 * The stream is not closed. 745 * 746 * Params: 747 * stream = a `GInputStream` to load the pixbuf from 748 * width = The width the image should have or -1 to not constrain the width 749 * height = The height the image should have or -1 to not constrain the height 750 * preserveAspectRatio = `TRUE` to preserve the image's aspect ratio 751 * cancellable = optional `GCancellable` object, `NULL` to ignore 752 * 753 * Returns: A newly-created pixbuf 754 * 755 * Since: 2.14 756 * 757 * Throws: GException on failure. 758 * Throws: ConstructionException GTK+ fails to create the object. 759 */ 760 public this(InputStream stream, int width, int height, bool preserveAspectRatio, Cancellable cancellable) 761 { 762 GError* err = null; 763 764 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); 765 766 if (err !is null) 767 { 768 throw new GException( new ErrorG(err) ); 769 } 770 771 if(__p is null) 772 { 773 throw new ConstructionException("null returned by new_from_stream_at_scale"); 774 } 775 776 this(cast(GdkPixbuf*) __p, true); 777 } 778 779 /** 780 * Finishes an asynchronous pixbuf creation operation started with 781 * gdk_pixbuf_new_from_stream_async(). 782 * 783 * Params: 784 * asyncResult = a `GAsyncResult` 785 * 786 * Returns: the newly created pixbuf 787 * 788 * Since: 2.24 789 * 790 * Throws: GException on failure. 791 * Throws: ConstructionException GTK+ fails to create the object. 792 */ 793 public this(AsyncResultIF asyncResult) 794 { 795 GError* err = null; 796 797 auto __p = gdk_pixbuf_new_from_stream_finish((asyncResult is null) ? null : asyncResult.getAsyncResultStruct(), &err); 798 799 if (err !is null) 800 { 801 throw new GException( new ErrorG(err) ); 802 } 803 804 if(__p is null) 805 { 806 throw new ConstructionException("null returned by new_from_stream_finish"); 807 } 808 809 this(cast(GdkPixbuf*) __p, true); 810 } 811 812 /** 813 * Creates a new pixbuf by parsing XPM data in memory. 814 * 815 * This data is commonly the result of including an XPM file into a 816 * program's C source. 817 * 818 * Params: 819 * data = Pointer to inline XPM data. 820 * 821 * Returns: A newly-created pixbuf 822 * 823 * Throws: ConstructionException GTK+ fails to create the object. 824 */ 825 public this(string[] data) 826 { 827 auto __p = gdk_pixbuf_new_from_xpm_data(Str.toStringzArray(data)); 828 829 if(__p is null) 830 { 831 throw new ConstructionException("null returned by new_from_xpm_data"); 832 } 833 834 this(cast(GdkPixbuf*) __p, true); 835 } 836 837 /** 838 * Calculates the rowstride that an image created with those values would 839 * have. 840 * 841 * This function is useful for front-ends and backends that want to check 842 * image values without needing to create a `GdkPixbuf`. 843 * 844 * Params: 845 * colorspace = Color space for image 846 * hasAlpha = Whether the image should have transparency information 847 * bitsPerSample = Number of bits per color sample 848 * width = Width of image in pixels, must be > 0 849 * height = Height of image in pixels, must be > 0 850 * 851 * Returns: the rowstride for the given values, or -1 in case of error. 852 * 853 * Since: 2.36.8 854 */ 855 public static int calculateRowstride(GdkColorspace colorspace, bool hasAlpha, int bitsPerSample, int width, int height) 856 { 857 return gdk_pixbuf_calculate_rowstride(colorspace, hasAlpha, bitsPerSample, width, height); 858 } 859 860 /** 861 * Parses an image file far enough to determine its format and size. 862 * 863 * Params: 864 * filename = The name of the file to identify. 865 * width = Return location for the width of the image 866 * height = Return location for the height of the image 867 * 868 * Returns: A `GdkPixbufFormat` describing 869 * the image format of the file 870 * 871 * Since: 2.4 872 */ 873 public static PixbufFormat getFileInfo(string filename, out int width, out int height) 874 { 875 auto __p = gdk_pixbuf_get_file_info(Str.toStringz(filename), &width, &height); 876 877 if(__p is null) 878 { 879 return null; 880 } 881 882 return ObjectG.getDObject!(PixbufFormat)(cast(GdkPixbufFormat*) __p); 883 } 884 885 /** 886 * Asynchronously parses an image file far enough to determine its 887 * format and size. 888 * 889 * For more details see gdk_pixbuf_get_file_info(), which is the synchronous 890 * version of this function. 891 * 892 * When the operation is finished, @callback will be called in the 893 * main thread. You can then call gdk_pixbuf_get_file_info_finish() to 894 * get the result of the operation. 895 * 896 * Params: 897 * filename = The name of the file to identify 898 * cancellable = optional `GCancellable` object, `NULL` to ignore 899 * callback = a `GAsyncReadyCallback` to call when the file info is available 900 * userData = the data to pass to the callback function 901 * 902 * Since: 2.32 903 */ 904 public static void getFileInfoAsync(string filename, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 905 { 906 gdk_pixbuf_get_file_info_async(Str.toStringz(filename), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 907 } 908 909 /** 910 * Finishes an asynchronous pixbuf parsing operation started with 911 * gdk_pixbuf_get_file_info_async(). 912 * 913 * Params: 914 * asyncResult = a `GAsyncResult` 915 * width = Return location for the width of the image, or `NULL` 916 * height = Return location for the height of the image, or `NULL` 917 * 918 * Returns: A `GdkPixbufFormat` describing the 919 * image format of the file 920 * 921 * Since: 2.32 922 * 923 * Throws: GException on failure. 924 */ 925 public static PixbufFormat getFileInfoFinish(AsyncResultIF asyncResult, out int width, out int height) 926 { 927 GError* err = null; 928 929 auto __p = gdk_pixbuf_get_file_info_finish((asyncResult is null) ? null : asyncResult.getAsyncResultStruct(), &width, &height, &err); 930 931 if (err !is null) 932 { 933 throw new GException( new ErrorG(err) ); 934 } 935 936 if(__p is null) 937 { 938 return null; 939 } 940 941 return ObjectG.getDObject!(PixbufFormat)(cast(GdkPixbufFormat*) __p); 942 } 943 944 /** 945 * Obtains the available information about the image formats supported 946 * by GdkPixbuf. 947 * 948 * Returns: A list of 949 * support image formats. 950 * 951 * Since: 2.2 952 */ 953 public static ListSG getFormats() 954 { 955 auto __p = gdk_pixbuf_get_formats(); 956 957 if(__p is null) 958 { 959 return null; 960 } 961 962 return new ListSG(cast(GSList*) __p); 963 } 964 965 /** 966 * Initalizes the gdk-pixbuf loader modules referenced by the `loaders.cache` 967 * file present inside that directory. 968 * 969 * This is to be used by applications that want to ship certain loaders 970 * in a different location from the system ones. 971 * 972 * This is needed when the OS or runtime ships a minimal number of loaders 973 * so as to reduce the potential attack surface of carefully crafted image 974 * files, especially for uncommon file types. Applications that require 975 * broader image file types coverage, such as image viewers, would be 976 * expected to ship the gdk-pixbuf modules in a separate location, bundled 977 * with the application in a separate directory from the OS or runtime- 978 * provided modules. 979 * 980 * Params: 981 * path = Path to directory where the `loaders.cache` is installed 982 * 983 * Since: 2.40 984 * 985 * Throws: GException on failure. 986 */ 987 public static bool initModules(string path) 988 { 989 GError* err = null; 990 991 auto __p = gdk_pixbuf_init_modules(Str.toStringz(path), &err) != 0; 992 993 if (err !is null) 994 { 995 throw new GException( new ErrorG(err) ); 996 } 997 998 return __p; 999 } 1000 1001 /** 1002 * Creates a new pixbuf by asynchronously loading an image from an input stream. 1003 * 1004 * For more details see gdk_pixbuf_new_from_stream(), which is the synchronous 1005 * version of this function. 1006 * 1007 * When the operation is finished, @callback will be called in the main thread. 1008 * You can then call gdk_pixbuf_new_from_stream_finish() to get the result of 1009 * the operation. 1010 * 1011 * Params: 1012 * stream = a `GInputStream` from which to load the pixbuf 1013 * cancellable = optional `GCancellable` object, `NULL` to ignore 1014 * callback = a `GAsyncReadyCallback` to call when the pixbuf is loaded 1015 * userData = the data to pass to the callback function 1016 * 1017 * Since: 2.24 1018 */ 1019 public static void newFromStreamAsync(InputStream stream, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 1020 { 1021 gdk_pixbuf_new_from_stream_async((stream is null) ? null : stream.getInputStreamStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 1022 } 1023 1024 /** 1025 * Creates a new pixbuf by asynchronously loading an image from an input stream. 1026 * 1027 * For more details see gdk_pixbuf_new_from_stream_at_scale(), which is the synchronous 1028 * version of this function. 1029 * 1030 * When the operation is finished, @callback will be called in the main thread. 1031 * You can then call gdk_pixbuf_new_from_stream_finish() to get the result of the operation. 1032 * 1033 * Params: 1034 * stream = a `GInputStream` from which to load the pixbuf 1035 * width = the width the image should have or -1 to not constrain the width 1036 * height = the height the image should have or -1 to not constrain the height 1037 * preserveAspectRatio = `TRUE` to preserve the image's aspect ratio 1038 * cancellable = optional `GCancellable` object, `NULL` to ignore 1039 * callback = a `GAsyncReadyCallback` to call when the pixbuf is loaded 1040 * userData = the data to pass to the callback function 1041 * 1042 * Since: 2.24 1043 */ 1044 public static void newFromStreamAtScaleAsync(InputStream stream, int width, int height, bool preserveAspectRatio, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 1045 { 1046 gdk_pixbuf_new_from_stream_at_scale_async((stream is null) ? null : stream.getInputStreamStruct(), width, height, preserveAspectRatio, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 1047 } 1048 1049 /** 1050 * Finishes an asynchronous pixbuf save operation started with 1051 * gdk_pixbuf_save_to_stream_async(). 1052 * 1053 * Params: 1054 * asyncResult = a `GAsyncResult` 1055 * 1056 * Returns: `TRUE` if the pixbuf was saved successfully, `FALSE` if an error was set. 1057 * 1058 * Since: 2.24 1059 * 1060 * Throws: GException on failure. 1061 */ 1062 public static bool saveToStreamFinish(AsyncResultIF asyncResult) 1063 { 1064 GError* err = null; 1065 1066 auto __p = gdk_pixbuf_save_to_stream_finish((asyncResult is null) ? null : asyncResult.getAsyncResultStruct(), &err) != 0; 1067 1068 if (err !is null) 1069 { 1070 throw new GException( new ErrorG(err) ); 1071 } 1072 1073 return __p; 1074 } 1075 1076 /** 1077 * Takes an existing pixbuf and adds an alpha channel to it. 1078 * 1079 * If the existing pixbuf already had an alpha channel, the channel 1080 * values are copied from the original; otherwise, the alpha channel 1081 * is initialized to 255 (full opacity). 1082 * 1083 * If `substitute_color` is `TRUE`, then the color specified by the 1084 * (`r`, `g`, `b`) arguments will be assigned zero opacity. That is, 1085 * if you pass `(255, 255, 255)` for the substitute color, all white 1086 * pixels will become fully transparent. 1087 * 1088 * If `substitute_color` is `FALSE`, then the (`r`, `g`, `b`) arguments 1089 * will be ignored. 1090 * 1091 * Params: 1092 * substituteColor = Whether to set a color to zero opacity. 1093 * r = Red value to substitute. 1094 * g = Green value to substitute. 1095 * b = Blue value to substitute. 1096 * 1097 * Returns: A newly-created pixbuf 1098 */ 1099 public Pixbuf addAlpha(bool substituteColor, char r, char g, char b) 1100 { 1101 auto __p = gdk_pixbuf_add_alpha(gdkPixbuf, substituteColor, r, g, b); 1102 1103 if(__p is null) 1104 { 1105 return null; 1106 } 1107 1108 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) __p, true); 1109 } 1110 1111 /** 1112 * Takes an existing pixbuf and checks for the presence of an 1113 * associated "orientation" option. 1114 * 1115 * The orientation option may be provided by the JPEG loader (which 1116 * reads the exif orientation tag) or the TIFF loader (which reads 1117 * the TIFF orientation tag, and compensates it for the partial 1118 * transforms performed by libtiff). 1119 * 1120 * If an orientation option/tag is present, the appropriate transform 1121 * will be performed so that the pixbuf is oriented correctly. 1122 * 1123 * Returns: A newly-created pixbuf 1124 * 1125 * Since: 2.12 1126 */ 1127 public Pixbuf applyEmbeddedOrientation() 1128 { 1129 auto __p = gdk_pixbuf_apply_embedded_orientation(gdkPixbuf); 1130 1131 if(__p is null) 1132 { 1133 return null; 1134 } 1135 1136 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) __p, true); 1137 } 1138 1139 /** 1140 * Creates a transformation of the source image @src by scaling by 1141 * @scale_x and @scale_y then translating by @offset_x and @offset_y. 1142 * 1143 * This gives an image in the coordinates of the destination pixbuf. 1144 * The rectangle (@dest_x, @dest_y, @dest_width, @dest_height) 1145 * is then alpha blended onto the corresponding rectangle of the 1146 * original destination image. 1147 * 1148 * When the destination rectangle contains parts not in the source 1149 * image, the data at the edges of the source image is replicated 1150 * to infinity. 1151 * 1152 * ![](composite.png) 1153 * 1154 * Params: 1155 * dest = the #GdkPixbuf into which to render the results 1156 * destX = the left coordinate for region to render 1157 * destY = the top coordinate for region to render 1158 * destWidth = the width of the region to render 1159 * destHeight = the height of the region to render 1160 * offsetX = the offset in the X direction (currently rounded to an integer) 1161 * offsetY = the offset in the Y direction (currently rounded to an integer) 1162 * scaleX = the scale factor in the X direction 1163 * scaleY = the scale factor in the Y direction 1164 * interpType = the interpolation type for the transformation. 1165 * overallAlpha = overall alpha for source image (0..255) 1166 */ 1167 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) 1168 { 1169 gdk_pixbuf_composite(gdkPixbuf, (dest is null) ? null : dest.getPixbufStruct(), destX, destY, destWidth, destHeight, offsetX, offsetY, scaleX, scaleY, interpType, overallAlpha); 1170 } 1171 1172 /** 1173 * Creates a transformation of the source image @src by scaling by 1174 * @scale_x and @scale_y then translating by @offset_x and @offset_y, 1175 * then alpha blends the rectangle (@dest_x ,@dest_y, @dest_width, 1176 * @dest_height) of the resulting image with a checkboard of the 1177 * colors @color1 and @color2 and renders it onto the destination 1178 * image. 1179 * 1180 * If the source image has no alpha channel, and @overall_alpha is 255, a fast 1181 * path is used which omits the alpha blending and just performs the scaling. 1182 * 1183 * See gdk_pixbuf_composite_color_simple() for a simpler variant of this 1184 * function suitable for many tasks. 1185 * 1186 * Params: 1187 * dest = the #GdkPixbuf into which to render the results 1188 * destX = the left coordinate for region to render 1189 * destY = the top coordinate for region to render 1190 * destWidth = the width of the region to render 1191 * destHeight = the height of the region to render 1192 * offsetX = the offset in the X direction (currently rounded to an integer) 1193 * offsetY = the offset in the Y direction (currently rounded to an integer) 1194 * scaleX = the scale factor in the X direction 1195 * scaleY = the scale factor in the Y direction 1196 * interpType = the interpolation type for the transformation. 1197 * overallAlpha = overall alpha for source image (0..255) 1198 * checkX = the X offset for the checkboard (origin of checkboard is at -@check_x, -@check_y) 1199 * checkY = the Y offset for the checkboard 1200 * checkSize = the size of checks in the checkboard (must be a power of two) 1201 * color1 = the color of check at upper left 1202 * color2 = the color of the other check 1203 */ 1204 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) 1205 { 1206 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); 1207 } 1208 1209 /** 1210 * Creates a new pixbuf by scaling `src` to `dest_width` x `dest_height` 1211 * and alpha blending the result with a checkboard of colors `color1` 1212 * and `color2`. 1213 * 1214 * Params: 1215 * destWidth = the width of destination image 1216 * destHeight = the height of destination image 1217 * interpType = the interpolation type for the transformation. 1218 * overallAlpha = overall alpha for source image (0..255) 1219 * checkSize = the size of checks in the checkboard (must be a power of two) 1220 * color1 = the color of check at upper left 1221 * color2 = the color of the other check 1222 * 1223 * Returns: the new pixbuf 1224 */ 1225 public Pixbuf compositeColorSimple(int destWidth, int destHeight, GdkInterpType interpType, int overallAlpha, int checkSize, uint color1, uint color2) 1226 { 1227 auto __p = gdk_pixbuf_composite_color_simple(gdkPixbuf, destWidth, destHeight, interpType, overallAlpha, checkSize, color1, color2); 1228 1229 if(__p is null) 1230 { 1231 return null; 1232 } 1233 1234 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) __p, true); 1235 } 1236 1237 /** 1238 * Creates a new `GdkPixbuf` with a copy of the information in the specified 1239 * `pixbuf`. 1240 * 1241 * Note that this does not copy the options set on the original `GdkPixbuf`, 1242 * use gdk_pixbuf_copy_options() for this. 1243 * 1244 * Returns: A newly-created pixbuf 1245 */ 1246 public Pixbuf copy() 1247 { 1248 auto __p = gdk_pixbuf_copy(gdkPixbuf); 1249 1250 if(__p is null) 1251 { 1252 return null; 1253 } 1254 1255 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) __p, true); 1256 } 1257 1258 /** 1259 * Copies a rectangular area from `src_pixbuf` to `dest_pixbuf`. 1260 * 1261 * Conversion of pixbuf formats is done automatically. 1262 * 1263 * If the source rectangle overlaps the destination rectangle on the 1264 * same pixbuf, it will be overwritten during the copy operation. 1265 * Therefore, you can not use this function to scroll a pixbuf. 1266 * 1267 * Params: 1268 * srcX = Source X coordinate within @src_pixbuf. 1269 * srcY = Source Y coordinate within @src_pixbuf. 1270 * width = Width of the area to copy. 1271 * height = Height of the area to copy. 1272 * destPixbuf = Destination pixbuf. 1273 * destX = X coordinate within @dest_pixbuf. 1274 * destY = Y coordinate within @dest_pixbuf. 1275 */ 1276 public void copyArea(int srcX, int srcY, int width, int height, Pixbuf destPixbuf, int destX, int destY) 1277 { 1278 gdk_pixbuf_copy_area(gdkPixbuf, srcX, srcY, width, height, (destPixbuf is null) ? null : destPixbuf.getPixbufStruct(), destX, destY); 1279 } 1280 1281 /** 1282 * Copies the key/value pair options attached to a `GdkPixbuf` to another 1283 * `GdkPixbuf`. 1284 * 1285 * This is useful to keep original metadata after having manipulated 1286 * a file. However be careful to remove metadata which you've already 1287 * applied, such as the "orientation" option after rotating the image. 1288 * 1289 * Params: 1290 * destPixbuf = the destination pixbuf 1291 * 1292 * Returns: `TRUE` on success. 1293 * 1294 * Since: 2.36 1295 */ 1296 public bool copyOptions(Pixbuf destPixbuf) 1297 { 1298 return gdk_pixbuf_copy_options(gdkPixbuf, (destPixbuf is null) ? null : destPixbuf.getPixbufStruct()) != 0; 1299 } 1300 1301 /** 1302 * Clears a pixbuf to the given RGBA value, converting the RGBA value into 1303 * the pixbuf's pixel format. 1304 * 1305 * The alpha component will be ignored if the pixbuf doesn't have an alpha 1306 * channel. 1307 * 1308 * Params: 1309 * pixel = RGBA pixel to used to clear (`0xffffffff` is opaque white, 1310 * `0x00000000` transparent black) 1311 */ 1312 public void fill(uint pixel) 1313 { 1314 gdk_pixbuf_fill(gdkPixbuf, pixel); 1315 } 1316 1317 /** 1318 * Flips a pixbuf horizontally or vertically and returns the 1319 * result in a new pixbuf. 1320 * 1321 * Params: 1322 * horizontal = `TRUE` to flip horizontally, `FALSE` to flip vertically 1323 * 1324 * Returns: the new pixbuf 1325 * 1326 * Since: 2.6 1327 */ 1328 public Pixbuf flip(bool horizontal) 1329 { 1330 auto __p = gdk_pixbuf_flip(gdkPixbuf, horizontal); 1331 1332 if(__p is null) 1333 { 1334 return null; 1335 } 1336 1337 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) __p, true); 1338 } 1339 1340 /** 1341 * Queries the number of bits per color sample in a pixbuf. 1342 * 1343 * Returns: Number of bits per color sample. 1344 */ 1345 public int getBitsPerSample() 1346 { 1347 return gdk_pixbuf_get_bits_per_sample(gdkPixbuf); 1348 } 1349 1350 /** 1351 * Returns the length of the pixel data, in bytes. 1352 * 1353 * Returns: The length of the pixel data. 1354 * 1355 * Since: 2.26 1356 */ 1357 public size_t getByteLength() 1358 { 1359 return gdk_pixbuf_get_byte_length(gdkPixbuf); 1360 } 1361 1362 /** 1363 * Queries the color space of a pixbuf. 1364 * 1365 * Returns: Color space. 1366 */ 1367 public GdkColorspace getColorspace() 1368 { 1369 return gdk_pixbuf_get_colorspace(gdkPixbuf); 1370 } 1371 1372 /** 1373 * Queries whether a pixbuf has an alpha channel (opacity information). 1374 * 1375 * Returns: `TRUE` if it has an alpha channel, `FALSE` otherwise. 1376 */ 1377 public bool getHasAlpha() 1378 { 1379 return gdk_pixbuf_get_has_alpha(gdkPixbuf) != 0; 1380 } 1381 1382 /** 1383 * Queries the height of a pixbuf. 1384 * 1385 * Returns: Height in pixels. 1386 */ 1387 public int getHeight() 1388 { 1389 return gdk_pixbuf_get_height(gdkPixbuf); 1390 } 1391 1392 /** 1393 * Queries the number of channels of a pixbuf. 1394 * 1395 * Returns: Number of channels. 1396 */ 1397 public int getNChannels() 1398 { 1399 return gdk_pixbuf_get_n_channels(gdkPixbuf); 1400 } 1401 1402 /** 1403 * Looks up @key in the list of options that may have been attached to the 1404 * @pixbuf when it was loaded, or that may have been attached by another 1405 * function using gdk_pixbuf_set_option(). 1406 * 1407 * For instance, the ANI loader provides "Title" and "Artist" options. 1408 * The ICO, XBM, and XPM loaders provide "x_hot" and "y_hot" hot-spot 1409 * options for cursor definitions. The PNG loader provides the tEXt ancillary 1410 * chunk key/value pairs as options. Since 2.12, the TIFF and JPEG loaders 1411 * return an "orientation" option string that corresponds to the embedded 1412 * TIFF/Exif orientation tag (if present). Since 2.32, the TIFF loader sets 1413 * the "multipage" option string to "yes" when a multi-page TIFF is loaded. 1414 * Since 2.32 the JPEG and PNG loaders set "x-dpi" and "y-dpi" if the file 1415 * contains image density information in dots per inch. 1416 * Since 2.36.6, the JPEG loader sets the "comment" option with the comment 1417 * EXIF tag. 1418 * 1419 * Params: 1420 * key = a nul-terminated string. 1421 * 1422 * Returns: the value associated with `key` 1423 */ 1424 public string getOption(string key) 1425 { 1426 return Str.toString(gdk_pixbuf_get_option(gdkPixbuf, Str.toStringz(key))); 1427 } 1428 1429 /** 1430 * Returns a `GHashTable` with a list of all the options that may have been 1431 * attached to the `pixbuf` when it was loaded, or that may have been 1432 * attached by another function using [method@GdkPixbuf.Pixbuf.set_option]. 1433 * 1434 * Returns: a #GHashTable 1435 * of key/values pairs 1436 * 1437 * Since: 2.32 1438 */ 1439 public HashTable getOptions() 1440 { 1441 auto __p = gdk_pixbuf_get_options(gdkPixbuf); 1442 1443 if(__p is null) 1444 { 1445 return null; 1446 } 1447 1448 return new HashTable(cast(GHashTable*) __p); 1449 } 1450 1451 /** 1452 * Queries a pointer to the pixel data of a pixbuf. 1453 * 1454 * This function will cause an implicit copy of the pixbuf data if the 1455 * pixbuf was created from read-only data. 1456 * 1457 * Please see the section on [image data](#image-data) for information 1458 * about how the pixel data is stored in memory. 1459 * 1460 * Returns: A pointer to the pixbuf's 1461 * pixel data. 1462 * 1463 * Since: 2.26 1464 */ 1465 public char[] getPixelsWithLength() 1466 { 1467 uint length; 1468 1469 auto __p = gdk_pixbuf_get_pixels_with_length(gdkPixbuf, &length); 1470 1471 return __p[0 .. length]; 1472 } 1473 1474 /** 1475 * Queries the rowstride of a pixbuf, which is the number of bytes between 1476 * the start of a row and the start of the next row. 1477 * 1478 * Returns: Distance between row starts. 1479 */ 1480 public int getRowstride() 1481 { 1482 return gdk_pixbuf_get_rowstride(gdkPixbuf); 1483 } 1484 1485 /** 1486 * Queries the width of a pixbuf. 1487 * 1488 * Returns: Width in pixels. 1489 */ 1490 public int getWidth() 1491 { 1492 return gdk_pixbuf_get_width(gdkPixbuf); 1493 } 1494 1495 /** 1496 * Creates a new pixbuf which represents a sub-region of `src_pixbuf`. 1497 * 1498 * The new pixbuf shares its pixels with the original pixbuf, so 1499 * writing to one affects both. The new pixbuf holds a reference to 1500 * `src_pixbuf`, so `src_pixbuf` will not be finalized until the new 1501 * pixbuf is finalized. 1502 * 1503 * Note that if `src_pixbuf` is read-only, this function will force it 1504 * to be mutable. 1505 * 1506 * Params: 1507 * srcX = X coord in @src_pixbuf 1508 * srcY = Y coord in @src_pixbuf 1509 * width = width of region in @src_pixbuf 1510 * height = height of region in @src_pixbuf 1511 * 1512 * Returns: a new pixbuf 1513 */ 1514 public Pixbuf newSubpixbuf(int srcX, int srcY, int width, int height) 1515 { 1516 auto __p = gdk_pixbuf_new_subpixbuf(gdkPixbuf, srcX, srcY, width, height); 1517 1518 if(__p is null) 1519 { 1520 return null; 1521 } 1522 1523 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) __p, true); 1524 } 1525 1526 /** 1527 * Provides a #GBytes buffer containing the raw pixel data; the data 1528 * must not be modified. 1529 * 1530 * This function allows skipping the implicit copy that must be made 1531 * if gdk_pixbuf_get_pixels() is called on a read-only pixbuf. 1532 * 1533 * Returns: A new reference to a read-only copy of 1534 * the pixel data. Note that for mutable pixbufs, this function will 1535 * incur a one-time copy of the pixel data for conversion into the 1536 * returned #GBytes. 1537 * 1538 * Since: 2.32 1539 */ 1540 public Bytes readPixelBytes() 1541 { 1542 auto __p = gdk_pixbuf_read_pixel_bytes(gdkPixbuf); 1543 1544 if(__p is null) 1545 { 1546 return null; 1547 } 1548 1549 return new Bytes(cast(GBytes*) __p, true); 1550 } 1551 1552 /** 1553 * Provides a read-only pointer to the raw pixel data. 1554 * 1555 * This function allows skipping the implicit copy that must be made 1556 * if gdk_pixbuf_get_pixels() is called on a read-only pixbuf. 1557 * 1558 * Returns: a read-only pointer to the raw pixel data 1559 * 1560 * Since: 2.32 1561 */ 1562 public ubyte* readPixels() 1563 { 1564 return gdk_pixbuf_read_pixels(gdkPixbuf); 1565 } 1566 1567 /** 1568 * Removes the key/value pair option attached to a `GdkPixbuf`. 1569 * 1570 * Params: 1571 * key = a nul-terminated string representing the key to remove. 1572 * 1573 * Returns: `TRUE` if an option was removed, `FALSE` if not. 1574 * 1575 * Since: 2.36 1576 */ 1577 public bool removeOption(string key) 1578 { 1579 return gdk_pixbuf_remove_option(gdkPixbuf, Str.toStringz(key)) != 0; 1580 } 1581 1582 /** 1583 * Rotates a pixbuf by a multiple of 90 degrees, and returns the 1584 * result in a new pixbuf. 1585 * 1586 * If `angle` is 0, this function will return a copy of `src`. 1587 * 1588 * Params: 1589 * angle = the angle to rotate by 1590 * 1591 * Returns: the new pixbuf 1592 * 1593 * Since: 2.6 1594 */ 1595 public Pixbuf rotateSimple(GdkPixbufRotation angle) 1596 { 1597 auto __p = gdk_pixbuf_rotate_simple(gdkPixbuf, angle); 1598 1599 if(__p is null) 1600 { 1601 return null; 1602 } 1603 1604 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) __p, true); 1605 } 1606 1607 /** 1608 * Modifies saturation and optionally pixelates `src`, placing the result in 1609 * `dest`. 1610 * 1611 * The `src` and `dest` pixbufs must have the same image format, size, and 1612 * rowstride. 1613 * 1614 * The `src` and `dest` arguments may be the same pixbuf with no ill effects. 1615 * 1616 * If `saturation` is 1.0 then saturation is not changed. If it's less than 1.0, 1617 * saturation is reduced (the image turns toward grayscale); if greater than 1618 * 1.0, saturation is increased (the image gets more vivid colors). 1619 * 1620 * If `pixelate` is `TRUE`, then pixels are faded in a checkerboard pattern to 1621 * create a pixelated image. 1622 * 1623 * Params: 1624 * dest = place to write modified version of @src 1625 * saturation = saturation factor 1626 * pixelate = whether to pixelate 1627 */ 1628 public void saturateAndPixelate(Pixbuf dest, float saturation, bool pixelate) 1629 { 1630 gdk_pixbuf_saturate_and_pixelate(gdkPixbuf, (dest is null) ? null : dest.getPixbufStruct(), saturation, pixelate); 1631 } 1632 1633 /** 1634 * Vector version of `gdk_pixbuf_save_to_callback()`. 1635 * 1636 * Saves pixbuf to a callback in format @type, which is currently "jpeg", 1637 * "png", "tiff", "ico" or "bmp". 1638 * 1639 * If @error is set, `FALSE` will be returned. 1640 * 1641 * See [method@GdkPixbuf.Pixbuf.save_to_callback] for more details. 1642 * 1643 * Params: 1644 * saveFunc = a function that is called to save each block of data that 1645 * the save routine generates. 1646 * userData = user data to pass to the save function. 1647 * type = name of file format. 1648 * optionKeys = name of options to set 1649 * optionValues = values for named options 1650 * 1651 * Returns: whether an error was set 1652 * 1653 * Since: 2.4 1654 * 1655 * Throws: GException on failure. 1656 */ 1657 public bool saveToCallbackv(GdkPixbufSaveFunc saveFunc, void* userData, string type, string[] optionKeys, string[] optionValues) 1658 { 1659 GError* err = null; 1660 1661 auto __p = gdk_pixbuf_save_to_callbackv(gdkPixbuf, saveFunc, userData, Str.toStringz(type), Str.toStringzArray(optionKeys), Str.toStringzArray(optionValues), &err) != 0; 1662 1663 if (err !is null) 1664 { 1665 throw new GException( new ErrorG(err) ); 1666 } 1667 1668 return __p; 1669 } 1670 1671 /** 1672 * Saves `pixbuf` to an output stream. 1673 * 1674 * Supported file formats are currently "jpeg", "tiff", "png", "ico" or 1675 * "bmp". 1676 * 1677 * See [method@GdkPixbuf.Pixbuf.save_to_stream] for more details. 1678 * 1679 * Params: 1680 * stream = a `GOutputStream` to save the pixbuf to 1681 * type = name of file format 1682 * optionKeys = name of options to set 1683 * optionValues = values for named options 1684 * cancellable = optional `GCancellable` object, `NULL` to ignore 1685 * 1686 * Returns: `TRUE` if the pixbuf was saved successfully, `FALSE` if an 1687 * error was set. 1688 * 1689 * Since: 2.36 1690 * 1691 * Throws: GException on failure. 1692 */ 1693 public bool saveToStreamv(OutputStream stream, string type, string[] optionKeys, string[] optionValues, Cancellable cancellable) 1694 { 1695 GError* err = null; 1696 1697 auto __p = gdk_pixbuf_save_to_streamv(gdkPixbuf, (stream is null) ? null : stream.getOutputStreamStruct(), Str.toStringz(type), Str.toStringzArray(optionKeys), Str.toStringzArray(optionValues), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 1698 1699 if (err !is null) 1700 { 1701 throw new GException( new ErrorG(err) ); 1702 } 1703 1704 return __p; 1705 } 1706 1707 /** 1708 * Saves `pixbuf` to an output stream asynchronously. 1709 * 1710 * For more details see gdk_pixbuf_save_to_streamv(), which is the synchronous 1711 * version of this function. 1712 * 1713 * When the operation is finished, `callback` will be called in the main thread. 1714 * 1715 * You can then call gdk_pixbuf_save_to_stream_finish() to get the result of 1716 * the operation. 1717 * 1718 * Params: 1719 * stream = a `GOutputStream` to which to save the pixbuf 1720 * type = name of file format 1721 * optionKeys = name of options to set 1722 * optionValues = values for named options 1723 * cancellable = optional `GCancellable` object, `NULL` to ignore 1724 * callback = a `GAsyncReadyCallback` to call when the pixbuf is saved 1725 * userData = the data to pass to the callback function 1726 * 1727 * Since: 2.36 1728 */ 1729 public void saveToStreamvAsync(OutputStream stream, string type, string[] optionKeys, string[] optionValues, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 1730 { 1731 gdk_pixbuf_save_to_streamv_async(gdkPixbuf, (stream is null) ? null : stream.getOutputStreamStruct(), Str.toStringz(type), Str.toStringzArray(optionKeys), Str.toStringzArray(optionValues), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 1732 } 1733 1734 /** 1735 * Vector version of `gdk_pixbuf_save()`. 1736 * 1737 * Saves pixbuf to a file in `type`, which is currently "jpeg", "png", "tiff", "ico" or "bmp". 1738 * 1739 * If @error is set, `FALSE` will be returned. 1740 * 1741 * See [method@GdkPixbuf.Pixbuf.save] for more details. 1742 * 1743 * Params: 1744 * filename = name of file to save. 1745 * type = name of file format. 1746 * optionKeys = name of options to set 1747 * optionValues = values for named options 1748 * 1749 * Returns: whether an error was set 1750 * 1751 * Throws: GException on failure. 1752 */ 1753 public bool savev(string filename, string type, string[] optionKeys, string[] optionValues) 1754 { 1755 GError* err = null; 1756 1757 auto __p = gdk_pixbuf_savev(gdkPixbuf, Str.toStringz(filename), Str.toStringz(type), Str.toStringzArray(optionKeys), Str.toStringzArray(optionValues), &err) != 0; 1758 1759 if (err !is null) 1760 { 1761 throw new GException( new ErrorG(err) ); 1762 } 1763 1764 return __p; 1765 } 1766 1767 /** 1768 * Creates a transformation of the source image @src by scaling by 1769 * @scale_x and @scale_y then translating by @offset_x and @offset_y, 1770 * then renders the rectangle (@dest_x, @dest_y, @dest_width, 1771 * @dest_height) of the resulting image onto the destination image 1772 * replacing the previous contents. 1773 * 1774 * Try to use gdk_pixbuf_scale_simple() first; this function is 1775 * the industrial-strength power tool you can fall back to, if 1776 * gdk_pixbuf_scale_simple() isn't powerful enough. 1777 * 1778 * If the source rectangle overlaps the destination rectangle on the 1779 * same pixbuf, it will be overwritten during the scaling which 1780 * results in rendering artifacts. 1781 * 1782 * Params: 1783 * dest = the #GdkPixbuf into which to render the results 1784 * destX = the left coordinate for region to render 1785 * destY = the top coordinate for region to render 1786 * destWidth = the width of the region to render 1787 * destHeight = the height of the region to render 1788 * offsetX = the offset in the X direction (currently rounded to an integer) 1789 * offsetY = the offset in the Y direction (currently rounded to an integer) 1790 * scaleX = the scale factor in the X direction 1791 * scaleY = the scale factor in the Y direction 1792 * interpType = the interpolation type for the transformation. 1793 */ 1794 public void scale(Pixbuf dest, int destX, int destY, int destWidth, int destHeight, double offsetX, double offsetY, double scaleX, double scaleY, GdkInterpType interpType) 1795 { 1796 gdk_pixbuf_scale(gdkPixbuf, (dest is null) ? null : dest.getPixbufStruct(), destX, destY, destWidth, destHeight, offsetX, offsetY, scaleX, scaleY, interpType); 1797 } 1798 1799 /** 1800 * Create a new pixbuf containing a copy of `src` scaled to 1801 * `dest_width` x `dest_height`. 1802 * 1803 * This function leaves `src` unaffected. 1804 * 1805 * The `interp_type` should be `GDK_INTERP_NEAREST` if you want maximum 1806 * speed (but when scaling down `GDK_INTERP_NEAREST` is usually unusably 1807 * ugly). The default `interp_type` should be `GDK_INTERP_BILINEAR` which 1808 * offers reasonable quality and speed. 1809 * 1810 * You can scale a sub-portion of `src` by creating a sub-pixbuf 1811 * pointing into `src`; see [method@GdkPixbuf.Pixbuf.new_subpixbuf]. 1812 * 1813 * If `dest_width` and `dest_height` are equal to the width and height of 1814 * `src`, this function will return an unscaled copy of `src`. 1815 * 1816 * For more complicated scaling/alpha blending see [method@GdkPixbuf.Pixbuf.scale] 1817 * and [method@GdkPixbuf.Pixbuf.composite]. 1818 * 1819 * Params: 1820 * destWidth = the width of destination image 1821 * destHeight = the height of destination image 1822 * interpType = the interpolation type for the transformation. 1823 * 1824 * Returns: the new pixbuf 1825 */ 1826 public Pixbuf scaleSimple(int destWidth, int destHeight, GdkInterpType interpType) 1827 { 1828 auto __p = gdk_pixbuf_scale_simple(gdkPixbuf, destWidth, destHeight, interpType); 1829 1830 if(__p is null) 1831 { 1832 return null; 1833 } 1834 1835 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) __p, true); 1836 } 1837 1838 /** 1839 * Attaches a key/value pair as an option to a `GdkPixbuf`. 1840 * 1841 * If `key` already exists in the list of options attached to the `pixbuf`, 1842 * the new value is ignored and `FALSE` is returned. 1843 * 1844 * Params: 1845 * key = a nul-terminated string. 1846 * value = a nul-terminated string. 1847 * 1848 * Returns: `TRUE` on success 1849 * 1850 * Since: 2.2 1851 */ 1852 public bool setOption(string key, string value) 1853 { 1854 return gdk_pixbuf_set_option(gdkPixbuf, Str.toStringz(key), Str.toStringz(value)) != 0; 1855 } 1856 }