FLTK 1.4.0
Loading...
Searching...
No Matches
Fl_Anim_GIF_Image Class Reference

The Fl_Anim_GIF_Image class supports loading, caching, and drawing of animated Compuserve GIFSM images. More...

Inheritance diagram for Fl_Anim_GIF_Image:
Fl_GIF_Image Fl_Pixmap Fl_Image

Public Types

enum  Flags {
  DONT_START = 1 , DONT_RESIZE_CANVAS = 2 , DONT_SET_AS_IMAGE = 4 , OPTIMIZE_MEMORY = 8 ,
  LOG_FLAG = 64 , DEBUG_FLAG = 128
}
 When opening an Fl_Anim_GIF_Image there are some options that can be passed in a flags value. More...
 

Public Member Functions

Fl_Widgetcanvas () const
 Gets the current widget, that is used to display the frame images.
 
void canvas (Fl_Widget *canvas, unsigned short flags=0)
 Link the image back to a widget for automated animation.
 
int canvas_h () const
 Return the height of the animation canvas.
 
int canvas_w () const
 Return the width of the animation canvas.
 
void color_average (Fl_Color c, float i) FL_OVERRIDE
 Applies a color average to all frames.
 
Fl_Imagecopy () const
 
Fl_Imagecopy (int W, int H) const FL_OVERRIDE
 Copy and resize the animation frames.
 
int debug () const
 
void delay (int frame, double delay)
 Set the delay of frame [0-frames() -1] in seconds.
 
double delay (int frame_) const
 Return the delay of frame [0-frames() -1] in seconds.
 
void desaturate () FL_OVERRIDE
 Desaturate to all frames of the animation.
 
void draw (int x, int y, int w, int h, int cx=0, int cy=0) FL_OVERRIDE
 Draw the current frame of the animation.
 
 Fl_Anim_GIF_Image ()
 Create an empty animated GIF image shell.
 
 Fl_Anim_GIF_Image (const char *filename, Fl_Widget *canvas=0, unsigned short flags=0)
 Load an animated GIF image from a file.
 
 Fl_Anim_GIF_Image (const char *imagename, const unsigned char *data, const size_t length, Fl_Widget *canvas=0, unsigned short flags=0)
 Load an animated GIF image from memory.
 
int frame () const
 Return the current frame.
 
void frame (int frame)
 Set the current frame.
 
int frame_h (int frame) const
 Return the frame dimensions of a frame.
 
bool frame_uncache () const
 Return the active frame_uncache() setting.
 
void frame_uncache (bool uncache)
 Use frame_uncache() to set or forbid frame image uncaching.
 
int frame_w (int frame) const
 Return the frame dimensions of a frame.
 
int frame_x (int frame) const
 Return the frame position of a frame.
 
int frame_y (int frame) const
 Return the frame position of a frame.
 
int frames () const
 Get the number of frames in the animation.
 
Fl_Imageimage () const
 Return the current frame image.
 
Fl_Imageimage (int frame) const
 Return the image of the given frame index.
 
bool is_animated () const
 Check if this is a valid animation with more than one frame.
 
bool load (const char *name, const unsigned char *imgdata=NULL, size_t imglength=0)
 Load an animation from a file or from a memory block.
 
const char * name () const
 Return the name of the played file as specified in the constructor.
 
bool next ()
 Show the next frame if the animation is stopped.
 
bool playing () const
 Return if the animation is currently running or stopped.
 
Fl_Anim_GIF_Imageresize (double scale)
 Resizes the image to the specified size, replacing the current image.
 
Fl_Anim_GIF_Imageresize (int w, int h)
 Resizes the image to the specified size, replacing the current image.
 
double speed () const
 Get the animation speed factor.
 
void speed (double speed)
 Set the animation speed factor.
 
bool start ()
 The start() method (re-)starts the playing of the frames.
 
bool stop ()
 The stop() method stops the playing of the frames.
 
void uncache () FL_OVERRIDE
 Uncache all cached image data now.
 
bool valid () const
 Check if animation is valid.
 
 ~Fl_Anim_GIF_Image () FL_OVERRIDE
 Release the image and all cached data.
 
