Added and documented wxImage::Mirror() and wxImage::Rotate90().

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7362 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2000-05-06 17:30:50 +00:00
parent 4a18b95556
commit 8e1a0be217
3 changed files with 109 additions and 7 deletions

View File

@@ -491,6 +491,13 @@ mimetype to the named file}
\end{twocollist}} \end{twocollist}}
} }
\membersection{wxImage::Mirror}\label{wximagemirror}
\constfunc{wxImage}{Mirror}{\param{bool}{ horizontally = TRUE}}
Returns a mirrored copy of the image. The parameter {\it horizontally}
indicates the orientation.
\membersection{wxImage::Replace}\label{wximagereplace} \membersection{wxImage::Replace}\label{wximagereplace}
\func{void}{Replace}{\param{unsigned char}{ r1}, \param{unsigned char}{ g1}, \param{unsigned char}{ b1}, \func{void}{Replace}{\param{unsigned char}{ r1}, \param{unsigned char}{ g1}, \param{unsigned char}{ b1},
@@ -523,6 +530,13 @@ rotated image background. Else, black (rgb 0, 0, 0) will be used.
Returns the rotated image, leaving this image intact. Returns the rotated image, leaving this image intact.
\membersection{wxImage::Rotate90}\label{wximagerotate90}
\constfunc{wxImage}{Rotate90}{\param{bool}{ clockwise = TRUE}}
Returns a copy of the image rotated 90 degrees in the direction
indicated by {\it clockwise}.
\membersection{wxImage::Scale}\label{wximagescale} \membersection{wxImage::Scale}\label{wximagescale}
\constfunc{wxImage}{Scale}{\param{int}{ width}, \param{int}{ height}} \constfunc{wxImage}{Scale}{\param{int}{ width}, \param{int}{ height}}

View File

@@ -124,15 +124,18 @@ public:
wxImage Rotate(double angle, const wxPoint & centre_of_rotation, wxImage Rotate(double angle, const wxPoint & centre_of_rotation,
bool interpolating = TRUE, wxPoint * offset_after_rotation = (wxPoint*) NULL) const; bool interpolating = TRUE, wxPoint * offset_after_rotation = (wxPoint*) NULL) const;
wxImage Rotate90( bool clockwise = TRUE ) const;
wxImage Mirror( bool horizontally = TRUE ) const;
// replace one colour with another // replace one colour with another
void Replace( unsigned char r1, unsigned char g1, unsigned char b1, void Replace( unsigned char r1, unsigned char g1, unsigned char b1,
unsigned char r2, unsigned char g2, unsigned char b2 ); unsigned char r2, unsigned char g2, unsigned char b2 );
// these routines are slow but safe // these routines are slow but safe
void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b ); void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b );
unsigned char GetRed( int x, int y ); unsigned char GetRed( int x, int y ) const;
unsigned char GetGreen( int x, int y ); unsigned char GetGreen( int x, int y ) const;
unsigned char GetBlue( int x, int y ); unsigned char GetBlue( int x, int y ) const;
static bool CanRead( const wxString& name ); static bool CanRead( const wxString& name );
virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY ); virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY );

View File

@@ -217,6 +217,91 @@ wxImage wxImage::Scale( int width, int height ) const
return image; return image;
} }
wxImage wxImage::Rotate90( bool clockwise ) const
{
wxImage image;
wxCHECK_MSG( Ok(), image, wxT("invalid image") );
image.Create( M_IMGDATA->m_height, M_IMGDATA->m_width );
char unsigned *data = image.GetData();
wxCHECK_MSG( data, image, wxT("unable to create image") );
if (M_IMGDATA->m_hasMask)
image.SetMaskColour( M_IMGDATA->m_maskRed, M_IMGDATA->m_maskGreen, M_IMGDATA->m_maskBlue );
long height = M_IMGDATA->m_height;
long width = M_IMGDATA->m_width;
char unsigned *source_data = M_IMGDATA->m_data;
char unsigned *target_data;
for (long j = 0; j < height; j++)
{
for (long i = 0; i < width; i++)
{
if (clockwise)
target_data = data + (((i+1)*height) - j - 1)*3;
else
target_data = data + ((height*(width-1)) + j - (i*height))*3;
memcpy( target_data, source_data, 3 );
source_data += 3;
}
}
return image;
}
wxImage wxImage::Mirror( bool horizontally ) const
{
wxImage image;
wxCHECK_MSG( Ok(), image, wxT("invalid image") );
image.Create( M_IMGDATA->m_width, M_IMGDATA->m_height );
char unsigned *data = image.GetData();
wxCHECK_MSG( data, image, wxT("unable to create image") );
if (M_IMGDATA->m_hasMask)
image.SetMaskColour( M_IMGDATA->m_maskRed, M_IMGDATA->m_maskGreen, M_IMGDATA->m_maskBlue );
long height = M_IMGDATA->m_height;
long width = M_IMGDATA->m_width;
char unsigned *source_data = M_IMGDATA->m_data;
char unsigned *target_data;
if (horizontally)
{
for (long j = 0; j < height; j++)
{
data += width*3;
target_data = data-3;
for (long i = 0; i < width; i++)
{
memcpy( target_data, source_data, 3 );
source_data += 3;
target_data -= 3;
}
}
}
else
{
for (long i = 0; i < height; i++)
{
target_data = data + 3*width*(height-1-i);
memcpy( target_data, source_data, 3*width );
source_data += 3*width;
}
}
return image;
}
wxImage wxImage::GetSubImage( const wxRect &rect ) const wxImage wxImage::GetSubImage( const wxRect &rect ) const
{ {
wxImage image; wxImage image;
@@ -293,7 +378,7 @@ void wxImage::SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned c
M_IMGDATA->m_data[ pos+2 ] = b; M_IMGDATA->m_data[ pos+2 ] = b;
} }
unsigned char wxImage::GetRed( int x, int y ) unsigned char wxImage::GetRed( int x, int y ) const
{ {
wxCHECK_MSG( Ok(), 0, wxT("invalid image") ); wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
@@ -307,7 +392,7 @@ unsigned char wxImage::GetRed( int x, int y )
return M_IMGDATA->m_data[pos]; return M_IMGDATA->m_data[pos];
} }
unsigned char wxImage::GetGreen( int x, int y ) unsigned char wxImage::GetGreen( int x, int y ) const
{ {
wxCHECK_MSG( Ok(), 0, wxT("invalid image") ); wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
@@ -321,7 +406,7 @@ unsigned char wxImage::GetGreen( int x, int y )
return M_IMGDATA->m_data[pos+1]; return M_IMGDATA->m_data[pos+1];
} }
unsigned char wxImage::GetBlue( int x, int y ) unsigned char wxImage::GetBlue( int x, int y ) const
{ {
wxCHECK_MSG( Ok(), 0, wxT("invalid image") ); wxCHECK_MSG( Ok(), 0, wxT("invalid image") );