Added wxImage:Copy()
Added first 30% of wxImage::Paste() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7377 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -187,6 +187,12 @@ on program start-up to look up colors. This ensures a very fast conversion, but
|
|||||||
the image quality won't be perfect (and could be better for photo images using more
|
the image quality won't be perfect (and could be better for photo images using more
|
||||||
sophisticated dithering algorithms).
|
sophisticated dithering algorithms).
|
||||||
|
|
||||||
|
\membersection{wxImage::Copy}\label{wximagecopy}
|
||||||
|
|
||||||
|
\constfunc{wxImage}{Copy}{\void}
|
||||||
|
|
||||||
|
Returns an identical copy of the image.
|
||||||
|
|
||||||
\membersection{wxImage::Create}\label{wximagecreate}
|
\membersection{wxImage::Create}\label{wximagecreate}
|
||||||
|
|
||||||
\func{bool}{Create}{\param{int}{ width}, \param{int}{ height}}
|
\func{bool}{Create}{\param{int}{ width}, \param{int}{ height}}
|
||||||
@@ -546,7 +552,7 @@ scaling bitmaps in general as the only other way to scale bitmaps
|
|||||||
is to blit a wxMemoryDC into another wxMemoryDC.
|
is to blit a wxMemoryDC into another wxMemoryDC.
|
||||||
|
|
||||||
It may be mentioned that the GTK port uses this function internally
|
It may be mentioned that the GTK port uses this function internally
|
||||||
to scale bitmaps when using mapping mode in wxDC.
|
to scale bitmaps when using mapping modes in wxDC.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
|
@@ -98,7 +98,6 @@ public:
|
|||||||
wxImage( const wxImage& image );
|
wxImage( const wxImage& image );
|
||||||
wxImage( const wxImage* image );
|
wxImage( const wxImage* image );
|
||||||
|
|
||||||
// these functions get implemented in /src/(platform)/bitmap.cpp
|
|
||||||
wxImage( const wxBitmap &bitmap );
|
wxImage( const wxBitmap &bitmap );
|
||||||
operator wxBitmap() const { return ConvertToBitmap(); }
|
operator wxBitmap() const { return ConvertToBitmap(); }
|
||||||
wxBitmap ConvertToBitmap() const;
|
wxBitmap ConvertToBitmap() const;
|
||||||
@@ -110,9 +109,17 @@ public:
|
|||||||
void Create( int width, int height, unsigned char* data, bool static_data = FALSE );
|
void Create( int width, int height, unsigned char* data, bool static_data = FALSE );
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
||||||
|
// creates an identical copy of the image (the = operator
|
||||||
|
// just raises the ref count)
|
||||||
|
wxImage Copy() const;
|
||||||
|
|
||||||
// return the new image with size width*height
|
// return the new image with size width*height
|
||||||
wxImage GetSubImage( const wxRect& ) const;
|
wxImage GetSubImage( const wxRect& ) const;
|
||||||
|
|
||||||
|
// pastes image into this instance and takes care of
|
||||||
|
// the mask colour and out of bounds problems
|
||||||
|
void Paste( const wxImage &image, int x, int y );
|
||||||
|
|
||||||
// return the new image with size width*height
|
// return the new image with size width*height
|
||||||
wxImage Scale( int width, int height ) const;
|
wxImage Scale( int width, int height ) const;
|
||||||
|
|
||||||
|
@@ -178,6 +178,26 @@ void wxImage::Destroy()
|
|||||||
UnRef();
|
UnRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxImage wxImage::Copy() 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 );
|
||||||
|
|
||||||
|
memcpy( data, GetData(), M_IMGDATA->m_width*M_IMGDATA->m_height*3 );
|
||||||
|
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
wxImage wxImage::Scale( int width, int height ) const
|
wxImage wxImage::Scale( int width, int height ) const
|
||||||
{
|
{
|
||||||
wxImage image;
|
wxImage image;
|
||||||
@@ -339,6 +359,59 @@ wxImage wxImage::GetSubImage( const wxRect &rect ) const
|
|||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxImage::Paste( const wxImage &image, int x, int y )
|
||||||
|
{
|
||||||
|
wxCHECK_RET( Ok(), wxT("invalid image") );
|
||||||
|
wxCHECK_RET( image.Ok(), wxT("invalid image") );
|
||||||
|
|
||||||
|
int xx = 0;
|
||||||
|
int yy = 0;
|
||||||
|
int width = image.GetWidth();
|
||||||
|
int height = image.GetHeight();
|
||||||
|
|
||||||
|
if (x < 0)
|
||||||
|
{
|
||||||
|
xx = -x;
|
||||||
|
width += x;
|
||||||
|
}
|
||||||
|
if (y < 0)
|
||||||
|
{
|
||||||
|
yy = -y;
|
||||||
|
height += y;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((x+xx)+width > M_IMGDATA->m_width)
|
||||||
|
width = M_IMGDATA->m_width - (x+xx);
|
||||||
|
if ((y+yy)+height > M_IMGDATA->m_height)
|
||||||
|
height = M_IMGDATA->m_height - (y+yy);
|
||||||
|
|
||||||
|
if (width < 1) return;
|
||||||
|
if (height < 1) return;
|
||||||
|
|
||||||
|
if ((!HasMask() && !image.HasMask()) ||
|
||||||
|
((HasMask() && image.HasMask() &&
|
||||||
|
(GetMaskRed()==image.GetMaskRed()) &&
|
||||||
|
(GetMaskGreen()==image.GetMaskGreen()) &&
|
||||||
|
(GetMaskBlue()==image.GetMaskBlue()))))
|
||||||
|
{
|
||||||
|
width *= 3;
|
||||||
|
unsigned char* source_data = image.GetData() + xx*3 + yy*3*image.GetWidth();
|
||||||
|
int source_step = image.GetWidth()*3;
|
||||||
|
|
||||||
|
unsigned char* target_data = GetData() + (x+xx)*3 + (y+yy)*3*M_IMGDATA->m_width;
|
||||||
|
int target_step = M_IMGDATA->m_width*3;
|
||||||
|
for (int j = 0; j < height; j++)
|
||||||
|
{
|
||||||
|
memcpy( target_data, source_data, width );
|
||||||
|
source_data += source_step;
|
||||||
|
target_data += target_step;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void wxImage::Replace( unsigned char r1, unsigned char g1, unsigned char b1,
|
void wxImage::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 )
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user