aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Scipione <jscipione@gmail.com>2012-07-28 22:00:22 -0400
committerJohn Scipione <jscipione@gmail.com>2012-07-28 22:00:22 -0400
commit1510ac00817ec2679621f9579bb25a71400f6c8b (patch)
treebcf214efef319d8dec7014f56cc72d55adb695d6
parent688e878807fee1750d876001cff4f1ce41da3a79 (diff)
Refactor icon scaling, fix off-by-one error.hrev44425
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.
-rw-r--r--src/apps/deskbar/BarApp.cpp2
-rw-r--r--src/libs/icon/IconUtils.cpp52
2 files changed, 25 insertions, 29 deletions
diff --git a/src/apps/deskbar/BarApp.cpp b/src/apps/deskbar/BarApp.cpp
index 33c5832a7e..40084069fb 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 d9884d5ebc..7a183cf474 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;