hrev44425 adds 1 changeset to branch 'master' old head: 688e878807fee1750d876001cff4f1ce41da3a79 new head: 1510ac00817ec2679621f9579bb25a71400f6c8b ---------------------------------------------------------------------------- 1510ac0: 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. [ John Scipione <jscipione@xxxxxxxxx> ] ---------------------------------------------------------------------------- Revision: hrev44425 Commit: 1510ac00817ec2679621f9579bb25a71400f6c8b URL: http://cgit.haiku-os.org/haiku/commit/?id=1510ac0 Author: John Scipione <jscipione@xxxxxxxxx> Date: Sun Jul 29 02:00:22 2012 UTC ---------------------------------------------------------------------------- 2 files changed, 25 insertions(+), 29 deletions(-) src/apps/deskbar/BarApp.cpp | 2 +- src/libs/icon/IconUtils.cpp | 52 ++++++++++++++++++--------------------- ---------------------------------------------------------------------------- diff --git a/src/apps/deskbar/BarApp.cpp b/src/apps/deskbar/BarApp.cpp index 33c5832..4008406 100644 --- a/src/apps/deskbar/BarApp.cpp +++ b/src/apps/deskbar/BarApp.cpp @@ -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) { diff --git a/src/libs/icon/IconUtils.cpp b/src/libs/icon/IconUtils.cpp index d9884d5..7a183cf 100644 --- a/src/libs/icon/IconUtils.cpp +++ b/src/libs/icon/IconUtils.cpp @@ -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 == 2 * width && dstHeight == 2 * height) { - // scale using the scale2x algorithm - BBitmap* converted = new BBitmap(BRect(0, 0, width - 1, height - 1), + 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(); + 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) { 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;