From 284f2b59db428e6ab05d31ff26b12043b6d42ff3 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sun, 13 Feb 2005 15:35:43 +0000 Subject: [PATCH] Added raw bitmap access support to GTK 2.0. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31996 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 11 +++++++++++ include/wx/gtk/bitmap.h | 6 ++++++ include/wx/gtk1/bitmap.h | 6 ++++++ include/wx/rawbmp.h | 5 +++++ samples/image/image.cpp | 9 +++++++-- src/gtk/bitmap.cpp | 41 +++++++++++++++++++++++++++++++++++++++- src/gtk1/bitmap.cpp | 41 +++++++++++++++++++++++++++++++++++++++- 7 files changed, 115 insertions(+), 4 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index b77a0a8017..956e7bcacf 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -43,6 +43,13 @@ All: the client size and total size of the window. Code that sets the client size using the best size, or that added extra space to sizers to compensate for this bug may need to be changed. +- Changed calculation of scrolling area to not clip away some bits + due to a rounding error. +- Changed GetVirtualSize() to return client size by default until + SetVirtualSize() gets called. From then on it will only return + that. +- Various changes to how wxListCtrl and wxTreeCtrl react to right + mouse clicks and left mouse click for starting a drag operation. All (GUI): @@ -83,6 +90,9 @@ wxGTK: are only called with GTK+ 2.4.x installed and should yield linker errors otherwise. - wxTextCtrl text insertion efficiency fixed. (Mart Raudsepp) +- Added wxRawBitmap support +- Corrected Input method handler code (for Chinese etc.) and its + interaction with wxWidgets' events. wxMac: @@ -101,6 +111,7 @@ wxMSW: wxWinCE: - Added support for MS Handheld PC 2000. This was done before 2.5.4, but not mentioned anywhere. +- Added (preliminary) support for sockets wxUniv: diff --git a/include/wx/gtk/bitmap.h b/include/wx/gtk/bitmap.h index c343811598..135805a5ae 100644 --- a/include/wx/gtk/bitmap.h +++ b/include/wx/gtk/bitmap.h @@ -20,6 +20,7 @@ #include "wx/string.h" #include "wx/palette.h" #include "wx/gdiobj.h" +#include "wx/rawbmp.h" #ifdef __WXGTK20__ typedef struct _GdkPixbuf GdkPixbuf; @@ -130,6 +131,11 @@ public: // Basically, this corresponds to Win32 StretchBlt() wxBitmap Rescale( int clipx, int clipy, int clipwidth, int clipheight, int width, int height ); + + // raw bitmap access support functions + void *GetRawData(wxPixelDataBase& data, int bpp); + void UngetRawData(wxPixelDataBase& data); + protected: bool CreateFromXpm(const char **bits); bool CreateFromImage(const wxImage& image, int depth); diff --git a/include/wx/gtk1/bitmap.h b/include/wx/gtk1/bitmap.h index c343811598..135805a5ae 100644 --- a/include/wx/gtk1/bitmap.h +++ b/include/wx/gtk1/bitmap.h @@ -20,6 +20,7 @@ #include "wx/string.h" #include "wx/palette.h" #include "wx/gdiobj.h" +#include "wx/rawbmp.h" #ifdef __WXGTK20__ typedef struct _GdkPixbuf GdkPixbuf; @@ -130,6 +131,11 @@ public: // Basically, this corresponds to Win32 StretchBlt() wxBitmap Rescale( int clipx, int clipy, int clipwidth, int clipheight, int width, int height ); + + // raw bitmap access support functions + void *GetRawData(wxPixelDataBase& data, int bpp); + void UngetRawData(wxPixelDataBase& data); + protected: bool CreateFromXpm(const char **bits); bool CreateFromImage(const wxImage& image, int depth); diff --git a/include/wx/rawbmp.h b/include/wx/rawbmp.h index 91a29f6f19..0815f09f17 100644 --- a/include/wx/rawbmp.h +++ b/include/wx/rawbmp.h @@ -160,6 +160,11 @@ typedef wxPixelFormat wxImagePixelFormat; // Cocoa is standard RGB or RGBA (normally it is RGBA) typedef wxPixelFormat wxNativePixelFormat; + #define wxPIXEL_FORMAT_ALPHA 3 +#elif defined(__WXGTK__) + // Under GTK+ 2.X we use GdkPixbuf, which should be RGBA + typedef wxPixelFormat wxNativePixelFormat; + #define wxPIXEL_FORMAT_ALPHA 3 #endif diff --git a/samples/image/image.cpp b/samples/image/image.cpp index 4d8d51e527..aeba4678ec 100644 --- a/samples/image/image.cpp +++ b/samples/image/image.cpp @@ -32,12 +32,17 @@ #include "smile.xbm" #include "smile.xpm" -#if defined(__WXMSW__) || defined(__WXMAC__) +#if defined(__WXMSW__) #ifdef wxHAVE_RAW_BITMAP #include "wx/rawbmp.h" #endif #endif +#if defined(__WXMAC__) || defined(__WXGTK__) + #define wxHAVE_RAW_BITMAP + #include "wx/rawbmp.h" +#endif + // derived classes class MyFrame; @@ -271,7 +276,7 @@ public: return; } - data.UseAlpha(); +// data.UseAlpha(); Data::Iterator p(data); diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index c8b75d0a4c..289f2653c8 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -306,7 +306,7 @@ bool wxBitmap::Create( int width, int height, int depth ) if (depth == -1) depth = visual->depth; - wxCHECK_MSG( (depth == visual->depth) || (depth == 1), FALSE, + wxCHECK_MSG( (depth == visual->depth) || (depth == 1) || (depth == 32), FALSE, wxT("invalid bitmap depth") ) m_refData = new wxBitmapRefData(); @@ -318,6 +318,14 @@ bool wxBitmap::Create( int width, int height, int depth ) M_BMPDATA->m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 ); M_BMPDATA->m_bpp = 1; } +#ifdef __WXGTK20__ + else if (depth == 32) + { + M_BMPDATA->m_pixbuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB, true, + 8, width, height); + M_BMPDATA->m_bpp = 32; + } +#endif else { M_BMPDATA->m_pixmap = gdk_pixmap_new( wxGetRootWindow()->window, width, height, depth ); @@ -1557,6 +1565,37 @@ void wxBitmap::PurgeOtherRepresentations(wxBitmap::Representation keep) #endif // __WXGTK20__ +void *wxBitmap::GetRawData(wxPixelDataBase& data, int bpp) +{ +#ifdef __WXGTK20__ + if (bpp != 32) + return NULL; + + GdkPixbuf *pixbuf = GetPixbuf(); + if (!pixbuf) + return NULL; + +#if 0 + if (gdk_pixbuf_get_has_alpha( pixbuf )) + wxPrintf( wxT("Has alpha\n") ); + else + wxPrintf( wxT("No alpha.\n") ); +#endif + + data.m_height = gdk_pixbuf_get_height( pixbuf ); + data.m_width = gdk_pixbuf_get_width( pixbuf ); + data.m_stride = gdk_pixbuf_get_rowstride( pixbuf ); + + return gdk_pixbuf_get_pixels( pixbuf ); +#else + return NULL; +#endif +} + +void wxBitmap::UngetRawData(wxPixelDataBase& data) +{ +} + //----------------------------------------------------------------------------- // wxBitmapHandler //----------------------------------------------------------------------------- diff --git a/src/gtk1/bitmap.cpp b/src/gtk1/bitmap.cpp index c8b75d0a4c..289f2653c8 100644 --- a/src/gtk1/bitmap.cpp +++ b/src/gtk1/bitmap.cpp @@ -306,7 +306,7 @@ bool wxBitmap::Create( int width, int height, int depth ) if (depth == -1) depth = visual->depth; - wxCHECK_MSG( (depth == visual->depth) || (depth == 1), FALSE, + wxCHECK_MSG( (depth == visual->depth) || (depth == 1) || (depth == 32), FALSE, wxT("invalid bitmap depth") ) m_refData = new wxBitmapRefData(); @@ -318,6 +318,14 @@ bool wxBitmap::Create( int width, int height, int depth ) M_BMPDATA->m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 ); M_BMPDATA->m_bpp = 1; } +#ifdef __WXGTK20__ + else if (depth == 32) + { + M_BMPDATA->m_pixbuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB, true, + 8, width, height); + M_BMPDATA->m_bpp = 32; + } +#endif else { M_BMPDATA->m_pixmap = gdk_pixmap_new( wxGetRootWindow()->window, width, height, depth ); @@ -1557,6 +1565,37 @@ void wxBitmap::PurgeOtherRepresentations(wxBitmap::Representation keep) #endif // __WXGTK20__ +void *wxBitmap::GetRawData(wxPixelDataBase& data, int bpp) +{ +#ifdef __WXGTK20__ + if (bpp != 32) + return NULL; + + GdkPixbuf *pixbuf = GetPixbuf(); + if (!pixbuf) + return NULL; + +#if 0 + if (gdk_pixbuf_get_has_alpha( pixbuf )) + wxPrintf( wxT("Has alpha\n") ); + else + wxPrintf( wxT("No alpha.\n") ); +#endif + + data.m_height = gdk_pixbuf_get_height( pixbuf ); + data.m_width = gdk_pixbuf_get_width( pixbuf ); + data.m_stride = gdk_pixbuf_get_rowstride( pixbuf ); + + return gdk_pixbuf_get_pixels( pixbuf ); +#else + return NULL; +#endif +} + +void wxBitmap::UngetRawData(wxPixelDataBase& data) +{ +} + //----------------------------------------------------------------------------- // wxBitmapHandler //----------------------------------------------------------------------------- -- 2.47.2