From 91d3981a7bfb4de206fea4a4f89ed07d57b269e8 Mon Sep 17 00:00:00 2001 From: New Pagodi Date: Sat, 2 Feb 2019 16:10:57 -0600 Subject: [PATCH] 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. --- src/stc/PlatWX.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index ffb3db94bc..44dfca3664 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -31,6 +31,7 @@ #include "wx/imaglist.h" #include "wx/tokenzr.h" #include "wx/dynlib.h" +#include "wx/scopedarray.h" #ifdef wxHAS_RAW_BITMAP #include "wx/rawbmp.h" @@ -508,17 +509,36 @@ wxBitmap BitmapFromRGBAImage(int width, int height, const unsigned char *pixelsI } return bmp; } +#else +wxBitmap BitmapFromRGBAImage(int width, int height, const unsigned char *pixelsImage) +{ + const int totalPixels = width * height; + wxScopedArray data(3*totalPixels); + wxScopedArray 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 void SurfaceImpl::DrawRGBAImage(PRectangle rc, int width, int height, const unsigned char *pixelsImage) { -#ifdef wxHAS_RAW_BITMAP wxRect r = wxRectFromPRectangle(rc); wxBitmap bmp = BitmapFromRGBAImage(width, height, pixelsImage); 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, const unsigned char *pixelsImage) { -#ifdef wxHAS_RAW_BITMAP wxBitmap bmp = BitmapFromRGBAImage(width, height, pixelsImage); RegisterImageHelper(type, bmp); -#endif }