git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20453
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
mask information so that bitmaps and images can be converted back
and forth without loss in that respect.
mask information so that bitmaps and images can be converted back
and forth without loss in that respect.
-\func{}{wxImage}{\param{int}{ width}, \param{int}{ height}}
+\func{}{wxImage}{\param{int}{ width}, \param{int}{ height}, \param{bool}{ clear=true}}
-Creates an image with the given width and height.
+Creates an image with the given width and height. If {\it clear} is true, the new image will be initialized to black.
+Otherwise, the image data will be uninitialized.
\func{}{wxImage}{\param{int}{ width}, \param{int}{ height}, \param{unsigned char*}{ data}, \param{bool}{ static\_data=false}}
\func{}{wxImage}{\param{int}{ width}, \param{int}{ height}, \param{unsigned char*}{ data}, \param{bool}{ static\_data=false}}
\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}, \param{bool}{ clear=true}}
+Creates a fresh image. If {\it clear} is true, the new image will be initialized to black.
+Otherwise, the image data will be uninitialized.
- wxImage( int width, int height );
+ wxImage( int width, int height, bool clear = true );
wxImage( int width, int height, unsigned char* data, bool static_data = FALSE );
wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 );
wxImage( const wxString& name, const wxString& mimetype, int index = -1 );
wxImage( int width, int height, unsigned char* data, bool static_data = FALSE );
wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 );
wxImage( const wxString& name, const wxString& mimetype, int index = -1 );
- void Create( int width, int height );
+ void Create( int width, int height, bool clear = true );
void Create( int width, int height, unsigned char* data, bool static_data = FALSE );
void Destroy();
void Create( int width, int height, unsigned char* data, bool static_data = FALSE );
void Destroy();
-wxImage::wxImage( int width, int height )
+wxImage::wxImage( int width, int height, bool clear )
- Create( width, height );
+ Create( width, height, clear );
}
wxImage::wxImage( int width, int height, unsigned char* data, bool static_data )
}
wxImage::wxImage( int width, int height, unsigned char* data, bool static_data )
if (image) Ref(*image);
}
if (image) Ref(*image);
}
-void wxImage::Create( int width, int height )
+void wxImage::Create( int width, int height, bool clear )
M_IMGDATA->m_data = (unsigned char *) malloc( width*height*3 );
if (M_IMGDATA->m_data)
{
M_IMGDATA->m_data = (unsigned char *) malloc( width*height*3 );
if (M_IMGDATA->m_data)
{
- for (int l = 0; l < width*height*3; l++) M_IMGDATA->m_data[l] = 0;
+ if (clear) memset(M_IMGDATA->m_data, 0, width*height*3);
M_IMGDATA->m_width = width;
M_IMGDATA->m_height = height;
M_IMGDATA->m_width = width;
M_IMGDATA->m_height = height;
wxCHECK_MSG( Ok(), image, wxT("invalid image") );
wxCHECK_MSG( Ok(), image, wxT("invalid image") );
- image.Create( M_IMGDATA->m_width, M_IMGDATA->m_height );
+ image.Create( M_IMGDATA->m_width, M_IMGDATA->m_height, false );
unsigned char *data = image.GetData();
unsigned char *data = image.GetData();
long width = old_width / xFactor ;
long height = old_height / yFactor ;
long width = old_width / xFactor ;
long height = old_height / yFactor ;
- image.Create( width , height );
+ image.Create( width, height, false );
char unsigned *data = image.GetData();
char unsigned *data = image.GetData();
{
return ShrinkBy( old_width / width , old_height / height ) ;
}
{
return ShrinkBy( old_width / width , old_height / height ) ;
}
- image.Create( width, height );
+ image.Create( width, height, false );
unsigned char *data = image.GetData();
unsigned char *data = image.GetData();
unsigned char *source_data = M_IMGDATA->m_data;
unsigned char *target_data = data;
unsigned char *source_data = M_IMGDATA->m_data;
unsigned char *target_data = data;
-#if 0
- // This is nonsense, RR.
-
- // We do (x, y) -> (x, y)*oldSize/newSize but the valid values of x and y
- // are from 0 to size-1, hence all decrement the sizes
- long old_old_width = old_width;
- old_height--;
- old_width--;
- height--;
- width--;
- for ( long j = 0; j <= height; j++ )
- {
- // don't crash for images with height == 1
- long y_offset = height ? (j * old_height / height)* old_old_width : 0;
+ long x_delta = (old_width<<16) / width;
+ long y_delta = (old_height<<16) / height;
- for ( long i = 0; i <= width; i++ )
- {
- long x_offset = width ? (i * old_width) / width : 0;
+ unsigned char* dest_pixel = target_data;
- memcpy( target_data, source_data + 3*(y_offset + x_offset), 3 );
- target_data += 3;
- }
- }
-#else
- for (long j = 0; j < height; j++)
- {
- long y_offset = (j * old_height / height) * old_width;
+ long y = 0;
+ for ( long j = 0; j < height; j++ )
+ {
+ unsigned char* src_line = &source_data[(y>>16)*old_width*3];
- for (long i = 0; i < width; i++)
+ long x = 0;
+ for ( long i = 0; i < width; i++ )
- memcpy( target_data,
- source_data + 3*(y_offset + ((i * old_width )/ width)),
- 3 );
- target_data += 3;
+ unsigned char* src_pixel = &src_line[(x>>16)*3];
+ dest_pixel[0] = src_pixel[0];
+ dest_pixel[1] = src_pixel[1];
+ dest_pixel[2] = src_pixel[2];
+ dest_pixel += 3;
+ x += x_delta;
// In case this is a cursor, make sure the hotspot is scalled accordingly:
if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_X) )
// In case this is a cursor, make sure the hotspot is scalled accordingly:
if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_X) )
wxCHECK_MSG( Ok(), image, wxT("invalid image") );
wxCHECK_MSG( Ok(), image, wxT("invalid image") );
- image.Create( M_IMGDATA->m_height, M_IMGDATA->m_width );
+ image.Create( M_IMGDATA->m_height, M_IMGDATA->m_width, false );
unsigned char *data = image.GetData();
unsigned char *data = image.GetData();
wxCHECK_MSG( Ok(), image, wxT("invalid image") );
wxCHECK_MSG( Ok(), image, wxT("invalid image") );
- image.Create( M_IMGDATA->m_width, M_IMGDATA->m_height );
+ image.Create( M_IMGDATA->m_width, M_IMGDATA->m_height, false );
unsigned char *data = image.GetData();
unsigned char *data = image.GetData();
int subwidth=rect.GetWidth();
const int subheight=rect.GetHeight();
int subwidth=rect.GetWidth();
const int subheight=rect.GetHeight();
- image.Create( subwidth, subheight );
+ image.Create( subwidth, subheight, false );
unsigned char *subdata = image.GetData(), *data=GetData();
unsigned char *subdata = image.GetData(), *data=GetData();
wxCHECK_MSG( Ok(), image, wxT("invalid image") );
wxCHECK_MSG( Ok(), image, wxT("invalid image") );
- image.Create( M_IMGDATA->m_width, M_IMGDATA->m_height );
+ image.Create( M_IMGDATA->m_width, M_IMGDATA->m_height, false );
unsigned char *data = image.GetData();
unsigned char *data = image.GetData();
//-----------------------------------------------------------------------------
// wxImageHandler
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// wxImageHandler
//-----------------------------------------------------------------------------
int x2 = (int) ceil (wxMax (wxMax(p1.x, p2.x), wxMax(p3.x, p4.x)));
int y2 = (int) ceil (wxMax (wxMax(p1.y, p2.y), wxMax(p3.y, p4.y)));
int x2 = (int) ceil (wxMax (wxMax(p1.x, p2.x), wxMax(p3.x, p4.x)));
int y2 = (int) ceil (wxMax (wxMax(p1.y, p2.y), wxMax(p3.y, p4.y)));
- wxImage rotated (x2 - x1 + 1, y2 - y1 + 1);
+ wxImage rotated (x2 - x1 + 1, y2 - y1 + 1, false);
if (offset_after_rotation != NULL)
{
if (offset_after_rotation != NULL)
{