fine-tuned API from the ICO patch

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12540 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2001-11-20 23:55:44 +00:00
parent 8065aebc48
commit 1f5b2017df
3 changed files with 32 additions and 31 deletions

View File

@@ -151,9 +151,14 @@ public:
unsigned char GetGreen( int x, int y ) const; unsigned char GetGreen( int x, int y ) const;
unsigned char GetBlue( int x, int y ) const; unsigned char GetBlue( int x, int y ) const;
// used to manipulate the icons while extracting from .ico files // find first colour that is not used in the image and has higher
bool GetUnusedColour( unsigned char *r, unsigned char *g, unsigned char *b ); // RGB values than <startR,startG,startB>
bool ApplyMask( const wxImage & mask ); bool FindFirstUnusedColour( unsigned char *r, unsigned char *g, unsigned char *b,
unsigned char startR = 1, unsigned char startG = 0,
unsigned char startB = 0 );
// Set image's mask to the area of 'mask' that has <r,g,b> colour
bool SetMaskFromImage(const wxImage & mask,
unsigned char mr, unsigned char mg, unsigned char mb);
static bool CanRead( const wxString& name ); static bool CanRead( const wxString& name );
virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY ); virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY );

View File

@@ -748,8 +748,6 @@ bool wxBMPHandler::DoLoadDib (wxImage * image, int width, int height, int bpp, i
bool wxBMPHandler::LoadDib( wxImage *image, wxInputStream& stream, bool verbose, bool IsBmp ) bool wxBMPHandler::LoadDib( wxImage *image, wxInputStream& stream, bool verbose, bool IsBmp )
{ {
wxUint8 aByte;
wxUint16 aWord; wxUint16 aWord;
wxInt32 dbuf[4]; wxInt32 dbuf[4];
wxInt8 bbuf[4]; wxInt8 bbuf[4];
@@ -844,7 +842,7 @@ bool wxBMPHandler::LoadDib( wxImage *image, wxInputStream& stream, bool verbose,
{ {
//read Icon mask which is monochrome //read Icon mask which is monochrome
//there is no palette, so we will create one //there is no palette, so we will create one
wxImage mask ; wxImage mask;
if (!DoLoadDib (&mask, width, height, 1, 2, BI_RGB, offset, stream, if (!DoLoadDib (&mask, width, height, 1, 2, BI_RGB, offset, stream,
verbose, IsBmp, FALSE ) ) verbose, IsBmp, FALSE ) )
{ {
@@ -852,7 +850,7 @@ bool wxBMPHandler::LoadDib( wxImage *image, wxInputStream& stream, bool verbose,
wxLogError( _("ICO: Error in reading mask DIB.") ); wxLogError( _("ICO: Error in reading mask DIB.") );
return FALSE; return FALSE;
} }
image -> ApplyMask ( &mask ); image->SetMaskFromImage(mask, 255, 255, 255);
} }
return TRUE; return TRUE;

View File

@@ -721,33 +721,33 @@ int wxImage::GetHeight() const
} }
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; wxHashTable hTable;
unsigned long key; unsigned long key;
ComputeHistogram( hTable ); ComputeHistogram( hTable );
// start with blackest color and work to lightest unsigned char r2 = startR;
// 0,0,0 is quite likely to be a used color unsigned char g2 = startG;
unsigned char r2 = 1; unsigned char b2 = startB;
unsigned char g2 = 0;
unsigned char b2 = 0;
key = (r2 << 16) | (g2 << 8) | b2; key = (r2 << 16) | (g2 << 8) | b2;
while ( (wxHNode *) hTable.Get(key) ) while ( (wxHNode *) hTable.Get(key) )
{ {
// color already used // color already used
r2 ++ ; r2++;
if ( r2 >= 255 ) if ( r2 >= 255 )
{ {
r2 = 0; r2 = 0;
g2 ++ ; g2++;
if ( g2 >= 255 ) if ( g2 >= 255 )
{ {
g2 = 0 ; g2 = 0;
b2 ++ ; b2++;
if ( b2 >= 255 ) if ( b2 >= 255 )
{ {
wxLogError( _("GetUnusedColour:: No Unused Color in image ") ); wxLogError( _("GetUnusedColour:: No Unused Color in image ") );
@@ -759,19 +759,17 @@ bool wxImage::GetUnusedColour ( unsigned char * r, unsigned char * g, unsigne
key = (r2 << 16) | (g2 << 8) | b2; key = (r2 << 16) | (g2 << 8) | b2;
} }
if (r) *r = r2;
if (g) *g = g2;
if (b) *b = b2;
return TRUE; 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 // check that the images are the same size
if ( (M_IMGDATA->m_height != mask.GetHeight() ) || (M_IMGDATA->m_width != mask.GetWidth () ) ) if ( (M_IMGDATA->m_height != mask.GetHeight() ) || (M_IMGDATA->m_width != mask.GetWidth () ) )
{ {
@@ -781,7 +779,7 @@ bool wxImage::ApplyMask ( const wxImage & mask )
// find unused colour // find unused colour
unsigned char r,g,b ; unsigned char r,g,b ;
if (!GetUnusedColour (&r, &g, &b)) if (!FindFirstUnusedColour(&r, &g, &b))
{ {
wxLogError( _("No Unused Color in image being masked") ); wxLogError( _("No Unused Color in image being masked") );
return FALSE ; return FALSE ;
@@ -794,9 +792,10 @@ bool wxImage::ApplyMask ( const wxImage & mask )
const int h = GetHeight(); const int h = GetHeight();
for (int j = 0; j < h; j++) for (int j = 0; j < h; j++)
{
for (int i = 0; i < w; i++) 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[0] = r;
imgdata[1] = g; imgdata[1] = g;
@@ -805,11 +804,10 @@ bool wxImage::ApplyMask ( const wxImage & mask )
imgdata += 3; imgdata += 3;
maskdata += 3; maskdata += 3;
} }
}
M_IMGDATA->m_maskRed = r; SetMaskColour(r, g, b);
M_IMGDATA->m_maskGreen = g; SetMask(TRUE);
M_IMGDATA->m_maskBlue = b;
M_IMGDATA->m_hasMask = TRUE;
return TRUE; return TRUE;
} }