Pixbuf

#------------------------------------------------------------------------------- #--[Class Description]---------------------------------------------------------- #-------------------------------------------------------------------------------

Gnome::GdkPixbuf::Pixbuf

Description

A pixel buffer.

Gnome::GdkPixbuf::Pixbuf contains information about an image's pixel data, its color space, bits per sample, width and height, and the rowstride (the number of bytes between the start of one row and the start of the next).

Creating new Gnome::GdkPixbuf::Pixbuf

The most basic way to create a pixbuf is to wrap an existing pixel buffer with a Gnome::GdkPixbuf::Pixbuf instance. You can use the [ctor $GdkPixbuf.Pixbuf.new_from_data] function to do this.

Every time you create a new Gnome::GdkPixbuf::Pixbuf instance for some data, you will need to specify the destroy notification function that will be called when the data buffer needs to be freed; this will happen when a Gnome::GdkPixbuf::Pixbuf is finalized by the reference counting functions. If you have a chunk of static data compiled into your application, you can pass in undefined as the destroy notification function so that the data will not be freed.

The [ctor $GdkPixbuf.Pixbuf.new] constructor function can be used as a convenience to create a pixbuf with an empty buffer; this is equivalent to allocating a data buffer using malloc() and then wrapping it with .new-from-data(). The .new-pixbuf() function will compute an optimal rowstride so that rendering can be performed with an efficient algorithm.

As a special case, you can use the [ctor $GdkPixbuf.Pixbuf.new_from_xpm_data] function to create a pixbuf from inline XPM image data.

You can also copy an existing pixbuf with the [method $Pixbuf.copy] function. This is not the same as just acquiring a reference to the old pixbuf instance: the copy function will actually duplicate the pixel data in memory and create a new Pixbuf instance for it.

Reference counting

Gnome::GdkPixbuf::Pixbuf structures are reference counted. This means that an application can share a single pixbuf among many parts of the code. When a piece of the program needs to use a pixbuf, it should acquire a reference to it by calling g_object_ref(); when it no longer needs the pixbuf, it should release the reference it acquired by calling g_object_unref(). The resources associated with a Gnome::GdkPixbuf::Pixbuf will be freed when its reference count drops to zero. Newly-created Gnome::GdkPixbuf::Pixbuf instances start with a reference count of one.

Image Data

Image data in a pixbuf is stored in memory in an uncompressed, packed format. Rows in the image are stored top to bottom, and in each row pixels are stored from left to right.

There may be padding at the end of a row.

The "rowstride" value of a pixbuf, as returned by [method $GdkPixbuf.Pixbuf.get_rowstride], indicates the number of bytes between rows.

**NOTE**: If you are copying raw pixbuf data with memcpy() note that the last row in the pixbuf may not be as wide as the full rowstride, but rather just as wide as the pixel data needs to be; that is: it is unsafe to do memcpy (dest, pixels, rowstride * height) to copy a whole pixbuf. Use .copy() in class Gnome::GdkPixbuf::Pixbuf instead, or compute the width in bytes of the last row as:

The same rule applies when iterating over each row of a Gnome::GdkPixbuf::Pixbuf pixels array.

The following code illustrates a simple put_pixel() function for RGB pixbufs with 8 bits per channel with an alpha channel.

Loading images

The GdkPixBuf class provides a simple mechanism for loading an image from a file in synchronous and asynchronous fashion.

For GUI applications, it is recommended to use the asynchronous stream API to avoid blocking the control flow of the application.

Additionally, Gnome::GdkPixbuf::Pixbuf provides the Gnome::GdkPixbuf::Pixbuf API for progressive image loading.

Saving images

The >GdkPixbuf class provides methods for saving image data in a number of file formats. The formatted data can be written to a file or to a memory buffer. GdkPixbufB< can also call a user-defined callback on the data, which allows to e.g. write the image to a socket or store it in a database.

#------------------------------------------------------------------------------- #--[Class Initialization]------------------------------------------------------- #-------------------------------------------------------------------------------

Class initialization

new

:native-object

Create an object using a native object from elsewhere. See also Gnome::N::TopLevelSupportClass.

multi method new ( N-Object :$native-object! )

#-------------------------------------------------------------------------------

new-gdkpixbuf

Creates a new >GdkPixbufB< structure and allocates a buffer for it.

If the allocation of the buffer failed, this function will return undefined.

The buffer has an optimal rowstride. Note that the buffer is not cleared; you will have to fill it completely yourself.

method new-gdkpixbuf ( GdkColorspace $colorspace, Bool() $has-alpha, Int() $bits-per-sample, Int() $width, Int() $height --> Gnome::GdkPixbuf::Pixbuf \)
  • $colorspace; Color space for image.

  • $has-alpha; Whether the image should have transparency information.

  • $bits-per-sample; Number of bits per color sample.

  • $width; Width of image in pixels, must be > 0.

  • $height; Height of image in pixels, must be > 0.

#-------------------------------------------------------------------------------

new-from-bytes

Creates a new Gnome::GdkPixbuf::Pixbuf out of in-memory readonly image data.

Currently only RGB images with 8 bits per sample are supported.

This is the >GBytesB< variant of .new-from-data(), useful for language bindings.

method new-from-bytes ( N-Object $data, GdkColorspace $colorspace, Bool() $has-alpha, Int() $bits-per-sample, Int() $width, Int() $height, Int() $rowstride --> Gnome::GdkPixbuf::Pixbuf \)
  • $data; Image data in 8-bit/sample packed format inside a Gnome::Glib::N-Bytes

  • $colorspace; Colorspace for the image data.

  • $has-alpha; Whether the data has an opacity channel.

  • $bits-per-sample; Number of bits per sample.

  • $width; Width of the image in pixels, must be > 0.

  • $height; Height of the image in pixels, must be > 0.

  • $rowstride; Distance in bytes between row starts.

#-------------------------------------------------------------------------------

new-from-data

Creates a new Gnome::GdkPixbuf::Pixbuf out of in-memory image data.

Currently only RGB images with 8 bits per sample are supported.

Since you are providing a pre-allocated pixel buffer, you must also specify a way to free that data. This is done with a function of type >GdkPixbufDestroyNotifyB<. When a pixbuf created with is finalized, your destroy notification function will be called, and it is its responsibility to free the pixel array.

