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