- Public Member Functions inherited from Fl_GIF_Image
 Fl_GIF_Image (const char *filename)
 This constructor loads a GIF image from the given file.
 
 Fl_GIF_Image (const char *imagename, const unsigned char *data)
 This constructor loads a GIF image from memory (deprecated).
 
 Fl_GIF_Image (const char *imagename, const unsigned char *data, const size_t length)
 This constructor loads a GIF image from memory.
 
- Public Member Functions inherited from Fl_Pixmap
int cache_h ()
 
int cache_w ()
 
void color_average (Fl_Color c, float i) FL_OVERRIDE
 The color_average() method averages the colors in the image with the provided FLTK color value.
 
Fl_Imagecopy () const
 
Fl_Imagecopy (int W, int H) const FL_OVERRIDE
 Creates a resized copy of the image.
 
void desaturate () FL_OVERRIDE
 The desaturate() method converts an image to grayscale.
 
void draw (int X, int Y)
 
void draw (int X, int Y, int W, int H, int cx=0, int cy=0) FL_OVERRIDE
 Draws the image to the current drawing surface with a bounding box.
 
 Fl_Pixmap (char *const *D)
 The constructors create a new pixmap from the specified XPM data.
 
 Fl_Pixmap (const char *const *D)
 The constructors create a new pixmap from the specified XPM data.
 
 Fl_Pixmap (const uchar *const *D)
 The constructors create a new pixmap from the specified XPM data.
 
 Fl_Pixmap (uchar *const *D)
 The constructors create a new pixmap from the specified XPM data.
 
void label (Fl_Menu_Item *m) FL_OVERRIDE
 This method is an obsolete way to set the image attribute of a menu item.
 
void label (Fl_Widget *w) FL_OVERRIDE
 This method is an obsolete way to set the image attribute of a widget or menu item.
 
void uncache () FL_OVERRIDE
 If the image has been cached for display, delete the cache data.
 
virtual ~Fl_Pixmap ()
 The destructor frees all memory and server resources that are used by the pixmap.
 
- Public Member Functions inherited from Fl_Image
virtual class Fl_Shared_Imageas_shared_image ()
 Returns whether an image is an Fl_Shared_Image or not.
 
Fl_Imagecopy () const
 Creates a copy of the image in the same size.
 
int count () const
 Returns the number of data values associated with the image.
 
int d () const
 Returns the image depth.
 
const char *const * data () const
 Returns a pointer to the current image data array.
 
int data_h () const
 Returns the height of the image data.
 
int data_w () const
 Returns the width of the image data.
 
void draw (int X, int Y)
 Draws the image to the current drawing surface.
 
int fail () const
 Returns a value that is not 0 if there is currently no image available.
 
 Fl_Image (int W, int H, int D)
 The constructor creates an empty image with the specified width, height, and depth.
 
int h () const
 Returns the current image drawing height in FLTK units.
 
void inactive ()
 The inactive() method calls color_average(FL_BACKGROUND_COLOR, 0.33f) to produce an image that appears grayed out.
 
int ld () const
 Returns the current line data size in bytes.
 
virtual void release ()
 Releases an Fl_Image - the same as 'delete this'.
 
virtual void scale (int width, int height, int proportional=1, int can_expand=0)
 Sets the drawing size of the image.
 
int w () const
 Returns the current image drawing width in FLTK units.
 
virtual ~Fl_Image ()
 The destructor is a virtual method that frees all memory used by the image.
 

Static Public Member Functions

static int frame_count (const char *name, const unsigned char *imgdata=NULL, size_t imglength=0)
 Get the number of frames in a GIF file or in a GIF compressed data block.
 
- Static Public Member Functions inherited from Fl_GIF_Image
static bool is_animated (const char *name_)
 
- Static Public Member Functions inherited from Fl_Image
static Fl_Labeltype define_FL_IMAGE_LABEL ()
 
static Fl_RGB_Scaling RGB_scaling ()
 Returns the currently used RGB image scaling method.
 
static void RGB_scaling (Fl_RGB_Scaling)
 Sets the RGB image scaling method used for copy(int, int).
 
static Fl_RGB_Scaling scaling_algorithm ()
 Gets what algorithm is used when resizing a source image to draw it.
 