See also: .new-from-bytes() in class Gnome::GdkPixbuf::Pixbuf

method new-from-data ( Str $data, GdkColorspace $colorspace, Bool() $has-alpha, Int() $bits-per-sample, Int() $width, Int() $height, Int() $rowstride, &destroy-fn, gpointer $destroy-fn-data --> Gnome::GdkPixbuf::Pixbuf \)
  • $data; Image data in 8-bit/sample packed format.

  • $colorspace; Colorspace for the image data.

  • $has-alpha; Whether the data has an opacity channel.

  • $bits-per-sample; Number of bits per sample.

  • $width; Width of the image in pixels, must be > 0.

  • $height; Height of the image in pixels, must be > 0.

  • $rowstride; Distance in bytes between row starts.

  • &destroy-fn; Function used to free the data when the pixbuf's reference count drops to zero, or undefined if the data should not be freed. Tthe function must be specified with following signature; :( Str $pixels, gpointer $data ).

  • $destroy-fn-data; Closure data to pass to the destroy notification function.

#-------------------------------------------------------------------------------

new-from-file

Creates a new pixbuf by loading an image from a file.

The file format is detected automatically.

If undefined is returned, then $error will be set. Possible errors are:

  • the file could not be opened

  • there is no loader for the file's format

  • there is not enough memory to allocate the image buffer

  • the image buffer contains invalid data

The error domains are >GDK_PIXBUF_ERROR and G_FILE_ERRORB<.

method new-from-file ( Str $filename, CArray[N-Error] $err --> Gnome::GdkPixbuf::Pixbuf \)
  • $filename; Name of file to load, in the GLib file name encoding.

  • $err; Error object. When defined, an error can be returned when there is one. Use Pointer when you want to ignore the error. .

#-------------------------------------------------------------------------------

new-from-file-at-scale

Creates a new pixbuf by loading an image from a file.

The file format is detected automatically.

If undefined is returned, then $error will be set. Possible errors are:

  • the file could not be opened

  • there is no loader for the file's format

  • there is not enough memory to allocate the image buffer

  • the image buffer contains invalid data

The error domains are >GDK_PIXBUF_ERROR and G_FILE_ERRORB<.

The image will be scaled to fit in the requested size, optionally preserving the image's aspect ratio.

When preserving the aspect ratio, a >width of -1 will cause the image to be scaled to the exact given height, and a height of -1 will cause the image to be scaled to the exact given width. When not preserving aspect ratio, a width or height of -1 means to not scale the image at all in that dimension. Negative values for width and heightB< are allowed since 2.8.

method new-from-file-at-scale ( Str $filename, Int() $width, Int() $height, Bool() $preserve-aspect-ratio, CArray[N-Error] $err --> Gnome::GdkPixbuf::Pixbuf \)
  • $filename; Name of file to load, in the GLib file name encoding.

  • $width; The width the image should have or -1 to not constrain the width.

  • $height; The height the image should have or -1 to not constrain the height.

  • $preserve-aspect-ratio; True to preserve the image's aspect ratio.

  • $err; Error object. When defined, an error can be returned when there is one. Use Pointer when you want to ignore the error. .

#-------------------------------------------------------------------------------

new-from-file-at-size

Creates a new pixbuf by loading an image from a file.

The file format is detected automatically.

If undefined is returned, then $error will be set. Possible errors are:

  • the file could not be opened

  • there is no loader for the file's format

  • there is not enough memory to allocate the image buffer

  • the image buffer contains invalid data

The error domains are >GDK_PIXBUF_ERROR and G_FILE_ERRORB<.

The image will be scaled to fit in the requested size, preserving the image's aspect ratio. Note that the returned pixbuf may be smaller than >width x heightB<, if the aspect ratio requires it. To load and image at the requested size, regardless of aspect ratio, use .new-from-file-at-scale() in class Gnome::GdkPixbuf::Pixbuf.

method new-from-file-at-size ( Str $filename, Int() $width, Int() $height, CArray[N-Error] $err --> Gnome::GdkPixbuf::Pixbuf \)
  • $filename; Name of file to load, in the GLib file name encoding.

  • $width; The width the image should have or -1 to not constrain the width.

  • $height; The height the image should have or -1 to not constrain the height.

  • $err; Error object. When defined, an error can be returned when there is one. Use Pointer when you want to ignore the error. .

#-------------------------------------------------------------------------------

new-from-resource

Creates a new pixbuf by loading an image from an resource.

The file format is detected automatically. If undefined is returned, then $error will be set.

method new-from-resource ( Str $resource-path, CArray[N-Error] $err --> Gnome::GdkPixbuf::Pixbuf \)
  • $resource-path; the path of the resource file.

  • $err; Error object. When defined, an error can be returned when there is one. Use Pointer when you want to ignore the error. .

#-------------------------------------------------------------------------------

new-from-resource-at-scale

Creates a new pixbuf by loading an image from an resource.

The file format is detected automatically. If undefined is returned, then $error will be set.

The image will be scaled to fit in the requested size, optionally preserving the image's aspect ratio. When preserving the aspect ratio, a $width of -1 will cause the image to be scaled to the exact given height, and a $height of -1 will cause the image to be scaled to the exact given width. When not preserving aspect ratio, a $width or $height of -1 means to not scale the image at all in that dimension.

The stream is not closed.

method new-from-resource-at-scale ( Str $resource-path, Int() $width, Int() $height, Bool() $preserve-aspect-ratio, CArray[N-Error] $err --> Gnome::GdkPixbuf::Pixbuf \)
  • $resource-path; the path of the resource file.

  • $width; The width the image should have or -1 to not constrain the width.

  • $height; The height the image should have or -1 to not constrain the height.

  • $preserve-aspect-ratio; True to preserve the image's aspect ratio.

  • $err; Error object. When defined, an error can be returned when there is one. Use Pointer when you want to ignore the error. .

#-------------------------------------------------------------------------------

new-from-stream

Creates a new pixbuf by loading an image from an input stream.

The file format is detected automatically.

If undefined is returned, then >errorB< will be set.

