]>
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"
26 #include "wx/dcmemory.h"
29 //---------------------------------------------------------------------------
33 wxBitmap
wxRegion::ConvertToBitmap() const
35 wxRect box
= GetBox();
36 wxBitmap
bmp(box
.GetRight(), box
.GetBottom());
39 dc
.SetBackground(*wxWHITE_BRUSH
);
41 dc
.SetClippingRegion(*this);
42 dc
.SetBackground(*wxBLACK_BRUSH
);
44 dc
.SelectObject(wxNullBitmap
);
48 //---------------------------------------------------------------------------
50 bool wxRegion::Union(const wxBitmap
& bmp
,
51 const wxColour
& transColour
,
54 unsigned char loR
, loG
, loB
;
55 unsigned char hiR
, hiG
, hiB
;
57 wxCHECK_MSG((bmp
.GetMask() != NULL
) || transColour
.Ok(),
59 wxT("Either the bitmap should have a mask or a colour should be given."));
61 wxImage image
= bmp
.ConvertToImage();
65 loR
= image
.GetMaskRed();
66 loG
= image
.GetMaskGreen();
67 loB
= image
.GetMaskBlue();
71 loR
= transColour
.Red();
72 loG
= transColour
.Green();
73 loB
= transColour
.Blue();
76 hiR
= wxMin(0xFF, loR
+ tolerance
);
77 hiG
= wxMin(0xFF, loG
+ tolerance
);
78 hiB
= wxMin(0xFF, loB
+ tolerance
);
80 // Loop through the image row by row, pixel by pixel, building up
81 // rectangles to add to the region.
82 int width
= image
.GetWidth();
83 int height
= image
.GetHeight();
84 for (int y
=0; y
< height
; y
++)
90 for (int x
=0; x
< width
; x
++)
92 // search for a continuous range of non-transparent pixels
96 unsigned char R
= image
.GetRed(x
,y
);
97 unsigned char G
= image
.GetGreen(x
,y
);
98 unsigned char B
= image
.GetBlue(x
,y
);
99 if (( R
>= loR
&& R
<= hiR
) &&
100 ( G
>= loG
&& G
<= hiG
) &&
101 ( B
>= loB
&& B
<= hiB
)) // It's transparent
106 // Add the run of non-transparent pixels (if any) to the region
118 //---------------------------------------------------------------------------