static void scaling_algorithm (Fl_RGB_Scaling algorithm)
 Sets what algorithm is used when resizing a source image to draw it.
 

Static Public Attributes

static bool loop = true
 The loop flag can be used to (dis-)allow loop count.
 
static double min_delay = 0.
 The min_delay value can be used to set a minimum value for the frame delay for playback.
 
- Static Public Attributes inherited from Fl_GIF_Image
static bool animate = false
 Sets how the shared image core routine should treat animated GIF files.
 
- Static Public Attributes inherited from Fl_Image
static const int ERR_FILE_ACCESS = -2
 
static const int ERR_FORMAT = -3
 
static const int ERR_MEMORY_ACCESS = -4
 
static const int ERR_NO_IMAGE = -1
 
static bool register_images_done = false
 True after fl_register_images() was called, false before.
 

Protected Member Functions

void clear_frames ()
 
bool next_frame ()
 
void on_extension_data (Fl_GIF_Image::GIF_FRAME &f) FL_OVERRIDE
 
void on_frame_data (Fl_GIF_Image::GIF_FRAME &f) FL_OVERRIDE
 
void scale_frame ()
 
void set_frame ()
 
void set_frame (int frame)
 
- Protected Member Functions inherited from Fl_GIF_Image
 Fl_GIF_Image ()
 The default constructor creates an empty GIF image.
 
 Fl_GIF_Image (const char *filename, bool anim)
 
 Fl_GIF_Image (const char *imagename, const unsigned char *data, const size_t length, bool anim)
 
void load (const char *filename, bool anim)
 The protected load() methods are used by Fl_Anim_GIF_Image to request loading of animated GIF's.
 
void load (const char *imagename, const unsigned char *data, const size_t length, bool anim)
 
void load_gif_ (class Fl_Image_Reader &rdr, bool anim=false)
 
- Protected Member Functions inherited from Fl_Pixmap
void measure ()
 
- Protected Member Functions inherited from Fl_Image
void d (int D)
 Sets the current image depth.
 
void data (const char *const *p, int c)
 Sets the current data pointer and count of pointers in the array.
 
void draw_empty (int X, int Y)
 The protected method draw_empty() draws a box with an X in it.
 
int draw_scaled (int X, int Y, int W, int H)
 Draw the image to the current drawing surface rescaled to a given width and height.
 
void h (int H)
 Sets the height of the image data.
 
void ld (int LD)
 Sets the current line data size in bytes.
 
void w (int W)
 Sets the width of the image data.
 

Static Protected Member Functions

static void cb_animate (void *d)
 
- Static Protected Member Functions inherited from Fl_Image
static void labeltype (const Fl_Label *lo, int lx, int ly, int lw, int lh, Fl_Align la)
 
static void measure (const Fl_Label *lo, int &lw, int &lh)
 

Additional Inherited Members

- Public Attributes inherited from Fl_Pixmap
int alloc_data
 

Detailed Description

The Fl_Anim_GIF_Image class supports loading, caching, and drawing of animated Compuserve GIFSM images.

The class loads all images contained in the file and animates them by cycling through them as defined by the delay times in the image file.

The user must supply an FLTK widget as "container" in order to see the animation by specifying it in the constructor or later using the canvas() method.

Member Enumeration Documentation

◆ Flags

When opening an Fl_Anim_GIF_Image there are some options that can be passed in a flags value.

Enumerator
DONT_START 

This flag indicates to the loader that it should not start the animation immediately after successful load, which is the default.

It can be started later using the start() method.

DONT_RESIZE_CANVAS 

This flag indicates to the loader that it should not resize the canvas widget of the animation to the dimensions of the animation, which is the default.

Needed for special use cases.

DONT_SET_AS_IMAGE 

This flag indicates to the loader that it should not set the animation as image() member of the canvas widget, which is the default.

Needed for special use cases.

OPTIMIZE_MEMORY 

Often frames change just a small area of the animation canvas.

This flag indicates to the loader to try using less memory by storing frame data not as canvas-sized images but use the sizes defined in the GIF file. The drawbacks are higher cpu usage during playback and maybe minor artifacts when resized.

LOG_FLAG 

This flag can be used to print informations about the decoding process to the console.

DEBUG_FLAG 

