gtkmm: Gdk::PixbufLoader Class Reference

gtkmm 4.18.0

Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Symbols | List of all members
Gdk::PixbufLoader Class Reference

Incremental image loader. More...

`#include <gdkmm/pixbufloader.h>`

Inheritance diagram for Gdk::PixbufLoader:
[legend]

## Public Member Functions
| PixbufLoader (PixbufLoader && src) noexcept
PixbufLoader & | operator= (PixbufLoader && src) noexcept
| ~PixbufLoader () noexcept override
GdkPixbufLoader * | gobj ()
| Provides access to the underlying C GObject.
const GdkPixbufLoader * | gobj () const
| Provides access to the underlying C GObject.
GdkPixbufLoader * | gobj_copy ()
| Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
void | set_size (int width, int height)
| Causes the image to be scaled while it is loaded.
void | write (const guint8 * buf, gsize count)
| Causes the pixbuf loader to parse the next count bytes of an image.
void | close ()
| Informs a pixbuf loader that no further writes with PixbufLoader::write() will occur, so that it can free its internal loading structures.
Glib::RefPtr< Gdk::Pixbuf > | get_pixbuf ()
| Queries the Gdk::Pixbuf that a pixbuf loader is currently creating.
Glib::RefPtr< Gdk::PixbufAnimation > | get_animation ()
| Queries the Gdk::PixbufAnimation that a pixbuf loader is currently creating.
PixbufFormat | get_format () const
| Obtains the available information about the format of the currently loading image file.
Glib::SignalProxy< void()> | signal_area_prepared ()
Glib::SignalProxy< void(int, int, int, int)> | signal_area_updated ()
Glib::SignalProxy< void()> | signal_closed ()
Glib::SignalProxy< void(int, int)> | signal_size_prepared ()
Public Member Functions inherited from Glib::Object
| Object (const Object &)=delete
Object & | operator= (const Object &)=delete
| Object (Object &&src) noexcept
Object & | operator= (Object &&src) noexcept
void * | get_data (const QueryQuark &key)
void | set_data (const Quark &key, void *data)
void | set_data_with_c_callback (const Quark &key, void *data, GDestroyNotify notify)
void | set_data (const Quark &key, void *data, DestroyNotify notify)
void | remove_data (const QueryQuark &quark)
void * | steal_data (const QueryQuark &quark)
Glib::RefPtr< Glib::Object > | wrap (GObject *object, bool take_copy=false)
Public Member Functions inherited from Glib::ObjectBase
| ObjectBase (const ObjectBase &)=delete
ObjectBase & | operator= (const ObjectBase &)=delete
void | set_property_value (const Glib::ustring &property_name, const Glib::ValueBase &value)
void | get_property_value (const Glib::ustring &property_name, Glib::ValueBase &value) const
void | set_property (const Glib::ustring &property_name, const PropertyType &value)
void | get_property (const Glib::ustring &property_name, PropertyType &value) const
PropertyType | get_property (const Glib::ustring &property_name) const
sigc::connection | connect_property_changed (const Glib::ustring &property_name, const sigc::slot< void()> &slot)
sigc::connection | connect_property_changed (const Glib::ustring &property_name, sigc::slot< void()> &&slot)
void | freeze_notify ()
void | thaw_notify ()
virtual void | reference () const
virtual void | unreference () const
GObject * | gobj ()
const GObject * | gobj () const
GObject * | gobj_copy () const

## Static Public Member Functions
static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system.
static Glib::RefPtr< PixbufLoader > | create ()
| Creates a new pixbuf loader object.
static Glib::RefPtr< PixbufLoader > | create (const Glib::ustring & image_type, bool mime_type=false)
| Constructs a pixbuf loader object for a specific image type.

