Implement BitmapFromRGBAImage without raw bitmap
The function BitmapFromRGBAImage in PlatWX.cpp is currently only used when wxHAS_RAW_BITMAP is defined. Consequently some functions in PlatWX.cpp simply do nothing when wxHAS_RAW_BITMAP is not defined. This provides a second implementation of the function based on wxImage that is used when wxHAS_RAW_BITMAP is not defined.
This commit is contained in:
@@ -31,6 +31,7 @@
|
|||||||
#include "wx/imaglist.h"
|
#include "wx/imaglist.h"
|
||||||
#include "wx/tokenzr.h"
|
#include "wx/tokenzr.h"
|
||||||
#include "wx/dynlib.h"
|
#include "wx/dynlib.h"
|
||||||
|
#include "wx/scopedarray.h"
|
||||||
|
|
||||||
#ifdef wxHAS_RAW_BITMAP
|
#ifdef wxHAS_RAW_BITMAP
|
||||||
#include "wx/rawbmp.h"
|
#include "wx/rawbmp.h"
|
||||||
@@ -508,17 +509,36 @@ wxBitmap BitmapFromRGBAImage(int width, int height, const unsigned char *pixelsI
|
|||||||
}
|
}
|
||||||
return bmp;
|
return bmp;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
wxBitmap BitmapFromRGBAImage(int width, int height, const unsigned char *pixelsImage)
|
||||||
|
{
|
||||||
|
const int totalPixels = width * height;
|
||||||
|
wxScopedArray<unsigned char> data(3*totalPixels);
|
||||||
|
wxScopedArray<unsigned char> alpha(totalPixels);
|
||||||
|
int curDataLocation = 0, curAlphaLocation = 0, curPixelsImageLocation = 0;
|
||||||
|
|
||||||
|
for ( int i = 0; i < totalPixels; ++i )
|
||||||
|
{
|
||||||
|
data[curDataLocation++] = pixelsImage[curPixelsImageLocation++];
|
||||||
|
data[curDataLocation++] = pixelsImage[curPixelsImageLocation++];
|
||||||
|
data[curDataLocation++] = pixelsImage[curPixelsImageLocation++];
|
||||||
|
alpha[curAlphaLocation++] = pixelsImage[curPixelsImageLocation++];
|
||||||
|
}
|
||||||
|
|
||||||
|
wxImage img(width, height, data.get(), alpha.get(), true);
|
||||||
|
wxBitmap bmp(img);
|
||||||
|
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void SurfaceImpl::DrawRGBAImage(PRectangle rc, int width, int height,
|
void SurfaceImpl::DrawRGBAImage(PRectangle rc, int width, int height,
|
||||||
const unsigned char *pixelsImage)
|
const unsigned char *pixelsImage)
|
||||||
{
|
{
|
||||||
#ifdef wxHAS_RAW_BITMAP
|
|
||||||
wxRect r = wxRectFromPRectangle(rc);
|
wxRect r = wxRectFromPRectangle(rc);
|
||||||
wxBitmap bmp = BitmapFromRGBAImage(width, height, pixelsImage);
|
wxBitmap bmp = BitmapFromRGBAImage(width, height, pixelsImage);
|
||||||
hdc->DrawBitmap(bmp, r.x, r.y, true);
|
hdc->DrawBitmap(bmp, r.x, r.y, true);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2551,10 +2571,8 @@ void ListBoxImpl::RegisterImage(int type, const char *xpm_data) {
|
|||||||
void ListBoxImpl::RegisterRGBAImage(int type, int width, int height,
|
void ListBoxImpl::RegisterRGBAImage(int type, int width, int height,
|
||||||
const unsigned char *pixelsImage)
|
const unsigned char *pixelsImage)
|
||||||
{
|
{
|
||||||
#ifdef wxHAS_RAW_BITMAP
|
|
||||||
wxBitmap bmp = BitmapFromRGBAImage(width, height, pixelsImage);
|
wxBitmap bmp = BitmapFromRGBAImage(width, height, pixelsImage);
|
||||||
RegisterImageHelper(type, bmp);
|
RegisterImageHelper(type, bmp);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user