This flag can be used to print even more informations about the decoding process to the console.

Constructor & Destructor Documentation

◆ Fl_Anim_GIF_Image() [1/2]

Fl_Anim_GIF_Image::Fl_Anim_GIF_Image ( const char *  filename,
Fl_Widget canvas = 0,
unsigned short  flags = 0 
)

Load an animated GIF image from a file.

This constructor creates an animated image from a GIF-formatted file. Optionally it applies the canvas() method after successful load. If DONT_START is not specified in the flags parameter it calls start() after successful load.

Parameters
[in]filenamepath and name of GIF file in the file system
[in]canvasa widget that will show and animate the GIF, or NULL
[in]flagssee Flags for details, or 0
Note
The GIF image must be decoupled from the canvas by calling myGif->canvas(NULL); before deleting the canvas.

◆ Fl_Anim_GIF_Image() [2/2]

Fl_Anim_GIF_Image::Fl_Anim_GIF_Image ( const char *  imagename,
const unsigned char *  data,
const size_t  length,
Fl_Widget canvas = 0,
unsigned short  flags = 0 
)

Load an animated GIF image from memory.

This constructor creates an animated image from a GIF-formatted block in memory. Optionally it applies the canvas() method after successful load. If DONT_START is not specified in the flags parameter it calls start() after successful load.

imagename can be NULL. If a name is given, the image is added to the list of shared images and will be available by that name.

Parameters
[in]imagenamea name given to this image or NULL
[in]datapointer to the start of the GIF image in memory
[in]lengthlength of the GIF image in memory
[in]canvasa widget that will show and animate the GIF, or NULL
[in]flagssee Flags for details, or 0
Note
The GIF image must be decoupled from the canvas by calling myGif->canvas(NULL); before deleting the canvas.

◆ ~Fl_Anim_GIF_Image()

Fl_Anim_GIF_Image::~Fl_Anim_GIF_Image ( )

Release the image and all cached data.

Also removes the animation timer.

Member Function Documentation

◆ canvas() [1/2]

Fl_Widget * Fl_Anim_GIF_Image::canvas ( ) const

Gets the current widget, that is used to display the frame images.

Returns
a pointer to a widget

◆ canvas() [2/2]

void Fl_Anim_GIF_Image::canvas ( Fl_Widget canvas,
unsigned short  flags = 0 
)

Link the image back to a widget for automated animation.

This method sets current widget, that is used to display the frame images. The flags parameter specifies whether the canvas widget is resized to the animation dimensions and/or its image() method will be used to set the current frame image during animation.

Parameters
[in]canvasa pointer to the widget that will show the animation
[in]flagssee Flags
Note
The GIF image must be decoupled from the canvas by calling myGif->canvas(NULL); before deleting the canvas.

◆ canvas_h()

int Fl_Anim_GIF_Image::canvas_h ( ) const

Return the height of the animation canvas.

Returns
the width in pixel units

◆ canvas_w()

int Fl_Anim_GIF_Image::canvas_w ( ) const

Return the width of the animation canvas.

Returns
the width in pixel units

◆ color_average()

void Fl_Anim_GIF_Image::color_average ( Fl_Color  c,
float  i 
)
virtual

Applies a color average to all frames.

The color_average() method averages the colors in the image with the provided FLTK color value.

Parameters
[in]cblend color
[in]ia value between 0.0 and 1.0 where 0 results in the blend color, and 1 returns the original image

Reimplemented from Fl_Image.

◆ copy()

Fl_Image * Fl_Anim_GIF_Image::copy ( int  W,
int  H 
) const
virtual

Copy and resize the animation frames.

The virtual copy() method makes a copy of the animated image and resizes all of its frame images to W x H using the current resize method.

Parameters
[in]W,Hnew size in FLTK pixel units
Returns
the resized copy of the animation

Reimplemented from Fl_Image.

◆ delay() [1/2]

void Fl_Anim_GIF_Image::delay ( int  frame,
double  delay 
)

Set the delay of frame [0-frames() -1] in seconds.

Parameters
[in]frameindex into frame list
[in]delayto next frame in seconds

◆ delay() [2/2]

double Fl_Anim_GIF_Image::delay ( int  frame) const