The >cancellable can be used to abort the operation from another thread. If the operation was cancelled, the error G_IO_ERROR_CANCELLED will be returned. Other possible errors are in the GDK_PIXBUF_ERROR and G_IO_ERRORB< domains.

The stream is not closed.

method new-from-stream ( N-Object() $stream, N-Object() $cancellable, CArray[N-Error] $err --> Gnome::GdkPixbuf::Pixbuf \)
  • $stream; a >GInputStreamB< to load the pixbuf from.

  • $cancellable; optional >GCancellableB< object, undefined to ignore.

  • $err; Error object. When defined, an error can be returned when there is one. Use Pointer when you want to ignore the error. .

#-------------------------------------------------------------------------------

new-from-stream-at-scale

Creates a new pixbuf by loading an image from an input stream.

The file format is detected automatically. If undefined is returned, then $error will be set. The $cancellable can be used to abort the operation from another thread. If the operation was cancelled, the error >G_IO_ERROR_CANCELLED will be returned. Other possible errors are in the GDK_PIXBUF_ERROR and G_IO_ERRORB< domains.

The image will be scaled to fit in the requested size, optionally preserving the image's aspect ratio.

When preserving the aspect ratio, a >width of -1 will cause the image to be scaled to the exact given height, and a height of -1 will cause the image to be scaled to the exact given width. If both width and heightB< are given, this function will behave as if the smaller of the two values is passed as -1.

When not preserving aspect ratio, a >width or heightB< of -1 means to not scale the image at all in that dimension.

The stream is not closed.

method new-from-stream-at-scale ( N-Object() $stream, Int() $width, Int() $height, Bool() $preserve-aspect-ratio, N-Object() $cancellable, CArray[N-Error] $err --> Gnome::GdkPixbuf::Pixbuf \)
  • $stream; a >GInputStreamB< to load the pixbuf from.

  • $width; The width the image should have or -1 to not constrain the width.

  • $height; The height the image should have or -1 to not constrain the height.

  • $preserve-aspect-ratio; True to preserve the image's aspect ratio.

  • $cancellable; optional >GCancellableB< object, undefined to ignore.

  • $err; Error object. When defined, an error can be returned when there is one. Use Pointer when you want to ignore the error. .

#-------------------------------------------------------------------------------

new-from-stream-finish

Finishes an asynchronous pixbuf creation operation started with .new-from-stream-async().

method new-from-stream-finish ( N-Object() $async-result, CArray[N-Error] $err --> Gnome::GdkPixbuf::Pixbuf \)
  • $async-result; a >GAsyncResultB<.

  • $err; Error object. When defined, an error can be returned when there is one. Use Pointer when you want to ignore the error. .

#-------------------------------------------------------------------------------

new-from-xpm-data

Creates a new pixbuf by parsing XPM data in memory.

This data is commonly the result of including an XPM file into a program's C source.

method new-from-xpm-data ( Array[Str] $data --> Gnome::GdkPixbuf::Pixbuf \)
  • $data; Pointer to inline XPM data..

#------------------------------------------------------------------------------- #--[Methods]-------------------------------------------------------------------- #-------------------------------------------------------------------------------

Methods

#-------------------------------------------------------------------------------

add-alpha

Takes an existing pixbuf and adds an alpha channel to it.

If the existing pixbuf already had an alpha channel, the channel values are copied from the original; otherwise, the alpha channel is initialized to 255 (full opacity).

If >substitute_color is True, then the color specified by the (r, g, b) arguments will be assigned zero opacity. That is, if you pass (255, 255, 255)B< for the substitute color, all white pixels will become fully transparent.

If >substitute_color is False, then the (r, g, bB<) arguments will be ignored.

method add-alpha ( Bool() $substitute-color, UInt() $r, UInt() $g, UInt() $b --> N-Object )
  • $substitute-color; Whether to set a color to zero opacity..

  • $r; Red value to substitute..

  • $g; Green value to substitute..

  • $b; Blue value to substitute..

Return value; A newly-created pixbuf.

#-------------------------------------------------------------------------------

apply-embedded-orientation

Takes an existing pixbuf and checks for the presence of an associated "orientation" option.

The orientation option may be provided by the JPEG loader (which reads the exif orientation tag) or the TIFF loader (which reads the TIFF orientation tag, and compensates it for the partial transforms performed by libtiff).

If an orientation option/tag is present, the appropriate transform will be performed so that the pixbuf is oriented correctly.

method apply-embedded-orientation (--> N-Object )

Return value; A newly-created pixbuf.

#-------------------------------------------------------------------------------

composite This function is not yet available

Creates a transformation of the source image $src by scaling by $scale-x and $scale-y then translating by $offset-x and $offset-y.

This gives an image in the coordinates of the destination pixbuf. The rectangle ( $dest-x, $dest-y, $dest-width, $dest-height) is then alpha blended onto the corresponding rectangle of the original destination image.

When the destination rectangle contains parts not in the source image, the data at the edges of the source image is replicated to infinity.

![](composite.png)

method composite ( N-Object() $dest, Int() $dest-x, Int() $dest-y, Int() $dest-width, Int() $dest-height, Num() $offset-x, Num() $offset-y, Num() $scale-x, Num() $scale-y, GdkInterpType  $interp-type, Int() $overall-alpha )
  • $dest; the Gnome::GdkPixbuf::Pixbuf into which to render the results.

  • $dest-x; the left coordinate for region to render.

  • $dest-y; the top coordinate for region to render.

  • $dest-width; the width of the region to render.

  • $dest-height; the height of the region to render.

  • $offset-x; the offset in the X direction (currently rounded to an integer).

  • $offset-y; the offset in the Y direction (currently rounded to an integer).

  • $scale-x; the scale factor in the X direction.

  • $scale-y; the scale factor in the Y direction.

  • $interp-type; the interpolation type for the transformation..

  • $overall-alpha; overall alpha for source image (0..255).

#-------------------------------------------------------------------------------

composite-color This function is not yet available

Creates a transformation of the source image $src by scaling by $scale-x and $scale-y then translating by $offset-x and $offset-y, then alpha blends the rectangle ( $dest-x , $dest-y, $dest-width, $dest-height) of the resulting image with a checkboard of the colors $color1 and $color2 and renders it onto the destination image.

