diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2022-11-28 17:26:37 +0100 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2022-12-09 10:43:20 +0100 |
| commit | 36cd0a397c6d8fee7ffc5b59d607ead523226e53 (patch) | |
| tree | 91f0bd3628ae3d7b7553706b24b66b1bb4620c6b /src/Fl_PNG_Image.cxx | |
| parent | 0bb30d8f92839af826fb389fccd625c74e981a13 (diff) | |
New Fl_ICO_Image class to read Windows .ico icon files
Many thanks to @darealshinji for contributing all the code
for this new FLTK image class (see branch Fl_ICO_Image of https://github.com/darealshinji/fltk).
Diffstat (limited to 'src/Fl_PNG_Image.cxx')
| -rw-r--r-- | src/Fl_PNG_Image.cxx | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/Fl_PNG_Image.cxx b/src/Fl_PNG_Image.cxx index e4584b188..6dbc75b15 100644 --- a/src/Fl_PNG_Image.cxx +++ b/src/Fl_PNG_Image.cxx @@ -4,7 +4,7 @@ // Copyright 1997-2012 by Easy Software Products. // Image support by Matthias Melcher, Copyright 2000-2009. // -// Copyright 2013-2021 by Bill Spitzak and others. +// Copyright 2013-2022 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -87,9 +87,15 @@ extern "C" { */ Fl_PNG_Image::Fl_PNG_Image (const char *filename): Fl_RGB_Image(0,0,0) { - load_png_(filename, NULL, 0); + load_png_(filename, 0, NULL, 0); } +// private c'tor used by Fl_ICO_Image +// \param offset Offset to seek for the begin of PNG data inside a .ICO file +Fl_PNG_Image::Fl_PNG_Image (const char *filename, int offset): Fl_RGB_Image(0,0,0) +{ + load_png_(filename, offset, NULL, 0); +} /** \brief Constructor that reads a PNG image from memory. @@ -106,11 +112,11 @@ Fl_PNG_Image::Fl_PNG_Image (const char *filename): Fl_RGB_Image(0,0,0) Fl_PNG_Image::Fl_PNG_Image ( const char *name_png, const unsigned char *buffer, int maxsize): Fl_RGB_Image(0,0,0) { - load_png_(name_png, buffer, maxsize); + load_png_(name_png, 0, buffer, maxsize); } -void Fl_PNG_Image::load_png_(const char *name_png, const unsigned char *buffer_png, int maxsize) +void Fl_PNG_Image::load_png_(const char *name_png, int offset, const unsigned char *buffer_png, int maxsize) { #if defined(HAVE_LIBPNG) && defined(HAVE_LIBZ) int i; // Looping var @@ -134,6 +140,12 @@ void Fl_PNG_Image::load_png_(const char *name_png, const unsigned char *buffer_p delete fp; return; } + if (offset > 0 && fseek(*fp, (long)offset, SEEK_SET) == -1) { + fclose(*fp); + ld(ERR_FORMAT); + delete fp; + return; + } } const char *display_name = (name_png ? name_png : "In-memory PNG data"); |