Return the delay of frame [0-frames() -1] in seconds.

Parameters
[in]frameindex into frame list
Returns
delay to next frame in seconds

◆ desaturate()

void Fl_Anim_GIF_Image::desaturate ( )
virtual

Desaturate to all frames of the animation.

Reimplemented from Fl_Image.

◆ draw()

void Fl_Anim_GIF_Image::draw ( int  x,
int  y,
int  w,
int  h,
int  cx = 0,
int  cy = 0 
)
virtual

Draw the current frame of the animation.

Parameters
[in]x,y,w,htarget rectangle
[in]cx,cysource offset

Reimplemented from Fl_Image.

◆ frame() [1/2]

int Fl_Anim_GIF_Image::frame ( ) const

Return the current frame.

Returns
the current frame index in the range for 0 to frames()-1.
-1 if the image has no frames.

◆ frame() [2/2]

void Fl_Anim_GIF_Image::frame ( int  frame)

Set the current frame.

Parameters
[in]frameindex into list of frames

◆ frame_count()

int Fl_Anim_GIF_Image::frame_count ( const char *  name,
const unsigned char *  imgdata = NULL,
size_t  imglength = 0 
)
static

Get the number of frames in a GIF file or in a GIF compressed data block.

The static frame_count() method is just a convenience method for getting the number of images (frames) stored in a GIF file.

As this count is not readily available in the GIF header, the whole GIF file has be parsed (which is done here by using a temporary Fl_Anim_GIF_Image object for simplicity). So this call may be slow with large files.

If imgdata is NULL, the image will be read from the file. Otherwise, it will be read from memory.

Parameters
[in]namepath and name of GIF file in the file system, ignored when reading from memeory
[in]imgdatapointer to the start of the GIF image in memory, or NULL to read from a file
[in]imglengthlength of the GIF image in memory, or 0
Returns
the number of frames in the animation

◆ frame_h()

int Fl_Anim_GIF_Image::frame_h ( int  frame) const

Return the frame dimensions of a frame.

Usefull only if loaded with 'optimize_mem' and the animation also has size optimized frames.

Parameters
[in]frameindex into frame list
Returns
height in FLTK pixle units

◆ frame_uncache() [1/2]

bool Fl_Anim_GIF_Image::frame_uncache ( ) const

Return the active frame_uncache() setting.

Returns
true if caching is disabled

◆ frame_uncache() [2/2]

void Fl_Anim_GIF_Image::frame_uncache ( bool  uncache)

Use frame_uncache() to set or forbid frame image uncaching.

If frame uncaching is set, frame images are not offscreen cached for re-use and will be re-created every time they are displayed. This saves a lot of memory on the expense of cpu usage and should be carefully considered. Per default frame caching will be done.

Parameters
[in]uncachetrue to disable caching

◆ frame_w()

int Fl_Anim_GIF_Image::frame_w ( int  frame) const

Return the frame dimensions of a frame.

Usefull only if loaded with 'optimize_mem' and the animation also has size optimized frames.

Parameters
[in]frameindex into frame list
Returns
width in FLTK pixle units

◆ frame_x()

int Fl_Anim_GIF_Image::frame_x ( int  frame) const

Return the frame position of a frame.

Usefull only if loaded with 'optimize_mem' and the animation also has size optimized frames.

Parameters
[in]frameindex into frame list
Returns
x position in FLTK pixle units

◆ frame_y()

int Fl_Anim_GIF_Image::frame_y ( int  frame) const

Return the frame position of a frame.

Usefull only if loaded with 'optimize_mem' and the animation also has size optimized frames.

Parameters
[in]frameindex into frame list
Returns
y position in FLTK pixle units

◆ frames()

int Fl_Anim_GIF_Image::frames ( ) const

Get the number of frames in the animation.

Returns
the number of frames

◆ image() [1/2]

Fl_Image * Fl_Anim_GIF_Image::image ( ) const

Return the current frame image.

Returns
a pointer to the image or NULL if this is not an animation.

◆ image() [2/2]

Fl_Image * Fl_Anim_GIF_Image::image ( int  frame_) const

Return the image of the given frame index.

Parameters
[in]frame_index into list of frames
Returns
image data or NULL if the frame number is not valid.

