Structures
The following structures are available globally.
-
Modules supporting animations must derive a type from
GdkPixbufAnimation, providing suitable implementations of the virtual functions.The
See morePixbufAnimationClassReftype acts as a lightweight Swift reference to an underlyingGdkPixbufAnimationClassinstance. It exposes methods that can operate on this data type throughPixbufAnimationClassProtocolconformance. UsePixbufAnimationClassRefonly as anunownedreference to an existingGdkPixbufAnimationClassinstance.Declaration
Swift
public struct PixbufAnimationClassRef : PixbufAnimationClassProtocol
-
Modules supporting animations must derive a type from
GdkPixbufAnimationIter, providing suitable implementations of the virtual functions.The
See morePixbufAnimationIterClassReftype acts as a lightweight Swift reference to an underlyingGdkPixbufAnimationIterClassinstance. It exposes methods that can operate on this data type throughPixbufAnimationIterClassProtocolconformance. UsePixbufAnimationIterClassRefonly as anunownedreference to an existingGdkPixbufAnimationIterClassinstance.Declaration
Swift
public struct PixbufAnimationIterClassRef : PixbufAnimationIterClassProtocol
-
A
GdkPixbufFormatcontains information about the image format accepted by a module.Only modules should access the fields directly, applications should use the
gdk_pixbuf_format_*family of functions.The
See morePixbufFormatReftype acts as a lightweight Swift reference to an underlyingGdkPixbufFormatinstance. It exposes methods that can operate on this data type throughPixbufFormatProtocolconformance. UsePixbufFormatRefonly as anunownedreference to an existingGdkPixbufFormatinstance.Declaration
Swift
public struct PixbufFormatRef : PixbufFormatProtocol
-
The
See morePixbufLoaderClassReftype acts as a lightweight Swift reference to an underlyingGdkPixbufLoaderClassinstance. It exposes methods that can operate on this data type throughPixbufLoaderClassProtocolconformance. UsePixbufLoaderClassRefonly as anunownedreference to an existingGdkPixbufLoaderClassinstance.Declaration
Swift
public struct PixbufLoaderClassRef : PixbufLoaderClassProtocol
-
A
GdkPixbufModulecontains the necessary functions to load and save images in a certain file format.If
GdkPixbufhas been compiled withGModulesupport, it can be extended by modules which can load (and perhaps also save) new image and animation formats.Implementing modules
The
GdkPixbufinterfaces needed for implementing modules are contained ingdk-pixbuf-io.h(andgdk-pixbuf-animation.hif the module supports animations). They are not covered by the same stability guarantees as the regular GdkPixbuf API. To underline this fact, they are protected by theGDK_PIXBUF_ENABLE_BACKENDpre-processor symbol.Each loadable module must contain a
GdkPixbufModuleFillVtableFuncfunction namedfill_vtable, which will get called when the module is loaded and must set the function pointers of theGdkPixbufModule.In order to make format-checking work before actually loading the modules (which may require calling
dlopento load image libraries), modules export their signatures (and other information) via thefill_infofunction. An external utility,gdk-pixbuf-query-loaders, uses this to create a text file containing a list of all available loaders and their signatures. This file is then read at runtime byGdkPixbufto obtain the list of available loaders and their signatures.Modules may only implement a subset of the functionality available via
GdkPixbufModule. If a particular functionality is not implemented, thefill_vtablefunction will simply not set the corresponding function pointers of theGdkPixbufModulestructure. If a module supports incremental loading (i.e. providesbegin_load,stop_loadandload_increment), it doesn’t have to implementload, sinceGdkPixbufcan supply a genericloadimplementation wrapping the incremental loading.Installing modules
Installing a module is a two-step process:
- copy the module
file(s)to the loader directory (normally$libdir/gdk-pixbuf-2.0/$version/loaders, unless overridden by the environment variableGDK_PIXBUF_MODULEDIR) - call
gdk-pixbuf-query-loadersto update the module file (normally$libdir/gdk-pixbuf-2.0/$version/loaders.cache, unless overridden by the environment variableGDK_PIXBUF_MODULE_FILE)
The
See morePixbufModuleReftype acts as a lightweight Swift reference to an underlyingGdkPixbufModuleinstance. It exposes methods that can operate on this data type throughPixbufModuleProtocolconformance. UsePixbufModuleRefonly as anunownedreference to an existingGdkPixbufModuleinstance.Declaration
Swift
public struct PixbufModuleRef : PixbufModuleProtocol - copy the module
-
The signature prefix for a module.
The signature of a module is a set of prefixes. Prefixes are encoded as pairs of ordinary strings, where the second string, called the mask, if not
NULL, must be of the same length as the first one and may contain ‘ ’, ‘!’, ‘x’, ‘z’, and ‘n’ to indicate bytes that must be matched, not matched, “don’t-care”-bytes, zeros and non-zeros, respectively.Each prefix has an associated integer that describes the relevance of the prefix, with 0 meaning a mismatch and 100 a “perfect match”.
Starting with gdk-pixbuf 2.8, the first byte of the mask may be ‘’, indicating an unanchored pattern that matches not only at the beginning, but also in the middle. Versions prior to 2.8 will interpret the ‘’ like an ‘x’.
The signature of a module is stored as an array of
GdkPixbufModulePatterns. The array is terminated by a pattern where theprefixisNULL.GdkPixbufModulePattern *signature[] = { { "abcdx", " !x z", 100 }, { "bla", NULL, 90 }, { NULL, NULL, 0 } };In the example above, the signature matches e.g. “auud\0” with relevance 100, and “blau” with relevance 90.
The
See morePixbufModulePatternReftype acts as a lightweight Swift reference to an underlyingGdkPixbufModulePatterninstance. It exposes methods that can operate on this data type throughPixbufModulePatternProtocolconformance. UsePixbufModulePatternRefonly as anunownedreference to an existingGdkPixbufModulePatterninstance.Declaration
Swift
public struct PixbufModulePatternRef : PixbufModulePatternProtocol
-
The
See morePixbufSimpleAnimClassReftype acts as a lightweight Swift reference to an underlyingGdkPixbufSimpleAnimClassinstance. It exposes methods that can operate on this data type throughPixbufSimpleAnimClassProtocolconformance. UsePixbufSimpleAnimClassRefonly as anunownedreference to an existingGdkPixbufSimpleAnimClassinstance.Declaration
Swift
public struct PixbufSimpleAnimClassRef : PixbufSimpleAnimClassProtocol
-
A pixel buffer.
GdkPixbufcontains 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
GdkPixbufThe most basic way to create a pixbuf is to wrap an existing pixel buffer with a [class
GdkPixbuf.Pixbuf] instance. You can use the [ctorGdkPixbuf.Pixbuf.new_from_data``] function to do this.Every time you create a new
GdkPixbufinstance 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 aGdkPixbufis finalized by the reference counting functions. If you have a chunk of static data compiled into your application, you can pass inNULLas the destroy notification function so that the data will not be freed.The [
ctorGdkPixbuf.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 usingmalloc()and then wrapping it withgdk_pixbuf_new_from_data(). Thegdk_pixbuf_new()“ function will compute an optimal rowstride so that rendering can be performed with an efficient algorithm.As a special case, you can use the [
ctorGdkPixbuf.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 [classPixbuf] instance for it.Reference counting
GdkPixbufstructures 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 callingg_object_ref(); when it no longer needs the pixbuf, it should release the reference it acquired by callingg_object_unref(). The resources associated with aGdkPixbufwill be freed when its reference count drops to zero. Newly-createdGdkPixbufinstances 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 [
methodGdkPixbuf.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 domemcpy (dest, pixels, rowstride * height)to copy a whole pixbuf. Use [methodGdkPixbuf.Pixbuf.copy] instead, or compute the width in bytes of the last row as:last_row = width * ((n_channels * bits_per_sample + 7) / 8);The same rule applies when iterating over each row of a
GdkPixbufpixels array.The following code illustrates a simple
put_pixel()function for RGB pixbufs with 8 bits per channel with an alpha channel.static void put_pixel (GdkPixbuf *pixbuf, int x, int y, guchar red, guchar green, guchar blue, guchar alpha) { int n_channels = gdk_pixbuf_get_n_channels (pixbuf); // Ensure that the pixbuf is valid g_assert (gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB); g_assert (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8); g_assert (gdk_pixbuf_get_has_alpha (pixbuf)); g_assert (n_channels == 4); int width = gdk_pixbuf_get_width (pixbuf); int height = gdk_pixbuf_get_height (pixbuf); // Ensure that the coordinates are in a valid range g_assert (x >= 0 && x < width); g_assert (y >= 0 && y < height); int rowstride = gdk_pixbuf_get_rowstride (pixbuf); // The pixel buffer in the GdkPixbuf instance guchar *pixels = gdk_pixbuf_get_pixels (pixbuf); // The pixel we wish to modify guchar *p = pixels + y * rowstride + x * n_channels; p[0] = red; p[1] = green; p[2] = blue; p[3] = alpha; }Loading images
The
GdkPixBufclass 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,
GdkPixbufprovides the [classGdkPixbuf.PixbufLoader`] API for progressive image loading.Saving images
The
GdkPixbufclass 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.GdkPixbufcan 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.The
See morePixbufReftype acts as a lightweight Swift reference to an underlyingGdkPixbufinstance. It exposes methods that can operate on this data type throughPixbufProtocolconformance. UsePixbufRefonly as anunownedreference to an existingGdkPixbufinstance.Declaration
Swift
public struct PixbufRef : PixbufProtocol, GWeakCapturing
-
An opaque object representing an animation.
The GdkPixBuf library provides a simple mechanism to load and represent animations. An animation is conceptually a series of frames to be displayed over time.
The animation may not be represented as a series of frames internally; for example, it may be stored as a sprite and instructions for moving the sprite around a background.
To display an animation you don’t need to understand its representation, however; you just ask
GdkPixbufwhat should be displayed at a given point in time.The
See morePixbufAnimationReftype acts as a lightweight Swift reference to an underlyingGdkPixbufAnimationinstance. It exposes methods that can operate on this data type throughPixbufAnimationProtocolconformance. UsePixbufAnimationRefonly as anunownedreference to an existingGdkPixbufAnimationinstance.Declaration
Swift
public struct PixbufAnimationRef : PixbufAnimationProtocol, GWeakCapturing
-
An opaque object representing an iterator which points to a certain position in an animation.
The
See morePixbufAnimationIterReftype acts as a lightweight Swift reference to an underlyingGdkPixbufAnimationIterinstance. It exposes methods that can operate on this data type throughPixbufAnimationIterProtocolconformance. UsePixbufAnimationIterRefonly as anunownedreference to an existingGdkPixbufAnimationIterinstance.Declaration
Swift
public struct PixbufAnimationIterRef : PixbufAnimationIterProtocol, GWeakCapturing
-
Incremental image loader.
GdkPixbufLoaderprovides a way for applications to drive the process of loading an image, by letting them send the image data directly to the loader instead of having the loader read the data from a file. Applications can use this functionality instead ofgdk_pixbuf_new_from_file()orgdk_pixbuf_animation_new_from_file()when they need to parse image data in small chunks. For example, it should be used when reading an image from a (potentially) slow network connection, or when loading an extremely large file.To use
GdkPixbufLoaderto load an image, create a new instance, and call [methodGdkPixbuf.PixbufLoader.write] to send the data to it. When done, [methodGdkPixbuf.PixbufLoader.close] should be called to end the stream and finalize everything.The loader will emit three important signals throughout the process:
- [signal
GdkPixbuf.PixbufLoader::size-prepared] will be emitted as soon as the image has enough information to determine the size of the image to be used. If you want to scale the image while loading it, you can call [methodGdkPixbuf.PixbufLoader.set_size] in response to this signal. - [signal
GdkPixbuf.PixbufLoader::area-prepared] will be emitted as soon as the pixbuf of the desired has been allocated. You can obtain theGdkPixbufinstance by calling [methodGdkPixbuf.PixbufLoader.get_pixbuf]. If you want to use it, simply acquire a reference to it. You can also callgdk_pixbuf_loader_get_pixbuf()later to get the same pixbuf. - [signal
GdkPixbuf.PixbufLoader::area-updated] will be emitted every time a region is updated. This way you can update a partially completed image. Note that you do not know anything about the completeness of an image from the updated area. For example, in an interlaced image you will need to make several passes before the image is done loading.
Loading an animation
Loading an animation is almost as easy as loading an image. Once the first [signal
GdkPixbuf.PixbufLoader::area-prepared] signal has been emitted, you can call [methodGdkPixbuf.PixbufLoader.get_animation] to get the [classGdkPixbuf.PixbufAnimation] instance, and then call and [methodGdkPixbuf.PixbufAnimation.get_iter] to get a [classGdkPixbuf.PixbufAnimationIter] to retrieve the pixbuf for the desired time stamp.The
See morePixbufLoaderReftype acts as a lightweight Swift reference to an underlyingGdkPixbufLoaderinstance. It exposes methods that can operate on this data type throughPixbufLoaderProtocolconformance. UsePixbufLoaderRefonly as anunownedreference to an existingGdkPixbufLoaderinstance.Declaration
Swift
public struct PixbufLoaderRef : PixbufLoaderProtocol, GWeakCapturing - [signal
-
The
See morePixbufNonAnimReftype acts as a lightweight Swift reference to an underlyingGdkPixbufNonAniminstance. It exposes methods that can operate on this data type throughPixbufNonAnimProtocolconformance. UsePixbufNonAnimRefonly as anunownedreference to an existingGdkPixbufNonAniminstance.Declaration
Swift
public struct PixbufNonAnimRef : PixbufNonAnimProtocol, GWeakCapturing
-
An opaque struct representing a simple animation.
The
See morePixbufSimpleAnimReftype acts as a lightweight Swift reference to an underlyingGdkPixbufSimpleAniminstance. It exposes methods that can operate on this data type throughPixbufSimpleAnimProtocolconformance. UsePixbufSimpleAnimRefonly as anunownedreference to an existingGdkPixbufSimpleAniminstance.Declaration
Swift
public struct PixbufSimpleAnimRef : PixbufSimpleAnimProtocol, GWeakCapturing
-
The
See morePixbufSimpleAnimIterReftype acts as a lightweight Swift reference to an underlyingGdkPixbufSimpleAnimIterinstance. It exposes methods that can operate on this data type throughPixbufSimpleAnimIterProtocolconformance. UsePixbufSimpleAnimIterRefonly as anunownedreference to an existingGdkPixbufSimpleAnimIterinstance.Declaration
Swift
public struct PixbufSimpleAnimIterRef : PixbufSimpleAnimIterProtocol, GWeakCapturing -
Flags which allow a module to specify further details about the supported operations.
See moreDeclaration
Swift
public struct PixbufFormatFlags : OptionSet
View on GitHub
Install in Dash
Structures Reference