int m_width;
int m_height;
+ wxBitmapType m_type;
unsigned char *m_data;
bool m_hasMask;
{
m_width = 0;
m_height = 0;
+ m_type = wxBITMAP_TYPE_INVALID;
m_data =
m_alpha = (unsigned char *) NULL;
(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;
int target_step = M_IMGDATA->m_width*3;
for (int j = 0; j < height; j++)
{
- memcpy( target_data, source_data, width );
+ memcpy( target_data, source_data, width*3 );
source_data += source_step;
target_data += target_step;
}
- return;
}
// Copy over the alpha channel from the original image
unsigned char g = image.GetMaskGreen();
unsigned char b = image.GetMaskBlue();
- width *= 3;
unsigned char* source_data = image.GetData() + xx*3 + yy*3*image.GetWidth();
int source_step = image.GetWidth()*3;
for (int j = 0; j < height; j++)
{
- for (int i = 0; i < width; i+=3)
+ for (int i = 0; i < width*3; i+=3)
{
if ((source_data[i] != r) ||
(source_data[i+1] != g) ||
return M_IMGDATA->m_height;
}
+wxBitmapType wxImage::GetType() const
+{
+ wxCHECK_MSG( IsOk(), wxBITMAP_TYPE_INVALID, wxT("invalid image") );
+
+ return M_IMGDATA->m_type;
+}
+
+void wxImage::SetType(wxBitmapType type)
+{
+ wxCHECK_RET( IsOk(), "must create the image before setting its type");
+
+ // type can be wxBITMAP_TYPE_INVALID to reset the image type to default
+ wxASSERT_MSG( type != wxBITMAP_TYPE_MAX, "invalid bitmap type" );
+
+ M_IMGDATA->m_type = type;
+}
+
long wxImage::XYToIndex(int x, int y) const
{
if ( Ok() &&
}
}
+bool wxImage::DoLoad(wxImageHandler& handler, wxInputStream& stream, int index)
+{
+ if ( !handler.LoadFile(this, stream, true/*verbose*/, index) )
+ return false;
+
+ M_IMGDATA->m_type = handler.GetType();
+ return true;
+}
+
bool wxImage::LoadFile( wxInputStream& stream, wxBitmapType type, int index )
{
UnRef();
node = node->GetNext() )
{
handler = (wxImageHandler*)node->GetData();
- if ( handler->CanRead(stream) &&
- handler->LoadFile(this, stream, true/*verbose*/, index) )
- {
+ if ( handler->CanRead(stream) && DoLoad(*handler, stream, index) )
return true;
- }
-
}
wxLogWarning( _("No handler found for image type.") );
return false;
}
- return handler->LoadFile(this, stream, true/*verbose*/, index);
+ return DoLoad(*handler, stream, index);
}
bool wxImage::LoadFile( wxInputStream& stream, const wxString& mimetype, int index )
return false;
}
- return handler->LoadFile( this, stream, true/*verbose*/, index );
+ return DoLoad(*handler, stream, index);
+}
+
+bool wxImage::DoSave(wxImageHandler& handler, wxOutputStream& stream) const
+{
+ wxImage * const self = wx_const_cast(wxImage *, this);
+ if ( !handler.SaveFile(self, stream) )
+ return false;
+
+ M_IMGDATA->m_type = handler.GetType();
+ return true;
}
bool wxImage::SaveFile( wxOutputStream& stream, wxBitmapType type ) const
return false;
}
- return handler->SaveFile( (wxImage*)this, stream );
+ return DoSave(*handler, stream);
}
bool wxImage::SaveFile( wxOutputStream& stream, const wxString& mimetype ) const
wxLogWarning( _("No image handler for type %s defined."), mimetype.GetData() );
}
- return handler->SaveFile( (wxImage*)this, stream );
+ return DoSave(*handler, stream);
}
#endif // wxUSE_STREAMS