X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/649d13e837b25f7b948ccfae02b18131f3a0a743..418d4918a23299c13c9d8236dbeaccedf663a68d:/src/common/image.cpp diff --git a/src/common/image.cpp b/src/common/image.cpp index 73f00d9f88..48b39581f5 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -723,12 +723,12 @@ int wxImage::GetHeight() const bool wxImage::FindFirstUnusedColour( unsigned char *r, unsigned char *g, unsigned char *b, - unsigned char startR, unsigned char startG, unsigned char startB) + unsigned char startR, unsigned char startG, unsigned char startB) const { - wxHashTable hTable; + wxImageHistogram histogram; unsigned long key; - ComputeHistogram( hTable ); + ComputeHistogram(histogram); unsigned char r2 = startR; unsigned char g2 = startG; @@ -736,7 +736,7 @@ bool wxImage::FindFirstUnusedColour( key = (r2 << 16) | (g2 << 8) | b2; - while ( (wxHNode *) hTable.Get(key) ) + while ( histogram.find(key) != histogram.end() ) { // color already used r2++; @@ -930,7 +930,7 @@ bool wxImage::LoadFile( const wxString& filename, const wxString& mimetype, int #endif // wxUSE_STREAMS } -bool wxImage::SaveFile( const wxString& filename, int type ) +bool wxImage::SaveFile( const wxString& filename, int type ) const { #if wxUSE_STREAMS wxFileOutputStream stream(filename); @@ -945,7 +945,7 @@ bool wxImage::SaveFile( const wxString& filename, int type ) return FALSE; } -bool wxImage::SaveFile( const wxString& filename, const wxString& mimetype ) +bool wxImage::SaveFile( const wxString& filename, const wxString& mimetype ) const { #if wxUSE_STREAMS wxFileOutputStream stream(filename); @@ -1089,7 +1089,7 @@ bool wxImage::LoadFile( wxInputStream& stream, const wxString& mimetype, int ind return handler->LoadFile( this, stream, TRUE/*verbose*/, index ); } -bool wxImage::SaveFile( wxOutputStream& stream, int type ) +bool wxImage::SaveFile( wxOutputStream& stream, int type ) const { wxCHECK_MSG( Ok(), FALSE, wxT("invalid image") ); @@ -1102,10 +1102,10 @@ bool wxImage::SaveFile( wxOutputStream& stream, int type ) return FALSE; } - return handler->SaveFile( this, stream ); + return handler->SaveFile( (wxImage*)this, stream ); } -bool wxImage::SaveFile( wxOutputStream& stream, const wxString& mimetype ) +bool wxImage::SaveFile( wxOutputStream& stream, const wxString& mimetype ) const { wxCHECK_MSG( Ok(), FALSE, wxT("invalid image") ); @@ -1118,7 +1118,7 @@ bool wxImage::SaveFile( wxOutputStream& stream, const wxString& mimetype ) return FALSE; } - return handler->SaveFile( this, stream ); + return handler->SaveFile( (wxImage*)this, stream ); } #endif // wxUSE_STREAMS @@ -1203,7 +1203,10 @@ wxImageHandler *wxImage::FindHandlerMime( const wxString& mimetype ) void wxImage::InitStandardHandlers() { +#if wxUSE_STREAMS AddHandler(new wxBMPHandler); +#endif // wxUSE_STREAMS + #if wxUSE_XPM && !defined(__WXGTK__) && !defined(__WXMOTIF__) AddHandler(new wxXPMHandler); #endif @@ -1319,7 +1322,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxImageModule, wxModule) // less, in this case it would be invoked as CountColours(256)). Default // value for stopafter is -1 (don't care). // -unsigned long wxImage::CountColours( unsigned long stopafter ) +unsigned long wxImage::CountColours( unsigned long stopafter ) const { wxHashTable h; wxObject dummy; @@ -1349,19 +1352,13 @@ unsigned long wxImage::CountColours( unsigned long stopafter ) } -// GRG, Dic/99 -// Computes the histogram of the image and fills a hash table, indexed -// with integer keys built as 0xRRGGBB, containing wxHNode objects. Each -// wxHNode contains an 'index' (useful to build a palette with the image -// colours) and a 'value', which is the number of pixels in the image with -// that colour. -// -unsigned long wxImage::ComputeHistogram( wxHashTable &h ) +unsigned long wxImage::ComputeHistogram( wxImageHistogram &h ) const { unsigned char r, g, b; unsigned char *p; unsigned long size, nentries, key; - wxHNode *hnode; + + h.clear(); p = GetData(); size = GetWidth() * GetHeight(); @@ -1374,18 +1371,9 @@ unsigned long wxImage::ComputeHistogram( wxHashTable &h ) b = *(p++); key = (r << 16) | (g << 8) | b; - hnode = (wxHNode *) h.Get(key); - - if (hnode) - hnode->value++; - else - { - hnode = new wxHNode(); - hnode->index = nentries++; - hnode->value = 1; - - h.Put(key, (wxObject *)hnode); - } + wxImageHistogramEntry& entry = h[key]; + if ( entry.value++ == 0 ) + entry.index = nentries++; } return nentries;