From de022e4f1197d146e9bdd6aeb2ac0ee9cb217737 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Thu, 10 Apr 2008 13:21:20 +0000 Subject: [PATCH] First attempt to document raw bitmap access git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53102 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- interface/bitmap.h | 7 +- interface/rawbmp.h | 201 +++++++++++++++++++++++++++++++++++++++++++++ interface/region.h | 5 +- 3 files changed, 211 insertions(+), 2 deletions(-) create mode 100644 interface/rawbmp.h diff --git a/interface/bitmap.h b/interface/bitmap.h index 8656ae6983..41fa0c644b 100644 --- a/interface/bitmap.h +++ b/interface/bitmap.h @@ -158,6 +158,11 @@ public: This class encapsulates the concept of a platform-dependent bitmap, either monochrome or colour or colour with alpha channel support. + + If you need direct access the bitmap data instead going through + drawing to it using wxMemoryDC you need to use the wxPixelData + class (either wxNativePixelData for RGB bitmaps or wxAlphaPixelData + for bitmaps with an additionaly alpha channel). @note Many wxBitmap functions take a @e type parameter, which is a value of the @@ -178,7 +183,7 @@ public: ::wxNullBitmap @see @ref overview_bitmap, @ref overview_bitmap_supportedformats, - wxDC::Blit, wxIcon, wxCursor, wxBitmap, wxMemoryDC + wxDC::Blit, wxIcon, wxCursor, wxMemoryDC, wxImage, wxPixelData */ class wxBitmap : public wxGDIObject { diff --git a/interface/rawbmp.h b/interface/rawbmp.h new file mode 100644 index 0000000000..45b2ab1a0a --- /dev/null +++ b/interface/rawbmp.h @@ -0,0 +1,201 @@ + +/** + @class wxPixelData + @wxheader{rawbmp.h} + + A class template with ready to use implementations for getting + direct and efficient access to wxBitmap's internal data and + wxImage's internal data through a standard interface. It is + possible to extend this class (interface) to other types of + image content. + + Implemented on Windows, GTK+ and OS X: + wxNativePixelData: Class to access to wxBitmap's internal data without alpha channel (RGB). + wxAlphaPixelData: Class to access to wxBitmap's internal data with alpha channel (RGBA). + + Implemented everywhere: + wxImagePixelData: Class to access to wxImage's internal data with alpha channel (RGBA). + + @code + wxBitmap bmp; + wxNativePixelData data(bmp); + if ( !data ) + { + ... raw access to bitmap data unavailable, do something else ... + return; + } + + if ( data.GetWidth() < 20 || data.GetHeight() < 20 ) + { + ... complain: the bitmap it too small ... + return; + } + + wxNativePixelData::Iterator p(data); + + // we draw a (10, 10)-(20, 20) rect manually using the given r, g, b + p.Offset(data, 10, 10); + + for ( int y = 0; y < 10; ++y ) + { + wxNativePixelData::Iterator rowStart = p; + + for ( int x = 0; x < 10; ++x, ++p ) + { + p.Red() = r; + p.Green() = g; + p.Blue() = b; + } + + p = rowStart; + p.OffsetY(data, 1); + } + @endcode + + @library{wxcore} + @category{gdi} + + @see wxBitmap, wxImage +*/ +template > +class wxPixelData : + public wxPixelDataOut::template wxPixelDataIn +{ +public: + /** + the type of the class we're working with + */ + typedef Image ImageType; + + /** + Create pixel data object representing the entire image + */ + wxPixelData(Image& image); + + + /** + Create pixel data object representing the area + of the image defined by @e rect. + */ + wxPixelData(Image& i, const wxRect& rect); + + /** + Create pixel data object representing the area + of the image defined by @e pt and @e sz. + */ + wxPixelData(Image& i, const wxPoint& pt, const wxSize& sz) + + /** + Return true of if we could get access to bitmap data + successfully + */ + operator bool() const: + + /** + Return the iterator pointing to the origin of the image + */ + Iterator GetPixels() const; + + /** + Returns origin of the rectangular region we represent + */ + wxPoint GetOrigin() const; + + /** + Return width of the region we represent + */ + int GetWidth() const; + + /** + Return height of the region we represent + */ + int GetHeight() const; + + /* + Return area which this class represents in the image + */ + wxSize GetSize() const; + + /** + Return the distance between two rows + */ + int GetRowStride() const; + + + /** + Iterator + */ + class Iterator + { + public: + /** + go back to (0, 0) + */ + void Reset(const PixelData& data); + + /** + Initializes the iterator to point to the origin of the given + pixel data + */ + Iterator(PixelData& data); + + /** + Initializes the iterator to point to the origin of the given + Bitmap + */ + Iterator(wxBitmap& bmp, PixelData& data); + + /** + Default constructor + */ + Iterator(); + + /** + Return true if this iterator is valid + */ + bool IsOk() const; + + /** + Advance the iterator to the next pixel, prefix version + */ + Iterator& operator++(); + + /** + Postfix (hence less efficient -- don't use it unless you + absolutely must) version + */ + Iterator operator++(int); + + /** + Move x pixels to the right and y down + note that the rows don't wrap! + */ + void Offset(const PixelData& data, int x, int y); + + /** + Move x pixels to the right (again, no row wrapping) + */ + void OffsetX(const PixelData&data, int x); + + /** + Move y rows to the bottom + */ + void OffsetY(const PixelData& data, int y); + + /** + Go to the given position + */ + void MoveTo(const PixelData& data, int x, int y); + + //@{ + /** + Data access: gives access to invidividual colour components. + */ + ChannelType& Red(); + ChannelType& Green(); + ChannelType& Blue(); + ChannelType& Alpha(); + //@} + }; +}; + diff --git a/interface/region.h b/interface/region.h index f27e9db586..a9f96cf2f5 100644 --- a/interface/region.h +++ b/interface/region.h @@ -20,7 +20,10 @@ See wxPaintEvent for an example of use. @library{wxcore} - @category{FIXME} + @category{gdi} + + @stdobjects + ::wxNullRegion @see wxPaintEvent */ -- 2.45.2