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