wxXPMDecoder decoder;
(*this) = decoder.ReadData(xpmData);
- return Ok();
+ return IsOk();
#else
+ wxUnusedVar(xpmData);
return false;
#endif
}
{
wxImage image;
- wxCHECK_MSG( Ok(), image, wxS("invalid image") );
+ wxCHECK_MSG( IsOk(), image, wxS("invalid image") );
long height = M_IMGDATA->m_height;
long width = M_IMGDATA->m_width;
{
wxImage image;
- wxCHECK_MSG( Ok(), image, wxT("invalid image") );
+ wxCHECK_MSG( IsOk(), image, wxT("invalid image") );
image.m_refData = CloneRefData(m_refData);
wxImage image;
- wxCHECK_MSG( Ok(), image, wxT("invalid image") );
+ wxCHECK_MSG( IsOk(), image, wxT("invalid image") );
// can't scale to/from 0 size
wxCHECK_MSG( (xFactor > 0) && (yFactor > 0), image,
{
wxImage image;
- wxCHECK_MSG( Ok(), image, wxT("invalid image") );
+ wxCHECK_MSG( IsOk(), image, wxT("invalid image") );
// can't scale to/from 0 size
wxCHECK_MSG( (width > 0) && (height > 0), image,
{
wxImage ret_image(MakeEmptyClone());
- wxCHECK( ret_image.Ok(), ret_image );
+ wxCHECK( ret_image.IsOk(), ret_image );
const unsigned char* src_data = M_IMGDATA->m_data;
unsigned char* dst_data = ret_image.GetData();
{
wxImage ret_image(MakeEmptyClone());
- wxCHECK( ret_image.Ok(), ret_image );
+ wxCHECK( ret_image.IsOk(), ret_image );
const unsigned char* src_data = M_IMGDATA->m_data;
unsigned char* dst_data = ret_image.GetData();
{
wxImage image(MakeEmptyClone(Clone_SwapOrientation));
- wxCHECK( image.Ok(), image );
+ wxCHECK( image.IsOk(), image );
long height = M_IMGDATA->m_height;
long width = M_IMGDATA->m_width;
{
wxImage image(MakeEmptyClone());
- wxCHECK( image.Ok(), image );
+ wxCHECK( image.IsOk(), image );
long height = M_IMGDATA->m_height;
long width = M_IMGDATA->m_width;
{
wxImage image(MakeEmptyClone());
- wxCHECK( image.Ok(), image );
+ wxCHECK( image.IsOk(), image );
long height = M_IMGDATA->m_height;
long width = M_IMGDATA->m_width;
{
wxImage image;
- wxCHECK_MSG( Ok(), image, wxT("invalid image") );
+ wxCHECK_MSG( IsOk(), image, wxT("invalid image") );
wxCHECK_MSG( (rect.GetLeft()>=0) && (rect.GetTop()>=0) &&
(rect.GetRight()<=GetWidth()) && (rect.GetBottom()<=GetHeight()),
{
wxImage image;
- wxCHECK_MSG( Ok(), image, wxT("invalid image") );
+ wxCHECK_MSG( IsOk(), image, wxT("invalid image") );
wxCHECK_MSG( (size.GetWidth() > 0) && (size.GetHeight() > 0), image, wxT("invalid size") );
int width = GetWidth(), height = GetHeight();
void wxImage::Paste( const wxImage &image, int x, int y )
{
- wxCHECK_RET( Ok(), wxT("invalid image") );
- wxCHECK_RET( image.Ok(), wxT("invalid image") );
+ wxCHECK_RET( IsOk(), wxT("invalid image") );
+ wxCHECK_RET( image.IsOk(), wxT("invalid image") );
AllocExclusive();
void wxImage::Replace( unsigned char r1, unsigned char g1, unsigned char b1,
unsigned char r2, unsigned char g2, unsigned char b2 )
{
- wxCHECK_RET( Ok(), wxT("invalid image") );
+ wxCHECK_RET( IsOk(), wxT("invalid image") );
AllocExclusive();
{
wxImage image(MakeEmptyClone());
- wxCHECK( image.Ok(), image );
+ wxCHECK( image.IsOk(), image );
const unsigned char *src = M_IMGDATA->m_data;
unsigned char *dest = image.GetData();
{
wxImage image;
- wxCHECK_MSG( Ok(), image, wxT("invalid image") );
+ wxCHECK_MSG( IsOk(), image, wxT("invalid image") );
image.Create( M_IMGDATA->m_width, M_IMGDATA->m_height, false );
int wxImage::GetWidth() const
{
- wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
+ wxCHECK_MSG( IsOk(), 0, wxT("invalid image") );
return M_IMGDATA->m_width;
}
int wxImage::GetHeight() const
{
- wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
+ wxCHECK_MSG( IsOk(), 0, wxT("invalid image") );
return M_IMGDATA->m_height;
}
long wxImage::XYToIndex(int x, int y) const
{
- if ( Ok() &&
+ if ( IsOk() &&
x >= 0 && y >= 0 &&
x < M_IMGDATA->m_width && y < M_IMGDATA->m_height )
{
void wxImage::SetRGB( const wxRect& rect_, unsigned char r, unsigned char g, unsigned char b )
{
- wxCHECK_RET( Ok(), wxT("invalid image") );
+ wxCHECK_RET( IsOk(), wxT("invalid image") );
AllocExclusive();
unsigned char *wxImage::GetData() const
{
- wxCHECK_MSG( Ok(), (unsigned char *)NULL, wxT("invalid image") );
+ wxCHECK_MSG( IsOk(), (unsigned char *)NULL, wxT("invalid image") );
return M_IMGDATA->m_data;
}
void wxImage::SetData( unsigned char *data, bool static_data )
{
- wxCHECK_RET( Ok(), wxT("invalid image") );
+ wxCHECK_RET( IsOk(), wxT("invalid image") );
wxImageRefData *newRefData = new wxImageRefData();
void wxImage::SetAlpha( unsigned char *alpha, bool static_data )
{
- wxCHECK_RET( Ok(), wxT("invalid image") );
+ wxCHECK_RET( IsOk(), wxT("invalid image") );
AllocExclusive();
unsigned char *wxImage::GetAlpha() const
{
- wxCHECK_MSG( Ok(), (unsigned char *)NULL, wxT("invalid image") );
+ wxCHECK_MSG( IsOk(), (unsigned char *)NULL, wxT("invalid image") );
return M_IMGDATA->m_alpha;
}
void wxImage::SetMaskColour( unsigned char r, unsigned char g, unsigned char b )
{
- wxCHECK_RET( Ok(), wxT("invalid image") );
+ wxCHECK_RET( IsOk(), wxT("invalid image") );
AllocExclusive();
bool wxImage::GetOrFindMaskColour( unsigned char *r, unsigned char *g, unsigned char *b ) const
{
- wxCHECK_MSG( Ok(), false, wxT("invalid image") );
+ wxCHECK_MSG( IsOk(), false, wxT("invalid image") );
if (M_IMGDATA->m_hasMask)
{
unsigned char wxImage::GetMaskRed() const
{
- wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
+ wxCHECK_MSG( IsOk(), 0, wxT("invalid image") );
return M_IMGDATA->m_maskRed;
}
unsigned char wxImage::GetMaskGreen() const
{
- wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
+ wxCHECK_MSG( IsOk(), 0, wxT("invalid image") );
return M_IMGDATA->m_maskGreen;
}
unsigned char wxImage::GetMaskBlue() const
{
- wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
+ wxCHECK_MSG( IsOk(), 0, wxT("invalid image") );
return M_IMGDATA->m_maskBlue;
}
void wxImage::SetMask( bool mask )
{
- wxCHECK_RET( Ok(), wxT("invalid image") );
+ wxCHECK_RET( IsOk(), wxT("invalid image") );
AllocExclusive();
bool wxImage::HasMask() const
{
- wxCHECK_MSG( Ok(), false, wxT("invalid image") );
+ wxCHECK_MSG( IsOk(), false, wxT("invalid image") );
return M_IMGDATA->m_hasMask;
}
bool wxImage::HasPalette() const
{
- if (!Ok())
+ if (!IsOk())
return false;
- return M_IMGDATA->m_palette.Ok();
+ return M_IMGDATA->m_palette.IsOk();
}
const wxPalette& wxImage::GetPalette() const
{
- wxCHECK_MSG( Ok(), wxNullPalette, wxT("invalid image") );
+ wxCHECK_MSG( IsOk(), wxNullPalette, wxT("invalid image") );
return M_IMGDATA->m_palette;
}
void wxImage::SetPalette(const wxPalette& palette)
{
- wxCHECK_RET( Ok(), wxT("invalid image") );
+ wxCHECK_RET( IsOk(), wxT("invalid image") );
AllocExclusive();
// image I/O
// ----------------------------------------------------------------------------
-bool wxImage::LoadFile( const wxString& WXUNUSED_UNLESS_STREAMS(filename),
- wxBitmapType WXUNUSED_UNLESS_STREAMS(type),
+// Under Windows we can load wxImage not only from files but also from
+// resources.
+#if defined(__WINDOWS__) && wxUSE_WXDIB && wxUSE_IMAGE
+ #define HAS_LOAD_FROM_RESOURCE
+#endif
+
+#ifdef HAS_LOAD_FROM_RESOURCE
+
+#include "wx/msw/dib.h"
+#include "wx/msw/private.h"
+
+static wxImage LoadImageFromResource(const wxString &name, wxBitmapType type)
+{
+ AutoHBITMAP
+ hBitmap,
+ hMask;
+
+ if ( type == wxBITMAP_TYPE_BMP_RESOURCE )
+ {
+ hBitmap.Init( ::LoadBitmap(wxGetInstance(), name.t_str()) );
+
+ if ( !hBitmap )
+ {
+ wxLogError(_("Failed to load bitmap \"%s\" from resources."), name);
+ }
+ }
+ else if ( type == wxBITMAP_TYPE_ICO_RESOURCE )
+ {
+ const HICON hIcon = ::LoadIcon(wxGetInstance(), name.t_str());
+
+ if ( !hIcon )
+ {
+ wxLogError(_("Failed to load icon \"%s\" from resources."), name);
+ }
+ else
+ {
+ ICONINFO info;
+ if ( !::GetIconInfo(hIcon, &info) )
+ {
+ wxLogLastError(wxT("GetIconInfo"));
+ return wxImage();
+ }
+
+ hBitmap.Init(info.hbmColor);
+ hMask.Init(info.hbmMask);
+ }
+ }
+ else if ( type == wxBITMAP_TYPE_CUR_RESOURCE )
+ {
+ wxLogDebug(wxS("Loading cursors from resources is not implemented."));
+ }
+ else
+ {
+ wxFAIL_MSG(wxS("Invalid bitmap resource type."));
+ }
+
+ if ( !hBitmap )
+ return wxImage();
+
+ wxImage image = wxDIB(hBitmap).ConvertToImage();
+ if ( hMask )
+ {
+ const wxImage mask = wxDIB(hMask).ConvertToImage();
+ image.SetMaskFromImage(mask, 255, 255, 255);
+ }
+ else
+ {
+ // Light gray colour is a default mask
+ image.SetMaskColour(0xc0, 0xc0, 0xc0);
+ }
+
+ // We could have already loaded alpha from the resources, but if not,
+ // initialize it now using the mask.
+ if ( !image.HasAlpha() )
+ image.InitAlpha();
+
+ return image;
+}
+
+#endif // HAS_LOAD_FROM_RESOURCE
+
+bool wxImage::LoadFile( const wxString& filename,
+ wxBitmapType type,
int WXUNUSED_UNLESS_STREAMS(index) )
{
+#ifdef HAS_LOAD_FROM_RESOURCE
+ if ( type == wxBITMAP_TYPE_BMP_RESOURCE
+ || type == wxBITMAP_TYPE_ICO_RESOURCE
+ || type == wxBITMAP_TYPE_CUR_RESOURCE)
+ {
+ const wxImage image = ::LoadImageFromResource(filename, type);
+ if ( image.IsOk() )
+ {
+ *this = image;
+ return true;
+ }
+ }
+#endif // HAS_LOAD_FROM_RESOURCE
+
#if HAS_FILE_STREAMS
wxImageFileInputStream stream(filename);
if ( stream.IsOk() )
wxBitmapType WXUNUSED_UNLESS_STREAMS(type) ) const
{
#if HAS_FILE_STREAMS
- wxCHECK_MSG( Ok(), false, wxT("invalid image") );
+ wxCHECK_MSG( IsOk(), false, wxT("invalid image") );
((wxImage*)this)->SetOption(wxIMAGE_OPTION_FILENAME, filename);
const wxString& WXUNUSED_UNLESS_STREAMS(mimetype) ) const
{
#if HAS_FILE_STREAMS
- wxCHECK_MSG( Ok(), false, wxT("invalid image") );
+ wxCHECK_MSG( IsOk(), false, wxT("invalid image") );
((wxImage*)this)->SetOption(wxIMAGE_OPTION_FILENAME, filename);
{
#if HAS_FILE_STREAMS
wxImageFileInputStream stream(name);
- if (stream.Ok())
+ if (stream.IsOk())
return GetImageCount(stream, type);
#endif
}
if ( width != widthOrig || height != heightOrig )
+ {
+ // get the original size if it was set by the image handler
+ // but also in order to restore it after Rescale
+ int widthOrigOption = GetOptionInt(wxIMAGE_OPTION_ORIGINAL_WIDTH),
+ heightOrigOption = GetOptionInt(wxIMAGE_OPTION_ORIGINAL_HEIGHT);
+
Rescale(width, height, wxIMAGE_QUALITY_HIGH);
+
+ SetOption(wxIMAGE_OPTION_ORIGINAL_WIDTH, widthOrigOption ? widthOrigOption : widthOrig);
+ SetOption(wxIMAGE_OPTION_ORIGINAL_HEIGHT, heightOrigOption ? heightOrigOption : heightOrig);
+ }
}
// Set this after Rescale, which currently does not preserve it
bool wxImage::SaveFile( wxOutputStream& stream, wxBitmapType type ) const
{
- wxCHECK_MSG( Ok(), false, wxT("invalid image") );
+ wxCHECK_MSG( IsOk(), false, wxT("invalid image") );
wxImageHandler *handler = FindHandler(type);
if ( !handler )
bool wxImage::SaveFile( wxOutputStream& stream, const wxString& mimetype ) const
{
- wxCHECK_MSG( Ok(), false, wxT("invalid image") );
+ wxCHECK_MSG( IsOk(), false, wxT("invalid image") );
wxImageHandler *handler = FindHandlerMime(mimetype);
if ( !handler )
{
wxLogWarning( _("No image handler for type %s defined."), mimetype.GetData() );
+ return false;
}
return DoSave(*handler, stream);
case BLUE:
hue = 4.0 + (red - green) / deltaRGB;
break;
-
- default:
- wxFAIL_MSG(wxT("hue not specified"));
- break;
}
hue /= 6.0;