mirror of
https://github.com/fltk/fltk.git
synced 2026-05-10 05:27:55 +08:00
Fix Fl_ICO_Image reading from memory block, #1420
This commit is contained in:
+10
-1
@@ -153,7 +153,16 @@ void Fl_ICO_Image::load_ico_(Fl_Image_Reader &rdr, int id)
|
||||
b[4]=='\r' && b[5]=='\n' && b[6]==0x1A && b[7]=='\n')
|
||||
{
|
||||
#if defined(HAVE_LIBPNG) && defined(HAVE_LIBZ)
|
||||
Fl_PNG_Image *png = new Fl_PNG_Image(rdr.name(), icondirentry_[pickedID].dwImageOffset);
|
||||
Fl_PNG_Image *png;
|
||||
if (rdr.is_data()) {
|
||||
size_t offset = icondirentry_[pickedID].dwImageOffset;
|
||||
size_t size = rdr.data_size();
|
||||
if (size) size -= offset;
|
||||
// `size` points at the end of the .ico data. The PNG may end before that.
|
||||
png = new Fl_PNG_Image(rdr.name(), rdr.data_start()+offset, size);
|
||||
} else {
|
||||
png = new Fl_PNG_Image(rdr.name(), icondirentry_[pickedID].dwImageOffset);
|
||||
}
|
||||
|
||||
int loaded = png ? png->fail() : ERR_FILE_ACCESS;
|
||||
if (loaded < 0) {
|
||||
|
||||
@@ -83,6 +83,25 @@ public:
|
||||
// skip a given number of bytes
|
||||
void skip(unsigned int n) { seek((unsigned int)tell() + n); }
|
||||
|
||||
// return 1 if we are reading from a file, 0 otherwise
|
||||
char is_file() const { return is_file_; }
|
||||
|
||||
// return 1 if we are reading from a block of memory, 0 otherwise
|
||||
char is_data() const { return is_data_; }
|
||||
|
||||
// return the start address of the data block if reading from memory, otherwise nullptr
|
||||
const unsigned char *data_start() const { return start_; }
|
||||
|
||||
// return the size of the data block if reading from memoryand the size of
|
||||
// the block is known, otherwise 0
|
||||
size_t data_size() const {
|
||||
if (is_data_ && end_ && end_ != (const unsigned char *)(-1L)) {
|
||||
return (size_t)(end_ - start_);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
// open() sets this if we read from a file
|
||||
char is_file_;
|
||||
|
||||
Reference in New Issue
Block a user