If the source image has no alpha channel, and $overall-alpha is 255, a fast path is used which omits the alpha blending and just performs the scaling.

See .composite-color-simple() for a simpler variant of this function suitable for many tasks.

method composite-color ( N-Object() $dest, Int() $dest-x, Int() $dest-y, Int() $dest-width, Int() $dest-height, Num() $offset-x, Num() $offset-y, Num() $scale-x, Num() $scale-y, GdkInterpType  $interp-type, Int() $overall-alpha, Int() $check-x, Int() $check-y, Int() $check-size, UInt() $color1, UInt() $color2 )
  • $dest; the Gnome::GdkPixbuf::Pixbuf into which to render the results.

  • $dest-x; the left coordinate for region to render.

  • $dest-y; the top coordinate for region to render.

  • $dest-width; the width of the region to render.

  • $dest-height; the height of the region to render.

  • $offset-x; the offset in the X direction (currently rounded to an integer).

  • $offset-y; the offset in the Y direction (currently rounded to an integer).

  • $scale-x; the scale factor in the X direction.

  • $scale-y; the scale factor in the Y direction.

  • $interp-type; the interpolation type for the transformation..

  • $overall-alpha; overall alpha for source image (0..255).

  • $check-x; the X offset for the checkboard (origin of checkboard is at - $check-x, - $check-y).

  • $check-y; the Y offset for the checkboard.

  • $check-size; the size of checks in the checkboard (must be a power of two).

  • $color1; the color of check at upper left.

  • $color2; the color of the other check.

#-------------------------------------------------------------------------------

composite-color-simple This function is not yet available

Creates a new pixbuf by scaling >src to dest_width x dest_height and alpha blending the result with a checkboard of colors color1 and color2B<.

method composite-color-simple ( Int() $dest-width, Int() $dest-height, GdkInterpType  $interp-type, Int() $overall-alpha, Int() $check-size, UInt() $color1, UInt() $color2 --> N-Object )
  • $dest-width; the width of destination image.

  • $dest-height; the height of destination image.

  • $interp-type; the interpolation type for the transformation..

  • $overall-alpha; overall alpha for source image (0..255).

  • $check-size; the size of checks in the checkboard (must be a power of two).

  • $color1; the color of check at upper left.

  • $color2; the color of the other check.

Return value; the new pixbuf.

#-------------------------------------------------------------------------------

copy

Creates a new >GdkPixbuf with a copy of the information in the specified pixbufB<.

Note that this does not copy the options set on the original >GdkPixbufB<, use .copy-options() for this.

method copy (--> N-Object )

Return value; A newly-created pixbuf.

#-------------------------------------------------------------------------------

copy-area

Copies a rectangular area from >src_pixbuf to dest_pixbufB<.

Conversion of pixbuf formats is done automatically.

If the source rectangle overlaps the destination rectangle on the same pixbuf, it will be overwritten during the copy operation. Therefore, you can not use this function to scroll a pixbuf.

method copy-area ( Int() $src-x, Int() $src-y, Int() $width, Int() $height, N-Object() $dest-pixbuf, Int() $dest-x, Int() $dest-y )
  • $src-x; Source X coordinate within $src-pixbuf..

  • $src-y; Source Y coordinate within $src-pixbuf..

  • $width; Width of the area to copy..

  • $height; Height of the area to copy..

  • $dest-pixbuf; Destination pixbuf..

  • $dest-x; X coordinate within $dest-pixbuf..

  • $dest-y; Y coordinate within $dest-pixbuf..

#-------------------------------------------------------------------------------

copy-options

Copies the key/value pair options attached to a >GdkPixbuf to another GdkPixbufB<.

This is useful to keep original metadata after having manipulated a file. However be careful to remove metadata which you've already applied, such as the "orientation" option after rotating the image.

method copy-options ( N-Object() $dest-pixbuf --> Bool )
  • $dest-pixbuf; the destination pixbuf.

Return value; True on success..

#-------------------------------------------------------------------------------

fill

Clears a pixbuf to the given RGBA value, converting the RGBA value into the pixbuf's pixel format.

The alpha component will be ignored if the pixbuf doesn't have an alpha channel.

method fill ( UInt() $pixel )
  • $pixel; RGBA pixel to used to clear (>0xffffffff is opaque white, 0x00000000B< transparent black).

#-------------------------------------------------------------------------------

flip

Flips a pixbuf horizontally or vertically and returns the result in a new pixbuf.

method flip ( Bool() $horizontal --> N-Object )
  • $horizontal; True to flip horizontally, False to flip vertically.

Return value; the new pixbuf.

#-------------------------------------------------------------------------------

get-bits-per-sample

Queries the number of bits per color sample in a pixbuf.

method get-bits-per-sample (--> Int )

Return value; Number of bits per color sample..

#-------------------------------------------------------------------------------

get-byte-length

Returns the length of the pixel data, in bytes.

method get-byte-length (--> Int )

Return value; The length of the pixel data..

#-------------------------------------------------------------------------------

get-colorspace

Queries the color space of a pixbuf.

method get-colorspace (--> GdkColorspace )

Return value; Color space..

#-------------------------------------------------------------------------------

get-has-alpha

Queries whether a pixbuf has an alpha channel (opacity information).

method get-has-alpha (--> Bool )

Return value; True if it has an alpha channel, False otherwise..

#-------------------------------------------------------------------------------

get-height

Queries the height of a pixbuf.

method get-height (--> Int )

Return value; Height in pixels..

#-------------------------------------------------------------------------------

get-n-channels

Queries the number of channels of a pixbuf.

method get-n-channels (--> Int )

Return value; Number of channels..

#-------------------------------------------------------------------------------

get-option

Looks up $key in the list of options that may have been attached to the $pixbuf when it was loaded, or that may have been attached by another function using .set-option().

