FLTK 1.4.0
|
The Fl_Anim_GIF_Image class supports loading, caching, and drawing of animated Compuserve GIFSM images. More...
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_Widget * | canvas () const |
Gets the current widget, that is used to display the frame images. More... | |
void | canvas (Fl_Widget *canvas, unsigned short flags=0) |
Link the image back to a widget for automated animation. More... | |
int | canvas_h () const |
Return the height of the animation canvas. More... | |
int | canvas_w () const |
Return the width of the animation canvas. More... | |
void | color_average (Fl_Color c, float i) FL_OVERRIDE |
Applies a color average to all frames. More... | |
Fl_Image * | copy () const |
Fl_Image * | copy (int W, int H) const FL_OVERRIDE |
Copy and resize the animation frames. More... | |
int | debug () const |
void | delay (int frame, double delay) |
Set the delay of frame [0-frames() -1] in seconds. More... | |
double | delay (int frame_) const |
Return the delay of frame [0-frames() -1] in seconds. More... | |
void | desaturate () FL_OVERRIDE |
Desaturate to all frames of the animation. More... | |
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. More... | |
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. More... | |
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. More... | |
int | frame () const |
Return the current frame. More... | |
void | frame (int frame) |
Set the current frame. More... | |
int | frame_h (int frame) const |
Return the frame dimensions of a frame. More... | |
bool | frame_uncache () const |
Return the active frame_uncache() setting. More... | |
void | frame_uncache (bool uncache) |
Use frame_uncache() to set or forbid frame image uncaching. More... | |
int | frame_w (int frame) const |
Return the frame dimensions of a frame. More... | |
int | frame_x (int frame) const |
Return the frame position of a frame. More... | |
int | frame_y (int frame) const |
Return the frame position of a frame. More... | |
int | frames () const |
Get the number of frames in the animation. More... | |
Fl_Image * | image () const |
Return the current frame image. More... | |
Fl_Image * | image (int frame) const |
Return the image of the given frame index. More... | |
bool | is_animated () const |
Check if this is a valid animation with more than one frame. More... | |
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. More... | |
const char * | name () const |
Return the name of the played file as specified in the constructor. More... | |
bool | next () |
Show the next frame if the animation is stopped. More... | |
bool | playing () const |
Return if the animation is currently running or stopped. More... | |
Fl_Anim_GIF_Image & | resize (double scale) |
Resizes the image to the specified size, replacing the current image. More... | |
Fl_Anim_GIF_Image & | resize (int w, int h) |
Resizes the image to the specified size, replacing the current image. More... | |
double | speed () const |
Get the animation speed factor. More... | |
void | speed (double speed) |
Set the animation speed factor. More... | |
bool | start () |
The start() method (re-)starts the playing of the frames. More... | |
bool | stop () |
The stop() method stops the playing of the frames. More... | |
void | uncache () FL_OVERRIDE |
Uncache all cached image data now. More... | |
bool | valid () const |
Check if animation is valid. More... | |
~Fl_Anim_GIF_Image () FL_OVERRIDE | |
Release the image and all cached data. More... | |
Public Member Functions inherited from Fl_GIF_Image | |
Fl_GIF_Image (const char *filename) | |
This constructor loads a GIF image from the given file. More... | |
Fl_GIF_Image (const char *imagename, const unsigned char *data) | |
This constructor loads a GIF image from memory (deprecated). More... | |
Fl_GIF_Image (const char *imagename, const unsigned char *data, const size_t length) | |
This constructor loads a GIF image from memory. More... | |
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. More... | |
Fl_Image * | copy () const |
Fl_Image * | copy (int W, int H) const FL_OVERRIDE |
Creates a resized copy of the image. More... | |
void | desaturate () FL_OVERRIDE |
The desaturate() method converts an image to grayscale. More... | |
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. More... | |
Fl_Pixmap (char *const *D) | |
The constructors create a new pixmap from the specified XPM data. More... | |
Fl_Pixmap (const char *const *D) | |
The constructors create a new pixmap from the specified XPM data. More... | |
Fl_Pixmap (const uchar *const *D) | |
The constructors create a new pixmap from the specified XPM data. More... | |
Fl_Pixmap (uchar *const *D) | |
The constructors create a new pixmap from the specified XPM data. More... | |
void | label (Fl_Menu_Item *m) FL_OVERRIDE |
This method is an obsolete way to set the image attribute of a menu item. More... | |
void | label (Fl_Widget *w) FL_OVERRIDE |
This method is an obsolete way to set the image attribute of a widget or menu item. More... | |
void | uncache () FL_OVERRIDE |
If the image has been cached for display, delete the cache data. More... | |
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_Image * | as_shared_image () |
Returns whether an image is an Fl_Shared_Image or not. More... | |
virtual void | color_average (Fl_Color c, float i) |
The color_average() method averages the colors in the image with the provided FLTK color value. More... | |
Fl_Image * | copy () const |
Creates a copy of the image in the same size. More... | |
virtual Fl_Image * | copy (int W, int H) const |
Creates a resized copy of the image. More... | |
int | count () const |
Returns the number of data values associated with the image. More... | |
int | d () const |
Returns the image depth. More... | |
const char *const * | data () const |
Returns a pointer to the current image data array. More... | |
int | data_h () const |
Returns the height of the image data. | |
int | data_w () const |
Returns the width of the image data. | |
virtual void | desaturate () |
The desaturate() method converts an image to grayscale. More... | |
void | draw (int X, int Y) |
Draws the image to the current drawing surface. More... | |
virtual void | draw (int X, int Y, int W, int H, int cx=0, int cy=0) |
Draws the image to the current drawing surface with a bounding box. More... | |
int | fail () const |
Returns a value that is not 0 if there is currently no image available. More... | |
Fl_Image (int W, int H, int D) | |
The constructor creates an empty image with the specified width, height, and depth. More... | |
int | h () const |
Returns the current image drawing height in FLTK units. More... | |
void | inactive () |
The inactive() method calls color_average(FL_BACKGROUND_COLOR, 0.33f) to produce an image that appears grayed out. More... | |
virtual void | label (Fl_Menu_Item *m) |
This method is an obsolete way to set the image attribute of a menu item. More... | |
virtual void | label (Fl_Widget *w) |
This method is an obsolete way to set the image attribute of a widget or menu item. More... | |
int | ld () const |
Returns the current line data size in bytes. More... | |
virtual void | release () |
Releases an Fl_Image - the same as 'delete this' . More... | |
virtual void | scale (int width, int height, int proportional=1, int can_expand=0) |
Sets the drawing size of the image. More... | |
virtual void | uncache () |
If the image has been cached for display, delete the cache data. More... | |
int | w () const |
Returns the current image drawing width in FLTK units. More... | |
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. More... | |
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). More... | |
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. More... | |
Static Public Attributes | |
static bool | loop = true |
The loop flag can be used to (dis-)allow loop count. More... | |
static double | min_delay = 0. |
The min_delay value can be used to set a minimum value for the frame delay for playback. More... | |
Static Public Attributes inherited from Fl_GIF_Image | |
static bool | animate = false |
Sets how the shared image core routine should treat animated GIF files. More... | |
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) |
virtual void | on_extension_data (GIF_FRAME &) |
virtual void | on_frame_data (GIF_FRAME &) |
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. More... | |
void | draw_empty (int X, int Y) |
The protected method draw_empty() draws a box with an X in it. More... | |
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. More... | |
void | h (int H) |
Sets the height of the image data. More... | |
void | ld (int LD) |
Sets the current line data size in bytes. More... | |
void | w (int W) |
Sets the width of the image data. More... | |
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 |
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.
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. |
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.
[in] | filename | path and name of GIF file in the file system |
[in] | canvas | a widget that will show and animate the GIF, or NULL |
[in] | flags | see Flags for details, or 0 |
myGif->canvas(NULL);
before deleting the canvas. 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.
[in] | imagename | a name given to this image or NULL |
[in] | data | pointer to the start of the GIF image in memory |
[in] | length | length of the GIF image in memory |
[in] | canvas | a widget that will show and animate the GIF, or NULL |
[in] | flags | see Flags for details, or 0 |
myGif->canvas(NULL);
before deleting the canvas. Fl_Anim_GIF_Image::~Fl_Anim_GIF_Image | ( | ) |
Release the image and all cached data.
Also removes the animation timer.
Fl_Widget * Fl_Anim_GIF_Image::canvas | ( | ) | const |
Gets the current widget, that is used to display the frame images.
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.
[in] | canvas | a pointer to the widget that will show the animation |
[in] | flags | see Flags |
myGif->canvas(NULL);
before deleting the canvas. int Fl_Anim_GIF_Image::canvas_h | ( | ) | const |
Return the height of the animation canvas.
int Fl_Anim_GIF_Image::canvas_w | ( | ) | const |
Return the width of the animation canvas.
|
virtual |
Applies a color average to all frames.
The color_average() method averages the colors in the image with the provided FLTK color value.
[in] | c | blend color |
[in] | i | a value between 0.0 and 1.0 where 0 results in the blend color, and 1 returns the original image |
Reimplemented from Fl_Image.
|
virtual |
void Fl_Anim_GIF_Image::delay | ( | int | frame, |
double | delay | ||
) |
Set the delay of frame [0-frames() -1]
in seconds.
[in] | frame | index into frame list |
[in] | delay | to next frame in seconds |
double Fl_Anim_GIF_Image::delay | ( | int | frame | ) | const |
Return the delay of frame [0-frames() -1]
in seconds.
[in] | frame | index into frame list |
|
virtual |
Desaturate to all frames of the animation.
Reimplemented from Fl_Image.
|
virtual |
Draw the current frame of the animation.
[in] | x,y,w,h | target rectangle |
[in] | cx,cy | source offset |
Reimplemented from Fl_Image.
int Fl_Anim_GIF_Image::frame | ( | ) | const |
Return the current frame.
frames()-1
. void Fl_Anim_GIF_Image::frame | ( | int | frame | ) |
Set the current frame.
[in] | frame | index into list of frames |
|
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.
[in] | name | path and name of GIF file in the file system, ignored when reading from memeory |
[in] | imgdata | pointer to the start of the GIF image in memory, or NULL to read from a file |
[in] | imglength | length of the GIF image in memory, or 0 |
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.
[in] | frame | index into frame list |
bool Fl_Anim_GIF_Image::frame_uncache | ( | ) | const |
Return the active frame_uncache() setting.
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.
[in] | uncache | true to disable caching |
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.
[in] | frame | index into frame list |
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.
[in] | frame | index into frame list |
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.
[in] | frame | index into frame list |
int Fl_Anim_GIF_Image::frames | ( | ) | const |
Get the number of frames in the animation.
Fl_Image * Fl_Anim_GIF_Image::image | ( | ) | const |
Return the current frame image.
Fl_Image * Fl_Anim_GIF_Image::image | ( | int | frame_ | ) | const |
Return the image of the given frame index.
[in] | frame_ | index into list of frames |
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.
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.
[in] | name | path and name of GIF file in the file system, or the image name when reading from memory |
[in] | imgdata | pointer to the start of the GIF image in memory, or NULL to read from a file |
[in] | imglength | length of the GIF image in memory, or 0 |
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.
bool Fl_Anim_GIF_Image::next | ( | ) |
Show the next frame if the animation is stopped.
|
protectedvirtual |
Reimplemented from Fl_GIF_Image.
|
protectedvirtual |
Reimplemented from Fl_GIF_Image.
|
inline |
Return if the animation is currently running or stopped.
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.
[in] | scale | rescale factor in relation to current size |
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.
[in] | w,h | new size of teh naimtion frames |
double Fl_Anim_GIF_Image::speed | ( | ) | const |
Get the animation speed factor.
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.
[in] | speed | floating point speed factor |
bool Fl_Anim_GIF_Image::start | ( | ) |
The start() method (re-)starts the playing of the frames.
bool Fl_Anim_GIF_Image::stop | ( | ) |
The stop() method stops the playing of the frames.
|
virtual |
bool Fl_Anim_GIF_Image::valid | ( | ) | const |
Check if animation is valid.
|
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.
|
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.