Added a work-around for broken ICO files that report a wrong icon height.

Fixed a wrong return code in case writing file data failed.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11327 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2005-02-10 18:52:52 +00:00
parent 71aa315c95
commit 5ff65f9b40
1 changed files with 11 additions and 4 deletions

View File

@ -365,7 +365,7 @@ convert_data_to_bits(ico_dir_entry &entry, ico_bitmap_header &header,
if (bytesWritten < B_OK)
return bytesWritten;
if (bytesWritten != outRowBytes)
return B_BAD_DATA;
return B_IO_ERROR;
}
return B_OK;
@ -567,6 +567,16 @@ ICO::convert_ico_to_bits(BPositionIO &source, BPositionIO &target)
if (bitmapHeader.compression != 0)
return EOPNOTSUPP;
int32 numColors = 0;
if (bitmapHeader.bits_per_pixel <= 8)
numColors = 1L << bitmapHeader.bits_per_pixel;
// This is a work-around for a broken ICO file writer that publishes
// a wrong image height in the ico_dir_entry structure
if (entry.size != 0 && 2 * entry.width == entry.height && numColors != 0
&& sizeof(rgba32_color) * numColors + entry.width * entry.height > entry.size)
entry.height = entry.width;
TranslatorBitmap bitsHeader;
bitsHeader.magic = B_TRANSLATOR_BITMAP;
bitsHeader.bounds.left = 0;
@ -579,9 +589,6 @@ ICO::convert_ico_to_bits(BPositionIO &source, BPositionIO &target)
bitsHeader.dataSize = bitsHeader.rowBytes * entry.height;
// read in palette
int32 numColors = 0;
if (bitmapHeader.bits_per_pixel <= 8)
numColors = 1L << bitmapHeader.bits_per_pixel;
rgba32_color palette[256];
if (numColors > 0) {