## Protected Member Functions
| PixbufLoader ()
| Constructs a pixbuf loader object.
| PixbufLoader (const Glib::ustring & image_type, bool mime_type=false)
| Constructs a pixbuf loader object for a specific image type.
virtual void | on_area_prepared ()
| This is a default handler for the signal signal_area_prepared().
virtual void | on_area_updated (int x, int y, int width, int height)
| This is a default handler for the signal signal_area_updated().
virtual void | on_closed ()
| This is a default handler for the signal signal_closed().
virtual void | on_size_prepared (int width, int height)
| This is a default handler for the signal signal_size_prepared().
Protected Member Functions inherited from Glib::Object
| Object ()
| Object (const Glib::ConstructParams &construct_params)
| Object (GObject *castitem)
| ~Object () noexcept override
Protected Member Functions inherited from Glib::ObjectBase
| ObjectBase ()
| ObjectBase (const char *custom_type_name)
| ObjectBase (const std::type_info &custom_type_info)
| ObjectBase (ObjectBase &&src) noexcept
ObjectBase & | operator= (ObjectBase &&src) noexcept
virtual | ~ObjectBase () noexcept=0
void | initialize (GObject *castitem)
void | initialize_move (GObject *castitem, Glib::ObjectBase *previous_wrapper)

## Related Symbols
(Note that these are not member symbols.)
Glib::RefPtr< Gdk::PixbufLoader > | wrap (GdkPixbufLoader * object, bool take_copy=false)
| A Glib::wrap() method for this object.

## Additional Inherited Members
Public Types inherited from Glib::Object
typedef void(*)(gpointer data | DestroyNotify)

## Detailed Description

Incremental image loader.

