From aac7507616fad7b43d22a981347ac585ed879609 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Mon, 18 Aug 2008 11:05:15 +0000 Subject: [PATCH] * r27001 left some parameter checks which need to be ommited for vector icons. Simplified the checks and moved them to where the old B_CMAP8 icon is retrieved. The bitmap is allowed to have another color space, in which case the icon data is converted (code was already in place). * Added a NOTE comment to how the new B_GET_VECTOR_ICON ioctl knows about the correct buffer size for the icon data. I've tested setting the desktop icon size to something else than 16x16 or 32x32 and it works fine now. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27032 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/storage/Mime.cpp | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/kits/storage/Mime.cpp b/src/kits/storage/Mime.cpp index bd80c8714f..c87c54a486 100644 --- a/src/kits/storage/Mime.cpp +++ b/src/kits/storage/Mime.cpp @@ -209,17 +209,6 @@ get_device_icon(const char *device, BBitmap *icon, icon_size which) if (device == NULL || icon == NULL) return B_BAD_VALUE; - BRect rect; - if (which == B_MINI_ICON) - rect.Set(0, 0, 15, 15); - else if (which == B_LARGE_ICON) - rect.Set(0, 0, 31, 31); - else - return B_BAD_VALUE; - - if (icon->Bounds() != rect) - return B_BAD_VALUE; - uint8* data; size_t size; type_code type; @@ -230,11 +219,20 @@ get_device_icon(const char *device, BBitmap *icon, icon_size which) return status; } - // Vector icon was not available, try old one + // Vector icon was not available, try old one, also checking the icon_size + // parameter + + BRect rect; + if (which == B_MINI_ICON) + rect.Set(0, 0, 15, 15); + else if (which == B_LARGE_ICON) + rect.Set(0, 0, 31, 31); + else + return B_BAD_VALUE; // check whether icon size and bitmap dimensions do match - if (icon->Bounds() != rect || icon->ColorSpace() != B_CMAP8) - return B_BAD_VALUE; + if (icon->Bounds() != rect) + return B_MISMATCHED_VALUES; void* iconData = icon->Bits(); size_t iconSize = icon->BitsLength(); @@ -246,7 +244,7 @@ get_device_icon(const char *device, BBitmap *icon, icon_size which) return B_NO_MEMORY; } - // get the icon + // get the icon, convert temporary data into bitmap if necessary status = get_device_icon(device, iconData, which); if (status == B_OK && iconData != icon->Bits()) icon->SetBits(iconData, iconSize, 0, B_CMAP8); @@ -282,6 +280,12 @@ get_device_icon(const char *device, uint8** _data, size_t* _size, // Getting the named icon failed, try vector icon next + // NOTE: The actual icon size is unknown as of yet. After the first call + // to B_GET_VECTOR_ICON, the actual size is known and the final buffer + // is allocated with the correct size. If the buffer needed to be + // larger, then the temporary buffer above will not yet contain the + // valid icon data. In that case, a second call to B_GET_VECTOR_ICON + // retrieves it into the final buffer. uint8 data[8192]; device_icon iconData = {sizeof(data), data}; status_t status = ioctl(fd, B_GET_VECTOR_ICON, &iconData, @@ -297,6 +301,7 @@ get_device_icon(const char *device, uint8** _data, size_t* _size, if (status == B_OK) { if (iconData.icon_size > (int32)sizeof(data)) { + // the stack buffer does not contain the data, see NOTE above iconData.icon_data = *_data; status = ioctl(fd, B_GET_VECTOR_ICON, &iconData, sizeof(device_icon));