LoadFile( name, type );
}
+wxImage::wxImage( const wxString& name, const wxString& mimetype )
+{
+ LoadFile( name, mimetype );
+}
+
#if wxUSE_STREAMS
wxImage::wxImage( wxInputStream& stream, long type )
{
LoadFile( stream, type );
}
+
+wxImage::wxImage( wxInputStream& stream, const wxString& mimetype )
+{
+ LoadFile( stream, mimetype );
+}
#endif // wxUSE_STREAMS
wxImage::wxImage( const wxImage& image )
{
wxImage image;
- wxCHECK_MSG( Ok(), image, "invlaid image" );
+ wxCHECK_MSG( Ok(), image, _T("invalid image") );
- wxCHECK_MSG( (width > 0) && (height > 0), image, "invalid image size" );
+ wxCHECK_MSG( (width > 0) && (height > 0), image, _T("invalid image size") );
image.Create( width, height );
char unsigned *data = image.GetData();
- wxCHECK_MSG( data, image, "unable to create image" );
+ wxCHECK_MSG( data, image, _T("unable to create image") );
if (M_IMGDATA->m_hasMask)
image.SetMaskColour( M_IMGDATA->m_maskRed, M_IMGDATA->m_maskGreen, M_IMGDATA->m_maskBlue );
void wxImage::SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b )
{
- wxCHECK_RET( Ok(), "invalid image" );
+ wxCHECK_RET( Ok(), _T("invalid image") );
int w = M_IMGDATA->m_width;
int h = M_IMGDATA->m_height;
- wxCHECK_RET( (x>=0) && (y>=0) && (x<w) && (y<h), "invalid image index" );
+ wxCHECK_RET( (x>=0) && (y>=0) && (x<w) && (y<h), _T("invalid image index") );
long pos = (y * w + x) * 3;
unsigned char wxImage::GetRed( int x, int y )
{
- wxCHECK_MSG( Ok(), 0, "invalid image" );
+ wxCHECK_MSG( Ok(), 0, _T("invalid image") );
int w = M_IMGDATA->m_width;
int h = M_IMGDATA->m_height;
- wxCHECK_MSG( (x>=0) && (y>=0) && (x<w) && (y<h), 0, "invalid image index" );
+ wxCHECK_MSG( (x>=0) && (y>=0) && (x<w) && (y<h), 0, _T("invalid image index") );
long pos = (y * w + x) * 3;
unsigned char wxImage::GetGreen( int x, int y )
{
- wxCHECK_MSG( Ok(), 0, "invalid image" );
+ wxCHECK_MSG( Ok(), 0, _T("invalid image") );
int w = M_IMGDATA->m_width;
int h = M_IMGDATA->m_height;
- wxCHECK_MSG( (x>=0) && (y>=0) && (x<w) && (y<h), 0, "invalid image index" );
+ wxCHECK_MSG( (x>=0) && (y>=0) && (x<w) && (y<h), 0, _T("invalid image index") );
long pos = (y * w + x) * 3;
unsigned char wxImage::GetBlue( int x, int y )
{
- wxCHECK_MSG( Ok(), 0, "invalid image" );
+ wxCHECK_MSG( Ok(), 0, _T("invalid image") );
int w = M_IMGDATA->m_width;
int h = M_IMGDATA->m_height;
- wxCHECK_MSG( (x>=0) && (y>=0) && (x<w) && (y<h), 0, "invalid image index" );
+ wxCHECK_MSG( (x>=0) && (y>=0) && (x<w) && (y<h), 0, _T("invalid image index") );
long pos = (y * w + x) * 3;
char unsigned *wxImage::GetData() const
{
- wxCHECK_MSG( Ok(), (char unsigned *)NULL, "invalid image" );
+ wxCHECK_MSG( Ok(), (char unsigned *)NULL, _T("invalid image") );
return M_IMGDATA->m_data;
}
void wxImage::SetData( char unsigned *data )
{
- wxCHECK_RET( Ok(), "invalid image" );
+ wxCHECK_RET( Ok(), _T("invalid image") );
memcpy(M_IMGDATA->m_data, data, M_IMGDATA->m_width * M_IMGDATA->m_height * 3);
}
void wxImage::SetMaskColour( unsigned char r, unsigned char g, unsigned char b )
{
- wxCHECK_RET( Ok(), "invalid image" );
+ wxCHECK_RET( Ok(), _T("invalid image") );
M_IMGDATA->m_maskRed = r;
M_IMGDATA->m_maskGreen = g;
unsigned char wxImage::GetMaskRed() const
{
- wxCHECK_MSG( Ok(), 0, "invalid image" );
+ wxCHECK_MSG( Ok(), 0, _T("invalid image") );
return M_IMGDATA->m_maskRed;
}
unsigned char wxImage::GetMaskGreen() const
{
- wxCHECK_MSG( Ok(), 0, "invalid image" );
+ wxCHECK_MSG( Ok(), 0, _T("invalid image") );
return M_IMGDATA->m_maskGreen;
}
unsigned char wxImage::GetMaskBlue() const
{
- wxCHECK_MSG( Ok(), 0, "invalid image" );
+ wxCHECK_MSG( Ok(), 0, _T("invalid image") );
return M_IMGDATA->m_maskBlue;
}
void wxImage::SetMask( bool mask )
{
- wxCHECK_RET( Ok(), "invalid image" );
+ wxCHECK_RET( Ok(), _T("invalid image") );
M_IMGDATA->m_hasMask = mask;
}
bool wxImage::HasMask() const
{
- wxCHECK_MSG( Ok(), FALSE, "invalid image" );
+ wxCHECK_MSG( Ok(), FALSE, _T("invalid image") );
return M_IMGDATA->m_hasMask;
}
int wxImage::GetWidth() const
{
- wxCHECK_MSG( Ok(), 0, "invalid image" );
+ wxCHECK_MSG( Ok(), 0, _T("invalid image") );
return M_IMGDATA->m_width;
}
int wxImage::GetHeight() const
{
- wxCHECK_MSG( Ok(), 0, "invalid image" );
+ wxCHECK_MSG( Ok(), 0, _T("invalid image") );
return M_IMGDATA->m_height;
}
wxFileInputStream stream(filename);
return LoadFile(stream, type);
}
+
+ else {
+ wxLogError( _T("Can't load image from file '%s': file does not exist."), filename.c_str() );
+
+ return FALSE;
+ }
+#else // !wxUSE_STREAMS
+ return FALSE;
+#endif // wxUSE_STREAMS
+}
+
+bool wxImage::LoadFile( const wxString& filename, const wxString& mimetype )
+{
+#if wxUSE_STREAMS
+ if (wxFileExists(filename))
+ {
+ wxFileInputStream stream(filename);
+ return LoadFile(stream, mimetype);
+ }
else {
- wxLogError( "Can't load image from file '%s': file does not exist.", filename.c_str() );
+ wxLogError( _T("Can't load image from file '%s': file does not exist."), filename.c_str() );
return FALSE;
}
{
#if wxUSE_STREAMS
wxFileOutputStream stream(filename);
-
+
if ( stream.LastError() == wxStream_NOERROR )
return SaveFile(stream, type);
else
return FALSE;
}
+bool wxImage::SaveFile( const wxString& filename, const wxString& mimetype )
+{
+#if wxUSE_STREAMS
+ wxFileOutputStream stream(filename);
+
+ if ( stream.LastError() == wxStream_NOERROR )
+ return SaveFile(stream, mimetype);
+ else
+#endif // wxUSE_STREAMS
+ return FALSE;
+}
+
#if wxUSE_STREAMS
bool wxImage::LoadFile( wxInputStream& stream, long type )
{
if (handler == NULL)
{
- wxLogWarning( "No image handler for type %d defined.", type );
+ wxLogWarning( _T("No image handler for type %d defined."), type );
return FALSE;
}
return handler->LoadFile( this, stream );
}
+bool wxImage::LoadFile( wxInputStream& stream, const wxString& mimetype )
+{
+ UnRef();
+
+ m_refData = new wxImageRefData;
+
+ wxImageHandler *handler = FindHandlerMime(mimetype);
+
+ if (handler == NULL)
+ {
+ wxLogWarning( _T("No image handler for type %s defined."), mimetype.GetData() );
+
+ return FALSE;
+ }
+
+ return handler->LoadFile( this, stream );
+}
+
bool wxImage::SaveFile( wxOutputStream& stream, int type )
{
- wxCHECK_MSG( Ok(), FALSE, "invalid image" );
+ wxCHECK_MSG( Ok(), FALSE, _T("invalid image") );
wxImageHandler *handler = FindHandler(type);
if (handler == NULL)
{
- wxLogWarning( "No image handler for type %d defined.", type );
+ wxLogWarning( _T("No image handler for type %d defined."), type );
+
+ return FALSE;
+ }
+
+ return handler->SaveFile( this, stream );
+}
+
+bool wxImage::SaveFile( wxOutputStream& stream, const wxString& mimetype )
+{
+ wxCHECK_MSG( Ok(), FALSE, _T("invalid image") );
+
+ wxImageHandler *handler = FindHandlerMime(mimetype);
+
+ if (handler == NULL)
+ {
+ wxLogWarning( _T("No image handler for type %s defined."), mimetype.GetData() );
return FALSE;
}
return NULL;
}
+wxImageHandler *wxImage::FindHandlerMime( const wxString& mimetype )
+{
+ wxNode *node = sm_handlers.First();
+ while (node)
+ {
+ wxImageHandler *handler = (wxImageHandler *)node->Data();
+ if (handler->GetMimeType().IsSameAs(mimetype, FALSE)) return handler;
+ node = node->Next();
+ }
+ return NULL;
+}
+
void wxImage::InitStandardHandlers()
{
AddHandler( new wxBMPHandler );
int height = (int)dbuf[1];
if (width > 32767)
{
- wxLogError( "Image width > 32767 pixels for file\n" );
+ wxLogError( _T("Image width > 32767 pixels for file\n") );
return FALSE;
}
if (height > 32767)
{
- wxLogError( "Image height > 32767 pixels for file\n" );
+ wxLogError( _T("Image height > 32767 pixels for file\n") );
return FALSE;
}
stream.Read(&word, 2);
bpp = (int)word;
if (bpp != 1 && bpp != 4 && bpp != 8 && bpp && 16 && bpp != 24 && bpp != 32)
{
- wxLogError( "unknown bitdepth in file\n" );
+ wxLogError( _T("unknown bitdepth in file\n") );
return FALSE;
}
stream.Read(dbuf, 4 * 4);
comp = (int)dbuf[0];
if (comp != BI_RGB && comp != BI_RLE4 && comp != BI_RLE8 && comp != BI_BITFIELDS)
{
- wxLogError( "unknown encoding in Windows BMP file\n" );
+ wxLogError( _T("unknown encoding in Windows BMP file\n") );
return FALSE;
}
stream.Read(dbuf, 4 * 2);
/* some more sanity checks */
if (((comp == BI_RLE4) && (bpp != 4)) || ((comp == BI_RLE8) && (bpp != 8)) || ((comp == BI_BITFIELDS) && (bpp != 16 && bpp != 32)))
{
- wxLogError( "encoding of BMP doesn't match bitdepth\n" );
+ wxLogError( _T("encoding of BMP doesn't match bitdepth\n") );
return FALSE;
}
if (bpp < 16)
if (!cmap)
{
- wxLogError( "Cannot allocate RAM for color map in BMP file\n" );
+ wxLogError( _T("Cannot allocate RAM for color map in BMP file\n") );
return FALSE;
}
}
ptr = image->GetData();
if (!ptr)
{
- wxLogError( "Cannot allocate RAM for RGB data in file\n" );
+ wxLogError( _T("Cannot allocate RAM for RGB data in file\n") );
if (cmap)
free(cmap);
return FALSE;
{
if (comp == BI_RLE4)
{
- wxLogError( "can't deal with 4bit encoded yet.\n");
+ wxLogError( _T("can't deal with 4bit encoded yet.\n") );
image->Destroy();
free(cmap);
return FALSE;
// set bitmap parameters
wxBitmap bitmap;
- wxCHECK_MSG( Ok(), bitmap, "invalid image" );
+ wxCHECK_MSG( Ok(), bitmap, _T("invalid image") );
bitmap.SetWidth( width );
bitmap.SetHeight( bmpHeight );
bitmap.SetDepth( wxDisplayDepth() );
// create a DIB header
int headersize = sizeof(BITMAPINFOHEADER);
LPBITMAPINFO lpDIBh = (BITMAPINFO *) malloc( headersize );
- wxCHECK_MSG( lpDIBh, bitmap, "could not allocate memory for DIB header" );
+ wxCHECK_MSG( lpDIBh, bitmap, _T("could not allocate memory for DIB header") );
// Fill in the DIB header
lpDIBh->bmiHeader.biSize = headersize;
lpDIBh->bmiHeader.biWidth = (DWORD)width;
lpBits = (unsigned char *)malloc( lpDIBh->bmiHeader.biSizeImage );
if( !lpBits )
{
- wxFAIL_MSG( "could not allocate memory for DIB" );
+ wxFAIL_MSG( _T("could not allocate memory for DIB") );
free( lpDIBh );
return bitmap;
}
// check the bitmap
if( !bitmap.Ok() )
{
- wxFAIL_MSG( "invalid bitmap" );
+ wxFAIL_MSG( _T("invalid bitmap") );
return;
}
unsigned char *data = GetData();
if( !data )
{
- wxFAIL_MSG( "could not allocate data for image" );
+ wxFAIL_MSG( _T("could not allocate data for image") );
return;
}
LPBITMAPINFO lpDIBh = (BITMAPINFO *) malloc( headersize );
if( !lpDIBh )
{
- wxFAIL_MSG( "could not allocate data for DIB header" );
+ wxFAIL_MSG( _T("could not allocate data for DIB header") );
free( data );
return;
}
lpBits = (unsigned char *) malloc( lpDIBh->bmiHeader.biSizeImage );
if( !lpBits )
{
- wxFAIL_MSG( "could not allocate data for DIB" );
+ wxFAIL_MSG( _T("could not allocate data for DIB") );
free( data );
free( lpDIBh );
return;
#include "gdk/gdk.h"
#include "gdk/gdkx.h"
+#if (GTK_MINOR_VERSION > 0)
+#include "gdk/gdkrgb.h"
+#endif
+
wxBitmap wxImage::ConvertToBitmap() const
{
wxBitmap bitmap;
- wxCHECK_MSG( Ok(), bitmap, "invalid image" );
+ wxCHECK_MSG( Ok(), bitmap, _T("invalid image") );
int width = GetWidth();
int height = GetHeight();
bitmap.SetHeight( height );
bitmap.SetWidth( width );
- // Create picture
+ bitmap.SetPixmap( gdk_pixmap_new( (GdkWindow*)&gdk_root_parent, width, height, -1 ) );
+
+ // Retrieve depth
+
+ GdkVisual *visual = gdk_window_get_visual( bitmap.GetPixmap() );
+ if (visual == NULL) visual = gdk_window_get_visual( (GdkWindow*) &gdk_root_parent );
+ int bpp = visual->depth;
+
+ bitmap.SetDepth( bpp );
+
+ if ((bpp == 16) && (visual->red_mask != 0xf800)) bpp = 15;
+ if (bpp < 8) bpp = 8;
+
+#if (GTK_MINOR_VERSION > 0)
+
+ if (!HasMask() && (bpp > 8))
+ {
+ static bool s_hasInitialized = FALSE;
+
+ if (!s_hasInitialized)
+ {
+ gdk_rgb_init();
+ s_hasInitialized = TRUE;
+ }
+
+ GdkGC *gc = gdk_gc_new( bitmap.GetPixmap() );
+
+ gdk_draw_rgb_image( bitmap.GetPixmap(),
+ gc,
+ 0, 0,
+ width, height,
+ GDK_RGB_DITHER_NONE,
+ GetData(),
+ width*3 );
+
+ gdk_gc_unref( gc );
+
+ return bitmap;
+ }
+
+#endif
+
+ // Create picture image
GdkImage *data_image =
gdk_image_new( GDK_IMAGE_FASTEST, gdk_visual_get_system(), width, height );
- bitmap.SetPixmap( gdk_pixmap_new( (GdkWindow*)&gdk_root_parent, width, height, -1 ) );
-
- // Create mask
+ // Create mask image
GdkImage *mask_image = (GdkImage*) NULL;
bitmap.SetMask( mask );
}
- // Retrieve depth
-
- GdkVisual *visual = gdk_window_get_visual( bitmap.GetPixmap() );
- if (visual == NULL) visual = gdk_window_get_visual( (GdkWindow*) &gdk_root_parent );
- int bpp = visual->depth;
-
- bitmap.SetDepth( bpp );
-
- if ((bpp == 16) && (visual->red_mask != 0xf800)) bpp = 15;
- if (bpp < 8) bpp = 8;
-
// Render
enum byte_order { RGB, RBG, BRG, BGR, GRB, GBR };
wxImage::wxImage( const wxBitmap &bitmap )
{
- wxCHECK_RET( bitmap.Ok(), "invalid bitmap" );
+ wxCHECK_RET( bitmap.Ok(), _T("invalid bitmap") );
GdkImage *gdk_image = gdk_image_get( bitmap.GetPixmap(),
0, 0,
bitmap.GetWidth(), bitmap.GetHeight() );
- wxCHECK_RET( gdk_image, "couldn't create image" );
+ wxCHECK_RET( gdk_image, _T("couldn't create image") );
Create( bitmap.GetWidth(), bitmap.GetHeight() );
char unsigned *data = GetData();
if (!data)
{
gdk_image_destroy( gdk_image );
- wxFAIL_MSG( "couldn't create image" );
+ wxFAIL_MSG( _T("couldn't create image") );
return;
}
{
wxBitmap bitmap;
- wxCHECK_MSG( Ok(), bitmap, "invalid image" );
+ wxCHECK_MSG( Ok(), bitmap, _T("invalid image") );
int width = GetWidth();
int height = GetHeight();
wxImage::wxImage( const wxBitmap &bitmap )
{
- wxCHECK_RET( bitmap.Ok(), "invalid bitmap" );
+ wxCHECK_RET( bitmap.Ok(), _T("invalid bitmap") );
Display *dpy = (Display*) wxGetDisplay();
Visual* vis = DefaultVisual( dpy, DefaultScreen( dpy ) );
bitmap.GetWidth(), bitmap.GetHeight(),
AllPlanes, ZPixmap );
- wxCHECK_RET( ximage, "couldn't create image" );
+ wxCHECK_RET( ximage, _T("couldn't create image") );
Create( bitmap.GetWidth(), bitmap.GetHeight() );
char unsigned *data = GetData();
if (!data)
{
XDestroyImage( ximage );
- wxFAIL_MSG( "couldn't create image" );
+ wxFAIL_MSG( _T("couldn't create image") );
return;
}
};
IMPLEMENT_DYNAMIC_CLASS(wxImageModule, wxModule)
-