Refactor icon scaling, fix off-by-one error.
Refactor the icon scaling code in IconUtils.cpp to avoid code duplication. Basically create and delete the temp bitmap to convert from B_CMAP8 to B_RGBA32 for scale2x/scale3x/scale4x just one time instead of 3. There was an off-by-one error in Deskbar which was causing it to scale up the 16x16 Bitmap icon to 32x32 instead of just using the 32x32 icon. This only affected BeOS bitmap-based icons, not Haiku HVIF icons.
This commit is contained in:
@@ -858,7 +858,7 @@ void
|
||||
TBarApp::FetchAppIcon(const char* signature, BBitmap* icon)
|
||||
{
|
||||
app_info appInfo;
|
||||
icon_size size = icon->Bounds().IntegerHeight() >= 32
|
||||
icon_size size = icon->Bounds().IntegerHeight() >= 31
|
||||
? B_LARGE_ICON : B_MINI_ICON;
|
||||
|
||||
if (be_roster->GetAppInfo(signature, &appInfo) == B_OK) {
|
||||
|
||||
+24
-28
@@ -230,8 +230,6 @@ scale4x(const uint8* srcBits, uint8* dstBits, int32 srcWidth, int32 srcHeight,
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
@@ -576,7 +574,7 @@ BIconUtils::ConvertFromCMAP8(const uint8* src, uint32 width, uint32 height,
|
||||
uint32 dstHeight = result->Bounds().IntegerHeight() + 1;
|
||||
|
||||
if (dstWidth < width || dstHeight < height) {
|
||||
// TODO: down scaling
|
||||
// TODO: implement down scaling
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
@@ -613,38 +611,36 @@ BIconUtils::ConvertFromCMAP8(const uint8* src, uint32 width, uint32 height,
|
||||
src = srcStart;
|
||||
dst = dstStart;
|
||||
|
||||
if (dstWidth > width || dstHeight > height) {
|
||||
if (dstWidth == width && dstHeight == height) {
|
||||
// No scaling, just convert to B_RGBA32
|
||||
result->ImportBits(src, height * srcBPR, srcBPR, 0, B_CMAP8);
|
||||
} else if (dstWidth == dstHeight && dstWidth == 2 * width
|
||||
|| dstWidth == 3 * width
|
||||
|| dstWidth == 4 * width) {
|
||||
// we can do some special convertions here
|
||||
|
||||
// first convert to B_RGBA32
|
||||
BBitmap* converted
|
||||
= new BBitmap(BRect(0, 0, width - 1, height - 1),
|
||||
result->ColorSpace());
|
||||
converted->ImportBits(src, height * srcBPR, srcBPR, 0, B_CMAP8);
|
||||
uint8* convertedBits = (uint8*)converted->Bits();
|
||||
int32 convertedBPR = converted->BytesPerRow();
|
||||
|
||||
// scale using the scale2x/scale3x/scale4x algorithm
|
||||
if (dstWidth == 2 * width && dstHeight == 2 * height) {
|
||||
// scale using the scale2x algorithm
|
||||
BBitmap* converted = new BBitmap(BRect(0, 0, width - 1, height - 1),
|
||||
result->ColorSpace());
|
||||
converted->ImportBits(src, height * srcBPR, srcBPR, 0, B_CMAP8);
|
||||
uint8* convertedBits = (uint8*)converted->Bits();
|
||||
int32 convertedBPR = converted->BytesPerRow();
|
||||
scale2x(convertedBits, dst, width, height, convertedBPR, dstBPR);
|
||||
delete converted;
|
||||
} else if (dstWidth == 3 * width && dstHeight == 3 * height) {
|
||||
// scale using the scale3x algorithm
|
||||
BBitmap* converted = new BBitmap(BRect(0, 0, width - 1, height - 1),
|
||||
result->ColorSpace());
|
||||
converted->ImportBits(src, height * srcBPR, srcBPR, 0, B_CMAP8);
|
||||
uint8* convertedBits = (uint8*)converted->Bits();
|
||||
int32 convertedBPR = converted->BytesPerRow();
|
||||
scale3x(convertedBits, dst, width, height, convertedBPR, dstBPR);
|
||||
delete converted;
|
||||
} else if (dstWidth == 4 * width && dstHeight == 4 * height) {
|
||||
// scale using the scale4x algorithm
|
||||
BBitmap* converted = new BBitmap(BRect(0, 0, width - 1, height - 1),
|
||||
result->ColorSpace());
|
||||
converted->ImportBits(src, height * srcBPR, srcBPR, 0, B_CMAP8);
|
||||
uint8* convertedBits = (uint8*)converted->Bits();
|
||||
int32 convertedBPR = converted->BytesPerRow();
|
||||
scale4x(convertedBits, dst, width, height, convertedBPR, dstBPR);
|
||||
delete converted;
|
||||
} else {
|
||||
// bilinear scaling
|
||||
scale_bilinear(dst, width, height, dstWidth, dstHeight, dstBPR);
|
||||
}
|
||||
|
||||
// cleanup
|
||||
delete converted;
|
||||
} else {
|
||||
// bilinear scaling
|
||||
scale_bilinear(dst, width, height, dstWidth, dstHeight, dstBPR);
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
|
||||
Reference in New Issue
Block a user