2008-05-04 05:04:38 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: rawbmp.h
|
|
|
|
// Purpose: interface of wxPixelData
|
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2008-04-10 09:21:20 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxPixelData
|
|
|
|
|
|
|
|
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.
|
2008-05-04 05:04:38 -04:00
|
|
|
|
2008-04-10 09:21:20 -04:00
|
|
|
Implemented on Windows, GTK+ and OS X:
|
2008-05-04 05:04:38 -04:00
|
|
|
@li wxNativePixelData: Class to access to wxBitmap's internal data
|
|
|
|
without alpha channel (RGB).
|
|
|
|
@li wxAlphaPixelData: Class to access to wxBitmap's internal data with
|
|
|
|
alpha channel (RGBA).
|
|
|
|
|
2008-04-10 09:21:20 -04:00
|
|
|
Implemented everywhere:
|
2008-05-04 05:04:38 -04:00
|
|
|
@li wxImagePixelData: Class to access to wxImage's internal data with
|
|
|
|
alpha channel (RGBA).
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2008-04-10 09:21:20 -04:00
|
|
|
@code
|
|
|
|
wxBitmap bmp;
|
|
|
|
wxNativePixelData data(bmp);
|
|
|
|
if ( !data )
|
|
|
|
{
|
2008-04-10 12:36:00 -04:00
|
|
|
// ... raw access to bitmap data unavailable, do something else ...
|
2008-04-10 09:21:20 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( data.GetWidth() < 20 || data.GetHeight() < 20 )
|
|
|
|
{
|
2008-04-10 12:36:00 -04:00
|
|
|
// ... complain: the bitmap it too small ...
|
2008-04-10 09:21:20 -04:00
|
|
|
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}
|
2008-05-04 05:04:38 -04:00
|
|
|
|
2008-04-10 09:21:20 -04:00
|
|
|
@see wxBitmap, wxImage
|
|
|
|
*/
|
|
|
|
template <class Image, class PixelFormat = wxPixelFormatFor<Image> >
|
|
|
|
class wxPixelData :
|
|
|
|
public wxPixelDataOut<Image>::template wxPixelDataIn<PixelFormat>
|
|
|
|
{
|
|
|
|
public:
|
2008-05-04 05:04:38 -04:00
|
|
|
/**
|
|
|
|
The type of the class we're working with.
|
2008-04-10 09:21:20 -04:00
|
|
|
*/
|
|
|
|
typedef Image ImageType;
|
2008-05-04 05:04:38 -04:00
|
|
|
|
2008-04-10 09:21:20 -04:00
|
|
|
/**
|
2008-05-04 05:04:38 -04:00
|
|
|
Create pixel data object representing the entire image.
|
2008-04-10 09:21:20 -04:00
|
|
|
*/
|
|
|
|
wxPixelData(Image& image);
|
2008-05-04 05:04:38 -04:00
|
|
|
|
|
|
|
|
2008-04-10 09:21:20 -04:00
|
|
|
/**
|
2008-05-04 05:04:38 -04:00
|
|
|
Create pixel data object representing the area of the image defined by
|
|
|
|
@a rect.
|
2008-04-10 09:21:20 -04:00
|
|
|
*/
|
|
|
|
wxPixelData(Image& i, const wxRect& rect);
|
2008-05-04 05:04:38 -04:00
|
|
|
|
2008-04-10 09:21:20 -04:00
|
|
|
/**
|
2008-05-04 05:04:38 -04:00
|
|
|
Create pixel data object representing the area of the image defined by
|
|
|
|
@a pt and @a sz.
|
2008-04-10 09:21:20 -04:00
|
|
|
*/
|
|
|
|
wxPixelData(Image& i, const wxPoint& pt, const wxSize& sz)
|
2008-05-04 05:04:38 -04:00
|
|
|
|
2008-04-10 09:21:20 -04:00
|
|
|
/**
|
2008-05-04 05:04:38 -04:00
|
|
|
Return @true of if we could get access to bitmap data successfully.
|
2008-04-10 09:21:20 -04:00
|
|
|
*/
|
|
|
|
operator bool() const:
|
|
|
|
|
2008-05-04 05:04:38 -04:00
|
|
|
/**
|
|
|
|
Return the iterator pointing to the origin of the image.
|
2008-04-10 09:21:20 -04:00
|
|
|
*/
|
|
|
|
Iterator GetPixels() const;
|
|
|
|
|
|
|
|
/**
|
2008-05-04 05:04:38 -04:00
|
|
|
Returns origin of the rectangular region this wxPixelData represents.
|
2008-04-10 09:21:20 -04:00
|
|
|
*/
|
|
|
|
wxPoint GetOrigin() const;
|
|
|
|
|
2008-05-04 05:04:38 -04:00
|
|
|
/**
|
|
|
|
Return width of the region this wxPixelData represents.
|
2008-04-10 09:21:20 -04:00
|
|
|
*/
|
|
|
|
int GetWidth() const;
|
|
|
|
|
2008-05-04 05:04:38 -04:00
|
|
|
/**
|
|
|
|
Return height of the region this wxPixelData represents.
|
2008-04-10 09:21:20 -04:00
|
|
|
*/
|
|
|
|
int GetHeight() const;
|
|
|
|
|
2008-05-04 05:04:38 -04:00
|
|
|
/**
|
|
|
|
Return the area which this wxPixelData represents in the image.
|
2008-04-10 09:21:20 -04:00
|
|
|
*/
|
|
|
|
wxSize GetSize() const;
|
|
|
|
|
|
|
|
/**
|
2008-05-04 05:04:38 -04:00
|
|
|
Return the distance between two rows.
|
2008-04-10 09:21:20 -04:00
|
|
|
*/
|
|
|
|
int GetRowStride() const;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-05-04 05:04:38 -04:00
|
|
|
The iterator of class wxPixelData.
|
2008-04-10 09:21:20 -04:00
|
|
|
*/
|
2008-05-04 05:04:38 -04:00
|
|
|
class Iterator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reset the iterator to point 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++();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Advance the iterator to the next pixel, postfix (hence less
|
|
|
|
efficient -- don't use it unless you absolutely must) version.
|
|
|
|
*/
|
|
|
|
Iterator operator++(int);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Move @a x pixels to the right and @a y down.
|
|
|
|
|
|
|
|
@note The rows won't wrap automatically.
|
|
|
|
*/
|
|
|
|
void Offset(const PixelData& data, int x, int y);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Move @a x pixels to the right.
|
|
|
|
|
|
|
|
@note The rows won't wrap automatically.
|
|
|
|
*/
|
|
|
|
void OffsetX(const PixelData&data, int x);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Move @a 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: Access to invidividual colour components.
|
|
|
|
*/
|
|
|
|
ChannelType& Red();
|
|
|
|
ChannelType& Green();
|
|
|
|
ChannelType& Blue();
|
|
|
|
ChannelType& Alpha();
|
|
|
|
//@}
|
|
|
|
};
|
2008-04-10 09:21:20 -04:00
|
|
|
};
|
|
|
|
|