[master] 59836fb - Separate Fl_GIF_Image constructors with and w/o length arg

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] 59836fb - Separate Fl_GIF_Image constructors with and w/o length arg "Albrecht Schlosser" 09:47 Oct 02 top right image
 
commit 59836fb19f45d123e0f75b47c497b97aaa7bdfbe
Author:     Albrecht Schlosser <albrechts.fltk@online.de>
AuthorDate: Sat Oct 2 17:01:00 2021 +0200
Commit:     Albrecht Schlosser <albrechts.fltk@online.de>
CommitDate: Sat Oct 2 18:40:32 2021 +0200

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

 FL/Fl_GIF_Image.H    |  5 ++++-
 src/Fl_GIF_Image.cxx | 55 +++++++++++++++++++++++++++++++++++++++-------------
 2 files changed, 45 insertions(+), 15 deletions(-)

diff --git FL/Fl_GIF_Image.H FL/Fl_GIF_Image.H
index 274af9a..4871bf5 100644
--- FL/Fl_GIF_Image.H
+++ FL/Fl_GIF_Image.H
@@ -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:
 
diff --git src/Fl_GIF_Image.cxx src/Fl_GIF_Image.cxx
index 6ae3f6c..b006a43 100644
--- src/Fl_GIF_Image.cxx
+++ src/Fl_GIF_Image.cxx
@@ -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)
 {
Direct Link to Message ]
 
bottom left image   bottom right image
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2022 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.