Separate Fl_GIF_Image constructors with and w/o length arg
Document clearly that reading from memory w/o the length argument (old constructor) is discouraged (deprecated).
This commit is contained in:
parent
01ea77ed88
commit
59836fb19f
@ -31,7 +31,10 @@ class FL_EXPORT Fl_GIF_Image : public Fl_Pixmap {
|
||||
public:
|
||||
|
||||
Fl_GIF_Image(const char* filename);
|
||||
Fl_GIF_Image(const char* imagename, const unsigned char *data, const long length = -1);
|
||||
// deprecated constructor w/o length (for backwards compatibility)
|
||||
Fl_GIF_Image(const char* imagename, const unsigned char *data);
|
||||
// constructor with length (since 1.4.0)
|
||||
Fl_GIF_Image(const char* imagename, const unsigned char *data, const size_t length);
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -146,16 +146,8 @@ Fl_GIF_Image::Fl_GIF_Image(const char *filename) :
|
||||
The destructor frees all memory and server resources that are used by
|
||||
the image.
|
||||
|
||||
The (new and optional) third parameter \p length \b should be used so buffer
|
||||
overruns (i.e. truncated images) can be checked. See note below.
|
||||
|
||||
If \p length is not used
|
||||
- it defaults to -1 (unlimited size)
|
||||
- buffer overruns will not be checked.
|
||||
|
||||
\note The optional parameter \p length is available since FLTK 1.4.0.
|
||||
Not using it is deprecated and old code should be modified to use it.
|
||||
This parameter will likely become mandatory in a future FLTK version.
|
||||
The third parameter \p length is used to test for buffer overruns,
|
||||
i.e. truncated images.
|
||||
|
||||
Use Fl_Image::fail() to check if Fl_GIF_Image failed to load. fail() returns
|
||||
ERR_FILE_ACCESS if the file could not be opened or read, ERR_FORMAT if the
|
||||
@ -168,8 +160,10 @@ Fl_GIF_Image::Fl_GIF_Image(const char *filename) :
|
||||
|
||||
\see Fl_GIF_Image::Fl_GIF_Image(const char *filename)
|
||||
\see Fl_Shared_Image
|
||||
|
||||
\since 1.4.0
|
||||
*/
|
||||
Fl_GIF_Image::Fl_GIF_Image(const char *imagename, const unsigned char *data, const long length) :
|
||||
Fl_GIF_Image::Fl_GIF_Image(const char *imagename, const unsigned char *data, const size_t length) :
|
||||
Fl_Pixmap((char *const*)0)
|
||||
{
|
||||
Fl_Image_Reader rdr;
|
||||
@ -180,10 +174,43 @@ Fl_GIF_Image::Fl_GIF_Image(const char *imagename, const unsigned char *data, con
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
This constructor loads a GIF image from memory (deprecated).
|
||||
|
||||
\deprecated Please use
|
||||
Fl_GIF_Image(const char *imagename, const unsigned char *data, const size_t length)
|
||||
instead.
|
||||
|
||||
\note Buffer overruns will not be checked.
|
||||
|
||||
This constructor should not be used because the caller can't supply the
|
||||
memory size and the image reader can't check for "end of memory" errors.
|
||||
|
||||
\note A new constructor with parameter \p length is available since FLTK 1.4.0.
|
||||
|
||||
\param[in] imagename A name given to this image or NULL
|
||||
\param[in] data Pointer to the start of the GIF image in memory.
|
||||
|
||||
\see Fl_GIF_Image(const char *filename)
|
||||
\see Fl_GIF_Image(const char *imagename, const unsigned char *data, const size_t length)
|
||||
*/
|
||||
Fl_GIF_Image::Fl_GIF_Image(const char *imagename, const unsigned char *data) :
|
||||
Fl_Pixmap((char *const*)0)
|
||||
{
|
||||
Fl_Image_Reader rdr;
|
||||
if (rdr.open(imagename, data) == -1) {
|
||||
ld(ERR_FILE_ACCESS);
|
||||
} else {
|
||||
load_gif_(rdr);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
This method reads GIF image data and creates an RGB or RGBA image. The GIF
|
||||
format supports only 1 bit for alpha. To avoid code duplication, we use
|
||||
an Fl_Image_Reader that reads data from either a file or from memory.
|
||||
This method reads GIF image data and creates an RGB or RGBA image. The GIF
|
||||
format supports only 1 bit for alpha. The final image data is stored in
|
||||
a modified XPM format (Fl_GIF_Image is a subclass of Fl_Pixmap).
|
||||
To avoid code duplication, we use an Fl_Image_Reader that reads data from
|
||||
either a file or from memory.
|
||||
*/
|
||||
void Fl_GIF_Image::load_gif_(Fl_Image_Reader &rdr)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user