Reference Manual
Inti Logo
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

Inti::Gdk::PixbufLoader Class Reference

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

#include <inti/gdk-pixbuf/pixbuf-loader.h>

Inheritance diagram for Inti::Gdk::PixbufLoader:

Inti::G::Object Inti::G::TypeInstance Inti::MemoryHandler Inti::ReferencedBase List of all members.

Public Member Functions

Constructors
Accessors
Methods
Signal Proxies

Protected Member Functions

Constructors
Signal Handlers

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.


Constructor & Destructor Documentation

Inti::Gdk::PixbufLoader::PixbufLoader GdkPixbufLoader *  pixbuf_loader,
bool  reference = true
[explicit, protected]
 

Construct a new PixbufLoader from an existing GdkPixbufLoader.

Parameters:
pixbuf_loader A pointer to a GdkPixbufLoader.
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).

Inti::Gdk::PixbufLoader::PixbufLoader const char *  image_type,
G::Error error = 0
 

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.

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.

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.


Member Function Documentation

bool Inti::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.

Pointer<PixbufAnimation> Inti::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> Inti::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.

Pointer<Pixbuf> Inti::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()).

void Inti::Gdk::PixbufLoader::on_area_prepared  )  [protected]
 

Called when the pixbuf loader has allocated the pixbuf in the desired size.

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

void Inti::Gdk::PixbufLoader::on_area_updated int  x,
int  y,
int  width,
int  height
[protected]
 

Called when a significant area of the image being loaded has been updated.

Parameters:
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.

Normally it means that one or more complete scanlines 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. Usually the x coordinate and the width will remain the same. The y coordinate changes each time one or more scanlines are read in. The height is the number of scanlines, in pixels.

void Inti::Gdk::PixbufLoader::on_closed  )  [protected]
 

Called when 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.

void Inti::Gdk::PixbufLoader::on_size_prepared int  width,
int  height
[protected]
 

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

Parameters:
width The width of the image the pixbuf loader will create.
height The height of the image the pixbuf loader will create.

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

void Inti::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 Inti::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.


The documentation for this class was generated from the following file: Main Page - Footer


Generated on Sun Sep 14 20:08:12 2003 for Inti by doxygen 1.3.2 written by Dimitri van Heesch, © 1997-2002