`Gdk::PixbufLoader` provides 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 of `Gdk::Pixbuf::create_from_file()` or `Gdk::PixbufAnimation::create_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 `GdkPixbufLoader` to load an image, create a new instance, and call write() to send the data to it. When done, close() should be called to end the stream and finalize everything.

The loader will emit three important signals throughout the process:

- signal_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 set_size() in response to this signal.
- signal_area_prepared() will be emitted as soon as the pixbuf of the desired size has been allocated. You can obtain the Gdk::Pixbuf instance by calling get_pixbuf(). You can also call get_pixbuf() later to get the same pixbuf.
- signal_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_area_prepared() has been emitted, you can call get_animation() to get the Gdk::PixbufAnimation instance, and then call and Gdk::PixbufAnimation::get_iter() to get a Gdk::PixbufAnimationIter to retrieve the pixbuf for the desired time stamp.

## Constructor & Destructor Documentation

## ◆ PixbufLoader() [1/3]

Gdk::PixbufLoader::PixbufLoader | ( | PixbufLoader && | src | ) |
| noexcept

## ◆ ~PixbufLoader()

Gdk::PixbufLoader::~PixbufLoader | ( |  | ) |
| overridenoexcept

## ◆ PixbufLoader() [2/3]

Gdk::PixbufLoader::PixbufLoader | ( |  | ) |
| protected

Constructs a pixbuf loader object.

## ◆ PixbufLoader() [3/3]

Gdk::PixbufLoader::PixbufLoader | ( | const Glib::ustring & | image_type,
|  | bool | mime_type = false )
| explicitprotected

Constructs a pixbuf loader object for a specific image type.

Constructs a new pixbuf loader object that always attempts to parse image data as if it were an image of type image_type, instead of identifying the type automatically. Useful if you want an error if the image isn't the expected type, for loading image formats that can't be reliably identified by looking at the data, or if the user manually forces a specific type.

The image_type can be one of the types returned by Gdk::Pixbuf::get_formats(), or a MIME type.

Common MIME Types are listed here http://www.iana.org/assignments/media-types/ and here: http://www.freedesktop.org/Software/shared-mime-info

The list of non-mime-type image formats depends on what image loaders are installed, but typically "png", "jpeg", "gif", "tiff" and "xpm" are among the supported formats. To obtain the full list of supported image formats, call PixbufFormat::get_name() on each of the PixbufFormats returned by Gdk::Pixbuf::get_formats().

Parameters

  image_type | Name of the image format to be loaded with the image.
  mime_type | If this is true then the image_type is a MIME type.

Exceptions

  Gdk::PixbufError |

## Member Function Documentation

## ◆ close()

void Gdk::PixbufLoader::close | ( |  | ) |

Informs a pixbuf loader that no further writes with PixbufLoader::write() will occur, so that it can free its internal loading structures.

Also, tries to parse any data that hasn't yet been parsed; if the remaining data is partial or corrupt, an exception will be thrown. If you're just cancelling a load rather than expecting it to be finished, writing an empty `catch()` block to ignore errors is reasonable.

Exceptions

  Gdk::PixbufError |
  Glib::FileError |

## ◆ create() [1/2]

static Glib::RefPtr< PixbufLoader > Gdk::PixbufLoader::create | ( |  | ) |
| static

Creates a new pixbuf loader object.

Returns
  A newly-created pixbuf loader.

## ◆ create() [2/2]

static Glib::RefPtr< PixbufLoader > Gdk::PixbufLoader::create | ( | const Glib::ustring & | image_type,
|  | bool | mime_type = false )
| static

Constructs a pixbuf loader object for a specific image type.

Constructs a new pixbuf loader object that always attempts to parse image data as if it were an image of type image_type, instead of identifying the type automatically. Useful if you want an error if the image isn't the expected type, for loading image formats that can't be reliably identified by looking at the data, or if the user manually forces a specific type.

The image_type can be one of the types returned by Gdk::Pixbuf::get_formats(), or a MIME type.

Common MIME Types are listed here http://www.iana.org/assignments/media-types/ and here: http://www.freedesktop.org/Software/shared-mime-info

The list of non-mime-type image formats depends on what image loaders are installed, but typically "png", "jpeg", "gif", "tiff" and "xpm" are among the supported formats. To obtain the full list of supported image formats, call PixbufFormat::get_name() on each of the PixbufFormats returned by Gdk::Pixbuf::get_formats().

Parameters

  image_type | Name of the image format to be loaded with the image.
  mime_type | If this is true then the image_type is a MIME type.

Exceptions

  Gdk::PixbufError |

## ◆ get_animation()

Glib::RefPtr< Gdk::PixbufAnimation > Gdk::PixbufLoader::get_animation | ( |  | ) |

Queries the Gdk::PixbufAnimation that a pixbuf loader is currently creating.

In general it only makes sense to call this function after the GdkPixbuf::PixbufLoader::signal_area_prepared() signal has been emitted by the loader.

If the loader doesn't have enough bytes yet, and hasn't emitted the `area-prepared` signal, this function will return `nullptr`.

Returns
  The animation that the loader is currently loading.

## ◆ get_format()

PixbufFormat Gdk::PixbufLoader::get_format | ( |  | ) | const

Obtains the available information about the format of the currently loading image file.

Since gtkmm 2.2

Returns
  A Gdk::PixbufFormat.

## ◆ get_pixbuf()

Glib::RefPtr< Gdk::Pixbuf > Gdk::PixbufLoader::get_pixbuf | ( |  | ) |

Queries the Gdk::Pixbuf that a pixbuf loader is currently creating.

In general it only makes sense to call this function after the GdkPixbuf::PixbufLoader::signal_area_prepared() signal has been emitted by the loader; this means that enough data has been read to know the size of the image that will be allocated.

If the loader has not received enough data via write(), then this function returns `nullptr`.

The returned pixbuf will be the same in all future calls to the loader, so if you want to keep using it, you should acquire a reference to it.

Additionally, if the loader is an animation, it will return the "static image" of the animation (see Gdk::PixbufAnimation::get_static_image()).

Returns
  The pixbuf that the loader is creating.

## ◆ get_type()

static GType Gdk::PixbufLoader::get_type | ( |  | ) |
| static

Get the GType for this class, for use with the underlying GObject type system.

## ◆ gobj() [1/2]

GdkPixbufLoader * Gdk::PixbufLoader::gobj | ( |  | ) |
| inline

Provides access to the underlying C GObject.

## ◆ gobj() [2/2]

const GdkPixbufLoader * Gdk::PixbufLoader::gobj | ( |  | ) | const
| inline

Provides access to the underlying C GObject.

## ◆ gobj_copy()

GdkPixbufLoader * Gdk::PixbufLoader::gobj_copy | ( |  | ) |

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

## ◆ on_area_prepared()

virtual void Gdk::PixbufLoader::on_area_prepared | ( |  | ) |
| protectedvirtual

This is a default handler for the signal signal_area_prepared().

## ◆ on_area_updated()

virtual void Gdk::PixbufLoader::on_area_updated | ( | int | x,
|  | int | y,
|  | int | width,
|  | int | height )
| protectedvirtual

This is a default handler for the signal signal_area_updated().

## ◆ on_closed()

virtual void Gdk::PixbufLoader::on_closed | ( |  | ) |
| protectedvirtual

This is a default handler for the signal signal_closed().

## ◆ on_size_prepared()

virtual void Gdk::PixbufLoader::on_size_prepared | ( | int | width,
|  | int | height )
| protectedvirtual

This is a default handler for the signal signal_size_prepared().

## ◆ operator=()

PixbufLoader & Gdk::PixbufLoader::operator= | ( | PixbufLoader && | src | ) |
| noexcept

## ◆ set_size()

void Gdk::PixbufLoader::set_size | ( | int | width,
|  | int | height )

Causes the image to be scaled while it is loaded.

The desired image size can be determined relative to the original size of the image by calling set_size() from a signal handler for the signal_size_prepared() signal.

Attempts to set the desired image size are ignored after the emission of the signal_size_prepared() signal.

Since gtkmm 2.2

Parameters

  width | The desired width of the image being loaded.
  height | The desired height of the image being loaded.

## ◆ signal_area_prepared()

Glib::SignalProxy< void()> Gdk::PixbufLoader::signal_area_prepared | ( |  | ) |

Slot Prototype:
  `void on_my_area_prepared()`

Flags: Run Last

This signal is emitted when the pixbuf loader has allocated the pixbuf in the desired size.

After this signal is emitted, applications can call Gdk::PixbufLoader::get_pixbuf() to fetch the partially-loaded pixbuf.

## ◆ signal_area_updated()

Glib::SignalProxy< void(int, int, int, int)> Gdk::PixbufLoader::signal_area_updated | ( |  | ) |

Slot Prototype:
  `void on_my_area_updated(int x, int y, int width, int height)`

Flags: Run Last

This signal is emitted when a significant area of the image being loaded has been updated.

Normally it means that a complete scanline has been read in, but it could be a different area as well.

Applications can use this signal to know when to repaint areas of an image that is being loaded.

Parameters

  x | X offset of upper-left corner of the updated area.
  y | Y offset of upper-left corner of the updated area.
  width | Width of updated area.
  height | Height of updated area.

## ◆ signal_closed()

Glib::SignalProxy< void()> Gdk::PixbufLoader::signal_closed | ( |  | ) |

Slot Prototype:
  `void on_my_closed()`

Flags: Run Last

This signal is emitted when Gdk::PixbufLoader::close() is called.

It can be used by different parts of an application to receive notification when an image loader is closed by the code that drives it.

## ◆ signal_size_prepared()

Glib::SignalProxy< void(int, int)> Gdk::PixbufLoader::signal_size_prepared | ( |  | ) |

Slot Prototype:
  `void on_my_size_prepared(int width, int height)`

Flags: Run Last

This signal is emitted when the pixbuf loader has been fed the initial amount of data that is required to figure out the size of the image that it will create.

Applications can call Gdk::PixbufLoader::set_size() in response to this signal to set the desired size to which the image should be scaled.

Parameters

  width | The original width of the image.
  height | The original height of the image.

## ◆ write()

void Gdk::PixbufLoader::write | ( | const guint8 * | buf,
|  | gsize | count )

Causes the pixbuf loader to parse the next count bytes of an image.

It will return if the data was loaded successfully, and throw an exception if an error occurred. In the latter case, the loader will be closed, and will not accept further writes.

Parameters

  buf | Pointer to image data.
  count | Length of the buf buffer in bytes.

Exceptions

  Gdk::PixbufError |
  Glib::FileError |

## Friends And Related Symbol Documentation

## ◆ wrap()

Glib::RefPtr< Gdk::PixbufLoader > wrap | ( | GdkPixbufLoader * | object,
|  | bool | take_copy = false )
| related

A Glib::wrap() method for this object.

Parameters

  object | The C instance.
  take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref.

Returns
  A C++ instance that wraps this C instance.