Moved RescaleBitmap() utility function to BitmapUtils.{cpp,h}.

This commit is contained in:
plfiorini 2010-05-08 16:21:36 +00:00
parent b1388d17e8
commit 4b01bd22bb
5 changed files with 43 additions and 46 deletions

View File

@ -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" { extern "C" {
status_t status_t

View File

@ -6,17 +6,13 @@
#define _CAYA_UTILS_H #define _CAYA_UTILS_H
#include <image.h> #include <image.h>
#include <Mime.h> #include <Mime.h>
#include "CayaConstants.h" #include "CayaConstants.h"
class BBitmap;
class BResources;
const char* CayaStatusToString(CayaStatus status); const char* CayaStatusToString(CayaStatus status);
BBitmap* RescaleBitmap(const BBitmap* src, int32 width, int32 height);
extern "C" status_t our_image(image_info& image); extern "C" status_t our_image(image_info& image);
#endif // _CAYA_UTILS_H #endif // _CAYA_UTILS_H

View File

@ -15,6 +15,7 @@
#include <PopUpMenu.h> #include <PopUpMenu.h>
#include <libinterface/BitmapMenuItem.h> #include <libinterface/BitmapMenuItem.h>
#include <libinterface/BitmapUtils.h>
#include "AccountManager.h" #include "AccountManager.h"
#include "BitmapView.h" #include "BitmapView.h"

View File

@ -87,3 +87,43 @@ BBitmap* IconFromResources(BResources* res, int32 num, icon_size size)
return icon; 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;
}

View File

@ -11,5 +11,6 @@
BBitmap* ReadNodeIcon(const char* name, icon_size size, bool followSymlink); BBitmap* ReadNodeIcon(const char* name, icon_size size, bool followSymlink);
BBitmap* IconFromResources(BResources* res, int32 num, icon_size size); BBitmap* IconFromResources(BResources* res, int32 num, icon_size size);
BBitmap* RescaleBitmap(const BBitmap* src, int32 width, int32 height);
#endif // _BITMAP_UTILS_H #endif // _BITMAP_UTILS_H