From 4b01bd22bb2d7afccad5d11f7a3bb62a1846ff61 Mon Sep 17 00:00:00 2001 From: plfiorini Date: Sat, 8 May 2010 16:21:36 +0000 Subject: [PATCH] Moved RescaleBitmap() utility function to BitmapUtils.{cpp,h}. --- application/CayaUtils.cpp | 41 ------------------------------- application/CayaUtils.h | 6 +---- application/views/StatusView.cpp | 1 + libs/libinterface/BitmapUtils.cpp | 40 ++++++++++++++++++++++++++++++ libs/libinterface/BitmapUtils.h | 1 + 5 files changed, 43 insertions(+), 46 deletions(-) diff --git a/application/CayaUtils.cpp b/application/CayaUtils.cpp index 1373320..128c7cc 100644 --- a/application/CayaUtils.cpp +++ b/application/CayaUtils.cpp @@ -34,47 +34,6 @@ CayaStatusToString(CayaStatus status) } } - -BBitmap* -RescaleBitmap(const BBitmap* src, int32 width, int32 height) -{ - width--; height--; - - if (!src || !src->IsValid()) - return NULL; - - BRect srcSize = src->Bounds(); - - if (height < 0) { - float srcProp = srcSize.Height() / srcSize.Width(); - height = (int32)(width * srcProp); - } - - BBitmap* res = new BBitmap(BRect(0, 0, width, height), src->ColorSpace()); - - float dx = (srcSize.Width() + 1) / (width + 1); - float dy = (srcSize.Height() + 1) / (height + 1); - uint8 bpp = (uint8)(src->BytesPerRow() / srcSize.Width()); - - int srcYOff = src->BytesPerRow(); - int dstYOff = res->BytesPerRow(); - - void* dstData = res->Bits(); - void* srcData = src->Bits(); - - for (int32 y = 0; y <= height; y++) { - void* dstRow = (void *)((uint32)dstData + (uint32)(y * dstYOff)); - void* srcRow = (void *)((uint32)srcData + ((uint32)(y * dy) * srcYOff)); - - for (int32 x = 0; x <= width; x++) - memcpy((void*)((uint32)dstRow + (x * bpp)), (void*)((uint32)srcRow + - ((uint32)(x * dx) * bpp)), bpp); - } - - return res; -} - - extern "C" { status_t diff --git a/application/CayaUtils.h b/application/CayaUtils.h index eae2007..6d3b7c9 100644 --- a/application/CayaUtils.h +++ b/application/CayaUtils.h @@ -6,17 +6,13 @@ #define _CAYA_UTILS_H #include + #include #include "CayaConstants.h" -class BBitmap; -class BResources; - const char* CayaStatusToString(CayaStatus status); -BBitmap* RescaleBitmap(const BBitmap* src, int32 width, int32 height); - extern "C" status_t our_image(image_info& image); #endif // _CAYA_UTILS_H diff --git a/application/views/StatusView.cpp b/application/views/StatusView.cpp index e3a8656..5c7c543 100644 --- a/application/views/StatusView.cpp +++ b/application/views/StatusView.cpp @@ -15,6 +15,7 @@ #include #include +#include #include "AccountManager.h" #include "BitmapView.h" diff --git a/libs/libinterface/BitmapUtils.cpp b/libs/libinterface/BitmapUtils.cpp index d0da628..5c4a6d5 100644 --- a/libs/libinterface/BitmapUtils.cpp +++ b/libs/libinterface/BitmapUtils.cpp @@ -87,3 +87,43 @@ BBitmap* IconFromResources(BResources* res, int32 num, icon_size size) return icon; } + + +BBitmap* +RescaleBitmap(const BBitmap* src, int32 width, int32 height) +{ + width--; height--; + + if (!src || !src->IsValid()) + return NULL; + + BRect srcSize = src->Bounds(); + + if (height < 0) { + float srcProp = srcSize.Height() / srcSize.Width(); + height = (int32)(width * srcProp); + } + + BBitmap* res = new BBitmap(BRect(0, 0, width, height), src->ColorSpace()); + + float dx = (srcSize.Width() + 1) / (width + 1); + float dy = (srcSize.Height() + 1) / (height + 1); + uint8 bpp = (uint8)(src->BytesPerRow() / srcSize.Width()); + + int srcYOff = src->BytesPerRow(); + int dstYOff = res->BytesPerRow(); + + void* dstData = res->Bits(); + void* srcData = src->Bits(); + + for (int32 y = 0; y <= height; y++) { + void* dstRow = (void *)((uint32)dstData + (uint32)(y * dstYOff)); + void* srcRow = (void *)((uint32)srcData + ((uint32)(y * dy) * srcYOff)); + + for (int32 x = 0; x <= width; x++) + memcpy((void*)((uint32)dstRow + (x * bpp)), (void*)((uint32)srcRow + + ((uint32)(x * dx) * bpp)), bpp); + } + + return res; +} diff --git a/libs/libinterface/BitmapUtils.h b/libs/libinterface/BitmapUtils.h index fc3c33e..1a0a3c8 100644 --- a/libs/libinterface/BitmapUtils.h +++ b/libs/libinterface/BitmapUtils.h @@ -11,5 +11,6 @@ BBitmap* ReadNodeIcon(const char* name, icon_size size, bool followSymlink); BBitmap* IconFromResources(BResources* res, int32 num, icon_size size); +BBitmap* RescaleBitmap(const BBitmap* src, int32 width, int32 height); #endif // _BITMAP_UTILS_H