Added mono bitmap to image conversion.
Added wxImage::Replace() (replaces one colour with another). Toolbar tips no longer eats ana new colour. This might prevent the wrong colour behaviour reported from some 8-bit visuals. Minor fixes and test code. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5122 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -37,8 +37,6 @@ class WXDLLEXPORT wxImage;
|
|||||||
|
|
||||||
class WXDLLEXPORT wxImageHandler: public wxObject
|
class WXDLLEXPORT wxImageHandler: public wxObject
|
||||||
{
|
{
|
||||||
DECLARE_CLASS(wxImageHandler)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
wxImageHandler() { m_name = ""; m_extension = ""; m_type = 0; }
|
wxImageHandler() { m_name = ""; m_extension = ""; m_type = 0; }
|
||||||
|
|
||||||
@@ -70,15 +68,15 @@ protected:
|
|||||||
wxString m_extension;
|
wxString m_extension;
|
||||||
wxString m_mime;
|
wxString m_mime;
|
||||||
long m_type;
|
long m_type;
|
||||||
};
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
DECLARE_CLASS(wxImageHandler)
|
||||||
|
};
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// wxImage
|
// wxImage
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
// GRG: Dic/99
|
|
||||||
class WXDLLEXPORT wxHNode
|
class WXDLLEXPORT wxHNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -86,15 +84,9 @@ public:
|
|||||||
unsigned long value;
|
unsigned long value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class WXDLLEXPORT wxImage: public wxObject
|
class WXDLLEXPORT wxImage: public wxObject
|
||||||
{
|
{
|
||||||
DECLARE_DYNAMIC_CLASS(wxImage)
|
|
||||||
|
|
||||||
friend class WXDLLEXPORT wxImageHandler;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
wxImage();
|
wxImage();
|
||||||
wxImage( int width, int height );
|
wxImage( int width, int height );
|
||||||
wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY );
|
wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY );
|
||||||
@@ -122,6 +114,10 @@ public:
|
|||||||
// rescales the image in place
|
// rescales the image in place
|
||||||
wxImage& Rescale( int width, int height ) { return *this = Scale(width, height); }
|
wxImage& Rescale( int width, int height ) { return *this = Scale(width, height); }
|
||||||
|
|
||||||
|
// replace one colour with another
|
||||||
|
void Replace( unsigned char r1, unsigned char g1, unsigned char b1,
|
||||||
|
unsigned char r2, unsigned char g2, unsigned char b2 );
|
||||||
|
|
||||||
// these routines are slow but safe
|
// these routines are slow but safe
|
||||||
void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b );
|
void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b );
|
||||||
unsigned char GetRed( int x, int y );
|
unsigned char GetRed( int x, int y );
|
||||||
@@ -160,6 +156,9 @@ public:
|
|||||||
void SetMask( bool mask = TRUE );
|
void SetMask( bool mask = TRUE );
|
||||||
bool HasMask() const;
|
bool HasMask() const;
|
||||||
|
|
||||||
|
unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 );
|
||||||
|
unsigned long ComputeHistogram( wxHashTable &h );
|
||||||
|
|
||||||
wxImage& operator = (const wxImage& image)
|
wxImage& operator = (const wxImage& image)
|
||||||
{
|
{
|
||||||
if ( (*this) != image )
|
if ( (*this) != image )
|
||||||
@@ -184,15 +183,13 @@ public:
|
|||||||
static void CleanUpHandlers();
|
static void CleanUpHandlers();
|
||||||
static void InitStandardHandlers();
|
static void InitStandardHandlers();
|
||||||
|
|
||||||
// GRG: Dic/99
|
|
||||||
unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 );
|
|
||||||
unsigned long ComputeHistogram( wxHashTable &h );
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
static wxList sm_handlers;
|
static wxList sm_handlers;
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend class WXDLLEXPORT wxImageHandler;
|
||||||
|
|
||||||
|
DECLARE_DYNAMIC_CLASS(wxImage)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -212,7 +212,8 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
|||||||
dc.SetPen( *wxWHITE_PEN );
|
dc.SetPen( *wxWHITE_PEN );
|
||||||
dc.DrawRectangle( 150, 30, 100, 100 );
|
dc.DrawRectangle( 150, 30, 100, 100 );
|
||||||
|
|
||||||
if (my_anti && my_anti->Ok()) dc.DrawBitmap( *my_anti, 280, 30 );
|
if (my_anti && my_anti->Ok())
|
||||||
|
dc.DrawBitmap( *my_anti, 280, 30 );
|
||||||
|
|
||||||
dc.DrawText( "PNG handler", 30, 135 );
|
dc.DrawText( "PNG handler", 30, 135 );
|
||||||
if (my_horse_png && my_horse_png->Ok())
|
if (my_horse_png && my_horse_png->Ok())
|
||||||
@@ -225,30 +226,43 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
|||||||
}
|
}
|
||||||
|
|
||||||
dc.DrawText( "JPEG handler", 30, 365 );
|
dc.DrawText( "JPEG handler", 30, 365 );
|
||||||
if (my_horse_jpeg && my_horse_jpeg->Ok()) dc.DrawBitmap( *my_horse_jpeg, 30, 380 );
|
if (my_horse_jpeg && my_horse_jpeg->Ok())
|
||||||
|
dc.DrawBitmap( *my_horse_jpeg, 30, 380 );
|
||||||
|
|
||||||
dc.DrawText( "GIF handler", 30, 595 );
|
dc.DrawText( "GIF handler", 30, 595 );
|
||||||
if (my_horse_gif && my_horse_gif->Ok()) dc.DrawBitmap( *my_horse_gif, 30, 610 );
|
if (my_horse_gif && my_horse_gif->Ok())
|
||||||
|
dc.DrawBitmap( *my_horse_gif, 30, 610 );
|
||||||
|
|
||||||
dc.DrawText( "PCX handler", 30, 825 );
|
dc.DrawText( "PCX handler", 30, 825 );
|
||||||
if (my_horse_pcx && my_horse_pcx->Ok()) dc.DrawBitmap( *my_horse_pcx, 30, 840 );
|
if (my_horse_pcx && my_horse_pcx->Ok())
|
||||||
|
dc.DrawBitmap( *my_horse_pcx, 30, 840 );
|
||||||
|
|
||||||
dc.DrawText( "BMP handler", 30, 1055 );
|
dc.DrawText( "BMP handler", 30, 1055 );
|
||||||
if (my_horse_bmp && my_horse_bmp->Ok()) dc.DrawBitmap( *my_horse_bmp, 30, 1070 );
|
if (my_horse_bmp && my_horse_bmp->Ok())
|
||||||
|
dc.DrawBitmap( *my_horse_bmp, 30, 1070 );
|
||||||
|
|
||||||
dc.DrawText( "PNM handler", 30, 1285 );
|
dc.DrawText( "PNM handler", 30, 1285 );
|
||||||
if (my_horse_pnm && my_horse_pnm->Ok()) dc.DrawBitmap( *my_horse_pnm, 30, 1300 );
|
if (my_horse_pnm && my_horse_pnm->Ok())
|
||||||
|
dc.DrawBitmap( *my_horse_pnm, 30, 1300 );
|
||||||
|
|
||||||
dc.DrawText( "TIFF handler", 30, 1515 );
|
dc.DrawText( "TIFF handler", 30, 1515 );
|
||||||
if (my_horse_tiff && my_horse_tiff->Ok()) dc.DrawBitmap( *my_horse_pnm, 30, 1530 );
|
if (my_horse_tiff && my_horse_tiff->Ok())
|
||||||
|
dc.DrawBitmap( *my_horse_pnm, 30, 1530 );
|
||||||
|
|
||||||
|
if (my_smile_xbm && my_smile_xbm->Ok())
|
||||||
|
{
|
||||||
dc.DrawText( "XBM bitmap", 30, 1745 );
|
dc.DrawText( "XBM bitmap", 30, 1745 );
|
||||||
dc.SetPen( *wxRED_PEN );
|
dc.SetPen( *wxRED_PEN );
|
||||||
if (my_smile_xbm && my_smile_xbm->Ok()) {
|
|
||||||
dc.DrawBitmap( *my_smile_xbm, 30, 1760 );
|
dc.DrawBitmap( *my_smile_xbm, 30, 1760 );
|
||||||
dc.DrawText( "..after wxImage conversion", 150, 1745 );
|
|
||||||
|
dc.DrawText( "After wxImage conversion", 150, 1745 );
|
||||||
wxImage i( *my_smile_xbm );
|
wxImage i( *my_smile_xbm );
|
||||||
dc.DrawBitmap( i.ConvertToBitmap(), 150, 1760 );
|
i.SetMaskColour( 0,0,0 );
|
||||||
|
i.Replace( 255,255,255,
|
||||||
|
wxRED_PEN->GetColour().Red(),
|
||||||
|
wxRED_PEN->GetColour().Green(),
|
||||||
|
wxRED_PEN->GetColour().Blue() );
|
||||||
|
dc.DrawBitmap( i.ConvertToBitmap(), 150, 1760, TRUE );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -224,6 +224,29 @@ wxImage wxImage::GetSubImage( const wxRect &rect ) const
|
|||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxImage::Replace( unsigned char r1, unsigned char g1, unsigned char b1,
|
||||||
|
unsigned char r2, unsigned char g2, unsigned char b2 )
|
||||||
|
{
|
||||||
|
wxCHECK_RET( Ok(), wxT("invalid image") );
|
||||||
|
|
||||||
|
char unsigned *data = GetData();
|
||||||
|
|
||||||
|
const int w = GetWidth();
|
||||||
|
const int h = GetHeight();
|
||||||
|
|
||||||
|
for (int j = 0; j < h; j++)
|
||||||
|
for (int i = 0; i < w; i++)
|
||||||
|
{
|
||||||
|
if ((data[0] == r1) && (data[1] == g1) && (data[2] == b1))
|
||||||
|
{
|
||||||
|
data[0] = r2;
|
||||||
|
data[1] = g2;
|
||||||
|
data[2] = b2;
|
||||||
|
}
|
||||||
|
data += 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void wxImage::SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b )
|
void wxImage::SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b )
|
||||||
{
|
{
|
||||||
wxCHECK_RET( Ok(), wxT("invalid image") );
|
wxCHECK_RET( Ok(), wxT("invalid image") );
|
||||||
@@ -1541,15 +1564,19 @@ wxImage::wxImage( const wxBitmap &bitmap )
|
|||||||
SetMaskColour( 16, 16, 16 ); // anything unlikely and dividable
|
SetMaskColour( 16, 16, 16 ); // anything unlikely and dividable
|
||||||
}
|
}
|
||||||
|
|
||||||
GdkVisual *visual = (GdkVisual*) NULL;
|
int bpp = -1;
|
||||||
if (bitmap.GetPixmap())
|
if (bitmap.GetPixmap())
|
||||||
visual = gdk_window_get_visual( bitmap.GetPixmap() );
|
{
|
||||||
else
|
GdkVisual *visual = gdk_window_get_visual( bitmap.GetPixmap() );
|
||||||
visual = gdk_window_get_visual( bitmap.GetBitmap() );
|
|
||||||
|
|
||||||
if (visual == NULL) visual = gdk_window_get_visual( (GdkWindow*) &gdk_root_parent );
|
if (visual == NULL) visual = gdk_window_get_visual( (GdkWindow*) &gdk_root_parent );
|
||||||
int bpp = visual->depth;
|
bpp = visual->depth;
|
||||||
if ((bpp == 16) && (visual->red_mask != 0xf800)) bpp = 15;
|
if ((bpp == 16) && (visual->red_mask != 0xf800)) bpp = 15;
|
||||||
|
}
|
||||||
|
if (bitmap.GetBitmap())
|
||||||
|
{
|
||||||
|
bpp = 1;
|
||||||
|
}
|
||||||
|
|
||||||
GdkColormap *cmap = gtk_widget_get_default_colormap();
|
GdkColormap *cmap = gtk_widget_get_default_colormap();
|
||||||
|
|
||||||
@@ -1559,7 +1586,21 @@ wxImage::wxImage( const wxBitmap &bitmap )
|
|||||||
for (int i = 0; i < bitmap.GetWidth(); i++)
|
for (int i = 0; i < bitmap.GetWidth(); i++)
|
||||||
{
|
{
|
||||||
wxInt32 pixel = gdk_image_get_pixel( gdk_image, i, j );
|
wxInt32 pixel = gdk_image_get_pixel( gdk_image, i, j );
|
||||||
if (bpp <= 8)
|
if (bpp == 1)
|
||||||
|
{
|
||||||
|
if (pixel == 0)
|
||||||
|
{
|
||||||
|
data[pos] = 0;
|
||||||
|
data[pos+1] = 0;
|
||||||
|
data[pos+2] = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data[pos] = 255;
|
||||||
|
data[pos+1] = 255;
|
||||||
|
data[pos+2] = 255;
|
||||||
|
}
|
||||||
|
} else if (bpp <= 8)
|
||||||
{
|
{
|
||||||
data[pos] = cmap->colors[pixel].red >> 8;
|
data[pos] = cmap->colors[pixel].red >> 8;
|
||||||
data[pos+1] = cmap->colors[pixel].green >> 8;
|
data[pos+1] = cmap->colors[pixel].green >> 8;
|
||||||
|
@@ -272,24 +272,26 @@ bool wxToolBar::Create( wxWindow *parent,
|
|||||||
|
|
||||||
gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), TRUE );
|
gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), TRUE );
|
||||||
|
|
||||||
#if (GTK_MINOR_VERSION > 0)
|
|
||||||
if (style & wxTB_FLAT)
|
if (style & wxTB_FLAT)
|
||||||
gtk_toolbar_set_button_relief( GTK_TOOLBAR(m_toolbar), GTK_RELIEF_NONE );
|
gtk_toolbar_set_button_relief( GTK_TOOLBAR(m_toolbar), GTK_RELIEF_NONE );
|
||||||
#endif
|
|
||||||
|
|
||||||
m_fg = new GdkColor;
|
m_fg = new GdkColor;
|
||||||
m_fg->red = 0;
|
m_fg->red = 0;
|
||||||
m_fg->green = 0;
|
m_fg->green = 0;
|
||||||
m_fg->blue = 0;
|
m_fg->blue = 0;
|
||||||
gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ), m_fg );
|
wxColour fg(0,0,0);
|
||||||
|
fg.CalcPixel( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ) );
|
||||||
|
m_fg->pixel = fg.GetPixel();
|
||||||
|
|
||||||
m_bg = new GdkColor;
|
m_bg = new GdkColor;
|
||||||
m_bg->red = 65535;
|
m_bg->red = 65535;
|
||||||
m_bg->green = 65535;
|
m_bg->green = 65535;
|
||||||
m_bg->blue = 50000;
|
m_bg->blue = 49980;
|
||||||
gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ), m_bg );
|
wxColour bg(255,255,196);
|
||||||
|
bg.CalcPixel( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ) );
|
||||||
|
m_bg->pixel = bg.GetPixel();
|
||||||
|
|
||||||
#if (GTK_MINOR_VERSION > 0)
|
|
||||||
gtk_tooltips_force_window( GTK_TOOLBAR(m_toolbar)->tooltips );
|
gtk_tooltips_force_window( GTK_TOOLBAR(m_toolbar)->tooltips );
|
||||||
|
|
||||||
GtkStyle *g_style =
|
GtkStyle *g_style =
|
||||||
@@ -299,9 +301,7 @@ bool wxToolBar::Create( wxWindow *parent,
|
|||||||
|
|
||||||
g_style->bg[GTK_STATE_NORMAL] = *m_bg;
|
g_style->bg[GTK_STATE_NORMAL] = *m_bg;
|
||||||
gtk_widget_set_style( GTK_TOOLBAR(m_toolbar)->tooltips->tip_window, g_style );
|
gtk_widget_set_style( GTK_TOOLBAR(m_toolbar)->tooltips->tip_window, g_style );
|
||||||
#else
|
|
||||||
gtk_tooltips_set_colors( GTK_TOOLBAR(m_toolbar)->tooltips, m_bg, m_fg );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
m_parent->DoAddChild( this );
|
m_parent->DoAddChild( this );
|
||||||
|
|
||||||
|
@@ -272,24 +272,26 @@ bool wxToolBar::Create( wxWindow *parent,
|
|||||||
|
|
||||||
gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), TRUE );
|
gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), TRUE );
|
||||||
|
|
||||||
#if (GTK_MINOR_VERSION > 0)
|
|
||||||
if (style & wxTB_FLAT)
|
if (style & wxTB_FLAT)
|
||||||
gtk_toolbar_set_button_relief( GTK_TOOLBAR(m_toolbar), GTK_RELIEF_NONE );
|
gtk_toolbar_set_button_relief( GTK_TOOLBAR(m_toolbar), GTK_RELIEF_NONE );
|
||||||
#endif
|
|
||||||
|
|
||||||
m_fg = new GdkColor;
|
m_fg = new GdkColor;
|
||||||
m_fg->red = 0;
|
m_fg->red = 0;
|
||||||
m_fg->green = 0;
|
m_fg->green = 0;
|
||||||
m_fg->blue = 0;
|
m_fg->blue = 0;
|
||||||
gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ), m_fg );
|
wxColour fg(0,0,0);
|
||||||
|
fg.CalcPixel( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ) );
|
||||||
|
m_fg->pixel = fg.GetPixel();
|
||||||
|
|
||||||
m_bg = new GdkColor;
|
m_bg = new GdkColor;
|
||||||
m_bg->red = 65535;
|
m_bg->red = 65535;
|
||||||
m_bg->green = 65535;
|
m_bg->green = 65535;
|
||||||
m_bg->blue = 50000;
|
m_bg->blue = 49980;
|
||||||
gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ), m_bg );
|
wxColour bg(255,255,196);
|
||||||
|
bg.CalcPixel( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ) );
|
||||||
|
m_bg->pixel = bg.GetPixel();
|
||||||
|
|
||||||
#if (GTK_MINOR_VERSION > 0)
|
|
||||||
gtk_tooltips_force_window( GTK_TOOLBAR(m_toolbar)->tooltips );
|
gtk_tooltips_force_window( GTK_TOOLBAR(m_toolbar)->tooltips );
|
||||||
|
|
||||||
GtkStyle *g_style =
|
GtkStyle *g_style =
|
||||||
@@ -299,9 +301,7 @@ bool wxToolBar::Create( wxWindow *parent,
|
|||||||
|
|
||||||
g_style->bg[GTK_STATE_NORMAL] = *m_bg;
|
g_style->bg[GTK_STATE_NORMAL] = *m_bg;
|
||||||
gtk_widget_set_style( GTK_TOOLBAR(m_toolbar)->tooltips->tip_window, g_style );
|
gtk_widget_set_style( GTK_TOOLBAR(m_toolbar)->tooltips->tip_window, g_style );
|
||||||
#else
|
|
||||||
gtk_tooltips_set_colors( GTK_TOOLBAR(m_toolbar)->tooltips, m_bg, m_fg );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
m_parent->DoAddChild( this );
|
m_parent->DoAddChild( this );
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
# Note that this is NOT a relocatable package
|
# Note that this is NOT a relocatable package
|
||||||
%define pref /usr
|
%define pref /usr
|
||||||
%define ver 2.1.11
|
%define ver 2.1.12
|
||||||
%define rel 0
|
%define rel 0
|
||||||
|
|
||||||
Summary: The GTK+ 1.2 port of the wxWindows library
|
Summary: The GTK+ 1.2 port of the wxWindows library
|
||||||
@@ -9,7 +9,7 @@ Version: %{ver}
|
|||||||
Release: %{rel}
|
Release: %{rel}
|
||||||
Copyright: wxWindows Licence
|
Copyright: wxWindows Licence
|
||||||
Group: X11/Libraries
|
Group: X11/Libraries
|
||||||
Source: ftp://wesley.informatik.uni-freiburg.de/pub/linux/wxxt/source/wxGTK-2.1.11.tgz
|
Source: ftp://wesley.informatik.uni-freiburg.de/pub/linux/wxxt/source/wxGTK-2.1.12.tgz
|
||||||
URL: http://wesley.informatik.uni-freiburg.de/~wxxt/docs.html
|
URL: http://wesley.informatik.uni-freiburg.de/~wxxt/docs.html
|
||||||
Packager: Robert Roebling <roebling@ruf.uni-freiburg.de>
|
Packager: Robert Roebling <roebling@ruf.uni-freiburg.de>
|
||||||
BuildRoot: /tmp/wxgtk_root
|
BuildRoot: /tmp/wxgtk_root
|
||||||
|
Reference in New Issue
Block a user