For instance, the ANI loader provides "Title" and "Artist" options. The ICO, XBM, and XPM loaders provide "x_hot" and "y_hot" hot-spot options for cursor definitions. The PNG loader provides the tEXt ancillary chunk key/value pairs as options. Since 2.12, the TIFF and JPEG loaders return an "orientation" option string that corresponds to the embedded TIFF/Exif orientation tag (if present). Since 2.32, the TIFF loader sets the "multipage" option string to "yes" when a multi-page TIFF is loaded. Since 2.32 the JPEG and PNG loaders set "x-dpi" and "y-dpi" if the file contains image density information in dots per inch. Since 2.36.6, the JPEG loader sets the "comment" option with the comment EXIF tag.

method get-option ( Str $key --> Str )
  • $key; a nul-terminated string..

Return value; the value associated with >keyB<.

#-------------------------------------------------------------------------------

get-options

Returns a >GHashTable with a list of all the options that may have been attached to the pixbufB< when it was loaded, or that may have been attached by another function using .set-option() in class Gnome::GdkPixbuf::Pixbuf.

method get-options (--> N-Object )

Return value; a Gnome::Glib::N-HashTable of key/values pairs.

#-------------------------------------------------------------------------------

get-pixels

Queries a pointer to the pixel data of a pixbuf.

This function will cause an implicit copy of the pixbuf data if the pixbuf was created from read-only data.

