bool IsMask)
{
- wxCHECK_MSG( image, false, _T("invalid pointer in wxBMPHandler::SaveFile") );
+ wxCHECK_MSG( image, false, wxT("invalid pointer in wxBMPHandler::SaveFile") );
if ( !image->Ok() )
{
if ( verbose )
+ {
wxLogError(_("BMP: Couldn't save invalid image."));
+ }
return false;
}
)
{
if ( verbose )
+ {
wxLogError(_("BMP: wxImage doesn't have own wxPalette."));
+ }
return false;
}
bpp = 8;
switch ( GetResolutionFromOptions(*image, &hres, &vres) )
{
default:
- wxFAIL_MSG( _T("unexpected image resolution units") );
+ wxFAIL_MSG( wxT("unexpected image resolution units") );
// fall through
case wxIMAGE_RESOLUTION_NONE:
)
{
if (verbose)
+ {
wxLogError(_("BMP: Couldn't write the file (Bitmap) header."));
+ }
return false;
}
}
)
{
if (verbose)
+ {
wxLogError(_("BMP: Couldn't write the file (BitmapInfo) header."));
+ }
return false;
}
}
if ( !stream.Write(rgbquad, palette_size*4) )
{
if (verbose)
+ {
wxLogError(_("BMP: Couldn't write RGB color map."));
+ }
delete[] rgbquad;
#if wxUSE_PALETTE
delete palette;
if ( !stream.Write(buffer, row_width) )
{
if (verbose)
+ {
wxLogError(_("BMP: Couldn't write data."));
+ }
delete[] buffer;
#if wxUSE_PALETTE
delete palette;
if ( !cmap )
{
if (verbose)
+ {
wxLogError(_("BMP: Couldn't allocate memory."));
+ }
return false;
}
}
if ( !ptr )
{
if ( verbose )
+ {
wxLogError( _("BMP: Couldn't allocate memory.") );
+ }
return false;
}
if ( !alpha )
{
if ( verbose )
+ {
wxLogError(_("BMP: Couldn't allocate memory."));
+ }
return false;
}
}
{
if ( comp == BI_BITFIELDS )
{
- int bit = 0;
+ int bit;
stream.Read(dbuf, 4 * 3);
rmask = wxINT32_SWAP_ON_BE(dbuf[0]);
gmask = wxINT32_SWAP_ON_BE(dbuf[1]);
{
// NOTE: seeking a positive amount in wxFromCurrent mode allows us to
// load even non-seekable streams (see wxInputStream::SeekI docs)!
- if (stream.SeekI(bmpOffset, wxFromCurrent) == wxInvalidOffset)
- return false;
+ const wxFileOffset pos = stream.TellI();
+ if (pos != wxInvalidOffset && bmpOffset > pos)
+ if (stream.SeekI(bmpOffset - pos, wxFromCurrent) == wxInvalidOffset)
+ return false;
//else: icon, just carry on
}
{
for (int nibble = 0; nibble < 2 && column < width; nibble++)
{
- int index = ((aByte & (0xF0 >> nibble * 4)) >> (!nibble * 4));
+ int index = ((aByte & (0xF0 >> (nibble * 4))) >> (!nibble * 4));
if ( index >= 16 )
index = 15;
ptr[poffset] = cmap[index].r;
stream.Read(&aWord, 2);
aWord = wxUINT16_SWAP_ON_BE(aWord);
linepos += 2;
- /* use the masks and calculated amonut of shift
+ /* Use the masks and calculated amount of shift
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 */
- temp = (unsigned char)((aWord & rmask) >> rshift << (8-rbits));
+ temp = (unsigned char)(((aWord & rmask) >> rshift) << (8-rbits));
ptr[poffset] = temp;
- temp = (unsigned char)((aWord & gmask) >> gshift << (8-gbits));
+ temp = (unsigned char)(((aWord & gmask) >> gshift) << (8-gbits));
ptr[poffset + 1] = temp;
- temp = (unsigned char)((aWord & bmask) >> bshift << (8-bbits));
+ temp = (unsigned char)(((aWord & bmask) >> bshift) << (8-bbits));
ptr[poffset + 2] = temp;
column++;
}
if ( width > 32767 )
{
if (verbose)
+ {
wxLogError( _("DIB Header: Image width > 32767 pixels for file.") );
+ }
return false;
}
if ( height > 32767 )
{
if (verbose)
+ {
wxLogError( _("DIB Header: Image height > 32767 pixels for file.") );
+ }
return false;
}
if ( bpp != 1 && bpp != 4 && bpp != 8 && bpp != 16 && bpp != 24 && bpp != 32 )
{
if (verbose)
+ {
wxLogError( _("DIB Header: Unknown bitdepth in file.") );
+ }
return false;
}
comp != BI_BITFIELDS )
{
if (verbose)
+ {
wxLogError( _("DIB Header: Unknown encoding in file.") );
+ }
return false;
}
((comp == BI_BITFIELDS) && (bpp != 16 && bpp != 32)))
{
if (verbose)
+ {
wxLogError( _("DIB Header: Encoding doesn't match bitdepth.") );
+ }
return false;
}
verbose, IsBmp, true) )
{
if (verbose)
+ {
wxLogError( _("Error in reading image DIB.") );
+ }
return false;
}
verbose, IsBmp, false) )
{
if (verbose)
+ {
wxLogError( _("ICO: Error in reading mask DIB.") );
+ }
return false;
}
image->SetMaskFromImage(mask, 255, 255, 255);
if ( image->GetHeight () > 127 )
{
if ( verbose )
+ {
wxLogError(_("ICO: Image too tall for an icon."));
+ }
return false;
}
if ( image->GetWidth () > 255 )
{
if ( verbose )
+ {
wxLogError(_("ICO: Image too wide for an icon."));
+ }
return false;
}
if ( !stream.IsOk() )
{
if ( verbose )
+ {
wxLogError(_("ICO: Error writing the image file!"));
+ }
return false;
}
if ( !bResult )
{
if ( verbose )
+ {
wxLogError(_("ICO: Error writing the image file!"));
+ }
return false;
}
IsMask = true;
if ( !bResult )
{
if ( verbose )
+ {
wxLogError(_("ICO: Error writing the image file!"));
+ }
return false;
}
wxUint32 Size = cStream.GetSize();
if ( !cStream.Ok() )
{
if ( verbose )
+ {
wxLogError(_("ICO: Error writing the image file!"));
+ }
return false;
}
#endif // 0
if ( !stream.IsOk() )
{
if ( verbose )
+ {
wxLogError(_("ICO: Error writing the image file!"));
+ }
return false;
}
if ( !bResult )
{
if ( verbose )
+ {
wxLogError(_("ICO: Error writing the image file!"));
+ }
return false;
}
IsMask = true;
if ( !bResult )
{
if ( verbose )
+ {
wxLogError(_("ICO: Error writing the image file!"));
+ }
return false;
}
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);
int iSel = wxNOT_FOUND;
// remember how many bytes we read from the stream:
- wxFileOffset offset = sizeof(IconDir);
-
+ wxFileOffset alreadySeeked = sizeof(IconDir);
+
for (unsigned int i = 0; i < nIcons; i++ )
{
- offset += stream.Read(pCurrentEntry, sizeof(ICONDIRENTRY)).LastRead();
-
+ alreadySeeked += stream.Read(pCurrentEntry, sizeof(ICONDIRENTRY)).LastRead();
+
// bHeight and bColorCount are wxUint8
if ( pCurrentEntry->bWidth >= wMax )
{
colmax = pCurrentEntry->bColorCount;
}
}
-
+
pCurrentEntry++;
}
{
// seek to selected icon:
pCurrentEntry = pIconDirEntry + iSel;
-
+
// NOTE: seeking a positive amount in wxFromCurrent mode allows us to
// load even non-seekable streams (see wxInputStream::SeekI docs)!
- if (stream.SeekI(wxUINT32_SWAP_ON_BE(pCurrentEntry->dwImageOffset) - offset,
- wxFromCurrent) == wxInvalidOffset)
+ 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 )
image->SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, wxUINT16_SWAP_ON_BE(pCurrentEntry->wBitCount));
}
}
-
+
delete [] pIconDirEntry;
-
+
return bResult;
}
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);
}