// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "image.h"
#endif
memcpy( data, GetData(), M_IMGDATA->m_width*M_IMGDATA->m_height*3 );
+ // also copy the image options
+ wxImageRefData *imgData = (wxImageRefData *)image.m_refData;
+ imgData->m_optionNames = M_IMGDATA->m_optionNames;
+ imgData->m_optionValues = M_IMGDATA->m_optionValues;
+
return image;
}
}
else
{
- *(target_data++) = avgRed / counter ;
- *(target_data++) = avgGreen / counter ;
- *(target_data++) = avgBlue / counter ;
+ *(target_data++) = (unsigned char)(avgRed / counter);
+ *(target_data++) = (unsigned char)(avgGreen / counter);
+ *(target_data++) = (unsigned char)(avgBlue / counter);
}
}
}
M_IMGDATA->m_alpha[y*w + x] = alpha;
}
-unsigned char wxImage::GetAlpha(int x, int y)
+unsigned char wxImage::GetAlpha(int x, int y) const
{
wxCHECK_MSG( Ok() && HasAlpha(), 0, wxT("invalid image or no alpha channel") );
alpha = (unsigned char *)malloc(M_IMGDATA->m_width*M_IMGDATA->m_height);
}
- delete [] M_IMGDATA->m_alpha;
+ free(M_IMGDATA->m_alpha);
M_IMGDATA->m_alpha = alpha;
}
// check that the images are the same size
if ( (M_IMGDATA->m_height != mask.GetHeight() ) || (M_IMGDATA->m_width != mask.GetWidth () ) )
{
- wxLogError( _("Image and Mask have different sizes") );
+ wxLogError( _("Image and mask have different sizes.") );
return false;
}
unsigned char r,g,b ;
if (!FindFirstUnusedColour(&r, &g, &b))
{
- wxLogError( _("No Unused Color in image being masked") );
+ wxLogError( _("No unused colour in image being masked.") );
return false ;
}
return true;
}
+
+bool wxImage::ConvertAlphaToMask(unsigned char threshold)
+{
+ if (!HasAlpha())
+ return true;
+
+ unsigned char mr, mg, mb;
+ if (!FindFirstUnusedColour(&mr, &mg, &mb))
+ {
+ wxLogError( _("No unused colour in image being masked.") );
+ return false;
+ }
+
+ SetMask(true);
+ SetMaskColour(mr, mg, mb);
+
+ unsigned char *imgdata = GetData();
+ unsigned char *alphadata = GetAlpha();
+
+ int w = GetWidth();
+ int h = GetHeight();
+
+ for (int y = 0; y < h; y++)
+ {
+ for (int x = 0; x < w; x++, imgdata += 3, alphadata++)
+ {
+ if (*alphadata < threshold)
+ {
+ imgdata[0] = mr;
+ imgdata[1] = mg;
+ imgdata[2] = mb;
+ }
+ }
+ }
+
+ free(M_IMGDATA->m_alpha);
+ M_IMGDATA->m_alpha = NULL;
+
+ return true;
+}
#if wxUSE_PALETTE
{
const wxList& list = GetHandlers();
- for ( wxList::Node *node = list.GetFirst(); node; node = node->GetNext() )
+ for ( wxList::compatibility_iterator node = list.GetFirst(); node; node = node->GetNext() )
{
wxImageHandler *handler=(wxImageHandler*)node->GetData();
if (handler->CanRead( stream ))
{
wxList &list=GetHandlers();
- for (wxList::Node *node = list.GetFirst(); node; node = node->GetNext())
+ for (wxList::compatibility_iterator node = list.GetFirst(); node; node = node->GetNext())
{
handler=(wxImageHandler*)node->GetData();
if ( handler->CanRead(stream) )
{
wxList &list=GetHandlers();
- for ( wxList::Node *node = list.GetFirst(); node; node = node->GetNext() )
+ for ( wxList::compatibility_iterator node = list.GetFirst(); node; node = node->GetNext() )
{
handler=(wxImageHandler*)node->GetData();
if ( handler->CanRead(stream) )
void wxImage::AddHandler( wxImageHandler *handler )
{
- // make sure that the memory will be freed at the program end
- sm_handlers.DeleteContents(true);
-
// Check for an existing handler of the type being added.
if (FindHandler( handler->GetType() ) == 0)
{
void wxImage::InsertHandler( wxImageHandler *handler )
{
- // make sure that the memory will be freed at the program end
- sm_handlers.DeleteContents(true);
-
// Check for an existing handler of the type being added.
if (FindHandler( handler->GetType() ) == 0)
{
if (handler)
{
sm_handlers.DeleteObject(handler);
+ delete handler;
return true;
}
else
wxImageHandler *wxImage::FindHandler( const wxString& name )
{
- wxNode *node = sm_handlers.GetFirst();
+ wxList::compatibility_iterator node = sm_handlers.GetFirst();
while (node)
{
wxImageHandler *handler = (wxImageHandler*)node->GetData();
wxImageHandler *wxImage::FindHandler( const wxString& extension, long bitmapType )
{
- wxNode *node = sm_handlers.GetFirst();
+ wxList::compatibility_iterator node = sm_handlers.GetFirst();
while (node)
{
wxImageHandler *handler = (wxImageHandler*)node->GetData();
wxImageHandler *wxImage::FindHandler( long bitmapType )
{
- wxNode *node = sm_handlers.GetFirst();
+ wxList::compatibility_iterator node = sm_handlers.GetFirst();
while (node)
{
wxImageHandler *handler = (wxImageHandler *)node->GetData();
wxImageHandler *wxImage::FindHandlerMime( const wxString& mimetype )
{
- wxNode *node = sm_handlers.GetFirst();
+ wxList::compatibility_iterator node = sm_handlers.GetFirst();
while (node)
{
wxImageHandler *handler = (wxImageHandler *)node->GetData();
void wxImage::CleanUpHandlers()
{
- wxNode *node = sm_handlers.GetFirst();
+ wxList::compatibility_iterator node = sm_handlers.GetFirst();
while (node)
{
wxImageHandler *handler = (wxImageHandler *)node->GetData();
- wxNode *next = node->GetNext();
+ wxList::compatibility_iterator next = node->GetNext();
delete handler;
- delete node;
node = next;
}
-}
+ sm_handlers.Clear();
+}
wxString wxImage::GetImageExtWildcard()
{
wxString fmts;
wxList& Handlers = wxImage::GetHandlers();
- wxNode* Node = Handlers.GetFirst();
+ wxList::compatibility_iterator Node = Handlers.GetFirst();
while ( Node )
{
wxImageHandler* Handler = (wxImageHandler*)Node->GetData();
return wxT("(") + fmts + wxT(")|") + fmts;
}
-
//-----------------------------------------------------------------------------
// wxImageHandler
//-----------------------------------------------------------------------------
b2++;
if ( b2 >= 255 )
{
- wxLogError(_("GetUnusedColour:: No Unused Color in image ") );
+ wxLogError(_("No unused colour in image.") );
return false;
}
}
w3 * *(v3++) + w4 * *(v4++)) /
(w1 + w2 + w3 + w4) );
*(dst++) = (unsigned char)
- ( (w1 * *(v1++) + w2 * *(v2++) +
- w3 * *(v3++) + w4 * *(v4++)) /
+ ( (w1 * *v1 + w2 * *v2 +
+ w3 * *v3 + w4 * *v4) /
(w1 + w2 + w3 + w4) );
}
}
unsigned char *p = data[ys] + (3 * xs);
*(dst++) = *(p++);
*(dst++) = *(p++);
- *(dst++) = *(p++);
+ *(dst++) = *p;
}
else
{