Please see the section on [image data](class.Pixbuf.html#image-data) for information about how the pixel data is stored in memory.

method get-pixels (--> Str )

Return value; A pointer to the pixbuf's pixel data..

#-------------------------------------------------------------------------------

get-pixels-with-length

Queries a pointer to the pixel data of a pixbuf.

This function will cause an implicit copy of the pixbuf data if the pixbuf was created from read-only data.

Please see the section on [image data](class.Pixbuf.html#image-data) for information about how the pixel data is stored in memory.

method get-pixels-with-length ( Array[Int] $length --> Str )
  • $length; (transfer ownership: full) The length of the binary data..

Return value; A pointer to the pixbuf's pixel data..

#-------------------------------------------------------------------------------

get-rowstride

Queries the rowstride of a pixbuf, which is the number of bytes between the start of a row and the start of the next row.

method get-rowstride (--> Int )

Return value; Distance between row starts..

#-------------------------------------------------------------------------------

get-width

Queries the width of a pixbuf.

method get-width (--> Int )

Return value; Width in pixels..

#-------------------------------------------------------------------------------

new-subpixbuf

Creates a new pixbuf which represents a sub-region of >src_pixbufB<.

The new pixbuf shares its pixels with the original pixbuf, so writing to one affects both. The new pixbuf holds a reference to >src_pixbuf, so src_pixbufB< will not be finalized until the new pixbuf is finalized.

Note that if >src_pixbufB< is read-only, this function will force it to be mutable.

method new-subpixbuf ( Int() $src-x, Int() $src-y, Int() $width, Int() $height --> N-Object )
  • $src-x; X coord in $src-pixbuf.

  • $src-y; Y coord in $src-pixbuf.

  • $width; width of region in $src-pixbuf.

  • $height; height of region in $src-pixbuf.

Return value; a new pixbuf.

#-------------------------------------------------------------------------------

read-pixel-bytes

Provides a Gnome::Glib::N-Bytes buffer containing the raw pixel data; the data must not be modified.

This function allows skipping the implicit copy that must be made if .get-pixels() is called on a read-only pixbuf.

method read-pixel-bytes (--> N-Object )

Return value; A new reference to a read-only copy of the pixel data. Note that for mutable pixbufs, this function will incur a one-time copy of the pixel data for conversion into the returned Gnome::Glib::N-Bytes..

#-------------------------------------------------------------------------------

read-pixels

Provides a read-only pointer to the raw pixel data.

This function allows skipping the implicit copy that must be made if .get-pixels() is called on a read-only pixbuf.

method read-pixels (--> Array[Int] )

Return value; a read-only pointer to the raw pixel data.

#-------------------------------------------------------------------------------

remove-option

Removes the key/value pair option attached to a >GdkPixbufB<.

method remove-option ( Str $key --> Bool )
  • $key; a nul-terminated string representing the key to remove..

Return value; True if an option was removed, False if not..

#-------------------------------------------------------------------------------

rotate-simple This function is not yet available

Rotates a pixbuf by a multiple of 90 degrees, and returns the result in a new pixbuf.

If >angle is 0, this function will return a copy of srcB<.

method rotate-simple ( GdkPixbufRotation  $angle --> N-Object )
  • $angle; the angle to rotate by.

Return value; the new pixbuf.

#-------------------------------------------------------------------------------

saturate-and-pixelate

Modifies saturation and optionally pixelates >src, placing the result in destB<.

The >src and destB< pixbufs must have the same image format, size, and rowstride.

The >src and destB< arguments may be the same pixbuf with no ill effects.

If >saturationB< is 1.0 then saturation is not changed. If it's less than 1.0, saturation is reduced (the image turns toward grayscale); if greater than 1.0, saturation is increased (the image gets more vivid colors).

If >pixelateB< is True, then pixels are faded in a checkerboard pattern to create a pixelated image.

method saturate-and-pixelate ( N-Object() $dest, Num() $saturation, Bool() $pixelate )
  • $dest; place to write modified version of $src.

  • $saturation; saturation factor.

  • $pixelate; whether to pixelate.

#-------------------------------------------------------------------------------

save This function is not yet available

Saves pixbuf to a file in format $type. By default, "jpeg", "png", "ico" and "bmp" are possible file formats to save in, but more formats may be installed. The list of all writable formats can be determined in the following way:

If >error is set, False will be returned. Possible errors include those in the GDK_PIXBUF_ERROR domain and those in the G_FILE_ERRORB< domain.

The variable argument list should be undefined-terminated; if not empty, it should contain pairs of strings that modify the save parameters. For example:

Currently only few parameters exist.

JPEG images can be saved with a "quality" parameter; its value should be in the range >[0, 100]B<. JPEG and PNG density can be set by setting the "x-dpi" and "y-dpi" parameters to the appropriate values in dots per inch.

Text chunks can be attached to PNG images by specifying parameters of the form "tEXt::key", where key is an ASCII string of length 1-79. The values are UTF-8 encoded strings. The PNG compression level can be specified using the "compression" parameter; it's value is in an integer in the range of >[0, 9]B<.

ICC color profiles can also be embedded into PNG, JPEG and TIFF images. The "icc-profile" value should be the complete ICC profile encoded into base64.

TIFF images recognize:

1. a "bits-per-sample" option (integer) which can be either 1 for saving
    bi-level CCITTFAX4 images, or 8 for saving 8-bits per sample
 2. a "compression" option (integer) which can be 1 for no compression,
    2 for Huffman, 5 for LZW, 7 for JPEG and 8 for DEFLATE (see the libtiff
    documentation and tiff.h for all supported codec values)
 3. an "icc-profile" option (zero-terminated string) containing a base64
    encoded ICC color profile.

ICO images can be saved in depth 16, 24, or 32, by using the "depth" parameter. When the ICO saver is given "x_hot" and "y_hot" parameters, it produces a CUR instead of an ICO.

method save ( Str $filename, Str $type, N-Object $error, … --> Bool )
  • $filename; name of file to save..

  • $type; name of file format..

  • $error; return location for error

  • …; …. Note that each argument must be specified as a type followed by its value!

Return value; True on success, and False otherwise.

#-------------------------------------------------------------------------------

save-to-buffer This function is not yet available

Saves pixbuf to a new buffer in format >typeB<, which is currently "jpeg", "png", "tiff", "ico" or "bmp".

This is a convenience function that uses >.save-to-callback()B< to do the real work.

Note that the buffer is not >NUL-terminated and may contain embedded NULB< characters.

If $error is set, False will be returned and $buffer will be set to undefined. Possible errors include those in the >GDK_PIXBUF_ERRORB< domain.

See >.save()B< for more details.

method save-to-buffer ( Array[Str] $buffer, Array[gsize] $buffer-size, Str $type, N-Object $error, … --> Bool )
  • $buffer; (transfer ownership: full) location to receive a pointer to the new buffer..

  • $buffer-size; (transfer ownership: full) location to receive the size of the new buffer..

  • $type; name of file format..

  • $error; return location for error, or undefined

  • …; …. Note that each argument must be specified as a type followed by its value!

Return value; whether an error was set.

#-------------------------------------------------------------------------------

save-to-bufferv

Vector version of >.save-to-buffer()B<.

Saves pixbuf to a new buffer in format $type, which is currently "jpeg", "tiff", "png", "ico" or "bmp".

See .save-to-buffer() in class Gnome::GdkPixbuf::Pixbuf for more details.

method save-to-bufferv ( Array[Str] $buffer, Array[gsize] $buffer-size, Str $type, Array[Str] $option-keys, Array[Str] $option-values, CArray[N-Error] $err --> Bool )
  • $buffer; (transfer ownership: full) location to receive a pointer to the new buffer..

  • $buffer-size; (transfer ownership: full) location to receive the size of the new buffer..

  • $type; name of file format..

  • $option-keys; name of options to set.

  • $option-values; values for named options.

  • $err; Error object. When defined, an error can be returned when there is one. Use Pointer when you want to ignore the error. .

Return value; whether an error was set.

#-------------------------------------------------------------------------------

save-to-callback This function is not yet available

Saves pixbuf in format >typeB< by feeding the produced data to a callback.

This function can be used when you want to store the image to something other than a file, such as an in-memory buffer or a socket.

If $error is set, False will be returned. Possible errors include those in the >GDK_PIXBUF_ERRORB< domain and whatever the save function generates.

See .save() in class Gnome::GdkPixbuf::Pixbuf for more details.

method save-to-callback ( &save-func, gpointer $user-data, Str $type, N-Object $error, … --> Bool )
  • &save-func; a function that is called to save each block of data that the save routine generates.. Tthe function must be specified with following signature; :( Str $buf, gsize $count, N-Object $error, gpointer $data -- gboolean )>.

  • $user-data; user data to pass to the save function..

  • $type; name of file format..

  • $error; return location for error, or undefined

  • …; …. Note that each argument must be specified as a type followed by its value!

Return value; whether an error was set.

#-------------------------------------------------------------------------------

save-to-callbackv

Vector version of >.save-to-callback()B<.

Saves pixbuf to a callback in format $type, which is currently "jpeg", "png", "tiff", "ico" or "bmp".

If $error is set, False will be returned.

See .save-to-callback() in class Gnome::GdkPixbuf::Pixbuf for more details.

method save-to-callbackv ( &save-func, gpointer $user-data, Str $type, Array[Str] $option-keys, Array[Str] $option-values, CArray[N-Error] $err --> Bool )
  • &save-func; a function that is called to save each block of data that the save routine generates.. Tthe function must be specified with following signature; :( Str $buf, gsize $count, N-Object $error, gpointer $data -- gboolean )>.

  • $user-data; user data to pass to the save function..

  • $type; name of file format..

  • $option-keys; name of options to set.

  • $option-values; values for named options.

  • $err; Error object. When defined, an error can be returned when there is one. Use Pointer when you want to ignore the error. .

Return value; whether an error was set.

#-------------------------------------------------------------------------------

save-to-stream This function is not yet available

Saves >pixbufB< to an output stream.

Supported file formats are currently "jpeg", "tiff", "png", "ico" or "bmp". See >.save-to-buffer()B< for more details.

The >cancellable can be used to abort the operation from another thread. If the operation was cancelled, the error G_IO_ERROR_CANCELLED will be returned. Other possible errors are in the GDK_PIXBUF_ERROR and G_IO_ERRORB< domains.

The stream is not closed at the end of this call.

method save-to-stream ( N-Object() $stream, Str $type, N-Object() $cancellable, N-Object $error, … --> Bool )
  • $stream; a >GOutputStreamB< to save the pixbuf to.

  • $type; name of file format.

  • $cancellable; optional >GCancellableB< object, undefined to ignore.

  • $error; return location for error, or undefined

  • …; …. Note that each argument must be specified as a type followed by its value!

Return value; True if the pixbuf was saved successfully, False if an error was set..

#-------------------------------------------------------------------------------

save-to-stream-async This function is not yet available

Saves >pixbufB< to an output stream asynchronously.

For more details see .save-to-stream(), which is the synchronous version of this function.

When the operation is finished, >callbackB< will be called in the main thread.

You can then call .save-to-stream-finish() to get the result of the operation.

method save-to-stream-async ( N-Object() $stream, Str $type, N-Object() $cancellable, …, gpointer $user-data, … )
  • $stream; a >GOutputStreamB< to which to save the pixbuf.

  • $type; name of file format.

  • $cancellable; optional >GCancellableB< object, undefined to ignore.

  • callback; a >GAsyncReadyCallbackB< to call when the pixbuf is saved. Note that each argument must be specified as a type followed by its value!

  • $user-data; the data to pass to the callback function.

  • …; …. Note that each argument must be specified as a type followed by its value!

#-------------------------------------------------------------------------------

save-to-streamv

Saves >pixbufB< to an output stream.

Supported file formats are currently "jpeg", "tiff", "png", "ico" or "bmp".

See .save-to-stream() in class Gnome::GdkPixbuf::Pixbuf for more details.

method save-to-streamv ( N-Object() $stream, Str $type, Array[Str] $option-keys, Array[Str] $option-values, N-Object() $cancellable, CArray[N-Error] $err --> Bool )
  • $stream; a >GOutputStreamB< to save the pixbuf to.

  • $type; name of file format.

  • $option-keys; name of options to set.

  • $option-values; values for named options.

  • $cancellable; optional >GCancellableB< object, undefined to ignore.

  • $err; Error object. When defined, an error can be returned when there is one. Use Pointer when you want to ignore the error. .

Return value; True if the pixbuf was saved successfully, False if an error was set..

#-------------------------------------------------------------------------------

save-to-streamv-async This function is not yet available

Saves >pixbufB< to an output stream asynchronously.

For more details see .save-to-streamv(), which is the synchronous version of this function.

When the operation is finished, >callbackB< will be called in the main thread.

You can then call .save-to-stream-finish() to get the result of the operation.

method save-to-streamv-async ( N-Object() $stream, Str $type, Array[Str] $option-keys, Array[Str] $option-values, N-Object() $cancellable, …, gpointer $user-data )
  • $stream; a >GOutputStreamB< to which to save the pixbuf.

  • $type; name of file format.

  • $option-keys; name of options to set.

  • $option-values; values for named options.

  • $cancellable; optional >GCancellableB< object, undefined to ignore.

  • callback; a >GAsyncReadyCallbackB< to call when the pixbuf is saved. Note that each argument must be specified as a type followed by its value!

  • $user-data; the data to pass to the callback function.

#-------------------------------------------------------------------------------

savev

Vector version of >.save()B<.

Saves pixbuf to a file in >typeB<, which is currently "jpeg", "png", "tiff", "ico" or "bmp".

If $error is set, False will be returned.

See .save() in class Gnome::GdkPixbuf::Pixbuf for more details.

method savev ( Str $filename, Str $type, Array[Str] $option-keys, Array[Str] $option-values, CArray[N-Error] $err --> Bool )
  • $filename; name of file to save..

  • $type; name of file format..

  • $option-keys; name of options to set.

  • $option-values; values for named options.

  • $err; Error object. When defined, an error can be returned when there is one. Use Pointer when you want to ignore the error. .

Return value; whether an error was set.

#-------------------------------------------------------------------------------

scale This function is not yet available

Creates a transformation of the source image $src by scaling by $scale-x and $scale-y then translating by $offset-x and $offset-y, then renders the rectangle ( $dest-x, $dest-y, $dest-width, $dest-height) of the resulting image onto the destination image replacing the previous contents.

Try to use .scale-simple() first; this function is the industrial-strength power tool you can fall back to, if .scale-simple() isn't powerful enough.

If the source rectangle overlaps the destination rectangle on the same pixbuf, it will be overwritten during the scaling which results in rendering artifacts.

method scale ( N-Object() $dest, Int() $dest-x, Int() $dest-y, Int() $dest-width, Int() $dest-height, Num() $offset-x, Num() $offset-y, Num() $scale-x, Num() $scale-y, GdkInterpType  $interp-type )
  • $dest; the Gnome::GdkPixbuf::Pixbuf into which to render the results.

  • $dest-x; the left coordinate for region to render.

  • $dest-y; the top coordinate for region to render.

  • $dest-width; the width of the region to render.

  • $dest-height; the height of the region to render.

  • $offset-x; the offset in the X direction (currently rounded to an integer).

  • $offset-y; the offset in the Y direction (currently rounded to an integer).

  • $scale-x; the scale factor in the X direction.

  • $scale-y; the scale factor in the Y direction.

  • $interp-type; the interpolation type for the transformation..

#-------------------------------------------------------------------------------

scale-simple This function is not yet available

Create a new pixbuf containing a copy of >src scaled to dest_width x dest_heightB<.

This function leaves >srcB< unaffected.

The >interp_type should be GDK_INTERP_NEAREST if you want maximum speed (but when scaling down GDK_INTERP_NEAREST is usually unusably ugly). The default interp_type should be GDK_INTERP_BILINEARB< which offers reasonable quality and speed.

You can scale a sub-portion of >src by creating a sub-pixbuf pointing into srcB<; see .new-subpixbuf() in class Gnome::GdkPixbuf::Pixbuf.

If >dest_width and dest_height are equal to the width and height of src, this function will return an unscaled copy of srcB<.

For more complicated scaling/alpha blending see .scale() in class Gnome::GdkPixbuf::Pixbuf and .composite() in class Gnome::GdkPixbuf::Pixbuf.

method scale-simple ( Int() $dest-width, Int() $dest-height, GdkInterpType  $interp-type --> N-Object )
  • $dest-width; the width of destination image.

  • $dest-height; the height of destination image.

  • $interp-type; the interpolation type for the transformation..

Return value; the new pixbuf.

#-------------------------------------------------------------------------------

set-option

Attaches a key/value pair as an option to a >GdkPixbufB<.

If >key already exists in the list of options attached to the pixbufB<, the new value is ignored and False is returned.

method set-option ( Str $key, Str $value --> Bool )
  • $key; a nul-terminated string..

  • $value; a nul-terminated string..

Return value; True on success.

#------------------------------------------------------------------------------- #--[Functions]------------------------------------------------------------------ #-------------------------------------------------------------------------------

Functions

#-------------------------------------------------------------------------------

calculate-rowstride

Calculates the rowstride that an image created with those values would have.

This function is useful for front-ends and backends that want to check image values without needing to create a >GdkPixbufB<.

method calculate-rowstride ( GdkColorspace $colorspace, Bool() $has-alpha, Int() $bits-per-sample, Int() $width, Int() $height --> Int )
  • $colorspace; Color space for image.

  • $has-alpha; Whether the image should have transparency information.

  • $bits-per-sample; Number of bits per color sample.

  • $width; Width of image in pixels, must be > 0.

  • $height; Height of image in pixels, must be > 0.

Return value; the rowstride for the given values, or -1 in case of error..

#-------------------------------------------------------------------------------

get-file-info

Parses an image file far enough to determine its format and size.

method get-file-info ( Str $filename, Array[Int] $width, Array[Int] $height --> N-Object )
  • $filename; The name of the file to identify..

  • $width; (transfer ownership: full) Return location for the width of the image.

  • $height; (transfer ownership: full) Return location for the height of the image.

Return value; A >GdkPixbufFormatB< describing the image format of the file.

#-------------------------------------------------------------------------------

get-file-info-async This function is not yet available

Asynchronously parses an image file far enough to determine its format and size.

For more details see .get-file-info(), which is the synchronous version of this function.

When the operation is finished, $callback will be called in the main thread. You can then call .get-file-info-finish() to get the result of the operation.

method get-file-info-async ( Str $filename, N-Object() $cancellable, …, gpointer $user-data )
  • $filename; The name of the file to identify.

  • $cancellable; optional >GCancellableB< object, undefined to ignore.

  • callback; a >GAsyncReadyCallbackB< to call when the file info is available. Note that each argument must be specified as a type followed by its value!

  • $user-data; the data to pass to the callback function.

#-------------------------------------------------------------------------------

get-file-info-finish

Finishes an asynchronous pixbuf parsing operation started with .get-file-info-async().

method get-file-info-finish ( N-Object() $async-result, Array[Int] $width, Array[Int] $height, CArray[N-Error] $err --> N-Object )
  • $async-result; a >GAsyncResultB<.

  • $width; (transfer ownership: full) Return location for the width of the image, or undefined.

  • $height; (transfer ownership: full) Return location for the height of the image, or undefined.

  • $err; Error object. When defined, an error can be returned when there is one. Use Pointer when you want to ignore the error. .

Return value; A >GdkPixbufFormatB< describing the image format of the file.

#-------------------------------------------------------------------------------

get-formats

Obtains the available information about the image formats supported by GdkPixbuf.

method get-formats (--> N-SList )

Return value; A list of support image formats..

#-------------------------------------------------------------------------------

init-modules

Initalizes the gdk-pixbuf loader modules referenced by the >loaders.cacheB< file present inside that directory.

This is to be used by applications that want to ship certain loaders in a different location from the system ones.

This is needed when the OS or runtime ships a minimal number of loaders so as to reduce the potential attack surface of carefully crafted image files, especially for uncommon file types. Applications that require broader image file types coverage, such as image viewers, would be expected to ship the gdk-pixbuf modules in a separate location, bundled with the application in a separate directory from the OS or runtime- provided modules.

method init-modules ( Str $path, CArray[N-Error] $err --> Bool )
  • $path; Path to directory where the >loaders.cacheB< is installed.

  • $err; Error object. When defined, an error can be returned when there is one. Use Pointer when you want to ignore the error. .

Return value; No documentation about its value and use.

#-------------------------------------------------------------------------------

new-from-stream-async This function is not yet available

Creates a new pixbuf by asynchronously loading an image from an input stream.

For more details see .new-from-stream(), which is the synchronous version of this function.

When the operation is finished, $callback will be called in the main thread. You can then call .new-from-stream-finish() to get the result of the operation.

method new-from-stream-async ( N-Object() $stream, N-Object() $cancellable, …, gpointer $user-data )
  • $stream; a >GInputStreamB< from which to load the pixbuf.

  • $cancellable; optional >GCancellableB< object, undefined to ignore.

  • callback; a >GAsyncReadyCallbackB< to call when the pixbuf is loaded. Note that each argument must be specified as a type followed by its value!

  • $user-data; the data to pass to the callback function.

#-------------------------------------------------------------------------------

new-from-stream-at-scale-async This function is not yet available

Creates a new pixbuf by asynchronously loading an image from an input stream.

For more details see .new-from-stream-at-scale(), which is the synchronous version of this function.

When the operation is finished, $callback will be called in the main thread. You can then call .new-from-stream-finish() to get the result of the operation.

method new-from-stream-at-scale-async ( N-Object() $stream, Int() $width, Int() $height, Bool() $preserve-aspect-ratio, N-Object() $cancellable, …, gpointer $user-data )
  • $stream; a >GInputStreamB< from which to load the pixbuf.

  • $width; the width the image should have or -1 to not constrain the width.

  • $height; the height the image should have or -1 to not constrain the height.

  • $preserve-aspect-ratio; True to preserve the image's aspect ratio.

  • $cancellable; optional >GCancellableB< object, undefined to ignore.

  • callback; a >GAsyncReadyCallbackB< to call when the pixbuf is loaded. Note that each argument must be specified as a type followed by its value!

  • $user-data; the data to pass to the callback function.

#-------------------------------------------------------------------------------

save-to-stream-finish

Finishes an asynchronous pixbuf save operation started with .save-to-stream-async().

method save-to-stream-finish ( N-Object() $async-result, CArray[N-Error] $err --> Bool )
  • $async-result; a >GAsyncResult`.

  • $err; Error object. When defined, an error can be returned when there is one. Use Pointer when you want to ignore the error. .

Return value; True if the pixbuf was saved successfully, False if an error was set..

Gnome::GdkPixbuf v0.1.3

Modules for Gnome::Pixbuf:api<2>. Graphical media loading and manipulation

Authors

  • Marcel Timmerman

License

Artistic-2.0

Dependencies

Gnome::GObject:api<2>Gnome::Glib:api<2>Gnome::Gio:api<2>Gnome::N:api<2>

Test Dependencies

Provides

  • Gnome::GdkPixbuf::Pixbuf
  • Gnome::GdkPixbuf::T-core

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.