Xfce Foundation Classes
Main Page  | IndexNamespace List  |  Alphabetical List  |  Class List  |  File List


Xfc::Gdk::PixbufLoader Class Reference

A GdkPixbufLoader C++ wrapper class. More...

#include <xfc/gdk-pixbuf/pixbuf-loader.hh>

Inheritance diagram for Xfc::Gdk::PixbufLoader:

Xfc::G::Object Xfc::G::TypeInstance Xfc::Trackable List of all members.

Signal Prototypes

Public Member Functions

Accessors
Methods
Signal Proxies

Static Public Member Functions

Constructors

Detailed Description

A GdkPixbufLoader C++ wrapper class.

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 constructing a Pixbuf or a PixbufAnimation directly from a 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 PixbufLoader to load an image, just construct a new one, 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. The first, size_prepared, will be called 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.

The second signal, area_prepared, will be called as soon as the pixbuf of the desired size has been allocated. You can obtain it by calling get_pixbuf(). If you want to use it, simply ref() it. In addition, no actual information will be passed in yet, so the pixbuf can be safely filled with any temporary graphics (or an initial color) as needed. You can also call get_pixbuf() later and get the same pixbuf.

The last signal, area_updated gets called 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 area updated. For example, in an interlaced image, you need to make several passes before the image is done loading.

Loading an animation is almost as easy as loading an image. Once the first area_prepared signal has been emitted, you can call get_animation() to get the PixbufAnimation object and get_iter() to get an PixbufAnimationIter for displaying it.

Note: dynamically allocated objects must either be unreferenced or assigned to a smart pointer. Stack objects are automatically unreferenced when they go out of scope.


Constructor & Destructor Documentation

Xfc::Gdk::PixbufLoader::PixbufLoader ( GdkPixbufLoader *  pixbuf_loader,
bool  owns_reference = true 
) [explicit, protected]

Construct a new PixbufLoader from an existing GdkPixbufLoader.

Parameters:
pixbuf_loader A pointer to a GdkPixbufLoader.
owns_reference Set false if the initial reference count is floating, set true if it's not.
The pixbuf_loader can be a newly created GdkPixbufLoader or an existing GdkPixbufLoader. (see G::Object::Object).

Xfc::Gdk::PixbufLoader::PixbufLoader ( GdkPixbufLoader *  pixbuf_loader,
bool  owns_reference = true 
) [explicit, protected]

Construct a new PixbufLoader from an existing GdkPixbufLoader.

Parameters:
pixbuf_loader A pointer to a GdkPixbufLoader.
owns_reference Set false if the initial reference count is floating, set true if it's not.
The pixbuf_loader can be a newly created GdkPixbufLoader or an existing GdkPixbufLoader. (see G::Object::Object).


Member Function Documentation

static Pointer<PixbufLoader> Xfc::Gdk::PixbufLoader::create_with_type ( const String image_type,
G::Error error = 0 
) [static]

Creates 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.

Parameters:
image_type The name of the image format to be loaded with the image.
error The return location for an allocated G::Error, or null to ignore errors.
Returns:
A newly-created pixbuf loader, or null if any error occurs.
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 png, jpeg, tiff, gif, xpm, pnm, ras, ico, bmp or wbmp.

static Pointer<PixbufLoader> Xfc::Gdk::PixbufLoader::create_with_mime_type ( const String mime_type,
G::Error error = 0 
) [static]

Creates a new pixbuf loader object that always attempts to parse image data as if it were an image of mime type mime_type, instead of identifying the type automatically.

Parameters:
mime_type The mime type to be loaded.
error The return location for an allocated G::Error, or null to ignore errors.
Returns:
A newly-created pixbuf loader, or null if any error occurs.
This is useful if you want an error if the image isn't the expected mime type, for loading image formats that can't be reliably identified by looking at the data, or if the user manually forces a specific mime type.

Pointer<Pixbuf> Xfc::Gdk::PixbufLoader::get_pixbuf (  )  const

Queries the Pixbuf that the pixbuf loader is currently creating.

Returns:
A smart pointer to the new Pixbuf the loader is creating, or null if not enough data has been read to determine how to create the image buffer.
In general it only makes sense to call this function after the 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 null. The returned pixbuf will be the same in all future calls to the loader. If the loader is an animation, it will return the "static image" of the animation (see Gdk::PixbufAnimation::get_static_image()).

Pointer<PixbufAnimation> Xfc::Gdk::PixbufLoader::get_animation (  )  const

Queries the PixbufAnimation that the pixbuf loader is currently creating.

Returns:
A smart pointer to the PixbufAnimation that the loader is loading, or null if not enough data has been read to determine the information.
In general it only makes sense to call this function after the area_prepared signal has been emitted by the loader. If the loader doesn't have enough bytes yet (hasn't emitted the area_prepared signal) this method will return null.

Pointer<PixbufFormat> Xfc::Gdk::PixbufLoader::get_format (  )  const

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

Returns:
A smart pointer to the new PixbufFormat, or null.

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

Causes the image to be scaled while it is loaded.

Parameters:
width The desired width of the image being loaded.
height The desired height of the image being 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 size_prepared signal. Attempts to set the desired image size are ignored after the emission of the size_prepared signal.

bool Xfc::Gdk::PixbufLoader::write ( const unsigned char *  buffer,
size_t  count,
G::Error error 
)

This method will cause a pixbuf loader to parse the next count bytes of an image.

Parameters:
buffer A pointer to the image data.
count The length of buffer in bytes.
error The return location for errors.
Returns:
true if the data was loaded successfully, false if an error occurred.
If an error occurs, the loader will be closed, and will not accept further writes. If false is returned, error will be set to an error from the GDK_PIXBUF_ERROR or G_FILE_ERROR domains.

bool Xfc::Gdk::PixbufLoader::close ( G::Error error = 0  ) 

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

Parameters:
error The return location for a G::Error, or null to ignore errors.
Returns:
true if all image data written so far was successfully passed out via the area_updated signal.
This method tries to parse any data that hasn't yet been parsed; if the remaining data is partial or corrupt, an error will be returned. If false is returned, error will be set to an error from the GDK_PIXBUF_ERROR or G_FILE_ERROR domains. If you're just cancelling a load rather than expecting it to be finished, passing null for error to ignore it is reasonable.


Member Data Documentation

const SizePreparedSignalType Xfc::Gdk::PixbufLoader::size_prepared_signal [static, protected]

Size prepared signal (see signal_size_prepared()).

Calls a slot with the signature:

< void function(int width, int height);
< // width: The width of the image the pixbuf loader will create.
< // height: The height of the image the pixbuf loader will create.
<

const AreaPreparedSignalType Xfc::Gdk::PixbufLoader::area_prepared_signal [static, protected]

Area prepared signal (see signal_area_prepared()).

Calls a slot with the signature:

< void function();
<

const AreaUpdatedSignalType Xfc::Gdk::PixbufLoader::area_updated_signal [static, protected]

Area updated signal (see signal_area_updated()).

Calls a slot with the signature:

< void function(int x, int y, int width, int height);
< // x: The X coordinate of the updated area.
< // y: The Y coordinate of the updated area.
< // width: The width of the updated area.
< // height: The height of the updated area.
<

const ClosedSignalType Xfc::Gdk::PixbufLoader::closed_signal [static, protected]

Closed signal (see signal_closed()).

Calls a slot with the signature:

< void function();
<


The documentation for this class was generated from the following file: Xfce Foundation Classes
Copyright © 2004-2005 The XFC Development Team XFC 4.3