Create( width, height, data, static_data );
}
-wxImage::wxImage( const wxString& name, long type )
+wxImage::wxImage( const wxString& name, long type, int index )
{
- LoadFile( name, type );
+ LoadFile( name, type, index );
}
-wxImage::wxImage( const wxString& name, const wxString& mimetype )
+wxImage::wxImage( const wxString& name, const wxString& mimetype, int index )
{
- LoadFile( name, mimetype );
+ LoadFile( name, mimetype, index );
}
#if wxUSE_STREAMS
-wxImage::wxImage( wxInputStream& stream, long type )
+wxImage::wxImage( wxInputStream& stream, long type, int index )
{
- LoadFile( stream, type );
+ LoadFile( stream, type, index );
}
-wxImage::wxImage( wxInputStream& stream, const wxString& mimetype )
+wxImage::wxImage( wxInputStream& stream, const wxString& mimetype, int index )
{
- LoadFile( stream, mimetype );
+ LoadFile( stream, mimetype, index );
}
#endif // wxUSE_STREAMS
}
-bool wxImage::GetUnusedColour ( unsigned char * r, unsigned char * g, unsigned char * b )
+bool wxImage::FindFirstUnusedColour(
+ unsigned char *r, unsigned char *g, unsigned char *b,
+ unsigned char startR, unsigned char startG, unsigned char startB)
{
wxHashTable hTable;
unsigned long key;
ComputeHistogram( hTable );
- // start with blackest color and work to lightest
- // 0,0,0 is quite likely to be a used color
- unsigned char r2 = 1;
- unsigned char g2 = 0;
- unsigned char b2 = 0;
+ unsigned char r2 = startR;
+ unsigned char g2 = startG;
+ unsigned char b2 = startB;
key = (r2 << 16) | (g2 << 8) | b2;
while ( (wxHNode *) hTable.Get(key) )
{
// color already used
- r2 ++ ;
+ r2++;
if ( r2 >= 255 )
{
r2 = 0;
- g2 ++ ;
+ g2++;
if ( g2 >= 255 )
{
- g2 = 0 ;
- b2 ++ ;
+ g2 = 0;
+ b2++;
if ( b2 >= 255 )
{
wxLogError( _("GetUnusedColour:: No Unused Color in image ") );
key = (r2 << 16) | (g2 << 8) | b2;
}
+ if (r) *r = r2;
+ if (g) *g = g2;
+ if (b) *b = b2;
+
return TRUE;
}
-bool wxImage::ApplyMask ( const wxImage & mask )
+bool wxImage::SetMaskFromImage(const wxImage& mask,
+ unsigned char mr, unsigned char mg, unsigned char mb)
{
- // what to do if we already have a mask ??
- if (M_IMGDATA->m_hasMask || mask.HasMask() )
- {
- wxLogError( _("Image already masked") );
- return FALSE;
- }
-
// check that the images are the same size
if ( (M_IMGDATA->m_height != mask.GetHeight() ) || (M_IMGDATA->m_width != mask.GetWidth () ) )
{
// find unused colour
unsigned char r,g,b ;
- if (!GetUnusedColour (&r, &g, &b))
+ if (!FindFirstUnusedColour(&r, &g, &b))
{
wxLogError( _("No Unused Color in image being masked") );
return FALSE ;
const int h = GetHeight();
for (int j = 0; j < h; j++)
+ {
for (int i = 0; i < w; i++)
{
- if ((maskdata[0] > 128) && (maskdata[1] > 128) && (maskdata[2] > 128 ))
+ if ((maskdata[0] == mr) && (maskdata[1] == mg) && (maskdata[2] == mb))
{
imgdata[0] = r;
imgdata[1] = g;
imgdata += 3;
maskdata += 3;
}
+ }
- M_IMGDATA->m_maskRed = r;
- M_IMGDATA->m_maskGreen = g;
- M_IMGDATA->m_maskBlue = b;
- M_IMGDATA->m_hasMask = TRUE;
+ SetMaskColour(r, g, b);
+ SetMask(TRUE);
return TRUE;
}
return (M_IMGDATA->m_optionNames.Index(name, FALSE) != wxNOT_FOUND);
}
-bool wxImage::LoadFile( const wxString& filename, long type )
+bool wxImage::LoadFile( const wxString& filename, long type, int index )
{
#if wxUSE_STREAMS
if (wxFileExists(filename))
{
wxFileInputStream stream(filename);
wxBufferedInputStream bstream( stream );
- return LoadFile(bstream, type);
+ return LoadFile(bstream, type, index);
}
else
{
#endif // wxUSE_STREAMS
}
-bool wxImage::LoadFile( const wxString& filename, const wxString& mimetype )
+bool wxImage::LoadFile( const wxString& filename, const wxString& mimetype, int index )
{
#if wxUSE_STREAMS
if (wxFileExists(filename))
{
wxFileInputStream stream(filename);
wxBufferedInputStream bstream( stream );
- return LoadFile(bstream, mimetype);
+ return LoadFile(bstream, mimetype, index);
}
else
{
#endif
}
+int wxImage::GetImageCount( const wxString &name, long type )
+{
+#if wxUSE_STREAMS
+ wxFileInputStream stream(name);
+ return GetImageCount(stream, type);
+#else
+ return 0;
+#endif
+}
+
#if wxUSE_STREAMS
bool wxImage::CanRead( wxInputStream &stream )
{
- wxList &list=GetHandlers();
+ wxList &list=GetHandlers();
- for ( wxList::Node *node = list.GetFirst(); node; node = node->GetNext() )
+ for ( wxList::Node *node = list.GetFirst(); node; node = node->GetNext() )
{
- wxImageHandler *handler=(wxImageHandler*)node->GetData();
- if (handler->CanRead( stream ))
- return TRUE;
+ wxImageHandler *handler=(wxImageHandler*)node->GetData();
+ if (handler->CanRead( stream ))
+ return TRUE;
}
- return FALSE;
+ return FALSE;
+}
+
+int wxImage::GetImageCount( wxInputStream &stream, long type )
+{
+ wxImageHandler *handler;
+
+ if ( type == wxBITMAP_TYPE_ANY )
+ {
+ wxList &list=GetHandlers();
+
+ for (wxList::Node *node = list.GetFirst(); node; node = node->GetNext())
+ {
+ handler=(wxImageHandler*)node->GetData();
+ if ( handler->CanRead(stream) )
+ return handler->GetImageCount(stream);
+
+ }
+
+ wxLogWarning(_("No handler found for image type."));
+ return 0;
+ }
+
+ handler = FindHandler(type);
+
+ if ( !handler )
+ {
+ wxLogWarning(_("No image handler for type %d defined."), type);
+ return FALSE;
+ }
+
+ if ( handler->CanRead(stream) )
+ {
+ return handler->GetImageCount(stream);
+ }
+ else
+ {
+ wxLogError(_("Image file is not of type %d."), type);
+ return 0;
+ }
}
-bool wxImage::LoadFile( wxInputStream& stream, long type )
+bool wxImage::LoadFile( wxInputStream& stream, long type, int index )
{
UnRef();
wxImageHandler *handler;
- if (type==wxBITMAP_TYPE_ANY)
+ if ( type == wxBITMAP_TYPE_ANY )
{
wxList &list=GetHandlers();
for ( wxList::Node *node = list.GetFirst(); node; node = node->GetNext() )
{
handler=(wxImageHandler*)node->GetData();
- if (handler->CanRead( stream ))
- return handler->LoadFile( this, stream );
+ if ( handler->CanRead(stream) )
+ return handler->LoadFile(this, stream, TRUE/*verbose*/, index);
}
return FALSE;
}
- return handler->LoadFile( this, stream );
+ return handler->LoadFile(this, stream, TRUE/*verbose*/, index);
}
-bool wxImage::LoadFile( wxInputStream& stream, const wxString& mimetype )
+bool wxImage::LoadFile( wxInputStream& stream, const wxString& mimetype, int index )
{
UnRef();
return FALSE;
}
- return handler->LoadFile( this, stream );
+ return handler->LoadFile( this, stream, TRUE/*verbose*/, index );
}
bool wxImage::SaveFile( wxOutputStream& stream, int type )