◆ is_animated()

bool Fl_Anim_GIF_Image::is_animated ( ) const

Check if this is a valid animation with more than one frame.

The is_animated() method is just a convenience method for testing the valid flag and the frame count beeing greater 1.

Returns
true if the animation is valid and has multiple frames.

◆ load()

bool Fl_Anim_GIF_Image::load ( const char *  name,
const unsigned char *  imgdata = NULL,
size_t  imglength = 0 
)

Load an animation from a file or from a memory block.

The load() method is either used from the constructor to load the image from the given file, or to re-load an existing animation from another file.

Parameters
[in]namepath and name of GIF file in the file system, or the image name when reading from memory
[in]imgdatapointer to the start of the GIF image in memory, or NULL to read from a file
[in]imglengthlength of the GIF image in memory, or 0
Returns
true if the animation loaded correctly

◆ name()

const char * Fl_Anim_GIF_Image::name ( ) const

Return the name of the played file as specified in the constructor.

If read from a memory block, this returns the name of the animation.

Returns
pointer to a C string

◆ next()

bool Fl_Anim_GIF_Image::next ( )

Show the next frame if the animation is stopped.

Returns
true if the animation has frames

◆ on_extension_data()

void Fl_Anim_GIF_Image::on_extension_data ( Fl_GIF_Image::GIF_FRAME f)
protectedvirtual

Reimplemented from Fl_GIF_Image.

◆ on_frame_data()

void Fl_Anim_GIF_Image::on_frame_data ( Fl_GIF_Image::GIF_FRAME f)
protectedvirtual

Reimplemented from Fl_GIF_Image.

◆ playing()

bool Fl_Anim_GIF_Image::playing ( ) const
inline

Return if the animation is currently running or stopped.

Returns
true if the animation is running

◆ resize() [1/2]

Fl_Anim_GIF_Image & Fl_Anim_GIF_Image::resize ( double  scale)

Resizes the image to the specified size, replacing the current image.

If DONT_RESIZE_CANVAS is not set, the canvas widget will also be resized.

Parameters
[in]scalerescale factor in relation to current size

◆ resize() [2/2]

Fl_Anim_GIF_Image & Fl_Anim_GIF_Image::resize ( int  w,
int  h 
)

Resizes the image to the specified size, replacing the current image.

If DONT_RESIZE_CANVAS is not set, the canvas widget will also be resized.

Parameters
[in]w,hnew size of teh naimtion frames

◆ speed() [1/2]

double Fl_Anim_GIF_Image::speed ( ) const

Get the animation speed factor.

Returns
the current speed factor

◆ speed() [2/2]

void Fl_Anim_GIF_Image::speed ( double  speed)

Set the animation speed factor.

The speed() method changes the playing speed to speed x original speed. E.g. to play at half speed call it with 0.5, for double speed with 2.

Parameters
[in]speedfloating point speed factor

◆ start()

bool Fl_Anim_GIF_Image::start ( )

The start() method (re-)starts the playing of the frames.

Returns
true if the animation has frames

◆ stop()

bool Fl_Anim_GIF_Image::stop ( )

The stop() method stops the playing of the frames.

Returns
true if the animation has frames

◆ uncache()

void Fl_Anim_GIF_Image::uncache ( )
virtual

Uncache all cached image data now.

Re-implemented from Fl_Pixmap.

Reimplemented from Fl_Image.

◆ valid()

bool Fl_Anim_GIF_Image::valid ( ) const

Check if animation is valid.

Returns
true if the class has successfully loaded and the image has at least one frame.

Member Data Documentation

◆ loop

bool Fl_Anim_GIF_Image::loop = true
static

The loop flag can be used to (dis-)allow loop count.

If set (which is the default), the animation will be stopped after the number of repeats specified in the GIF file (typically this count is set to 'forever' anyway). If cleared the animation will always be 'forever', regardless of what is specified in the GIF file.

◆ min_delay

double Fl_Anim_GIF_Image::min_delay = 0.
static

The min_delay value can be used to set a minimum value for the frame delay for playback.

This is to prevent CPU hogs caused by images with very low delay rates. This is a global value for all Fl_Anim_GIF_Image objects.


The documentation for this class was generated from the following files: