// get the resolution from the image options or fall back to 72dpi standard
// for the BMP format if not specified
// get the resolution from the image options or fall back to 72dpi standard
// for the BMP format if not specified
- wxUint32 hres = image->GetOptionInt(wxIMAGE_OPTION_RESOLUTIONX),
- vres = image->GetOptionInt(wxIMAGE_OPTION_RESOLUTIONY);
- switch ( image->GetOptionInt(wxIMAGE_OPTION_RESOLUTION) )
+ int hres, vres;
+ switch ( GetResolutionFromOptions(*image, &hres, &vres) )
bool wxBMPHandler::DoLoadDib(wxImage * image, int width, int height,
int bpp, int ncolors, int comp,
wxFileOffset bmpOffset, wxInputStream& stream,
bool verbose, bool IsBmp, bool hasPalette)
{
bool wxBMPHandler::DoLoadDib(wxImage * image, int width, int height,
int bpp, int ncolors, int comp,
wxFileOffset bmpOffset, wxInputStream& stream,
bool verbose, bool IsBmp, bool hasPalette)
{
- wxInt32 aDword, rmask = 0, gmask = 0, bmask = 0;
- int rshift = 0, gshift = 0, bshift = 0;
+ wxInt32 aDword, rmask = 0, gmask = 0, bmask = 0, amask = 0;
+ int rshift = 0, gshift = 0, bshift = 0, ashift = 0;
// Reading the palette, if it exists:
if ( bpp < 16 && ncolors != 0 )
{
// Reading the palette, if it exists:
if ( bpp < 16 && ncolors != 0 )
{
stream.Read(dbuf, 4 * 3);
rmask = wxINT32_SWAP_ON_BE(dbuf[0]);
gmask = wxINT32_SWAP_ON_BE(dbuf[1]);
stream.Read(dbuf, 4 * 3);
rmask = wxINT32_SWAP_ON_BE(dbuf[0]);
gmask = wxINT32_SWAP_ON_BE(dbuf[1]);
- stream.SeekI(bmpOffset); // else icon, just carry on
+ {
+ // NOTE: seeking a positive amount in wxFromCurrent mode allows us to
+ // load even non-seekable streams (see wxInputStream::SeekI docs)!
+ const wxFileOffset pos = stream.TellI();
+ if (pos != wxInvalidOffset && bmpOffset > pos)
+ if (stream.SeekI(bmpOffset - pos, wxFromCurrent) == wxInvalidOffset)
+ return false;
+ //else: icon, just carry on
+ }
+ // flag indicating if we have any not fully transparent alpha values: this
+ // is used to account for the bitmaps which use 32bpp format (normally
+ // meaning that they have alpha channel) but have only zeroes in it so that
+ // without this hack they appear fully transparent -- and as this is
+ // unlikely intentional, we consider that they don't have alpha at all in
+ // this case (see #10915)
+ bool hasValidAlpha = false;
+
to retrieve the color data out of the word. Then
shift it left by (8 - number of bits) such that
the image has the proper dynamic range */
to retrieve the color data out of the word. Then
shift it left by (8 - number of bits) such that
the image has the proper dynamic range */
const wxStreamError err = stream.GetLastError();
return err == wxSTREAM_NO_ERROR || err == wxSTREAM_EOF;
}
const wxStreamError err = stream.GetLastError();
return err == wxSTREAM_NO_ERROR || err == wxSTREAM_EOF;
}
stream.Read(dbuf, 4 * 2);
int width = wxINT32_SWAP_ON_BE((int)dbuf[0]);
stream.Read(dbuf, 4 * 2);
int width = wxINT32_SWAP_ON_BE((int)dbuf[0]);
return false;
}
image->SetMaskFromImage(mask, 255, 255, 255);
return false;
}
image->SetMaskFromImage(mask, 255, 255, 255);
return DoLoadFile(image, stream, verbose, index);
}
return DoLoadFile(image, stream, verbose, index);
}
stream.Read(&IconDir, sizeof(IconDir));
wxUint16 nIcons = wxUINT16_SWAP_ON_BE(IconDir.idCount);
stream.Read(&IconDir, sizeof(IconDir));
wxUint16 nIcons = wxUINT16_SWAP_ON_BE(IconDir.idCount);
// nType is 1 for Icons, 2 for Cursors:
wxUint16 nType = wxUINT16_SWAP_ON_BE(IconDir.idType);
// nType is 1 for Icons, 2 for Cursors:
wxUint16 nType = wxUINT16_SWAP_ON_BE(IconDir.idType);
- stream.SeekI(iPos + wxUINT32_SWAP_ON_BE(pCurrentEntry->dwImageOffset), wxFromStart);
+
+ // NOTE: seeking a positive amount in wxFromCurrent mode allows us to
+ // load even non-seekable streams (see wxInputStream::SeekI docs)!
+ wxFileOffset offset = wxUINT32_SWAP_ON_BE(pCurrentEntry->dwImageOffset) - alreadySeeked;
+ if (offset != 0 && stream.SeekI(offset, wxFromCurrent) == wxInvalidOffset)
+ return false;
+
bResult = LoadDib(image, stream, true, IsBmp);
bool bIsCursorType = (this->GetType() == wxBITMAP_TYPE_CUR) || (this->GetType() == wxBITMAP_TYPE_ANI);
if ( bResult && bIsCursorType && nType == 2 )
bResult = LoadDib(image, stream, true, IsBmp);
bool bIsCursorType = (this->GetType() == wxBITMAP_TYPE_CUR) || (this->GetType() == wxBITMAP_TYPE_ANI);
if ( bResult && bIsCursorType && nType == 2 )
- wxFileOffset iPos = stream.TellI();
- stream.SeekI(0);
- stream.Read(&IconDir, sizeof(IconDir));
- wxUint16 nIcons = wxUINT16_SWAP_ON_BE(IconDir.idCount);
- stream.SeekI(iPos);
- return (int)nIcons;
+
+ if (stream.Read(&IconDir, sizeof(IconDir)).LastRead() != sizeof(IconDir))
+ // it's ok to modify the stream position here
+ return 0;
+
+ return (int)wxUINT16_SWAP_ON_BE(IconDir.idCount);