]>
git.saurik.com Git - wxWidgets.git/blob - src/common/rgncmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Methods of wxRegion that have a generic implementation
6 // Created: 27-Mar-2003
8 // Copyright: (c) Robin Dunn
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "rgncmn.h"
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
24 #include "wx/region.h"
25 #include "wx/bitmap.h"
27 #include "wx/dcmemory.h"
30 //---------------------------------------------------------------------------
34 wxBitmap
wxRegion::ConvertToBitmap() const
36 wxRect box
= GetBox();
37 wxBitmap
bmp(box
.GetRight(), box
.GetBottom());
40 dc
.SetBackground(*wxBLACK_BRUSH
);
42 dc
.SetClippingRegion(*this);
43 dc
.SetBackground(*wxWHITE_BRUSH
);
45 dc
.SelectObject(wxNullBitmap
);
49 //---------------------------------------------------------------------------
51 bool wxRegion::Union(const wxBitmap
& bmp
,
52 const wxColour
& transColour
,
55 unsigned char loR
, loG
, loB
;
56 unsigned char hiR
, hiG
, hiB
;
58 wxCHECK_MSG((bmp
.GetMask() != NULL
) || transColour
.Ok(),
60 wxT("Either the bitmap should have a mask or a colour should be given."));
62 wxImage image
= bmp
.ConvertToImage();
66 loR
= image
.GetMaskRed();
67 loG
= image
.GetMaskGreen();
68 loB
= image
.GetMaskBlue();
72 loR
= transColour
.Red();
73 loG
= transColour
.Green();
74 loB
= transColour
.Blue();
77 hiR
= wxMin(0xFF, loR
+ tolerance
);
78 hiG
= wxMin(0xFF, loG
+ tolerance
);
79 hiB
= wxMin(0xFF, loB
+ tolerance
);
81 // Loop through the image row by row, pixel by pixel, building up
82 // rectangles to add to the region.
83 int width
= image
.GetWidth();
84 int height
= image
.GetHeight();
85 for (int y
=0; y
< height
; y
++)
91 for (int x
=0; x
< width
; x
++)
93 // search for a continuous range of non-transparent pixels
97 unsigned char R
= image
.GetRed(x
,y
);
98 unsigned char G
= image
.GetGreen(x
,y
);
99 unsigned char B
= image
.GetBlue(x
,y
);
100 if (( R
>= loR
&& R
<= hiR
) &&
101 ( G
>= loG
&& G
<= hiG
) &&
102 ( B
>= loB
&& B
<= hiB
)) // It's transparent
107 // Add the run of non-transparent pixels (if any) to the region
119 //---------------------------------------------------------------------------