]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/bitmap.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "bitmap.h"
16 #include "wx/palette.h"
17 #include "wx/bitmap.h"
19 #include "wx/filefn.h"
21 #include "wx/dcmemory.h"
28 #if (GTK_MINOR_VERSION > 0)
29 #include <gdk/gdkrgb.h>
32 extern void gdk_wx_draw_bitmap (GdkDrawable
*drawable
,
42 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
46 extern GtkWidget
*wxGetRootWindow();
48 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
52 IMPLEMENT_DYNAMIC_CLASS(wxMask
,wxObject
)
56 m_bitmap
= (GdkBitmap
*) NULL
;
59 wxMask::wxMask( const wxBitmap
& bitmap
, const wxColour
& colour
)
61 m_bitmap
= (GdkBitmap
*) NULL
;
62 Create( bitmap
, colour
);
65 wxMask::wxMask( const wxBitmap
& bitmap
, int paletteIndex
)
67 m_bitmap
= (GdkBitmap
*) NULL
;
68 Create( bitmap
, paletteIndex
);
71 wxMask::wxMask( const wxBitmap
& bitmap
)
73 m_bitmap
= (GdkBitmap
*) NULL
;
80 gdk_bitmap_unref( m_bitmap
);
83 bool wxMask::Create( const wxBitmap
& bitmap
,
84 const wxColour
& colour
)
88 gdk_bitmap_unref( m_bitmap
);
89 m_bitmap
= (GdkBitmap
*) NULL
;
92 wxImage
image( bitmap
);
93 if (!image
.Ok()) return FALSE
;
95 m_bitmap
= gdk_pixmap_new( wxGetRootWindow()->window
, image
.GetWidth(), image
.GetHeight(), 1 );
96 GdkGC
*gc
= gdk_gc_new( m_bitmap
);
103 gdk_gc_set_foreground( gc
, &color
);
104 gdk_gc_set_fill( gc
, GDK_SOLID
);
105 gdk_draw_rectangle( m_bitmap
, gc
, TRUE
, 0, 0, image
.GetWidth(), image
.GetHeight() );
107 unsigned char *data
= image
.GetData();
110 unsigned char red
= colour
.Red();
111 unsigned char green
= colour
.Green();
112 unsigned char blue
= colour
.Blue();
114 GdkVisual
*visual
= gdk_window_get_visual( wxGetRootWindow()->window
);
117 int bpp
= visual
->depth
;
118 if ((bpp
== 16) && (visual
->red_mask
!= 0xf800)) bpp
= 15;
122 green
= green
& 0xf8;
128 green
= green
& 0xfc;
136 gdk_gc_set_foreground( gc
, &color
);
138 for (int j
= 0; j
< image
.GetHeight(); j
++)
142 for (i
= 0; i
< image
.GetWidth(); i
++)
144 if ((data
[index
] == red
) &&
145 (data
[index
+1] == green
) &&
146 (data
[index
+2] == blue
))
155 gdk_draw_line( m_bitmap
, gc
, start_x
, j
, i
-1, j
);
162 gdk_draw_line( m_bitmap
, gc
, start_x
, j
, i
, j
);
170 bool wxMask::Create( const wxBitmap
& bitmap
, int paletteIndex
)
173 wxPalette
*pal
= bitmap
.GetPalette();
175 wxCHECK_MSG( pal
, FALSE
, wxT("Cannot create mask from bitmap without palette") );
177 pal
->GetRGB(paletteIndex
, &r
, &g
, &b
);
179 return Create(bitmap
, wxColour(r
, g
, b
));
182 bool wxMask::Create( const wxBitmap
& bitmap
)
186 gdk_bitmap_unref( m_bitmap
);
187 m_bitmap
= (GdkBitmap
*) NULL
;
190 if (!bitmap
.Ok()) return FALSE
;
192 wxCHECK_MSG( bitmap
.GetBitmap(), FALSE
, wxT("Cannot create mask from colour bitmap") );
194 m_bitmap
= gdk_pixmap_new( wxGetRootWindow()->window
, bitmap
.GetWidth(), bitmap
.GetHeight(), 1 );
196 if (!m_bitmap
) return FALSE
;
198 GdkGC
*gc
= gdk_gc_new( m_bitmap
);
200 gdk_wx_draw_bitmap( m_bitmap
, gc
, bitmap
.GetBitmap(), 0, 0, 0, 0, bitmap
.GetWidth(), bitmap
.GetHeight() );
207 GdkBitmap
*wxMask::GetBitmap() const
212 //-----------------------------------------------------------------------------
214 //-----------------------------------------------------------------------------
216 class wxBitmapRefData
: public wxObjectRefData
228 wxPalette
*m_palette
;
231 wxBitmapRefData::wxBitmapRefData()
233 m_pixmap
= (GdkPixmap
*) NULL
;
234 m_bitmap
= (GdkBitmap
*) NULL
;
235 m_mask
= (wxMask
*) NULL
;
239 m_palette
= (wxPalette
*) NULL
;
242 wxBitmapRefData::~wxBitmapRefData()
244 if (m_pixmap
) gdk_pixmap_unref( m_pixmap
);
245 if (m_bitmap
) gdk_bitmap_unref( m_bitmap
);
246 if (m_mask
) delete m_mask
;
247 if (m_palette
) delete m_palette
;
250 //-----------------------------------------------------------------------------
252 #define M_BMPDATA ((wxBitmapRefData *)m_refData)
254 IMPLEMENT_DYNAMIC_CLASS(wxBitmap
,wxGDIObject
)
258 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
261 wxBitmap::wxBitmap( int width
, int height
, int depth
)
263 Create( width
, height
, depth
);
265 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
268 bool wxBitmap::Create( int width
, int height
, int depth
)
272 wxCHECK_MSG( (width
> 0) && (height
> 0), FALSE
, wxT("invalid bitmap size") )
274 GdkVisual
*visual
= gdk_window_get_visual( wxGetRootWindow()->window
);
277 if (depth
== -1) depth
= visual
->depth
;
279 wxCHECK_MSG( (depth
== visual
->depth
) ||
280 (depth
== 1), FALSE
, wxT("invalid bitmap depth") )
282 m_refData
= new wxBitmapRefData();
283 M_BMPDATA
->m_mask
= (wxMask
*) NULL
;
284 M_BMPDATA
->m_width
= width
;
285 M_BMPDATA
->m_height
= height
;
288 M_BMPDATA
->m_bitmap
= gdk_pixmap_new( wxGetRootWindow()->window
, width
, height
, 1 );
289 M_BMPDATA
->m_bpp
= 1;
293 M_BMPDATA
->m_pixmap
= gdk_pixmap_new( wxGetRootWindow()->window
, width
, height
, depth
);
294 M_BMPDATA
->m_bpp
= visual
->depth
;
300 bool wxBitmap::CreateFromXpm( const char **bits
)
302 wxCHECK_MSG( bits
!= NULL
, FALSE
, wxT("invalid bitmap data") )
304 GdkVisual
*visual
= gdk_window_get_visual( wxGetRootWindow()->window
);
307 m_refData
= new wxBitmapRefData();
309 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
311 M_BMPDATA
->m_pixmap
= gdk_pixmap_create_from_xpm_d( wxGetRootWindow()->window
, &mask
, NULL
, (gchar
**) bits
);
313 wxCHECK_MSG( M_BMPDATA
->m_pixmap
, FALSE
, wxT("couldn't create pixmap") );
317 M_BMPDATA
->m_mask
= new wxMask();
318 M_BMPDATA
->m_mask
->m_bitmap
= mask
;
321 gdk_window_get_size( M_BMPDATA
->m_pixmap
, &(M_BMPDATA
->m_width
), &(M_BMPDATA
->m_height
) );
323 M_BMPDATA
->m_bpp
= visual
->depth
; // ?
325 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
330 bool wxBitmap::CreateFromImage( const wxImage
& image
, int depth
)
332 wxCHECK_MSG( image
.Ok(), FALSE
, wxT("invalid image") )
333 wxCHECK_MSG( depth
== -1 || depth
== 1, FALSE
, wxT("invalid bitmap depth") )
335 m_refData
= new wxBitmapRefData();
337 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
340 // convertion to mono bitmap:
344 int width
= image
.GetWidth();
345 int height
= image
.GetHeight();
350 SetBitmap( gdk_pixmap_new( wxGetRootWindow()->window
, width
, height
, 1 ) );
354 GdkVisual
*visual
= gdk_window_get_visual( wxGetRootWindow()->window
);
357 // Create picture image
359 unsigned char *data_data
= (unsigned char*)malloc( ((width
>> 3)+8) * height
);
361 GdkImage
*data_image
=
362 gdk_image_new_bitmap( visual
, data_data
, width
, height
);
366 GdkImage
*mask_image
= (GdkImage
*) NULL
;
370 unsigned char *mask_data
= (unsigned char*)malloc( ((width
>> 3)+8) * height
);
372 mask_image
= gdk_image_new_bitmap( visual
, mask_data
, width
, height
);
374 wxMask
*mask
= new wxMask();
375 mask
->m_bitmap
= gdk_pixmap_new( wxGetRootWindow()->window
, width
, height
, 1 );
380 int r_mask
= image
.GetMaskRed();
381 int g_mask
= image
.GetMaskGreen();
382 int b_mask
= image
.GetMaskBlue();
384 unsigned char* data
= image
.GetData();
387 for (int y
= 0; y
< height
; y
++)
389 for (int x
= 0; x
< width
; x
++)
400 if ((r
== r_mask
) && (b
== b_mask
) && (g
== g_mask
))
401 gdk_image_put_pixel( mask_image
, x
, y
, 1 );
403 gdk_image_put_pixel( mask_image
, x
, y
, 0 );
406 if ((r
== 255) && (b
== 255) && (g
== 255))
407 gdk_image_put_pixel( data_image
, x
, y
, 1 );
409 gdk_image_put_pixel( data_image
, x
, y
, 0 );
416 GdkGC
*data_gc
= gdk_gc_new( GetBitmap() );
418 gdk_draw_image( GetBitmap(), data_gc
, data_image
, 0, 0, 0, 0, width
, height
);
420 gdk_image_destroy( data_image
);
421 gdk_gc_unref( data_gc
);
427 GdkGC
*mask_gc
= gdk_gc_new( GetMask()->GetBitmap() );
429 gdk_draw_image( GetMask()->GetBitmap(), mask_gc
, mask_image
, 0, 0, 0, 0, width
, height
);
431 gdk_image_destroy( mask_image
);
432 gdk_gc_unref( mask_gc
);
437 // convertion to colour bitmap:
441 int width
= image
.GetWidth();
442 int height
= image
.GetHeight();
447 SetPixmap( gdk_pixmap_new( wxGetRootWindow()->window
, width
, height
, -1 ) );
451 GdkVisual
*visual
= gdk_window_get_visual( wxGetRootWindow()->window
);
454 int bpp
= visual
->depth
;
458 if ((bpp
== 16) && (visual
->red_mask
!= 0xf800)) bpp
= 15;
459 if (bpp
< 8) bpp
= 8;
461 #if (GTK_MINOR_VERSION > 0)
463 if (!image
.HasMask() && (bpp
> 8))
465 static bool s_hasInitialized
= FALSE
;
467 if (!s_hasInitialized
)
470 s_hasInitialized
= TRUE
;
473 GdkGC
*gc
= gdk_gc_new( GetPixmap() );
475 gdk_draw_rgb_image( GetPixmap(),
489 // Create picture image
491 GdkImage
*data_image
=
492 gdk_image_new( GDK_IMAGE_FASTEST
, visual
, width
, height
);
496 GdkImage
*mask_image
= (GdkImage
*) NULL
;
500 unsigned char *mask_data
= (unsigned char*)malloc( ((width
>> 3)+8) * height
);
502 mask_image
= gdk_image_new_bitmap( visual
, mask_data
, width
, height
);
504 wxMask
*mask
= new wxMask();
505 mask
->m_bitmap
= gdk_pixmap_new( wxGetRootWindow()->window
, width
, height
, 1 );
512 enum byte_order
{ RGB
, RBG
, BRG
, BGR
, GRB
, GBR
};
513 byte_order b_o
= RGB
;
517 if ((visual
->red_mask
> visual
->green_mask
) && (visual
->green_mask
> visual
->blue_mask
)) b_o
= RGB
;
518 else if ((visual
->red_mask
> visual
->blue_mask
) && (visual
->blue_mask
> visual
->green_mask
)) b_o
= RGB
;
519 else if ((visual
->blue_mask
> visual
->red_mask
) && (visual
->red_mask
> visual
->green_mask
)) b_o
= BRG
;
520 else if ((visual
->blue_mask
> visual
->green_mask
) && (visual
->green_mask
> visual
->red_mask
)) b_o
= BGR
;
521 else if ((visual
->green_mask
> visual
->red_mask
) && (visual
->red_mask
> visual
->blue_mask
)) b_o
= GRB
;
522 else if ((visual
->green_mask
> visual
->blue_mask
) && (visual
->blue_mask
> visual
->red_mask
)) b_o
= GBR
;
525 int r_mask
= image
.GetMaskRed();
526 int g_mask
= image
.GetMaskGreen();
527 int b_mask
= image
.GetMaskBlue();
529 unsigned char* data
= image
.GetData();
532 for (int y
= 0; y
< height
; y
++)
534 for (int x
= 0; x
< width
; x
++)
545 if ((r
== r_mask
) && (b
== b_mask
) && (g
== g_mask
))
546 gdk_image_put_pixel( mask_image
, x
, y
, 1 );
548 gdk_image_put_pixel( mask_image
, x
, y
, 0 );
556 if (wxTheApp
->m_colorCube
)
558 pixel
= wxTheApp
->m_colorCube
[ ((r
& 0xf8) << 7) + ((g
& 0xf8) << 2) + ((b
& 0xf8) >> 3) ];
562 GdkColormap
*cmap
= gtk_widget_get_default_colormap();
563 GdkColor
*colors
= cmap
->colors
;
564 int max
= 3 * (65536);
566 for (int i
= 0; i
< cmap
->size
; i
++)
568 int rdiff
= (r
<< 8) - colors
[i
].red
;
569 int gdiff
= (g
<< 8) - colors
[i
].green
;
570 int bdiff
= (b
<< 8) - colors
[i
].blue
;
571 int sum
= ABS (rdiff
) + ABS (gdiff
) + ABS (bdiff
);
572 if (sum
< max
) { pixel
= i
; max
= sum
; }
576 gdk_image_put_pixel( data_image
, x
, y
, pixel
);
582 guint32 pixel
= ((r
& 0xf8) << 7) | ((g
& 0xf8) << 2) | ((b
& 0xf8) >> 3);
583 gdk_image_put_pixel( data_image
, x
, y
, pixel
);
588 guint32 pixel
= ((r
& 0xf8) << 8) | ((g
& 0xfc) << 3) | ((b
& 0xf8) >> 3);
589 gdk_image_put_pixel( data_image
, x
, y
, pixel
);
598 case RGB
: pixel
= (r
<< 16) | (g
<< 8) | b
; break;
599 case RBG
: pixel
= (r
<< 16) | (b
<< 8) | g
; break;
600 case BRG
: pixel
= (b
<< 16) | (r
<< 8) | g
; break;
601 case BGR
: pixel
= (b
<< 16) | (g
<< 8) | r
; break;
602 case GRB
: pixel
= (g
<< 16) | (r
<< 8) | b
; break;
603 case GBR
: pixel
= (g
<< 16) | (b
<< 8) | r
; break;
605 gdk_image_put_pixel( data_image
, x
, y
, pixel
);
614 GdkGC
*data_gc
= gdk_gc_new( GetPixmap() );
616 gdk_draw_image( GetPixmap(), data_gc
, data_image
, 0, 0, 0, 0, width
, height
);
618 gdk_image_destroy( data_image
);
619 gdk_gc_unref( data_gc
);
625 GdkGC
*mask_gc
= gdk_gc_new( GetMask()->GetBitmap() );
627 gdk_draw_image( GetMask()->GetBitmap(), mask_gc
, mask_image
, 0, 0, 0, 0, width
, height
);
629 gdk_image_destroy( mask_image
);
630 gdk_gc_unref( mask_gc
);
637 wxImage
wxBitmap::ConvertToImage() const
641 wxCHECK_MSG( Ok(), wxNullImage
, wxT("invalid bitmap") );
643 GdkImage
*gdk_image
= (GdkImage
*) NULL
;
646 gdk_image
= gdk_image_get( GetPixmap(),
648 GetWidth(), GetHeight() );
652 gdk_image
= gdk_image_get( GetBitmap(),
654 GetWidth(), GetHeight() );
657 wxFAIL_MSG( wxT("Ill-formed bitmap") );
660 wxCHECK_MSG( gdk_image
, wxNullImage
, wxT("couldn't create image") );
662 image
.Create( GetWidth(), GetHeight() );
663 char unsigned *data
= image
.GetData();
667 gdk_image_destroy( gdk_image
);
668 wxFAIL_MSG( wxT("couldn't create image") );
672 GdkImage
*gdk_image_mask
= (GdkImage
*) NULL
;
675 gdk_image_mask
= gdk_image_get( GetMask()->GetBitmap(),
677 GetWidth(), GetHeight() );
679 image
.SetMaskColour( 16, 16, 16 ); // anything unlikely and dividable
683 int red_shift_right
= 0;
684 int green_shift_right
= 0;
685 int blue_shift_right
= 0;
686 int red_shift_left
= 0;
687 int green_shift_left
= 0;
688 int blue_shift_left
= 0;
689 bool use_shift
= FALSE
;
693 GdkVisual
*visual
= gdk_window_get_visual( GetPixmap() );
695 if (visual
== NULL
) visual
= gdk_window_get_visual( wxGetRootWindow()->window
);
697 if (bpp
== 16) bpp
= visual
->red_prec
+ visual
->green_prec
+ visual
->blue_prec
;
698 red_shift_right
= visual
->red_shift
;
699 red_shift_left
= 8-visual
->red_prec
;
700 green_shift_right
= visual
->green_shift
;
701 green_shift_left
= 8-visual
->green_prec
;
702 blue_shift_right
= visual
->blue_shift
;
703 blue_shift_left
= 8-visual
->blue_prec
;
705 use_shift
= (visual
->type
== GDK_VISUAL_TRUE_COLOR
) || (visual
->type
== GDK_VISUAL_DIRECT_COLOR
);
713 GdkColormap
*cmap
= gtk_widget_get_default_colormap();
716 for (int j
= 0; j
< GetHeight(); j
++)
718 for (int i
= 0; i
< GetWidth(); i
++)
720 wxUint32 pixel
= gdk_image_get_pixel( gdk_image
, i
, j
);
738 data
[pos
] = (pixel
>> red_shift_right
) << red_shift_left
;
739 data
[pos
+1] = (pixel
>> green_shift_right
) << green_shift_left
;
740 data
[pos
+2] = (pixel
>> blue_shift_right
) << blue_shift_left
;
742 else if (cmap
->colors
)
744 data
[pos
] = cmap
->colors
[pixel
].red
>> 8;
745 data
[pos
+1] = cmap
->colors
[pixel
].green
>> 8;
746 data
[pos
+2] = cmap
->colors
[pixel
].blue
>> 8;
750 wxFAIL_MSG( wxT("Image conversion failed. Unknown visual type.") );
755 int mask_pixel
= gdk_image_get_pixel( gdk_image_mask
, i
, j
);
768 gdk_image_destroy( gdk_image
);
769 if (gdk_image_mask
) gdk_image_destroy( gdk_image_mask
);
774 wxBitmap::wxBitmap( const wxBitmap
& bmp
)
778 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
781 wxBitmap::wxBitmap( const wxString
&filename
, int type
)
783 LoadFile( filename
, type
);
785 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
788 wxBitmap::wxBitmap( const char bits
[], int width
, int height
, int WXUNUSED(depth
))
790 m_refData
= new wxBitmapRefData();
792 M_BMPDATA
->m_mask
= (wxMask
*) NULL
;
793 M_BMPDATA
->m_bitmap
=
794 gdk_bitmap_create_from_data( wxGetRootWindow()->window
, (gchar
*) bits
, width
, height
);
795 M_BMPDATA
->m_width
= width
;
796 M_BMPDATA
->m_height
= height
;
797 M_BMPDATA
->m_bpp
= 1;
799 wxCHECK_RET( M_BMPDATA
->m_bitmap
, wxT("couldn't create bitmap") );
801 if (wxTheBitmapList
) wxTheBitmapList
->AddBitmap(this);
804 wxBitmap::~wxBitmap()
806 if (wxTheBitmapList
) wxTheBitmapList
->DeleteObject(this);
809 wxBitmap
& wxBitmap::operator = ( const wxBitmap
& bmp
)
811 if (*this == bmp
) return (*this);
816 bool wxBitmap::operator == ( const wxBitmap
& bmp
) const
818 return m_refData
== bmp
.m_refData
;
821 bool wxBitmap::operator != ( const wxBitmap
& bmp
) const
823 return m_refData
!= bmp
.m_refData
;
826 bool wxBitmap::Ok() const
828 return (m_refData
!= NULL
);
831 int wxBitmap::GetHeight() const
833 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
835 return M_BMPDATA
->m_height
;
838 int wxBitmap::GetWidth() const
840 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
842 return M_BMPDATA
->m_width
;
845 int wxBitmap::GetDepth() const
847 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
849 return M_BMPDATA
->m_bpp
;
852 wxMask
*wxBitmap::GetMask() const
854 wxCHECK_MSG( Ok(), (wxMask
*) NULL
, wxT("invalid bitmap") );
856 return M_BMPDATA
->m_mask
;
859 void wxBitmap::SetMask( wxMask
*mask
)
861 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
863 if (M_BMPDATA
->m_mask
) delete M_BMPDATA
->m_mask
;
865 M_BMPDATA
->m_mask
= mask
;
868 wxBitmap
wxBitmap::GetSubBitmap( const wxRect
& rect
) const
871 (rect
.x
>= 0) && (rect
.y
>= 0) &&
872 (rect
.x
+rect
.width
<= M_BMPDATA
->m_width
) && (rect
.y
+rect
.height
<= M_BMPDATA
->m_height
),
873 wxNullBitmap
, wxT("invalid bitmap or bitmap region") );
875 wxBitmap
ret( rect
.width
, rect
.height
, M_BMPDATA
->m_bpp
);
876 wxASSERT_MSG( ret
.Ok(), wxT("GetSubBitmap error") );
880 GdkGC
*gc
= gdk_gc_new( ret
.GetPixmap() );
881 gdk_draw_pixmap( ret
.GetPixmap(), gc
, GetPixmap(), rect
.x
, rect
.y
, 0, 0, rect
.width
, rect
.height
);
882 gdk_gc_destroy( gc
);
886 GdkGC
*gc
= gdk_gc_new( ret
.GetBitmap() );
887 gdk_wx_draw_bitmap( ret
.GetBitmap(), gc
, GetBitmap(), rect
.x
, rect
.y
, 0, 0, rect
.width
, rect
.height
);
888 gdk_gc_destroy( gc
);
893 wxMask
*mask
= new wxMask
;
894 mask
->m_bitmap
= gdk_pixmap_new( wxGetRootWindow()->window
, rect
.width
, rect
.height
, 1 );
896 GdkGC
*gc
= gdk_gc_new( mask
->m_bitmap
);
897 gdk_wx_draw_bitmap( mask
->m_bitmap
, gc
, M_BMPDATA
->m_mask
->m_bitmap
, 0, 0, rect
.x
, rect
.y
, rect
.width
, rect
.height
);
898 gdk_gc_destroy( gc
);
906 bool wxBitmap::SaveFile( const wxString
&name
, int type
, wxPalette
*WXUNUSED(palette
) )
908 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid bitmap") );
910 // Try to save the bitmap via wxImage handlers:
912 wxImage
image( *this );
913 if (image
.Ok()) return image
.SaveFile( name
, type
);
919 bool wxBitmap::LoadFile( const wxString
&name
, int type
)
923 if (!wxFileExists(name
)) return FALSE
;
925 GdkVisual
*visual
= gdk_window_get_visual( wxGetRootWindow()->window
);
928 if (type
== wxBITMAP_TYPE_XPM
)
930 m_refData
= new wxBitmapRefData();
932 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
934 M_BMPDATA
->m_pixmap
= gdk_pixmap_create_from_xpm( wxGetRootWindow()->window
, &mask
, NULL
, name
.fn_str() );
938 M_BMPDATA
->m_mask
= new wxMask();
939 M_BMPDATA
->m_mask
->m_bitmap
= mask
;
942 gdk_window_get_size( M_BMPDATA
->m_pixmap
, &(M_BMPDATA
->m_width
), &(M_BMPDATA
->m_height
) );
944 M_BMPDATA
->m_bpp
= visual
->depth
;
946 else // try if wxImage can load it
949 if (!image
.LoadFile( name
, type
)) return FALSE
;
950 if (image
.Ok()) *this = image
.ConvertToBitmap();
957 wxPalette
*wxBitmap::GetPalette() const
959 if (!Ok()) return (wxPalette
*) NULL
;
961 return M_BMPDATA
->m_palette
;
964 void wxBitmap::SetHeight( int height
)
966 if (!m_refData
) m_refData
= new wxBitmapRefData();
968 M_BMPDATA
->m_height
= height
;
971 void wxBitmap::SetWidth( int width
)
973 if (!m_refData
) m_refData
= new wxBitmapRefData();
975 M_BMPDATA
->m_width
= width
;
978 void wxBitmap::SetDepth( int depth
)
980 if (!m_refData
) m_refData
= new wxBitmapRefData();
982 M_BMPDATA
->m_bpp
= depth
;
985 void wxBitmap::SetPixmap( GdkPixmap
*pixmap
)
987 if (!m_refData
) m_refData
= new wxBitmapRefData();
989 M_BMPDATA
->m_pixmap
= pixmap
;
992 void wxBitmap::SetBitmap( GdkPixmap
*bitmap
)
994 if (!m_refData
) m_refData
= new wxBitmapRefData();
996 M_BMPDATA
->m_bitmap
= bitmap
;
999 GdkPixmap
*wxBitmap::GetPixmap() const
1001 wxCHECK_MSG( Ok(), (GdkPixmap
*) NULL
, wxT("invalid bitmap") );
1003 return M_BMPDATA
->m_pixmap
;
1006 GdkBitmap
*wxBitmap::GetBitmap() const
1008 wxCHECK_MSG( Ok(), (GdkBitmap
*) NULL
, wxT("invalid bitmap") );
1010 return M_BMPDATA
->m_bitmap
;